Chromium Code Reviews| Index: chrome_frame/html_utils.cc |
| diff --git a/chrome_frame/html_utils.cc b/chrome_frame/html_utils.cc |
| index 3121a756fa786fa0556201e1625e6171e5bde094..e0c645ed48421f8dc18dc81f90b55d9af6a84b4d 100644 |
| --- a/chrome_frame/html_utils.cc |
| +++ b/chrome_frame/html_utils.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2012 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. |
| // |
| @@ -369,6 +369,40 @@ std::string AddChromeFrameToUserAgentValue(const std::string& value) { |
| return ret; |
| } |
| + |
| +std::string RemoveChromeFrameFromUserAgentValue(const std::string& value) { |
| + if (value.empty()) { |
| + DLOG(WARNING) << "empty user agent value"; |
| + return ""; |
| + } |
| + |
| + 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
|
| + |
| + 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.
|
| + if (cf_start == std::string::npos) { |
| + // The user agent is not present. |
| + return value; |
| + } |
| + |
| + int offset = 0; |
| + // If we prepended a '; ' or a ' ' then remove that in the output. |
| + 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.
|
| + if (cf_start > 2 && value[cf_start - 2] == ';') ++offset; |
| + |
| + 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
|
| + cf_start += strlen(kChromeFrameUserAgent); |
| + while (cf_start < value.length() && |
| + (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!
|
| + value[cf_start] == '.' || |
| + (value[cf_start] >= '0' && value[cf_start] <= '9'))) { |
| + ++cf_start; |
| + } |
| + if (cf_start < value.length()) |
| + ret += value.substr(cf_start); |
| + |
| + return ret; |
| +} |
| + |
| std::string GetDefaultUserAgentHeaderWithCFTag() { |
| std::string ua(GetDefaultUserAgent()); |
| return "User-Agent: " + AddChromeFrameToUserAgentValue(ua); |