Chromium Code Reviews| Index: Source/core/xml/XMLHttpRequest.cpp |
| diff --git a/Source/core/xml/XMLHttpRequest.cpp b/Source/core/xml/XMLHttpRequest.cpp |
| index cc6d559f71327a67760ae612ff3a9361b804d8c8..243b8d8849c4db6a33ee826c40cfcd91247657c3 100644 |
| --- a/Source/core/xml/XMLHttpRequest.cpp |
| +++ b/Source/core/xml/XMLHttpRequest.cpp |
| @@ -23,12 +23,7 @@ |
| #include "config.h" |
| #include "core/xml/XMLHttpRequest.h" |
| -#include <wtf/ArrayBuffer.h> |
| -#include <wtf/ArrayBufferView.h> |
| -#include <wtf/RefCountedLeakCounter.h> |
| -#include <wtf/StdLibExtras.h> |
| -#include <wtf/text/CString.h> |
| -#include <wtf/UnusedParam.h> |
| +#include "RuntimeEnabledFeatures.h" |
| #include "core/dom/ContextFeatures.h" |
| #include "core/dom/DOMImplementation.h" |
| #include "core/dom/Event.h" |
| @@ -39,6 +34,7 @@ |
| #include "core/editing/markup.h" |
| #include "core/fileapi/Blob.h" |
| #include "core/fileapi/File.h" |
| +#include "core/fileapi/Stream.h" |
| #include "core/html/DOMFormData.h" |
| #include "core/html/HTMLDocument.h" |
| #include "core/inspector/InspectorInstrumentation.h" |
| @@ -58,6 +54,12 @@ |
| #include "core/xml/XMLHttpRequestProgressEvent.h" |
| #include "core/xml/XMLHttpRequestUpload.h" |
| #include "weborigin/SecurityOrigin.h" |
| +#include "wtf/ArrayBuffer.h" |
| +#include "wtf/ArrayBufferView.h" |
| +#include "wtf/RefCountedLeakCounter.h" |
| +#include "wtf/StdLibExtras.h" |
| +#include "wtf/UnusedParam.h" |
| +#include "wtf/text/CString.h" |
| namespace WebCore { |
| @@ -313,6 +315,19 @@ ArrayBuffer* XMLHttpRequest::responseArrayBuffer(ExceptionCode& ec) |
| return m_responseArrayBuffer.get(); |
| } |
| +Stream* XMLHttpRequest::responseStream(ExceptionCode& ec) |
| +{ |
| + if (m_responseTypeCode != ResponseTypeStream) { |
| + ec = InvalidStateError; |
| + return 0; |
| + } |
| + |
| + if (m_error || (m_state != LOADING && m_state != DONE)) |
| + return 0; |
| + |
| + return m_responseStream.get(); |
| +} |
| + |
| void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionCode& ec) |
| { |
| // FIXME: Need to trigger or update the timeout Timer here, if needed. http://webkit.org/b/98156 |
| @@ -342,35 +357,43 @@ void XMLHttpRequest::setResponseType(const String& responseType, ExceptionCode& |
| return; |
| } |
| - if (responseType == "") |
| + if (responseType == "") { |
| m_responseTypeCode = ResponseTypeDefault; |
| - else if (responseType == "text") |
| + } else if (responseType == "text") { |
| m_responseTypeCode = ResponseTypeText; |
| - else if (responseType == "document") |
| + } else if (responseType == "document") { |
| m_responseTypeCode = ResponseTypeDocument; |
| - else if (responseType == "blob") |
| + } else if (responseType == "blob") { |
| m_responseTypeCode = ResponseTypeBlob; |
| - else if (responseType == "arraybuffer") |
| + } else if (responseType == "arraybuffer") { |
| m_responseTypeCode = ResponseTypeArrayBuffer; |
| - else |
| + } else if (responseType == "stream") { |
| + if (RuntimeEnabledFeatures::streamEnabled()) |
| + m_responseTypeCode = ResponseTypeStream; |
| + else |
| + return; |
| + } else { |
| ASSERT_NOT_REACHED(); |
| + } |
| } |
| String XMLHttpRequest::responseType() |
| { |
| switch (m_responseTypeCode) { |
| case ResponseTypeDefault: |
| - return ""; |
| + return ASCIILiteral(""); |
| case ResponseTypeText: |
| - return "text"; |
| + return ASCIILiteral("text"); |
| case ResponseTypeDocument: |
| - return "document"; |
| + return ASCIILiteral("document"); |
| case ResponseTypeBlob: |
| - return "blob"; |
| + return ASCIILiteral("blob"); |
| case ResponseTypeArrayBuffer: |
| - return "arraybuffer"; |
| + return ASCIILiteral("arraybuffer"); |
| + case ResponseTypeStream: |
| + return ASCIILiteral("stream"); |
| } |
| - return ""; |
| + return ASCIILiteral(""); |
| } |
| XMLHttpRequestUpload* XMLHttpRequest::upload() |
| @@ -938,7 +961,7 @@ String XMLHttpRequest::getAllResponseHeaders(ExceptionCode& ec) const |
| { |
| if (m_state < HEADERS_RECEIVED) { |
| ec = InvalidStateError; |
| - return ""; |
| + return ASCIILiteral(""); |
| } |
| StringBuilder stringBuilder; |
| @@ -1086,6 +1109,9 @@ void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) |
| InspectorInstrumentation::didFinishXHRLoading(scriptExecutionContext(), this, identifier, m_responseText, m_url, m_lastSendURL, m_lastSendLineNumber); |
| + if (m_responseStream) |
| + m_responseStream->finalize(); |
| + |
| bool hadLoader = m_loader; |
| m_loader = 0; |
| @@ -1162,6 +1188,10 @@ void XMLHttpRequest::didReceiveData(const char* data, int len) |
| if (!m_binaryResponseBuilder) |
| m_binaryResponseBuilder = SharedBuffer::create(); |
| m_binaryResponseBuilder->append(data, len); |
| + } else if (m_responseTypeCode == ResponseTypeStream) { |
| + if (!m_responseStream) |
| + m_responseStream = Stream::create(responseMIMEType()); |
| + m_responseStream->addData(data, len); |
|
michaeln
2013/07/24 03:57:22
Also, it it a desired characteristic of this imple
|
| } |
| if (!m_error) { |