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

Add custom badge to ipfs pages #8234

Merged
merged 1 commit into from
Mar 18, 2021
Merged
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
6 changes: 5 additions & 1 deletion app/theme/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
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")

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",
Expand Down
3 changes: 3 additions & 0 deletions app/theme/brave_theme_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<structure type="chrome_scaled_image" name="IDR_SIDEBAR_ITEM_ADD_FOCUSED" file="brave/sidebar_item_add_focused.png" />
<structure type="chrome_scaled_image" name="IDR_SIDEBAR_SETTINGS_FOCUSED" file="brave/sidebar_settings_focused.png" />
</if>
<if expr="ipfs_enabled">
<structure type="chrome_scaled_image" name="IDR_BRAVE_IPFS_LOGO" file="brave/ipfs_logo.png" />
</if>

<if expr="not is_android">
<structure type="chrome_scaled_image" name="IDR_TOR_WINDOW_FRAME_GRAPHIC" file="brave/tor_window_frame_graphic.png" />
Expand Down
Binary file added app/theme/default_100_percent/brave/ipfs_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/theme/default_200_percent/brave/ipfs_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions browser/ui/views/location_bar/brave_location_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,31 @@
#include "brave/browser/ui/views/location_bar/brave_location_bar_view.h"

#include <memory>
#include <utility>

#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)
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down
4 changes: 4 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 @@ -44,6 +44,9 @@ class BraveLocationBarView : public LocationBarView {
// LocationBarView:
std::vector<views::View*> GetTrailingViews() override;

ui::ImageModel GetLocationIcon(LocationIconView::Delegate::IconFetchedCallback
on_icon_fetched) const override;

// views::View:
gfx::Size CalculatePreferredSize() const override;
void OnThemeChanged() override;
Expand All @@ -53,6 +56,7 @@ class BraveLocationBarView : public LocationBarView {

SkPath GetFocusRingHighlightPath() const;
ContentSettingImageView* GetContentSettingsImageViewForTesting(size_t idx);
bool ShouldShowIPFSLocationView() const;

private:
friend class ::BraveActionsContainerTest;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions components/resources/ipfs_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<message name="IDS_IPFS_GC_ERROR" desc="Text of garbage collection error">Garbage collection error</message>
<message name="IDS_UTILITY_PROCESS_IPFS_NAME" desc="The utility process which manages IPFS daemon">IPFS Service</message>
<message name="IDS_IPFS_OPEN_WEBUI" desc="Title of brave://ipfs webui button">My Node</message>
<message name="IDS_IPFS_BADGE_TITLE" desc="Title of page info badge in location bar">IPFS</message>
<message name="IDS_IPFS_PEERS_DETAILS_LINK" desc="Link to open details about peers on brave://ipfs.">
(details)
</message>
Expand Down
Original file line number Diff line number Diff line change
@@ -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)) {