summaryrefslogtreecommitdiffstats
path: root/chrome_frame
diff options
context:
space:
mode:
authortommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 15:05:02 +0000
committertommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 15:05:02 +0000
commite67a73f47398a8d89a98abde04f3d4c7695a6d30 (patch)
treeae5652a01e709405ab8fc3c2887b0b96b38ca490 /chrome_frame
parent22e1168491f768ae6ff20ded07b3063ac5fe34db (diff)
downloadchromium_src-e67a73f47398a8d89a98abde04f3d4c7695a6d30.zip
chromium_src-e67a73f47398a8d89a98abde04f3d4c7695a6d30.tar.gz
chromium_src-e67a73f47398a8d89a98abde04f3d4c7695a6d30.tar.bz2
When GCF is the default renderer, use Chrome's User-agent header instead of IE's.
TEST=Set IsDefaultRenderer to 1 (REG_DWORD) under the ChromeFrame registry key. Check if the User agent header in requests is the Chrome user agent. Then set the value to 0 and make sure the regular user-agent header is there. BUG=50788 Review URL: http://codereview.chromium.org/3130016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57991 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r--chrome_frame/chrome_frame.gyp10
-rw-r--r--chrome_frame/chrome_frame_activex_base.h3
-rw-r--r--chrome_frame/chrome_frame_automation.cc7
-rw-r--r--chrome_frame/chrome_frame_automation.h3
-rw-r--r--chrome_frame/html_utils.cc27
-rw-r--r--chrome_frame/html_utils.h3
-rw-r--r--chrome_frame/http_negotiate.cc47
-rw-r--r--chrome_frame/http_negotiate.h7
-rw-r--r--chrome_frame/renderer_glue.cc21
-rw-r--r--chrome_frame/test/html_util_unittests.cc11
-rw-r--r--chrome_frame/test/util_unittests.cc70
-rw-r--r--chrome_frame/urlmon_url_request.cc7
-rw-r--r--chrome_frame/utils.cc42
-rw-r--r--chrome_frame/utils.h19
14 files changed, 217 insertions, 60 deletions
diff --git a/chrome_frame/chrome_frame.gyp b/chrome_frame/chrome_frame.gyp
index 13f61f1..fa11702 100644
--- a/chrome_frame/chrome_frame.gyp
+++ b/chrome_frame/chrome_frame.gyp
@@ -132,6 +132,7 @@
'chrome_launcher.h',
'chrome_launcher_unittest.cc',
'function_stub_unittest.cc',
+ 'renderer_glue.cc',
'test/chrome_frame_test_utils.h',
'test/chrome_frame_test_utils.cc',
'test/com_message_event_unittest.cc',
@@ -231,7 +232,7 @@
'chrome_frame_ie',
'chrome_frame_npapi',
'chrome_frame_strings',
- 'npchrome_frame',
+ 'npchrome_frame',
'xulrunner_sdk',
],
'sources': [
@@ -270,6 +271,7 @@
'test/win_event_receiver.h',
'chrome_tab.h',
'chrome_tab.idl',
+ 'renderer_glue.cc',
'test_utils.cc',
'test_utils.h',
],
@@ -311,6 +313,7 @@
'../base/base.gyp:test_support_base',
'../build/temp_gyp/googleurl.gyp:googleurl',
'../chrome/chrome.gyp:common',
+ '../chrome/chrome.gyp:debugger',
'../chrome/chrome.gyp:test_support_ui',
'../chrome/chrome.gyp:utility',
'../testing/gmock.gyp:gmock',
@@ -457,6 +460,7 @@
'dependencies': [
'../base/base.gyp:test_support_base',
'../chrome/chrome.gyp:browser',
+ '../chrome/chrome.gyp:debugger',
'../chrome/chrome.gyp:renderer',
'../chrome/chrome.gyp:test_support_common',
'../testing/gtest.gyp:gtest',
@@ -605,6 +609,7 @@
'../build/temp_gyp/googleurl.gyp:googleurl',
'../third_party/libxml/libxml.gyp:libxml',
'../third_party/bzip2/bzip2.gyp:bzip2',
+ '../webkit/support/webkit_support.gyp:webkit_user_agent',
],
'sources': [
'bho.cc',
@@ -759,12 +764,12 @@
'chrome_frame_utils',
'xulrunner_sdk',
'chrome_frame_launcher.gyp:chrome_launcher',
+ '../build/temp_gyp/googleurl.gyp:googleurl',
'chrome_frame_launcher.gyp:chrome_frame_helper',
'chrome_frame_launcher.gyp:chrome_frame_helper_dll',
'../chrome/chrome.gyp:chrome_version_header',
'../chrome/chrome.gyp:common',
'../chrome/chrome.gyp:utility',
- '../build/temp_gyp/googleurl.gyp:googleurl',
],
'sources': [
'chrome_frame_npapi.rgs',
@@ -781,6 +786,7 @@
'resources/tlb_resource.rc',
'chrome_tab.rgs',
'chrome_tab_version.rc',
+ 'renderer_glue.cc',
'resource.h',
],
'include_dirs': [
diff --git a/chrome_frame/chrome_frame_activex_base.h b/chrome_frame/chrome_frame_activex_base.h
index c5ec65e..c2c4035 100644
--- a/chrome_frame/chrome_frame_activex_base.h
+++ b/chrome_frame/chrome_frame_activex_base.h
@@ -37,9 +37,6 @@
// Include without path to make GYP build see it.
#include "chrome_tab.h" // NOLINT
-static const wchar_t kIexploreProfileName[] = L"iexplore";
-static const wchar_t kRundllProfileName[] = L"rundll32";
-
// Connection point class to support firing IChromeFrameEvents (dispinterface).
template<class T>
class ATL_NO_VTABLE ProxyDIChromeFrameEvents
diff --git a/chrome_frame/chrome_frame_automation.cc b/chrome_frame/chrome_frame_automation.cc
index aa89256..32fc24d 100644
--- a/chrome_frame/chrome_frame_automation.cc
+++ b/chrome_frame/chrome_frame_automation.cc
@@ -209,8 +209,11 @@ AutomationProxyCacheEntry::AutomationProxyCacheEntry(
DCHECK(delegate);
thread_.reset(new base::Thread(WideToASCII(profile_name).c_str()));
thread_->Start();
+ // Use scoped_refptr so that the params will get released when the task
+ // has been run.
+ scoped_refptr<ChromeFrameLaunchParams> ref_params(params);
thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this,
- &AutomationProxyCacheEntry::CreateProxy, params, delegate));
+ &AutomationProxyCacheEntry::CreateProxy, ref_params, delegate));
}
AutomationProxyCacheEntry::~AutomationProxyCacheEntry() {
@@ -408,7 +411,7 @@ void AutomationProxyCacheEntry::SendUMAData() {
}
if (!proxy_.get()) {
- NOTREACHED() << __FUNCTION__ << " Invalid proxy entry";
+ DLOG(WARNING) << __FUNCTION__ << " NULL proxy, can't send UMA data";
} else {
ChromeFrameHistogramSnapshots::HistogramPickledList histograms =
snapshots_->GatherAllHistograms();
diff --git a/chrome_frame/chrome_frame_automation.h b/chrome_frame/chrome_frame_automation.h
index e2bdfa0..7bb572a 100644
--- a/chrome_frame/chrome_frame_automation.h
+++ b/chrome_frame/chrome_frame_automation.h
@@ -76,6 +76,7 @@ class ChromeFrameAutomationProxyImpl
virtual scoped_refptr<TabProxy> CreateTabProxy(int handle);
virtual void ReleaseTabProxy(AutomationHandle handle);
+
virtual std::string server_version() {
return AutomationProxy::server_version();
}
@@ -103,7 +104,7 @@ class ChromeFrameAutomationProxyImpl
// This class contains information used for launching chrome.
class ChromeFrameLaunchParams : // NOLINT
- public base::RefCounted<ChromeFrameLaunchParams> {
+ public base::RefCountedThreadSafe<ChromeFrameLaunchParams> {
public:
ChromeFrameLaunchParams(const GURL& url, const GURL& referrer,
const FilePath& profile_path,
diff --git a/chrome_frame/html_utils.cc b/chrome_frame/html_utils.cc
index 3b71845..0f7d8ab 100644
--- a/chrome_frame/html_utils.cc
+++ b/chrome_frame/html_utils.cc
@@ -11,6 +11,7 @@
#include "base/string_tokenizer.h"
#include "chrome_frame/utils.h"
#include "net/base/net_util.h"
+#include "webkit/glue/user_agent.h"
const wchar_t kQuotes[] = L"\"'";
const char kXFrameOptionsHeader[] = "X-Frame-Options";
@@ -289,22 +290,23 @@ bool HTMLScanner::NextTag(StringRange* html_string, StringRange* tag) {
namespace http_utils {
const char kChromeFrameUserAgent[] = "chromeframe";
+static char g_cf_user_agent[100] = {0};
+static char g_chrome_user_agent[255] = {0};
const char* GetChromeFrameUserAgent() {
- static char cf_user_agent[100] = {0};
- if (!cf_user_agent[0]) {
+ if (!g_cf_user_agent[0]) {
_pAtlModule->m_csStaticDataInitAndTypeInfo.Lock();
- if (!cf_user_agent[0]) {
+ if (!g_cf_user_agent[0]) {
uint32 high_version = 0, low_version = 0;
GetModuleVersion(reinterpret_cast<HMODULE>(&__ImageBase), &high_version,
&low_version);
- wsprintfA(cf_user_agent, "%s/%i.%i.%i.%i", kChromeFrameUserAgent,
+ wsprintfA(g_cf_user_agent, "%s/%i.%i.%i.%i", kChromeFrameUserAgent,
HIWORD(high_version), LOWORD(high_version),
HIWORD(low_version), LOWORD(low_version));
}
_pAtlModule->m_csStaticDataInitAndTypeInfo.Unlock();
}
- return cf_user_agent;
+ return g_cf_user_agent;
}
std::string AddChromeFrameToUserAgentValue(const std::string& value) {
@@ -332,6 +334,21 @@ std::string GetDefaultUserAgentHeaderWithCFTag() {
return "User-Agent: " + AddChromeFrameToUserAgentValue(ua);
}
+const char* GetChromeUserAgent() {
+ if (!g_chrome_user_agent[0]) {
+ _pAtlModule->m_csStaticDataInitAndTypeInfo.Lock();
+ if (!g_chrome_user_agent[0]) {
+ std::string ua;
+ webkit_glue::BuildUserAgent(false, &ua);
+ DCHECK(ua.length() < arraysize(g_chrome_user_agent));
+ lstrcpynA(g_chrome_user_agent, ua.c_str(),
+ arraysize(g_chrome_user_agent) - 1);
+ }
+ _pAtlModule->m_csStaticDataInitAndTypeInfo.Unlock();
+ }
+ return g_chrome_user_agent;
+}
+
std::string GetDefaultUserAgent() {
std::string ret;
DWORD size = MAX_PATH;
diff --git a/chrome_frame/html_utils.h b/chrome_frame/html_utils.h
index 8296b5f..8bffb32 100644
--- a/chrome_frame/html_utils.h
+++ b/chrome_frame/html_utils.h
@@ -130,6 +130,9 @@ std::string AddChromeFrameToUserAgentValue(const std::string& value);
// NOTE: The returned string includes the "User-Agent: " header name.
std::string GetDefaultUserAgentHeaderWithCFTag();
+// Returns the User-Agent header as would be used by Chrome itself.
+const char* GetChromeUserAgent();
+
// Fetches the default user agent string from urlmon.
// This value does not include the "User-Agent:" header name.
std::string GetDefaultUserAgent();
diff --git a/chrome_frame/http_negotiate.cc b/chrome_frame/http_negotiate.cc
index dd62de1..403a313 100644
--- a/chrome_frame/http_negotiate.cc
+++ b/chrome_frame/http_negotiate.cc
@@ -25,6 +25,7 @@
#include "net/http/http_util.h"
const char kUACompatibleHttpHeader[] = "x-ua-compatible";
+const char kLowerCaseUserAgent[] = "user-agent";
// From the latest urlmon.h. Symbol name prepended with LOCAL_ to
// avoid conflict (and therefore build errors) for those building with
@@ -98,7 +99,6 @@ class SimpleBindStatusCallback : public CComObjectRootEx<CComSingleThreadModel>,
std::string AppendCFUserAgentString(LPCWSTR headers,
LPCWSTR additional_headers) {
- static const char kLowerCaseUserAgent[] = "user-agent";
using net::HttpUtil;
std::string ascii_headers;
@@ -106,7 +106,7 @@ std::string AppendCFUserAgentString(LPCWSTR headers,
ascii_headers = WideToASCII(additional_headers);
}
- // Extract "User-Agent" from |additiona_headers| or |headers|.
+ // Extract "User-Agent" from |additional_headers| or |headers|.
HttpUtil::HeadersIterator headers_iterator(ascii_headers.begin(),
ascii_headers.end(), "\r\n");
std::string user_agent_value;
@@ -116,7 +116,7 @@ std::string AppendCFUserAgentString(LPCWSTR headers,
// See if there's a user-agent header specified in the original headers.
std::string original_headers(WideToASCII(headers));
HttpUtil::HeadersIterator original_it(original_headers.begin(),
- original_headers.end(), "\r\n");
+ original_headers.end(), "\r\n");
if (original_it.AdvanceTo(kLowerCaseUserAgent))
user_agent_value = original_it.values();
}
@@ -145,6 +145,32 @@ std::string AppendCFUserAgentString(LPCWSTR headers,
return new_headers;
}
+std::string ReplaceOrAddUserAgent(LPCWSTR headers,
+ const std::string& user_agent_value) {
+ DCHECK(headers);
+ using net::HttpUtil;
+
+ std::string ascii_headers(WideToASCII(headers));
+
+ // Extract "User-Agent" from the headers.
+ HttpUtil::HeadersIterator headers_iterator(ascii_headers.begin(),
+ ascii_headers.end(), "\r\n");
+
+ // Build new headers, skip the existing user agent value from
+ // existing headers.
+ std::string new_headers;
+ while (headers_iterator.GetNext()) {
+ std::string name(headers_iterator.name());
+ if (!LowerCaseEqualsASCII(name, kLowerCaseUserAgent)) {
+ new_headers += name + ": " + headers_iterator.values() + "\r\n";
+ }
+ }
+
+ new_headers += "User-Agent: " + user_agent_value;
+ new_headers += "\r\n";
+ return new_headers;
+}
+
HRESULT GetBrowserServiceFromProtocolSink(IInternetProtocolSink* sink,
IBrowserService** browser_service) {
DCHECK(browser_service);
@@ -278,7 +304,7 @@ HRESULT HttpNegotiatePatch::BeginningTransaction(
DLOG(INFO) << "No NavigationManager";
}
- std::string updated = AppendCFUserAgentString(headers, *additional_headers);
+ std::string updated(AppendCFUserAgentString(headers, *additional_headers));
*additional_headers = reinterpret_cast<wchar_t*>(::CoTaskMemRealloc(
*additional_headers, (updated.length() + 1) * sizeof(wchar_t)));
lstrcpyW(*additional_headers, ASCIIToWide(updated).c_str());
@@ -416,9 +442,16 @@ STDMETHODIMP UserAgentAddOn::BeginningTransaction(LPCWSTR url, LPCWSTR headers,
}
if (hr == S_OK) {
- // Add "chromeframe" user-agent string.
- std::string updated_headers = AppendCFUserAgentString(headers,
- *additional_headers);
+ std::string updated_headers;
+ if (IsGcfDefaultRenderer() && IsOptInUrl(url)) {
+ // Replace the user-agent header with Chrome's.
+ updated_headers = ReplaceOrAddUserAgent(*additional_headers,
+ http_utils::GetChromeUserAgent());
+ } else {
+ // Add "chromeframe" user-agent string.
+ updated_headers = AppendCFUserAgentString(headers, *additional_headers);
+ }
+
*additional_headers = reinterpret_cast<wchar_t*>(::CoTaskMemRealloc(
*additional_headers, (updated_headers.length() + 1) * sizeof(wchar_t)));
lstrcpyW(*additional_headers, ASCIIToWide(updated_headers).c_str());
diff --git a/chrome_frame/http_negotiate.h b/chrome_frame/http_negotiate.h
index dd4748a..a4d135a 100644
--- a/chrome_frame/http_negotiate.h
+++ b/chrome_frame/http_negotiate.h
@@ -86,9 +86,14 @@ extern const int LOCAL_BINDSTATUS_SERVER_MIMETYPEAVAILABLE;
// The function is a public since we want to use it from
// UrlmonUrlRequest::BeginningTransaction for the unusual but yet possible case
// when |headers| contains an User-Agent string.
-// TODO(stoyan): Add unit test.
std::string AppendCFUserAgentString(LPCWSTR headers,
LPCWSTR additional_headers);
+
+// Adds or replaces the User-Agent header in a set of HTTP headers.
+// Arguments are the same as with AppendCFUserAgentString.
+std::string ReplaceOrAddUserAgent(LPCWSTR headers,
+ const std::string& user_agent_value);
+
// Simple class that wraps IHttpNegotiate interface and adds "chromeframe"
// to User-agent Http header.
class UserAgentAddOn : public IHttpNegotiate {
diff --git a/chrome_frame/renderer_glue.cc b/chrome_frame/renderer_glue.cc
new file mode 100644
index 0000000..8980e97
--- /dev/null
+++ b/chrome_frame/renderer_glue.cc
@@ -0,0 +1,21 @@
+// Copyright (c) 2010 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 "chrome/common/chrome_version_info.h"
+
+namespace webkit_glue {
+
+// 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() {
+ chrome::VersionInfo version_info;
+ std::string product("Chrome/");
+ product += version_info.is_valid() ? version_info.Version()
+ : "0.0.0.0";
+ return product;
+}
+
+} // end namespace webkit_glue
+
diff --git a/chrome_frame/test/html_util_unittests.cc b/chrome_frame/test/html_util_unittests.cc
index 055ed8b..02b54a4 100644
--- a/chrome_frame/test/html_util_unittests.cc
+++ b/chrome_frame/test/html_util_unittests.cc
@@ -19,11 +19,12 @@
#include "base/utf_string_conversions.h"
#include "net/base/net_util.h"
+#include "chrome/browser/automation/url_request_automation_job.h"
#include "chrome_frame/chrome_frame_automation.h"
#include "chrome_frame/chrome_frame_delegate.h"
#include "chrome_frame/html_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "chrome/browser/automation/url_request_automation_job.h"
+#include "webkit/glue/user_agent.h"
const char kChromeFrameUserAgent[] = "chromeframe";
@@ -297,6 +298,14 @@ TEST_F(HtmlUtilUnittest, GetDefaultUserAgentHeaderWithCFTag) {
EXPECT_NE(std::string::npos, ua.find(kChromeFrameUserAgent));
}
+TEST_F(HtmlUtilUnittest, GetChromeUserAgent) {
+ std::string chrome_ua;
+ webkit_glue::BuildUserAgent(false, &chrome_ua);
+ EXPECT_FALSE(chrome_ua.empty());
+ const char* ua = http_utils::GetChromeUserAgent();
+ EXPECT_EQ(0, chrome_ua.compare(ua));
+}
+
TEST_F(HtmlUtilUnittest, GetDefaultUserAgent) {
std::string ua(http_utils::GetDefaultUserAgent());
EXPECT_NE(0u, ua.length());
diff --git a/chrome_frame/test/util_unittests.cc b/chrome_frame/test/util_unittests.cc
index f8ef22e..8d91434 100644
--- a/chrome_frame/test/util_unittests.cc
+++ b/chrome_frame/test/util_unittests.cc
@@ -5,6 +5,7 @@
#include "base/file_path.h"
#include "base/file_version_info.h"
#include "base/file_version_info_win.h"
+#include "base/registry.h"
#include "chrome_frame/utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -276,12 +277,65 @@ TEST(UtilTests, CanNavigateTest) {
SetConfigBool(kAllowUnsafeURLs, enable_gcf);
}
-TEST(UtilTests, ParseVersionTest) {
- uint32 high = 0, low = 0;
- EXPECT_FALSE(ParseVersion(L"", &high, &low));
- EXPECT_TRUE(ParseVersion(L"1", &high, &low) && high == 1 && low == 0);
- EXPECT_TRUE(ParseVersion(L"1.", &high, &low) && high == 1 && low == 0);
- EXPECT_TRUE(ParseVersion(L"1.2", &high, &low) && high == 1 && low == 2);
- EXPECT_TRUE(ParseVersion(L"1.2.3.4", &high, &low) && high == 1 && low == 2);
- EXPECT_TRUE(ParseVersion(L"10.20", &high, &low) && high == 10 && low == 20);
+TEST(UtilTests, IsDefaultRendererTest) {
+ RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS);
+ EXPECT_TRUE(config_key.Valid());
+
+ DWORD saved_default_renderer = 0; // NOLINT
+ config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer);
+
+ config_key.DeleteValue(kEnableGCFRendererByDefault);
+ EXPECT_FALSE(IsGcfDefaultRenderer());
+
+ config_key.WriteValue(kEnableGCFRendererByDefault, static_cast<DWORD>(0));
+ EXPECT_FALSE(IsGcfDefaultRenderer());
+
+ config_key.WriteValue(kEnableGCFRendererByDefault, static_cast<DWORD>(1));
+ EXPECT_TRUE(IsGcfDefaultRenderer());
+
+ config_key.WriteValue(kEnableGCFRendererByDefault, saved_default_renderer);
+}
+
+TEST(UtilTests, IsOptInUrlTest) {
+ // Open all the keys we need.
+ RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS);
+ EXPECT_TRUE(config_key.Valid());
+ RegKey opt_for_gcf(config_key.Handle(), kRenderInGCFUrlList, KEY_ALL_ACCESS);
+ EXPECT_TRUE(opt_for_gcf.Valid());
+ RegKey opt_for_host(config_key.Handle(), kRenderInHostUrlList,
+ KEY_ALL_ACCESS);
+ EXPECT_TRUE(opt_for_host.Valid());
+ if (!config_key.Valid() || !opt_for_gcf.Valid() || !opt_for_host.Valid())
+ return;
+
+ const wchar_t kTestFilter[] = L"*.testing.chromium.org";
+ const wchar_t kTestUrl[] = L"www.testing.chromium.org";
+
+ // Save the current state of the registry.
+ DWORD saved_default_renderer = 0;
+ config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer);
+
+ // Make sure the host is the default renderer.
+ config_key.WriteValue(kEnableGCFRendererByDefault, static_cast<DWORD>(0));
+ EXPECT_FALSE(IsGcfDefaultRenderer());
+
+ opt_for_gcf.DeleteValue(kTestFilter); // Just in case this exists
+ EXPECT_FALSE(IsOptInUrl(kTestUrl));
+ opt_for_gcf.WriteValue(kTestFilter, L"");
+ EXPECT_TRUE(IsOptInUrl(kTestUrl));
+
+ // Now set GCF as the default renderer.
+ config_key.WriteValue(kEnableGCFRendererByDefault, static_cast<DWORD>(1));
+ EXPECT_TRUE(IsGcfDefaultRenderer());
+
+ opt_for_host.DeleteValue(kTestFilter); // Just in case this exists
+ EXPECT_TRUE(IsOptInUrl(kTestUrl));
+ opt_for_host.WriteValue(kTestFilter, L"");
+ EXPECT_FALSE(IsOptInUrl(kTestUrl));
+
+ // Cleanup.
+ opt_for_gcf.DeleteValue(kTestFilter);
+ opt_for_host.DeleteValue(kTestFilter);
+ config_key.WriteValue(kEnableGCFRendererByDefault, saved_default_renderer);
}
+
diff --git a/chrome_frame/urlmon_url_request.cc b/chrome_frame/urlmon_url_request.cc
index 26713a8..ea064e3 100644
--- a/chrome_frame/urlmon_url_request.cc
+++ b/chrome_frame/urlmon_url_request.cc
@@ -560,7 +560,12 @@ STDMETHODIMP UrlmonUrlRequest::BeginningTransaction(const wchar_t* url,
}
// In the rare case if "User-Agent" string is already in |current_headers|.
- new_headers += AppendCFUserAgentString(current_headers, NULL);
+ if (IsGcfDefaultRenderer()) {
+ new_headers += ReplaceOrAddUserAgent(current_headers,
+ http_utils::GetChromeUserAgent());
+ } else {
+ new_headers += AppendCFUserAgentString(current_headers, NULL);
+ }
if (!new_headers.empty()) {
*additional_headers = reinterpret_cast<wchar_t*>(
diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc
index 33d004f..c2c2d48 100644
--- a/chrome_frame/utils.cc
+++ b/chrome_frame/utils.cc
@@ -21,6 +21,7 @@
#include "base/string_util.h"
#include "base/thread_local.h"
#include "base/utf_string_conversions.h"
+#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/url_constants.h"
#include "chrome/installer/util/chrome_frame_distribution.h"
#include "chrome_frame/extra_system_apis.h"
@@ -45,13 +46,14 @@ const char kGCFProtocol[] = "gcf";
const wchar_t kChromeProtocolPrefix[] = L"gcf:";
const wchar_t kChromeMimeType[] = L"application/chromepage";
const wchar_t kPatchProtocols[] = L"PatchProtocols";
+const wchar_t kChromeFrameConfigKey[] = L"Software\\Google\\ChromeFrame";
+const wchar_t kRenderInGCFUrlList[] = L"RenderInGcfUrls";
+const wchar_t kRenderInHostUrlList[] = L"RenderInHostUrls";
+const wchar_t kEnableGCFRendererByDefault[] = L"IsDefaultRenderer";
+const wchar_t kIexploreProfileName[] = L"iexplore";
+const wchar_t kRundllProfileName[] = L"rundll32";
-static const wchar_t kChromeFrameConfigKey[] =
- L"Software\\Google\\ChromeFrame";
-static const wchar_t kRenderInGCFUrlList[] = L"RenderInGcfUrls";
-static const wchar_t kRenderInHostUrlList[] = L"RenderInHostUrls";
static const wchar_t kAllowUnsafeURLs[] = L"AllowUnsafeURLs";
-static const wchar_t kEnableGCFRendererByDefault[] = L"IsDefaultRenderer";
static const wchar_t kEnableBuggyBhoIntercept[] = L"EnableBuggyBhoIntercept";
static const wchar_t kChromeFrameNPAPIKey[] =
@@ -539,23 +541,6 @@ bool GetModuleVersion(HMODULE module, uint32* high, uint32* low) {
return ok;
}
-bool ParseVersion(const std::wstring& version, uint32* high, uint32* low) {
- DCHECK(high);
- if (!isdigit(version[0]))
- return false;
-
- *high = _wtoi(version.c_str());
- if (low) {
- *low = 0;
- size_t i = version.find(L'.');
- if (i != std::wstring::npos) {
- *low = _wtoi(version.c_str() + i + 1);
- }
- }
-
- return true;
-}
-
HMODULE GetModuleFromAddress(void* address) {
MEMORY_BASIC_INFORMATION info = {0};
::VirtualQuery(address, &info, sizeof(info));
@@ -697,6 +682,18 @@ bool DeleteConfigValue(const wchar_t* value_name) {
return false;
}
+bool IsGcfDefaultRenderer() {
+ // TODO(tommi): Implement caching for this config value as it gets
+ // checked frequently.
+ DWORD is_default = 0; // NOLINT
+ RegKey config_key;
+ if (config_key.Open(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_READ)) {
+ config_key.ReadValueDW(kEnableGCFRendererByDefault, &is_default);
+ }
+
+ return is_default != 0;
+}
+
bool IsOptInUrl(const wchar_t* url) {
// TODO(tommi): Unit test.
RegKey config_key;
@@ -1392,3 +1389,4 @@ bool CanNavigate(const GURL& url, IInternetSecurityManager* security_manager,
return true;
}
+
diff --git a/chrome_frame/utils.h b/chrome_frame/utils.h
index 56d2460..2c8c700 100644
--- a/chrome_frame/utils.h
+++ b/chrome_frame/utils.h
@@ -33,6 +33,12 @@ extern const wchar_t kAllowUnsafeURLs[];
extern const wchar_t kEnableBuggyBhoIntercept[];
extern const wchar_t kChromeMimeType[];
extern const wchar_t kChromeFrameAttachTabPattern[];
+extern const wchar_t kChromeFrameConfigKey[];
+extern const wchar_t kRenderInGCFUrlList[];
+extern const wchar_t kRenderInHostUrlList[];
+extern const wchar_t kEnableGCFRendererByDefault[];
+extern const wchar_t kIexploreProfileName[];
+extern const wchar_t kRundllProfileName[];
typedef enum ProtocolPatchMethod {
PATCH_METHOD_IBROWSER = 0,
@@ -109,11 +115,11 @@ void DisplayVersionMismatchWarning(HWND parent,
// This class provides a base implementation for ATL modules which want to
// perform all their registration under HKCU. This class overrides the
// RegisterServer and UnregisterServer methods and registers the type libraries
-// under HKCU (the rest of the registation is made under HKCU by changing the
+// under HKCU (the rest of the registration is made under HKCU by changing the
// appropriate .RGS files)
template < class BaseAtlModule >
class AtlPerUserModule : public BaseAtlModule {
- public:
+ public:
HRESULT RegisterServer(BOOL reg_typelib = FALSE,
const CLSID* clsid = NULL) throw() {
HRESULT hr = BaseAtlModule::RegisterServer(FALSE, clsid);
@@ -193,10 +199,6 @@ FilePath GetIETemporaryFilesFolder();
// @returns true if the version info was successfully retrieved.
bool GetModuleVersion(HMODULE module, uint32* high, uint32* low);
-// Parses a version string and returns the major, minor versions or 0 if not
-// present in the string. The rest of the version string is ignored.
-bool ParseVersion(const std::wstring& version, uint32* high, uint32* low);
-
// @returns the module handle to which an address belongs.
HMODULE GetModuleFromAddress(void* address);
@@ -241,6 +243,9 @@ bool IsHeadlessMode();
// eviction should be possible.
bool IsUnpinnedMode();
+// Returns true if all HTML pages should be rendered in GCF by default.
+bool IsGcfDefaultRenderer();
+
// Check if this url is opting into Chrome Frame based on static settings.
bool IsOptInUrl(const wchar_t* url);
@@ -475,7 +480,7 @@ std::string Bscf2Str(DWORD flags);
// Reads data from a stream into a string.
HRESULT ReadStream(IStream* stream, size_t size, std::string* data);
-// Parses urls targetted at ChromeFrame. This class maintains state like
+// Parses urls targeted at ChromeFrame. This class maintains state like
// whether a url is prefixed with the gcf: prefix, whether it is being
// attached to an existing external tab, etc.
class ChromeFrameUrl {