| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/common/user_agent/user_agent.h" | 5 #include "content/public/common/user_agent.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "webkit/common/user_agent/user_agent_util.h" | 12 #include "content/public/common/user_agent_util.h" |
| 13 | 13 |
| 14 namespace webkit_glue { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class UserAgentState { | 18 class UserAgentState { |
| 19 public: | 19 public: |
| 20 UserAgentState(); | 20 UserAgentState(); |
| 21 ~UserAgentState(); | 21 ~UserAgentState(); |
| 22 | 22 |
| 23 void Set(const std::string& user_agent, bool overriding); | 23 void Set(const std::string& user_agent, bool overriding); |
| 24 const std::string& Get(const GURL& url) const; | 24 const std::string& Get(const GURL& url) const; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // Workarounds for sites that use misguided UA sniffing. | 97 // Workarounds for sites that use misguided UA sniffing. |
| 98 if (!user_agent_is_overridden_) { | 98 if (!user_agent_is_overridden_) { |
| 99 if (IsMicrosoftSiteThatNeedsSpoofingForSilverlight(url) || | 99 if (IsMicrosoftSiteThatNeedsSpoofingForSilverlight(url) || |
| 100 IsYahooSiteThatNeedsSpoofingForSilverlight(url)) { | 100 IsYahooSiteThatNeedsSpoofingForSilverlight(url)) { |
| 101 if (user_agent_for_spoofing_hack_.empty()) { | 101 if (user_agent_for_spoofing_hack_.empty()) { |
| 102 #if defined(OS_MACOSX) && !defined(OS_IOS) | 102 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 103 user_agent_for_spoofing_hack_ = | 103 user_agent_for_spoofing_hack_ = |
| 104 BuildUserAgentFromProduct("Version/5.1.1 Safari/534.51.22"); | 104 BuildUserAgentFromProduct("Version/5.1.1 Safari/534.51.22"); |
| 105 #elif defined(OS_WIN) | 105 #elif defined(OS_WIN) |
| 106 // Pretend to be Firefox. Silverlight doesn't support Win Safari. | 106 // Pretend to be Firefox. Silverlight doesn't support Win Safari. |
| 107 base::StringAppendF( | 107 base::StringAppendF(&user_agent_for_spoofing_hack_, |
| 108 &user_agent_for_spoofing_hack_, | 108 "Mozilla/5.0 (%s) Gecko/20100101 Firefox/8.0", |
| 109 "Mozilla/5.0 (%s) Gecko/20100101 Firefox/8.0", | 109 BuildOSCpuInfo().c_str()); |
| 110 webkit_glue::BuildOSCpuInfo().c_str()); | |
| 111 #endif | 110 #endif |
| 112 } | 111 } |
| 113 DCHECK(!user_agent_for_spoofing_hack_.empty()); | 112 DCHECK(!user_agent_for_spoofing_hack_.empty()); |
| 114 return user_agent_for_spoofing_hack_; | 113 return user_agent_for_spoofing_hack_; |
| 115 } | 114 } |
| 116 } | 115 } |
| 117 | 116 |
| 118 return user_agent_; | 117 return user_agent_; |
| 119 } | 118 } |
| 120 | 119 |
| 121 base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER; | 120 base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER; |
| 122 | 121 |
| 123 } // namespace | 122 } // namespace |
| 124 | 123 |
| 125 void SetUserAgent(const std::string& user_agent, bool overriding) { | 124 void SetUserAgent(const std::string& user_agent, bool overriding) { |
| 126 g_user_agent.Get().Set(user_agent, overriding); | 125 g_user_agent.Get().Set(user_agent, overriding); |
| 127 } | 126 } |
| 128 | 127 |
| 129 const std::string& GetUserAgent(const GURL& url) { | 128 const std::string& GetUserAgent(const GURL& url) { |
| 130 return g_user_agent.Get().Get(url); | 129 return g_user_agent.Get().Get(url); |
| 131 } | 130 } |
| 132 | 131 |
| 133 } // namespace webkit_glue | 132 } // namespace content |
| OLD | NEW |