Index: chrome_frame/html_utils.cc |
diff --git a/chrome_frame/html_utils.cc b/chrome_frame/html_utils.cc |
index 3121a756fa786fa0556201e1625e6171e5bde094..6892ede6c943435d831bf4f3b09cd63f3b41bcb6 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. |
// |
@@ -343,19 +343,16 @@ const char* GetChromeFrameUserAgent() { |
std::string AddChromeFrameToUserAgentValue(const std::string& value) { |
if (value.empty()) { |
- DLOG(WARNING) << "empty user agent value"; |
- return ""; |
+ return value; |
} |
- 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); |
- std::string::size_type insert_position = ret.find(')'); |
+ size_t insert_position = ret.find(')'); |
if (insert_position != std::string::npos) { |
if (insert_position > 1 && isalnum(ret[insert_position - 1])) |
ret.insert(insert_position++, ";"); |
@@ -369,6 +366,38 @@ std::string AddChromeFrameToUserAgentValue(const std::string& value) { |
return ret; |
} |
+std::string RemoveChromeFrameFromUserAgentValue(const std::string& value) { |
+ size_t cf_start = value.find(kChromeFrameUserAgent); |
+ if (cf_start == std::string::npos) { |
+ // The user agent is not present. |
+ return value; |
+ } |
+ |
+ size_t offset = 0; |
+ // If we prepended a '; ' or a ' ' then remove that in the output. |
+ if (cf_start > 1 && value[cf_start - 1] == ' ') |
+ ++offset; |
+ if (cf_start > 3 && |
+ value[cf_start - 2] == ';' && |
+ isalnum(value[cf_start - 3])) { |
+ ++offset; |
+ } |
+ |
+ std::string ret(value, 0, std::max(cf_start - offset, 0U)); |
+ cf_start += strlen(kChromeFrameUserAgent); |
+ while (cf_start < value.length() && |
+ ((value[cf_start] >= '0' && value[cf_start] <= '9') || |
+ value[cf_start] == '.' || |
+ value[cf_start] == '/')) { |
+ ++cf_start; |
+ } |
+ |
+ if (cf_start < value.length()) |
+ ret.append(value, cf_start, std::string::npos); |
+ |
+ return ret; |
+} |
+ |
std::string GetDefaultUserAgentHeaderWithCFTag() { |
std::string ua(GetDefaultUserAgent()); |
return "User-Agent: " + AddChromeFrameToUserAgentValue(ua); |