Skip to content

Commit

Permalink
Disable ipfs-internals webui page on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyBarabash committed Apr 13, 2023
1 parent ab92b35 commit 94c3d2a
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 57 deletions.
4 changes: 4 additions & 0 deletions browser/ipfs/content_browser_client_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ bool HandleIPFSURLRewrite(GURL* url, content::BrowserContext* browser_context) {
base::EndsWith(url->host_piece(), kIpnsLocalhost))) {
return true;
}
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
if (url->SchemeIs(content::kChromeUIScheme) && url->DomainIs(kIPFSScheme)) {
GURL::Replacements host_replacements;
host_replacements.SetHostStr(kIPFSWebUIHost);
*url = url->ReplaceComponents(host_replacements);
return true;
}
#endif
PrefService* prefs = user_prefs::UserPrefs::Get(browser_context);
if (!IsIpfsResolveMethodDisabled(prefs) &&
// When it's not the local gateway we don't want to show a ipfs:// URL.
Expand Down Expand Up @@ -105,10 +107,12 @@ bool HandleIPFSURLRewrite(GURL* url, content::BrowserContext* browser_context) {

bool HandleIPFSURLReverseRewrite(GURL* url,
content::BrowserContext* browser_context) {
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
if (url->SchemeIs(content::kChromeUIScheme) &&
url->DomainIs(kIPFSWebUIHost)) {
return true;
}
#endif

std::size_t ipfs_pos = url->host_piece().find(kIpfsLocalhost);
std::size_t ipns_pos = url->host_piece().find(kIpnsLocalhost);
Expand Down
2 changes: 2 additions & 0 deletions browser/ipfs/import/ipfs_import_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,12 @@ void IpfsImportController::OnWebPageImportCompleted(

void IpfsImportController::OnImportCompleted(const ipfs::ImportedData& data) {
auto link = CreateAndCopyShareableLink(data);
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
if (!link.is_valid()) {
// Open node diagnostic page if import failed
link = GURL(kIPFSWebUIURL);
}
#endif
PushNotification(GetImportNotificationTitle(data.state),
GetImportNotificationBody(data.state, link), link);
if (data.state == ipfs::IPFS_IMPORT_SUCCESS) {
Expand Down
7 changes: 5 additions & 2 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ source_set("ui") {
]
}

if (enable_ipfs) {
if (enable_ipfs_internals_webui) {
sources += [
"webui/ipfs_ui.cc",
"webui/ipfs_ui.h",
Expand Down Expand Up @@ -586,9 +586,12 @@ source_set("ui") {
if (enable_ipfs) {
deps += [
"//brave/components/ipfs",
"//brave/components/ipfs_ui:generated_resources",
"//components/component_updater",
]

if (enable_ipfs_internals_webui) {
deps += [ "//brave/components/ipfs_ui:generated_resources" ]
}
}

if (enable_speedreader && !is_android) {
Expand Down
12 changes: 7 additions & 5 deletions browser/ui/webui/brave_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@

#if BUILDFLAG(ENABLE_IPFS)
#include "brave/browser/ipfs/ipfs_service_factory.h"
#include "brave/browser/ui/webui/ipfs_ui.h"
#include "brave/components/ipfs/features.h"
#include "brave/components/ipfs/ipfs_utils.h"
#endif
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
#include "brave/browser/ui/webui/ipfs_ui.h"
#endif // BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
#endif // BUILDFLAG(ENABLE_IPFS)

#if BUILDFLAG(ENABLE_PLAYLIST_WEBUI)
#include "brave/browser/ui/webui/playlist_ui.h"
Expand Down Expand Up @@ -95,7 +97,7 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) {
return new BraveAdblockInternalsUI(web_ui, url.host());
} else if (host == kWebcompatReporterHost) {
return new WebcompatReporterUI(web_ui, url.host());
#if BUILDFLAG(ENABLE_IPFS)
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
} else if (host == kIPFSWebUIHost &&
ipfs::IpfsServiceFactory::IsIpfsEnabled(profile)) {
return new IPFSUI(web_ui, url.host());
Expand Down Expand Up @@ -191,10 +193,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, const GURL& url) {
if (url.host_piece() == kAdblockHost ||
url.host_piece() == kAdblockInternalsHost ||
url.host_piece() == kWebcompatReporterHost ||
#if BUILDFLAG(ENABLE_IPFS)
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
(url.host_piece() == kIPFSWebUIHost &&
base::FeatureList::IsEnabled(ipfs::features::kIpfsFeature)) ||
#endif // BUILDFLAG(ENABLE_IPFS)
#endif // BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
#if !BUILDFLAG(IS_ANDROID)
url.host_piece() == kWalletPanelHost ||
url.host_piece() == kWalletPageHost ||
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ void CustomizeWebUIHTMLSource(content::WebUI* web_ui,
{ "customListSubscriptionsUnsubscribe", IDS_ADBLOCK_CUSTOM_LIST_SUBSCRIPTIONS_UNSUBSCRIBE }, // NOLINT
}
}, {
#if BUILDFLAG(ENABLE_IPFS)
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
std::string("ipfs-internals"), {
{ "connectedPeersTitle", IDS_IPFS_CONNECTED_PEERS_TITLE },
{ "addressesConfigTitle", IDS_IPFS_ADDRESSES_CONFIG_TITLE },
Expand Down
1 change: 1 addition & 0 deletions chromium_src/chrome/common/DEPS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include_rules = [
"+brave/common",
"+brave/components/constants",
"+brave/components/ipfs/buildflags",
"+brave/grit",
"+components/version_info",
"+components/component_updater",
Expand Down
17 changes: 13 additions & 4 deletions chromium_src/chrome/common/webui_url_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/constants/webui_url_constants.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "chrome/common/webui_url_constants.h"

#define kChromeUIAttributionInternalsHost \
kChromeUIAttributionInternalsHost, kAdblockHost, kAdblockInternalsHost, \
kIPFSWebUIHost, kRewardsPageHost, kRewardsInternalsHost, kWelcomeHost, \
kWalletPageHost, kTorInternalsHost
#define kChromeUIAttributionInternalsHost \
kChromeUIAttributionInternalsHost, kAdblockHost, kAdblockInternalsHost, \
kRewardsPageHost, kRewardsInternalsHost, kWelcomeHost, kWalletPageHost, \
kTorInternalsHost
#define kChromeUIPerformanceSettingsURL kChromeUIPerformanceSettingsURL_UnUsed
#define kPerformanceSubPage kPerformanceSubPage_UnUsed

#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
#define kChromeUIBlobInternalsHost kChromeUIBlobInternalsHost, kIPFSWebUIHost
#endif

#include "src/chrome/common/webui_url_constants.cc"

#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
#undef kChromeUIBlobInternalsHost
#endif

#undef kPerformanceSubPage
#undef kChromeUIPerformanceSettingsURL
#undef kChromeUIAttributionInternalsHost
Expand Down
5 changes: 4 additions & 1 deletion components/constants/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ source_set("constants") {
]

public_deps = [ ":brave_services_key" ]
deps = [ "//base" ]
deps = [
"//base",
"//brave/components/ipfs/buildflags",
]
}

source_set("brave_service_key_helper") {
Expand Down
4 changes: 4 additions & 0 deletions components/constants/webui_url_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/components/constants/webui_url_constants.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "build/build_config.h"

const char kAdblockHost[] = "adblock";
const char kAdblockInternalsHost[] = "adblock-internals";
const char kAdblockJS[] = "brave_adblock.js";
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
const char kIPFSWebUIHost[] = "ipfs-internals";
const char kIPFSWebUIURL[] = "chrome://ipfs-internals/";
#endif
const char kWebcompatReporterHost[] = "webcompat";
const char kRewardsPageHost[] = "rewards";
const char kRewardsInternalsHost[] = "rewards-internals";
Expand Down
3 changes: 3 additions & 0 deletions components/constants/webui_url_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
#ifndef BRAVE_COMPONENTS_CONSTANTS_WEBUI_URL_CONSTANTS_H_
#define BRAVE_COMPONENTS_CONSTANTS_WEBUI_URL_CONSTANTS_H_

#include "brave/components/ipfs/buildflags/buildflags.h"
#include "build/build_config.h"

extern const char kAdblockHost[];
extern const char kAdblockInternalsHost[];
extern const char kAdblockJS[];
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
extern const char kIPFSWebUIHost[];
extern const char kIPFSWebUIURL[];
#endif
extern const char kWebcompatReporterHost[];
extern const char kRewardsPageHost[];
extern const char kRewardsInternalsHost[];
Expand Down
6 changes: 6 additions & 0 deletions components/ipfs/buildflags/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2020 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 https://mozilla.org/MPL/2.0/.

import("//brave/components/ipfs/buildflags/buildflags.gni")
import("//build/buildflag_header.gni")

Expand All @@ -6,5 +11,6 @@ buildflag_header("buildflags") {
flags = [
"ENABLE_IPFS=$enable_ipfs",
"ENABLE_IPFS_LOCAL_NODE=$enable_ipfs_local_node",
"ENABLE_IPFS_INTERNALS_WEBUI=$enable_ipfs_internals_webui",
]
}
9 changes: 9 additions & 0 deletions components/ipfs/buildflags/buildflags.gni
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# Copyright (c) 2020 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 https://mozilla.org/MPL/2.0/.

declare_args() {
enable_ipfs = true
}

declare_args() {
enable_ipfs_local_node = enable_ipfs && !is_ios
}

declare_args() {
enable_ipfs_internals_webui = enable_ipfs && !is_android
}
18 changes: 12 additions & 6 deletions components/ipfs_ui/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Copyright (c) 2020 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 https://mozilla.org/MPL/2.0/.

import("//brave/components/common/typescript.gni")

assert(!is_android)

transpile_web_ui("ipfs_ui") {
entry_points = [
["ipfs", rebase_path("ipfs.tsx")]
]
entry_points = [ [
"ipfs",
rebase_path("ipfs.tsx"),
] ]

resource_name = "ipfs"
}

pack_web_resources("generated_resources") {
resource_name = "ipfs"
output_dir = "$root_gen_dir/brave/components/ipfs_ui/resources"
deps = [
":ipfs_ui"
]
deps = [ ":ipfs_ui" ]
}
4 changes: 3 additions & 1 deletion components/resources/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ brave_grit("static_resources") {
defines = [
"enable_brave_vpn=$enable_brave_vpn",
"enable_ipfs=$enable_ipfs",
"enable_ipfs_internals_webui=$enable_ipfs_internals_webui",
"enable_playlist=$enable_playlist",
"enable_playlist_webui=$enable_playlist_webui",
"enable_speedreader=$enable_speedreader",
Expand Down Expand Up @@ -87,7 +88,7 @@ repack("resources") {
]
}

if (enable_ipfs) {
if (enable_ipfs_internals_webui) {
deps += [ "//brave/components/ipfs_ui:generated_resources" ]
sources += [
"$root_gen_dir/brave/components/ipfs_ui/resources/ipfs_generated.pak",
Expand Down Expand Up @@ -141,6 +142,7 @@ brave_grit("strings") {
defines = [
"enable_speedreader=$enable_speedreader",
"enable_ipfs=$enable_ipfs",
"enable_ipfs_internals_webui=$enable_ipfs_internals_webui",
"ethereum_remote_client_enabled=$ethereum_remote_client_enabled",
"enable_tor=$enable_tor",
"enable_brave_vpn=$enable_brave_vpn",
Expand Down
76 changes: 39 additions & 37 deletions components/resources/ipfs_strings.grdp
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<grit-part>
<if expr="enable_ipfs">
<message name="IDS_IPFS_CONNECTED_PEERS_TITLE" desc="Number of peers connected">Connected peers:</message>
<message name="IDS_IPFS_ADDRESSES_CONFIG_TITLE" desc="Title of addresses config section">Addresses</message>
<message name="IDS_IPFS_REPO_STATS_TITLE" desc="Title of repo stats section">Repo Stats</message>
<message name="IDS_IPFS_NODE_INFO_TITLE" desc="Title of node info section">Node info</message>
<if expr="enable_ipfs_internals_webui">
<message name="IDS_IPFS_CONNECTED_PEERS_TITLE" desc="Number of peers connected">Connected peers:</message>
<message name="IDS_IPFS_ADDRESSES_CONFIG_TITLE" desc="Title of addresses config section">Addresses</message>
<message name="IDS_IPFS_REPO_STATS_TITLE" desc="Title of repo stats section">Repo Stats</message>
<message name="IDS_IPFS_NODE_INFO_TITLE" desc="Title of node info section">Node info</message>
<message name="IDS_IPFS_DAEMON_STATUS_TITLE" desc="Title of daemon status section">IPFS node status</message>
<message name="IDS_IPFS_API" desc="Title of the API config">API</message>
<message name="IDS_IPFS_GATEWAY" desc="Title of the gateway config">Gateway</message>
<message name="IDS_IPFS_SWARM" desc="Title of the swarm config">Swarm</message>
<message name="IDS_IPFS_REPO_OBJECTS" desc="Title of the objects repo stats section">Objects</message>
<message name="IDS_IPFS_REPO_SIZE" desc="Title of the size repo stats section">Size</message>
<message name="IDS_IPFS_REPO_STORAGE" desc="Title of the storage repo stats section">StorageMax</message>
<message name="IDS_IPFS_REPO_PATH" desc="Title of the path repo stats section">Path</message>
<message name="IDS_IPFS_REPO_VERSION" desc="Title of the version repo stats section">Version</message>
<message name="IDS_IPFS_NODE_INFO_ID" desc="Title of the id node info section">Peer ID</message>
<message name="IDS_IPFS_NODE_INFO_VERSION" desc="Title of the version node info section">Agent version</message>
<message name="IDS_IPFS_LAUNCHED" desc="Title of the launched status">Node is running</message>
<message name="IDS_IPFS_NOT_LAUNCHED" desc="Title of not launched status">Node is not running</message>
<message name="IDS_IPFS_LAUNCH" desc="Text of launch action">Start</message>
<message name="IDS_IPFS_SHUTDOWN" desc="Text of shutdown action">Stop</message>
<message name="IDS_IPFS_RESTART" desc="Text of shutdown action">Restart</message>
<message name="IDS_IPFS_NOT_INSTALLED" desc="Text of not installed state">Not Installed</message>
<message name="IDS_IPFS_INSTALLING" desc="Text of installing state">Installing IPFS...</message>
<message name="IDS_IPFS_RUN_GC_BUTTON" desc="Text of garbage collection button on state">Perform a garbage collection sweep</message>
<message name="IDS_IPFS_GC_ERROR" desc="Text of garbage collection error">Garbage collection error</message>
<message name="IDS_IPFS_PEERS_DETAILS_LINK" desc="Link to open details about peers on brave://ipfs.">
(details)
</message>
<message name="IDS_IPFS_INSTALL_AND_LAUNCH" desc="Title of brave://ipfs install and launch button.">
Install and start
</message>
<message name="IDS_IPFS_LEARN_MORE" desc="Link to open infromation about IPFS on brave://ipfs.">
Learn more about IPFS and privacy
</message>
<message name="IDS_IPFS_ROTATE_IDENTITY_TITLE" desc="The title for the link to rotate identity on ipfs diagnostic page.">
Manage Peer ID and IPNS keys
</message>
<message name="IDS_IPFS_OPEN_WEBUI" desc="Title of brave://ipfs webui button">My Node</message>
</if>
<message name="IDS_IPFS_NODE_LAUNCH_ERROR" desc="Text of node launch error">An error occurred, please try to launch again</message>
<message name="IDS_IPFS_NODE_INSTALLATION_ERROR" desc="Text of node installation error">An error occurred, please try to install the node again</message>
<message name="IDS_IPFS_DAEMON_STATUS_TITLE" desc="Title of daemon status section">IPFS node status</message>
<message name="IDS_IPFS_API" desc="Title of the API config">API</message>
<message name="IDS_IPFS_GATEWAY" desc="Title of the gateway config">Gateway</message>
<message name="IDS_IPFS_SWARM" desc="Title of the swarm config">Swarm</message>
<message name="IDS_IPFS_REPO_OBJECTS" desc="Title of the objects repo stats section">Objects</message>
<message name="IDS_IPFS_REPO_SIZE" desc="Title of the size repo stats section">Size</message>
<message name="IDS_IPFS_REPO_STORAGE" desc="Title of the storage repo stats section">StorageMax</message>
<message name="IDS_IPFS_REPO_PATH" desc="Title of the path repo stats section">Path</message>
<message name="IDS_IPFS_REPO_VERSION" desc="Title of the version repo stats section">Version</message>
<message name="IDS_IPFS_NODE_INFO_ID" desc="Title of the id node info section">Peer ID</message>
<message name="IDS_IPFS_NODE_INFO_VERSION" desc="Title of the version node info section">Agent version</message>
<message name="IDS_IPFS_LAUNCHED" desc="Title of the launched status">Node is running</message>
<message name="IDS_IPFS_NOT_LAUNCHED" desc="Title of not launched status">Node is not running</message>
<message name="IDS_IPFS_LAUNCH" desc="Text of launch action">Start</message>
<message name="IDS_IPFS_SHUTDOWN" desc="Text of shutdown action">Stop</message>
<message name="IDS_IPFS_RESTART" desc="Text of shutdown action">Restart</message>
<message name="IDS_IPFS_NOT_INSTALLED" desc="Text of not installed state">Not Installed</message>
<message name="IDS_IPFS_INSTALLING" desc="Text of installing state">Installing IPFS...</message>
<message name="IDS_IPFS_RUN_GC_BUTTON" desc="Text of garbage collection button on state">Perform a garbage collection sweep</message>
<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>
<message name="IDS_IPFS_INSTALL_AND_LAUNCH" desc="Title of brave://ipfs install and launch button.">
Install and start
</message>
<message name="IDS_IPFS_LEARN_MORE" desc="Link to open infromation about IPFS on brave://ipfs.">
Learn more about IPFS and privacy
</message>
<message name="IDS_IPFS_SERVICE_LAUNCH_RETRY" desc="Retry button text for IPFS interstitial page.">
Try again
</message>
Expand Down Expand Up @@ -159,8 +164,5 @@
<message name="IDS_IPFS_IMPORT_PARTLY_COMPLETED_NOTIFICATION_BODY" desc="The title for ips import error notification.">
The data was successfully uploaded but not moved to the brave-import directory. You can do this manually on the import settings page.
</message>
<message name="IDS_IPFS_ROTATE_IDENTITY_TITLE" desc="The title for the link to rotate identity on ipfs diagnostic page.">
Manage Peer ID and IPNS keys
</message>
</if>
</grit-part>

0 comments on commit 94c3d2a

Please sign in to comment.