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 |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 | 530 |
| 531 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, Exception State& exceptionState) | 531 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, Exception State& exceptionState) |
| 532 { | 532 { |
| 533 open(method, url, true, exceptionState); | 533 open(method, url, true, exceptionState); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn c, ExceptionState& exceptionState) | 536 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn c, ExceptionState& exceptionState) |
| 537 { | 537 { |
| 538 WTF_LOG(Network, "XMLHttpRequest %p open('%s', '%s', %d)", this, method.utf8 ().data(), url.elidedString().utf8().data(), async); | 538 WTF_LOG(Network, "XMLHttpRequest %p open('%s', '%s', %d)", this, method.utf8 ().data(), url.elidedString().utf8().data(), async); |
| 539 | 539 |
| 540 if (!internalAbort()) | 540 internalAbort(); |
| 541 if (!cancelLoader()) | |
| 541 return; | 542 return; |
| 542 | 543 |
| 543 State previousState = m_state; | 544 State previousState = m_state; |
| 544 m_state = UNSENT; | 545 m_state = UNSENT; |
| 545 m_error = false; | 546 m_error = false; |
| 546 m_uploadComplete = false; | 547 m_uploadComplete = false; |
| 547 | 548 |
| 548 // clear stuff from possible previous load | 549 // clear stuff from possible previous load |
| 549 clearResponse(); | 550 clearResponse(); |
| 550 clearRequest(); | 551 clearRequest(); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 void XMLHttpRequest::abort() | 889 void XMLHttpRequest::abort() |
| 889 { | 890 { |
| 890 WTF_LOG(Network, "XMLHttpRequest %p abort()", this); | 891 WTF_LOG(Network, "XMLHttpRequest %p abort()", this); |
| 891 | 892 |
| 892 bool sendFlag = m_loader; | 893 bool sendFlag = m_loader; |
| 893 | 894 |
| 894 // Response is cleared next, save needed progress event data. | 895 // Response is cleared next, save needed progress event data. |
| 895 long long expectedLength = m_response.expectedContentLength(); | 896 long long expectedLength = m_response.expectedContentLength(); |
| 896 long long receivedLength = m_receivedLength; | 897 long long receivedLength = m_receivedLength; |
| 897 | 898 |
| 898 if (!internalAbort()) | 899 internalAbort(); |
| 900 if (!cancelLoader()) | |
| 899 return; | 901 return; |
| 900 | 902 |
| 901 clearResponse(); | 903 clearResponse(); |
| 902 | 904 |
| 903 // Clear headers as required by the spec | 905 // Clear headers as required by the spec |
| 904 m_requestHeaders.clear(); | 906 m_requestHeaders.clear(); |
| 905 | 907 |
| 906 if (!((m_state <= OPENED && !sendFlag) || m_state == DONE)) { | 908 if (!((m_state <= OPENED && !sendFlag) || m_state == DONE)) { |
| 907 ASSERT(!m_loader); | 909 ASSERT(!m_loader); |
| 908 handleRequestError(0, EventTypeNames::abort, receivedLength, expectedLen gth); | 910 handleRequestError(0, EventTypeNames::abort, receivedLength, expectedLen gth); |
| 909 } | 911 } |
| 910 m_state = UNSENT; | 912 m_state = UNSENT; |
| 911 } | 913 } |
| 912 | 914 |
| 913 void XMLHttpRequest::clearVariablesForLoading() | 915 void XMLHttpRequest::clearVariablesForLoading() |
| 914 { | 916 { |
| 915 m_decoder.clear(); | 917 m_decoder.clear(); |
| 916 | 918 |
| 917 m_finalResponseCharset = String(); | 919 m_finalResponseCharset = String(); |
| 918 } | 920 } |
| 919 | 921 |
| 920 bool XMLHttpRequest::internalAbort() | 922 void XMLHttpRequest::internalAbort() |
| 921 { | 923 { |
| 922 m_error = true; | 924 m_error = true; |
| 923 | 925 |
| 924 clearVariablesForLoading(); | 926 clearVariablesForLoading(); |
| 925 | 927 |
| 926 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this); | 928 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this); |
| 927 | 929 |
| 928 if (m_responseLegacyStream && m_state != DONE) | 930 if (m_responseLegacyStream && m_state != DONE) |
| 929 m_responseLegacyStream->abort(); | 931 m_responseLegacyStream->abort(); |
| 930 | 932 |
| 931 if (m_responseStream) { | 933 if (m_responseStream) { |
| 932 // When the stream is already closed (including canceled from the | 934 // When the stream is already closed (including canceled from the |
| 933 // user), |error| does nothing. | 935 // user), |error| does nothing. |
| 934 // FIXME: Create a more specific error. | 936 // FIXME: Create a more specific error. |
| 935 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort")); | 937 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort")); |
| 936 } | 938 } |
| 939 } | |
| 937 | 940 |
| 941 bool XMLHttpRequest::cancelLoader() | |
| 942 { | |
|
yhirano
2014/08/21 06:49:20
ASSERT(m_error) here?
| |
| 938 if (!m_loader) | 943 if (!m_loader) |
| 939 return true; | 944 return true; |
| 940 | 945 |
| 941 // Cancelling the ThreadableLoader m_loader may result in calling | 946 // Cancelling the ThreadableLoader m_loader may result in calling |
| 942 // window.onload synchronously. If such an onload handler contains open() | 947 // window.onload synchronously. If such an onload handler contains open() |
| 943 // call on the same XMLHttpRequest object, reentry happens. | 948 // call on the same XMLHttpRequest object, reentry happens. |
| 944 // | 949 // |
| 945 // If, window.onload contains open() and send(), m_loader will be set to | 950 // If, window.onload contains open() and send(), m_loader will be set to |
| 946 // non 0 value. So, we cannot continue the outer open(). In such case, | 951 // non 0 value. So, we cannot continue the outer open(). In such case, |
| 947 // just abort the outer open() by returning false. | 952 // just abort the outer open() by returning false. |
| 948 RefPtrWillBeRawPtr<XMLHttpRequest> protect(this); | 953 RefPtrWillBeRawPtr<XMLHttpRequest> protect(this); |
| 949 RefPtr<ThreadableLoader> loader = m_loader.release(); | 954 RefPtr<ThreadableLoader> loader = m_loader.release(); |
| 950 loader->cancel(); | 955 loader->cancel(); |
| 951 | 956 |
| 952 // If abort() called internalAbort() and a nested open() ended up | 957 // If abort() called cancelLoader() and a nested open() ended up |
|
yhirano
2014/08/21 06:49:20
I'm not sure if this split is good. The latter hal
tyoshino (SeeGerritForStatus)
2014/08/21 07:06:31
Call of abort() is just one of possible scenarios
yhirano
2014/08/21 08:01:36
I'm a bit confused.
Are you going to call |cancelL
tyoshino (SeeGerritForStatus)
2014/08/21 08:06:51
The latter. See the newly added FIXME below.
I th
| |
| 953 // clearing the error flag, but didn't send(), make sure the error | 958 // clearing the error flag, but didn't send(), make sure the error |
| 954 // flag is still set. | 959 // flag is still set. |
| 955 bool newLoadStarted = hasPendingActivity(); | 960 bool newLoadStarted = hasPendingActivity(); |
| 956 if (!newLoadStarted) | 961 if (!newLoadStarted) |
| 957 m_error = true; | 962 m_error = true; |
| 958 | 963 |
| 959 return !newLoadStarted; | 964 return !newLoadStarted; |
| 960 } | 965 } |
| 961 | 966 |
| 962 void XMLHttpRequest::clearResponse() | 967 void XMLHttpRequest::clearResponse() |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 } | 1021 } |
| 1017 | 1022 |
| 1018 void XMLHttpRequest::handleNetworkError() | 1023 void XMLHttpRequest::handleNetworkError() |
| 1019 { | 1024 { |
| 1020 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); | 1025 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); |
| 1021 | 1026 |
| 1022 // Response is cleared next, save needed progress event data. | 1027 // Response is cleared next, save needed progress event data. |
| 1023 long long expectedLength = m_response.expectedContentLength(); | 1028 long long expectedLength = m_response.expectedContentLength(); |
| 1024 long long receivedLength = m_receivedLength; | 1029 long long receivedLength = m_receivedLength; |
| 1025 | 1030 |
| 1026 if (!internalAbort()) | 1031 internalAbort(); |
| 1032 if (!cancelLoader()) | |
| 1027 return; | 1033 return; |
| 1028 | 1034 |
| 1029 handleDidFailGeneric(); | 1035 handleDidFailGeneric(); |
| 1030 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength); | 1036 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength); |
| 1031 } | 1037 } |
| 1032 | 1038 |
| 1033 void XMLHttpRequest::handleDidCancel() | 1039 void XMLHttpRequest::handleDidCancel() |
| 1034 { | 1040 { |
| 1035 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); | 1041 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); |
| 1036 | 1042 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1059 // the end here. | 1065 // the end here. |
| 1060 ASSERT(m_error); | 1066 ASSERT(m_error); |
| 1061 changeState(DONE); | 1067 changeState(DONE); |
| 1062 | 1068 |
| 1063 if (!m_uploadComplete) { | 1069 if (!m_uploadComplete) { |
| 1064 m_uploadComplete = true; | 1070 m_uploadComplete = true; |
| 1065 if (m_upload && m_uploadEventsAllowed) | 1071 if (m_upload && m_uploadEventsAllowed) |
| 1066 m_upload->handleRequestError(type); | 1072 m_upload->handleRequestError(type); |
| 1067 } | 1073 } |
| 1068 | 1074 |
| 1069 // Note: The below event dispatch may be called while |hasPendingActivity() == false|, | 1075 // Note: The below event dispatch may be called while |hasPendingActivity() == false|, |
|
yhirano
2014/08/21 06:49:20
Please wrap the comment in 80 columns.
| |
| 1070 // when |handleRequestError| is called after |internalAbort()|. | 1076 // when |handleRequestError| is called after |cancelLoader()|. |
| 1071 // This is safe, however, as |this| will be kept alive from a strong ref |Ev ent::m_target|. | 1077 // This is safe, however, as |this| will be kept alive from a strong ref |Ev ent::m_target|. |
| 1072 dispatchProgressEvent(EventTypeNames::progress, receivedLength, expectedLeng th); | 1078 dispatchProgressEvent(EventTypeNames::progress, receivedLength, expectedLeng th); |
| 1073 dispatchProgressEvent(type, receivedLength, expectedLength); | 1079 dispatchProgressEvent(type, receivedLength, expectedLength); |
| 1074 dispatchProgressEvent(EventTypeNames::loadend, receivedLength, expectedLengt h); | 1080 dispatchProgressEvent(EventTypeNames::loadend, receivedLength, expectedLengt h); |
| 1075 } | 1081 } |
| 1076 | 1082 |
| 1077 void XMLHttpRequest::overrideMimeType(const AtomicString& mimeType, ExceptionSta te& exceptionState) | 1083 void XMLHttpRequest::overrideMimeType(const AtomicString& mimeType, ExceptionSta te& exceptionState) |
| 1078 { | 1084 { |
| 1079 if (m_state == LOADING || m_state == DONE) { | 1085 if (m_state == LOADING || m_state == DONE) { |
| 1080 exceptionState.throwDOMException(InvalidStateError, "MimeType cannot be overridden when the state is LOADING or DONE."); | 1086 exceptionState.throwDOMException(InvalidStateError, "MimeType cannot be overridden when the state is LOADING or DONE."); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1448 } | 1454 } |
| 1449 | 1455 |
| 1450 void XMLHttpRequest::handleDidTimeout() | 1456 void XMLHttpRequest::handleDidTimeout() |
| 1451 { | 1457 { |
| 1452 WTF_LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this); | 1458 WTF_LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this); |
| 1453 | 1459 |
| 1454 // Response is cleared next, save needed progress event data. | 1460 // Response is cleared next, save needed progress event data. |
| 1455 long long expectedLength = m_response.expectedContentLength(); | 1461 long long expectedLength = m_response.expectedContentLength(); |
| 1456 long long receivedLength = m_receivedLength; | 1462 long long receivedLength = m_receivedLength; |
| 1457 | 1463 |
| 1458 if (!internalAbort()) | 1464 internalAbort(); |
| 1465 // FIXME: It shouldn't be needed to call cancel() on m_loader. We just need | |
| 1466 // to clear it. Fix it but after investigating if there's the reentry issue | |
| 1467 // here, too. | |
| 1468 if (!cancelLoader()) | |
| 1459 return; | 1469 return; |
| 1460 | 1470 |
| 1461 handleDidFailGeneric(); | 1471 handleDidFailGeneric(); |
| 1462 handleRequestError(TimeoutError, EventTypeNames::timeout, receivedLength, ex pectedLength); | 1472 handleRequestError(TimeoutError, EventTypeNames::timeout, receivedLength, ex pectedLength); |
| 1463 } | 1473 } |
| 1464 | 1474 |
| 1465 void XMLHttpRequest::suspend() | 1475 void XMLHttpRequest::suspend() |
| 1466 { | 1476 { |
| 1467 m_progressEventThrottle.suspend(); | 1477 m_progressEventThrottle.suspend(); |
| 1468 } | 1478 } |
| 1469 | 1479 |
| 1470 void XMLHttpRequest::resume() | 1480 void XMLHttpRequest::resume() |
| 1471 { | 1481 { |
| 1472 m_progressEventThrottle.resume(); | 1482 m_progressEventThrottle.resume(); |
| 1473 } | 1483 } |
| 1474 | 1484 |
| 1475 void XMLHttpRequest::stop() | 1485 void XMLHttpRequest::stop() |
| 1476 { | 1486 { |
| 1477 internalAbort(); | 1487 internalAbort(); |
| 1488 cancelLoader(); | |
| 1478 } | 1489 } |
| 1479 | 1490 |
| 1480 bool XMLHttpRequest::hasPendingActivity() const | 1491 bool XMLHttpRequest::hasPendingActivity() const |
| 1481 { | 1492 { |
| 1482 // Neither this object nor the JavaScript wrapper should be deleted while | 1493 // Neither this object nor the JavaScript wrapper should be deleted while |
| 1483 // a request is in progress because we need to keep the listeners alive, | 1494 // a request is in progress because we need to keep the listeners alive, |
| 1484 // and they are referenced by the JavaScript wrapper. | 1495 // and they are referenced by the JavaScript wrapper. |
| 1485 return m_loader; | 1496 return m_loader; |
| 1486 } | 1497 } |
| 1487 | 1498 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1507 visitor->trace(m_responseLegacyStream); | 1518 visitor->trace(m_responseLegacyStream); |
| 1508 visitor->trace(m_responseStream); | 1519 visitor->trace(m_responseStream); |
| 1509 visitor->trace(m_streamSource); | 1520 visitor->trace(m_streamSource); |
| 1510 visitor->trace(m_responseDocument); | 1521 visitor->trace(m_responseDocument); |
| 1511 visitor->trace(m_progressEventThrottle); | 1522 visitor->trace(m_progressEventThrottle); |
| 1512 visitor->trace(m_upload); | 1523 visitor->trace(m_upload); |
| 1513 XMLHttpRequestEventTarget::trace(visitor); | 1524 XMLHttpRequestEventTarget::trace(visitor); |
| 1514 } | 1525 } |
| 1515 | 1526 |
| 1516 } // namespace blink | 1527 } // namespace blink |
| OLD | NEW |