From e1502f6953aaf870a4425f0785683c5d61182dde Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 22 Jan 2019 00:02:34 +0530 Subject: [PATCH] Move GetUserAgent from ContentClient to ContentBrowserClient https://chromium-review.googlesource.com/c/chromium/src/+/1352086 --- atom/app/atom_content_client.cc | 13 --------- atom/app/atom_content_client.h | 2 -- atom/browser/atom_browser_client.cc | 10 +++++++ atom/browser/atom_browser_client.h | 2 ++ atom/browser/atom_browser_context.cc | 27 +------------------ atom/browser/common_web_contents_delegate.cc | 3 ++- .../net/system_network_context_manager.cc | 3 +++ atom/common/application_info.cc | 22 +++++++++++++++ atom/common/application_info.h | 2 ++ 9 files changed, 42 insertions(+), 42 deletions(-) diff --git a/atom/app/atom_content_client.cc b/atom/app/atom_content_client.cc index 2317a65470aa..ff5dce323d16 100644 --- a/atom/app/atom_content_client.cc +++ b/atom/app/atom_content_client.cc @@ -7,17 +7,14 @@ #include #include -#include "atom/common/atom_version.h" #include "atom/common/options_switches.h" #include "base/command_line.h" #include "base/files/file_util.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/common/chrome_version.h" #include "content/public/common/content_constants.h" #include "content/public/common/pepper_plugin_info.h" -#include "content/public/common/user_agent.h" #include "electron/buildflags/buildflags.h" #include "ppapi/shared_impl/ppapi_permissions.h" #include "ui/base/l10n/l10n_util.h" @@ -180,16 +177,6 @@ AtomContentClient::AtomContentClient() {} AtomContentClient::~AtomContentClient() {} -std::string AtomContentClient::GetProduct() const { - return "Chrome/" CHROME_VERSION_STRING; -} - -std::string AtomContentClient::GetUserAgent() const { - return content::BuildUserAgentFromProduct("Chrome/" CHROME_VERSION_STRING - " " ATOM_PRODUCT_NAME - "/" ATOM_VERSION_STRING); -} - base::string16 AtomContentClient::GetLocalizedString(int message_id) const { return l10n_util::GetStringUTF16(message_id); } diff --git a/atom/app/atom_content_client.h b/atom/app/atom_content_client.h index bf07825c474c..f7095f6ab04e 100644 --- a/atom/app/atom_content_client.h +++ b/atom/app/atom_content_client.h @@ -20,8 +20,6 @@ class AtomContentClient : public content::ContentClient { protected: // content::ContentClient: - std::string GetProduct() const override; - std::string GetUserAgent() const override; base::string16 GetLocalizedString(int message_id) const override; base::StringPiece GetDataResource(int resource_id, ui::ScaleFactor) const override; diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 229ffa29fabd..4941a1912314 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -32,6 +32,7 @@ #include "atom/browser/web_contents_permission_helper.h" #include "atom/browser/web_contents_preferences.h" #include "atom/browser/window_list.h" +#include "atom/common/application_info.h" #include "atom/common/options_switches.h" #include "atom/common/platform_util.h" #include "base/command_line.h" @@ -47,6 +48,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/task/post_task.h" #include "chrome/browser/browser_process.h" +#include "chrome/common/chrome_version.h" #include "components/net_log/chrome_net_log.h" #include "content/public/browser/browser_ppapi_host.h" #include "content/public/browser/browser_task_traits.h" @@ -898,6 +900,14 @@ bool AtomBrowserClient::ShouldBypassCORB(int render_process_id) const { return it != process_preferences_.end() && !it->second.web_security; } +std::string AtomBrowserClient::GetProduct() const { + return "Chrome/" CHROME_VERSION_STRING; +} + +std::string AtomBrowserClient::GetUserAgent() const { + return GetApplicationUserAgent(); +} + std::string AtomBrowserClient::GetApplicationLocale() { if (BrowserThread::CurrentlyOn(BrowserThread::IO)) return g_io_thread_application_locale.Get(); diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index 52de6e3231ce..65a0aba20d97 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -153,6 +153,8 @@ class AtomBrowserClient : public content::ContentBrowserClient, void OnNetworkServiceCreated( network::mojom::NetworkService* network_service) override; bool ShouldBypassCORB(int render_process_id) const override; + std::string GetProduct() const override; + std::string GetUserAgent() const override; // content::RenderProcessHostObserver: void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 55f783c18501..9d4ac92f1bb5 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -11,7 +11,6 @@ #include "atom/browser/atom_download_manager_delegate.h" #include "atom/browser/atom_paths.h" #include "atom/browser/atom_permission_manager.h" -#include "atom/browser/browser.h" #include "atom/browser/cookie_change_notifier.h" #include "atom/browser/net/resolve_proxy_helper.h" #include "atom/browser/pref_store_delegate.h" @@ -20,17 +19,14 @@ #include "atom/browser/web_view_manager.h" #include "atom/browser/zoom_level_delegate.h" #include "atom/common/application_info.h" -#include "atom/common/atom_version.h" #include "atom/common/options_switches.h" #include "base/command_line.h" #include "base/files/file_path.h" #include "base/path_service.h" #include "base/strings/string_util.h" -#include "base/strings/stringprintf.h" #include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/thread_restrictions.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/chrome_version.h" #include "chrome/common/pref_names.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/prefs/json_pref_store.h" @@ -42,7 +38,6 @@ #include "components/proxy_config/proxy_config_pref_names.h" #include "content/browser/blob_storage/chrome_blob_storage_context.h" #include "content/public/browser/storage_partition.h" -#include "content/public/common/user_agent.h" #include "net/base/escape.h" using content::BrowserThread; @@ -51,14 +46,6 @@ namespace atom { namespace { -std::string RemoveWhitespace(const std::string& str) { - std::string trimmed; - if (base::RemoveChars(str, " ", &trimmed)) - return trimmed; - else - return str; -} - // Convert string to lower case and escape it. std::string MakePartitionName(const std::string& input) { return net::EscapePath(base::ToLowerASCII(input)); @@ -78,19 +65,7 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition, storage_policy_(new SpecialStoragePolicy), in_memory_(in_memory), weak_factory_(this) { - // Construct user agent string. - Browser* browser = Browser::Get(); - std::string name = RemoveWhitespace(browser->GetName()); - std::string user_agent; - if (name == ATOM_PRODUCT_NAME) { - user_agent = "Chrome/" CHROME_VERSION_STRING " " ATOM_PRODUCT_NAME - "/" ATOM_VERSION_STRING; - } else { - user_agent = base::StringPrintf( - "%s/%s Chrome/%s " ATOM_PRODUCT_NAME "/" ATOM_VERSION_STRING, - name.c_str(), browser->GetVersion().c_str(), CHROME_VERSION_STRING); - } - user_agent_ = content::BuildUserAgentFromProduct(user_agent); + user_agent_ = GetApplicationUserAgent(); // Read options. base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 8ca255e88cc6..114e484d50d9 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -183,7 +183,8 @@ void CommonWebContentsDelegate::InitWithWebContents( #if BUILDFLAG(ENABLE_PRINTING) PrintPreviewMessageHandler::CreateForWebContents(web_contents); printing::PrintViewManagerBasic::CreateForWebContents(web_contents); - printing::CreateCompositeClientIfNeeded(web_contents); + printing::CreateCompositeClientIfNeeded(web_contents, + browser_context->GetUserAgent()); #endif // Determien whether the WebContents is offscreen. diff --git a/atom/browser/net/system_network_context_manager.cc b/atom/browser/net/system_network_context_manager.cc index 82069a2ea7a2..964376afbb5b 100644 --- a/atom/browser/net/system_network_context_manager.cc +++ b/atom/browser/net/system_network_context_manager.cc @@ -8,6 +8,7 @@ #include #include "atom/browser/io_thread.h" +#include "atom/common/application_info.h" #include "atom/common/options_switches.h" #include "base/command_line.h" #include "base/lazy_instance.h" @@ -222,6 +223,8 @@ SystemNetworkContextManager::CreateNetworkContextParams() { network_context_params->context_name = std::string("system"); + network_context_params->user_agent = atom::GetApplicationUserAgent(); + network_context_params->http_cache_enabled = false; // These are needed for PAC scripts that use file or data URLs (Or FTP URLs?). diff --git a/atom/common/application_info.cc b/atom/common/application_info.cc index 53a1b0a52dcf..c0f771576839 100644 --- a/atom/common/application_info.cc +++ b/atom/common/application_info.cc @@ -4,7 +4,12 @@ #include "atom/common/application_info.h" +#include "atom/browser/browser.h" +#include "atom/common/atom_version.h" #include "base/no_destructor.h" +#include "base/strings/stringprintf.h" +#include "chrome/common/chrome_version.h" +#include "content/public/common/user_agent.h" namespace atom { @@ -31,4 +36,21 @@ std::string GetOverriddenApplicationVersion() { return *g_overridden_application_version; } +std::string GetApplicationUserAgent() { + // Construct user agent string. + Browser* browser = Browser::Get(); + std::string name, user_agent; + if (!base::RemoveChars(browser->GetName(), " ", &name)) + name = browser->GetName(); + if (name == ATOM_PRODUCT_NAME) { + user_agent = "Chrome/" CHROME_VERSION_STRING " " ATOM_PRODUCT_NAME + "/" ATOM_VERSION_STRING; + } else { + user_agent = base::StringPrintf( + "%s/%s Chrome/%s " ATOM_PRODUCT_NAME "/" ATOM_VERSION_STRING, + name.c_str(), browser->GetVersion().c_str(), CHROME_VERSION_STRING); + } + return content::BuildUserAgentFromProduct(user_agent); +} + } // namespace atom diff --git a/atom/common/application_info.h b/atom/common/application_info.h index 6243f288682c..f899d3583d25 100644 --- a/atom/common/application_info.h +++ b/atom/common/application_info.h @@ -22,6 +22,8 @@ std::string GetOverriddenApplicationVersion(); std::string GetApplicationName(); std::string GetApplicationVersion(); +// Returns the user agent of Electron. +std::string GetApplicationUserAgent(); #if defined(OS_WIN) PCWSTR GetRawAppUserModelID();