WebKit Doesn't Recognize Content-Language HTTP Header
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Oct 2012 19:53:58 +0000 (19:53 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Oct 2012 19:53:58 +0000 (19:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=97929

Patch by Brian White <bcwhite@chromium.org> on 2012-10-18
Reviewed by Alexey Proskuryakov.

The HTTP "Content-Language" header may be present and include the
language of the page contents (as opposed to an embedded meta tag).

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::didBeginDocument):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@131794 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/http/tests/misc/extract-http-content-language-against-equiv-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/extract-http-content-language-against-equiv.php [new file with mode: 0644]
LayoutTests/http/tests/misc/extract-http-content-language-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/extract-http-content-language-malformed-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/extract-http-content-language-malformed.php [new file with mode: 0644]
LayoutTests/http/tests/misc/extract-http-content-language-multiple-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/extract-http-content-language-multiple.php [new file with mode: 0644]
LayoutTests/http/tests/misc/extract-http-content-language.php [new file with mode: 0644]
Source/WebCore/ChangeLog [changed mode: 0644->0755]
Source/WebCore/html/parser/HTMLParserIdioms.h [changed mode: 0644->0755]
Source/WebCore/loader/FrameLoader.cpp [changed mode: 0644->0755]

diff --git a/LayoutTests/http/tests/misc/extract-http-content-language-against-equiv-expected.txt b/LayoutTests/http/tests/misc/extract-http-content-language-against-equiv-expected.txt
new file mode 100644 (file)
index 0000000..0a5915d
--- /dev/null
@@ -0,0 +1,11 @@
+Test for bug 97929: Extract HTTP Content-Language header.
+
+==> Value extracted from meta "http-equiv" and overriding HTTP "Content-Language"...
+PASS window.getComputedStyle(document.getElementById("x")).webkitLocale is "en-GB"
+==> Value set by div "lang" tag...
+PASS window.getComputedStyle(document.getElementById("y")).webkitLocale is "ar"
+==> All done...
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/misc/extract-http-content-language-against-equiv.php b/LayoutTests/http/tests/misc/extract-http-content-language-against-equiv.php
new file mode 100644 (file)
index 0000000..9ee0566
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+  header("Content-Language: zh-CN");
+?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="content-language" content="en-GB">
+<script src="../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=97929">bug 97929</a>:
+Extract HTTP Content-Language header.</p>
+<div id="console"></div>
+<div id="x"></div>
+<div id="y" lang="ar"></div>
+<script>
+  debug('==> Value extracted from meta "http-equiv" and overriding HTTP "Content-Language"...');
+  shouldBe('window.getComputedStyle(document.getElementById("x")).webkitLocale', '"en-GB"')
+  debug('==> Value set by div "lang" tag...');
+  shouldBe('window.getComputedStyle(document.getElementById("y")).webkitLocale', '"ar"')
+  debug('==> All done...');
+</script>
+<script src="../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/misc/extract-http-content-language-expected.txt b/LayoutTests/http/tests/misc/extract-http-content-language-expected.txt
new file mode 100644 (file)
index 0000000..1f1678e
--- /dev/null
@@ -0,0 +1,11 @@
+Test for bug 97929: Extract HTTP Content-Language header.
+
+==> Value extracted from HTTP "Content-Language" header...
+PASS window.getComputedStyle(document.getElementById("x")).webkitLocale is "zh-CN"
+==> Value set by div "lang" tag...
+PASS window.getComputedStyle(document.getElementById("y")).webkitLocale is "ar"
+==> All done...
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/misc/extract-http-content-language-malformed-expected.txt b/LayoutTests/http/tests/misc/extract-http-content-language-malformed-expected.txt
new file mode 100644 (file)
index 0000000..fec308b
--- /dev/null
@@ -0,0 +1,11 @@
+Test for bug 97929: Extract HTTP Content-Language header.
+
+==> Value extracted from malformed HTTP "Content-Language" header...
+PASS window.getComputedStyle(document.getElementById("x")).webkitLocale == "es" || window.getComputedStyle(document.getElementById("x")).webkitLocale == "auto" is true
+==> Value set by div "lang" tag...
+PASS window.getComputedStyle(document.getElementById("y")).webkitLocale is "ar"
+==> All done...
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/misc/extract-http-content-language-malformed.php b/LayoutTests/http/tests/misc/extract-http-content-language-malformed.php
new file mode 100644 (file)
index 0000000..ae57054
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+  header("Content-Language: ,es");
+?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<script src="../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=97929">bug 97929</a>:
+Extract HTTP Content-Language header.</p>
+<div id="console"></div>
+<div id="x"></div>
+<div id="y" lang="ar"></div>
+<script>
+  debug('==> Value extracted from malformed HTTP "Content-Language" header...');
+  // A malformed header may be fixed by the browser ("es") or left bad and so remain unset ("auto").
+  // Chrome does the former; Safari does the latter.
+  shouldBeTrue('window.getComputedStyle(document.getElementById("x")).webkitLocale == "es" || window.getComputedStyle(document.getElementById("x")).webkitLocale == "auto"')
+  debug('==> Value set by div "lang" tag...');
+  shouldBe('window.getComputedStyle(document.getElementById("y")).webkitLocale', '"ar"')
+  debug('==> All done...');
+</script>
+<script src="../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/misc/extract-http-content-language-multiple-expected.txt b/LayoutTests/http/tests/misc/extract-http-content-language-multiple-expected.txt
new file mode 100644 (file)
index 0000000..dcdbeed
--- /dev/null
@@ -0,0 +1,11 @@
+Test for bug 97929: Extract HTTP Content-Language header.
+
+==> Value extracted singly from HTTP "Content-Language" header...
+PASS window.getComputedStyle(document.getElementById("x")).webkitLocale is "fr"
+==> Value set by div "lang" tag...
+PASS window.getComputedStyle(document.getElementById("y")).webkitLocale is "ar"
+==> All done...
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/misc/extract-http-content-language-multiple.php b/LayoutTests/http/tests/misc/extract-http-content-language-multiple.php
new file mode 100644 (file)
index 0000000..3605c3a
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+  header("Content-Language:  fr \t , fi ");
+?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<script src="../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=97929">bug 97929</a>:
+Extract HTTP Content-Language header.</p>
+<div id="console"></div>
+<div id="x"></div>
+<div id="y" lang="ar"></div>
+<script>
+  debug('==> Value extracted singly from HTTP "Content-Language" header...');
+  shouldBe('window.getComputedStyle(document.getElementById("x")).webkitLocale', '"fr"')
+  debug('==> Value set by div "lang" tag...');
+  shouldBe('window.getComputedStyle(document.getElementById("y")).webkitLocale', '"ar"')
+  debug('==> All done...');
+</script>
+<script src="../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/misc/extract-http-content-language.php b/LayoutTests/http/tests/misc/extract-http-content-language.php
new file mode 100644 (file)
index 0000000..2a117f2
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+  header("Content-Language: zh-CN");
+?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<script src="../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=97929">bug 97929</a>:
+Extract HTTP Content-Language header.</p>
+<div id="console"></div>
+<div id="x"></div>
+<div id="y" lang="ar"></div>
+<script>
+  debug('==> Value extracted from HTTP "Content-Language" header...');
+  shouldBe('window.getComputedStyle(document.getElementById("x")).webkitLocale', '"zh-CN"')
+  debug('==> Value set by div "lang" tag...');
+  shouldBe('window.getComputedStyle(document.getElementById("y")).webkitLocale', '"ar"')
+  debug('==> All done...');
+</script>
+<script src="../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
old mode 100644 (file)
new mode 100755 (executable)
index bd51285..8b20fed
@@ -1,3 +1,16 @@
+2012-10-18  Brian White  <bcwhite@chromium.org>
+
+        WebKit Doesn't Recognize Content-Language HTTP Header
+        https://bugs.webkit.org/show_bug.cgi?id=97929
+
+        Reviewed by Alexey Proskuryakov.
+
+        The HTTP "Content-Language" header may be present and include the
+        language of the page contents (as opposed to an embedded meta tag).
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::didBeginDocument):
+
 2012-10-18  Jer Noble  <jer.noble@apple.com>
 
         Crash in WebCore::Document::webkitExitFullscreen + 618
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index befaa92..81fc0c5
@@ -70,6 +70,7 @@
 #include "HTMLFormElement.h"
 #include "HTMLNames.h"
 #include "HTMLObjectElement.h"
+#include "HTMLParserIdioms.h"
 #include "HTTPParsers.h"
 #include "HistoryItem.h"
 #include "InspectorController.h"
@@ -666,6 +667,15 @@ void FrameLoader::didBeginDocument(bool dispatch)
         String reportOnlyContentSecurityPolicy = m_documentLoader->response().httpHeaderField("X-WebKit-CSP-Report-Only");
         if (!reportOnlyContentSecurityPolicy.isEmpty())
             m_frame->document()->contentSecurityPolicy()->didReceiveHeader(reportOnlyContentSecurityPolicy, ContentSecurityPolicy::ReportOnly);
+
+        String headerContentLanguage = m_documentLoader->response().httpHeaderField("Content-Language");
+        if (!headerContentLanguage.isEmpty()) {
+            size_t commaIndex = headerContentLanguage.find(',');
+            headerContentLanguage.truncate(commaIndex); // notFound == -1 == don't truncate
+            headerContentLanguage = headerContentLanguage.stripWhiteSpace(isHTMLSpace);
+            if (!headerContentLanguage.isEmpty())
+                m_frame->document()->setContentLanguage(headerContentLanguage);
+        }
     }
 
     history()->restoreDocumentState();