Index: Source/core/xml/XMLHttpRequest.cpp |
=================================================================== |
--- Source/core/xml/XMLHttpRequest.cpp (revision 169408) |
+++ Source/core/xml/XMLHttpRequest.cpp (working copy) |
@@ -168,7 +168,6 @@ |
, m_timeoutMilliseconds(0) |
, m_state(UNSENT) |
, m_createdDocument(false) |
- , m_downloadedBlobLength(0) |
, m_error(false) |
, m_uploadEventsAllowed(true) |
, m_uploadComplete(false) |
@@ -272,26 +271,26 @@ |
Blob* XMLHttpRequest::responseBlob() |
{ |
ASSERT(m_responseTypeCode == ResponseTypeBlob); |
- ASSERT(!m_binaryResponseBuilder.get()); |
// We always return null before DONE. |
if (m_error || m_state != DONE) |
return 0; |
if (!m_responseBlob) { |
- // When "blob" is specified for the responseType attribute, |
- // we redirect the downloaded data to a file-handle directly |
- // in the browser process. |
- // We get the file-path from the ResourceResponse directly |
- // instead of copying the bytes between the browser and the renderer. |
+ // FIXME: Once RedirectToFileResourceHandler is fixed in Chromium, |
+ // re-enable download-to-file optimization introduced by Blink revision |
+ // 163141. |
OwnPtr<BlobData> blobData = BlobData::create(); |
- String filePath = m_response.downloadedFilePath(); |
- // If we errored out or got no data, we still return a blob, just an empty one. |
- if (!filePath.isEmpty() && m_downloadedBlobLength) { |
- blobData->appendFile(filePath); |
+ size_t size = 0; |
+ if (m_binaryResponseBuilder.get() && m_binaryResponseBuilder->size() > 0) { |
+ RefPtr<RawData> rawData = RawData::create(); |
+ size = m_binaryResponseBuilder->size(); |
+ rawData->mutableData()->append(m_binaryResponseBuilder->data(), size); |
+ blobData->appendData(rawData, 0, BlobDataItem::toEndOfFile); |
blobData->setContentType(responseMIMEType()); // responseMIMEType defaults to text/xml which may be incorrect. |
+ m_binaryResponseBuilder.clear(); |
} |
- m_responseBlob = Blob::create(BlobDataHandle::create(blobData.release(), m_downloadedBlobLength)); |
+ m_responseBlob = Blob::create(BlobDataHandle::create(blobData.release(), size)); |
} |
return m_responseBlob.get(); |
@@ -800,12 +799,6 @@ |
request.setHTTPMethod(m_method); |
request.setTargetType(ResourceRequest::TargetIsXHR); |
- // When "blob" is specified for the responseType attribute, |
- // we redirect the downloaded data to a file-handle directly |
- // and get the file-path as the result. |
- if (responseTypeCode() == ResponseTypeBlob) |
- request.setDownloadToFile(true); |
- |
InspectorInstrumentation::willLoadXHR(executionContext(), this, this, m_method, m_url, m_async, m_requestEntityBody ? m_requestEntityBody->deepCopy() : 0, m_requestHeaders, m_includeCredentials); |
if (m_requestEntityBody) { |
@@ -830,12 +823,6 @@ |
options.mixedContentBlockingTreatment = TreatAsPassiveContent; |
options.timeoutMilliseconds = m_timeoutMilliseconds; |
- // Since we redirect the downloaded data to a file-handle directly |
- // when "blob" is specified for the responseType attribute, |
- // buffering is not needed. |
- if (responseTypeCode() == ResponseTypeBlob) |
- options.dataBufferingPolicy = DoNotBufferData; |
- |
m_exceptionCode = 0; |
m_error = false; |
@@ -958,7 +945,7 @@ |
m_createdDocument = false; |
m_responseDocument = 0; |
- m_responseBlob = 0; |
+ m_responseBlob = nullptr; |
m_responseStream = 0; |
@@ -1307,8 +1294,6 @@ |
void XMLHttpRequest::didReceiveData(const char* data, int len) |
{ |
- ASSERT(m_responseTypeCode != ResponseTypeBlob); |
- |
if (m_error) |
return; |
@@ -1341,7 +1326,7 @@ |
if (useDecoder) { |
m_responseText = m_responseText.concatenateWith(m_decoder->decode(data, len)); |
- } else if (m_responseTypeCode == ResponseTypeArrayBuffer) { |
+ } else if (m_responseTypeCode == ResponseTypeArrayBuffer || m_responseTypeCode == ResponseTypeBlob) { |
// Buffer binary data. |
if (!m_binaryResponseBuilder) |
m_binaryResponseBuilder = SharedBuffer::create(); |
@@ -1358,26 +1343,6 @@ |
trackProgress(len); |
} |
-void XMLHttpRequest::didDownloadData(int dataLength) |
-{ |
- ASSERT(m_responseTypeCode == ResponseTypeBlob); |
- |
- if (m_error) |
- return; |
- |
- if (m_state < HEADERS_RECEIVED) |
- changeState(HEADERS_RECEIVED); |
- |
- if (!dataLength) |
- return; |
- |
- if (m_error) |
- return; |
- |
- m_downloadedBlobLength += dataLength; |
- trackProgress(dataLength); |
-} |
- |
void XMLHttpRequest::handleDidTimeout() |
{ |
WTF_LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this); |