diff options
author | dpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-22 19:44:41 +0000 |
---|---|---|
committer | dpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-22 19:44:41 +0000 |
commit | 6568e6bb74a14bb6be71c1963c223ebe51eb4b4d (patch) | |
tree | 3855fdcd8a01d31682d566a9317b95a67b4fee3a /webkit/glue/webkit_glue.cc | |
parent | 9d43e371e6c0b70b938575690f561f3742ad8397 (diff) | |
download | chromium_src-6568e6bb74a14bb6be71c1963c223ebe51eb4b4d.zip chromium_src-6568e6bb74a14bb6be71c1963c223ebe51eb4b4d.tar.gz chromium_src-6568e6bb74a14bb6be71c1963c223ebe51eb4b4d.tar.bz2 |
Remove webkit_glue::BuildUserAgent(), change the contract in webkit_glue so that SetUserAgent() must be called before GetUserAgent().
This was causing a dependency inversion between webkit_support and its clients, and was needed for the content component build.
For content users, calling SetContentClient() will automatically initialize the user agent (retrieved from client->GetUserAgent()).
As a bonus, fixing this allowed me to re-test the "mimic_windows" code path and it looks like we no longer need it.
R=jam@chromium.org,tony@chromium.org
BUG=11136,90442
TEST=visit yahoo! mail using Chromium on Linux, ensure that we don't get an "unsupported browser" warning.
Review URL: http://codereview.chromium.org/7922023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102336 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webkit_glue.cc')
-rw-r--r-- | webkit/glue/webkit_glue.cc | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc index cb8d05f..1d89305 100644 --- a/webkit/glue/webkit_glue.cc +++ b/webkit/glue/webkit_glue.cc @@ -343,13 +343,11 @@ class UserAgentState { UserAgentState(); ~UserAgentState(); - void Set(const std::string& user_agent); + void Set(const std::string& user_agent, bool overriding); const std::string& Get(const GURL& url) const; private: mutable std::string user_agent_; - // The UA string when we're pretending to be Windows Chrome. - mutable std::string mimic_windows_user_agent_; // The UA string when we're pretending to be Mac Safari. mutable std::string mimic_mac_safari_user_agent_; @@ -369,11 +367,18 @@ UserAgentState::UserAgentState() UserAgentState::~UserAgentState() { } -void UserAgentState::Set(const std::string& user_agent) { +void UserAgentState::Set(const std::string& user_agent, bool overriding) { 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_is_overridden_ = true; + user_agent_is_overridden_ = overriding; user_agent_ = user_agent; } @@ -381,21 +386,10 @@ const std::string& UserAgentState::Get(const GURL& url) const { base::AutoLock auto_lock(lock_); user_agent_requested_ = true; - if (user_agent_.empty()) - user_agent_ = BuildUserAgent(false); + DCHECK(!user_agent_.empty()); // Workarounds for sites that use misguided UA sniffing. if (!user_agent_is_overridden_) { -#if defined(OS_POSIX) && !defined(OS_MACOSX) - if (MatchPattern(url.host(), "*.mail.yahoo.com")) { - // mail.yahoo.com is ok with Windows Chrome but not Linux Chrome. - // http://bugs.chromium.org/11136 - // TODO(evanm): remove this if Yahoo fixes their sniffing. - if (mimic_windows_user_agent_.empty()) - mimic_windows_user_agent_ = BuildUserAgent(true); - return mimic_windows_user_agent_; - } -#endif #if defined(OS_MACOSX) if (url.host() == "www.microsoft.com" && StartsWithASCII(url.path(), "/getsilverlight", false)) { @@ -405,7 +399,7 @@ const std::string& UserAgentState::Get(const GURL& url) const { // Should be removed if the sniffing is removed: http://crbug.com/88211 if (mimic_mac_safari_user_agent_.empty()) { mimic_mac_safari_user_agent_ = - BuildUserAgentHelper(false, "Version/5.0.4 Safari/533.20.27"); + BuildUserAgentFromProduct("Version/5.0.4 Safari/533.20.27"); } return mimic_mac_safari_user_agent_; } @@ -419,8 +413,8 @@ base::LazyInstance<UserAgentState> g_user_agent(base::LINKER_INITIALIZED); } // namespace -void SetUserAgent(const std::string& new_user_agent) { - g_user_agent.Get().Set(new_user_agent); +void SetUserAgent(const std::string& user_agent, bool overriding) { + g_user_agent.Get().Set(user_agent, overriding); } const std::string& GetUserAgent(const GURL& url) { |