Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong location icon and page info bubble of brave page #1722

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ source_set("ui") {
"brave_browser_command_controller.h",
"brave_browser_content_setting_bubble_model_delegate.cc",
"brave_browser_content_setting_bubble_model_delegate.h",
"brave_browser_location_bar_model_delegate.cc",
"brave_browser_location_bar_model_delegate.h",
"brave_pages.cc",
"brave_pages.h",
"brave_layout_constants.cc",
Expand Down Expand Up @@ -47,6 +49,8 @@ source_set("ui") {
"views/importer/brave_import_lock_dialog_view.h",
"views/location_bar/brave_location_bar_view.cc",
"views/location_bar/brave_location_bar_view.h",
"views/location_bar/brave_location_icon_view.cc",
"views/location_bar/brave_location_icon_view.h",
"views/profiles/brave_avatar_toolbar_button.cc",
"views/profiles/brave_avatar_toolbar_button.h",
"views/profiles/brave_profile_chooser_view.cc",
Expand Down
26 changes: 26 additions & 0 deletions browser/ui/brave_browser_location_bar_model_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/brave_browser_location_bar_model_delegate.h"

#if !defined(OS_ANDROID)
#include "components/omnibox/browser/vector_icons.h" // nogncheck
#endif // !defined(OS_ANDROID)

#include "content/public/common/url_constants.h"
const gfx::VectorIcon*
BraveBrowserLocationBarModelDelegate::GetVectorIconOverride() const {
#if !defined(OS_ANDROID)
GURL url;
GetURL(&url);

if (url.SchemeIs(content::kBraveUIScheme))
return &omnibox::kProductIcon;

return BrowserLocationBarModelDelegate::GetVectorIconOverride();
#endif

return nullptr;
}
23 changes: 23 additions & 0 deletions browser/ui/brave_browser_location_bar_model_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_BRAVE_BROWSER_LOCATION_BAR_MODEL_DELEGATE_H_
#define BRAVE_BROWSER_UI_BRAVE_BROWSER_LOCATION_BAR_MODEL_DELEGATE_H_

#include "chrome/browser/ui/browser_location_bar_model_delegate.h"

class BraveBrowserLocationBarModelDelegate
: public BrowserLocationBarModelDelegate {
public:
using BrowserLocationBarModelDelegate::BrowserLocationBarModelDelegate;
~BraveBrowserLocationBarModelDelegate() override = default;

private:
const gfx::VectorIcon* GetVectorIconOverride() const override;

DISALLOW_COPY_AND_ASSIGN(BraveBrowserLocationBarModelDelegate);
};

#endif // BRAVE_BROWSER_UI_BRAVE_BROWSER_LOCATION_BAR_MODEL_DELEGATE_H_
30 changes: 30 additions & 0 deletions browser/ui/brave_browser_location_bar_model_delegate_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/brave_browser_location_bar_model_delegate.h"

#include "components/omnibox/browser/vector_icons.h"
#include "testing/gtest/include/gtest/gtest.h"

class TestLocationBarModelDelegate
: public BraveBrowserLocationBarModelDelegate {
public:
TestLocationBarModelDelegate()
: BraveBrowserLocationBarModelDelegate(nullptr) {}
~TestLocationBarModelDelegate() override {}

bool GetURL(GURL* url) const override {
*url = GURL("brave://sync/");
return true;
}
};

// Check proper icon is used for brave url.
TEST(BraveBrowserLocationBarModelDelegateTest, VectorIconOverrideTest) {
TestLocationBarModelDelegate delegate;
EXPECT_EQ(&omnibox::kProductIcon,
static_cast<LocationBarModelDelegate*>(&delegate)->
GetVectorIconOverride());
}
25 changes: 21 additions & 4 deletions browser/ui/views/location_bar/brave_location_bar_view.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/location_bar/brave_location_bar_view.h"

#include "brave/browser/themes/brave_theme_service.h"
#include "brave/browser/ui/views/location_bar/brave_location_icon_view.h"
#include "chrome/browser/profiles/profile.h"
#include "brave/browser/ui/views/brave_actions/brave_actions_container.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/location_bar/star_view.h"
#include "components/version_info/channel.h"
Expand All @@ -19,6 +22,8 @@ void BraveLocationBarView::Init() {
tint_ = GetTint();
// base method calls Update and Layout
LocationBarView::Init();
ReplaceLocationIconView();

// brave action buttons
brave_actions_ = new BraveActionsContainer(browser_, profile());
brave_actions_->Init();
Expand All @@ -27,6 +32,17 @@ void BraveLocationBarView::Init() {
Update(nullptr);
}

void BraveLocationBarView::ReplaceLocationIconView() {
DCHECK(location_icon_view_);

delete location_icon_view_;
const gfx::FontList& font_list = views::style::GetFont(
CONTEXT_OMNIBOX_PRIMARY, views::style::STYLE_PRIMARY);
location_icon_view_ = new BraveLocationIconView(font_list, this);
location_icon_view_->set_drag_controller(this);
AddChildView(location_icon_view_);
}

void BraveLocationBarView::Layout() {
LocationBarView::Layout(brave_actions_ ? brave_actions_ : nullptr);
}
Expand Down Expand Up @@ -60,7 +76,7 @@ void BraveLocationBarView::OnChanged() {

gfx::Size BraveLocationBarView::CalculatePreferredSize() const {
gfx::Size min_size = LocationBarView::CalculatePreferredSize();
if (brave_actions_ && brave_actions_->visible()){
if (brave_actions_ && brave_actions_->visible()) {
const int brave_actions_min = brave_actions_->GetMinimumSize().width();
const int extra_width = brave_actions_min +
GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING);
Expand All @@ -75,9 +91,10 @@ OmniboxTint BraveLocationBarView::GetTint() {
// a theme extension.
if (profile()->GetProfileType() == Profile::INCOGNITO_PROFILE ||
profile()->IsTorProfile()) {
return OmniboxTint::PRIVATE; // special extra enum value
return OmniboxTint::PRIVATE; // special extra enum value
}
// TODO: BraveThemeService can have a simpler get dark / light function
// TODO(simonhong): BraveThemeService can have a simpler get dark / light
// function
switch (BraveThemeService::GetActiveBraveThemeType(profile())) {
case BraveThemeType::BRAVE_THEME_TYPE_LIGHT:
return OmniboxTint::LIGHT;
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/views/location_bar/brave_location_bar_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class BraveLocationBarView : public LocationBarView {
OmniboxTint GetTint() override;
BraveActionsContainer* brave_actions_ = nullptr;

void ReplaceLocationIconView();

DISALLOW_COPY_AND_ASSIGN(BraveLocationBarView);
};

Expand Down
30 changes: 30 additions & 0 deletions browser/ui/views/location_bar/brave_location_icon_view.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/location_bar/brave_location_icon_view.h"

#include "chrome/grit/chromium_strings.h"
#include "content/public/common/url_constants.h"
#include "ui/base/l10n/l10n_util.h"

bool BraveLocationIconView::ShouldShowText() const {
const auto* location_bar_model = delegate_->GetLocationBarModel();
if (!location_bar_model->input_in_progress()) {
const GURL& url = location_bar_model->GetURL();
if (url.SchemeIs(content::kBraveUIScheme))
return true;
}

return LocationIconView::ShouldShowText();
}

base::string16 BraveLocationIconView::GetText() const {
if (delegate_->GetLocationBarModel()->GetURL().SchemeIs(
content::kBraveUIScheme)) {
return l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
}

return LocationIconView::GetText();
}
24 changes: 24 additions & 0 deletions browser/ui/views/location_bar/brave_location_icon_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_VIEWS_LOCATION_BAR_BRAVE_LOCATION_ICON_VIEW_H_
#define BRAVE_BROWSER_UI_VIEWS_LOCATION_BAR_BRAVE_LOCATION_ICON_VIEW_H_

#include "chrome/browser/ui/views/location_bar/location_icon_view.h"

class BraveLocationIconView : public LocationIconView {
public:
using LocationIconView::LocationIconView;
~BraveLocationIconView() override = default;

private:
// LocationIconView overrides:
base::string16 GetText() const override;
bool ShouldShowText() const override;

DISALLOW_COPY_AND_ASSIGN(BraveLocationIconView);
};

#endif // BRAVE_BROWSER_UI_VIEWS_LOCATION_BAR_BRAVE_LOCATION_ICON_VIEW_H_
77 changes: 77 additions & 0 deletions browser/ui/views/location_bar/brave_location_icon_view_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/location_bar/brave_location_icon_view.h"

#include <memory>

#include "chrome/grit/chromium_strings.h"
#include "chrome/test/views/chrome_views_test_base.h"
#include "components/omnibox/browser/test_location_bar_model.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"

class TestLocationIconViewDelegate : public LocationIconView::Delegate {
public:
explicit TestLocationIconViewDelegate(LocationBarModel* location_bar_model)
: location_bar_model_(location_bar_model) {}

// LocationIconView::Delegate overrides:
content::WebContents* GetWebContents() override { return nullptr; }
bool IsEditingOrEmpty() override { return false; }
SkColor GetSecurityChipColor(
security_state::SecurityLevel security_level) const override {
return SK_ColorWHITE;
}
bool ShowPageInfoDialog() override { return false; }
const LocationBarModel* GetLocationBarModel() const override {
return location_bar_model_;
}
gfx::ImageSkia GetLocationIcon(
IconFetchedCallback on_icon_fetched) const override {
return gfx::ImageSkia();
}
SkColor GetLocationIconInkDropColor() const override {
return SK_ColorWHITE;
}

private:
LocationBarModel* location_bar_model_ = nullptr;
};

class BraveLocationIconViewTest : public ChromeViewsTestBase {
protected:
// ChromeViewsTestBase overrides:
void SetUp() override {
ChromeViewsTestBase::SetUp();

gfx::FontList font_list;
location_bar_model_ = std::make_unique<TestLocationBarModel>();
delegate_ =
std::make_unique<TestLocationIconViewDelegate>(location_bar_model());
view_ = new BraveLocationIconView(font_list, delegate());
}

TestLocationBarModel* location_bar_model() {
return location_bar_model_.get();
}
TestLocationIconViewDelegate* delegate() { return delegate_.get(); }
LocationIconView* view() { return view_; }

private:
std::unique_ptr<TestLocationBarModel> location_bar_model_;
std::unique_ptr<TestLocationIconViewDelegate> delegate_;
LocationIconView* view_;
};

// Check LocationIconView shows proper icon and text for brave url.
TEST_F(BraveLocationIconViewTest, BraveURLTest) {
location_bar_model()->set_url(GURL("brave://sync/"));
location_bar_model()->set_input_in_progress(false);

EXPECT_TRUE(view()->ShouldShowText());
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME),
view()->GetText());
}
3 changes: 3 additions & 0 deletions chromium_src/chrome/browser/ui/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
#include "brave/browser/ui/brave_browser_content_setting_bubble_model_delegate.h"
#include "brave/browser/ui/brave_browser_command_controller.h"
#include "brave/browser/ui/brave_browser_location_bar_model_delegate.h"

#define BrowserContentSettingBubbleModelDelegate \
BraveBrowserContentSettingBubbleModelDelegate
#define BrowserCommandController BraveBrowserCommandController
#define BrowserLocationBarModelDelegate BraveBrowserLocationBarModelDelegate
#include "../../../../../chrome/browser/ui/browser.cc" // NOLINT
#undef BrowserContentSettingBubbleModelDelegate
#undef BrowserCommandController
#undef BrowserLocationBarModelDelegate
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "chrome/browser/ui/views/page_info/page_info_bubble_view.h"

#include "chrome/test/views/chrome_views_test_base.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/widget/widget.h"

class PageInfoBubbleViewTest : public ChromeViewsTestBase {
protected:
// ChromeViewsTestBase overrides:
void SetUp() override {
ChromeViewsTestBase::SetUp();
CreateWidget();
}

void TearDown() override {
if (widget_ && !widget_->IsClosed())
widget_->Close();

ChromeViewsTestBase::TearDown();
}

views::Widget* widget() const {
return widget_;
}

private:
void CreateWidget() {
DCHECK(!widget_);

widget_ = new views::Widget;
views::Widget::InitParams params =
CreateParams(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
widget_->Init(params);
}

private:
views::Widget* widget_ = nullptr;
};

// Check InternalPageInfoBubbleView is used for brave url.
TEST_F(PageInfoBubbleViewTest, BraveURLTest) {
PageInfoBubbleView::CreatePageInfoBubble(
nullptr, gfx::Rect(), widget()->GetNativeWindow(),
nullptr, nullptr, GURL("brave://sync/"), security_state::SecurityInfo());
EXPECT_EQ(PageInfoBubbleViewBase::BUBBLE_INTERNAL_PAGE,
PageInfoBubbleViewBase::GetShownBubbleType());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h b/chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h
index 26d74e9c5d80d2c699df1a6ee16f4ed494d563dd..d3bc3bd42e610d4395746ce314a49d848f7d5975 100644
--- a/chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h
+++ b/chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h
@@ -37,6 +37,7 @@ class ChromeLocationBarModelDelegate : public LocationBarModelDelegate {
content::NavigationEntry* GetNavigationEntry() const;

private:
+ friend class BraveBrowserLocationBarModelDelegate;
base::string16 FormattedStringWithEquivalentMeaning(
const GURL& url,
const base::string16& formatted_url) const override;
Loading