Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
| 12 * | 12 * |
| 13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 * Lesser General Public License for more details. | 16 * Lesser General Public License for more details. |
| 17 * | 17 * |
| 18 * You should have received a copy of the GNU Lesser General Public | 18 * You should have received a copy of the GNU Lesser General Public |
| 19 * License along with this library; if not, write to the Free Software | 19 * License along with this library; if not, write to the Free Software |
| 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 U SA | 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 * Boston, MA 02110-1301 USA | |
| 21 */ | 22 */ |
| 22 | 23 |
| 23 #include "core/xmlhttprequest/XMLHttpRequest.h" | 24 #include "core/xmlhttprequest/XMLHttpRequest.h" |
| 24 | 25 |
| 25 #include "bindings/core/v8/ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrStringO rFormData.h" | 26 #include "bindings/core/v8/ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrStringO rFormData.h" |
| 26 #include "bindings/core/v8/ArrayBufferOrArrayBufferViewOrBlobOrUSVString.h" | 27 #include "bindings/core/v8/ArrayBufferOrArrayBufferViewOrBlobOrUSVString.h" |
| 27 #include "bindings/core/v8/DOMWrapperWorld.h" | 28 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 28 #include "bindings/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "bindings/core/v8/ScriptState.h" | 30 #include "bindings/core/v8/ScriptState.h" |
| 30 #include "core/dom/DOMArrayBuffer.h" | 31 #include "core/dom/DOMArrayBuffer.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 void replaceCharsetInMediaType(String& mediaType, const String& charsetValue) { | 104 void replaceCharsetInMediaType(String& mediaType, const String& charsetValue) { |
| 104 unsigned pos = 0, len = 0; | 105 unsigned pos = 0, len = 0; |
| 105 | 106 |
| 106 findCharsetInMediaType(mediaType, pos, len); | 107 findCharsetInMediaType(mediaType, pos, len); |
| 107 | 108 |
| 108 if (!len) { | 109 if (!len) { |
| 109 // When no charset found, do nothing. | 110 // When no charset found, do nothing. |
| 110 return; | 111 return; |
| 111 } | 112 } |
| 112 | 113 |
| 113 // Found at least one existing charset, replace all occurrences with new chars et. | 114 // Found at least one existing charset, replace all occurrences with new |
| 115 // charset. | |
| 114 while (len) { | 116 while (len) { |
| 115 mediaType.replace(pos, len, charsetValue); | 117 mediaType.replace(pos, len, charsetValue); |
| 116 unsigned start = pos + charsetValue.length(); | 118 unsigned start = pos + charsetValue.length(); |
| 117 findCharsetInMediaType(mediaType, pos, len, start); | 119 findCharsetInMediaType(mediaType, pos, len, start); |
| 118 } | 120 } |
| 119 } | 121 } |
| 120 | 122 |
| 121 void logConsoleError(ExecutionContext* context, const String& message) { | 123 void logConsoleError(ExecutionContext* context, const String& message) { |
| 122 if (!context) | 124 if (!context) |
| 123 return; | 125 return; |
| 124 // FIXME: It's not good to report the bad usage without indicating what source line it came from. | 126 // FIXME: It's not good to report the bad usage without indicating what source |
| 125 // We should pass additional parameters so we can tell the console where the m istake occurred. | 127 // line it came from. We should pass additional parameters so we can tell the |
| 128 // console where the mistake occurred. | |
| 126 ConsoleMessage* consoleMessage = | 129 ConsoleMessage* consoleMessage = |
| 127 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message); | 130 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message); |
| 128 context->addConsoleMessage(consoleMessage); | 131 context->addConsoleMessage(consoleMessage); |
| 129 } | 132 } |
| 130 | 133 |
| 131 enum HeaderValueCategoryByRFC7230 { | 134 enum HeaderValueCategoryByRFC7230 { |
| 132 HeaderValueInvalid, | 135 HeaderValueInvalid, |
| 133 HeaderValueAffectedByNormalization, | 136 HeaderValueAffectedByNormalization, |
| 134 HeaderValueValid, | 137 HeaderValueValid, |
| 135 HeaderValueCategoryByRFC7230End | 138 HeaderValueCategoryByRFC7230End |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 | 277 |
| 275 ScriptString XMLHttpRequest::responseJSONSource() { | 278 ScriptString XMLHttpRequest::responseJSONSource() { |
| 276 DCHECK_EQ(m_responseTypeCode, ResponseTypeJSON); | 279 DCHECK_EQ(m_responseTypeCode, ResponseTypeJSON); |
| 277 | 280 |
| 278 if (m_error || m_state != kDone) | 281 if (m_error || m_state != kDone) |
| 279 return ScriptString(); | 282 return ScriptString(); |
| 280 return m_responseText; | 283 return m_responseText; |
| 281 } | 284 } |
| 282 | 285 |
| 283 void XMLHttpRequest::initResponseDocument() { | 286 void XMLHttpRequest::initResponseDocument() { |
| 284 // The W3C spec requires the final MIME type to be some valid XML type, or tex t/html. | 287 // The W3C spec requires the final MIME type to be some valid XML type, or |
| 285 // If it is text/html, then the responseType of "document" must have been supp lied explicitly. | 288 // text/html. If it is text/html, then the responseType of "document" must |
| 289 // have been supplied explicitly. | |
| 286 bool isHTML = responseIsHTML(); | 290 bool isHTML = responseIsHTML(); |
| 287 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) || | 291 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) || |
| 288 (isHTML && m_responseTypeCode == ResponseTypeDefault) || | 292 (isHTML && m_responseTypeCode == ResponseTypeDefault) || |
| 289 !getExecutionContext() || getExecutionContext()->isWorkerGlobalScope()) { | 293 !getExecutionContext() || getExecutionContext()->isWorkerGlobalScope()) { |
| 290 m_responseDocument = nullptr; | 294 m_responseDocument = nullptr; |
| 291 return; | 295 return; |
| 292 } | 296 } |
| 293 | 297 |
| 294 DocumentInit init = | 298 DocumentInit init = |
| 295 DocumentInit::fromContext(document()->contextDocument(), m_url); | 299 DocumentInit::fromContext(document()->contextDocument(), m_url); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 DCHECK_EQ(m_responseTypeCode, ResponseTypeLegacyStream); | 401 DCHECK_EQ(m_responseTypeCode, ResponseTypeLegacyStream); |
| 398 | 402 |
| 399 if (m_error || (m_state != kLoading && m_state != kDone)) | 403 if (m_error || (m_state != kLoading && m_state != kDone)) |
| 400 return nullptr; | 404 return nullptr; |
| 401 | 405 |
| 402 return m_responseLegacyStream; | 406 return m_responseLegacyStream; |
| 403 } | 407 } |
| 404 | 408 |
| 405 void XMLHttpRequest::setTimeout(unsigned timeout, | 409 void XMLHttpRequest::setTimeout(unsigned timeout, |
| 406 ExceptionState& exceptionState) { | 410 ExceptionState& exceptionState) { |
| 407 // FIXME: Need to trigger or update the timeout Timer here, if needed. http:// webkit.org/b/98156 | 411 // FIXME: Need to trigger or update the timeout Timer here, if needed. |
| 408 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set while fetching is in progress. If that occurs it will still be measured relative to t he start of fetching." | 412 // http://webkit.org/b/98156 |
| 413 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set while | |
| 414 // fetching is in progress. If that occurs it will still be measured relative | |
| 415 // to the start of fetching." | |
| 409 if (getExecutionContext() && getExecutionContext()->isDocument() && | 416 if (getExecutionContext() && getExecutionContext()->isDocument() && |
| 410 !m_async) { | 417 !m_async) { |
| 411 exceptionState.throwDOMException(InvalidAccessError, | 418 exceptionState.throwDOMException(InvalidAccessError, |
| 412 "Timeouts cannot be set for synchronous " | 419 "Timeouts cannot be set for synchronous " |
| 413 "requests made from a document."); | 420 "requests made from a document."); |
| 414 return; | 421 return; |
| 415 } | 422 } |
| 416 | 423 |
| 417 m_timeoutMilliseconds = timeout; | 424 m_timeoutMilliseconds = timeout; |
| 418 | 425 |
| 419 // From http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute: | 426 // From http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute: |
| 420 // Note: This implies that the timeout attribute can be set while fetching is in progress. If | 427 // Note: This implies that the timeout attribute can be set while fetching is |
| 421 // that occurs it will still be measured relative to the start of fetching. | 428 // in progress. If that occurs it will still be measured relative to the start |
| 429 // of fetching. | |
| 422 // | 430 // |
| 423 // The timeout may be overridden after send. | 431 // The timeout may be overridden after send. |
| 424 if (m_loader) | 432 if (m_loader) |
| 425 m_loader->overrideTimeout(timeout); | 433 m_loader->overrideTimeout(timeout); |
| 426 } | 434 } |
| 427 | 435 |
| 428 void XMLHttpRequest::setResponseType(const String& responseType, | 436 void XMLHttpRequest::setResponseType(const String& responseType, |
| 429 ExceptionState& exceptionState) { | 437 ExceptionState& exceptionState) { |
| 430 if (m_state >= kLoading) { | 438 if (m_state >= kLoading) { |
| 431 exceptionState.throwDOMException(InvalidStateError, | 439 exceptionState.throwDOMException(InvalidStateError, |
| 432 "The response type cannot be set if the " | 440 "The response type cannot be set if the " |
| 433 "object's state is LOADING or DONE."); | 441 "object's state is LOADING or DONE."); |
| 434 return; | 442 return; |
| 435 } | 443 } |
| 436 | 444 |
| 437 // Newer functionality is not available to synchronous requests in window cont exts, as a spec-mandated | 445 // Newer functionality is not available to synchronous requests in window |
| 438 // attempt to discourage synchronous XHR use. responseType is one such piece o f functionality. | 446 // contexts, as a spec-mandated attempt to discourage synchronous XHR use. |
| 447 // responseType is one such piece of functionality. | |
| 439 if (getExecutionContext() && getExecutionContext()->isDocument() && | 448 if (getExecutionContext() && getExecutionContext()->isDocument() && |
| 440 !m_async) { | 449 !m_async) { |
| 441 exceptionState.throwDOMException(InvalidAccessError, | 450 exceptionState.throwDOMException(InvalidAccessError, |
| 442 "The response type cannot be changed for " | 451 "The response type cannot be changed for " |
| 443 "synchronous requests made from a " | 452 "synchronous requests made from a " |
| 444 "document."); | 453 "document."); |
| 445 return; | 454 return; |
| 446 } | 455 } |
| 447 | 456 |
| 448 if (responseType == "") { | 457 if (responseType == "") { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 return; | 620 return; |
| 612 | 621 |
| 613 State previousState = m_state; | 622 State previousState = m_state; |
| 614 m_state = kUnsent; | 623 m_state = kUnsent; |
| 615 m_error = false; | 624 m_error = false; |
| 616 m_uploadComplete = false; | 625 m_uploadComplete = false; |
| 617 | 626 |
| 618 if (!ContentSecurityPolicy::shouldBypassMainWorld(getExecutionContext()) && | 627 if (!ContentSecurityPolicy::shouldBypassMainWorld(getExecutionContext()) && |
| 619 !getExecutionContext()->contentSecurityPolicy()->allowConnectToSource( | 628 !getExecutionContext()->contentSecurityPolicy()->allowConnectToSource( |
| 620 url)) { | 629 url)) { |
| 621 // We can safely expose the URL to JavaScript, as these checks happen synchr onously before redirection. JavaScript receives no new information. | 630 // We can safely expose the URL to JavaScript, as these checks happen |
| 631 // synchronously before redirection. JavaScript receives no new information. | |
| 622 exceptionState.throwSecurityError( | 632 exceptionState.throwSecurityError( |
| 623 "Refused to connect to '" + url.elidedString() + | 633 "Refused to connect to '" + url.elidedString() + |
| 624 "' because it violates the document's Content Security Policy."); | 634 "' because it violates the document's Content Security Policy."); |
| 625 return; | 635 return; |
| 626 } | 636 } |
| 627 | 637 |
| 628 if (!async && getExecutionContext()->isDocument()) { | 638 if (!async && getExecutionContext()->isDocument()) { |
| 629 if (document()->settings() && | 639 if (document()->settings() && |
| 630 !document()->settings()->syncXHRInDocumentsEnabled()) { | 640 !document()->settings()->syncXHRInDocumentsEnabled()) { |
| 631 exceptionState.throwDOMException( | 641 exceptionState.throwDOMException( |
| 632 InvalidAccessError, | 642 InvalidAccessError, |
| 633 "Synchronous requests are disabled for this page."); | 643 "Synchronous requests are disabled for this page."); |
| 634 return; | 644 return; |
| 635 } | 645 } |
| 636 | 646 |
| 637 // Newer functionality is not available to synchronous requests in window co ntexts, as a spec-mandated | 647 // Newer functionality is not available to synchronous requests in window |
| 638 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality. | 648 // contexts, as a spec-mandated attempt to discourage synchronous XHR use. |
| 649 // responseType is one such piece of functionality. | |
| 639 if (m_responseTypeCode != ResponseTypeDefault) { | 650 if (m_responseTypeCode != ResponseTypeDefault) { |
| 640 exceptionState.throwDOMException( | 651 exceptionState.throwDOMException( |
| 641 InvalidAccessError, | 652 InvalidAccessError, |
| 642 "Synchronous requests from a document must not set a response type."); | 653 "Synchronous requests from a document must not set a response type."); |
| 643 return; | 654 return; |
| 644 } | 655 } |
| 645 | 656 |
| 646 // Similarly, timeouts are disabled for synchronous requests as well. | 657 // Similarly, timeouts are disabled for synchronous requests as well. |
| 647 if (m_timeoutMilliseconds > 0) { | 658 if (m_timeoutMilliseconds > 0) { |
| 648 exceptionState.throwDOMException( | 659 exceptionState.throwDOMException( |
| 649 InvalidAccessError, "Synchronous requests must not set a timeout."); | 660 InvalidAccessError, "Synchronous requests must not set a timeout."); |
| 650 return; | 661 return; |
| 651 } | 662 } |
| 652 | 663 |
| 653 // Here we just warn that firing sync XHR's may affect responsiveness. | 664 // Here we just warn that firing sync XHR's may affect responsiveness. |
| 654 // Eventually sync xhr will be deprecated and an "InvalidAccessError" except ion thrown. | 665 // Eventually sync xhr will be deprecated and an "InvalidAccessError" |
| 666 // exception thrown. | |
| 655 // Refer : https://xhr.spec.whatwg.org/#sync-warning | 667 // Refer : https://xhr.spec.whatwg.org/#sync-warning |
| 656 // Use count for XHR synchronous requests on main thread only. | 668 // Use count for XHR synchronous requests on main thread only. |
| 657 if (!document()->processingBeforeUnload()) | 669 if (!document()->processingBeforeUnload()) |
| 658 Deprecation::countDeprecation( | 670 Deprecation::countDeprecation( |
| 659 getExecutionContext(), | 671 getExecutionContext(), |
| 660 UseCounter::XMLHttpRequestSynchronousInNonWorkerOutsideBeforeUnload); | 672 UseCounter::XMLHttpRequestSynchronousInNonWorkerOutsideBeforeUnload); |
| 661 } | 673 } |
| 662 | 674 |
| 663 m_method = FetchUtils::normalizeMethod(method); | 675 m_method = FetchUtils::normalizeMethod(method); |
| 664 | 676 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 if (!m_async) { | 933 if (!m_async) { |
| 922 throwForLoadFailureIfNeeded( | 934 throwForLoadFailureIfNeeded( |
| 923 exceptionState, "'GET' is the only method allowed for 'blob:' URLs."); | 935 exceptionState, "'GET' is the only method allowed for 'blob:' URLs."); |
| 924 } | 936 } |
| 925 return; | 937 return; |
| 926 } | 938 } |
| 927 | 939 |
| 928 DCHECK(getExecutionContext()); | 940 DCHECK(getExecutionContext()); |
| 929 ExecutionContext& executionContext = *getExecutionContext(); | 941 ExecutionContext& executionContext = *getExecutionContext(); |
| 930 | 942 |
| 931 // The presence of upload event listeners forces us to use preflighting becaus e POSTing to an URL that does not | 943 // The presence of upload event listeners forces us to use preflighting |
| 932 // permit cross origin requests should look exactly like POSTing to an URL tha t does not respond at all. | 944 // because POSTing to an URL that does not permit cross origin requests should |
| 945 // look exactly like POSTing to an URL that does not respond at all. | |
| 933 // Also, only async requests support upload progress events. | 946 // Also, only async requests support upload progress events. |
| 934 bool uploadEvents = false; | 947 bool uploadEvents = false; |
| 935 if (m_async) { | 948 if (m_async) { |
| 936 InspectorInstrumentation::asyncTaskScheduled( | 949 InspectorInstrumentation::asyncTaskScheduled( |
| 937 &executionContext, "XMLHttpRequest.send", this, true); | 950 &executionContext, "XMLHttpRequest.send", this, true); |
| 938 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); | 951 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); |
| 939 if (httpBody && m_upload) { | 952 if (httpBody && m_upload) { |
| 940 uploadEvents = m_upload->hasEventListeners(); | 953 uploadEvents = m_upload->hasEventListeners(); |
| 941 m_upload->dispatchEvent( | 954 m_upload->dispatchEvent( |
| 942 ProgressEvent::create(EventTypeNames::loadstart, false, 0, 0)); | 955 ProgressEvent::create(EventTypeNames::loadstart, false, 0, 0)); |
| 943 } | 956 } |
| 944 } | 957 } |
| 945 | 958 |
| 946 m_sameOriginRequest = getSecurityOrigin()->canRequestNoSuborigin(m_url); | 959 m_sameOriginRequest = getSecurityOrigin()->canRequestNoSuborigin(m_url); |
| 947 | 960 |
| 948 if (!m_sameOriginRequest && m_includeCredentials) | 961 if (!m_sameOriginRequest && m_includeCredentials) |
| 949 UseCounter::count(&executionContext, | 962 UseCounter::count(&executionContext, |
| 950 UseCounter::XMLHttpRequestCrossOriginWithCredentials); | 963 UseCounter::XMLHttpRequestCrossOriginWithCredentials); |
| 951 | 964 |
| 952 // We also remember whether upload events should be allowed for this request i n case the upload listeners are | 965 // We also remember whether upload events should be allowed for this request |
| 953 // added after the request is started. | 966 // in case the upload listeners are added after the request is started. |
| 954 m_uploadEventsAllowed = | 967 m_uploadEventsAllowed = |
| 955 m_sameOriginRequest || uploadEvents || | 968 m_sameOriginRequest || uploadEvents || |
| 956 !FetchUtils::isSimpleRequest(m_method, m_requestHeaders); | 969 !FetchUtils::isSimpleRequest(m_method, m_requestHeaders); |
| 957 | 970 |
| 958 ResourceRequest request(m_url); | 971 ResourceRequest request(m_url); |
| 959 request.setHTTPMethod(m_method); | 972 request.setHTTPMethod(m_method); |
| 960 request.setRequestContext(WebURLRequest::RequestContextXMLHttpRequest); | 973 request.setRequestContext(WebURLRequest::RequestContextXMLHttpRequest); |
| 961 request.setFetchCredentialsMode( | 974 request.setFetchCredentialsMode( |
| 962 m_includeCredentials ? WebURLRequest::FetchCredentialsModeInclude | 975 m_includeCredentials ? WebURLRequest::FetchCredentialsModeInclude |
| 963 : WebURLRequest::FetchCredentialsModeSameOrigin); | 976 : WebURLRequest::FetchCredentialsModeSameOrigin); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1230 // the end here. | 1243 // the end here. |
| 1231 DCHECK(m_error); | 1244 DCHECK(m_error); |
| 1232 changeState(kDone); | 1245 changeState(kDone); |
| 1233 | 1246 |
| 1234 if (!m_uploadComplete) { | 1247 if (!m_uploadComplete) { |
| 1235 m_uploadComplete = true; | 1248 m_uploadComplete = true; |
| 1236 if (m_upload && m_uploadEventsAllowed) | 1249 if (m_upload && m_uploadEventsAllowed) |
| 1237 m_upload->handleRequestError(type); | 1250 m_upload->handleRequestError(type); |
| 1238 } | 1251 } |
| 1239 | 1252 |
| 1240 // Note: The below event dispatch may be called while |hasPendingActivity() == false|, | 1253 // Note: The below event dispatch may be called while |hasPendingActivity() == |
| 1241 // when |handleRequestError| is called after |internalAbort()|. | 1254 // false|, when |handleRequestError| is called after |internalAbort()|. This |
|
jbroman
2016/10/04 19:56:51
ditto
| |
| 1242 // This is safe, however, as |this| will be kept alive from a strong ref |Even t::m_target|. | 1255 // is safe, however, as |this| will be kept alive from a strong ref |
| 1256 // |Event::m_target|. | |
| 1243 dispatchProgressEvent(EventTypeNames::progress, receivedLength, | 1257 dispatchProgressEvent(EventTypeNames::progress, receivedLength, |
| 1244 expectedLength); | 1258 expectedLength); |
| 1245 dispatchProgressEvent(type, receivedLength, expectedLength); | 1259 dispatchProgressEvent(type, receivedLength, expectedLength); |
| 1246 dispatchProgressEvent(EventTypeNames::loadend, receivedLength, | 1260 dispatchProgressEvent(EventTypeNames::loadend, receivedLength, |
| 1247 expectedLength); | 1261 expectedLength); |
| 1248 } | 1262 } |
| 1249 | 1263 |
| 1250 void XMLHttpRequest::overrideMimeType(const AtomicString& mimeType, | 1264 void XMLHttpRequest::overrideMimeType(const AtomicString& mimeType, |
| 1251 ExceptionState& exceptionState) { | 1265 ExceptionState& exceptionState) { |
| 1252 if (m_state == kLoading || m_state == kDone) { | 1266 if (m_state == kLoading || m_state == kDone) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1442 if (!m_response.httpStatusText().isNull()) | 1456 if (!m_response.httpStatusText().isNull()) |
| 1443 return m_response.httpStatusText(); | 1457 return m_response.httpStatusText(); |
| 1444 | 1458 |
| 1445 return String(); | 1459 return String(); |
| 1446 } | 1460 } |
| 1447 | 1461 |
| 1448 void XMLHttpRequest::didFail(const ResourceError& error) { | 1462 void XMLHttpRequest::didFail(const ResourceError& error) { |
| 1449 NETWORK_DVLOG(1) << this << " didFail()"; | 1463 NETWORK_DVLOG(1) << this << " didFail()"; |
| 1450 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); | 1464 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); |
| 1451 | 1465 |
| 1452 // If we are already in an error state, for instance we called abort(), bail o ut early. | 1466 // If we are already in an error state, for instance we called abort(), bail |
| 1467 // out early. | |
| 1453 if (m_error) | 1468 if (m_error) |
| 1454 return; | 1469 return; |
| 1455 | 1470 |
| 1456 if (error.isCancellation()) { | 1471 if (error.isCancellation()) { |
| 1457 handleDidCancel(); | 1472 handleDidCancel(); |
| 1458 return; | 1473 return; |
| 1459 } | 1474 } |
| 1460 | 1475 |
| 1461 if (error.isTimeout()) { | 1476 if (error.isTimeout()) { |
| 1462 handleDidTimeout(); | 1477 handleDidTimeout(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1496 // but the user changed the response type after that. Hence we need to | 1511 // but the user changed the response type after that. Hence we need to |
| 1497 // read the response data and provide it to this object. | 1512 // read the response data and provide it to this object. |
| 1498 m_blobLoader = BlobLoader::create(this, createBlobDataHandleFromResponse()); | 1513 m_blobLoader = BlobLoader::create(this, createBlobDataHandleFromResponse()); |
| 1499 } else { | 1514 } else { |
| 1500 didFinishLoadingInternal(); | 1515 didFinishLoadingInternal(); |
| 1501 } | 1516 } |
| 1502 } | 1517 } |
| 1503 | 1518 |
| 1504 void XMLHttpRequest::didFinishLoadingInternal() { | 1519 void XMLHttpRequest::didFinishLoadingInternal() { |
| 1505 if (m_responseDocumentParser) { | 1520 if (m_responseDocumentParser) { |
| 1506 // |DocumentParser::finish()| tells the parser that we have reached end of t he data. | 1521 // |DocumentParser::finish()| tells the parser that we have reached end of |
| 1507 // When using |HTMLDocumentParser|, which works asynchronously, we do not ha ve the | 1522 // the data. When using |HTMLDocumentParser|, which works asynchronously, |
|
jbroman
2016/10/04 19:56:51
ditto
| |
| 1508 // complete document just after the |DocumentParser::finish()| call. | 1523 // we do not have the complete document just after the |
| 1509 // Wait for the parser to call us back in |notifyParserStopped| to progress state. | 1524 // |DocumentParser::finish()| call. Wait for the parser to call us back in |
| 1525 // |notifyParserStopped| to progress state. | |
| 1510 m_responseDocumentParser->finish(); | 1526 m_responseDocumentParser->finish(); |
| 1511 DCHECK(m_responseDocument); | 1527 DCHECK(m_responseDocument); |
| 1512 return; | 1528 return; |
| 1513 } | 1529 } |
| 1514 | 1530 |
| 1515 if (m_decoder) { | 1531 if (m_decoder) { |
| 1516 auto text = m_decoder->flush(); | 1532 auto text = m_decoder->flush(); |
| 1517 if (!text.isEmpty() && !m_responseTextOverflow) { | 1533 if (!text.isEmpty() && !m_responseTextOverflow) { |
| 1518 m_responseText = m_responseText.concatenateWith(text); | 1534 m_responseText = m_responseText.concatenateWith(text); |
| 1519 m_responseTextOverflow = m_responseText.isEmpty(); | 1535 m_responseTextOverflow = m_responseText.isEmpty(); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1840 visitor->traceWrappers(m_responseLegacyStream); | 1856 visitor->traceWrappers(m_responseLegacyStream); |
| 1841 visitor->traceWrappers(m_responseDocument); | 1857 visitor->traceWrappers(m_responseDocument); |
| 1842 visitor->traceWrappers(m_responseArrayBuffer); | 1858 visitor->traceWrappers(m_responseArrayBuffer); |
| 1843 } | 1859 } |
| 1844 | 1860 |
| 1845 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { | 1861 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { |
| 1846 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); | 1862 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); |
| 1847 } | 1863 } |
| 1848 | 1864 |
| 1849 } // namespace blink | 1865 } // namespace blink |
| OLD | NEW |