Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp

Issue 2467233002: Remove "legacy" experimental stream support (Closed)
Patch Set: fix Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org>
4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org>
5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved.
6 * Copyright (C) 2012 Intel Corporation 6 * Copyright (C) 2012 Intel Corporation
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "core/frame/csp/ContentSecurityPolicy.h" 54 #include "core/frame/csp/ContentSecurityPolicy.h"
55 #include "core/html/FormData.h" 55 #include "core/html/FormData.h"
56 #include "core/html/HTMLDocument.h" 56 #include "core/html/HTMLDocument.h"
57 #include "core/html/parser/TextResourceDecoder.h" 57 #include "core/html/parser/TextResourceDecoder.h"
58 #include "core/inspector/ConsoleMessage.h" 58 #include "core/inspector/ConsoleMessage.h"
59 #include "core/inspector/InspectorInstrumentation.h" 59 #include "core/inspector/InspectorInstrumentation.h"
60 #include "core/inspector/InspectorTraceEvents.h" 60 #include "core/inspector/InspectorTraceEvents.h"
61 #include "core/loader/ThreadableLoader.h" 61 #include "core/loader/ThreadableLoader.h"
62 #include "core/page/ChromeClient.h" 62 #include "core/page/ChromeClient.h"
63 #include "core/page/Page.h" 63 #include "core/page/Page.h"
64 #include "core/streams/Stream.h"
65 #include "core/xmlhttprequest/XMLHttpRequestUpload.h" 64 #include "core/xmlhttprequest/XMLHttpRequestUpload.h"
66 #include "platform/FileMetadata.h" 65 #include "platform/FileMetadata.h"
67 #include "platform/HTTPNames.h" 66 #include "platform/HTTPNames.h"
68 #include "platform/Histogram.h" 67 #include "platform/Histogram.h"
69 #include "platform/RuntimeEnabledFeatures.h" 68 #include "platform/RuntimeEnabledFeatures.h"
70 #include "platform/SharedBuffer.h" 69 #include "platform/SharedBuffer.h"
71 #include "platform/blob/BlobData.h" 70 #include "platform/blob/BlobData.h"
72 #include "platform/network/HTTPParsers.h" 71 #include "platform/network/HTTPParsers.h"
73 #include "platform/network/NetworkLog.h" 72 #include "platform/network/NetworkLog.h"
74 #include "platform/network/ParsedContentType.h" 73 #include "platform/network/ParsedContentType.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 return xmlHttpRequest; 220 return xmlHttpRequest;
222 } 221 }
223 222
224 XMLHttpRequest::XMLHttpRequest( 223 XMLHttpRequest::XMLHttpRequest(
225 ExecutionContext* context, 224 ExecutionContext* context,
226 PassRefPtr<SecurityOrigin> isolatedWorldSecurityOrigin) 225 PassRefPtr<SecurityOrigin> isolatedWorldSecurityOrigin)
227 : ActiveScriptWrappable(this), 226 : ActiveScriptWrappable(this),
228 ActiveDOMObject(context), 227 ActiveDOMObject(context),
229 m_timeoutMilliseconds(0), 228 m_timeoutMilliseconds(0),
230 m_responseBlob(this, nullptr), 229 m_responseBlob(this, nullptr),
231 m_responseLegacyStream(this, nullptr),
232 m_state(kUnsent), 230 m_state(kUnsent),
233 m_responseDocument(this, nullptr), 231 m_responseDocument(this, nullptr),
234 m_lengthDownloadedToFile(0), 232 m_lengthDownloadedToFile(0),
235 m_responseArrayBuffer(this, nullptr), 233 m_responseArrayBuffer(this, nullptr),
236 m_receivedLength(0), 234 m_receivedLength(0),
237 m_exceptionCode(0), 235 m_exceptionCode(0),
238 m_progressEventThrottle( 236 m_progressEventThrottle(
239 XMLHttpRequestProgressEventThrottle::create(this)), 237 XMLHttpRequestProgressEventThrottle::create(this)),
240 m_responseTypeCode(ResponseTypeDefault), 238 m_responseTypeCode(ResponseTypeDefault),
241 m_isolatedWorldSecurityOrigin(isolatedWorldSecurityOrigin), 239 m_isolatedWorldSecurityOrigin(isolatedWorldSecurityOrigin),
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 m_responseArrayBuffer = buffer; 395 m_responseArrayBuffer = buffer;
398 m_binaryResponseBuilder.clear(); 396 m_binaryResponseBuilder.clear();
399 } else { 397 } else {
400 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0); 398 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0);
401 } 399 }
402 } 400 }
403 401
404 return m_responseArrayBuffer.get(); 402 return m_responseArrayBuffer.get();
405 } 403 }
406 404
407 Stream* XMLHttpRequest::responseLegacyStream() {
408 DCHECK_EQ(m_responseTypeCode, ResponseTypeLegacyStream);
409
410 if (m_error || (m_state != kLoading && m_state != kDone))
411 return nullptr;
412
413 return m_responseLegacyStream;
414 }
415
416 void XMLHttpRequest::setTimeout(unsigned timeout, 405 void XMLHttpRequest::setTimeout(unsigned timeout,
417 ExceptionState& exceptionState) { 406 ExceptionState& exceptionState) {
418 // FIXME: Need to trigger or update the timeout Timer here, if needed. 407 // FIXME: Need to trigger or update the timeout Timer here, if needed.
419 // http://webkit.org/b/98156 408 // http://webkit.org/b/98156
420 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set while 409 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set while
421 // fetching is in progress. If that occurs it will still be measured relative 410 // fetching is in progress. If that occurs it will still be measured relative
422 // to the start of fetching." 411 // to the start of fetching."
423 if (getExecutionContext() && getExecutionContext()->isDocument() && 412 if (getExecutionContext() && getExecutionContext()->isDocument() &&
424 !m_async) { 413 !m_async) {
425 exceptionState.throwDOMException(InvalidAccessError, 414 exceptionState.throwDOMException(InvalidAccessError,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 } else if (responseType == "text") { 455 } else if (responseType == "text") {
467 m_responseTypeCode = ResponseTypeText; 456 m_responseTypeCode = ResponseTypeText;
468 } else if (responseType == "json") { 457 } else if (responseType == "json") {
469 m_responseTypeCode = ResponseTypeJSON; 458 m_responseTypeCode = ResponseTypeJSON;
470 } else if (responseType == "document") { 459 } else if (responseType == "document") {
471 m_responseTypeCode = ResponseTypeDocument; 460 m_responseTypeCode = ResponseTypeDocument;
472 } else if (responseType == "blob") { 461 } else if (responseType == "blob") {
473 m_responseTypeCode = ResponseTypeBlob; 462 m_responseTypeCode = ResponseTypeBlob;
474 } else if (responseType == "arraybuffer") { 463 } else if (responseType == "arraybuffer") {
475 m_responseTypeCode = ResponseTypeArrayBuffer; 464 m_responseTypeCode = ResponseTypeArrayBuffer;
476 } else if (responseType == "legacystream") {
477 if (RuntimeEnabledFeatures::experimentalStreamEnabled())
478 m_responseTypeCode = ResponseTypeLegacyStream;
479 else
480 return;
481 } else { 465 } else {
482 NOTREACHED(); 466 NOTREACHED();
483 } 467 }
484 } 468 }
485 469
486 String XMLHttpRequest::responseType() { 470 String XMLHttpRequest::responseType() {
487 switch (m_responseTypeCode) { 471 switch (m_responseTypeCode) {
488 case ResponseTypeDefault: 472 case ResponseTypeDefault:
489 return ""; 473 return "";
490 case ResponseTypeText: 474 case ResponseTypeText:
491 return "text"; 475 return "text";
492 case ResponseTypeJSON: 476 case ResponseTypeJSON:
493 return "json"; 477 return "json";
494 case ResponseTypeDocument: 478 case ResponseTypeDocument:
495 return "document"; 479 return "document";
496 case ResponseTypeBlob: 480 case ResponseTypeBlob:
497 return "blob"; 481 return "blob";
498 case ResponseTypeArrayBuffer: 482 case ResponseTypeArrayBuffer:
499 return "arraybuffer"; 483 return "arraybuffer";
500 case ResponseTypeLegacyStream:
501 return "legacystream";
502 } 484 }
503 return ""; 485 return "";
504 } 486 }
505 487
506 String XMLHttpRequest::responseURL() { 488 String XMLHttpRequest::responseURL() {
507 KURL responseURL(m_response.url()); 489 KURL responseURL(m_response.url());
508 if (!responseURL.isNull()) 490 if (!responseURL.isNull())
509 responseURL.removeFragmentIdentifier(); 491 responseURL.removeFragmentIdentifier();
510 return responseURL.getString(); 492 return responseURL.getString();
511 } 493 }
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 } 1104 }
1123 1105
1124 bool XMLHttpRequest::internalAbort() { 1106 bool XMLHttpRequest::internalAbort() {
1125 m_error = true; 1107 m_error = true;
1126 1108
1127 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped()) 1109 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped())
1128 m_responseDocumentParser->stopParsing(); 1110 m_responseDocumentParser->stopParsing();
1129 1111
1130 clearVariablesForLoading(); 1112 clearVariablesForLoading();
1131 1113
1132 if (m_responseLegacyStream && m_state != kDone)
1133 m_responseLegacyStream->abort();
1134
1135 clearResponse(); 1114 clearResponse();
1136 clearRequest(); 1115 clearRequest();
1137 1116
1138 if (!m_loader) 1117 if (!m_loader)
1139 return true; 1118 return true;
1140 1119
1141 // Cancelling the ThreadableLoader m_loader may result in calling 1120 // Cancelling the ThreadableLoader m_loader may result in calling
1142 // window.onload synchronously. If such an onload handler contains open() 1121 // window.onload synchronously. If such an onload handler contains open()
1143 // call on the same XMLHttpRequest object, reentry happens. 1122 // call on the same XMLHttpRequest object, reentry happens.
1144 // 1123 //
(...skipping 23 matching lines...) Expand all
1168 m_responseText.clear(); 1147 m_responseText.clear();
1169 1148
1170 m_parsedResponse = false; 1149 m_parsedResponse = false;
1171 m_responseDocument = nullptr; 1150 m_responseDocument = nullptr;
1172 1151
1173 m_responseBlob = nullptr; 1152 m_responseBlob = nullptr;
1174 1153
1175 m_downloadingToFile = false; 1154 m_downloadingToFile = false;
1176 m_lengthDownloadedToFile = 0; 1155 m_lengthDownloadedToFile = 0;
1177 1156
1178 m_responseLegacyStream = nullptr;
1179
1180 // These variables may referred by the response accessors. So, we can clear 1157 // These variables may referred by the response accessors. So, we can clear
1181 // this only when we clear the response holder variables above. 1158 // this only when we clear the response holder variables above.
1182 m_binaryResponseBuilder.clear(); 1159 m_binaryResponseBuilder.clear();
1183 m_responseArrayBuffer.clear(); 1160 m_responseArrayBuffer.clear();
1184 } 1161 }
1185 1162
1186 void XMLHttpRequest::clearRequest() { 1163 void XMLHttpRequest::clearRequest() {
1187 m_requestHeaders.clear(); 1164 m_requestHeaders.clear();
1188 } 1165 }
1189 1166
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 } 1529 }
1553 1530
1554 if (m_decoder) { 1531 if (m_decoder) {
1555 auto text = m_decoder->flush(); 1532 auto text = m_decoder->flush();
1556 if (!text.isEmpty() && !m_responseTextOverflow) { 1533 if (!text.isEmpty() && !m_responseTextOverflow) {
1557 m_responseText = m_responseText.concatenateWith(text); 1534 m_responseText = m_responseText.concatenateWith(text);
1558 m_responseTextOverflow = m_responseText.isEmpty(); 1535 m_responseTextOverflow = m_responseText.isEmpty();
1559 } 1536 }
1560 } 1537 }
1561 1538
1562 if (m_responseLegacyStream)
1563 m_responseLegacyStream->finalize();
1564
1565 clearVariablesForLoading(); 1539 clearVariablesForLoading();
1566 endLoading(); 1540 endLoading();
1567 } 1541 }
1568 1542
1569 void XMLHttpRequest::didFinishLoadingFromBlob() { 1543 void XMLHttpRequest::didFinishLoadingFromBlob() {
1570 NETWORK_DVLOG(1) << this << " didFinishLoadingFromBlob"; 1544 NETWORK_DVLOG(1) << this << " didFinishLoadingFromBlob";
1571 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); 1545 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel);
1572 1546
1573 didFinishLoadingInternal(); 1547 didFinishLoadingInternal();
1574 } 1548 }
(...skipping 22 matching lines...) Expand all
1597 } 1571 }
1598 return BlobDataHandle::create(std::move(blobData), m_lengthDownloadedToFile); 1572 return BlobDataHandle::create(std::move(blobData), m_lengthDownloadedToFile);
1599 } 1573 }
1600 1574
1601 void XMLHttpRequest::notifyParserStopped() { 1575 void XMLHttpRequest::notifyParserStopped() {
1602 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); 1576 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel);
1603 1577
1604 // This should only be called when response document is parsed asynchronously. 1578 // This should only be called when response document is parsed asynchronously.
1605 DCHECK(m_responseDocumentParser); 1579 DCHECK(m_responseDocumentParser);
1606 DCHECK(!m_responseDocumentParser->isParsing()); 1580 DCHECK(!m_responseDocumentParser->isParsing());
1607 DCHECK(!m_responseLegacyStream);
1608 1581
1609 // Do nothing if we are called from |internalAbort()|. 1582 // Do nothing if we are called from |internalAbort()|.
1610 if (m_error) 1583 if (m_error)
1611 return; 1584 return;
1612 1585
1613 clearVariablesForLoading(); 1586 clearVariablesForLoading();
1614 1587
1615 m_responseDocument->implicitClose(); 1588 m_responseDocument->implicitClose();
1616 1589
1617 if (!m_responseDocument->wellFormed()) 1590 if (!m_responseDocument->wellFormed())
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 if (!text.isEmpty() && !m_responseTextOverflow) { 1733 if (!text.isEmpty() && !m_responseTextOverflow) {
1761 m_responseText = m_responseText.concatenateWith(text); 1734 m_responseText = m_responseText.concatenateWith(text);
1762 m_responseTextOverflow = m_responseText.isEmpty(); 1735 m_responseTextOverflow = m_responseText.isEmpty();
1763 } 1736 }
1764 } else if (m_responseTypeCode == ResponseTypeArrayBuffer || 1737 } else if (m_responseTypeCode == ResponseTypeArrayBuffer ||
1765 m_responseTypeCode == ResponseTypeBlob) { 1738 m_responseTypeCode == ResponseTypeBlob) {
1766 // Buffer binary data. 1739 // Buffer binary data.
1767 if (!m_binaryResponseBuilder) 1740 if (!m_binaryResponseBuilder)
1768 m_binaryResponseBuilder = SharedBuffer::create(); 1741 m_binaryResponseBuilder = SharedBuffer::create();
1769 m_binaryResponseBuilder->append(data, len); 1742 m_binaryResponseBuilder->append(data, len);
1770 } else if (m_responseTypeCode == ResponseTypeLegacyStream) {
1771 if (!m_responseLegacyStream)
1772 m_responseLegacyStream =
1773 Stream::create(getExecutionContext(), responseType());
1774 m_responseLegacyStream->addData(data, len);
1775 } 1743 }
1776 1744
1777 if (m_blobLoader) { 1745 if (m_blobLoader) {
1778 // In this case, the data is provided by m_blobLoader. As progress 1746 // In this case, the data is provided by m_blobLoader. As progress
1779 // events are already fired, we should return here. 1747 // events are already fired, we should return here.
1780 return; 1748 return;
1781 } 1749 }
1782 trackProgress(len); 1750 trackProgress(len);
1783 } 1751 }
1784 1752
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 const AtomicString& XMLHttpRequest::interfaceName() const { 1817 const AtomicString& XMLHttpRequest::interfaceName() const {
1850 return EventTargetNames::XMLHttpRequest; 1818 return EventTargetNames::XMLHttpRequest;
1851 } 1819 }
1852 1820
1853 ExecutionContext* XMLHttpRequest::getExecutionContext() const { 1821 ExecutionContext* XMLHttpRequest::getExecutionContext() const {
1854 return ActiveDOMObject::getExecutionContext(); 1822 return ActiveDOMObject::getExecutionContext();
1855 } 1823 }
1856 1824
1857 DEFINE_TRACE(XMLHttpRequest) { 1825 DEFINE_TRACE(XMLHttpRequest) {
1858 visitor->trace(m_responseBlob); 1826 visitor->trace(m_responseBlob);
1859 visitor->trace(m_responseLegacyStream);
1860 visitor->trace(m_loader); 1827 visitor->trace(m_loader);
1861 visitor->trace(m_responseDocument); 1828 visitor->trace(m_responseDocument);
1862 visitor->trace(m_responseDocumentParser); 1829 visitor->trace(m_responseDocumentParser);
1863 visitor->trace(m_responseArrayBuffer); 1830 visitor->trace(m_responseArrayBuffer);
1864 visitor->trace(m_progressEventThrottle); 1831 visitor->trace(m_progressEventThrottle);
1865 visitor->trace(m_upload); 1832 visitor->trace(m_upload);
1866 visitor->trace(m_blobLoader); 1833 visitor->trace(m_blobLoader);
1867 XMLHttpRequestEventTarget::trace(visitor); 1834 XMLHttpRequestEventTarget::trace(visitor);
1868 DocumentParserClient::trace(visitor); 1835 DocumentParserClient::trace(visitor);
1869 ActiveDOMObject::trace(visitor); 1836 ActiveDOMObject::trace(visitor);
1870 } 1837 }
1871 1838
1872 DEFINE_TRACE_WRAPPERS(XMLHttpRequest) { 1839 DEFINE_TRACE_WRAPPERS(XMLHttpRequest) {
1873 visitor->traceWrappers(m_responseBlob); 1840 visitor->traceWrappers(m_responseBlob);
1874 visitor->traceWrappers(m_responseLegacyStream);
1875 visitor->traceWrappers(m_responseDocument); 1841 visitor->traceWrappers(m_responseDocument);
1876 visitor->traceWrappers(m_responseArrayBuffer); 1842 visitor->traceWrappers(m_responseArrayBuffer);
1877 XMLHttpRequestEventTarget::traceWrappers(visitor); 1843 XMLHttpRequestEventTarget::traceWrappers(visitor);
1878 } 1844 }
1879 1845
1880 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { 1846 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) {
1881 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); 1847 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr);
1882 } 1848 }
1883 1849
1884 } // namespace blink 1850 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698