From 3dc3cb46911bfa40d69db35b8a8796b8aa2b1279 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim <43750833+pilgrim-brave@users.noreply.github.com> Date: Wed, 31 Mar 2021 10:09:28 -0400 Subject: [PATCH 1/2] Merge pull request #8320 from brave/mpilgrim_ua_mobile Fix farbled user agent on mobile --- browser/brave_content_browser_client.cc | 28 +++--- browser/brave_content_browser_client.h | 9 +- ...avigator_useragent_farbling_browsertest.cc | 91 +++++++++++-------- 3 files changed, 76 insertions(+), 52 deletions(-) diff --git a/browser/brave_content_browser_client.cc b/browser/brave_content_browser_client.cc index c50b26e2e720..97920ebaba2f 100644 --- a/browser/brave_content_browser_client.cc +++ b/browser/brave_content_browser_client.cc @@ -179,7 +179,11 @@ std::string GetUserAgentPlatform() { } std::string GetMinimalProduct() { - return version_info::GetProductNameAndVersionForUserAgent(); + std::string product = version_info::GetProductNameAndVersionForUserAgent(); + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kUseMobileUserAgent)) + product += " Mobile"; + return product; } std::string GetMinimalOSVersion() { @@ -503,6 +507,16 @@ void BraveContentBrowserClient::MaybeHideReferrer( } } +std::string BraveContentBrowserClient::GetMinimalUserAgent() { + std::string minimal_os_info; + base::StringAppendF(&minimal_os_info, "%s%s", GetUserAgentPlatform().c_str(), + content::BuildOSCpuInfoFromOSVersionAndCpuType( + GetMinimalOSVersion(), content::BuildCpuInfo()) + .c_str()); + return content::BuildUserAgentFromOSAndProduct(minimal_os_info, + GetMinimalProduct()); +} + std::string BraveContentBrowserClient::GetEffectiveUserAgent( content::BrowserContext* browser_context, const GURL& url) { @@ -518,16 +532,8 @@ std::string BraveContentBrowserClient::GetEffectiveUserAgent( // respect it. if (GetBraveShieldsEnabled(map, url) && (GetFingerprintingControlType(map, url) != ControlType::ALLOW) && - (ua == content::BuildUserAgentFromProduct( - version_info::GetProductNameAndVersionForUserAgent()))) { - std::string minimal_os_info; - base::StringAppendF(&minimal_os_info, "%s%s", - GetUserAgentPlatform().c_str(), - content::BuildOSCpuInfoFromOSVersionAndCpuType( - GetMinimalOSVersion(), content::BuildCpuInfo()) - .c_str()); - ua = content::BuildUserAgentFromOSAndProduct(minimal_os_info, - GetMinimalProduct()); + (ua == content::BuildUserAgentFromProduct(GetMinimalProduct()))) { + ua = GetMinimalUserAgent(); } } return ua; diff --git a/browser/brave_content_browser_client.h b/browser/brave_content_browser_client.h index b1fe510daaa4..e31157d0891b 100644 --- a/browser/brave_content_browser_client.h +++ b/browser/brave_content_browser_client.h @@ -18,6 +18,7 @@ #include "services/metrics/public/cpp/ukm_source_id.h" #include "third_party/blink/public/mojom/loader/referrer.mojom.h" +class BraveNavigatorUserAgentFarblingBrowserTest; class PrefChangeRegistrar; namespace content { @@ -102,10 +103,11 @@ class BraveContentBrowserClient : public ChromeContentBrowserClient { GURL GetEffectiveURL(content::BrowserContext* browser_context, const GURL& url) override; - static bool HandleURLOverrideRewrite(GURL* url, + static bool HandleURLOverrideRewrite( + GURL* url, content::BrowserContext* browser_context); std::vector> - CreateThrottlesForNavigation(content::NavigationHandle* handle) override; + CreateThrottlesForNavigation(content::NavigationHandle* handle) override; std::string GetEffectiveUserAgent(content::BrowserContext* browser_context, const GURL& url) override; @@ -115,10 +117,13 @@ class BraveContentBrowserClient : public ChromeContentBrowserClient { content::RenderProcessHost* render_process_host) override; private: + friend class ::BraveNavigatorUserAgentFarblingBrowserTest; + uint64_t session_token_; uint64_t incognito_session_token_; void OnAllowGoogleAuthChanged(); + std::string GetMinimalUserAgent(); std::unique_ptr pref_change_registrar_; diff --git a/browser/farbling/brave_navigator_useragent_farbling_browsertest.cc b/browser/farbling/brave_navigator_useragent_farbling_browsertest.cc index e1cbfb4803ce..a6319f76ca28 100644 --- a/browser/farbling/brave_navigator_useragent_farbling_browsertest.cc +++ b/browser/farbling/brave_navigator_useragent_farbling_browsertest.cc @@ -35,8 +35,7 @@ using brave_shields::ControlType; using content::TitleWatcher; -const char kUserAgentScript[] = - "domAutomationController.send(navigator.userAgent);"; +const char kUserAgentScript[] = "navigator.userAgent"; class BraveNavigatorUserAgentFarblingBrowserTest : public InProcessBrowserTest { public: @@ -78,9 +77,8 @@ class BraveNavigatorUserAgentFarblingBrowserTest : public InProcessBrowserTest { return user_agents_[user_agents_.size() - 1]; } - std::string effective_user_agent() { - return browser_content_client_->GetEffectiveUserAgent( - browser()->profile(), contents()->GetLastCommittedURL()); + std::string minimal_user_agent() { + return browser_content_client_->GetMinimalUserAgent(); } HostContentSettingsMap* content_settings() { @@ -105,20 +103,6 @@ class BraveNavigatorUserAgentFarblingBrowserTest : public InProcessBrowserTest { embedded_test_server()->GetURL(domain, "/")); } - template - int ExecScriptGetInt(const std::string& script, T* frame) { - int value; - EXPECT_TRUE(ExecuteScriptAndExtractInt(frame, script, &value)); - return value; - } - - template - std::string ExecScriptGetStr(const std::string& script, T* frame) { - std::string value; - EXPECT_TRUE(ExecuteScriptAndExtractString(frame, script, &value)); - return value; - } - content::WebContents* contents() { return browser()->tab_strip_model()->GetActiveWebContents(); } @@ -134,6 +118,15 @@ class BraveNavigatorUserAgentFarblingBrowserTest : public InProcessBrowserTest { std::vector user_agents_; }; +class BraveNavigatorUserAgentFarblingMobileBrowserTest + : public BraveNavigatorUserAgentFarblingBrowserTest { + void SetUpCommandLine(base::CommandLine* command_line) override { +#if defined(OS_ANDROID) + command_line->AppendSwitch(switches::kUseMobileUserAgent); +#endif + } +}; + // Tests results of farbling user agent IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingBrowserTest, FarbleNavigatorUserAgent) { @@ -143,32 +136,36 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingBrowserTest, GURL url_b = embedded_test_server()->GetURL(domain_b, "/simple.html"); GURL url_z = embedded_test_server()->GetURL(domain_z, "/simple.html"); // get real navigator.userAgent - std::string real_ua = embedder_support::GetUserAgent(); + std::string unfarbled_ua = embedder_support::GetUserAgent(); // Farbling level: off AllowFingerprinting(domain_b); NavigateToURLUntilLoadStop(url_b); - EXPECT_EQ(last_requested_http_user_agent(), real_ua); - std::string off_ua_b = ExecScriptGetStr(kUserAgentScript, contents()); - // user agent should be the same as the real user agent - EXPECT_EQ(off_ua_b, real_ua); + // HTTP User-Agent header we just sent in that request should be the same as + // the unfarbled user agent + EXPECT_EQ(last_requested_http_user_agent(), unfarbled_ua); + auto off_ua_b = EvalJs(contents(), kUserAgentScript); + // user agent should be the same as the unfarbled user agent + EXPECT_EQ(unfarbled_ua, off_ua_b); AllowFingerprinting(domain_z); NavigateToURLUntilLoadStop(url_z); // HTTP User-Agent header we just sent in that request should be the same as - // the real user agent - EXPECT_EQ(last_requested_http_user_agent(), real_ua); - std::string off_ua_z = ExecScriptGetStr(kUserAgentScript, contents()); + // the unfarbled user agent + EXPECT_EQ(last_requested_http_user_agent(), unfarbled_ua); + auto off_ua_z = EvalJs(contents(), kUserAgentScript); // user agent should be the same on every domain if farbling is off - EXPECT_EQ(off_ua_z, real_ua); + EXPECT_EQ(unfarbled_ua, off_ua_z); // Farbling level: default // navigator.userAgent may be farbled, but the farbling is not // domain-specific SetFingerprintingDefault(domain_b); NavigateToURLUntilLoadStop(url_b); - std::string default_ua_b = ExecScriptGetStr(kUserAgentScript, contents()); + std::string default_ua_b = + EvalJs(contents(), kUserAgentScript).ExtractString(); SetFingerprintingDefault(domain_z); NavigateToURLUntilLoadStop(url_z); - std::string default_ua_z = ExecScriptGetStr(kUserAgentScript, contents()); + std::string default_ua_z = + EvalJs(contents(), kUserAgentScript).ExtractString(); // user agent should be the same on every domain if farbling is default EXPECT_EQ(default_ua_b, default_ua_z); @@ -179,12 +176,12 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingBrowserTest, BlockFingerprinting(domain_b); // test known values NavigateToURLUntilLoadStop(url_b); - std::string max_ua_b = ExecScriptGetStr(kUserAgentScript, contents()); - EXPECT_EQ(max_ua_b, default_ua_b + " "); + auto max_ua_b = EvalJs(contents(), kUserAgentScript); + EXPECT_EQ(default_ua_b + " ", max_ua_b); BlockFingerprinting(domain_z); NavigateToURLUntilLoadStop(url_z); - std::string max_ua_z = ExecScriptGetStr(kUserAgentScript, contents()); - EXPECT_EQ(max_ua_z, default_ua_z + " "); + auto max_ua_z = EvalJs(contents(), kUserAgentScript); + EXPECT_EQ(default_ua_z + " ", max_ua_z); // test that iframes also inherit the farbled user agent // (farbling level is still maximum) @@ -202,8 +199,8 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingBrowserTest, NavigateToURLUntilLoadStop(embedded_test_server()->GetURL( domain_b, "/navigator/workers-useragent.html")); // HTTP User-Agent header we just sent in that request should be the same as - // the real user agent - EXPECT_EQ(last_requested_http_user_agent(), effective_user_agent()); + // the farbled user agent + EXPECT_EQ(last_requested_http_user_agent(), minimal_user_agent()); TitleWatcher watcher3(contents(), expected_title); EXPECT_EQ(expected_title, watcher3.WaitAndGetTitle()); @@ -211,7 +208,23 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingBrowserTest, // verify that user agent is reset properly after having been farbled AllowFingerprinting(domain_b); NavigateToURLUntilLoadStop(url_b); - EXPECT_EQ(last_requested_http_user_agent(), real_ua); - std::string off_ua_b2 = ExecScriptGetStr(kUserAgentScript, contents()); - EXPECT_EQ(off_ua_b, off_ua_b2); + EXPECT_EQ(last_requested_http_user_agent(), unfarbled_ua); + auto off_ua_b2 = EvalJs(contents(), kUserAgentScript); + EXPECT_EQ(off_ua_b.ExtractString(), off_ua_b2); +} + +// Tests results of farbling with mobile user agent +IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingMobileBrowserTest, + FarbleNavigatorUserAgentMobile) { + base::string16 expected_title = base::ASCIIToUTF16("pass"); + std::string domain_b = "b.com"; + GURL url_b = embedded_test_server()->GetURL(domain_b, "/simple.html"); + SetFingerprintingDefault(domain_b); + NavigateToURLUntilLoadStop(url_b); + std::string default_ua_b = + EvalJs(contents(), kUserAgentScript).ExtractString(); + BlockFingerprinting(domain_b); + NavigateToURLUntilLoadStop(url_b); + EXPECT_EQ(default_ua_b + " ", EvalJs(contents(), kUserAgentScript)); + EXPECT_EQ(last_requested_http_user_agent(), minimal_user_agent()); } From d8d8077a472365fe3c8316c3797e2a0e90370be2 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim <43750833+pilgrim-brave@users.noreply.github.com> Date: Tue, 20 Apr 2021 20:00:06 -0400 Subject: [PATCH 2/2] Merge pull request #8562 from brave/mpilgrim_remove_ua_farbling Remove UA farbling on all platforms and unconditionally exclude Android model --- browser/brave_content_browser_client.cc | 108 ------------------ browser/brave_content_browser_client.h | 6 - ...avigator_useragent_farbling_browsertest.cc | 33 +----- .../renderer_host/navigation_request.cc | 8 -- chromium_src/content/common/DEPS | 4 + .../user_agent.cc} | 10 +- ...-renderer_host-navigation_request.cc.patch | 20 +--- patches/content-common-user_agent.cc.patch | 12 ++ 8 files changed, 25 insertions(+), 176 deletions(-) create mode 100644 chromium_src/content/common/DEPS rename chromium_src/content/{browser/worker_host/shared_worker_host.cc => common/user_agent.cc} (52%) create mode 100644 patches/content-common-user_agent.cc.patch diff --git a/browser/brave_content_browser_client.cc b/browser/brave_content_browser_client.cc index 97920ebaba2f..d1e15ce7e14c 100644 --- a/browser/brave_content_browser_client.cc +++ b/browser/brave_content_browser_client.cc @@ -59,7 +59,6 @@ #include "content/public/browser/navigation_handle.h" #include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" -#include "content/public/common/user_agent.h" #include "extensions/buildflags/buildflags.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" @@ -136,81 +135,6 @@ using extensions::ChromeContentBrowserClientExtensionsPart; namespace { -#if defined(OS_MAC) -int32_t GetMinimumBugfixVersion(int32_t os_major_version, - int32_t os_minor_version) { - if (os_major_version == 10) { - switch (os_minor_version) { - case 9: - case 10: - return 5; - case 11: - case 12: - case 13: - case 14: - return 6; - case 15: - return 7; - } - } else if (os_major_version == 11) { - switch (os_minor_version) { - case 0: - return 1; - case 1: - return 0; - } - } - return 0; -} -#endif - -std::string GetUserAgentPlatform() { -#if defined(OS_WIN) - return ""; -#elif defined(OS_MAC) - return "Macintosh; "; -#elif defined(USE_X11) - return "X11; "; -#elif defined(OS_ANDROID) - return "Linux; "; -#elif defined(OS_POSIX) - return "Unknown; "; -#endif -} - -std::string GetMinimalProduct() { - std::string product = version_info::GetProductNameAndVersionForUserAgent(); - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kUseMobileUserAgent)) - product += " Mobile"; - return product; -} - -std::string GetMinimalOSVersion() { - std::string os_version; - -#if defined(OS_MAC) - int32_t os_major_version = 0; - int32_t os_minor_version = 0; - int32_t os_bugfix_version = 0; - base::SysInfo::OperatingSystemVersionNumbers( - &os_major_version, &os_minor_version, &os_bugfix_version); - // change from upstream: compute bugfix version - os_bugfix_version = - std::max(os_bugfix_version, - GetMinimumBugfixVersion(os_major_version, os_minor_version)); - base::StringAppendF(&os_version, "%d_%d_%d", os_major_version, - os_minor_version, os_bugfix_version); -#else - // change from upstream: exclude Android model - os_version = - content::GetOSVersion(content::IncludeAndroidBuildNumber::Exclude, - content::IncludeAndroidModel::Exclude); -#endif - - return os_version; -} - bool HandleURLReverseOverrideRewrite(GURL* url, content::BrowserContext* browser_context) { if (BraveContentBrowserClient::HandleURLOverrideRewrite(url, browser_context)) @@ -507,38 +431,6 @@ void BraveContentBrowserClient::MaybeHideReferrer( } } -std::string BraveContentBrowserClient::GetMinimalUserAgent() { - std::string minimal_os_info; - base::StringAppendF(&minimal_os_info, "%s%s", GetUserAgentPlatform().c_str(), - content::BuildOSCpuInfoFromOSVersionAndCpuType( - GetMinimalOSVersion(), content::BuildCpuInfo()) - .c_str()); - return content::BuildUserAgentFromOSAndProduct(minimal_os_info, - GetMinimalProduct()); -} - -std::string BraveContentBrowserClient::GetEffectiveUserAgent( - content::BrowserContext* browser_context, - const GURL& url) { - std::string ua = GetUserAgent(); - if (Profile* profile = Profile::FromBrowserContext(browser_context)) { - auto* map = HostContentSettingsMapFactory::GetForProfile(profile); - // If shields is off or farbling is off, do not override. - // Also, we construct real user agent two different ways, through the - // browser client's higher level utility function and through direct - // functions. If they differ, there's some sort of override happening. Maybe - // the end user is forcing the user agent via command line flags. Or maybe - // they turned on the "freeze user agent" flag. Whatever it is, we want to - // respect it. - if (GetBraveShieldsEnabled(map, url) && - (GetFingerprintingControlType(map, url) != ControlType::ALLOW) && - (ua == content::BuildUserAgentFromProduct(GetMinimalProduct()))) { - ua = GetMinimalUserAgent(); - } - } - return ua; -} - GURL BraveContentBrowserClient::GetEffectiveURL( content::BrowserContext* browser_context, const GURL& url) { diff --git a/browser/brave_content_browser_client.h b/browser/brave_content_browser_client.h index e31157d0891b..d23e4cb8fc86 100644 --- a/browser/brave_content_browser_client.h +++ b/browser/brave_content_browser_client.h @@ -18,7 +18,6 @@ #include "services/metrics/public/cpp/ukm_source_id.h" #include "third_party/blink/public/mojom/loader/referrer.mojom.h" -class BraveNavigatorUserAgentFarblingBrowserTest; class PrefChangeRegistrar; namespace content { @@ -109,21 +108,16 @@ class BraveContentBrowserClient : public ChromeContentBrowserClient { std::vector> CreateThrottlesForNavigation(content::NavigationHandle* handle) override; - std::string GetEffectiveUserAgent(content::BrowserContext* browser_context, - const GURL& url) override; void ExposeInterfacesToRenderer( service_manager::BinderRegistry* registry, blink::AssociatedInterfaceRegistry* associated_registry, content::RenderProcessHost* render_process_host) override; private: - friend class ::BraveNavigatorUserAgentFarblingBrowserTest; - uint64_t session_token_; uint64_t incognito_session_token_; void OnAllowGoogleAuthChanged(); - std::string GetMinimalUserAgent(); std::unique_ptr pref_change_registrar_; diff --git a/browser/farbling/brave_navigator_useragent_farbling_browsertest.cc b/browser/farbling/brave_navigator_useragent_farbling_browsertest.cc index a6319f76ca28..686e04414f97 100644 --- a/browser/farbling/brave_navigator_useragent_farbling_browsertest.cc +++ b/browser/farbling/brave_navigator_useragent_farbling_browsertest.cc @@ -77,10 +77,6 @@ class BraveNavigatorUserAgentFarblingBrowserTest : public InProcessBrowserTest { return user_agents_[user_agents_.size() - 1]; } - std::string minimal_user_agent() { - return browser_content_client_->GetMinimalUserAgent(); - } - HostContentSettingsMap* content_settings() { return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); } @@ -118,15 +114,6 @@ class BraveNavigatorUserAgentFarblingBrowserTest : public InProcessBrowserTest { std::vector user_agents_; }; -class BraveNavigatorUserAgentFarblingMobileBrowserTest - : public BraveNavigatorUserAgentFarblingBrowserTest { - void SetUpCommandLine(base::CommandLine* command_line) override { -#if defined(OS_ANDROID) - command_line->AppendSwitch(switches::kUseMobileUserAgent); -#endif - } -}; - // Tests results of farbling user agent IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingBrowserTest, FarbleNavigatorUserAgent) { @@ -199,8 +186,8 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingBrowserTest, NavigateToURLUntilLoadStop(embedded_test_server()->GetURL( domain_b, "/navigator/workers-useragent.html")); // HTTP User-Agent header we just sent in that request should be the same as - // the farbled user agent - EXPECT_EQ(last_requested_http_user_agent(), minimal_user_agent()); + // the unfarbled user agent + EXPECT_EQ(last_requested_http_user_agent(), unfarbled_ua); TitleWatcher watcher3(contents(), expected_title); EXPECT_EQ(expected_title, watcher3.WaitAndGetTitle()); @@ -212,19 +199,3 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingBrowserTest, auto off_ua_b2 = EvalJs(contents(), kUserAgentScript); EXPECT_EQ(off_ua_b.ExtractString(), off_ua_b2); } - -// Tests results of farbling with mobile user agent -IN_PROC_BROWSER_TEST_F(BraveNavigatorUserAgentFarblingMobileBrowserTest, - FarbleNavigatorUserAgentMobile) { - base::string16 expected_title = base::ASCIIToUTF16("pass"); - std::string domain_b = "b.com"; - GURL url_b = embedded_test_server()->GetURL(domain_b, "/simple.html"); - SetFingerprintingDefault(domain_b); - NavigateToURLUntilLoadStop(url_b); - std::string default_ua_b = - EvalJs(contents(), kUserAgentScript).ExtractString(); - BlockFingerprinting(domain_b); - NavigateToURLUntilLoadStop(url_b); - EXPECT_EQ(default_ua_b + " ", EvalJs(contents(), kUserAgentScript)); - EXPECT_EQ(last_requested_http_user_agent(), minimal_user_agent()); -} diff --git a/chromium_src/content/browser/renderer_host/navigation_request.cc b/chromium_src/content/browser/renderer_host/navigation_request.cc index 68ae775271d7..df4ec032a22f 100644 --- a/chromium_src/content/browser/renderer_host/navigation_request.cc +++ b/chromium_src/content/browser/renderer_host/navigation_request.cc @@ -44,14 +44,6 @@ GURL GetTopDocumentGURL(content::FrameTreeNode* frame_tree_node) { browser_context, common_params_->url, \ GetTopDocumentGURL(frame_tree_node_), &common_params_->referrer); -#define BRAVE_NAVIGATION_REQUEST_ADD_ADDITIONAL_REQUEST_HEADERS \ - ? GetContentClient()->browser()->GetEffectiveUserAgent(browser_context, url) - -#define BRAVE_NAVIGATION_REQUEST_SET_IS_OVERRIDING_USERAGENT \ - ? GetContentClient()->browser()->GetEffectiveUserAgent( \ - frame_tree_node_->navigator().controller().GetBrowserContext(), \ - GetURL()) - #include "../../../../../content/browser/renderer_host/navigation_request.cc" #undef BRAVE_ONSTARTCHECKSCOMPLETE_MAYBEHIDEREFERRER diff --git a/chromium_src/content/common/DEPS b/chromium_src/content/common/DEPS new file mode 100644 index 000000000000..0109200c6d71 --- /dev/null +++ b/chromium_src/content/common/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+../../../../content/common", + "+content/public/common", +] diff --git a/chromium_src/content/browser/worker_host/shared_worker_host.cc b/chromium_src/content/common/user_agent.cc similarity index 52% rename from chromium_src/content/browser/worker_host/shared_worker_host.cc rename to chromium_src/content/common/user_agent.cc index 53cba38f5cef..3923ef87961b 100644 --- a/chromium_src/content/browser/worker_host/shared_worker_host.cc +++ b/chromium_src/content/common/user_agent.cc @@ -3,9 +3,11 @@ * 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 "content/browser/worker_host/shared_worker_host.h" +#include "content/public/common/user_agent.h" -#define GetUserAgent() \ - GetEffectiveUserAgent(GetProcessHost()->GetBrowserContext(), instance_.url()) +#define BRAVE_GET_ANDROID_OS_INFO \ + include_android_model = IncludeAndroidModel::Exclude; -#include "../../../../../content/browser/worker_host/shared_worker_host.cc" +#include "../../../../content/common/user_agent.cc" + +#undef BRAVE_GET_ANDROID_OS_INFO diff --git a/patches/content-browser-renderer_host-navigation_request.cc.patch b/patches/content-browser-renderer_host-navigation_request.cc.patch index c803fc603927..50d3388fdbbc 100644 --- a/patches/content-browser-renderer_host-navigation_request.cc.patch +++ b/patches/content-browser-renderer_host-navigation_request.cc.patch @@ -1,16 +1,7 @@ diff --git a/content/browser/renderer_host/navigation_request.cc b/content/browser/renderer_host/navigation_request.cc -index dae1c91d2d720f09b9a0840d829d4cc8600232ba..7e987915f766bd320cb1db2924047931f4adf4df 100644 +index dae1c91d2d720f09b9a0840d829d4cc8600232ba..0f19c1307b05eb1fb4aab124c992c2f6474598a7 100644 --- a/content/browser/renderer_host/navigation_request.cc +++ b/content/browser/renderer_host/navigation_request.cc -@@ -302,7 +302,7 @@ void AddAdditionalRequestHeaders( - headers->SetHeaderIfMissing( - net::HttpRequestHeaders::kUserAgent, - user_agent_override.empty() -- ? GetContentClient()->browser()->GetUserAgent() -+ BRAVE_NAVIGATION_REQUEST_ADD_ADDITIONAL_REQUEST_HEADERS - : user_agent_override); - - if (!render_prefs.enable_referrers) { @@ -2041,6 +2041,7 @@ void NavigationRequest::OnRequestRedirected( common_params_->url = redirect_info.new_url; common_params_->method = redirect_info.new_method; @@ -27,12 +18,3 @@ index dae1c91d2d720f09b9a0840d829d4cc8600232ba..7e987915f766bd320cb1db2924047931 // TODO(clamy): Avoid cloning the navigation params and create the // ResourceRequest directly here. std::vector> interceptor; -@@ -5413,7 +5415,7 @@ void NavigationRequest::SetIsOverridingUserAgent(bool override_ua) { - auto user_agent_override = GetUserAgentOverride(); - headers.SetHeader(net::HttpRequestHeaders::kUserAgent, - user_agent_override.empty() -- ? GetContentClient()->browser()->GetUserAgent() -+ BRAVE_NAVIGATION_REQUEST_SET_IS_OVERRIDING_USERAGENT - : user_agent_override); - BrowserContext* browser_context = - frame_tree_node_->navigator().controller().GetBrowserContext(); diff --git a/patches/content-common-user_agent.cc.patch b/patches/content-common-user_agent.cc.patch new file mode 100644 index 000000000000..b06e2cf51592 --- /dev/null +++ b/patches/content-common-user_agent.cc.patch @@ -0,0 +1,12 @@ +diff --git a/content/common/user_agent.cc b/content/common/user_agent.cc +index 104986360e1c593fe9db99b9cb54fa2385c0731d..7a9e6990d16a46734fe42f5081b5dfaeccd4292f 100644 +--- a/content/common/user_agent.cc ++++ b/content/common/user_agent.cc +@@ -280,6 +280,7 @@ std::string GetAndroidOSInfo( + + // Send information about the device. + bool semicolon_inserted = false; ++ BRAVE_GET_ANDROID_OS_INFO + if (include_android_model == IncludeAndroidModel::Include) { + std::string android_device_name = BuildModelInfo(); + if (!android_device_name.empty()) {