diff options
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) { |