diff --git a/browser/BUILD.gn b/browser/BUILD.gn index 6bb9414a7de..d6e8dd74601 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -59,8 +59,6 @@ source_set("browser_process") { "component_updater/brave_component_updater_configurator.h", "component_updater/brave_component_updater_delegate.cc", "component_updater/brave_component_updater_delegate.h", - "component_updater/brave_crx_update_service.cc", - "component_updater/brave_crx_update_service.h", "geolocation/brave_geolocation_permission_context.cc", "geolocation/brave_geolocation_permission_context.h", "metrics/metrics_reporting_util.cc", diff --git a/browser/brave_browser_process_impl.cc b/browser/brave_browser_process_impl.cc index ee807b86acc..a599abcd20e 100644 --- a/browser/brave_browser_process_impl.cc +++ b/browser/brave_browser_process_impl.cc @@ -21,7 +21,6 @@ #include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h" #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/autoplay_whitelist_service.h" -#include "brave/components/brave_shields/browser/extension_whitelist_service.h" #include "brave/components/brave_shields/browser/https_everywhere_service.h" #include "brave/components/brave_shields/browser/referrer_whitelist_service.h" #include "brave/components/brave_shields/browser/tracking_protection_service.h" @@ -40,6 +39,11 @@ #include "brave/components/brave_referrals/browser/brave_referrals_service.h" #endif +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "brave/common/extensions/whitelist.h" +#include "brave/components/brave_component_updater/browser/extension_whitelist_service.h" +#endif + #if defined(OS_ANDROID) #include "chrome/browser/android/chrome_feature_list.h" #include "chrome/browser/android/component_updater/background_task_update_scheduler.h" @@ -85,35 +89,6 @@ BraveBrowserProcessImpl::brave_component_updater_delegate() { return brave_component_updater_delegate_.get(); } -component_updater::ComponentUpdateService* -BraveBrowserProcessImpl::component_updater() { - if (component_updater_) - return component_updater_.get(); - - if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) - return nullptr; - - std::unique_ptr scheduler; -#if defined(OS_ANDROID) - if (base::FeatureList::IsEnabled( - chrome::android::kBackgroundTaskComponentUpdate) && - component_updater::BackgroundTaskUpdateScheduler::IsAvailable()) { - scheduler = - std::make_unique(); - } -#endif - if (!scheduler) - scheduler = std::make_unique(); - - component_updater_ = component_updater::ComponentUpdateServiceFactory( - component_updater::MakeBraveComponentUpdaterConfigurator( - base::CommandLine::ForCurrentProcess(), - g_browser_process->local_state()), - std::move(scheduler)); - - return component_updater_.get(); -} - void BraveBrowserProcessImpl::ResourceDispatcherHostCreated() { BrowserProcessImpl::ResourceDispatcherHostCreated(); ad_block_service()->Start(); @@ -176,12 +151,12 @@ BraveBrowserProcessImpl::autoplay_whitelist_service() { } #if BUILDFLAG(ENABLE_EXTENSIONS) -brave_shields::ExtensionWhitelistService* +brave_component_updater::ExtensionWhitelistService* BraveBrowserProcessImpl::extension_whitelist_service() { if (!extension_whitelist_service_) { extension_whitelist_service_ = - brave_shields::ExtensionWhitelistServiceFactory( - local_data_files_service()); + brave_component_updater::ExtensionWhitelistServiceFactory( + local_data_files_service(), kVettedExtensions); } return extension_whitelist_service_.get(); } diff --git a/browser/brave_browser_process_impl.h b/browser/brave_browser_process_impl.h index 72345f77a40..a1cf3286c96 100644 --- a/browser/brave_browser_process_impl.h +++ b/browser/brave_browser_process_impl.h @@ -25,6 +25,9 @@ class BraveWidevineBundleManager; #endif namespace brave_component_updater { +#if BUILDFLAG(ENABLE_EXTENSIONS) +class ExtensionWhitelistService; +#endif class LocalDataFilesService; } @@ -33,7 +36,6 @@ class AdBlockService; class AdBlockCustomFiltersService; class AdBlockRegionalServiceManager; class AutoplayWhitelistService; -class ExtensionWhitelistService; class HTTPSEverywhereService; class ReferrerWhitelistService; class TrackingProtectionService; @@ -55,7 +57,6 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl { ~BraveBrowserProcessImpl() override; // BrowserProcess implementation. - component_updater::ComponentUpdateService* component_updater() override; void ResourceDispatcherHostCreated() override; ProfileManager* profile_manager() override; @@ -66,7 +67,8 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl { ad_block_regional_service_manager(); brave_shields::AutoplayWhitelistService* autoplay_whitelist_service(); #if BUILDFLAG(ENABLE_EXTENSIONS) - brave_shields::ExtensionWhitelistService* extension_whitelist_service(); + brave_component_updater::ExtensionWhitelistService* + extension_whitelist_service(); #endif brave_shields::ReferrerWhitelistService* referrer_whitelist_service(); greaselion::GreaselionDownloadService* greaselion_download_service(); @@ -98,8 +100,10 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl { ad_block_regional_service_manager_; std::unique_ptr autoplay_whitelist_service_; - std::unique_ptr +#if BUILDFLAG(ENABLE_EXTENSIONS) + std::unique_ptr extension_whitelist_service_; +#endif std::unique_ptr referrer_whitelist_service_; std::unique_ptr diff --git a/browser/component_updater/brave_component_updater_configurator.cc b/browser/component_updater/brave_component_updater_configurator.cc index e966cf2f00e..8558de68124 100644 --- a/browser/component_updater/brave_component_updater_configurator.cc +++ b/browser/component_updater/brave_component_updater_configurator.cc @@ -18,7 +18,6 @@ #include "chrome/browser/net/system_network_context_manager.h" #include "chrome/common/pref_names.h" #include "components/component_updater/component_updater_command_line_config_policy.h" -#include "components/component_updater/configurator_impl.h" #include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_service.h" #include "components/update_client/activity_data_service.h" @@ -40,57 +39,6 @@ namespace component_updater { -namespace { - -class BraveConfigurator : public update_client::Configurator { - public: - BraveConfigurator(const base::CommandLine* cmdline, - PrefService* pref_service); - - // update_client::Configurator overrides. - int InitialDelay() const override; - int NextCheckDelay() const override; - int OnDemandDelay() const override; - int UpdateDelay() const override; - std::vector UpdateUrl() const override; - std::vector PingUrl() const override; - std::string GetProdId() const override; - base::Version GetBrowserVersion() const override; - std::string GetChannel() const override; - std::string GetBrand() const override; - std::string GetLang() const override; - std::string GetOSLongName() const override; - base::flat_map ExtraRequestParams() const override; - std::string GetDownloadPreference() const override; - scoped_refptr GetNetworkFetcherFactory() - override; - scoped_refptr GetUnzipperFactory() override; - scoped_refptr GetPatcherFactory() override; - bool EnabledDeltas() const override; - bool EnabledComponentUpdates() const override; - bool EnabledBackgroundDownloader() const override; - bool EnabledCupSigning() const override; - PrefService* GetPrefService() const override; - update_client::ActivityDataService* GetActivityDataService() const override; - bool IsPerUserInstall() const override; - std::vector GetRunActionKeyHash() const override; - std::string GetAppGuid() const override; - std::unique_ptr - GetProtocolHandlerFactory() const override; - update_client::RecoveryCRXElevator GetRecoveryCRXElevator() const override; - - private: - friend class base::RefCountedThreadSafe; - - ConfiguratorImpl configurator_impl_; - PrefService* pref_service_; // This member is not owned by this class. - scoped_refptr network_fetcher_factory_; - scoped_refptr unzip_factory_; - scoped_refptr patch_factory_; - - ~BraveConfigurator() override {} -}; - // Allows the component updater to use non-encrypted communication with the // update backend. The security of the update checks is enforced using // a custom message signing protocol and it does not depend on using HTTPS. @@ -103,6 +51,8 @@ BraveConfigurator::BraveConfigurator( DCHECK(pref_service_); } +BraveConfigurator::~BraveConfigurator() {} + int BraveConfigurator::InitialDelay() const { return configurator_impl_.InitialDelay(); } @@ -246,19 +196,4 @@ update_client::RecoveryCRXElevator BraveConfigurator::GetRecoveryCRXElevator() #endif } -} // namespace - -void RegisterPrefsForBraveComponentUpdaterConfigurator( - PrefRegistrySimple* registry) { - // The component updates are enabled by default, if the preference is not set. - registry->RegisterBooleanPref(prefs::kComponentUpdatesEnabled, true); -} - -scoped_refptr -MakeBraveComponentUpdaterConfigurator( - const base::CommandLine* cmdline, - PrefService* pref_service) { - return base::MakeRefCounted(cmdline, pref_service); -} - } // namespace component_updater diff --git a/browser/component_updater/brave_component_updater_configurator.h b/browser/component_updater/brave_component_updater_configurator.h index 14c1c38fa76..0667ecd4a19 100644 --- a/browser/component_updater/brave_component_updater_configurator.h +++ b/browser/component_updater/brave_component_updater_configurator.h @@ -1,11 +1,17 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 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/. */ -#ifndef BRAVE_BROWSER_COMPONENT_UPDATER_CHROME_COMPONENT_UPDATER_CONFIGURATOR_H_ -#define BRAVE_BROWSER_COMPONENT_UPDATER_CHROME_COMPONENT_UPDATER_CONFIGURATOR_H_ +#ifndef BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_UPDATER_CONFIGURATOR_H_ +#define BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_UPDATER_CONFIGURATOR_H_ + +#include +#include +#include #include "base/memory/ref_counted.h" +#include "components/component_updater/configurator_impl.h" #include "components/update_client/configurator.h" class PrefRegistrySimple; @@ -21,18 +27,55 @@ class URLRequestContextGetter; namespace component_updater { -// Registers preferences associated with the component updater configurator -// for Chrome. The preferences must be registered with the local pref store -// before they can be queried by the configurator instance. -// This function is called before MakeChromeComponentUpdaterConfigurator. -void RegisterPrefsForBraveComponentUpdaterConfigurator( - PrefRegistrySimple* registry); +class BraveConfigurator : public update_client::Configurator { + public: + BraveConfigurator(const base::CommandLine* cmdline, + PrefService* pref_service); + + // update_client::Configurator overrides. + int InitialDelay() const override; + int NextCheckDelay() const override; + int OnDemandDelay() const override; + int UpdateDelay() const override; + std::vector UpdateUrl() const override; + std::vector PingUrl() const override; + std::string GetProdId() const override; + base::Version GetBrowserVersion() const override; + std::string GetChannel() const override; + std::string GetBrand() const override; + std::string GetLang() const override; + std::string GetOSLongName() const override; + base::flat_map ExtraRequestParams() const override; + std::string GetDownloadPreference() const override; + scoped_refptr GetNetworkFetcherFactory() + override; + scoped_refptr GetUnzipperFactory() override; + scoped_refptr GetPatcherFactory() override; + bool EnabledDeltas() const override; + bool EnabledComponentUpdates() const override; + bool EnabledBackgroundDownloader() const override; + bool EnabledCupSigning() const override; + PrefService* GetPrefService() const override; + update_client::ActivityDataService* GetActivityDataService() const override; + bool IsPerUserInstall() const override; + std::vector GetRunActionKeyHash() const override; + std::string GetAppGuid() const override; + std::unique_ptr + GetProtocolHandlerFactory() const override; + update_client::RecoveryCRXElevator GetRecoveryCRXElevator() const override; + + private: + friend class base::RefCountedThreadSafe; + + ConfiguratorImpl configurator_impl_; + PrefService* pref_service_; // This member is not owned by this class. + scoped_refptr network_fetcher_factory_; + scoped_refptr unzip_factory_; + scoped_refptr patch_factory_; -scoped_refptr -MakeBraveComponentUpdaterConfigurator( - const base::CommandLine* cmdline, - PrefService* pref_service); + ~BraveConfigurator() override; +}; } // namespace component_updater -#endif // BRAVE_BROWSER_COMPONENT_UPDATER_CHROME_COMPONENT_UPDATER_CONFIGURATOR_H_ +#endif // BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_UPDATER_CONFIGURATOR_H_ diff --git a/browser/component_updater/brave_crx_update_service.cc b/browser/component_updater/brave_crx_update_service.cc deleted file mode 100644 index 6988fe6e96f..00000000000 --- a/browser/component_updater/brave_crx_update_service.cc +++ /dev/null @@ -1,110 +0,0 @@ -/* Copyright (c) 2019 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/browser/component_updater/brave_crx_update_service.h" - -#include -#include -#include - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/threading/thread_task_runner_handle.h" -#include "components/component_updater/update_scheduler.h" -#include "components/update_client/configurator.h" -#include "components/update_client/task_update.h" -#include "components/update_client/update_client_internal.h" -#include "components/update_client/update_engine.h" -#include "components/update_client/utils.h" -#include "extensions/buildflags/buildflags.h" - -#if BUILDFLAG(ENABLE_EXTENSIONS) -#include "brave/browser/extensions/brave_extension_provider.h" -#endif - -namespace component_updater { - -BraveCrxUpdateService::BraveCrxUpdateService( - scoped_refptr config, - std::unique_ptr scheduler, - scoped_refptr update_client) - : CrxUpdateService(config, std::move(scheduler), update_client) {} - -void BraveCrxUpdateService::Start() { - DCHECK(thread_checker_.CalledOnValidThread()); - scheduler_->Schedule( - base::TimeDelta::FromSeconds(config_->InitialDelay()), - base::TimeDelta::FromSeconds(config_->NextCheckDelay()), - base::Bind(base::IgnoreResult(&BraveCrxUpdateService::CheckForUpdates), - base::Unretained(this)), - base::DoNothing()); -} - -bool BraveCrxUpdateService::CheckForUpdates( - UpdateScheduler::OnFinishedCallback on_finished) { - DCHECK(thread_checker_.CalledOnValidThread()); - - std::vector secure_ids; // Requires HTTPS for update checks. - std::vector unsecure_ids; // Can fallback to HTTP. - for (const auto id : components_order_) { - DCHECK(components_.find(id) != components_.end()); -#if BUILDFLAG(ENABLE_EXTENSIONS) - if (!extensions::BraveExtensionProvider::IsVetted(id)) { - continue; - } -#endif - const auto component = GetComponent(id); - if (!component || component->requires_network_encryption) - secure_ids.push_back(id); - else - unsecure_ids.push_back(id); - } - - if (unsecure_ids.empty() && secure_ids.empty()) { - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, - std::move(on_finished)); - return true; - } - - Callback on_finished_callback = base::BindOnce( - [](UpdateScheduler::OnFinishedCallback on_finished, - update_client::Error error) { std::move(on_finished).Run(); }, - std::move(on_finished)); - - if (!unsecure_ids.empty()) { - for (auto id : unsecure_ids) { - update_client_->Update( - {id}, - base::BindOnce(&CrxUpdateService::GetCrxComponents, - base::Unretained(this)), - false, - base::BindOnce(&CrxUpdateService::OnUpdateComplete, - base::Unretained(this), - secure_ids.empty() && (id == unsecure_ids.back()) - ? std::move(on_finished_callback) - : Callback(), - base::TimeTicks::Now())); - } - } - - if (!secure_ids.empty()) { - for (auto id : secure_ids) { - update_client_->Update( - {id}, - base::BindOnce(&CrxUpdateService::GetCrxComponents, - base::Unretained(this)), - false, - base::BindOnce( - &CrxUpdateService::OnUpdateComplete, base::Unretained(this), - (id == secure_ids.back()) ? std::move(on_finished_callback) - : Callback(), - base::TimeTicks::Now())); - } - } - - return true; -} - -} // namespace component_updater diff --git a/browser/component_updater/brave_crx_update_service.h b/browser/component_updater/brave_crx_update_service.h deleted file mode 100644 index 41619c24dbe..00000000000 --- a/browser/component_updater/brave_crx_update_service.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (c) 2019 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/. */ - -#ifndef BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_CRX_UPDATE_SERVICE_H_ -#define BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_CRX_UPDATE_SERVICE_H_ - -#include - -#include "components/component_updater/component_updater_service.h" -#include "components/component_updater/component_updater_service_internal.h" - -namespace component_updater { - -using CrxInstaller = update_client::CrxInstaller; -using UpdateClient = update_client::UpdateClient; - -class BraveCrxUpdateService : public CrxUpdateService { - public: - using CrxUpdateService::CrxUpdateService; - BraveCrxUpdateService(scoped_refptr config, - std::unique_ptr scheduler, - scoped_refptr update_client); - - ~BraveCrxUpdateService() override {} - - private: - bool CheckForUpdates(UpdateScheduler::OnFinishedCallback on_finished); - void Start(); - - DISALLOW_COPY_AND_ASSIGN(BraveCrxUpdateService); -}; -} // namespace component_updater - -#endif // BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_CRX_UPDATE_SERVICE_H_ diff --git a/browser/extensions/brave_extension_install_prompt.cc b/browser/extensions/brave_extension_install_prompt.cc index b55bffebe84..aade90853dc 100644 --- a/browser/extensions/brave_extension_install_prompt.cc +++ b/browser/extensions/brave_extension_install_prompt.cc @@ -5,12 +5,14 @@ #include "brave/browser/extensions/brave_extension_install_prompt.h" -#include "brave/browser/extensions/brave_extension_provider.h" +#include "brave/browser/brave_browser_process_impl.h" +#include "brave/components/brave_component_updater/browser/extension_whitelist_service.h" #include "brave/grit/brave_generated_resources.h" #include "ui/base/l10n/l10n_util.h" base::string16 BravePrompt::GetDialogTitle() const { - if (!extensions::BraveExtensionProvider::IsVetted(extension())) { + if (!g_brave_browser_process->extension_whitelist_service()->IsVetted( + extension())) { if (type_ == ExtensionInstallPrompt::INSTALL_PROMPT || type_ == ExtensionInstallPrompt::WEBSTORE_WIDGET_PROMPT) { return l10n_util::GetStringUTF16( diff --git a/browser/extensions/brave_extension_provider.cc b/browser/extensions/brave_extension_provider.cc index d75b9e5d57a..ebef3ad13ce 100644 --- a/browser/extensions/brave_extension_provider.cc +++ b/browser/extensions/brave_extension_provider.cc @@ -13,7 +13,7 @@ #include "brave/browser/brave_browser_process_impl.h" #include "brave/common/extensions/extension_constants.h" #include "brave/components/brave_component_updater/browser/local_data_files_service.h" -#include "brave/components/brave_shields/browser/extension_whitelist_service.h" +#include "brave/components/brave_component_updater/browser/extension_whitelist_service.h" #include "brave/grit/brave_generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -41,54 +41,6 @@ bool IsBlacklisted(const extensions::Extension* extension) { namespace extensions { -bool BraveExtensionProvider::IsVetted(const Extension* extension) { - // This is a hardcoded list of vetted extensions, mostly - // the built-in ones that ship with Brave or are used for - // unit tests. - // Don't add new extensions to this list. Add them to - // the files managed by the extension whitelist service. - return BraveExtensionProvider::IsVetted(extension->id()); -} - -bool BraveExtensionProvider::IsVetted(const std::string id) { - static std::vector vetted_extensions({ - brave_extension_id, - brave_rewards_extension_id, - brave_sync_extension_id, - brave_webtorrent_extension_id, - crl_set_extension_id, - ethereum_remote_client_extension_id, - hangouts_extension_id, - widevine_extension_id, - brave_component_updater::kLocalDataFilesComponentId, - // Web Store - "ahfgeienlihckogmohjhadlkjgocpleb", - // Brave Automation Extension - "aapnijgdinlhnhlmodcfapnahmbfebeb", - // Test ID: Brave Default Ad Block Updater - "naccapggpomhlhoifnlebfoocegenbol", - // Test ID: Brave Regional Ad Block Updater - // (9852EFC4-99E4-4F2D-A915-9C3196C7A1DE) - "dlpmaigjliompnelofkljgcmlenklieh", - // Test ID: Brave Tracking Protection Updater - "eclbkhjphkhalklhipiicaldjbnhdfkc", - // Test ID: PDFJS - "kpbdcmcgkedhpbcpfndimofjnefgjidd", - // Test ID: Brave HTTPS Everywhere Updater - "bhlmpjhncoojbkemjkeppfahkglffilp", - // Test ID: Brave Tor Client Updater - "ngicbhhaldfdgmjhilmnleppfpmkgbbk", - // Chromium PDF Viewer. - "mhjfbmdgcfjbbpaeojofohoefgiehjai", - }); - if (std::find(vetted_extensions.begin(), vetted_extensions.end(), id) != - vetted_extensions.end()) - return true; - - return g_brave_browser_process->extension_whitelist_service()->IsWhitelisted( - id); -} - BraveExtensionProvider::BraveExtensionProvider() {} BraveExtensionProvider::~BraveExtensionProvider() {} diff --git a/browser/extensions/brave_extension_provider.h b/browser/extensions/brave_extension_provider.h index 4b34f980004..73499ab5eb1 100644 --- a/browser/extensions/brave_extension_provider.h +++ b/browser/extensions/brave_extension_provider.h @@ -21,8 +21,7 @@ class BraveExtensionProvider : public ManagementPolicy::Provider { base::string16* error) const override; bool MustRemainInstalled(const Extension* extension, base::string16* error) const override; - static bool IsVetted(const extensions::Extension* extension); - static bool IsVetted(const std::string id); + private: DISALLOW_COPY_AND_ASSIGN(BraveExtensionProvider); }; diff --git a/chromium_src/chrome/browser/component_updater/chrome_component_updater_configurator.cc b/chromium_src/chrome/browser/component_updater/chrome_component_updater_configurator.cc new file mode 100644 index 00000000000..79ec884e2ab --- /dev/null +++ b/chromium_src/chrome/browser/component_updater/chrome_component_updater_configurator.cc @@ -0,0 +1,21 @@ +/* Copyright (c) 2019 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/browser/component_updater/brave_component_updater_configurator.h" + +#define MakeChromeComponentUpdaterConfigurator \ + MakeChromeComponentUpdaterConfigurator_ChromiumImpl +#include "../../../../../chrome/browser/component_updater/chrome_component_updater_configurator.cc" // NOLINT +#undef MakeChromeComponentUpdaterConfigurator + +namespace component_updater { + +scoped_refptr +MakeChromeComponentUpdaterConfigurator(const base::CommandLine* cmdline, + PrefService* pref_service) { + return base::MakeRefCounted(cmdline, pref_service); +} + +} // namespace component_updater diff --git a/chromium_src/components/component_updater/component_updater_service.cc b/chromium_src/components/component_updater/component_updater_service.cc deleted file mode 100644 index 75487e0156c..00000000000 --- a/chromium_src/components/component_updater/component_updater_service.cc +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (c) 2019 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 "components/component_updater/component_updater_service.h" - -#include "brave/browser/component_updater/brave_crx_update_service.h" -#include "components/update_client/crx_downloader.h" -#include "components/update_client/ping_manager.h" -#include "components/update_client/update_checker.h" -#include "components/update_client/update_client_internal.h" - -#define ComponentUpdateServiceFactory ComponentUpdateServiceFactory_ChromiumImpl -#include "../../../../components/component_updater/component_updater_service.cc" // NOLINT -#undef ComponentUpdateServiceFactory - -using update_client::CrxDownloader; -using update_client::PingManager; -using update_client::UpdateChecker; -using update_client::UpdateClientImpl; - -namespace component_updater { - -std::unique_ptr ComponentUpdateServiceFactory( - scoped_refptr config, - std::unique_ptr scheduler) { - DCHECK(config); - DCHECK(scheduler); - auto update_client = base::MakeRefCounted( - config, base::MakeRefCounted(config), &UpdateChecker::Create, - &CrxDownloader::Create); - return std::make_unique(config, std::move(scheduler), - std::move(update_client)); -} - -} // namespace component_updater diff --git a/common/BUILD.gn b/common/BUILD.gn index caadf808411..574fe5434f1 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -79,6 +79,8 @@ source_set("common") { "extensions/brave_extensions_api_provider.h", "extensions/extension_constants.cc", "extensions/extension_constants.h", + "extensions/whitelist.cc", + "extensions/whitelist.h", ] public_deps = [ diff --git a/common/extensions/whitelist.cc b/common/extensions/whitelist.cc new file mode 100644 index 00000000000..76e6dc2c4b2 --- /dev/null +++ b/common/extensions/whitelist.cc @@ -0,0 +1,45 @@ +/* Copyright (c) 2019 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/common/extensions/whitelist.h" + +#include "brave/common/extensions/extension_constants.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" + +// This is a hardcoded list of vetted extensions, mostly +// the built-in ones that ship with Brave or are used for +// unit tests. +// Don't add new extensions to this list. Add them to +// the files managed by the extension whitelist service. +const std::vector kVettedExtensions{ + brave_extension_id, + brave_rewards_extension_id, + brave_sync_extension_id, + brave_webtorrent_extension_id, + crl_set_extension_id, + ethereum_remote_client_extension_id, + hangouts_extension_id, + widevine_extension_id, + brave_component_updater::kLocalDataFilesComponentId, + // Web Store + "ahfgeienlihckogmohjhadlkjgocpleb", + // Brave Automation Extension + "aapnijgdinlhnhlmodcfapnahmbfebeb", + // Test ID: Brave Default Ad Block Updater + "naccapggpomhlhoifnlebfoocegenbol", + // Test ID: Brave Regional Ad Block Updater + // (9852EFC4-99E4-4F2D-A915-9C3196C7A1DE) + "dlpmaigjliompnelofkljgcmlenklieh", + // Test ID: Brave Tracking Protection Updater + "eclbkhjphkhalklhipiicaldjbnhdfkc", + // Test ID: PDFJS + "kpbdcmcgkedhpbcpfndimofjnefgjidd", + // Test ID: Brave HTTPS Everywhere Updater + "bhlmpjhncoojbkemjkeppfahkglffilp", + // Test ID: Brave Tor Client Updater + "ngicbhhaldfdgmjhilmnleppfpmkgbbk", + // Chromium PDF Viewer. + "mhjfbmdgcfjbbpaeojofohoefgiehjai", +}; diff --git a/common/extensions/whitelist.h b/common/extensions/whitelist.h new file mode 100644 index 00000000000..70f286f649d --- /dev/null +++ b/common/extensions/whitelist.h @@ -0,0 +1,14 @@ +/* Copyright (c) 2019 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/. */ + +#ifndef BRAVE_COMMON_EXTENSIONS_WHITELIST_H_ +#define BRAVE_COMMON_EXTENSIONS_WHITELIST_H_ + +#include +#include + +extern const std::vector kVettedExtensions; + +#endif // BRAVE_COMMON_EXTENSIONS_WHITELIST_H_ diff --git a/components/brave_component_updater/browser/BUILD.gn b/components/brave_component_updater/browser/BUILD.gn index 74bc1982118..d7418994bc3 100644 --- a/components/brave_component_updater/browser/BUILD.gn +++ b/components/brave_component_updater/browser/BUILD.gn @@ -1,3 +1,5 @@ +import("//extensions/buildflags/buildflags.gni") + source_set("browser") { sources = [ "brave_component.cc", @@ -13,4 +15,16 @@ source_set("browser") { deps = [ "//base", ] + + if (enable_extensions) { + sources += [ + "extension_whitelist_service.cc", + "extension_whitelist_service.h", + ] + + deps += [ + "//brave/vendor/extension-whitelist/brave:extension-whitelist", + "//extensions/common", + ] + } } diff --git a/components/brave_shields/browser/extension_whitelist_service.cc b/components/brave_component_updater/browser/extension_whitelist_service.cc similarity index 75% rename from components/brave_shields/browser/extension_whitelist_service.cc rename to components/brave_component_updater/browser/extension_whitelist_service.cc index ca1196c2e56..6775c832bc9 100644 --- a/components/brave_shields/browser/extension_whitelist_service.cc +++ b/components/brave_component_updater/browser/extension_whitelist_service.cc @@ -3,7 +3,7 @@ * 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/brave_shields/browser/extension_whitelist_service.h" +#include "brave/components/brave_component_updater/browser/extension_whitelist_service.h" #include @@ -11,13 +11,18 @@ #include "base/task_runner_util.h" #include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/vendor/extension-whitelist/extension_whitelist_parser.h" +#include "extensions/common/extension.h" -namespace brave_shields { +using extensions::Extension; + +namespace brave_component_updater { ExtensionWhitelistService::ExtensionWhitelistService( - LocalDataFilesService* local_data_files_service) + LocalDataFilesService* local_data_files_service, + const std::vector& whitelist) : LocalDataFilesObserver(local_data_files_service), extension_whitelist_client_(new ExtensionWhitelistParser()), + whitelist_(whitelist), weak_factory_(this) { } @@ -38,6 +43,18 @@ bool ExtensionWhitelistService::IsBlacklisted( return extension_whitelist_client_->isBlacklisted(extension_id.c_str()); } +bool ExtensionWhitelistService::IsVetted(const Extension* extension) const { + return ExtensionWhitelistService::IsVetted(extension->id()); +} + +bool ExtensionWhitelistService::IsVetted(const std::string& id) const { + if (std::find(whitelist_.begin(), whitelist_.end(), id) != + whitelist_.end()) + return true; + + return IsWhitelisted(id); +} + void ExtensionWhitelistService::OnComponentReady( const std::string& component_id, const base::FilePath& install_dir, @@ -75,8 +92,10 @@ void ExtensionWhitelistService::OnGetDATFileData(GetDATFileDataResult result) { /////////////////////////////////////////////////////////////////////////////// std::unique_ptr ExtensionWhitelistServiceFactory( - LocalDataFilesService* local_data_files_service) { - return std::make_unique(local_data_files_service); + LocalDataFilesService* local_data_files_service, + const std::vector& whitelist) { + return std::make_unique(local_data_files_service, + whitelist); } -} // namespace brave_shields +} // namespace brave_component_updater diff --git a/components/brave_shields/browser/extension_whitelist_service.h b/components/brave_component_updater/browser/extension_whitelist_service.h similarity index 72% rename from components/brave_shields/browser/extension_whitelist_service.h rename to components/brave_component_updater/browser/extension_whitelist_service.h index 79fd9dafe44..227cc353b2a 100644 --- a/components/brave_shields/browser/extension_whitelist_service.h +++ b/components/brave_component_updater/browser/extension_whitelist_service.h @@ -3,8 +3,8 @@ * 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/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_EXTENSION_WHITELIST_SERVICE_H_ -#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_EXTENSION_WHITELIST_SERVICE_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_EXTENSION_WHITELIST_SERVICE_H_ +#define BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_EXTENSION_WHITELIST_SERVICE_H_ #include #include @@ -22,11 +22,11 @@ class ExtensionWhitelistParser; class BraveExtensionProviderTest; class BravePDFDownloadTest; -using brave_component_updater::LocalDataFilesObserver; -using brave_component_updater::LocalDataFilesService; +namespace extensions { +class Extension; +} -// TODO(bridiver) - move out of brave shields -namespace brave_shields { +namespace brave_component_updater { // The brave shields service in charge of extension whitelist class ExtensionWhitelistService : public LocalDataFilesObserver { @@ -35,11 +35,14 @@ class ExtensionWhitelistService : public LocalDataFilesObserver { brave_component_updater::LoadDATFileDataResult; explicit ExtensionWhitelistService( - LocalDataFilesService* local_data_files_service); + LocalDataFilesService* local_data_files_service, + const std::vector& whitelist); ~ExtensionWhitelistService() override; bool IsWhitelisted(const std::string& extension_id) const; bool IsBlacklisted(const std::string& extension_id) const; + bool IsVetted(const std::string& extension_id) const; + bool IsVetted(const extensions::Extension* extension) const; // implementation of LocalDataFilesObserver void OnComponentReady(const std::string& component_id, @@ -52,9 +55,10 @@ class ExtensionWhitelistService : public LocalDataFilesObserver { void OnGetDATFileData(GetDATFileDataResult result); + SEQUENCE_CHECKER(sequence_checker_); std::unique_ptr extension_whitelist_client_; brave_component_updater::DATFileDataBuffer buffer_; - SEQUENCE_CHECKER(sequence_checker_); + std::vector whitelist_; base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(ExtensionWhitelistService); @@ -62,8 +66,9 @@ class ExtensionWhitelistService : public LocalDataFilesObserver { // Creates the ExtensionWhitelistService std::unique_ptr ExtensionWhitelistServiceFactory( - LocalDataFilesService* local_data_files_service); + LocalDataFilesService* local_data_files_service, + const std::vector& whitelist); -} // namespace brave_shields +} // namespace brave_component_updater -#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_EXTENSION_WHITELIST_SERVICE_H_ +#endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_EXTENSION_WHITELIST_SERVICE_H_ diff --git a/components/brave_shields/browser/BUILD.gn b/components/brave_shields/browser/BUILD.gn index fd2071eabca..73a2af79bd7 100644 --- a/components/brave_shields/browser/BUILD.gn +++ b/components/brave_shields/browser/BUILD.gn @@ -68,17 +68,6 @@ source_set("browser") { "//third_party/leveldatabase", "//url", ] - - if (enable_extensions) { - sources += [ - "extension_whitelist_service.cc", - "extension_whitelist_service.h", - ] - - deps += [ - "//brave/vendor/extension-whitelist/brave:extension-whitelist", - ] - } } if (is_mac) { diff --git a/patches/components-component_updater-component_updater_service_internal.h.patch b/patches/components-component_updater-component_updater_service_internal.h.patch deleted file mode 100644 index 4729da7d5cd..00000000000 --- a/patches/components-component_updater-component_updater_service_internal.h.patch +++ /dev/null @@ -1,20 +0,0 @@ -diff --git a/components/component_updater/component_updater_service_internal.h b/components/component_updater/component_updater_service_internal.h -index 341fbf78a96bb1b0b8e10bf9579dea9b930bec13..5d1d80b412cc8669c0acfd3b707651af27b62809 100644 ---- a/components/component_updater/component_updater_service_internal.h -+++ b/components/component_updater/component_updater_service_internal.h -@@ -26,6 +26,7 @@ enum class Error; - - namespace component_updater { - -+class BraveCrxUpdateService; - class OnDemandUpdater; - - using CrxInstaller = update_client::CrxInstaller; -@@ -66,6 +67,7 @@ class CrxUpdateService : public ComponentUpdateService, - Callback callback) override; - - private: -+ friend class BraveCrxUpdateService; - void Start(); - void Stop(); -