From c8892b1368695d82b5a1ae3df2b06861d44600e1 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Tue, 11 Apr 2023 21:49:58 +0300 Subject: [PATCH] Disable IPFS WebUI on Android --- browser/brave_content_browser_client.cc | 7 +++++-- browser/ipfs/content_browser_client_helper.cc | 5 +++++ browser/ipfs/import/ipfs_import_controller.cc | 3 +++ browser/ipfs/import/ipfs_import_controller.h | 4 ++++ browser/ipfs/import/save_package_observer.h | 2 +- browser/ipfs/ipfs_tab_helper.cc | 2 ++ browser/ipfs/ipfs_tab_helper.h | 10 +++++++++- browser/ipfs/sources.gni | 8 ++++++-- browser/ui/BUILD.gn | 7 ++++--- .../webui/brave_web_ui_controller_factory.cc | 11 +++++++---- browser/ui/webui/ipfs_ui.cc | 2 ++ browser/ui/webui/ipfs_ui.h | 2 ++ .../download/download_ui_controller.cc | 4 ++++ chromium_src/chrome/common/DEPS | 1 + .../chrome/common/webui_url_constants.cc | 17 +++++++++++++---- components/constants/BUILD.gn | 5 ++++- components/constants/webui_url_constants.cc | 4 ++++ components/constants/webui_url_constants.h | 3 +++ components/ipfs/buildflags/BUILD.gn | 6 ++++++ components/ipfs/buildflags/buildflags.gni | 11 ++++++++++- components/ipfs_ui/BUILD.gn | 19 +++++++++++++------ components/resources/BUILD.gn | 2 +- 22 files changed, 109 insertions(+), 26 deletions(-) diff --git a/browser/brave_content_browser_client.cc b/browser/brave_content_browser_client.cc index 5583f91a9abd..11f5fac6621b 100644 --- a/browser/brave_content_browser_client.cc +++ b/browser/brave_content_browser_client.cc @@ -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" @@ -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)); diff --git a/browser/ipfs/content_browser_client_helper.cc b/browser/ipfs/content_browser_client_helper.cc index 09fa3d8fd557..fdc198f6e3db 100644 --- a/browser/ipfs/content_browser_client_helper.cc +++ b/browser/ipfs/content_browser_client_helper.cc @@ -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" @@ -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. @@ -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); diff --git a/browser/ipfs/import/ipfs_import_controller.cc b/browser/ipfs/import/ipfs_import_controller.cc index 0c9e28382394..a35ea0b010bf 100644 --- a/browser/ipfs/import/ipfs_import_controller.cc +++ b/browser/ipfs/import/ipfs_import_controller.cc @@ -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: diff --git a/browser/ipfs/import/ipfs_import_controller.h b/browser/ipfs/import/ipfs_import_controller.h index c30b78a20162..5ed3f6ea371c 100644 --- a/browser/ipfs/import/ipfs_import_controller.h +++ b/browser/ipfs/import/ipfs_import_controller.h @@ -12,8 +12,12 @@ #include #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 diff --git a/browser/ipfs/import/save_package_observer.h b/browser/ipfs/import/save_package_observer.h index 3a01799df57e..03ea97803b5e 100644 --- a/browser/ipfs/import/save_package_observer.h +++ b/browser/ipfs/import/save_package_observer.h @@ -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: diff --git a/browser/ipfs/ipfs_tab_helper.cc b/browser/ipfs/ipfs_tab_helper.cc index 3c57445b7614..2f84f93e111b 100644 --- a/browser/ipfs/ipfs_tab_helper.cc +++ b/browser/ipfs/ipfs_tab_helper.cc @@ -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(*web_contents) { pref_service_ = user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()); auto* storage_partition = diff --git a/browser/ipfs/ipfs_tab_helper.h b/browser/ipfs/ipfs_tab_helper.h index 868d7abbe63d..d972e857d930 100644 --- a/browser/ipfs/ipfs_tab_helper.h +++ b/browser/ipfs/ipfs_tab_helper.h @@ -11,12 +11,16 @@ #include #include -#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; @@ -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 { public: IPFSTabHelper(const IPFSTabHelper&) = delete; @@ -44,9 +50,11 @@ class IPFSTabHelper : public content::WebContentsObserver, resolver_ = std::move(resolver); } +#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE) IpfsImportController* GetImportController() { return static_cast(this); } +#endif void SetPageURLForTesting(const GURL& url) { current_page_url_for_testing_ = url; diff --git a/browser/ipfs/sources.gni b/browser/ipfs/sources.gni index f8842d1dd9db..7853c84f27f8 100644 --- a/browser/ipfs/sources.gni +++ b/browser/ipfs/sources.gni @@ -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", diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index a8426332ba21..d527fd42e8ff 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -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", @@ -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) { diff --git a/browser/ui/webui/brave_web_ui_controller_factory.cc b/browser/ui/webui/brave_web_ui_controller_factory.cc index cdaace7f7c3a..97e493912737 100644 --- a/browser/ui/webui/brave_web_ui_controller_factory.cc +++ b/browser/ui/webui/brave_web_ui_controller_factory.cc @@ -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 @@ -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()); @@ -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 || diff --git a/browser/ui/webui/ipfs_ui.cc b/browser/ui/webui/ipfs_ui.cc index 9997e6acf912..e12ffc0e0689 100644 --- a/browser/ui/webui/ipfs_ui.cc +++ b/browser/ui/webui/ipfs_ui.cc @@ -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() { diff --git a/browser/ui/webui/ipfs_ui.h b/browser/ui/webui/ipfs_ui.h index 26699253be32..a7f18626c9de 100644 --- a/browser/ui/webui/ipfs_ui.h +++ b/browser/ui/webui/ipfs_ui.h @@ -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; diff --git a/chromium_src/chrome/browser/download/download_ui_controller.cc b/chromium_src/chrome/browser/download/download_ui_controller.cc index 976e9558e57f..2234bcef2670 100644 --- a/chromium_src/chrome/browser/download/download_ui_controller.cc +++ b/chromium_src/chrome/browser/download/download_ui_controller.cc @@ -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 } diff --git a/chromium_src/chrome/common/DEPS b/chromium_src/chrome/common/DEPS index 469400e5840d..7a61e77e01e8 100644 --- a/chromium_src/chrome/common/DEPS +++ b/chromium_src/chrome/common/DEPS @@ -1,6 +1,7 @@ include_rules = [ "+brave/common", "+brave/components/constants", + "+brave/components/ipfs/buildflags", "+brave/grit", "+components/version_info", "+components/component_updater", diff --git a/chromium_src/chrome/common/webui_url_constants.cc b/chromium_src/chrome/common/webui_url_constants.cc index 843de9dbb6dd..23d257cc1e25 100644 --- a/chromium_src/chrome/common/webui_url_constants.cc +++ b/chromium_src/chrome/common/webui_url_constants.cc @@ -4,12 +4,18 @@ * 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 @@ -17,6 +23,9 @@ #undef kPerformanceSubPage #undef kChromeUIPerformanceSettingsURL +#if BUILDFLAG(ENABLE_IPFS_WEBUI) +#undef kChromeUIBlobInternalsHost +#endif #undef kChromeUIAttributionInternalsHost namespace chrome { diff --git a/components/constants/BUILD.gn b/components/constants/BUILD.gn index 7028cd1f603f..14ff1aa69edc 100644 --- a/components/constants/BUILD.gn +++ b/components/constants/BUILD.gn @@ -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") { diff --git a/components/constants/webui_url_constants.cc b/components/constants/webui_url_constants.cc index c9a438b6594a..cb0ffa2b6acc 100644 --- a/components/constants/webui_url_constants.cc +++ b/components/constants/webui_url_constants.cc @@ -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"; diff --git a/components/constants/webui_url_constants.h b/components/constants/webui_url_constants.h index a6ade736c72a..ceb14244b0ce 100644 --- a/components/constants/webui_url_constants.h +++ b/components/constants/webui_url_constants.h @@ -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[]; diff --git a/components/ipfs/buildflags/BUILD.gn b/components/ipfs/buildflags/BUILD.gn index b0c943879619..e4f7fa10be91 100644 --- a/components/ipfs/buildflags/BUILD.gn +++ b/components/ipfs/buildflags/BUILD.gn @@ -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") @@ -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", ] } diff --git a/components/ipfs/buildflags/buildflags.gni b/components/ipfs/buildflags/buildflags.gni index 56d4d98d7878..80768d474101 100644 --- a/components/ipfs/buildflags/buildflags.gni +++ b/components/ipfs/buildflags/buildflags.gni @@ -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 } diff --git a/components/ipfs_ui/BUILD.gn b/components/ipfs_ui/BUILD.gn index c89f83482fdf..6fd4ade84f30 100644 --- a/components/ipfs_ui/BUILD.gn +++ b/components/ipfs_ui/BUILD.gn @@ -1,9 +1,18 @@ +# 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/build/config.gni") 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" } @@ -11,7 +20,5 @@ transpile_web_ui("ipfs_ui") { pack_web_resources("generated_resources") { resource_name = "ipfs" output_dir = "$root_gen_dir/brave/components/ipfs_ui/resources" - deps = [ - ":ipfs_ui" - ] + deps = [ ":ipfs_ui" ] } diff --git a/components/resources/BUILD.gn b/components/resources/BUILD.gn index a8feae9bd690..61d0b2230dcd 100644 --- a/components/resources/BUILD.gn +++ b/components/resources/BUILD.gn @@ -87,7 +87,7 @@ repack("resources") { ] } - if (enable_ipfs) { + if (enable_ipfs_webui) { deps += [ "//brave/components/ipfs_ui:generated_resources" ] sources += [ "$root_gen_dir/brave/components/ipfs_ui/resources/ipfs_generated.pak",