Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed Aug 31, 2021
1 parent e75d0f9 commit a79c514
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,82 @@
* 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 "brave/common/webui_url_constants.h"
#include "brave/components/vector_icons/vector_icons.h"
#include "brave/components/ipfs/ipfs_constants.h"
#include "brave/components/ipfs/ipfs_utils.h"
#include "brave/components/vector_icons/vector_icons.h"
#include "brave/grit/brave_theme_resources.h"
#include "chrome/browser/ui/views/page_info/page_info_bubble_view.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/views/page_info/page_info_view_factory.h"
#include "components/grit/brave_components_strings.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_finder.h"
#include "ui/base/l10n/l10n_util.h"

namespace {

const char kIPFSDocsURL[] = "https://docs.ipfs.io/";

std::unique_ptr<PageInfoHoverButton> CreateButton(int logo_resource_id,
int text_resource_id, int tooltip_resource_ud,
std::unique_ptr<PageInfoHoverButton> CreateButton(
int logo_resource_id,
int text_resource_id,
int tooltip_resource_id,
views::Button::PressedCallback callback) {
auto& bundle = ui::ResourceBundle::GetSharedInstance();
const auto& ipfs_logo = *bundle.GetImageSkiaNamed(logo_resource_id);
const std::u16string& tooltip =
l10n_util::GetStringUTF16(tooltip_resource_ud);
l10n_util::GetStringUTF16(tooltip_resource_id);

return std::make_unique<PageInfoHoverButton>(std::move(callback),
ui::ImageModel::FromImageSkia(ipfs_logo),
return std::make_unique<PageInfoHoverButton>(
std::move(callback), ui::ImageModel::FromImageSkia(ipfs_logo),
text_resource_id, std::u16string(),
PageInfoViewFactory::VIEW_ID_PAGE_INFO_LINK_OR_BUTTON_COOKIE_DIALOG,
tooltip, std::u16string());
}

} // namespace

#define InitializeUiState InitializeUiState(this); \
if (ipfs::IsIPFSScheme(url)) BraveAddIPFSButtons
// clang-format off
#define InitializeUiState InitializeUiState(this); if (ipfs::IsIPFSScheme(url)) BraveAddIPFSButtons // NOLINT
// clang-format on

#include "../../../../../../../chrome/browser/ui/views/page_info/page_info_bubble_view.cc"
#undef InitializeUiState

void PageInfoBubbleView::BraveAddIPFSButtons(PageInfoBubbleView* ui) {
site_settings_view_->AddChildViewAt(CreateButton(
IDR_BRAVE_IPFS_LOGO,
IDS_PAGE_INFO_IPFS_SETTINGS_BUTTON_TEXT,
IDS_PAGE_INFO_IPFS_SETTINGS_BUTTON_TOOLTIP_TEXT,
base::BindRepeating(
[](Profile* profile) {
chrome::AddTabAt(chrome::FindLastActiveWithProfile(profile),
GURL(ipfs::kIPFSSettingsURL), -1, true);
},
profile_)), 0);
site_settings_view_->AddChildViewAt(CreateButton(
IDR_BRAVE_IPFS_LOGO,
IDS_PAGE_INFO_IPFS_DIAGNOSTICS_BUTTON_TEXT,
IDS_PAGE_INFO_IPFS_DIAGNOSTICS_BUTTON_TOOLTIP_TEXT,
base::BindRepeating(
[](Profile* profile) {
chrome::AddTabAt(chrome::FindLastActiveWithProfile(profile),
GURL(kIPFSWebUIURL), -1, true);
},
profile_)), 0);
site_settings_view_->AddChildViewAt(CreateButton(
IDR_BRAVE_IPFS_LOGO,
IDS_PAGE_INFO_IPFS_DOCS_BUTTON_TEXT,
IDS_PAGE_INFO_IPFS_DOCS_BUTTON_TEXT_TOOLTIP_TEXT,
base::BindRepeating(
[](Profile* profile) {
chrome::AddTabAt(chrome::FindLastActiveWithProfile(profile),
GURL(kIPFSDocsURL), -1, true);
},
profile_)), 0);
site_settings_view_->AddChildViewAt(
CreateButton(IDR_BRAVE_IPFS_LOGO, IDS_PAGE_INFO_IPFS_SETTINGS_BUTTON_TEXT,
IDS_PAGE_INFO_IPFS_SETTINGS_BUTTON_TOOLTIP_TEXT,
base::BindRepeating(
[](Profile* profile) {
chrome::AddTabAt(
chrome::FindLastActiveWithProfile(profile),
GURL(ipfs::kIPFSSettingsURL), -1, true);
},
profile_)),
0);
site_settings_view_->AddChildViewAt(
CreateButton(
IDR_BRAVE_IPFS_LOGO, IDS_PAGE_INFO_IPFS_DIAGNOSTICS_BUTTON_TEXT,
IDS_PAGE_INFO_IPFS_DIAGNOSTICS_BUTTON_TOOLTIP_TEXT,
base::BindRepeating(
[](Profile* profile) {
chrome::AddTabAt(chrome::FindLastActiveWithProfile(profile),
GURL(kIPFSWebUIURL), -1, true);
},
profile_)),
0);
site_settings_view_->AddChildViewAt(
CreateButton(IDR_BRAVE_IPFS_LOGO, IDS_PAGE_INFO_IPFS_DOCS_BUTTON_TEXT,
IDS_PAGE_INFO_IPFS_DOCS_BUTTON_TEXT_TOOLTIP_TEXT,
base::BindRepeating(
[](Profile* profile) {
chrome::AddTabAt(
chrome::FindLastActiveWithProfile(profile),
GURL(kIPFSDocsURL), -1, true);
},
profile_)),
0);

Layout();
SizeToContents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

class PageInfoBubbleView;

#define HandleMoreInfoRequest BraveAddIPFSButtons(PageInfoBubbleView* ui); \
void HandleMoreInfoRequest
#define HandleMoreInfoRequest \
BraveAddIPFSButtons(PageInfoBubbleView* ui); \
void HandleMoreInfoRequest

#include "../../../../../../../chrome/browser/ui/views/page_info/page_info_bubble_view.h"
#undef HandleMoreInfoRequest
Expand Down
12 changes: 6 additions & 6 deletions components/resources/ipfs_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,22 @@
InterPlanetary File System (IPFS) is a public network for peer-to-peer data storage and delivery. You can learn more about Brave's integration or configure your IPFS settings at any time.
</message>
<message name="IDS_PAGE_INFO_IPFS_SETTINGS_BUTTON_TEXT" desc="The text for ips page info bubble IPFS Settings button.">
IPFS Settings
IPFS settings
</message>
<message name="IDS_PAGE_INFO_IPFS_SETTINGS_BUTTON_TOOLTIP_TEXT" desc="The text for ips page info bubble IPFS Settings button tooltip text.">
Go to IPFS Settings page
Go to the IPFS settings page
</message>
<message name="IDS_PAGE_INFO_IPFS_DIAGNOSTICS_BUTTON_TEXT" desc="The text for ips page info bubble ipfs diagnostic button text.">
IPFS Diagnostics
IPFS diagnostics
</message>
<message name="IDS_PAGE_INFO_IPFS_DIAGNOSTICS_BUTTON_TOOLTIP_TEXT" desc="The text for ips page info bubble diagnostic button tooltip text.">
Go to IPFS Diagnostics page
Go to the IPFS diagnostics page
</message>
<message name="IDS_PAGE_INFO_IPFS_DOCS_BUTTON_TEXT" desc="The text for ips page info bubble ipfs diagnostic button text.">
IPFS Docs
IPFS docs
</message>
<message name="IDS_PAGE_INFO_IPFS_DOCS_BUTTON_TEXT_TOOLTIP_TEXT" desc="The text for ips page info bubble docs button tooltip text.">
Go to IPFS Docs page
Go to the IPFS docs page
</message>
<message name="IDS_IPFS_IMPORT_NOTIFICATION_TITLE" desc="The title for ips import error notification.">
IPFS import completed
Expand Down

0 comments on commit a79c514

Please sign in to comment.