summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-07 05:28:00 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-07 05:28:00 +0000
commit5a7dc5aa805f2d94ea5bfa2cb2c01d228cfc00e7 (patch)
tree1e3f2583502baace59869cf96250351da92a40e1
parentd04aca190d6797ee21d9ae3ff4204abf8a0eab56 (diff)
downloadchromium_src-5a7dc5aa805f2d94ea5bfa2cb2c01d228cfc00e7.zip
chromium_src-5a7dc5aa805f2d94ea5bfa2cb2c01d228cfc00e7.tar.gz
chromium_src-5a7dc5aa805f2d94ea5bfa2cb2c01d228cfc00e7.tar.bz2
Simplify the user agent overriding code, in preparation for moving it out of src/webkit.
These workarounds were added a long time ago before Chrome launched. The Microsoft one isn't needed as the download page has a link to the Mac version without the spoof. The Yahoo Japan download page says it's going away in June and just redirects to Microsoft. The gyao.yahoo.co.jp host doesn't use Silverlight now. promotion.shopping.yahoo.co.jp is dead. BUG=338338 R=jamesr@chromium.org Review URL: https://codereview.chromium.org/178263007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255534 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/app/content_main_runner.cc4
-rw-r--r--content/content_tests.gypi1
-rw-r--r--content/public/common/content_client.cc5
-rw-r--r--content/test/webkit_support.cc2
-rw-r--r--webkit/common/user_agent/user_agent.cc74
-rw-r--r--webkit/common/user_agent/user_agent.h11
-rw-r--r--webkit/common/user_agent/user_agent_unittest.cc55
7 files changed, 17 insertions, 135 deletions
diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc
index 18464350..94c1b9f 100644
--- a/content/app/content_main_runner.cc
+++ b/content/app/content_main_runner.cc
@@ -384,7 +384,7 @@ int RunZygote(const MainFunctionParams& main_function_params,
// initialized.
if (command_line.HasSwitch(switches::kUserAgent)) {
webkit_glue::SetUserAgent(
- command_line.GetSwitchValueASCII(switches::kUserAgent), true);
+ command_line.GetSwitchValueASCII(switches::kUserAgent));
}
// The StatsTable must be initialized in each process; we already
@@ -746,7 +746,7 @@ class ContentMainRunnerImpl : public ContentMainRunner {
// defaults to the user agent set during SetContentClient().
if (command_line.HasSwitch(switches::kUserAgent)) {
webkit_glue::SetUserAgent(
- command_line.GetSwitchValueASCII(switches::kUserAgent), true);
+ command_line.GetSwitchValueASCII(switches::kUserAgent));
}
if (!process_type.empty())
diff --git a/content/content_tests.gypi b/content/content_tests.gypi
index 1d5692c..21d7b97 100644
--- a/content/content_tests.gypi
+++ b/content/content_tests.gypi
@@ -634,7 +634,6 @@
'../webkit/common/database/database_connections_unittest.cc',
'../webkit/common/database/database_identifier_unittest.cc',
'../webkit/common/fileapi/file_system_util_unittest.cc',
- '../webkit/common/user_agent/user_agent_unittest.cc',
'../webkit/browser/quota/mock_quota_manager.cc',
'../webkit/browser/quota/mock_quota_manager.h',
'../webkit/browser/quota/mock_quota_manager_proxy.cc',
diff --git a/content/public/common/content_client.cc b/content/public/common/content_client.cc
index 54db517..52325d1 100644
--- a/content/public/common/content_client.cc
+++ b/content/public/common/content_client.cc
@@ -40,9 +40,8 @@ void SetContentClient(ContentClient* 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).
- if (client) {
- webkit_glue::SetUserAgent(client->GetUserAgent(), false);
- }
+ if (client)
+ webkit_glue::SetUserAgent(client->GetUserAgent());
}
ContentClient* GetContentClient() {
diff --git a/content/test/webkit_support.cc b/content/test/webkit_support.cc
index 18380c8..7a1cf2e 100644
--- a/content/test/webkit_support.cc
+++ b/content/test/webkit_support.cc
@@ -111,7 +111,7 @@ void SetUpTestEnvironmentForUnitTests() {
url_util::Initialize();
test_environment = new TestEnvironment;
webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct(
- "DumpRenderTree/0.0.0.0"), false);
+ "DumpRenderTree/0.0.0.0"));
}
void TearDownTestEnvironment() {
diff --git a/webkit/common/user_agent/user_agent.cc b/webkit/common/user_agent/user_agent.cc
index 9a1fdb0..b746e25 100644
--- a/webkit/common/user_agent/user_agent.cc
+++ b/webkit/common/user_agent/user_agent.cc
@@ -6,10 +6,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
#include "base/synchronization/lock.h"
-#include "webkit/common/user_agent/user_agent_util.h"
namespace webkit_glue {
@@ -20,16 +17,13 @@ class UserAgentState {
UserAgentState();
~UserAgentState();
- void Set(const std::string& user_agent, bool overriding);
- const std::string& Get(const GURL& url) const;
+ void Set(const std::string& user_agent);
+ const std::string& Get() 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.
@@ -37,14 +31,13 @@ class UserAgentState {
};
UserAgentState::UserAgentState()
- : user_agent_requested_(false),
- user_agent_is_overridden_(false) {
+ : user_agent_requested_(false) {
}
UserAgentState::~UserAgentState() {
}
-void UserAgentState::Set(const std::string& user_agent, bool overriding) {
+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
@@ -55,66 +48,15 @@ void UserAgentState::Set(const std::string& user_agent, bool overriding) {
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) && !defined(OS_IOS)
- // 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_IOS)
- 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() == "promotion.shopping.yahoo.co.jp") {
- return true;
- }
-#endif
- return false;
-}
-
-const std::string& UserAgentState::Get(const GURL& url) const {
+const std::string& UserAgentState::Get() 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) && !defined(OS_IOS)
- 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_;
}
@@ -122,12 +64,12 @@ 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);
+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(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
index 849f5c3..2118122 100644
--- a/webkit/common/user_agent/user_agent.h
+++ b/webkit/common/user_agent/user_agent.h
@@ -7,18 +7,15 @@
#include <string>
-#include "base/basictypes.h"
-#include "url/gurl.h"
#include "webkit/common/user_agent/webkit_user_agent_export.h"
+class GURL;
+
namespace webkit_glue {
-// Sets the user agent. Pass true for overriding if this is a custom
-// user agent instead of the default one (in order to turn off any browser
-// sniffing workarounds). This must be called before GetUserAgent() can
+// Sets the user agent. This must be called before GetUserAgent() can
// be called.
-WEBKIT_USER_AGENT_EXPORT void SetUserAgent(const std::string& user_agent,
- bool overriding);
+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.
diff --git a/webkit/common/user_agent/user_agent_unittest.cc b/webkit/common/user_agent/user_agent_unittest.cc
deleted file mode 100644
index bed7652..0000000
--- a/webkit/common/user_agent/user_agent_unittest.cc
+++ /dev/null
@@ -1,55 +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 "webkit/common/user_agent/user_agent.h"
-
-#include <string>
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "url/gurl.h"
-
-namespace {
-
-typedef testing::Test WebkitGlueUserAgentTest;
-
-bool IsSpoofedUserAgent(const std::string& user_agent) {
- return user_agent.find("TestContentClient") == std::string::npos;
-}
-
-TEST_F(WebkitGlueUserAgentTest, UserAgentSpoofingHack) {
- enum Platform {
- NONE = 0,
- MACOSX = 1,
- WIN = 2,
- OTHER = 4,
- };
-
- struct Expected {
- const char* url;
- int os_mask;
- };
-
- Expected expected[] = {
- { "http://wwww.google.com", NONE },
- { "http://www.microsoft.com/getsilverlight", MACOSX },
- { "http://downloads.yahoo.co.jp/docs/silverlight/", MACOSX },
- { "http://gyao.yahoo.co.jp/", MACOSX },
- { "http://promotion.shopping.yahoo.co.jp/", WIN },
- };
-#if defined(OS_MACOSX)
- int os_bit = MACOSX;
-#elif defined(OS_WIN)
- int os_bit = WIN;
-#else
- int os_bit = OTHER;
-#endif
-
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(expected); ++i) {
- EXPECT_EQ((expected[i].os_mask & os_bit) != 0,
- IsSpoofedUserAgent(
- webkit_glue::GetUserAgent(GURL(expected[i].url))));
- }
-}
-
-} // namespace