Title: [170960] trunk
- Revision
- 170960
- Author
- commit-qu...@webkit.org
- Date
- 2014-07-10 03:09:41 -0700 (Thu, 10 Jul 2014)
Log Message
[XHR] overrideMimeType() should be able to change encoding in HEADERS RECEIVED state
https://bugs.webkit.org/show_bug.cgi?id=128968
Patch by Youenn Fablet <youenn.fab...@crf.canon.fr> on 2014-07-10
Reviewed by Alexey Proskuryakov.
Source/WebCore:
Moved response encoding computation from didReceiveResponse to didReceiveData, just before the decoder is instantiated.
This allows overrideMimeType to be changed within readystatechange event callback and have an impact on selected encoding.
Test: http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis.html
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::didReceiveResponse): Removed m_responseEncoding computation from response and mimeTypeOverride.
(WebCore::XMLHttpRequest::didReceiveData): Added m_responseEncoding computation from response and mimeTypeOverride.
LayoutTests:
Added test equivalent to http://w3c-test.org/web-platform-tests/master/XMLHttpRequest/overridemimetype-headers-received-state-force-shiftjis.htm
The test sets overrideMimeType when xhr state is changed to HEADERS RECEIVED.
* http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis-expected.txt: Added.
* http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis.html: Added.
* http/tests/xmlhttprequest/resources/get-content.php: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (170959 => 170960)
--- trunk/LayoutTests/ChangeLog 2014-07-10 06:35:08 UTC (rev 170959)
+++ trunk/LayoutTests/ChangeLog 2014-07-10 10:09:41 UTC (rev 170960)
@@ -1,3 +1,17 @@
+2014-07-10 Youenn Fablet <youenn.fab...@crf.canon.fr>
+
+ [XHR] overrideMimeType() should be able to change encoding in HEADERS RECEIVED state
+ https://bugs.webkit.org/show_bug.cgi?id=128968
+
+ Reviewed by Alexey Proskuryakov.
+
+ Added test equivalent to http://w3c-test.org/web-platform-tests/master/XMLHttpRequest/overridemimetype-headers-received-state-force-shiftjis.htm
+ The test sets overrideMimeType when xhr state is changed to HEADERS RECEIVED.
+
+ * http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis-expected.txt: Added.
+ * http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis.html: Added.
+ * http/tests/xmlhttprequest/resources/get-content.php: Added.
+
2014-07-08 Jeffrey Pfau <jp...@apple.com>
Fix flaky loading tests
Added: trunk/LayoutTests/http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis-expected.txt (0 => 170960)
--- trunk/LayoutTests/http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis-expected.txt 2014-07-10 10:09:41 UTC (rev 170960)
@@ -0,0 +1,3 @@
+
+PASS XMLHttpRequest: overrideMimeType() in HEADERS RECEIVED state, enforcing Shift-JIS encoding
+
Added: trunk/LayoutTests/http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis.html (0 => 170960)
--- trunk/LayoutTests/http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis.html (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis.html 2014-07-10 10:09:41 UTC (rev 170960)
@@ -0,0 +1,35 @@
+<!doctype html>
+<html>
+ <head>
+ <title>XMLHttpRequest: overrideMimeType() in HEADERS RECEIVED state, enforcing Shift-JIS encoding</title>
+ <meta charset="utf-8">
+ <script src=""
+ <script src=""
+ <link rel="help" href="" data-tested-assertations="/following::ol/li[1] /following::ol/li[4]" />
+ <!-- similar to http://w3c-test.org/XMLHttpRequest/overridemimetype-headers-received-state-force-shiftjis.htm -->
+ </head>
+ <body>
+ <div id="log"></div>
+ <script>
+ var test = async_test();
+ var client = new XMLHttpRequest();
+ var readyState2Reached = false;
+ client._onreadystatechange_ = test.step_func( function() {
+ if(client.readyState===2){
+ readyState2Reached = true;
+ try{
+ client.overrideMimeType('text/plain;charset=Shift-JIS');
+ }catch(e){
+ assert_unreached('overrideMimeType should not throw in state 2');
+ }
+ }
+ if (client.readyState !== 4) return;
+ assert_equals( readyState2Reached, true, "readyState = 2 event fired" );
+ assert_equals( client.responseText, 'ใในใ', 'overrideMimeType() in HEADERS RECEIVED state set encoding' );
+ test.done();
+ });
+ client.open("GET", "resources/get-content.php?type="+encodeURIComponent('text/html;charset=UTF-8')+'&content=%83%65%83%58%83%67');
+ client.send( '' );
+ </script>
+ </body>
+</html>
Added: trunk/LayoutTests/http/tests/xmlhttprequest/resources/get-content.php (0 => 170960)
--- trunk/LayoutTests/http/tests/xmlhttprequest/resources/get-content.php (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/resources/get-content.php 2014-07-10 10:09:41 UTC (rev 170960)
@@ -0,0 +1,9 @@
+<?php
+ $content = $_GET["content"] ? $_GET["content"] : "";
+ $type = $_GET["type"] ? $_GET["type"] : "";
+ header("HTTP/1.1 200 OK");
+ header("Content-Type:" . $type);
+
+ echo $content;
+ exit;
+?>
Modified: trunk/Source/WebCore/ChangeLog (170959 => 170960)
--- trunk/Source/WebCore/ChangeLog 2014-07-10 06:35:08 UTC (rev 170959)
+++ trunk/Source/WebCore/ChangeLog 2014-07-10 10:09:41 UTC (rev 170960)
@@ -1,3 +1,19 @@
+2014-07-10 Youenn Fablet <youenn.fab...@crf.canon.fr>
+
+ [XHR] overrideMimeType() should be able to change encoding in HEADERS RECEIVED state
+ https://bugs.webkit.org/show_bug.cgi?id=128968
+
+ Reviewed by Alexey Proskuryakov.
+
+ Moved response encoding computation from didReceiveResponse to didReceiveData, just before the decoder is instantiated.
+ This allows overrideMimeType to be changed within readystatechange event callback and have an impact on selected encoding.
+
+ Test: http/tests/xmlhttprequest/overridemimetype-headers-received-state-force-shiftjis.html
+
+ * xml/XMLHttpRequest.cpp:
+ (WebCore::XMLHttpRequest::didReceiveResponse): Removed m_responseEncoding computation from response and mimeTypeOverride.
+ (WebCore::XMLHttpRequest::didReceiveData): Added m_responseEncoding computation from response and mimeTypeOverride.
+
2014-07-09 Brady Eidson <beid...@apple.com>
Fire connected/disconnected events for Gamepads.
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (170959 => 170960)
--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2014-07-10 06:35:08 UTC (rev 170959)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2014-07-10 10:09:41 UTC (rev 170960)
@@ -1128,13 +1128,8 @@
InspectorInstrumentation::didReceiveXHRResponse(scriptExecutionContext(), identifier);
m_response = response;
- if (!m_mimeTypeOverride.isEmpty()) {
+ if (!m_mimeTypeOverride.isEmpty())
m_response.setHTTPHeaderField(HTTPHeaderName::ContentType, m_mimeTypeOverride);
- m_responseEncoding = extractCharsetFromMediaType(m_mimeTypeOverride);
- }
-
- if (m_responseEncoding.isEmpty())
- m_responseEncoding = response.textEncodingName();
}
void XMLHttpRequest::didReceiveData(const char* data, int len)
@@ -1145,6 +1140,12 @@
if (m_state < HEADERS_RECEIVED)
changeState(HEADERS_RECEIVED);
+ // FIXME: Should we update "Content-Type" header field with m_mimeTypeOverride value in case it has changed since didReceiveResponse?
+ if (!m_mimeTypeOverride.isEmpty())
+ m_responseEncoding = extractCharsetFromMediaType(m_mimeTypeOverride);
+ if (m_responseEncoding.isEmpty())
+ m_responseEncoding = m_response.textEncodingName();
+
bool useDecoder = shouldDecodeResponse();
if (useDecoder && !m_decoder) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes