Skip to content

Commit

Permalink
Disable IPFS WebUI on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyBarabash committed Apr 11, 2023
1 parent ab92b35 commit c8892b1
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 26 deletions.
7 changes: 5 additions & 2 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ using extensions::ChromeContentBrowserClientExtensionsPart;
#if BUILDFLAG(ENABLE_IPFS)
#include "brave/browser/ipfs/content_browser_client_helper.h"
#include "brave/browser/ipfs/ipfs_service_factory.h"
#include "brave/browser/ipfs/ipfs_subframe_navigation_throttle.h"
#include "brave/components/ipfs/ipfs_constants.h"
#include "brave/components/ipfs/ipfs_navigation_throttle.h"
#endif

#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
#include "brave/browser/ipfs/ipfs_subframe_navigation_throttle.h"
#endif

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/tor/onion_location_navigation_throttle_delegate.h"
#include "brave/browser/tor/tor_profile_service_factory.h"
Expand Down Expand Up @@ -996,7 +999,7 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
}
#endif

#if BUILDFLAG(ENABLE_IPFS)
#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
throttles.insert(
throttles.begin(),
ipfs::IpfsSubframeNavigationThrottle::CreateThrottleFor(handle));
Expand Down
5 changes: 5 additions & 0 deletions browser/ipfs/content_browser_client_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "brave/components/constants/url_constants.h"
#include "brave/components/constants/webui_url_constants.h"
#include "brave/components/decentralized_dns/core/utils.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/ipfs/ipfs_constants.h"
#include "brave/components/ipfs/ipfs_utils.h"
#include "brave/components/ipfs/pref_names.h"
Expand Down Expand Up @@ -55,12 +56,14 @@ bool HandleIPFSURLRewrite(GURL* url, content::BrowserContext* browser_context) {
base::EndsWith(url->host_piece(), kIpnsLocalhost))) {
return true;
}
#if BUILDFLAG(ENABLE_IPFS_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 +108,12 @@ bool HandleIPFSURLRewrite(GURL* url, content::BrowserContext* browser_context) {

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

std::size_t ipfs_pos = url->host_piece().find(kIpfsLocalhost);
std::size_t ipns_pos = url->host_piece().find(kIpnsLocalhost);
Expand Down
3 changes: 3 additions & 0 deletions browser/ipfs/import/ipfs_import_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#include "ui/message_center/public/cpp/notification_types.h"
#include "ui/message_center/public/cpp/notifier_id.h"

static_assert(!BUILDFLAG(IS_ANDROID));
static_assert(BUILDFLAG(ENABLE_IPFS_LOCAL_NODE));

namespace {

// Converts url to directory name:
Expand Down
4 changes: 4 additions & 0 deletions browser/ipfs/import/ipfs_import_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
#include <vector>

#include "brave/components/ipfs/ipfs_service.h"
#include "build/build_config.h"
#include "ui/shell_dialogs/select_file_dialog.h"

static_assert(!BUILDFLAG(IS_ANDROID));
static_assert(BUILDFLAG(ENABLE_IPFS_LOCAL_NODE));

namespace content {
class WebContents;
} // namespace content
Expand Down
2 changes: 1 addition & 1 deletion browser/ipfs/import/save_package_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "components/download/public/common/download_item.h"
#include "content/public/browser/download_manager.h"

// Tracks downloading process for a pacakge and notifies when it is completed.
// Tracks downloading process for a package and notifies when it is completed.
class SavePackageFinishedObserver : public download::DownloadItem::Observer,
public content::DownloadManager::Observer {
public:
Expand Down
2 changes: 2 additions & 0 deletions browser/ipfs/ipfs_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ IPFSTabHelper::~IPFSTabHelper() = default;

IPFSTabHelper::IPFSTabHelper(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
IpfsImportController(web_contents),
#endif
content::WebContentsUserData<IPFSTabHelper>(*web_contents) {
pref_service_ = user_prefs::UserPrefs::Get(web_contents->GetBrowserContext());
auto* storage_partition =
Expand Down
10 changes: 9 additions & 1 deletion browser/ipfs/ipfs_tab_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
#include <utility>
#include <vector>

#include "brave/browser/ipfs/import/ipfs_import_controller.h"
#include "brave/browser/ipfs/ipfs_host_resolver.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"

#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
#include "brave/browser/ipfs/import/ipfs_import_controller.h"
#endif

namespace content {
class NavigationHandle;
class WebContents;
Expand All @@ -30,7 +34,9 @@ class IpfsImportController;

// Determines if IPFS should be active for a given top-level navigation.
class IPFSTabHelper : public content::WebContentsObserver,
#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
public IpfsImportController,
#endif
public content::WebContentsUserData<IPFSTabHelper> {
public:
IPFSTabHelper(const IPFSTabHelper&) = delete;
Expand All @@ -44,9 +50,11 @@ class IPFSTabHelper : public content::WebContentsObserver,
resolver_ = std::move(resolver);
}

#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
IpfsImportController* GetImportController() {
return static_cast<IpfsImportController*>(this);
}
#endif

void SetPageURLForTesting(const GURL& url) {
current_page_url_for_testing_ = url;
Expand Down
8 changes: 6 additions & 2 deletions browser/ipfs/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ brave_browser_ipfs_sources = []
brave_browser_ipfs_deps = []

if (enable_ipfs) {
if (enable_ipfs_local_node) {
brave_browser_ipfs_sources += [
"//brave/browser/ipfs/import/ipfs_import_controller.cc",
"//brave/browser/ipfs/import/ipfs_import_controller.h",
]
}
brave_browser_ipfs_sources += [
"//brave/browser/ipfs/content_browser_client_helper.cc",
"//brave/browser/ipfs/content_browser_client_helper.h",
"//brave/browser/ipfs/import/ipfs_import_controller.cc",
"//brave/browser/ipfs/import/ipfs_import_controller.h",
"//brave/browser/ipfs/import/save_package_observer.cc",
"//brave/browser/ipfs/import/save_package_observer.h",
"//brave/browser/ipfs/ipfs_blob_context_getter_factory.cc",
Expand Down
7 changes: 4 additions & 3 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ source_set("ui") {
"webui/commands_ui.h",
]
}

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

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

#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_WEBUI)
#include "brave/browser/ui/webui/ipfs_ui.h"
#endif

#if BUILDFLAG(ENABLE_PLAYLIST_WEBUI)
#include "brave/browser/ui/webui/playlist_ui.h"
#endif
Expand Down Expand Up @@ -95,7 +98,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_WEBUI)
} else if (host == kIPFSWebUIHost &&
ipfs::IpfsServiceFactory::IsIpfsEnabled(profile)) {
return new IPFSUI(web_ui, url.host());
Expand Down Expand Up @@ -191,10 +194,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_WEBUI)
(url.host_piece() == kIPFSWebUIHost &&
base::FeatureList::IsEnabled(ipfs::features::kIpfsFeature)) ||
#endif // BUILDFLAG(ENABLE_IPFS)
#endif // BUILDFLAG(ENABLE_IPFS_WEBUI)
#if !BUILDFLAG(IS_ANDROID)
url.host_piece() == kWalletPanelHost ||
url.host_piece() == kWalletPageHost ||
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/webui/ipfs_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/l10n/l10n_util.h"

static_assert(!BUILDFLAG(IS_ANDROID));

namespace {

std::string GetIPFSUpdaterVersion() {
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/webui/ipfs_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_message_handler.h"

static_assert(!BUILDFLAG(IS_ANDROID));

namespace ipfs {
struct AddressesConfig;
struct RepoStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ bool IsIpfsImportDownloadCreated(content::WebContents* web_contents,

bool IsIpfsImportDownloadCreated(content::WebContents* web_contents,
download::DownloadItem* item) {
#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
ipfs::IPFSTabHelper* helper =
ipfs::IPFSTabHelper::FromWebContents(web_contents);
return (helper && helper->GetImportController()->HasInProgressDownload(item));
#else
return false;
#endif
}
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,19 +4,28 @@
* 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

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

#define kChromeUIPerformanceSettingsURL kChromeUIPerformanceSettingsURL_UnUsed
#define kPerformanceSubPage kPerformanceSubPage_UnUsed

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

#undef kPerformanceSubPage
#undef kChromeUIPerformanceSettingsURL
#if BUILDFLAG(ENABLE_IPFS_WEBUI)
#undef kChromeUIBlobInternalsHost
#endif
#undef kChromeUIAttributionInternalsHost

namespace chrome {
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_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_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_WEBUI=$enable_ipfs_webui",
]
}
11 changes: 10 additions & 1 deletion 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
enable_ipfs_local_node = enable_ipfs && !is_ios && !is_android
}

declare_args() {
enable_ipfs_webui = enable_ipfs && !is_android
}
Loading

0 comments on commit c8892b1

Please sign in to comment.