summaryrefslogtreecommitdiffstats
path: root/chrome_frame
diff options
context:
space:
mode:
authorerikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 20:29:12 +0000
committererikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 20:29:12 +0000
commit8e698b6c58faf3a267ebc7512e530dc4323a010b (patch)
treea9e1d055c274fb2f6fdda77d5a5cfe3d7f2a3b15 /chrome_frame
parenteba0116741b4849809fc57d97cdf527a1b5da507 (diff)
downloadchromium_src-8e698b6c58faf3a267ebc7512e530dc4323a010b.zip
chromium_src-8e698b6c58faf3a267ebc7512e530dc4323a010b.tar.gz
chromium_src-8e698b6c58faf3a267ebc7512e530dc4323a010b.tar.bz2
Modify the parsing of X-UA-COMPATIBLE header (and meta tag) to allow comma or semi-colon as delimiter for backwards compatibility.
BUG=52601 TEST=chrome_frame_unittests / UtilTests.XUaCompatibleDirectiveTest Review URL: http://codereview.chromium.org/4103004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63937 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r--chrome_frame/test/util_unittests.cc8
-rw-r--r--chrome_frame/utils.cc23
-rw-r--r--chrome_frame/utils.h11
3 files changed, 31 insertions, 11 deletions
diff --git a/chrome_frame/test/util_unittests.cc b/chrome_frame/test/util_unittests.cc
index 6f6be52..6581184 100644
--- a/chrome_frame/test/util_unittests.cc
+++ b/chrome_frame/test/util_unittests.cc
@@ -394,7 +394,13 @@ TEST(UtilTests, XUaCompatibleDirectiveTest) {
// Ignore unrecognized values
{ " IE=8 ; chrome = IE7.1; chrome = IE6;", 6 },
// First valid wins
- { " IE=8 ; chrome = IE6; chrome = IE8;", 6 }
+ { " IE=8 ; chrome = IE6; chrome = IE8;", 6 },
+ // Comma delimiter
+ { " IE=8,chrome=IE6;", -1 },
+ { " IE=8,chrome=IE6", 6 },
+ { " IE=8,chrome=IE6, Something=Else;Why;Not", 6 },
+ { " IE=8,chrome=1,Something=Else", INT_MAX },
+ { " IE=8(a;b;c),chrome=IE7,Something=Else", 7 }
};
for (int case_index = 0; case_index < arraysize(test_cases); ++case_index) {
diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc
index 2e5f13e..eff1331 100644
--- a/chrome_frame/utils.cc
+++ b/chrome_frame/utils.cc
@@ -1533,11 +1533,13 @@ void WaitWithMessageLoop(HANDLE* handles, int count, DWORD timeout) {
}
}
-bool CheckXUaCompatibleDirective(const std::string& directive,
- int ie_major_version) {
+// Returns -1 if no directive is found, std::numeric_limits<int>::max() if the
+// directive matches all IE versions ('Chrome=1') or the maximum IE version
+// matched ('Chrome=IE7' => 7)
+int GetXUaCompatibleDirective(const std::string& directive, char delimiter) {
net::HttpUtil::NameValuePairsIterator name_value_pairs(directive.begin(),
directive.end(),
- ';');
+ delimiter);
// Loop through the values until a valid 'Chrome=<FILTER>' entry is found
while (name_value_pairs.GetNext()) {
@@ -1552,7 +1554,7 @@ bool CheckXUaCompatibleDirective(const std::string& directive,
size_t filter_length = filter_end - filter_begin;
if (filter_length == 1 && *filter_begin == '1') {
- return true;
+ return std::numeric_limits<int>::max();
}
if (filter_length < 3 ||
@@ -1568,9 +1570,18 @@ bool CheckXUaCompatibleDirective(const std::string& directive,
}
// The first valid directive we find wins, whether it matches or not
- return ie_major_version <= header_ie_version;
+ return header_ie_version;
}
- return false;
+ return -1;
+}
+
+bool CheckXUaCompatibleDirective(const std::string& directive,
+ int ie_major_version) {
+ int header_ie_version = GetXUaCompatibleDirective(directive, ';');
+ if (header_ie_version == -1) {
+ header_ie_version = GetXUaCompatibleDirective(directive, ',');
+ }
+ return header_ie_version >= ie_major_version;
}
void EnumerateKeyValues(HKEY parent_key, const wchar_t* sub_key_name,
diff --git a/chrome_frame/utils.h b/chrome_frame/utils.h
index 678b86c..7cafc26 100644
--- a/chrome_frame/utils.h
+++ b/chrome_frame/utils.h
@@ -610,10 +610,10 @@ void EnumerateKeyValues(HKEY parent_key, const wchar_t* sub_key_name,
//
// The header is a series of name-value pairs, with the names being HTTP tokens
// and the values being either tokens or quoted-strings. Names and values are
-// joined by '=' and pairs are delimited by ';'. LWS may be used liberally
-// before and between names, values, '=', and ';'. See RFC 2616 for definitions
-// of token, quoted-string, and LWS. See Microsoft's documentation of the
-// X-UA-COMPATIBLE header here:
+// joined by '=' and pairs are delimited by either ';' or ','. LWS may be used
+// liberally before and between names, values, '=', and ';' or ','. See RFC 2616
+// for definitions of token, quoted-string, and LWS. See Microsoft's
+// documentation of the X-UA-COMPATIBLE header here:
// http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx
//
// At most one 'Chrome=<FILTER>' entry is expected in the header value. The
@@ -625,6 +625,9 @@ void EnumerateKeyValues(HKEY parent_key, const wchar_t* sub_key_name,
//
// For example:
// X-UA-Compatible: IE=8; Chrome=IE6
+//
+// The string is first interpreted using ';' as a delimiter. It is reevaluated
+// using ',' iff no valid 'chrome=' value is found.
bool CheckXUaCompatibleDirective(const std::string& directive,
int ie_major_version);