OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> | 7 #include <atlbase.h> |
8 #include <urlmon.h> | 8 #include <urlmon.h> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/string_tokenizer.h" | 11 #include "base/string_tokenizer.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 ret.insert(insert_position++, " "); | 362 ret.insert(insert_position++, " "); |
363 ret.insert(insert_position, GetChromeFrameUserAgent()); | 363 ret.insert(insert_position, GetChromeFrameUserAgent()); |
364 } else { | 364 } else { |
365 ret += " "; | 365 ret += " "; |
366 ret += GetChromeFrameUserAgent(); | 366 ret += GetChromeFrameUserAgent(); |
367 } | 367 } |
368 | 368 |
369 return ret; | 369 return ret; |
370 } | 370 } |
371 | 371 |
372 | |
373 std::string RemoveChromeFrameFromUserAgentValue(const std::string& value) { | |
374 if (value.empty()) { | |
375 DLOG(WARNING) << "empty user agent value"; | |
376 return ""; | |
377 } | |
378 | |
379 DCHECK_EQ(false, StartsWithASCII(value, "User-Agent:", true)); | |
slightlyoff1
2012/03/20 15:31:56
What's the rationale for this check? Is it that we
robertshield
2012/03/26 02:43:33
I was following the tradition established in AddCh
| |
380 | |
381 std::string::size_type cf_start = value.find(kChromeFrameUserAgent); | |
grt (UTC plus 2)
2012/03/20 17:27:45
Chromium style says to use size_t instead of size_
robertshield
2012/03/26 02:43:33
Fixed here and above.
| |
382 if (cf_start == std::string::npos) { | |
383 // The user agent is not present. | |
384 return value; | |
385 } | |
386 | |
387 int offset = 0; | |
388 // If we prepended a '; ' or a ' ' then remove that in the output. | |
389 if (cf_start > 1 && value[cf_start - 1] == ' ') ++offset; | |
grt (UTC plus 2)
2012/03/20 17:27:45
nit: i find this single-line stuff foreign enough
robertshield
2012/03/26 02:43:33
Done.
| |
390 if (cf_start > 2 && value[cf_start - 2] == ';') ++offset; | |
391 | |
392 std::string ret(value, 0, cf_start - offset); | |
slightlyoff1
2012/03/20 15:31:56
can we get a check to make sure that cf_start - of
robertshield
2012/03/26 02:43:33
Sure, added. Note that since cf_start is a positiv
| |
393 cf_start += strlen(kChromeFrameUserAgent); | |
394 while (cf_start < value.length() && | |
395 (value[cf_start] == '/' || | |
grt (UTC plus 2)
2012/03/20 17:27:45
nit: order these clauses from most-likely-to-match
robertshield
2012/03/26 02:43:33
Indeed!
| |
396 value[cf_start] == '.' || | |
397 (value[cf_start] >= '0' && value[cf_start] <= '9'))) { | |
398 ++cf_start; | |
399 } | |
400 if (cf_start < value.length()) | |
401 ret += value.substr(cf_start); | |
402 | |
403 return ret; | |
404 } | |
405 | |
372 std::string GetDefaultUserAgentHeaderWithCFTag() { | 406 std::string GetDefaultUserAgentHeaderWithCFTag() { |
373 std::string ua(GetDefaultUserAgent()); | 407 std::string ua(GetDefaultUserAgent()); |
374 return "User-Agent: " + AddChromeFrameToUserAgentValue(ua); | 408 return "User-Agent: " + AddChromeFrameToUserAgentValue(ua); |
375 } | 409 } |
376 | 410 |
377 const char* GetChromeUserAgent() { | 411 const char* GetChromeUserAgent() { |
378 if (!g_chrome_user_agent[0]) { | 412 if (!g_chrome_user_agent[0]) { |
379 _pAtlModule->m_csStaticDataInitAndTypeInfo.Lock(); | 413 _pAtlModule->m_csStaticDataInitAndTypeInfo.Lock(); |
380 if (!g_chrome_user_agent[0]) { | 414 if (!g_chrome_user_agent[0]) { |
381 std::string ua; | 415 std::string ua; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 const std::string& headers) { | 471 const std::string& headers) { |
438 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); | 472 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
439 while (it.GetNext()) { | 473 while (it.GetNext()) { |
440 if (!lstrcmpiA(it.name().c_str(), header.c_str())) | 474 if (!lstrcmpiA(it.name().c_str(), header.c_str())) |
441 return std::string(it.values_begin(), it.values_end()); | 475 return std::string(it.values_begin(), it.values_end()); |
442 } | 476 } |
443 return std::string(); | 477 return std::string(); |
444 } | 478 } |
445 | 479 |
446 } // namespace http_utils | 480 } // namespace http_utils |
OLD | NEW |