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 2 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_
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_
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,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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/chrome/browser/ui/views/location_bar/location_icon_view.h b/chrome/browser/ui/views/location_bar/location_icon_view.h
index c5a8d05e0598f7e067f32d905f2bb060eca9e51f..af34e908d1c36e93e6b648ddfbee76811f872f92 100644
--- a/chrome/browser/ui/views/location_bar/location_icon_view.h
+++ b/chrome/browser/ui/views/location_bar/location_icon_view.h
@@ -92,13 +92,13 @@ class LocationIconView : public IconLabelBubbleView {
// - For extension URLs, returns the extension name.
// - For chrome:// URLs, returns the short product name (e.g. Chrome).
// - For file:// URLs, returns the text "File".
- base::string16 GetText() const;
+ virtual base::string16 GetText() const;

// Determines whether or not text should be shown (e.g Insecure/Secure).
// Returns true if any of the following is true:
// - the current page is explicitly secure or insecure.
// - the current page URL is a chrome-extension:// URL.
- bool ShouldShowText() const;
+ virtual bool ShouldShowText() const;

const views::InkDrop* get_ink_drop_for_testing();

@@ -108,6 +108,7 @@ class LocationIconView : public IconLabelBubbleView {
double WidthMultiplier() const override;

private:
+ friend class BraveLocationIconView;
// The security level when the location icon was last updated. Used to decide
// whether to animate security level transitions.
security_state::SecurityLevel last_update_security_level_ =
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/chrome/browser/ui/views/page_info/page_info_bubble_view.cc b/chrome/browser/ui/views/page_info/page_info_bubble_view.cc
index ebe5987d5b4239e09a9b255b0d73ec9f7ad74fe9..933b15b53b86376e63a425701ae8cb8571d8b692 100644
--- a/chrome/browser/ui/views/page_info/page_info_bubble_view.cc
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't avoid this patch file because multiple PageInfoBubbleView::CreatePageInfoBubble() is used in this file and InternalPageInfoBubbleView class is in anonymous namespace.

+++ b/chrome/browser/ui/views/page_info/page_info_bubble_view.cc
@@ -386,6 +386,9 @@ InternalPageInfoBubbleView::InternalPageInfoBubbleView(
} else if (url.SchemeIs(url::kFileScheme)) {
text = IDS_PAGE_INFO_FILE_PAGE;
} else if (!url.SchemeIs(content::kChromeUIScheme) &&
+#if defined(BRAVE_CHROMIUM_BUILD)
+ !url.SchemeIs(content::kBraveUIScheme) &&
+#endif
!url.SchemeIs(content::kChromeDevToolsScheme)) {
NOTREACHED();
}
@@ -430,6 +433,9 @@ views::BubbleDialogDelegateView* PageInfoBubbleView::CreatePageInfoBubble(
gfx::NativeView parent_view = platform_util::GetViewForWindow(parent_window);

if (url.SchemeIs(content::kChromeUIScheme) ||
+#if defined(BRAVE_CHROMIUM_BUILD)
+ url.SchemeIs(content::kBraveUIScheme) ||
+#endif
url.SchemeIs(content::kChromeDevToolsScheme) ||
url.SchemeIs(extensions::kExtensionScheme) ||
url.SchemeIs(content::kViewSourceScheme) ||