Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8361)

Unified Diff: chrome_frame/html_utils.cc

Issue 259025: Add the chromeframe tag to the user agent header at runtime instead of static... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome_frame/html_utils.h ('k') | chrome_frame/http_negotiate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome_frame/html_utils.cc
===================================================================
--- chrome_frame/html_utils.cc (revision 29337)
+++ chrome_frame/html_utils.cc (working copy)
@@ -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 @@
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
« no previous file with comments | « chrome_frame/html_utils.h ('k') | chrome_frame/http_negotiate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698