diff --git a/app/brave_main_delegate.cc b/app/brave_main_delegate.cc index 96ce80b92723..489d532aea08 100644 --- a/app/brave_main_delegate.cc +++ b/app/brave_main_delegate.cc @@ -18,7 +18,8 @@ #include "brave/browser/brave_content_browser_client.h" #include "brave/common/brave_switches.h" #include "brave/common/resource_bundle_helper.h" -#include "brave/components/brave_component_updater/browser/brave_component.h" +#include "brave/components/brave_component_updater/browser/features.h" +#include "brave/components/brave_component_updater/browser/switches.h" #include "brave/components/speedreader/buildflags.h" #include "brave/renderer/brave_content_renderer_client.h" #include "brave/utility/brave_content_utility_client.h" @@ -87,6 +88,17 @@ const char kBraveOriginTrialsPublicKey[] = const char kDummyUrl[] = "https://no-thanks.invalid"; +std::string GetUpdateURLHost() { + const base::CommandLine& command_line = + *base::CommandLine::ForCurrentProcess(); + if (!command_line.HasSwitch(brave_component_updater::kUseGoUpdateDev) && + !base::FeatureList::IsEnabled( + brave_component_updater::kUseDevUpdaterUrl)) { + return UPDATER_PROD_ENDPOINT; + } + return UPDATER_DEV_ENDPOINT; +} + BraveMainDelegate::BraveMainDelegate() : ChromeMainDelegate() {} BraveMainDelegate::BraveMainDelegate(base::TimeTicks exe_entry_point_ticks) @@ -166,7 +178,7 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) { command_line.AppendSwitch(switches::kEnableDomDistiller); command_line.AppendSwitch(switches::kNoPings); - auto update_url = brave_component_updater::GetUpdateURLHost(); + auto update_url = GetUpdateURLHost(); if (!update_url.empty()) { std::string source = "url-source=" + update_url; command_line.AppendSwitchASCII(switches::kComponentUpdater, source.c_str()); diff --git a/build/features.gni b/build/features.gni index 5fafd7f2482e..46411294a0cc 100644 --- a/build/features.gni +++ b/build/features.gni @@ -4,6 +4,12 @@ declare_args() { updater_prod_endpoint = "" } +if (is_official_build) { + assert(brave_services_key != "") + assert(updater_dev_endpoint != "") + assert(updater_prod_endpoint != "") +} + brave_service_key_defines = [] if (brave_services_key != "") { brave_service_key_defines += [ "BRAVE_SERVICES_KEY=\"$brave_services_key\"" ] diff --git a/chromium_src/chrome/common/extensions/chrome_extensions_client.cc b/chromium_src/chrome/common/extensions/chrome_extensions_client.cc new file mode 100644 index 000000000000..62578913c695 --- /dev/null +++ b/chromium_src/chrome/common/extensions/chrome_extensions_client.cc @@ -0,0 +1,59 @@ +// Copyright (c) 2021 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 "chrome/common/extensions/chrome_extensions_client.h" + +#include "base/command_line.h" +#include "base/strings/string_split.h" +#include "components/component_updater/component_updater_switches.h" + +#define ChromeExtensionsClient ChromeExtensionsClient_ChromiumImpl +#include "../../../../../chrome/common/extensions/chrome_extensions_client.cc" +#undef ChromeExtensionsClient + +namespace extensions { + +namespace { + +std::string ParseUpdateUrlHost(std::string options) { + std::vector flags = base::SplitString( + options, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); + + for (const auto& flag : flags) { + if (flag.empty()) { + continue; + } + + std::vector values = base::SplitString( + flag, "=", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); + + if (values.size() != 2) { + continue; + } + + std::string name = base::ToLowerASCII(values[0]); + std::string value = values[1]; + + if (name == "url-source") { + return value; + } + } + + return ""; +} + +} // namespace + +void ChromeExtensionsClient::InitializeWebStoreUpdateURL() { + auto* command_line = base::CommandLine::ForCurrentProcess(); + webstore_update_url_ = GURL(ParseUpdateUrlHost( + command_line->GetSwitchValueASCII(switches::kComponentUpdater))); +} + +const GURL& ChromeExtensionsClient::GetWebstoreUpdateURL() const { + return webstore_update_url_; +} + +} // namespace extensions diff --git a/chromium_src/chrome/common/extensions/chrome_extensions_client.h b/chromium_src/chrome/common/extensions/chrome_extensions_client.h new file mode 100644 index 000000000000..a2ba871e0209 --- /dev/null +++ b/chromium_src/chrome/common/extensions/chrome_extensions_client.h @@ -0,0 +1,30 @@ +// Copyright (c) 2021 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_CHROMIUM_SRC_CHROME_COMMON_EXTENSIONS_CHROME_EXTENSIONS_CLIENT_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_COMMON_EXTENSIONS_CHROME_EXTENSIONS_CLIENT_H_ + +#define ChromeExtensionsClient ChromeExtensionsClient_ChromiumImpl +#include "../../../../../chrome/common/extensions/chrome_extensions_client.h" +#undef ChromeExtensionsClient + +namespace extensions { + +class ChromeExtensionsClient : public ChromeExtensionsClient_ChromiumImpl { + public: + using ChromeExtensionsClient_ChromiumImpl:: + ChromeExtensionsClient_ChromiumImpl; + + void InitializeWebStoreUpdateURL(); + const GURL& GetWebstoreUpdateURL() const override; + + private: + GURL webstore_update_url_; + DISALLOW_COPY_AND_ASSIGN(ChromeExtensionsClient); +}; + +} // namespace extensions + +#endif // BRAVE_CHROMIUM_SRC_CHROME_COMMON_EXTENSIONS_CHROME_EXTENSIONS_CLIENT_H_ diff --git a/chromium_src/extensions/common/extension_urls.cc b/chromium_src/extensions/common/extension_urls.cc deleted file mode 100644 index d891152239d0..000000000000 --- a/chromium_src/extensions/common/extension_urls.cc +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (c) 2021 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 "extensions/common/extension_urls.h" - -#include "brave/components/brave_component_updater/browser/brave_component.h" - -#define GetDefaultWebstoreUpdateUrl GetDefaultWebstoreUpdateUrl_ChromiumImpl -#include "../../../../extensions/common/extension_urls.cc" -#undef GetDefaultWebstoreUpdateUrl - -namespace extension_urls { - -GURL GetDefaultWebstoreUpdateUrl() { - return GURL(brave_component_updater::GetUpdateURLHost()); -} - -} // namespace extension_urls diff --git a/components/brave_component_updater/browser/brave_component.cc b/components/brave_component_updater/browser/brave_component.cc index 30402168a4d8..30a26160dfee 100644 --- a/components/brave_component_updater/browser/brave_component.cc +++ b/components/brave_component_updater/browser/brave_component.cc @@ -8,25 +8,11 @@ #include #include "base/bind.h" -#include "base/command_line.h" #include "base/logging.h" #include "base/sequenced_task_runner.h" -#include "brave/components/brave_component_updater/browser/features.h" -#include "brave/components/brave_component_updater/browser/switches.h" namespace brave_component_updater { -std::string GetUpdateURLHost() { - const base::CommandLine& command_line = - *base::CommandLine::ForCurrentProcess(); - if (!command_line.HasSwitch(brave_component_updater::kUseGoUpdateDev) && - !base::FeatureList::IsEnabled( - brave_component_updater::kUseDevUpdaterUrl)) { - return UPDATER_PROD_ENDPOINT; - } - return UPDATER_DEV_ENDPOINT; -} - BraveComponent::BraveComponent(Delegate* delegate) : delegate_(delegate), weak_factory_(this) {} diff --git a/components/brave_component_updater/browser/brave_component.h b/components/brave_component_updater/browser/brave_component.h index 099824f8fe6e..3713b58baf61 100644 --- a/components/brave_component_updater/browser/brave_component.h +++ b/components/brave_component_updater/browser/brave_component.h @@ -19,8 +19,6 @@ class PrefService; namespace brave_component_updater { -std::string GetUpdateURLHost(); - class BraveComponent { public: using ReadyCallback = base::RepeatingCallback