summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-27 22:28:54 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-27 22:28:54 +0000
commit6f681a41c70030593dc14640920d8447ef9389f2 (patch)
treeda9b0bb6552dc93ba1c1ab59a47588e5bb9196e9 /webkit
parentb06878082f5dd7a9e289c0363e2aa9331a154fdb (diff)
downloadchromium_src-6f681a41c70030593dc14640920d8447ef9389f2.zip
chromium_src-6f681a41c70030593dc14640920d8447ef9389f2.tar.gz
chromium_src-6f681a41c70030593dc14640920d8447ef9389f2.tar.bz2
Add support for UA spoofing, and spoof Safari's UA string when loading URLs
from *.mail.live.com (to fix hotmail). BUG=4111 R=wtc Review URL: http://codereview.chromium.org/19025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8764 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/plugins/plugin_host.cc2
-rw-r--r--webkit/glue/webframeloaderclient_impl.cc3
-rw-r--r--webkit/glue/webkit_glue.cc41
-rw-r--r--webkit/glue/webkit_glue.h7
-rw-r--r--webkit/tools/test_shell/test_shell_request_context.cc6
-rw-r--r--webkit/tools/test_shell/test_shell_request_context.h2
6 files changed, 42 insertions, 19 deletions
diff --git a/webkit/glue/plugins/plugin_host.cc b/webkit/glue/plugins/plugin_host.cc
index 108537b..c12ee5c 100644
--- a/webkit/glue/plugins/plugin_host.cc
+++ b/webkit/glue/plugins/plugin_host.cc
@@ -575,7 +575,7 @@ const char* NPN_UserAgent(NPP id) {
if (id) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin.get() && !plugin->use_mozilla_user_agent())
- return webkit_glue::GetUserAgent().c_str();
+ return webkit_glue::GetUserAgent(GURL()).c_str();
}
static const char *UA = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061103 Firefox/2.0a1";
diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc
index 2bdb9d8..cd4aca0 100644
--- a/webkit/glue/webframeloaderclient_impl.cc
+++ b/webkit/glue/webframeloaderclient_impl.cc
@@ -1264,7 +1264,8 @@ void WebFrameLoaderClient::setTitle(const String& title, const KURL& url) {
}
String WebFrameLoaderClient::userAgent(const KURL& url) {
- return webkit_glue::StdStringToString(webkit_glue::GetUserAgent());
+ return webkit_glue::StdStringToString(
+ webkit_glue::GetUserAgent(webkit_glue::KURLToGURL(url)));
}
void WebFrameLoaderClient::savePlatformDataToCachedPage(WebCore::CachedPage*) {
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index 276ba47..ebcb3e8 100644
--- a/webkit/glue/webkit_glue.cc
+++ b/webkit/glue/webkit_glue.cc
@@ -316,11 +316,11 @@ std::string GetWebKitVersion() {
namespace {
-std::string* user_agent = NULL;
+const std::string* user_agent = NULL;
bool user_agent_requested = false;
+bool user_agent_is_overridden = false;
-void SetUserAgentToDefault() {
- static std::string default_user_agent;
+void BuildUserAgent(bool mimic_safari, std::string* result) {
#if defined(OS_WIN) || defined(OS_MACOSX)
int32 os_major_version = 0;
int32 os_minor_version = 0;
@@ -345,17 +345,19 @@ void SetUserAgentToDefault() {
// maximally compatible with Safari, we hope!!
std::string product;
- scoped_ptr<FileVersionInfo> version_info(
- FileVersionInfo::CreateFileVersionInfoForCurrentModule());
- if (version_info.get())
- product = "Chrome/" + WideToASCII(version_info->product_version());
+ if (!mimic_safari) {
+ scoped_ptr<FileVersionInfo> version_info(
+ FileVersionInfo::CreateFileVersionInfoForCurrentModule());
+ if (version_info.get())
+ product = "Chrome/" + WideToASCII(version_info->product_version());
+ }
if (product.empty())
- product = "Version/3.1";
+ product = "Version/3.2.1";
// Derived from Safari's UA string.
StringAppendF(
- &default_user_agent,
+ result,
#if defined(OS_WIN)
"Mozilla/5.0 (Windows; U; Windows NT %d.%d; en-US) AppleWebKit/%d.%d"
#elif defined(OS_MACOSX)
@@ -380,17 +382,22 @@ void SetUserAgentToDefault() {
// Windows. Some solution for embedding the Chrome version number needs to be
// found here.
StringAppendF(
- &default_user_agent,
+ result,
"Mozilla/5.0 (Linux; U; en-US) AppleWebKit/525.13 "
"(KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13");
#else
// TODO(port): we need something like FileVersionInfo for our UA string.
NOTIMPLEMENTED();
#endif
+}
+
+void SetUserAgentToDefault() {
+ static std::string default_user_agent;
+ BuildUserAgent(false, &default_user_agent);
user_agent = &default_user_agent;
}
-};
+} // namespace
void SetUserAgent(const std::string& new_user_agent) {
DCHECK(!user_agent_requested) << "Setting the user agent after someone has "
@@ -399,13 +406,23 @@ void SetUserAgent(const std::string& new_user_agent) {
overridden_user_agent = new_user_agent; // If you combine this with the
// previous line, the function only
// works the first time.
+ user_agent_is_overridden = true;
user_agent = &overridden_user_agent;
}
-const std::string& GetUserAgent() {
+const std::string& GetUserAgent(const GURL& url) {
if (!user_agent)
SetUserAgentToDefault();
user_agent_requested = true;
+ if (!user_agent_is_overridden) {
+ static std::string mimic_safari_user_agent;
+ // For hotmail, we need to spoof as Safari (bug 4111).
+ if (MatchPattern(url.host(), "*.mail.live.com")) {
+ if (mimic_safari_user_agent.empty())
+ BuildUserAgent(true, &mimic_safari_user_agent);
+ return mimic_safari_user_agent;
+ }
+ }
return *user_agent;
}
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index 50cd2c4..a3c4d2c 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -105,9 +105,10 @@ std::string GetWebKitVersion();
// inconsistent behavior.
void SetUserAgent(const std::string& new_user_agent);
-// Returns the user agent, which is usually the default user agent but may be
-// overriden by a call to SetUserAgent() (which should be done at startup).
-const std::string& GetUserAgent();
+// Returns the user agent to use for the given URL, which is usually the
+// default user agent but may be overriden by a call to SetUserAgent() (which
+// should be done at startup).
+const std::string& GetUserAgent(const GURL& url);
// Creates serialized state for the specified URL. This is a variant of
// HistoryItemToString (in glue_serialize) that is used during session restore
diff --git a/webkit/tools/test_shell/test_shell_request_context.cc b/webkit/tools/test_shell/test_shell_request_context.cc
index 8f8202d..2597f77 100644
--- a/webkit/tools/test_shell/test_shell_request_context.cc
+++ b/webkit/tools/test_shell/test_shell_request_context.cc
@@ -25,8 +25,6 @@ void TestShellRequestContext::Init(
bool no_proxy) {
cookie_store_ = new net::CookieMonster();
- user_agent_ = webkit_glue::GetUserAgent();
-
// hard-code A-L and A-C for test shells
accept_language_ = "en-us,en";
accept_charset_ = "iso-8859-1,*,utf-8";
@@ -51,3 +49,7 @@ TestShellRequestContext::~TestShellRequestContext() {
delete proxy_service_;
}
+const std::string& TestShellRequestContext::GetUserAgent(
+ const GURL& url) const {
+ return webkit_glue::GetUserAgent(url);
+}
diff --git a/webkit/tools/test_shell/test_shell_request_context.h b/webkit/tools/test_shell/test_shell_request_context.h
index 45a899d..daf3ab2 100644
--- a/webkit/tools/test_shell/test_shell_request_context.h
+++ b/webkit/tools/test_shell/test_shell_request_context.h
@@ -22,6 +22,8 @@ class TestShellRequestContext : public URLRequestContext {
~TestShellRequestContext();
+ virtual const std::string& GetUserAgent(const GURL& url) const;
+
private:
void Init(const std::wstring& cache_path, net::HttpCache::Mode cache_mode,
bool no_proxy);