summaryrefslogtreecommitdiffstats
path: root/chrome_frame/html_utils.cc
diff options
context:
space:
mode:
authortommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-17 04:48:37 +0000
committertommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-17 04:48:37 +0000
commit3f55e8712f88d8477d9e58f68958e83c92664389 (patch)
tree21f9eeeda041fd570c31d8b0f266f780b767418f /chrome_frame/html_utils.cc
parentcd1c89e833b7e67b7a7ca8799122e07b65999771 (diff)
downloadchromium_src-3f55e8712f88d8477d9e58f68958e83c92664389.zip
chromium_src-3f55e8712f88d8477d9e58f68958e83c92664389.tar.gz
chromium_src-3f55e8712f88d8477d9e58f68958e83c92664389.tar.bz2
Add the chromeframe tag to the user agent header at runtime instead of statically in the registry.TEST=Try disabling GCF and see if the chromeframe tag in the user agent is still set. It should not be. Also make sure you don't have an older version installed... the chromeframe tag should not be in the registry - if it is, you've got an older version still registered. This should fix the issue with going to wave.google.com after disabling chrome frame and seeing the white page of death.R=amitBUG=22760
Review URL: http://codereview.chromium.org/259025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29370 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/html_utils.cc')
-rw-r--r--chrome_frame/html_utils.cc76
1 files changed, 75 insertions, 1 deletions
diff --git a/chrome_frame/html_utils.cc b/chrome_frame/html_utils.cc
index 944ea11..7ab1fd1 100644
--- a/chrome_frame/html_utils.cc
+++ b/chrome_frame/html_utils.cc
@@ -4,10 +4,14 @@
//
#include "chrome_frame/html_utils.h"
+#include <atlbase.h>
+#include <urlmon.h>
+
#include "base/string_util.h"
#include "base/string_tokenizer.h"
+#include "chrome_frame/utils.h"
-const wchar_t* kQuotes = L"\"'";
+const wchar_t kQuotes[] = L"\"'";
HTMLScanner::StringRange::StringRange() {
}
@@ -279,3 +283,73 @@ bool HTMLScanner::NextTag(StringRange* html_string, StringRange* tag) {
return true;
}
+namespace http_utils {
+
+const char kChromeFrameUserAgent[] = "chromeframe";
+
+const char* GetChromeFrameUserAgent() {
+ static char cf_user_agent[100] = {0};
+ if (!cf_user_agent[0]) {
+ _pAtlModule->m_csStaticDataInitAndTypeInfo.Lock();
+ if (!cf_user_agent[0]) {
+ uint32 version = 0;
+ GetModuleVersion(reinterpret_cast<HMODULE>(&__ImageBase), &version, NULL);
+ wsprintfA(cf_user_agent, "%s/%i.%i", kChromeFrameUserAgent,
+ HIWORD(version), LOWORD(version));
+ }
+ _pAtlModule->m_csStaticDataInitAndTypeInfo.Unlock();
+ }
+ return cf_user_agent;
+}
+
+std::string AddChromeFrameToUserAgentValue(const std::string& value) {
+ if (value.empty()) {
+ DLOG(WARNING) << "empty user agent value";
+ return "";
+ }
+
+ DCHECK_EQ(false, StartsWithASCII(value, "User-Agent:", true));
+
+ if (value.find(kChromeFrameUserAgent) != std::string::npos) {
+ // Our user agent has already been added.
+ return value;
+ }
+
+ std::string ret(value);
+ ret += " ";
+ ret += GetChromeFrameUserAgent();
+
+ return ret;
+}
+
+std::string GetDefaultUserAgentHeaderWithCFTag() {
+ std::string ua(GetDefaultUserAgent());
+ return "User-Agent: " + AddChromeFrameToUserAgentValue(ua);
+}
+
+std::string GetDefaultUserAgent() {
+ std::string ret;
+ DWORD size = MAX_PATH; // NOLINT
+ HRESULT hr = E_OUTOFMEMORY;
+ for (int retries = 1; hr == E_OUTOFMEMORY && retries <= 10; ++retries) {
+ hr = ::ObtainUserAgentString(0, WriteInto(&ret, size + 1), &size);
+ if (hr == E_OUTOFMEMORY) {
+ size = MAX_PATH * retries;
+ } else if (SUCCEEDED(hr)) {
+ // Truncate the extra allocation.
+ DCHECK(size > 0); // NOLINT
+ ret.resize(size - sizeof(char)); // NOLINT
+ }
+ }
+
+ if (FAILED(hr)) {
+ NOTREACHED() << StringPrintf("ObtainUserAgentString==0x%08X", hr);
+ return "";
+ } else {
+ DCHECK(ret.length() == lstrlenA(ret.c_str()));
+ }
+
+ return ret;
+}
+
+} // namespace http_utils