diff --git a/app/brave_main_delegate.cc b/app/brave_main_delegate.cc index a2ea04be710d..6c7ccd5ec13c 100644 --- a/app/brave_main_delegate.cc +++ b/app/brave_main_delegate.cc @@ -18,6 +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/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" @@ -29,6 +31,7 @@ #include "chrome/common/chrome_switches.h" #include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_payments_features.h" +#include "components/component_updater/component_updater_switches.h" #include "components/dom_distiller/core/dom_distiller_switches.h" #include "components/embedder_support/switches.h" #include "components/federated_learning/features/features.h" @@ -85,6 +88,21 @@ const char kBraveOriginTrialsPublicKey[] = const char kDummyUrl[] = "https://no-thanks.invalid"; +namespace { + +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) @@ -164,6 +182,10 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) { command_line.AppendSwitch(switches::kEnableDomDistiller); command_line.AppendSwitch(switches::kNoPings); + std::string source = "url-source=" + GetUpdateURLHost(); + command_line.AppendSwitchASCII(switches::kComponentUpdater, + source.c_str()); + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( embedder_support::kOriginTrialPublicKey)) { command_line.AppendSwitchASCII(embedder_support::kOriginTrialPublicKey, diff --git a/browser/extensions/BUILD.gn b/browser/extensions/BUILD.gn index ae11a21f70ab..46bd8b1f1db1 100644 --- a/browser/extensions/BUILD.gn +++ b/browser/extensions/BUILD.gn @@ -120,7 +120,6 @@ source_set("extensions") { ] configs += [ ":infura_config", - ":brave_services_config", ] deps += [ "//brave/browser/ethereum_remote_client", @@ -221,10 +220,6 @@ group("resources") { } } -config("brave_services_config") { - defines = [ "BRAVE_SERVICES_KEY=\"$brave_services_key\"" ] -} - config("infura_config") { defines = [ "BRAVE_INFURA_PROJECT_ID=\"$brave_infura_project_id\"" ] } diff --git a/browser/net/brave_common_static_redirect_network_delegate_helper.cc b/browser/net/brave_common_static_redirect_network_delegate_helper.cc index 096a6bb188cd..7ace7168b0cc 100644 --- a/browser/net/brave_common_static_redirect_network_delegate_helper.cc +++ b/browser/net/brave_common_static_redirect_network_delegate_helper.cc @@ -14,60 +14,14 @@ #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "brave/common/network_constants.h" -#include "brave/components/brave_component_updater/browser/features.h" -#include "brave/components/brave_component_updater/browser/switches.h" -#include "components/component_updater/component_updater_url_constants.h" #include "extensions/buildflags/buildflags.h" #include "extensions/common/url_pattern.h" #include "net/base/net_errors.h" -#if BUILDFLAG(ENABLE_EXTENSIONS) -#include "extensions/common/extension_urls.h" -#endif - namespace brave { -const char kUpdaterTestingEndpoint[] = "test.updater.com"; - namespace { -bool g_updater_url_host_for_testing_ = false; - -std::string GetUpdateURLHost() { - if (g_updater_url_host_for_testing_) - return kUpdaterTestingEndpoint; - - 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; -} - -// Update server checks happen from the profile context for admin policy -// installed extensions. Update server checks happen from the system context for -// normal update operations. -bool IsUpdaterURL(const GURL& gurl) { - static std::vector updater_patterns( - {URLPattern(URLPattern::SCHEME_HTTPS, - std::string(component_updater::kUpdaterJSONDefaultUrl) + "*"), - URLPattern( - URLPattern::SCHEME_HTTP, - std::string(component_updater::kUpdaterJSONFallbackUrl) + "*"), -#if BUILDFLAG(ENABLE_EXTENSIONS) - URLPattern( - URLPattern::SCHEME_HTTPS, - std::string(extension_urls::kChromeWebstoreUpdateURL) + "*") -#endif - }); - return std::any_of( - updater_patterns.begin(), updater_patterns.end(), - [&gurl](URLPattern pattern) { return pattern.MatchesURL(gurl); }); -} - bool RewriteBugReportingURL(const GURL& request_url, GURL* new_url) { GURL url("https://github.com/brave/brave-browser/issues/new"); std::string query = "title=Crash%20Report&labels=crash"; @@ -94,10 +48,6 @@ bool RewriteBugReportingURL(const GURL& request_url, GURL* new_url) { } // namespace -void SetUpdateURLHostForTesting(bool testing) { - g_updater_url_host_for_testing_ = testing; -} - int OnBeforeURLRequest_CommonStaticRedirectWork( const ResponseCallback& next_callback, std::shared_ptr ctx) { @@ -124,15 +74,6 @@ int OnBeforeURLRequest_CommonStaticRedirectWorkForGURL( URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, "*://bugs.chromium.org/p/chromium/issues/entry?*"); - if (IsUpdaterURL(request_url)) { - auto update_host = GetUpdateURLHost(); - if (!update_host.empty()) { - replacements.SetQueryStr(request_url.query_piece()); - *new_url = GURL(update_host).ReplaceComponents(replacements); - } - return net::OK; - } - if (chromecast_pattern.MatchesURL(request_url)) { replacements.SetSchemeStr("https"); replacements.SetHostStr(kBraveRedirectorProxy); diff --git a/browser/net/brave_common_static_redirect_network_delegate_helper.h b/browser/net/brave_common_static_redirect_network_delegate_helper.h index 33bd68f014fe..db08dcf3823b 100644 --- a/browser/net/brave_common_static_redirect_network_delegate_helper.h +++ b/browser/net/brave_common_static_redirect_network_delegate_helper.h @@ -14,8 +14,6 @@ class GURL; namespace brave { -extern const char kUpdaterTestingEndpoint[]; - int OnBeforeURLRequest_CommonStaticRedirectWork( const ResponseCallback& next_callback, std::shared_ptr ctx); @@ -24,7 +22,6 @@ int OnBeforeURLRequest_CommonStaticRedirectWorkForGURL( const GURL& url, GURL* new_url); -void SetUpdateURLHostForTesting(bool testing); } // namespace brave #endif // BRAVE_BROWSER_NET_BRAVE_COMMON_STATIC_REDIRECT_NETWORK_DELEGATE_HELPER_H_ diff --git a/browser/net/brave_common_static_redirect_network_delegate_helper_unittest.cc b/browser/net/brave_common_static_redirect_network_delegate_helper_unittest.cc index d1f3c8769139..15a2eab0aeea 100644 --- a/browser/net/brave_common_static_redirect_network_delegate_helper_unittest.cc +++ b/browser/net/brave_common_static_redirect_network_delegate_helper_unittest.cc @@ -11,7 +11,6 @@ #include "base/command_line.h" #include "brave/browser/net/url_context.h" #include "brave/common/network_constants.h" -#include "brave/components/brave_component_updater/browser/switches.h" #include "components/component_updater/component_updater_url_constants.h" #include "net/base/net_errors.h" #include "testing/gtest/include/gtest/gtest.h" @@ -20,53 +19,6 @@ using brave::ResponseCallback; -namespace { -const char kComponentUpdaterProxy[] = "https://componentupdater.brave.com"; -} - -TEST(BraveCommonStaticRedirectNetworkDelegateHelperTest, - ModifyComponentUpdaterURL) { - brave::SetUpdateURLHostForTesting(true); - const std::string query_string("?foo=bar"); - const GURL url(component_updater::kUpdaterJSONDefaultUrl + query_string); - auto request_info = std::make_shared(url); - const GURL expected_url( - std::string(brave::kUpdaterTestingEndpoint + query_string)); - - int rc = OnBeforeURLRequest_CommonStaticRedirectWork(ResponseCallback(), - request_info); - EXPECT_EQ(GURL(request_info->new_url_spec), expected_url); - EXPECT_EQ(rc, net::OK); -} - -TEST(BraveCommonStaticRedirectNetworkDelegateHelperTest, - ModifyComponentUpdaterURLDev) { - brave::SetUpdateURLHostForTesting(true); - base::CommandLine::ForCurrentProcess()->AppendSwitch( - brave_component_updater::kUseGoUpdateDev); - const std::string query_string("?foo=bar"); - const GURL url(component_updater::kUpdaterJSONDefaultUrl + query_string); - auto request_info = std::make_shared(url); - const GURL expected_url( - std::string(brave::kUpdaterTestingEndpoint + query_string)); - - int rc = OnBeforeURLRequest_CommonStaticRedirectWork(ResponseCallback(), - request_info); - EXPECT_EQ(GURL(request_info->new_url_spec), expected_url); - EXPECT_EQ(rc, net::OK); -} - -TEST(BraveCommonStaticRedirectNetworkDelegateHelperTest, - NoModifyComponentUpdaterURL) { - const GURL url(kComponentUpdaterProxy); - auto request_info = std::make_shared(url); - - int rc = OnBeforeURLRequest_CommonStaticRedirectWork(ResponseCallback(), - request_info); - EXPECT_EQ(request_info->new_url_spec, GURL()); - EXPECT_EQ(rc, net::OK); -} - TEST(BraveCommonStaticRedirectNetworkDelegateHelperTest, RedirectChromecastDownload) { const GURL url( diff --git a/browser/net/brave_service_key_network_delegate_helper.cc b/browser/net/brave_service_key_network_delegate_helper.cc index a84c31adc7f6..906cd8dca8da 100644 --- a/browser/net/brave_service_key_network_delegate_helper.cc +++ b/browser/net/brave_service_key_network_delegate_helper.cc @@ -21,8 +21,7 @@ int OnBeforeStartTransaction_BraveServiceKey( const ResponseCallback& next_callback, std::shared_ptr ctx) { const std::vector whitelisted_domains = { - kExtensionUpdaterDomain, GURL(UPDATER_DEV_ENDPOINT).host(), - GURL(UPDATER_PROD_ENDPOINT).host()}; + kExtensionUpdaterDomain}; const GURL url = ctx->request_url; diff --git a/browser/net/brave_service_key_network_delegate_helper_browsertest.cc b/browser/net/brave_service_key_network_delegate_helper_browsertest.cc index 95b6c26b7662..bc458c982538 100644 --- a/browser/net/brave_service_key_network_delegate_helper_browsertest.cc +++ b/browser/net/brave_service_key_network_delegate_helper_browsertest.cc @@ -85,16 +85,6 @@ IN_PROC_BROWSER_TEST_F(BraveServiceKeyNetworkDelegateBrowserTest, IN_PROC_BROWSER_TEST_F(BraveServiceKeyNetworkDelegateBrowserTest, IncludesBraveServiceKey) { - GURL target = - https_server().GetURL(GURL(UPDATER_DEV_ENDPOINT).host(), "/index.html"); - ui_test_utils::NavigateToURL(browser(), target); - EXPECT_TRUE(header_result()); - - target = - https_server().GetURL(GURL(UPDATER_PROD_ENDPOINT).host(), "/index.html"); - ui_test_utils::NavigateToURL(browser(), target); - EXPECT_TRUE(header_result()); - target = https_server().GetURL(kExtensionUpdaterDomain, "/index.html"); ui_test_utils::NavigateToURL(browser(), target); EXPECT_TRUE(header_result()); diff --git a/build/BUILD.gn b/build/BUILD.gn index fbf65421778d..8a5831afcd61 100644 --- a/build/BUILD.gn +++ b/build/BUILD.gn @@ -5,6 +5,8 @@ brave_include_dirs_ = [ "//brave/chromium_src" ] config("compiler") { include_dirs = brave_include_dirs_ + defines = brave_service_key_defines + defines += brave_updater_defines } # do not expose this as a public config anywhere diff --git a/build/features.gni b/build/features.gni index 308109b4b18d..5fafd7f2482e 100644 --- a/build/features.gni +++ b/build/features.gni @@ -1,5 +1,7 @@ declare_args() { brave_services_key = "" + updater_dev_endpoint = "" + updater_prod_endpoint = "" } brave_service_key_defines = [] @@ -8,3 +10,8 @@ if (brave_services_key != "") { } else { brave_service_key_defines += [ "BRAVE_SERVICES_KEY=\"dummytoken\"" ] } + +brave_updater_defines = [ + "UPDATER_DEV_ENDPOINT=\"$updater_dev_endpoint\"", + "UPDATER_PROD_ENDPOINT=\"$updater_prod_endpoint\"", +] diff --git a/chromium_src/components/update_client/protocol_serializer.cc b/chromium_src/components/update_client/protocol_serializer.cc new file mode 100644 index 000000000000..14f254b8a10e --- /dev/null +++ b/chromium_src/components/update_client/protocol_serializer.cc @@ -0,0 +1,26 @@ +/* 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 "components/update_client/protocol_serializer.h" + +#define BuildUpdateCheckExtraRequestHeaders \ + BuildUpdateCheckExtraRequestHeaders_ChromiumImpl +#include "../../../../components/update_client/protocol_serializer.cc" +#undef BuildUpdateCheckExtraRequestHeaders + +namespace update_client { + +base::flat_map BuildUpdateCheckExtraRequestHeaders( + const std::string& prod_id, + const base::Version& browser_version, + const std::vector& ids, + bool is_foreground) { + auto headers = BuildUpdateCheckExtraRequestHeaders_ChromiumImpl( + prod_id, browser_version, ids, is_foreground); + headers.insert({"BraveServiceKey", BRAVE_SERVICES_KEY}); + return headers; +} + +} // namespace update_client diff --git a/chromium_src/components/update_client/protocol_serializer.h b/chromium_src/components/update_client/protocol_serializer.h new file mode 100644 index 000000000000..f0650dfbc765 --- /dev/null +++ b/chromium_src/components/update_client/protocol_serializer.h @@ -0,0 +1,16 @@ +/* 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 https://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_UPDATE_CLIENT_PROTOCOL_SERIALIZER_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_UPDATE_CLIENT_PROTOCOL_SERIALIZER_H_ + +#define BuildUpdateCheckExtraRequestHeaders \ + BuildUpdateCheckExtraRequestHeaders_ChromiumImpl(); \ + base::flat_map BuildUpdateCheckExtraRequestHeaders + +#include "../../../../../components/update_client/protocol_serializer.h" +#undef BuildUpdateCheckExtraRequestHeaders + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_UPDATE_CLIENT_PROTOCOL_SERIALIZER_H_ diff --git a/components/brave_component_updater/browser/BUILD.gn b/components/brave_component_updater/browser/BUILD.gn index 196d6a0d4edf..a1e702aef87a 100644 --- a/components/brave_component_updater/browser/BUILD.gn +++ b/components/brave_component_updater/browser/BUILD.gn @@ -1,17 +1,5 @@ import("//extensions/buildflags/buildflags.gni") -declare_args() { - updater_dev_endpoint = "" - updater_prod_endpoint = "" -} - -config("updater_config") { - defines = [ - "UPDATER_DEV_ENDPOINT=\"$updater_dev_endpoint\"", - "UPDATER_PROD_ENDPOINT=\"$updater_prod_endpoint\"", - ] -} - static_library("browser") { sources = [ "brave_component.cc", @@ -29,7 +17,6 @@ static_library("browser") { "switches.h", ] - public_configs = [ ":updater_config" ] deps = [ "//base", "//components/component_updater:component_updater", diff --git a/components/greaselion/browser/greaselion_service_impl.cc b/components/greaselion/browser/greaselion_service_impl.cc index 1b853795ec53..1f8de5e1ad04 100644 --- a/components/greaselion/browser/greaselion_service_impl.cc +++ b/components/greaselion/browser/greaselion_service_impl.cc @@ -29,6 +29,8 @@ #include "base/version.h" #include "brave/components/brave_component_updater/browser/features.h" #include "brave/components/brave_component_updater/browser/switches.h" +#include "brave/common/brave_features.h" +#include "brave/common/brave_switches.h" #include "brave/components/greaselion/browser/greaselion_download_service.h" #include "brave/components/version_info//version_info.h" #include "chrome/browser/extensions/extension_service.h" diff --git a/test/BUILD.gn b/test/BUILD.gn index febc9333a00d..7275b64e7765 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -145,8 +145,6 @@ test("brave_unit_tests") { "//components/sync_device_info/device_info_sync_bridge_unittest.cc", ] - defines = brave_service_key_defines - deps = [ ":test_support", "//brave/app:command_ids",