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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/html_utils.h ('k') | chrome_frame/http_negotiate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 #include "chrome_frame/html_utils.h" 5 #include "chrome_frame/html_utils.h"
6 6
7 #include <atlbase.h>
8 #include <urlmon.h>
9
7 #include "base/string_util.h" 10 #include "base/string_util.h"
8 #include "base/string_tokenizer.h" 11 #include "base/string_tokenizer.h"
12 #include "chrome_frame/utils.h"
9 13
10 const wchar_t* kQuotes = L"\"'"; 14 const wchar_t kQuotes[] = L"\"'";
11 15
12 HTMLScanner::StringRange::StringRange() { 16 HTMLScanner::StringRange::StringRange() {
13 } 17 }
14 18
15 HTMLScanner::StringRange::StringRange(StrPos start, StrPos end) 19 HTMLScanner::StringRange::StringRange(StrPos start, StrPos end)
16 : start_(start), end_(end) { 20 : start_(start), end_(end) {
17 } 21 }
18 22
19 bool HTMLScanner::StringRange::LowerCaseEqualsASCII(const char* other) const { 23 bool HTMLScanner::StringRange::LowerCaseEqualsASCII(const char* other) const {
20 return ::LowerCaseEqualsASCII(start_, end_, other); 24 return ::LowerCaseEqualsASCII(start_, end_, other);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // incomplete tag and do not report it. 276 // incomplete tag and do not report it.
273 if (tag->end_ >= html_string->end_) 277 if (tag->end_ >= html_string->end_)
274 return false; 278 return false;
275 279
276 // Modify html_string to point to just beyond the end_ of the current tag. 280 // Modify html_string to point to just beyond the end_ of the current tag.
277 html_string->start_ = tag->end_ + 1; 281 html_string->start_ = tag->end_ + 1;
278 282
279 return true; 283 return true;
280 } 284 }
281 285
286 namespace http_utils {
287
288 const char kChromeFrameUserAgent[] = "chromeframe";
289
290 const char* GetChromeFrameUserAgent() {
291 static char cf_user_agent[100] = {0};
292 if (!cf_user_agent[0]) {
293 _pAtlModule->m_csStaticDataInitAndTypeInfo.Lock();
294 if (!cf_user_agent[0]) {
295 uint32 version = 0;
296 GetModuleVersion(reinterpret_cast<HMODULE>(&__ImageBase), &version, NULL);
297 wsprintfA(cf_user_agent, "%s/%i.%i", kChromeFrameUserAgent,
298 HIWORD(version), LOWORD(version));
299 }
300 _pAtlModule->m_csStaticDataInitAndTypeInfo.Unlock();
301 }
302 return cf_user_agent;
303 }
304
305 std::string AddChromeFrameToUserAgentValue(const std::string& value) {
306 if (value.empty()) {
307 DLOG(WARNING) << "empty user agent value";
308 return "";
309 }
310
311 DCHECK_EQ(false, StartsWithASCII(value, "User-Agent:", true));
312
313 if (value.find(kChromeFrameUserAgent) != std::string::npos) {
314 // Our user agent has already been added.
315 return value;
316 }
317
318 std::string ret(value);
319 ret += " ";
320 ret += GetChromeFrameUserAgent();
321
322 return ret;
323 }
324
325 std::string GetDefaultUserAgentHeaderWithCFTag() {
326 std::string ua(GetDefaultUserAgent());
327 return "User-Agent: " + AddChromeFrameToUserAgentValue(ua);
328 }
329
330 std::string GetDefaultUserAgent() {
331 std::string ret;
332 DWORD size = MAX_PATH; // NOLINT
333 HRESULT hr = E_OUTOFMEMORY;
334 for (int retries = 1; hr == E_OUTOFMEMORY && retries <= 10; ++retries) {
335 hr = ::ObtainUserAgentString(0, WriteInto(&ret, size + 1), &size);
336 if (hr == E_OUTOFMEMORY) {
337 size = MAX_PATH * retries;
338 } else if (SUCCEEDED(hr)) {
339 // Truncate the extra allocation.
340 DCHECK(size > 0); // NOLINT
341 ret.resize(size - sizeof(char)); // NOLINT
342 }
343 }
344
345 if (FAILED(hr)) {
346 NOTREACHED() << StringPrintf("ObtainUserAgentString==0x%08X", hr);
347 return "";
348 } else {
349 DCHECK(ret.length() == lstrlenA(ret.c_str()));
350 }
351
352 return ret;
353 }
354
355 } // namespace http_utils
OLDNEW
« 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