Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1424)

Unified Diff: webkit/glue/webkit_glue.cc

Issue 10869073: Split user agent code out of the 'glue' target (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to trunk Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/webkit_glue.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/webkit_glue.cc
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index 36584d1f4c16a50b96a230d732d4216a6cbc5589..cd14f456aede977fce61b24f9a2e58f50df1c850 100644
--- a/webkit/glue/webkit_glue.cc
+++ b/webkit/glue/webkit_glue.cc
@@ -13,7 +13,6 @@
#include <limits>
-#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
@@ -21,7 +20,6 @@
#include "base/string_tokenizer.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
-#include "base/synchronization/lock.h"
#include "base/sys_info.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
@@ -53,7 +51,6 @@
#endif
#include "v8/include/v8.h"
#include "webkit/glue/glue_serialize.h"
-#include "webkit/glue/user_agent.h"
using WebKit::WebCanvas;
using WebKit::WebData;
@@ -321,135 +318,6 @@ void PlatformFileInfoToWebFileInfo(
web_file_info->type = WebKit::WebFileInfo::TypeFile;
}
-namespace {
-
-class UserAgentState {
- public:
- UserAgentState();
- ~UserAgentState();
-
- 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 Mac Safari or Win Firefox.
- mutable std::string user_agent_for_spoofing_hack_;
-
- mutable bool user_agent_requested_;
- bool user_agent_is_overridden_;
-
- // 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),
- user_agent_is_overridden_(false) {
-}
-
-UserAgentState::~UserAgentState() {
-}
-
-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_ = overriding;
- user_agent_ = user_agent;
-}
-
-bool IsMicrosoftSiteThatNeedsSpoofingForSilverlight(const GURL& url) {
-#if defined(OS_MACOSX)
- // The landing page for updating Silverlight gives a confusing experience
- // in browsers that Silverlight doesn't officially support; spoof as
- // Safari to reduce the chance that users won't complete updates.
- // Should be removed if the sniffing is removed: http://crbug.com/88211
- if (url.host() == "www.microsoft.com" &&
- StartsWithASCII(url.path(), "/getsilverlight", false)) {
- return true;
- }
-#endif
- return false;
-}
-
-bool IsYahooSiteThatNeedsSpoofingForSilverlight(const GURL& url) {
-#if defined(OS_MACOSX) || defined(OS_WIN)
- // The following Yahoo! JAPAN pages erroneously judge that Silverlight does
- // not support Chromium. Until the pages are fixed, spoof the UA.
- // http://crbug.com/104426
- if (url.host() == "headlines.yahoo.co.jp" &&
- StartsWithASCII(url.path(), "/videonews/", true)) {
- return true;
- }
-#endif
-#if defined(OS_MACOSX)
- if ((url.host() == "downloads.yahoo.co.jp" &&
- StartsWithASCII(url.path(), "/docs/silverlight/", true)) ||
- url.host() == "gyao.yahoo.co.jp") {
- return true;
- }
-#elif defined(OS_WIN)
- if ((url.host() == "weather.yahoo.co.jp" &&
- StartsWithASCII(url.path(), "/weather/zoomradar/", true)) ||
- url.host() == "promotion.shopping.yahoo.co.jp" ||
- url.host() == "pokemon.kids.yahoo.co.jp") {
- return true;
- }
-#endif
- return false;
-}
-
-const std::string& UserAgentState::Get(const GURL& url) const {
- base::AutoLock auto_lock(lock_);
- user_agent_requested_ = true;
-
- DCHECK(!user_agent_.empty());
-
- // Workarounds for sites that use misguided UA sniffing.
- if (!user_agent_is_overridden_) {
- if (IsMicrosoftSiteThatNeedsSpoofingForSilverlight(url) ||
- IsYahooSiteThatNeedsSpoofingForSilverlight(url)) {
- if (user_agent_for_spoofing_hack_.empty()) {
-#if defined(OS_MACOSX)
- user_agent_for_spoofing_hack_ =
- BuildUserAgentFromProduct("Version/5.1.1 Safari/534.51.22");
-#elif defined(OS_WIN)
- // Pretend to be Firefox. Silverlight doesn't support Win Safari.
- base::StringAppendF(
- &user_agent_for_spoofing_hack_,
- "Mozilla/5.0 (%s) Gecko/20100101 Firefox/8.0",
- webkit_glue::BuildOSCpuInfo().c_str());
-#endif
- }
- DCHECK(!user_agent_for_spoofing_hack_.empty());
- return user_agent_for_spoofing_hack_;
- }
- }
-
- return user_agent_;
-}
-
-base::LazyInstance<UserAgentState> g_user_agent = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-void SetUserAgent(const std::string& user_agent, bool overriding) {
- g_user_agent.Get().Set(user_agent, overriding);
-}
-
-const std::string& GetUserAgent(const GURL& url) {
- return g_user_agent.Get().Get(url);
-}
-
void SetForcefullyTerminatePluginProcess(bool value) {
g_forcefully_terminate_plugin_process = value;
}
« no previous file with comments | « webkit/glue/webkit_glue.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698