summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 22:35:50 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-16 22:35:50 +0000
commitd7196e3474c92f1e85c32f98ad564a32604fa535 (patch)
treeac137140b97ff1af774775e80e0708c15fa28f6a
parenta65ed542245bbe6089590d06507892a704fb08f0 (diff)
downloadchromium_src-d7196e3474c92f1e85c32f98ad564a32604fa535.zip
chromium_src-d7196e3474c92f1e85c32f98ad564a32604fa535.tar.gz
chromium_src-d7196e3474c92f1e85c32f98ad564a32604fa535.tar.bz2
Removed the GetProductVersion function from webkit_glue and replace it with the BuildUserAgent function.
The BuildUserAgent function has been deleted from user_agent.cc. The implementation of this function in content\renderer_glue.cc calls the GetUserAgent API in ContentClient which is implemented by the embedder (Chrome). Added implementations of the BuildUserAgent function for test_shell and DumpRenderTree. To build the user agent string we need the webkit major and minor versions. Added getters for them in the webkit_glue namespace in the user_agent.h/.cc files. This helps reduce the implicit dependency of content on chrome. BUG=82454 Review URL: http://codereview.chromium.org/7166004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89415 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/chrome_renderer.gypi1
-rw-r--r--chrome/common/chrome_content_client.cc12
-rw-r--r--chrome/common/chrome_content_client.h4
-rw-r--r--chrome/renderer/chrome_renderer_glue.cc24
-rw-r--r--chrome_frame/html_utils.cc10
-rw-r--r--chrome_frame/renderer_glue.cc14
-rw-r--r--chrome_frame/test/html_util_unittests.cc4
-rw-r--r--content/common/content_client.cc4
-rw-r--r--content/common/content_client.h6
-rw-r--r--content/renderer/renderer_glue.cc5
-rwxr-xr-xwebkit/build/webkit_version.py11
-rw-r--r--webkit/glue/user_agent.cc29
-rw-r--r--webkit/glue/user_agent.h13
-rw-r--r--webkit/glue/webkit_glue.cc4
-rw-r--r--webkit/glue/webkit_glue.h7
-rw-r--r--webkit/glue/webkit_glue_dummy.cc5
-rw-r--r--webkit/support/webkit_support_glue.cc10
-rw-r--r--webkit/tools/test_shell/test_shell.cc5
18 files changed, 101 insertions, 67 deletions
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi
index 8f17d6b..356a870 100644
--- a/chrome/chrome_renderer.gypi
+++ b/chrome/chrome_renderer.gypi
@@ -105,7 +105,6 @@
'renderer/chrome_render_process_observer.h',
'renderer/chrome_render_view_observer.cc',
'renderer/chrome_render_view_observer.h',
- 'renderer/chrome_renderer_glue.cc',
'renderer/content_settings_observer.cc',
'renderer/content_settings_observer.h',
'renderer/devtools_agent.cc',
diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc
index 2d8c2ae..02c1ad1 100644
--- a/chrome/common/chrome_content_client.cc
+++ b/chrome/common/chrome_content_client.cc
@@ -9,12 +9,14 @@
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_number_conversions.h"
+#include "base/stringprintf.h"
#include "base/string_split.h"
#include "base/string_util.h"
#include "base/win/windows_version.h"
#include "chrome/common/child_process_logging.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/chrome_version_info.h"
#include "chrome/common/render_messages.h"
#include "content/common/pepper_plugin_registry.h"
#include "remoting/client/plugin/pepper_entrypoints.h"
@@ -24,6 +26,8 @@
#include "sandbox/src/sandbox.h"
#endif
+#include "webkit/glue/user_agent.h"
+
namespace {
const char* kPDFPluginName = "Chrome PDF Viewer";
@@ -291,6 +295,14 @@ bool ChromeContentClient::CanHandleWhileSwappedOut(
return false;
}
+std::string ChromeContentClient::GetUserAgent(bool mimic_windows) const {
+ chrome::VersionInfo version_info;
+ std::string product("Chrome/");
+ product += version_info.is_valid() ? version_info.Version() : "0.0.0.0";
+
+ return webkit_glue::BuildUserAgentHelper(mimic_windows, product);
+}
+
#if defined(OS_WIN)
bool ChromeContentClient::SandboxPlugin(CommandLine* command_line,
sandbox::TargetPolicy* policy) {
diff --git a/chrome/common/chrome_content_client.h b/chrome/common/chrome_content_client.h
index b408edf..0aa74dc 100644
--- a/chrome/common/chrome_content_client.h
+++ b/chrome/common/chrome_content_client.h
@@ -6,6 +6,8 @@
#define CHROME_COMMON_CHROME_CONTENT_CLIENT_H_
#pragma once
+#include <string>
+
#include "content/common/content_client.h"
namespace chrome {
@@ -20,6 +22,8 @@ class ChromeContentClient : public content::ContentClient {
virtual void AddPepperPlugins(std::vector<PepperPluginInfo>* plugins);
virtual bool CanSendWhileSwappedOut(const IPC::Message* msg);
virtual bool CanHandleWhileSwappedOut(const IPC::Message& msg);
+ virtual std::string GetUserAgent(bool mimic_windows) const;
+
#if defined(OS_WIN)
virtual bool SandboxPlugin(CommandLine* command_line,
sandbox::TargetPolicy* policy);
diff --git a/chrome/renderer/chrome_renderer_glue.cc b/chrome/renderer/chrome_renderer_glue.cc
deleted file mode 100644
index 461970c..0000000
--- a/chrome/renderer/chrome_renderer_glue.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) 2011 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.
-
-// This file provides the Chrome-specific embedder's side of random webkit glue
-// functions.
-
-#include "base/utf_string_conversions.h"
-#include "chrome/common/chrome_version_info.h"
-#include "content/common/view_messages.h"
-#include "content/renderer/render_thread.h"
-#include "webkit/glue/webkit_glue.h"
-
-namespace webkit_glue {
-
-std::string GetProductVersion() {
- chrome::VersionInfo version_info;
- std::string product("Chrome/");
- product += version_info.is_valid() ? version_info.Version()
- : "0.0.0.0";
- return product;
-}
-
-} // namespace webkit_glue
diff --git a/chrome_frame/html_utils.cc b/chrome_frame/html_utils.cc
index 25e4829..9458166 100644
--- a/chrome_frame/html_utils.cc
+++ b/chrome_frame/html_utils.cc
@@ -10,6 +10,7 @@
#include "base/string_util.h"
#include "base/string_tokenizer.h"
#include "base/stringprintf.h"
+#include "chrome/common/chrome_version_info.h"
#include "chrome_frame/utils.h"
#include "net/base/net_util.h"
#include "webkit/glue/user_agent.h"
@@ -378,7 +379,14 @@ const char* GetChromeUserAgent() {
_pAtlModule->m_csStaticDataInitAndTypeInfo.Lock();
if (!g_chrome_user_agent[0]) {
std::string ua;
- webkit_glue::BuildUserAgent(false, &ua);
+
+ chrome::VersionInfo version_info;
+ std::string product("Chrome/");
+ product += version_info.is_valid() ? version_info.Version()
+ : "0.0.0.0";
+
+ ua = webkit_glue::BuildUserAgentHelper(false, product);
+
DCHECK(ua.length() < arraysize(g_chrome_user_agent));
lstrcpynA(g_chrome_user_agent, ua.c_str(),
arraysize(g_chrome_user_agent) - 1);
diff --git a/chrome_frame/renderer_glue.cc b/chrome_frame/renderer_glue.cc
index 6f4b7fe..64890ef 100644
--- a/chrome_frame/renderer_glue.cc
+++ b/chrome_frame/renderer_glue.cc
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "webkit/glue/user_agent.h"
+#include "webkit/glue/webkit_glue.h"
+
#include "chrome/common/chrome_version_info.h"
class GURL;
@@ -12,23 +15,16 @@ bool IsPluginProcess() {
namespace webkit_glue {
-bool IsDefaultPluginEnabled() {
- return false;
-}
-
bool FindProxyForUrl(const GURL& url, std::string* proxy_list) {
return false;
}
-// This function is called from BuildUserAgent so we have our own version
-// here instead of pulling in the whole renderer lib where this function
-// is implemented for Chrome.
-std::string GetProductVersion() {
+std::string BuildUserAgent(bool mimic_windows) {
chrome::VersionInfo version_info;
std::string product("Chrome/");
product += version_info.is_valid() ? version_info.Version()
: "0.0.0.0";
- return product;
+ return webkit_glue::BuildUserAgentHelper(mimic_windows, product);
}
} // end namespace webkit_glue
diff --git a/chrome_frame/test/html_util_unittests.cc b/chrome_frame/test/html_util_unittests.cc
index eb7d386..9d59106 100644
--- a/chrome_frame/test/html_util_unittests.cc
+++ b/chrome_frame/test/html_util_unittests.cc
@@ -24,7 +24,7 @@
#include "chrome_frame/chrome_frame_delegate.h"
#include "chrome_frame/html_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/glue/user_agent.h"
+#include "webkit/glue/webkit_glue.h"
const char kChromeFrameUserAgent[] = "chromeframe";
@@ -404,7 +404,7 @@ TEST_F(HtmlUtilUnittest, GetDefaultUserAgentHeaderWithCFTag) {
TEST_F(HtmlUtilUnittest, GetChromeUserAgent) {
std::string chrome_ua;
- webkit_glue::BuildUserAgent(false, &chrome_ua);
+ chrome_ua = webkit_glue::BuildUserAgent(false);
EXPECT_FALSE(chrome_ua.empty());
const char* ua = http_utils::GetChromeUserAgent();
EXPECT_EQ(0, chrome_ua.compare(ua));
diff --git a/content/common/content_client.cc b/content/common/content_client.cc
index 9b52ff7..c34765f 100644
--- a/content/common/content_client.cc
+++ b/content/common/content_client.cc
@@ -31,6 +31,10 @@ bool ContentClient::CanHandleWhileSwappedOut(const IPC::Message& msg) {
return false;
}
+std::string ContentClient::GetUserAgent(bool mimic_windows) const {
+ return std::string();
+}
+
#if defined(OS_WIN)
bool ContentClient::SandboxPlugin(CommandLine* command_line,
sandbox::TargetPolicy* policy) {
diff --git a/content/common/content_client.h b/content/common/content_client.h
index 0e57fd0..9934411 100644
--- a/content/common/content_client.h
+++ b/content/common/content_client.h
@@ -6,6 +6,7 @@
#define CONTENT_COMMON_CONTENT_CLIENT_H_
#pragma once
+#include <string>
#include <vector>
#include "base/basictypes.h"
@@ -69,6 +70,11 @@ class ContentClient {
// behalf of a swapped out renderer.
virtual bool CanHandleWhileSwappedOut(const IPC::Message& msg);
+ // Returns the user agent. If mimic_windows is true then the embedder can
+ // return a fake Windows user agent. This is a workaround for broken
+ // websites.
+ virtual std::string GetUserAgent(bool mimic_windows) const;
+
#if defined(OS_WIN)
// Allows the embedder to sandbox a plugin, and apply a custom policy.
virtual bool SandboxPlugin(CommandLine* command_line,
diff --git a/content/renderer/renderer_glue.cc b/content/renderer/renderer_glue.cc
index beb5a1b..91a1078 100644
--- a/content/renderer/renderer_glue.cc
+++ b/content/renderer/renderer_glue.cc
@@ -17,6 +17,7 @@
#include "base/shared_memory.h"
#include "base/string_util.h"
#include "content/common/clipboard_messages.h"
+#include "content/common/content_client.h"
#include "content/common/content_switches.h"
#include "content/common/socket_stream_dispatcher.h"
#include "content/common/url_constants.h"
@@ -291,4 +292,8 @@ string16 GetLocalizedString(int message_id) {
return l10n_util::GetStringUTF16(message_id);
}
+std::string BuildUserAgent(bool mimic_windows) {
+ return content::GetContentClient()->GetUserAgent(mimic_windows);
+}
+
} // namespace webkit_glue
diff --git a/webkit/build/webkit_version.py b/webkit/build/webkit_version.py
index f488a2e..c365b18 100755
--- a/webkit/build/webkit_version.py
+++ b/webkit/build/webkit_version.py
@@ -12,7 +12,16 @@ import os
import re
import sys
-sys.path.insert(0, '../../build/util')
+# Get the full path of the current script which would be something like
+# src/webkit/build/webkit_version.py and navigate backwards twice to strip the
+# last two path components to get to the srcroot.
+# This is to ensure that the script can load the lastchange module by updating
+# the sys.path variable with the desired location.
+path = os.path.dirname(os.path.realpath(__file__))
+path = os.path.dirname(os.path.dirname(path))
+path = os.path.join(path, 'build', 'util')
+
+sys.path.insert(0, path)
import lastchange
def ReadVersionFile(fname):
diff --git a/webkit/glue/user_agent.cc b/webkit/glue/user_agent.cc
index f92bc9a..7f9b438 100644
--- a/webkit/glue/user_agent.cc
+++ b/webkit/glue/user_agent.cc
@@ -21,10 +21,6 @@
namespace webkit_glue {
-// Forward declare GetProductVersionInfo. This is implemented in
-// renderer_glue.cc as part of the renderer lib.
-std::string GetProductVersion();
-
std::string GetWebKitVersion() {
return base::StringPrintf("%d.%d (%s)",
WEBKIT_VERSION_MAJOR,
@@ -109,7 +105,16 @@ std::string BuildOSCpuInfo() {
return os_cpu;
}
-void BuildUserAgent(bool mimic_windows, std::string* result) {
+int GetWebKitMajorVersion() {
+ return WEBKIT_VERSION_MAJOR;
+}
+
+int GetWebKitMinorVersion() {
+ return WEBKIT_VERSION_MINOR;
+}
+
+std::string BuildUserAgentHelper(bool mimic_windows,
+ const std::string& product) {
const char kUserAgentPlatform[] =
#if defined(OS_WIN)
"";
@@ -121,23 +126,25 @@ void BuildUserAgent(bool mimic_windows, std::string* result) {
"Unknown; ";
#endif
- // Get the product name and version, and replace Safari's Version/X string
- // with it. This is done to expose our product name in a manner that is
- // maximally compatible with Safari, we hope!!
- std::string product = GetProductVersion();
+ std::string user_agent;
+
+ // Replace Safari's Version/X string with the product name/version passed in.
+ // This is done to expose our product name in a manner that is maximally
+ // compatible with Safari, we hope!!
// Derived from Safari's UA string.
base::StringAppendF(
- result,
+ &user_agent,
"Mozilla/5.0 (%s%s) AppleWebKit/%d.%d"
" (KHTML, like Gecko) %s Safari/%d.%d",
mimic_windows ? "Windows " : kUserAgentPlatform,
- BuildOSCpuInfo().c_str(),
+ webkit_glue::BuildOSCpuInfo().c_str(),
WEBKIT_VERSION_MAJOR,
WEBKIT_VERSION_MINOR,
product.c_str(),
WEBKIT_VERSION_MAJOR,
WEBKIT_VERSION_MINOR);
+ return user_agent;
}
} // namespace webkit_glue
diff --git a/webkit/glue/user_agent.h b/webkit/glue/user_agent.h
index 62c8324..583eef0 100644
--- a/webkit/glue/user_agent.h
+++ b/webkit/glue/user_agent.h
@@ -11,17 +11,20 @@
namespace webkit_glue {
-// Construct the User-Agent header, filling in |result|.
-// The other parameters are workarounds for broken websites:
-// - If mimic_windows is true, produce a fake Windows Chrome string.
-void BuildUserAgent(bool mimic_windows, std::string* result);
-
// Builds a User-agent compatible string that describes the OS and CPU type.
std::string BuildOSCpuInfo();
// Returns the WebKit version, in the form "major.minor (branch@revision)".
std::string GetWebKitVersion();
+// The following 2 functions return the major and minor webkit versions.
+int GetWebKitMajorVersion();
+int GetWebKitMinorVersion();
+
+// Helper function to generate the user agent.
+// - If mimic_windows is true, produce a fake Windows Chrome string..
+std::string BuildUserAgentHelper(bool mimic_windows,
+ const std::string& product);
} // namespace webkit_glue
#endif // WEBKIT_GLUE_USER_AGENT_H_
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index 6e43e8b88..3c86c58 100644
--- a/webkit/glue/webkit_glue.cc
+++ b/webkit/glue/webkit_glue.cc
@@ -356,7 +356,7 @@ static base::LazyInstance<UserAgentState> g_user_agent(
base::LINKER_INITIALIZED);
void SetUserAgentToDefault() {
- BuildUserAgent(false, &g_user_agent.Get().user_agent);
+ g_user_agent.Get().user_agent = BuildUserAgent(false);
}
} // namespace
@@ -383,7 +383,7 @@ const std::string& GetUserAgent(const GURL& url) {
// http://bugs.chromium.org/11136
// TODO(evanm): remove this if Yahoo fixes their sniffing.
if (g_user_agent.Get().mimic_windows_user_agent.empty())
- BuildUserAgent(true, &g_user_agent.Get().mimic_windows_user_agent);
+ g_user_agent.Get().mimic_windows_user_agent = BuildUserAgent(true);
return g_user_agent.Get().mimic_windows_user_agent;
}
#endif
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index 2e24ece..37a360f 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -152,6 +152,10 @@ WebKit::WebCanvas* ToWebCanvas(skia::PlatformCanvas*);
// used to get memory usage statistics.
int GetGlyphPageCount();
+// Construct the User-Agent header, filling in |result|.
+// - If mimic_windows is true, produce a fake Windows Chrome string.
+std::string BuildUserAgent(bool mimic_windows);
+
//---- END FUNCTIONS IMPLEMENTED BY WEBKIT/GLUE -------------------------------
@@ -239,9 +243,6 @@ void ClearHostResolverCache();
// debugging.
void ClearPredictorCache();
-// Returns the product version. E.g., Chrome/4.1.333.0
-std::string GetProductVersion();
-
// Returns true if the embedder is running in single process mode.
bool IsSingleProcess();
diff --git a/webkit/glue/webkit_glue_dummy.cc b/webkit/glue/webkit_glue_dummy.cc
index 9947c3c..e05dd42 100644
--- a/webkit/glue/webkit_glue_dummy.cc
+++ b/webkit/glue/webkit_glue_dummy.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "webkit/glue/webkit_glue.h"
+#include "webkit/glue/user_agent.h"
//------------------------------------------------------------------------------
@@ -16,5 +17,9 @@ bool g_forcefully_terminate_plugin_process = false;
void SetUserAgent(const std::string& new_user_agent) {
}
+std::string BuildUserAgentHelper(bool mimic_windows,
+ const std::string& product) {
+ return std::string();
+}
} // namespace webkit_glue
diff --git a/webkit/support/webkit_support_glue.cc b/webkit/support/webkit_support_glue.cc
index f7bcf50..02a2233 100644
--- a/webkit/support/webkit_support_glue.cc
+++ b/webkit/support/webkit_support_glue.cc
@@ -7,6 +7,7 @@
#include "base/base_paths.h"
#include "base/path_service.h"
#include "googleurl/src/gurl.h"
+#include "webkit/glue/user_agent.h"
#include "webkit/plugins/npapi/plugin_list.h"
// Functions needed by webkit_glue.
@@ -34,10 +35,6 @@ void GetPlugins(bool refresh,
}
}
-bool IsDefaultPluginEnabled() {
- return false;
-}
-
void AppendToLog(const char*, int, const char*) {
}
@@ -69,8 +66,9 @@ void ClearHostResolverCache() {
void ClearPredictorCache() {
}
-std::string GetProductVersion() {
- return std::string("DumpRenderTree/0.0.0.0");
+std::string BuildUserAgent(bool mimic_windows) {
+ return webkit_glue::BuildUserAgentHelper(mimic_windows,
+ "DumpRenderTree/0.0.0.0");
}
bool GetPluginFinderURL(std::string* plugin_finder_url) {
diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc
index db79be7..651635c 100644
--- a/webkit/tools/test_shell/test_shell.cc
+++ b/webkit/tools/test_shell/test_shell.cc
@@ -44,6 +44,7 @@
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/size.h"
#include "webkit/glue/glue_serialize.h"
+#include "webkit/glue/user_agent.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webpreferences.h"
#include "webkit/plugins/npapi/plugin_list.h"
@@ -662,8 +663,8 @@ void EnableSpdy(bool enable) {
// Used in benchmarking, Ignored for test_shell.
}
-std::string GetProductVersion() {
- return std::string("Chrome/0.0.0.0");
+std::string BuildUserAgent(bool mimic_windows) {
+ return webkit_glue::BuildUserAgentHelper(mimic_windows, "Chrome/0.0.0.0");
}
bool IsSingleProcess() {