From f6b3e1f5f205a1b40a74a4efd11b45ba24bce94e Mon Sep 17 00:00:00 2001 From: "spylogsster@gmail.com" Date: Fri, 12 Mar 2021 12:49:36 +0300 Subject: [PATCH] Customized identificator for ipfs pages --- app/theme/BUILD.gn | 6 ++- app/theme/brave_theme_resources.grd | 3 ++ .../default_100_percent/brave/ipfs_logo.png | Bin 0 -> 428 bytes .../default_200_percent/brave/ipfs_logo.png | Bin 0 -> 610 bytes .../location_bar/brave_location_bar_view.cc | 42 ++++++++++++++++++ .../location_bar/brave_location_bar_view.h | 4 ++ .../views/location_bar/location_icon_view.cc | 12 +++++ components/resources/ipfs_strings.grdp | 1 + ...s-location_bar-location_icon_view.cc.patch | 12 +++++ 9 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 app/theme/default_100_percent/brave/ipfs_logo.png create mode 100644 app/theme/default_200_percent/brave/ipfs_logo.png create mode 100644 chromium_src/chrome/browser/ui/views/location_bar/location_icon_view.cc create mode 100644 patches/chrome-browser-ui-views-location_bar-location_icon_view.cc.patch diff --git a/app/theme/BUILD.gn b/app/theme/BUILD.gn index eae7432ed0ca..c9d4109b0428 100644 --- a/app/theme/BUILD.gn +++ b/app/theme/BUILD.gn @@ -1,3 +1,4 @@ +import("//brave/components/ipfs/buildflags/buildflags.gni") import("//brave/components/sidebar/buildflags/buildflags.gni") import("//chrome/common/features.gni") import("//tools/grit/grit_rule.gni") @@ -5,7 +6,10 @@ import("//tools/grit/grit_rule.gni") grit("brave_theme_resources") { source = "brave_theme_resources.grd" defines = chrome_grit_defines - defines += [ "enable_sidebar=$enable_sidebar" ] + defines += [ + "enable_sidebar=$enable_sidebar", + "ipfs_enabled=$ipfs_enabled", + ] outputs = [ "grit/brave_theme_resources.h", "grit/brave_theme_resources_map.cc", diff --git a/app/theme/brave_theme_resources.grd b/app/theme/brave_theme_resources.grd index 78da66d1e0b0..8bdfe3064efd 100644 --- a/app/theme/brave_theme_resources.grd +++ b/app/theme/brave_theme_resources.grd @@ -31,6 +31,9 @@ + + + diff --git a/app/theme/default_100_percent/brave/ipfs_logo.png b/app/theme/default_100_percent/brave/ipfs_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..33f31e1dce1234e182dff1da4a9d5691c00c8d86 GIT binary patch literal 428 zcmV;d0aN~oP)}pqd}XWK9`(1k(fW2 zo>#WKTe`nMnVw6dtVExqMxmudpQAdGnLn7FI+2(0yTMAMt7ys4OsB3!pr=l!uvf9WShT%8l$uDRsfwcwh5!Hn zAaqhrQve;^veW|n4Hv^eyyVPzH()i;`Tkh>yoYJcthRwi{-xjfQ~&?~qDe$SRCr!Z z&({)yFc3h|0ES)_drK{J^#4Cj6N=u)Gdr`pzy!milR>a%o#L{LQ)>qAY*&pCO_}7L zo_+*7B}{7PgaG(kCdC|Okq7)u+YvK@N&5^mj6?k%DIFP+asq@%$9Y>}yaIAxyi)&w zIv3*w1`Rb)U!WQ;{SU}@EexZ>FadR)%$%NY`>`hSne4sgxx3Aoo%&!67Po6Lz5fA? WeHF$Uawv`f0000QaZPH<9EQiK6HksI%**6KtigCQcZO@5I2eX5 zho;IbT35r94nI}=pnkugH`NBMQ6S>q1uhVdySZhE(zoUhPzYF*&vA(Xy +#include +#include "brave/app/vector_icons/vector_icons.h" #include "brave/browser/profiles/profile_util.h" #include "brave/browser/themes/brave_theme_service.h" #include "brave/browser/ui/views/brave_actions/brave_actions_container.h" #include "brave/browser/ui/views/toolbar/brave_toolbar_view.h" +#include "brave/components/ipfs/ipfs_constants.h" +#include "brave/components/ipfs/ipfs_utils.h" +#include "brave/grit/brave_theme_resources.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/ui/layout_constants.h" #include "chrome/browser/ui/omnibox/omnibox_theme.h" #include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h" +#include "chrome/browser/ui/views/page_info/page_info_bubble_view.h" +#include "chrome/grit/chromium_strings.h" +#include "components/grit/brave_components_strings.h" +#include "components/omnibox/browser/omnibox_edit_model.h" #include "components/version_info/channel.h" +#include "content/public/browser/navigation_entry.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/gfx/paint_vector_icon.h" #include "ui/views/controls/highlight_path_generator.h" #if BUILDFLAG(ENABLE_TOR) @@ -92,6 +105,15 @@ void BraveLocationBarView::Init() { content_setting_view->disable_animation(); } +bool BraveLocationBarView::ShouldShowIPFSLocationView() const { + const GURL& url = GetLocationBarModel()->GetURL(); + if (!ipfs::IsIPFSScheme(url) || !ipfs::IsIpfsEnabled(profile_) || + !ipfs::IsLocalGatewayConfigured(profile_)) + return false; + + return true; +} + void BraveLocationBarView::Update(content::WebContents* contents) { // base Init calls update before our Init is run, so our children // may not be initialized yet @@ -108,6 +130,26 @@ void BraveLocationBarView::Update(content::WebContents* contents) { #endif LocationBarView::Update(contents); + + if (!ShouldShowIPFSLocationView()) + return; + // Secure display text for a page was set by chromium. + // We do not want to override this. + if (!GetLocationBarModel()->GetSecureDisplayText().empty()) + return; + auto badge_text = l10n_util::GetStringUTF16(IDS_IPFS_BADGE_TITLE); + location_icon_view()->SetLabel(badge_text); +} + +ui::ImageModel BraveLocationBarView::GetLocationIcon( + LocationIconView::Delegate::IconFetchedCallback on_icon_fetched) const { + if (!ShouldShowIPFSLocationView() || + !omnibox_view_->model()->ShouldShowCurrentPageIcon()) + return LocationBarView::GetLocationIcon(std::move(on_icon_fetched)); + + auto& bundle = ui::ResourceBundle::GetSharedInstance(); + const auto& ipfs_logo = *bundle.GetImageSkiaNamed(IDR_BRAVE_IPFS_LOGO); + return ui::ImageModel::FromImageSkia(ipfs_logo); } void BraveLocationBarView::OnChanged() { diff --git a/browser/ui/views/location_bar/brave_location_bar_view.h b/browser/ui/views/location_bar/brave_location_bar_view.h index 4eb3e6bcf11d..239984834d0d 100644 --- a/browser/ui/views/location_bar/brave_location_bar_view.h +++ b/browser/ui/views/location_bar/brave_location_bar_view.h @@ -44,6 +44,9 @@ class BraveLocationBarView : public LocationBarView { // LocationBarView: std::vector GetTrailingViews() override; + ui::ImageModel GetLocationIcon(LocationIconView::Delegate::IconFetchedCallback + on_icon_fetched) const override; + // views::View: gfx::Size CalculatePreferredSize() const override; void OnThemeChanged() override; @@ -53,6 +56,7 @@ class BraveLocationBarView : public LocationBarView { SkPath GetFocusRingHighlightPath() const; ContentSettingImageView* GetContentSettingsImageViewForTesting(size_t idx); + bool ShouldShowIPFSLocationView() const; private: friend class ::BraveActionsContainerTest; diff --git a/chromium_src/chrome/browser/ui/views/location_bar/location_icon_view.cc b/chromium_src/chrome/browser/ui/views/location_bar/location_icon_view.cc new file mode 100644 index 000000000000..d951daea62fe --- /dev/null +++ b/chromium_src/chrome/browser/ui/views/location_bar/location_icon_view.cc @@ -0,0 +1,12 @@ +/* Copyright (c) 2021 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/components/ipfs/ipfs_constants.h" + +#define BRAVE_SHOULD_SHOW_URL_IPFS_CHECK \ + url.SchemeIs(ipfs::kIPFSScheme) || url.SchemeIs(ipfs::kIPNSScheme) || + +#include "../../../../../../../chrome/browser/ui/views/location_bar/location_icon_view.cc" +#undef BRAVE_SHOULD_SHOW_URL_IPFS_CHECK diff --git a/components/resources/ipfs_strings.grdp b/components/resources/ipfs_strings.grdp index 410d5e942f76..396dcdf8a855 100644 --- a/components/resources/ipfs_strings.grdp +++ b/components/resources/ipfs_strings.grdp @@ -29,6 +29,7 @@ Garbage collection error IPFS Service My Node + IPFS (details) diff --git a/patches/chrome-browser-ui-views-location_bar-location_icon_view.cc.patch b/patches/chrome-browser-ui-views-location_bar-location_icon_view.cc.patch new file mode 100644 index 000000000000..9643eb495485 --- /dev/null +++ b/patches/chrome-browser-ui-views-location_bar-location_icon_view.cc.patch @@ -0,0 +1,12 @@ +diff --git a/chrome/browser/ui/views/location_bar/location_icon_view.cc b/chrome/browser/ui/views/location_bar/location_icon_view.cc +index de836abcf94a550687d47894ecf19c6df1428b32..665df7d24b95bc7d9bfc19044c953c2bb954a745 100644 +--- a/chrome/browser/ui/views/location_bar/location_icon_view.cc ++++ b/chrome/browser/ui/views/location_bar/location_icon_view.cc +@@ -134,6 +134,7 @@ bool LocationIconView::ShouldShowText() const { + const auto* location_bar_model = delegate_->GetLocationBarModel(); + const GURL& url = location_bar_model->GetURL(); + if (url.SchemeIs(content::kChromeUIScheme) || ++ BRAVE_SHOULD_SHOW_URL_IPFS_CHECK + url.SchemeIs(extensions::kExtensionScheme) || + url.SchemeIs(url::kFileScheme) || + url.SchemeIs(dom_distiller::kDomDistillerScheme)) {