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

Unified Diff: chrome_frame/html_utils.cc

Issue 9720001: Add a setting to CF to remove 'chromeframe' from the UserAgent on a per-pattern basis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: In the end. Created 8 years, 9 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.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « chrome_frame/html_utils.h ('k') | chrome_frame/http_negotiate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698