diff --git a/libcef/browser/content_browser_client.cc b/libcef/browser/content_browser_client.cc index 0f4e2b808..eb2007a83 100644 --- a/libcef/browser/content_browser_client.cc +++ b/libcef/browser/content_browser_client.cc @@ -56,6 +56,7 @@ #include "base/threading/thread_restrictions.h" #include "cef/grit/cef_resources.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/chrome_service.h" #include "chrome/browser/net/system_network_context_manager.h" #include "chrome/browser/plugins/plugin_info_host_impl.h" @@ -1371,27 +1372,19 @@ bool CefContentBrowserClient::HandleExternalProtocol( } std::string CefContentBrowserClient::GetProduct() const { - const base::CommandLine* command_line = - base::CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kProductVersion)) - return command_line->GetSwitchValueASCII(switches::kProductVersion); - - return GetChromeProduct(); + // Match the logic in chrome_content_browser_client.cc GetProduct() which + // will be called when the NetworkService is enabled. + return ::GetProduct(); } std::string CefContentBrowserClient::GetChromeProduct() const { - return base::StringPrintf("Chrome/%d.%d.%d.%d", CHROME_VERSION_MAJOR, - CHROME_VERSION_MINOR, CHROME_VERSION_BUILD, - CHROME_VERSION_PATCH); + return version_info::GetProductNameAndVersionForUserAgent(); } std::string CefContentBrowserClient::GetUserAgent() const { - const base::CommandLine* command_line = - base::CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kUserAgent)) - return command_line->GetSwitchValueASCII(switches::kUserAgent); - - return content::BuildUserAgentFromProduct(GetProduct()); + // Match the logic in chrome_content_browser_client.cc GetUserAgent() which + // will be called when the NetworkService is enabled. + return ::GetUserAgent(); } blink::UserAgentMetadata CefContentBrowserClient::GetUserAgentMetadata() const { diff --git a/patch/patch.cfg b/patch/patch.cfg index 4756637dd..14e96c180 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -244,6 +244,12 @@ patches = [ # https://bitbucket.org/chromiumembedded/cef/issues/2613 'name': 'chrome_browser_net_export', }, + { + # Support override of the User-Agent product component when NetworkService + # is enabled. + # https://bitbucket.org/chromiumembedded/cef/issues/2622 + 'name': 'chrome_browser_product_override', + }, { # Allow CEF to share Chrome plugin loading code. 'name': 'chrome_plugins', diff --git a/patch/patches/chrome_browser_product_override.patch b/patch/patches/chrome_browser_product_override.patch new file mode 100644 index 000000000..b52af0906 --- /dev/null +++ b/patch/patches/chrome_browser_product_override.patch @@ -0,0 +1,37 @@ +diff --git chrome/browser/chrome_content_browser_client.cc chrome/browser/chrome_content_browser_client.cc +index 52a1a31ee131..5a1e29fec9c8 100644 +--- chrome/browser/chrome_content_browser_client.cc ++++ chrome/browser/chrome_content_browser_client.cc +@@ -1033,12 +1033,16 @@ void LaunchURL( + } + } + ++} // namespace ++ + std::string GetProduct() { ++ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); ++ if (command_line->HasSwitch(switches::kProductVersion)) ++ return command_line->GetSwitchValueASCII(switches::kProductVersion); ++ + return version_info::GetProductNameAndVersionForUserAgent(); + } + +-} // namespace +- + std::string GetUserAgent() { + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kUserAgent)) { +diff --git chrome/browser/chrome_content_browser_client.h chrome/browser/chrome_content_browser_client.h +index cbf1e2218e91..a42d2a4d71bb 100644 +--- chrome/browser/chrome_content_browser_client.h ++++ chrome/browser/chrome_content_browser_client.h +@@ -77,7 +77,8 @@ class Origin; + + class ChromeSerialDelegate; + +-// Returns the user agent of Chrome. ++// Returns the product and user agent of Chrome. ++std::string GetProduct(); + std::string GetUserAgent(); + + blink::UserAgentMetadata GetUserAgentMetadata();