diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-10 05:56:56 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-10 05:56:56 +0000 |
commit | aa051274bdd5359b31fe250152a7db8ccf2879bf (patch) | |
tree | 8fbc6bde879e0d82bb602ce7b366bf86172719c8 | |
parent | c53f6ac2da44db7f880f548f4ba393168d211e9c (diff) | |
download | chromium_src-aa051274bdd5359b31fe250152a7db8ccf2879bf.zip chromium_src-aa051274bdd5359b31fe250152a7db8ccf2879bf.tar.gz chromium_src-aa051274bdd5359b31fe250152a7db8ccf2879bf.tar.bz2 |
Simplify the user agent code some more since after r255534 it's not affected by the site's URL.
Code in content always gets it now from ContentClient::GetUserAgent. In Chrome, there's a GetUserAgent function which returns it.
BUG=338338
R=isherman@chromium.org, pauljensen@chromium.org, scottmg@chromium.org, tfarina@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=255858
Review URL: https://codereview.chromium.org/191093002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255877 0039d316-1c4b-4281-b951-d872f2087c98
58 files changed, 136 insertions, 303 deletions
diff --git a/android_webview/browser/net/aw_url_request_context_getter.cc b/android_webview/browser/net/aw_url_request_context_getter.cc index 2ee7525..38c70a2 100644 --- a/android_webview/browser/net/aw_url_request_context_getter.cc +++ b/android_webview/browser/net/aw_url_request_context_getter.cc @@ -11,6 +11,7 @@ #include "android_webview/browser/net/aw_network_delegate.h" #include "android_webview/browser/net/aw_url_request_job_factory.h" #include "android_webview/browser/net/init_native_callback.h" +#include "android_webview/common/aw_content_client.h" #include "android_webview/common/aw_switches.h" #include "base/command_line.h" #include "base/strings/string_number_conversions.h" @@ -177,7 +178,7 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() { DCHECK(!url_request_context_); net::URLRequestContextBuilder builder; - builder.set_user_agent(content::GetUserAgent(GURL())); + builder.set_user_agent(GetUserAgent()); builder.set_network_delegate(new AwNetworkDelegate()); #if !defined(DISABLE_FTP_SUPPORT) builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. diff --git a/android_webview/common/aw_content_client.cc b/android_webview/common/aw_content_client.cc index e91faa9..856e7b7 100644 --- a/android_webview/common/aw_content_client.cc +++ b/android_webview/common/aw_content_client.cc @@ -12,16 +12,20 @@ #include "ui/base/resource/resource_bundle.h" #include "webkit/common/user_agent/user_agent_util.h" -namespace android_webview { +namespace { -std::string AwContentClient::GetProduct() const { +std::string GetProduct() { // "Chrome/XX.0.0.0" identifies that this WebView is derived from the // corresponding Chromium version XX. // TODO(torne): Use chrome/VERSION file. See http://crbug.com/297522 return "Chrome/33.0.0.0"; } -std::string AwContentClient::GetUserAgent() const { +} + +namespace android_webview { + +std::string GetUserAgent() { // "Version/4.0" had been hardcoded in the legacy WebView. std::string product = "Version/4.0 " + GetProduct(); if (CommandLine::ForCurrentProcess()->HasSwitch( @@ -31,6 +35,14 @@ std::string AwContentClient::GetUserAgent() const { return webkit_glue::BuildUserAgentFromProduct(product); } +std::string AwContentClient::GetProduct() const { + return ::GetProduct(); +} + +std::string AwContentClient::GetUserAgent() const { + return android_webview::GetUserAgent(); +} + base::string16 AwContentClient::GetLocalizedString(int message_id) const { // TODO(boliu): Used only by WebKit, so only bundle those resources for // Android WebView. diff --git a/android_webview/common/aw_content_client.h b/android_webview/common/aw_content_client.h index b764944..697f4e3 100644 --- a/android_webview/common/aw_content_client.h +++ b/android_webview/common/aw_content_client.h @@ -11,6 +11,8 @@ namespace android_webview { +std::string GetUserAgent(); + class AwContentClient : public content::ContentClient { public: // ContentClient implementation. diff --git a/android_webview/native/aw_settings.cc b/android_webview/native/aw_settings.cc index 92bfbad..e2379ed 100644 --- a/android_webview/native/aw_settings.cc +++ b/android_webview/native/aw_settings.cc @@ -5,6 +5,7 @@ #include "android_webview/native/aw_settings.h" #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" +#include "android_webview/common/aw_content_client.h" #include "android_webview/native/aw_contents.h" #include "base/android/jni_android.h" #include "base/android/jni_string.h" @@ -14,10 +15,8 @@ #include "content/public/browser/navigation_entry.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" -#include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" #include "jni/AwSettings_jni.h" -#include "webkit/common/user_agent/user_agent.h" #include "webkit/common/webpreferences.h" using base::android::ConvertJavaStringToUTF16; @@ -341,8 +340,7 @@ static jlong Init(JNIEnv* env, } static jstring GetDefaultUserAgent(JNIEnv* env, jclass clazz) { - return base::android::ConvertUTF8ToJavaString( - env, content::GetUserAgent(GURL())).Release(); + return base::android::ConvertUTF8ToJavaString(env, GetUserAgent()).Release(); } bool RegisterAwSettings(JNIEnv* env) { diff --git a/chrome/browser/autofill/risk/fingerprint_browsertest.cc b/chrome/browser/autofill/risk/fingerprint_browsertest.cc index db1b66a..7b7bea43 100644 --- a/chrome/browser/autofill/risk/fingerprint_browsertest.cc +++ b/chrome/browser/autofill/risk/fingerprint_browsertest.cc @@ -8,6 +8,7 @@ #include "base/message_loop/message_loop.h" #include "base/port.h" #include "chrome/browser/browser_process.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/test/base/in_process_browser_test.h" #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" #include "content/public/browser/geolocation_provider.h" @@ -38,6 +39,7 @@ void GetFingerprintInternal( const std::string& accept_languages, const base::Time& install_time, const std::string& app_locale, + const std::string& user_agent, const base::TimeDelta& timeout, const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); @@ -198,7 +200,7 @@ IN_PROC_BROWSER_TEST_F(AutofillRiskFingerprintTest, GetFingerprint) { internal::GetFingerprintInternal( kObfuscatedGaiaId, window_bounds_, content_bounds_, screen_info, "25.0.0.123", kCharset, kAcceptLanguages, base::Time::Now(), - g_browser_process->GetApplicationLocale(), + g_browser_process->GetApplicationLocale(), GetUserAgent(), base::TimeDelta::FromDays(1), // Ought to be longer than any test run. base::Bind(&AutofillRiskFingerprintTest::GetFingerprintTestCallback, base::Unretained(this))); diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 346456d..f80358b 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -1474,6 +1474,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); static const char* const kCommonSwitchNames[] = { + switches::kUserAgent, switches::kUserDataDir, // Make logs go to the right file. }; command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames, diff --git a/chrome/browser/chromeos/policy/auto_enrollment_client.cc b/chrome/browser/chromeos/policy/auto_enrollment_client.cc index 6d4e989..a5b9425 100644 --- a/chrome/browser/chromeos/policy/auto_enrollment_client.cc +++ b/chrome/browser/chromeos/policy/auto_enrollment_client.cc @@ -17,13 +17,13 @@ #include "base/strings/string_number_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/pref_names.h" #include "chromeos/chromeos_switches.h" #include "components/policy/core/browser/browser_policy_connector.h" #include "components/policy/core/common/cloud/device_management_service.h" #include "components/policy/core/common/cloud/system_policy_request_context.h" #include "content/public/browser/browser_thread.h" -#include "content/public/common/content_client.h" #include "crypto/sha2.h" #include "net/url_request/url_request_context_getter.h" #include "url/gurl.h" @@ -103,9 +103,7 @@ AutoEnrollmentClient::AutoEnrollmentClient( device_management_service_(service), local_state_(local_state) { request_context_ = new SystemPolicyRequestContext( - system_request_context, - content::GetUserAgent( - GURL(device_management_service_->GetServerUrl()))); + system_request_context, GetUserAgent()); DCHECK_LE(power_initial_, power_limit_); DCHECK(!completion_callback_.is_null()); diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc index 86af5f6..e6a7514 100644 --- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc +++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc @@ -14,6 +14,7 @@ #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h" #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/pref_names.h" #include "chromeos/chromeos_constants.h" #include "chromeos/system/statistics_provider.h" @@ -22,7 +23,6 @@ #include "components/policy/core/common/cloud/device_management_service.h" #include "components/policy/core/common/cloud/system_policy_request_context.h" #include "content/public/browser/browser_thread.h" -#include "content/public/common/content_client.h" #include "policy/proto/device_management_backend.pb.h" #include "url/gurl.h" @@ -250,9 +250,7 @@ std::string DeviceCloudPolicyManagerChromeOS::GetMachineModel() { scoped_ptr<CloudPolicyClient> DeviceCloudPolicyManagerChromeOS::CreateClient() { scoped_refptr<net::URLRequestContextGetter> request_context = new SystemPolicyRequestContext( - g_browser_process->system_request_context(), - content::GetUserAgent(GURL( - device_management_service_->GetServerUrl()))); + g_browser_process->system_request_context(), GetUserAgent()); return make_scoped_ptr( new CloudPolicyClient(GetMachineID(), GetMachineModel(), diff --git a/chrome/browser/chromeos/policy/device_local_account_policy_service.cc b/chrome/browser/chromeos/policy/device_local_account_policy_service.cc index ef4b832..c42c4fc 100644 --- a/chrome/browser/chromeos/policy/device_local_account_policy_service.cc +++ b/chrome/browser/chromeos/policy/device_local_account_policy_service.cc @@ -21,6 +21,7 @@ #include "chrome/browser/chromeos/policy/device_local_account_external_data_service.h" #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h" #include "chrome/browser/chromeos/settings/device_settings_service.h" +#include "chrome/common/chrome_content_client.h" #include "chromeos/chromeos_paths.h" #include "chromeos/dbus/session_manager_client.h" #include "chromeos/settings/cros_settings_names.h" @@ -30,7 +31,6 @@ #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" #include "components/policy/core/common/cloud/device_management_service.h" #include "components/policy/core/common/cloud/system_policy_request_context.h" -#include "content/public/common/content_client.h" #include "net/url_request/url_request_context_getter.h" #include "policy/policy_constants.h" #include "policy/proto/device_management_backend.pb.h" @@ -59,9 +59,7 @@ scoped_ptr<CloudPolicyClient> CreateClient( scoped_refptr<net::URLRequestContextGetter> request_context = new SystemPolicyRequestContext( - system_request_context, - content::GetUserAgent(GURL( - device_management_service->GetServerUrl()))); + system_request_context, GetUserAgent()); scoped_ptr<CloudPolicyClient> client( new CloudPolicyClient(std::string(), std::string(), diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc index 9437367..a8acd1f 100644 --- a/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc +++ b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc @@ -16,12 +16,12 @@ #include "chrome/browser/chromeos/policy/wildcard_login_checker.h" #include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/lifetime/application_lifetime.h" +#include "chrome/common/chrome_content_client.h" #include "components/policy/core/common/cloud/cloud_external_data_manager.h" #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" #include "components/policy/core/common/cloud/device_management_service.h" #include "components/policy/core/common/cloud/system_policy_request_context.h" #include "components/policy/core/common/policy_pref_names.h" -#include "content/public/common/content_client.h" #include "net/url_request/url_request_context_getter.h" #include "url/gurl.h" @@ -115,9 +115,7 @@ void UserCloudPolicyManagerChromeOS::Connect( // TODO(atwilson): Change this to use a UserPolicyRequestContext once // Connect() is called after profile initialization. http://crbug.com/323591 request_context = new SystemPolicyRequestContext( - system_request_context, - content::GetUserAgent(GURL( - device_management_service->GetServerUrl()))); + system_request_context, GetUserAgent()); } scoped_ptr<CloudPolicyClient> cloud_policy_client( new CloudPolicyClient(std::string(), std::string(), diff --git a/chrome/browser/feedback/feedback_util.cc b/chrome/browser/feedback/feedback_util.cc index bc3a9a2..677b92c 100644 --- a/chrome/browser/feedback/feedback_util.cc +++ b/chrome/browser/feedback/feedback_util.cc @@ -31,6 +31,7 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/metrics/metrics_log_manager.h" @@ -165,7 +166,7 @@ void SendReport(scoped_refptr<FeedbackData> data) { userfeedback::WebData* web_data = feedback_data.mutable_web_data(); web_data->set_url(data->page_url()); - web_data->mutable_navigator()->set_user_agent(content::GetUserAgent(GURL())); + web_data->mutable_navigator()->set_user_agent(GetUserAgent()); gfx::Rect screen_size; if (data->sys_info()) { diff --git a/chrome/browser/invalidation/ticl_invalidation_service.cc b/chrome/browser/invalidation/ticl_invalidation_service.cc index 55f9012..179c87d 100644 --- a/chrome/browser/invalidation/ticl_invalidation_service.cc +++ b/chrome/browser/invalidation/ticl_invalidation_service.cc @@ -14,6 +14,7 @@ #include "chrome/browser/signin/about_signin_internals_factory.h" #include "chrome/browser/signin/profile_oauth2_token_service.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" +#include "chrome/common/chrome_content_client.h" #include "google_apis/gaia/gaia_constants.h" #include "sync/notifier/gcm_network_channel_delegate.h" #include "sync/notifier/invalidation_util.h" @@ -375,7 +376,7 @@ void TiclInvalidationService::StartInvalidator( invalidator_storage_->GetBootstrapData(), syncer::WeakHandle<syncer::InvalidationStateTracker>( invalidator_storage_->AsWeakPtr()), - content::GetUserAgent(GURL()), + GetUserAgent(), profile_->GetRequestContext())); UpdateInvalidatorCredentials(); diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 81f6fca..5e40680 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -29,7 +29,6 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/event_router_forwarder.h" #include "chrome/browser/net/async_dns_field_trial.h" -#include "chrome/browser/net/basic_http_user_agent_settings.h" #include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/chrome_network_delegate.h" #include "chrome/browser/net/chrome_url_request_context.h" @@ -40,6 +39,7 @@ #include "chrome/browser/net/proxy_service_factory.h" #include "chrome/browser/net/sdch_dictionary_fetcher.h" #include "chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/pref_names.h" @@ -78,6 +78,7 @@ #include "net/url_request/data_protocol_handler.h" #include "net/url_request/file_protocol_handler.h" #include "net/url_request/ftp_protocol_handler.h" +#include "net/url_request/static_http_user_agent_settings.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_request_job_factory_impl.h" #include "net/url_request/url_request_throttler_manager.h" @@ -644,7 +645,7 @@ void IOThread::InitAsync() { globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService()); globals_->host_mapping_rules.reset(new net::HostMappingRules()); globals_->http_user_agent_settings.reset( - new BasicHttpUserAgentSettings(std::string())); + new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent())); if (command_line.HasSwitch(switches::kHostRules)) { TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString"); globals_->host_mapping_rules->SetRulesFromString( diff --git a/chrome/browser/net/basic_http_user_agent_settings.cc b/chrome/browser/net/basic_http_user_agent_settings.cc deleted file mode 100644 index 243a475..0000000 --- a/chrome/browser/net/basic_http_user_agent_settings.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/net/basic_http_user_agent_settings.h" - -#include "content/public/common/content_client.h" - -BasicHttpUserAgentSettings::BasicHttpUserAgentSettings( - const std::string& accept_language) - : accept_language_(accept_language) { -} - -BasicHttpUserAgentSettings::~BasicHttpUserAgentSettings() { -} - -std::string BasicHttpUserAgentSettings::GetAcceptLanguage() const { - return accept_language_; -} - -std::string BasicHttpUserAgentSettings::GetUserAgent(const GURL& url) const { - return content::GetUserAgent(url); -} - diff --git a/chrome/browser/net/basic_http_user_agent_settings.h b/chrome/browser/net/basic_http_user_agent_settings.h deleted file mode 100644 index 19d9389..0000000 --- a/chrome/browser/net/basic_http_user_agent_settings.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NET_BASIC_HTTP_USER_AGENT_SETTINGS_H_ -#define CHROME_BROWSER_NET_BASIC_HTTP_USER_AGENT_SETTINGS_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "net/url_request/http_user_agent_settings.h" - -// An implementation of |HttpUserAgentSettings| that provides fixed value for -// the Accept-Language HTTP header and uses |content::GetUserAgent| to provide -// the HTTP User-Agent header value. -class BasicHttpUserAgentSettings : public net::HttpUserAgentSettings { - public: - explicit BasicHttpUserAgentSettings(const std::string& accept_language); - virtual ~BasicHttpUserAgentSettings(); - - // HttpUserAgentSettings implementation - virtual std::string GetAcceptLanguage() const OVERRIDE; - virtual std::string GetUserAgent(const GURL& url) const OVERRIDE; - - private: - const std::string accept_language_; - - DISALLOW_COPY_AND_ASSIGN(BasicHttpUserAgentSettings); -}; - -#endif // CHROME_BROWSER_NET_BASIC_HTTP_USER_AGENT_SETTINGS_H_ - diff --git a/chrome/browser/net/chrome_http_user_agent_settings.cc b/chrome/browser/net/chrome_http_user_agent_settings.cc index f1e9d15..dca7cfa 100644 --- a/chrome/browser/net/chrome_http_user_agent_settings.cc +++ b/chrome/browser/net/chrome_http_user_agent_settings.cc @@ -5,9 +5,9 @@ #include "chrome/browser/net/chrome_http_user_agent_settings.h" #include "base/prefs/pref_service.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" -#include "content/public/common/content_client.h" #include "net/http/http_util.h" ChromeHttpUserAgentSettings::ChromeHttpUserAgentSettings(PrefService* prefs) { @@ -41,8 +41,8 @@ std::string ChromeHttpUserAgentSettings::GetAcceptLanguage() const { return last_http_accept_language_; } -std::string ChromeHttpUserAgentSettings::GetUserAgent(const GURL& url) const { +std::string ChromeHttpUserAgentSettings::GetUserAgent() const { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - return content::GetUserAgent(url); + return ::GetUserAgent(); } diff --git a/chrome/browser/net/chrome_http_user_agent_settings.h b/chrome/browser/net/chrome_http_user_agent_settings.h index 484349c..78f70cb 100644 --- a/chrome/browser/net/chrome_http_user_agent_settings.h +++ b/chrome/browser/net/chrome_http_user_agent_settings.h @@ -15,8 +15,7 @@ class PrefService; // An implementation of |HttpUserAgentSettings| that provides HTTP header -// Accept-Language value that tracks Pref settings and uses -// |content::GetUserAgent| to provide the HTTP User-Agent header value. +// Accept-Language value that tracks Pref settings. class ChromeHttpUserAgentSettings : public net::HttpUserAgentSettings { public: // Must be called on the UI thread. @@ -28,7 +27,7 @@ class ChromeHttpUserAgentSettings : public net::HttpUserAgentSettings { // net::HttpUserAgentSettings implementation virtual std::string GetAcceptLanguage() const OVERRIDE; - virtual std::string GetUserAgent(const GURL& url) const OVERRIDE; + virtual std::string GetUserAgent() const OVERRIDE; private: StringPrefMember pref_accept_language_; diff --git a/chrome/browser/net/preconnect.cc b/chrome/browser/net/preconnect.cc index c87f7a8..05321a9 100644 --- a/chrome/browser/net/preconnect.cc +++ b/chrome/browser/net/preconnect.cc @@ -60,7 +60,7 @@ void PreconnectOnIOThread( std::string user_agent; if (context->http_user_agent_settings()) - user_agent = context->http_user_agent_settings()->GetUserAgent(url); + user_agent = context->http_user_agent_settings()->GetUserAgent(); net::HttpRequestInfo request_info; request_info.url = url; request_info.method = "GET"; diff --git a/chrome/browser/policy/cloud/user_policy_signin_service_base.cc b/chrome/browser/policy/cloud/user_policy_signin_service_base.cc index 4ede37d..db69d5a 100644 --- a/chrome/browser/policy/cloud/user_policy_signin_service_base.cc +++ b/chrome/browser/policy/cloud/user_policy_signin_service_base.cc @@ -11,6 +11,7 @@ #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_switches.h" #include "components/policy/core/browser/browser_policy_connector.h" #include "components/policy/core/common/cloud/device_management_service.h" @@ -18,7 +19,6 @@ #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" #include "components/policy/core/common/cloud/user_policy_request_context.h" #include "content/public/browser/notification_source.h" -#include "content/public/common/content_client.h" #include "net/url_request/url_request_context_getter.h" namespace policy { @@ -252,17 +252,14 @@ void UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager() { scoped_refptr<net::URLRequestContextGetter> UserPolicySigninServiceBase::CreateSystemRequestContext() { return new SystemPolicyRequestContext( - system_request_context(), - content::GetUserAgent(GURL(device_management_service_->GetServerUrl()))); + system_request_context(), GetUserAgent()); } scoped_refptr<net::URLRequestContextGetter> UserPolicySigninServiceBase::CreateUserRequestContext( scoped_refptr<net::URLRequestContextGetter> profile_request_context) { return new UserPolicyRequestContext( - profile_request_context, - system_request_context(), - content::GetUserAgent(GURL(device_management_service_->GetServerUrl()))); + profile_request_context, system_request_context(), GetUserAgent()); } } // namespace policy diff --git a/chrome/browser/profile_resetter/resettable_settings_snapshot.cc b/chrome/browser/profile_resetter/resettable_settings_snapshot.cc index eace6bd..2ef05d5 100644 --- a/chrome/browser/profile_resetter/resettable_settings_snapshot.cc +++ b/chrome/browser/profile_resetter/resettable_settings_snapshot.cc @@ -16,6 +16,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" @@ -248,7 +249,7 @@ scoped_ptr<base::ListValue> GetReadableFeedbackForSnapshot( g_browser_process->GetApplicationLocale()); AddPair(list.get(), l10n_util::GetStringUTF16(IDS_RESET_PROFILE_SETTINGS_USER_AGENT), - content::GetUserAgent(GURL())); + GetUserAgent()); chrome::VersionInfo version_info; std::string version = version_info.Version(); version += chrome::VersionInfo::GetVersionStringModifier(); diff --git a/chrome/browser/task_profiler/task_profiler_data_serializer.cc b/chrome/browser/task_profiler/task_profiler_data_serializer.cc index b52cc25..9b41ed9 100644 --- a/chrome/browser/task_profiler/task_profiler_data_serializer.cc +++ b/chrome/browser/task_profiler/task_profiler_data_serializer.cc @@ -9,7 +9,7 @@ #include "base/json/json_string_value_serializer.h" #include "base/time/time.h" #include "base/tracked_objects.h" -#include "content/public/common/content_client.h" +#include "chrome/common/chrome_content_client.h" #include "content/public/common/process_type.h" #include "url/gurl.h" @@ -140,7 +140,7 @@ bool TaskProfilerDataSerializer::WriteToFile(const base::FilePath& path) { base::ListValue* per_process_data = new base::ListValue(); root->SetInteger("version", 1); - root->SetString("userAgent", content::GetUserAgent(GURL())); + root->SetString("userAgent", GetUserAgent()); // TODO(ramant): Collect data from other processes, then add that data to the // 'per_process_data' array here. Should leverage the TrackingSynchronizer diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index 39c2513..7701bf0 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -39,6 +39,7 @@ #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -2714,7 +2715,7 @@ void AutofillDialogControllerImpl::LoadRiskFingerprintData() { risk::GetFingerprint( obfuscated_gaia_id, window_bounds, *web_contents(), chrome::VersionInfo().Version(), charset, accept_languages, install_time, - g_browser_process->GetApplicationLocale(), + g_browser_process->GetApplicationLocale(), GetUserAgent(), base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, weak_ptr_factory_.GetWeakPtr())); } diff --git a/chrome/browser/ui/webui/help/help_handler.cc b/chrome/browser/ui/webui/help/help_handler.cc index 9b77ced..da00f5e 100644 --- a/chrome/browser/ui/webui/help/help_handler.cc +++ b/chrome/browser/ui/webui/help/help_handler.cc @@ -21,6 +21,7 @@ #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/chrome_pages.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" @@ -28,7 +29,6 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_data_source.h" -#include "content/public/common/content_client.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/google_chrome_strings.h" @@ -280,7 +280,7 @@ void HelpHandler::GetLocalizedValues(content::WebUIDataSource* source) { source->AddString("jsEngine", "V8"); source->AddString("jsEngineVersion", v8::V8::GetVersion()); - source->AddString("userAgentInfo", content::GetUserAgent(GURL())); + source->AddString("userAgentInfo", GetUserAgent()); CommandLine::StringType command_line = CommandLine::ForCurrentProcess()->GetCommandLineString(); diff --git a/chrome/browser/ui/webui/version_ui.cc b/chrome/browser/ui/webui/version_ui.cc index 9426b72..a88d610 100644 --- a/chrome/browser/ui/webui/version_ui.cc +++ b/chrome/browser/ui/webui/version_ui.cc @@ -9,12 +9,12 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/version_handler.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/url_constants.h" #include "content/public/browser/url_data_source.h" #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_data_source.h" -#include "content/public/common/content_client.h" #include "grit/browser_resources.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -92,7 +92,7 @@ content::WebUIDataSource* CreateVersionUIDataSource(Profile* profile) { IDS_ABOUT_VERSION_UNOFFICIAL); html_source->AddLocalizedString("user_agent_name", IDS_ABOUT_VERSION_USER_AGENT); - html_source->AddString("useragent", content::GetUserAgent(GURL())); + html_source->AddString("useragent", GetUserAgent()); html_source->AddLocalizedString("command_line_name", IDS_ABOUT_VERSION_COMMAND_LINE); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index b2bdb9b..6227912 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1298,8 +1298,6 @@ 'browser/net/about_protocol_handler.h', 'browser/net/async_dns_field_trial.cc', 'browser/net/async_dns_field_trial.h', - 'browser/net/basic_http_user_agent_settings.cc', - 'browser/net/basic_http_user_agent_settings.h', 'browser/net/chrome_cookie_notification_details.h', 'browser/net/chrome_fraudulent_certificate_reporter.cc', 'browser/net/chrome_fraudulent_certificate_reporter.h', diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc index 44fc688..ada5b3f 100644 --- a/chrome/common/chrome_content_client.cc +++ b/chrome/common/chrome_content_client.cc @@ -417,8 +417,27 @@ bool GetBundledPepperFlash(content::PepperPluginInfo* plugin) { #endif // FLAPPER_AVAILABLE } +std::string GetProduct() { + chrome::VersionInfo version_info; + return version_info.is_valid() ? + version_info.ProductNameAndVersionForUserAgent() : std::string(); +} + } // namespace +std::string GetUserAgent() { + CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kUserAgent)) + return command_line->GetSwitchValueASCII(switches::kUserAgent); + + std::string product = GetProduct(); +#if defined(OS_ANDROID) + if (command_line->HasSwitch(switches::kUseMobileUserAgent)) + product += " Mobile"; +#endif + return webkit_glue::BuildUserAgentFromProduct(product); +} + void ChromeContentClient::SetActiveURL(const GURL& url) { base::debug::SetCrashKeyValue(crash_keys::kActiveURL, url.possibly_invalid_spec()); @@ -480,19 +499,11 @@ bool ChromeContentClient::CanHandleWhileSwappedOut( } std::string ChromeContentClient::GetProduct() const { - chrome::VersionInfo version_info; - return version_info.is_valid() ? - version_info.ProductNameAndVersionForUserAgent() : std::string(); + return ::GetProduct(); } std::string ChromeContentClient::GetUserAgent() const { - std::string product = GetProduct(); -#if defined(OS_ANDROID) - CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kUseMobileUserAgent)) - product += " Mobile"; -#endif - return webkit_glue::BuildUserAgentFromProduct(product); + return ::GetUserAgent(); } base::string16 ChromeContentClient::GetLocalizedString(int message_id) const { diff --git a/chrome/common/chrome_content_client.h b/chrome/common/chrome_content_client.h index 804f666..845d994 100644 --- a/chrome/common/chrome_content_client.h +++ b/chrome/common/chrome_content_client.h @@ -12,6 +12,9 @@ #include "base/files/file_path.h" #include "content/public/common/content_client.h" +// Returns the user agent of Chrome. +std::string GetUserAgent(); + class ChromeContentClient : public content::ContentClient { public: static const char* const kPDFPluginName; diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 6c64c99..0c5195e 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1448,6 +1448,9 @@ const char kUseSpdy[] = "use-spdy"; // This will only work if asynchronous spell checking is not disabled. const char kUseSpellingSuggestions[] = "use-spelling-suggestions"; +// A string used to override the default user agent with a custom one. +const char kUserAgent[] = "user-agent"; + // Specifies the user data directory, which is where the browser will look for // all of its state. const char kUserDataDir[] = "user-data-dir"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index c59a03b..38b4b81 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -392,6 +392,7 @@ extern const char kUnlimitedStorage[]; extern const char kUseSimpleCacheBackend[]; extern const char kUseSpdy[]; extern const char kUseSpellingSuggestions[]; +extern const char kUserAgent[]; extern const char kUserDataDir[]; extern const char kValidateCrx[]; extern const char kVariationsServerURL[]; diff --git a/components/autofill/content/browser/risk/fingerprint.cc b/components/autofill/content/browser/risk/fingerprint.cc index b7aca6a..b8c7e79 100644 --- a/components/autofill/content/browser/risk/fingerprint.cc +++ b/components/autofill/content/browser/risk/fingerprint.cc @@ -263,6 +263,7 @@ class FingerprintDataLoader : public content::GpuDataManagerObserver { const std::string& accept_languages, const base::Time& install_time, const std::string& app_locale, + const std::string& user_agent, const base::TimeDelta& timeout, const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); @@ -301,6 +302,8 @@ class FingerprintDataLoader : public content::GpuDataManagerObserver { const std::string version_; const std::string charset_; const std::string accept_languages_; + const std::string app_locale_; + const std::string user_agent_; const base::Time install_time_; // Data that will be loaded asynchronously. @@ -317,9 +320,6 @@ class FingerprintDataLoader : public content::GpuDataManagerObserver { // instance is destroyed. base::WeakPtrFactory<FingerprintDataLoader> weak_ptr_factory_; - // The current application locale. - std::string app_locale_; - // The callback that will be called once all the data is available. base::Callback<void(scoped_ptr<Fingerprint>)> callback_; @@ -336,6 +336,7 @@ FingerprintDataLoader::FingerprintDataLoader( const std::string& accept_languages, const base::Time& install_time, const std::string& app_locale, + const std::string& user_agent, const base::TimeDelta& timeout, const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) : gpu_data_manager_(content::GpuDataManager::GetInstance()), @@ -347,6 +348,8 @@ FingerprintDataLoader::FingerprintDataLoader( version_(version), charset_(charset), accept_languages_(accept_languages), + app_locale_(app_locale), + user_agent_(user_agent), install_time_(install_time), waiting_on_plugins_(true), weak_ptr_factory_(this), @@ -445,7 +448,7 @@ void FingerprintDataLoader::FillFingerprint() { machine->set_utc_offset_ms(GetTimezoneOffset().InMilliseconds()); machine->set_browser_language(app_locale_); machine->set_charset(charset_); - machine->set_user_agent(content::GetUserAgent(GURL())); + machine->set_user_agent(user_agent_); machine->set_ram(base::SysInfo::AmountOfPhysicalMemory()); machine->set_browser_build(version_); machine->set_browser_feature( @@ -511,13 +514,15 @@ void GetFingerprintInternal( const std::string& accept_languages, const base::Time& install_time, const std::string& app_locale, + const std::string& user_agent, const base::TimeDelta& timeout, const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { // Begin loading all of the data that we need to load asynchronously. // This class is responsible for freeing its own memory. new FingerprintDataLoader(obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, charset, accept_languages, - install_time, app_locale, timeout, callback); + install_time, app_locale, user_agent, timeout, + callback); } } // namespace internal @@ -531,6 +536,7 @@ void GetFingerprint( const std::string& accept_languages, const base::Time& install_time, const std::string& app_locale, + const std::string& user_agent, const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { gfx::Rect content_bounds; web_contents.GetView()->GetContainerBounds(&content_bounds); @@ -543,7 +549,7 @@ void GetFingerprint( internal::GetFingerprintInternal( obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, - charset, accept_languages, install_time, app_locale, + charset, accept_languages, install_time, app_locale, user_agent, base::TimeDelta::FromSeconds(kTimeoutSeconds), callback); } diff --git a/components/autofill/content/browser/risk/fingerprint.h b/components/autofill/content/browser/risk/fingerprint.h index 86d3c4b..9b490c3 100644 --- a/components/autofill/content/browser/risk/fingerprint.h +++ b/components/autofill/content/browser/risk/fingerprint.h @@ -59,6 +59,7 @@ void GetFingerprint( const std::string& accept_languages, const base::Time& install_time, const std::string& app_locale, + const std::string& user_agent, const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); } // namespace risk diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc index aca3c79..13d112ab 100644 --- a/content/app/content_main_runner.cc +++ b/content/app/content_main_runner.cc @@ -51,7 +51,6 @@ #include "ui/base/ui_base_paths.h" #include "ui/base/ui_base_switches.h" #include "ui/gfx/win/dpi.h" -#include "webkit/common/user_agent/user_agent.h" #if defined(USE_TCMALLOC) #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" @@ -380,14 +379,6 @@ int RunZygote(const MainFunctionParams& main_function_params, command_line.GetSwitchValueASCII(switches::kProcessType); ContentClientInitializer::Set(process_type, delegate); - // If a custom user agent was passed on the command line, we need - // to (re)set it now, rather than using the default one the zygote - // initialized. - if (command_line.HasSwitch(switches::kUserAgent)) { - webkit_glue::SetUserAgent( - command_line.GetSwitchValueASCII(switches::kUserAgent)); - } - // The StatsTable must be initialized in each process; we already // initialized for the browser process, now we need to initialize // within the new processes as well. @@ -747,14 +738,6 @@ class ContentMainRunnerImpl : public ContentMainRunner { if (delegate_) delegate_->PreSandboxStartup(); - // Set any custom user agent passed on the command line now so the string - // doesn't change between calls to webkit_glue::GetUserAgent(), otherwise it - // defaults to the user agent set during SetContentClient(). - if (command_line.HasSwitch(switches::kUserAgent)) { - webkit_glue::SetUserAgent( - command_line.GetSwitchValueASCII(switches::kUserAgent)); - } - if (!process_type.empty()) CommonSubprocessInit(process_type); diff --git a/content/browser/devtools/devtools_http_handler_impl.cc b/content/browser/devtools/devtools_http_handler_impl.cc index 1d0fca1..06119f6 100644 --- a/content/browser/devtools/devtools_http_handler_impl.cc +++ b/content/browser/devtools/devtools_http_handler_impl.cc @@ -37,7 +37,6 @@ #include "net/base/ip_endpoint.h" #include "net/server/http_server_request_info.h" #include "net/server/http_server_response_info.h" -#include "webkit/common/user_agent/user_agent.h" #include "webkit/common/user_agent/user_agent_util.h" #if defined(OS_ANDROID) @@ -454,9 +453,8 @@ void DevToolsHttpHandlerImpl::OnJsonRequestUI( base::DictionaryValue version; version.SetString("Protocol-Version", kProtocolVersion); version.SetString("WebKit-Version", webkit_glue::GetWebKitVersion()); - version.SetString("Browser", content::GetContentClient()->GetProduct()); - version.SetString("User-Agent", - webkit_glue::GetUserAgent(GURL(kAboutBlankURL))); + version.SetString("Browser", GetContentClient()->GetProduct()); + version.SetString("User-Agent", GetContentClient()->GetUserAgent()); #if defined(OS_ANDROID) version.SetString("Android-Package", base::android::BuildInfo::GetInstance()->package_name()); diff --git a/content/browser/media/android/browser_media_player_manager.cc b/content/browser/media/android/browser_media_player_manager.cc index ddff685..669cc60 100644 --- a/content/browser/media/android/browser_media_player_manager.cc +++ b/content/browser/media/android/browser_media_player_manager.cc @@ -76,7 +76,7 @@ MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer( BrowserDemuxerAndroid* demuxer) { switch (type) { case MEDIA_PLAYER_TYPE_URL: { - const std::string user_agent = GetUserAgent(url); + const std::string user_agent = GetContentClient()->GetUserAgent(); MediaPlayerBridge* media_player_bridge = new MediaPlayerBridge( player_id, url, diff --git a/content/browser/plugin_process_host.cc b/content/browser/plugin_process_host.cc index f30fd5d..38ca6d1 100644 --- a/content/browser/plugin_process_host.cc +++ b/content/browser/plugin_process_host.cc @@ -206,7 +206,6 @@ bool PluginProcessHost::Init(const WebPluginInfo& info) { switches::kTestSandbox, switches::kTraceStartup, switches::kUseGL, - switches::kUserAgent, }; cmd_line->CopySwitchesFrom(browser_command_line, kSwitchNames, diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 8bb7d71..cdbc6ea 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -1087,7 +1087,6 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( // --in-process-webgl. switches::kUseGL, switches::kUseMobileUserAgent, - switches::kUserAgent, switches::kV, switches::kVideoThreads, switches::kVModule, diff --git a/content/child/blink_platform_impl.cc b/content/child/blink_platform_impl.cc index ceb1f0e..10e061a 100644 --- a/content/child/blink_platform_impl.cc +++ b/content/child/blink_platform_impl.cc @@ -28,6 +28,7 @@ #include "base/time/time.h" #include "content/child/web_socket_stream_handle_impl.h" #include "content/child/web_url_loader_impl.h" +#include "content/public/common/content_client.h" #include "grit/blink_resources.h" #include "grit/webkit_resources.h" #include "grit/webkit_strings.h" @@ -38,7 +39,6 @@ #include "third_party/WebKit/public/platform/WebString.h" #include "ui/base/layout.h" #include "webkit/child/webkit_child_helpers.h" -#include "webkit/common/user_agent/user_agent.h" #if defined(OS_ANDROID) #include "base/android/sys_utils.h" @@ -362,8 +362,12 @@ WebSocketStreamHandle* BlinkPlatformImpl::createSocketStreamHandle() { return new WebSocketStreamHandleImpl(this); } +WebString BlinkPlatformImpl::userAgent() { + return WebString::fromUTF8(GetContentClient()->GetUserAgent()); +} + WebString BlinkPlatformImpl::userAgent(const WebURL& url) { - return WebString::fromUTF8(webkit_glue::GetUserAgent(url)); + return userAgent(); } WebData BlinkPlatformImpl::parseDataURL( diff --git a/content/child/blink_platform_impl.h b/content/child/blink_platform_impl.h index 944272a..e14808d 100644 --- a/content/child/blink_platform_impl.h +++ b/content/child/blink_platform_impl.h @@ -63,6 +63,8 @@ class CONTENT_EXPORT BlinkPlatformImpl virtual size_t maxDecodedImageBytes() OVERRIDE; virtual blink::WebURLLoader* createURLLoader(); virtual blink::WebSocketStreamHandle* createSocketStreamHandle(); + virtual blink::WebString userAgent(); + // TODO(jam): remove this after Blink is updated virtual blink::WebString userAgent(const blink::WebURL& url); virtual blink::WebData parseDataURL( const blink::WebURL& url, blink::WebString& mimetype, diff --git a/content/child/npapi/plugin_host.cc b/content/child/npapi/plugin_host.cc index e0ac05d..7d98ba5 100644 --- a/content/child/npapi/plugin_host.cc +++ b/content/child/npapi/plugin_host.cc @@ -17,6 +17,7 @@ #include "content/child/npapi/plugin_lib.h" #include "content/child/npapi/plugin_stream_url.h" #include "content/child/npapi/webplugin_delegate.h" +#include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" #include "content/public/common/webplugininfo.h" #include "net/base/net_util.h" @@ -25,7 +26,6 @@ #include "third_party/npapi/bindings/npruntime.h" #include "ui/gl/gl_implementation.h" #include "ui/gl/gl_surface.h" -#include "webkit/common/user_agent/user_agent.h" #if defined(OS_MACOSX) #include "base/mac/mac_util.h" @@ -598,7 +598,7 @@ const char* NPN_UserAgent(NPP id) { "Gecko/20061103 Firefox/2.0a1"; #endif - return webkit_glue::GetUserAgent(GURL()).c_str(); + return content::GetContentClient()->GetUserAgent().c_str(); } void NPN_Status(NPP id, const char* message) { diff --git a/content/public/common/content_client.cc b/content/public/common/content_client.cc index 52325d1..b13b72f 100644 --- a/content/public/common/content_client.cc +++ b/content/public/common/content_client.cc @@ -7,7 +7,6 @@ #include "base/logging.h" #include "base/strings/string_piece.h" #include "ui/gfx/image/image.h" -#include "webkit/common/user_agent/user_agent.h" namespace content { @@ -37,11 +36,10 @@ class InternalTestInitializer { void SetContentClient(ContentClient* client) { g_client = client; - // Set the default user agent as provided by the client. We need to make - // sure this is done before webkit_glue::GetUserAgent() is called (so that - // the UA doesn't change). + // TODO(jam): find out which static on Windows is causing this to have to be + // called on startup. if (client) - webkit_glue::SetUserAgent(client->GetUserAgent()); + client->GetUserAgent(); } ContentClient* GetContentClient() { @@ -60,11 +58,6 @@ ContentUtilityClient* SetUtilityClientForTesting(ContentUtilityClient* u) { return InternalTestInitializer::SetUtility(u); } -const std::string& GetUserAgent(const GURL& url) { - DCHECK(g_client); - return webkit_glue::GetUserAgent(url); -} - ContentClient::ContentClient() : browser_(NULL), plugin_(NULL), renderer_(NULL), utility_(NULL) { } diff --git a/content/public/common/content_client.h b/content/public/common/content_client.h index 1695656..5aba3b6 100644 --- a/content/public/common/content_client.h +++ b/content/public/common/content_client.h @@ -65,16 +65,6 @@ CONTENT_EXPORT ContentRendererClient* SetRendererClientForTesting( CONTENT_EXPORT ContentUtilityClient* SetUtilityClientForTesting( ContentUtilityClient* u); -// Returns the user agent string being used by the browser. SetContentClient() -// must be called prior to calling this, and this routine must be used -// instead of webkit_glue::GetUserAgent() in order to ensure that we use -// the same user agent string everywhere. -// TODO(dpranke): This is caused by webkit_glue being a library that can -// get linked into multiple linkable objects, causing us to have multiple -// static values of the user agent. This will be fixed when we clean up -// webkit_glue. -CONTENT_EXPORT const std::string& GetUserAgent(const GURL& url); - // Interface that the embedder implements. class CONTENT_EXPORT ContentClient { public: diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index 7af3649f..aff8c14 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -914,9 +914,6 @@ const char kUseFakeUIForMediaStream[] = "use-fake-ui-for-media-stream"; // Set when Chromium should use a mobile user agent. const char kUseMobileUserAgent[] = "use-mobile-user-agent"; -// A string used to override the default user agent with a custom one. -const char kUserAgent[] = "user-agent"; - // On POSIX only: the contents of this flag are prepended to the utility // process command line. Useful values might be "valgrind" or "xterm -e gdb // --args". diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index fef37fa..b7cb552 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -256,7 +256,6 @@ CONTENT_EXPORT extern const char kUseDiscardableMemory[]; CONTENT_EXPORT extern const char kUseFakeDeviceForMediaStream[]; CONTENT_EXPORT extern const char kUseFakeUIForMediaStream[]; CONTENT_EXPORT extern const char kUseMobileUserAgent[]; -CONTENT_EXPORT extern const char kUserAgent[]; extern const char kUtilityCmdPrefix[]; CONTENT_EXPORT extern const char kUtilityProcess[]; extern const char kUtilityProcessAllowedDir[]; diff --git a/content/renderer/pepper/pepper_url_request_unittest.cc b/content/renderer/pepper/pepper_url_request_unittest.cc index 4f171ff..d3a8b96 100644 --- a/content/renderer/pepper/pepper_url_request_unittest.cc +++ b/content/renderer/pepper/pepper_url_request_unittest.cc @@ -16,8 +16,6 @@ #include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebFrameClient.h" #include "third_party/WebKit/public/web/WebView.h" -#include "webkit/common/user_agent/user_agent.h" -#include "webkit/common/user_agent/user_agent_util.h" // This test is a end-to-end test from the resource to the WebKit request // object. The actual resource implementation is so simple, it makes sense to diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc index 07b609e..250c769 100644 --- a/content/renderer/renderer_webkitplatformsupport_impl.cc +++ b/content/renderer/renderer_webkitplatformsupport_impl.cc @@ -912,11 +912,6 @@ void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { } } -blink::WebString RendererWebKitPlatformSupportImpl::userAgent( - const blink::WebURL& url) { - return WebKitPlatformSupportImpl::userAgent(url); -} - //------------------------------------------------------------------------------ WebRTCPeerConnectionHandler* diff --git a/content/renderer/renderer_webkitplatformsupport_impl.h b/content/renderer/renderer_webkitplatformsupport_impl.h index 9da11d9..bfaaabc 100644 --- a/content/renderer/renderer_webkitplatformsupport_impl.h +++ b/content/renderer/renderer_webkitplatformsupport_impl.h @@ -127,7 +127,6 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl virtual blink::WebBlobRegistry* blobRegistry(); virtual void sampleGamepads(blink::WebGamepads&); - virtual blink::WebString userAgent(const blink::WebURL& url); virtual blink::WebRTCPeerConnectionHandler* createRTCPeerConnectionHandler( blink::WebRTCPeerConnectionHandlerClient* client); virtual blink::WebMediaStreamCenter* createMediaStreamCenter( diff --git a/content/renderer/service_worker/embedded_worker_dispatcher.cc b/content/renderer/service_worker/embedded_worker_dispatcher.cc index d975479..f901db0 100644 --- a/content/renderer/service_worker/embedded_worker_dispatcher.cc +++ b/content/renderer/service_worker/embedded_worker_dispatcher.cc @@ -12,13 +12,13 @@ #include "content/child/thread_safe_sender.h" #include "content/child/worker_task_runner.h" #include "content/common/service_worker/embedded_worker_messages.h" +#include "content/public/common/content_client.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/service_worker/embedded_worker_context_client.h" #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebURL.h" #include "third_party/WebKit/public/web/WebEmbeddedWorker.h" #include "third_party/WebKit/public/web/WebEmbeddedWorkerStartData.h" -#include "webkit/common/user_agent/user_agent.h" namespace content { @@ -73,8 +73,7 @@ void EmbeddedWorkerDispatcher::OnStartWorker( blink::WebEmbeddedWorkerStartData start_data; start_data.scriptURL = script_url; - start_data.userAgent = - base::UTF8ToUTF16(webkit_glue::GetUserAgent(script_url)); + start_data.userAgent = base::UTF8ToUTF16(GetContentClient()->GetUserAgent()); start_data.startMode = blink::WebEmbeddedWorkerStartModeDontPauseOnStart; wrapper->worker()->startWorkerContext(start_data); diff --git a/content/test/test_webkit_platform_support.cc b/content/test/test_webkit_platform_support.cc index fcdc606..f7cc6b6 100644 --- a/content/test/test_webkit_platform_support.cc +++ b/content/test/test_webkit_platform_support.cc @@ -126,6 +126,15 @@ blink::WebURLLoader* TestWebKitPlatformSupport::createURLLoader() { BlinkPlatformImpl::createURLLoader()); } +blink::WebString TestWebKitPlatformSupport::userAgent() { + return blink::WebString::fromUTF8("DumpRenderTree/0.0.0.0"); +} + +blink::WebString TestWebKitPlatformSupport::userAgent( + const blink::WebURL& url) { + return userAgent(); +} + blink::WebData TestWebKitPlatformSupport::loadResource(const char* name) { if (!strcmp(name, "deleteButton")) { // Create a red 30x30 square. diff --git a/content/test/test_webkit_platform_support.h b/content/test/test_webkit_platform_support.h index 57568a4..d26c8cc 100644 --- a/content/test/test_webkit_platform_support.h +++ b/content/test/test_webkit_platform_support.h @@ -35,6 +35,9 @@ class TestWebKitPlatformSupport virtual blink::WebIDBFactory* idbFactory(); virtual blink::WebURLLoader* createURLLoader(); + virtual blink::WebString userAgent() OVERRIDE; + // TODO(jam): remove this after Blink is updated + virtual blink::WebString userAgent(const blink::WebURL& url); virtual blink::WebData loadResource(const char* name); virtual blink::WebString queryLocalizedString( blink::WebLocalizedString::Name name); diff --git a/content/test/webkit_support.cc b/content/test/webkit_support.cc index 7a1cf2e..a7081d6 100644 --- a/content/test/webkit_support.cc +++ b/content/test/webkit_support.cc @@ -18,8 +18,6 @@ #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" #include "ui/base/resource/resource_bundle.h" #include "url/url_util.h" -#include "webkit/common/user_agent/user_agent.h" -#include "webkit/common/user_agent/user_agent_util.h" #if defined(OS_ANDROID) #include "base/android/jni_android.h" @@ -110,8 +108,6 @@ void SetUpTestEnvironmentForUnitTests() { // at same time. url_util::Initialize(); test_environment = new TestEnvironment; - webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct( - "DumpRenderTree/0.0.0.0")); } void TearDownTestEnvironment() { diff --git a/net/url_request/http_user_agent_settings.h b/net/url_request/http_user_agent_settings.h index d475a88..40eb1a6 100644 --- a/net/url_request/http_user_agent_settings.h +++ b/net/url_request/http_user_agent_settings.h @@ -24,9 +24,8 @@ class NET_EXPORT HttpUserAgentSettings { // Gets the value of 'Accept-Language' header field. virtual std::string GetAcceptLanguage() const = 0; - // Gets the UA string to use for the given URL. Pass an empty URL to get - // the default UA string. - virtual std::string GetUserAgent(const GURL& url) const = 0; + // Gets the UA string. + virtual std::string GetUserAgent() const = 0; private: DISALLOW_COPY_AND_ASSIGN(HttpUserAgentSettings); diff --git a/net/url_request/static_http_user_agent_settings.cc b/net/url_request/static_http_user_agent_settings.cc index 1fd1992..dd74f96 100644 --- a/net/url_request/static_http_user_agent_settings.cc +++ b/net/url_request/static_http_user_agent_settings.cc @@ -20,7 +20,7 @@ std::string StaticHttpUserAgentSettings::GetAcceptLanguage() const { return accept_language_; } -std::string StaticHttpUserAgentSettings::GetUserAgent(const GURL& url) const { +std::string StaticHttpUserAgentSettings::GetUserAgent() const { return user_agent_; } diff --git a/net/url_request/static_http_user_agent_settings.h b/net/url_request/static_http_user_agent_settings.h index 8819daa..7406abc 100644 --- a/net/url_request/static_http_user_agent_settings.h +++ b/net/url_request/static_http_user_agent_settings.h @@ -24,7 +24,7 @@ class NET_EXPORT StaticHttpUserAgentSettings : public HttpUserAgentSettings { // HttpUserAgentSettings implementation virtual std::string GetAcceptLanguage() const OVERRIDE; - virtual std::string GetUserAgent(const GURL& url) const OVERRIDE; + virtual std::string GetUserAgent() const OVERRIDE; private: const std::string accept_language_; diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 947686c..3bedc3d 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -270,8 +270,7 @@ void URLRequestHttpJob::Start() { request_info_.extra_headers.SetHeaderIfMissing( HttpRequestHeaders::kUserAgent, http_user_agent_settings_ ? - http_user_agent_settings_->GetUserAgent(request_->url()) : - std::string()); + http_user_agent_settings_->GetUserAgent() : std::string()); AddExtraHeaders(); AddCookieHeaderAndStart(); diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index 452e7e0..68507f8 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -5923,7 +5923,7 @@ TEST_F(URLRequestTestHTTP, DefaultUserAgent) { &default_context_); req.Start(); base::RunLoop().Run(); - EXPECT_EQ(req.context()->http_user_agent_settings()->GetUserAgent(req.url()), + EXPECT_EQ(req.context()->http_user_agent_settings()->GetUserAgent(), d.data_received()); } diff --git a/webkit/common/user_agent/user_agent.cc b/webkit/common/user_agent/user_agent.cc deleted file mode 100644 index b746e25..0000000 --- a/webkit/common/user_agent/user_agent.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/common/user_agent/user_agent.h" - -#include "base/lazy_instance.h" -#include "base/logging.h" -#include "base/synchronization/lock.h" - -namespace webkit_glue { - -namespace { - -class UserAgentState { - public: - UserAgentState(); - ~UserAgentState(); - - void Set(const std::string& user_agent); - const std::string& Get() const; - - private: - mutable std::string user_agent_; - - mutable bool user_agent_requested_; - - // This object can be accessed from multiple threads, so use a lock around - // accesses to the data members. - mutable base::Lock lock_; -}; - -UserAgentState::UserAgentState() - : user_agent_requested_(false) { -} - -UserAgentState::~UserAgentState() { -} - -void UserAgentState::Set(const std::string& user_agent) { - base::AutoLock auto_lock(lock_); - if (user_agent == user_agent_) { - // We allow the user agent to be set multiple times as long as it - // is set to the same value, in order to simplify unit testing - // given g_user_agent is a global. - return; - } - DCHECK(!user_agent.empty()); - DCHECK(!user_agent_requested_) << "Setting the user agent after someone has " - "already requested it can result in unexpected behavior."; - user_agent_ = user_agent; -} - -const std::string& UserAgentState::Get() const { - base::AutoLock auto_lock(lock_); - user_agent_requested_ = true; - - DCHECK(!user_agent_.empty()); - - return user_agent_; -} - -base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER; - -} // namespace - -void SetUserAgent(const std::string& user_agent) { - g_user_agent.Get().Set(user_agent); -} - -const std::string& GetUserAgent(const GURL& url) { - return g_user_agent.Get().Get(); -} - -} // namespace webkit_glue diff --git a/webkit/common/user_agent/user_agent.h b/webkit/common/user_agent/user_agent.h deleted file mode 100644 index 2118122..0000000 --- a/webkit/common/user_agent/user_agent.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_COMMON_USER_AGENT_USER_AGENT_H_ -#define WEBKIT_COMMON_USER_AGENT_USER_AGENT_H_ - -#include <string> - -#include "webkit/common/user_agent/webkit_user_agent_export.h" - -class GURL; - -namespace webkit_glue { - -// Sets the user agent. This must be called before GetUserAgent() can -// be called. -WEBKIT_USER_AGENT_EXPORT void SetUserAgent(const std::string& user_agent); - -// Returns the user agent to use for the given URL. SetUserAgent() must -// be called prior to calling this function. -WEBKIT_USER_AGENT_EXPORT const std::string& GetUserAgent(const GURL& url); - -} // namespace webkit_glue - -#endif // WEBKIT_COMMON_USER_AGENT_USER_AGENT_H_ diff --git a/webkit/common/user_agent/webkit_user_agent.gyp b/webkit/common/user_agent/webkit_user_agent.gyp index 27449b7..3fbc5e0 100644 --- a/webkit/common/user_agent/webkit_user_agent.gyp +++ b/webkit/common/user_agent/webkit_user_agent.gyp @@ -19,8 +19,6 @@ '<(DEPTH)/url/url.gyp:url_lib', ], 'sources': [ - 'user_agent.cc', - 'user_agent.h', 'user_agent_util.cc', 'user_agent_util_ios.mm', 'user_agent_util.h', |