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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 if (!internalAbort()) |
541 return; | 541 return; |
542 | 542 |
543 State previousState = m_state; | 543 State previousState = m_state; |
544 m_state = UNSENT; | 544 m_state = UNSENT; |
545 m_error = false; | 545 m_error = false; |
546 m_uploadComplete = false; | 546 m_uploadComplete = false; |
547 | 547 |
548 // clear stuff from possible previous load | |
549 clearResponse(); | |
550 clearRequest(); | |
551 | |
552 ASSERT(m_state == UNSENT); | 548 ASSERT(m_state == UNSENT); |
yhirano
2014/08/21 11:23:09
We don't need this assertion: it's too obvious.
tyoshino (SeeGerritForStatus)
2014/08/21 14:14:58
Done.
| |
553 | 549 |
554 if (!isValidHTTPToken(method)) { | 550 if (!isValidHTTPToken(method)) { |
555 exceptionState.throwDOMException(SyntaxError, "'" + method + "' is not a valid HTTP method."); | 551 exceptionState.throwDOMException(SyntaxError, "'" + method + "' is not a valid HTTP method."); |
556 return; | 552 return; |
557 } | 553 } |
558 | 554 |
559 if (FetchUtils::isForbiddenMethod(method)) { | 555 if (FetchUtils::isForbiddenMethod(method)) { |
560 exceptionState.throwSecurityError("'" + method + "' HTTP method is unsup ported."); | 556 exceptionState.throwSecurityError("'" + method + "' HTTP method is unsup ported."); |
561 return; | 557 return; |
562 } | 558 } |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 | 887 |
892 bool sendFlag = m_loader; | 888 bool sendFlag = m_loader; |
893 | 889 |
894 // Response is cleared next, save needed progress event data. | 890 // Response is cleared next, save needed progress event data. |
895 long long expectedLength = m_response.expectedContentLength(); | 891 long long expectedLength = m_response.expectedContentLength(); |
896 long long receivedLength = m_receivedLength; | 892 long long receivedLength = m_receivedLength; |
897 | 893 |
898 if (!internalAbort()) | 894 if (!internalAbort()) |
899 return; | 895 return; |
900 | 896 |
901 clearResponse(); | |
902 | |
903 // Clear headers as required by the spec | |
904 m_requestHeaders.clear(); | |
905 | |
906 if (!((m_state <= OPENED && !sendFlag) || m_state == DONE)) { | 897 if (!((m_state <= OPENED && !sendFlag) || m_state == DONE)) { |
907 ASSERT(!m_loader); | 898 ASSERT(!m_loader); |
908 handleRequestError(0, EventTypeNames::abort, receivedLength, expectedLen gth); | 899 handleRequestError(0, EventTypeNames::abort, receivedLength, expectedLen gth); |
909 } | 900 } |
910 m_state = UNSENT; | 901 m_state = UNSENT; |
911 } | 902 } |
912 | 903 |
913 void XMLHttpRequest::clearVariablesForLoading() | 904 void XMLHttpRequest::clearVariablesForLoading() |
914 { | 905 { |
915 m_decoder.clear(); | 906 m_decoder.clear(); |
(...skipping 12 matching lines...) Expand all Loading... | |
928 if (m_responseLegacyStream && m_state != DONE) | 919 if (m_responseLegacyStream && m_state != DONE) |
929 m_responseLegacyStream->abort(); | 920 m_responseLegacyStream->abort(); |
930 | 921 |
931 if (m_responseStream) { | 922 if (m_responseStream) { |
932 // When the stream is already closed (including canceled from the | 923 // When the stream is already closed (including canceled from the |
933 // user), |error| does nothing. | 924 // user), |error| does nothing. |
934 // FIXME: Create a more specific error. | 925 // FIXME: Create a more specific error. |
935 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort")); | 926 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort")); |
936 } | 927 } |
937 | 928 |
929 clearResponse(); | |
930 clearRequest(); | |
yhirano
2014/08/21 11:23:09
Doesn't Moving clearing code beyond loader->cancel
tyoshino (SeeGerritForStatus)
2014/08/21 12:19:48
If internalAbort() returned true, it means send()
tyoshino (SeeGerritForStatus)
2014/08/21 14:14:58
And, as we're clearing the variables before cancel
| |
931 | |
938 if (!m_loader) | 932 if (!m_loader) |
939 return true; | 933 return true; |
940 | 934 |
941 // Cancelling the ThreadableLoader m_loader may result in calling | 935 // Cancelling the ThreadableLoader m_loader may result in calling |
942 // window.onload synchronously. If such an onload handler contains open() | 936 // window.onload synchronously. If such an onload handler contains open() |
943 // call on the same XMLHttpRequest object, reentry happens. | 937 // call on the same XMLHttpRequest object, reentry happens. |
944 // | 938 // |
945 // If, window.onload contains open() and send(), m_loader will be set to | 939 // 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, | 940 // non 0 value. So, we cannot continue the outer open(). In such case, |
947 // just abort the outer open() by returning false. | 941 // just abort the outer open() by returning false. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
983 // this only when we clear the response holder variables above. | 977 // this only when we clear the response holder variables above. |
984 m_binaryResponseBuilder.clear(); | 978 m_binaryResponseBuilder.clear(); |
985 m_responseArrayBuffer.clear(); | 979 m_responseArrayBuffer.clear(); |
986 } | 980 } |
987 | 981 |
988 void XMLHttpRequest::clearRequest() | 982 void XMLHttpRequest::clearRequest() |
989 { | 983 { |
990 m_requestHeaders.clear(); | 984 m_requestHeaders.clear(); |
991 } | 985 } |
992 | 986 |
993 void XMLHttpRequest::handleDidFailGeneric() | |
994 { | |
995 clearResponse(); | |
996 clearRequest(); | |
997 | |
998 m_error = true; | |
999 } | |
1000 | |
1001 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type, long long r eceivedLength, long long expectedLength) | 987 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type, long long r eceivedLength, long long expectedLength) |
1002 { | 988 { |
1003 bool lengthComputable = expectedLength > 0 && receivedLength <= expectedLeng th; | 989 bool lengthComputable = expectedLength > 0 && receivedLength <= expectedLeng th; |
1004 unsigned long long loaded = receivedLength >= 0 ? static_cast<unsigned long long>(receivedLength) : 0; | 990 unsigned long long loaded = receivedLength >= 0 ? static_cast<unsigned long long>(receivedLength) : 0; |
1005 unsigned long long total = lengthComputable ? static_cast<unsigned long long >(expectedLength) : 0; | 991 unsigned long long total = lengthComputable ? static_cast<unsigned long long >(expectedLength) : 0; |
1006 | 992 |
1007 m_progressEventThrottle.dispatchProgressEvent(type, lengthComputable, loaded , total); | 993 m_progressEventThrottle.dispatchProgressEvent(type, lengthComputable, loaded , total); |
1008 | 994 |
1009 if (type == EventTypeNames::loadend) | 995 if (type == EventTypeNames::loadend) |
1010 InspectorInstrumentation::didDispatchXHRLoadendEvent(executionContext(), this); | 996 InspectorInstrumentation::didDispatchXHRLoadendEvent(executionContext(), this); |
1011 } | 997 } |
1012 | 998 |
1013 void XMLHttpRequest::dispatchProgressEventFromSnapshot(const AtomicString& type) | 999 void XMLHttpRequest::dispatchProgressEventFromSnapshot(const AtomicString& type) |
1014 { | 1000 { |
1015 dispatchProgressEvent(type, m_receivedLength, m_response.expectedContentLeng th()); | 1001 dispatchProgressEvent(type, m_receivedLength, m_response.expectedContentLeng th()); |
1016 } | 1002 } |
1017 | 1003 |
1018 void XMLHttpRequest::handleNetworkError() | 1004 void XMLHttpRequest::handleNetworkError() |
1019 { | 1005 { |
1020 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); | 1006 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); |
1021 | 1007 |
1022 // Response is cleared next, save needed progress event data. | 1008 // Response is cleared next, save needed progress event data. |
1023 long long expectedLength = m_response.expectedContentLength(); | 1009 long long expectedLength = m_response.expectedContentLength(); |
1024 long long receivedLength = m_receivedLength; | 1010 long long receivedLength = m_receivedLength; |
1025 | 1011 |
1026 if (!internalAbort()) | 1012 if (!internalAbort()) |
1027 return; | 1013 return; |
1028 | 1014 |
1029 handleDidFailGeneric(); | |
1030 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength); | 1015 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength); |
1031 } | 1016 } |
1032 | 1017 |
1033 void XMLHttpRequest::handleDidCancel() | 1018 void XMLHttpRequest::handleDidCancel() |
1034 { | 1019 { |
1035 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); | 1020 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); |
1036 | 1021 |
1037 // Response is cleared next, save needed progress event data. | 1022 // Response is cleared next, save needed progress event data. |
1038 long long expectedLength = m_response.expectedContentLength(); | 1023 long long expectedLength = m_response.expectedContentLength(); |
1039 long long receivedLength = m_receivedLength; | 1024 long long receivedLength = m_receivedLength; |
1040 | 1025 |
1041 handleDidFailGeneric(); | 1026 if (!internalAbort()) |
1027 return; | |
1028 | |
1042 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength); | 1029 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength); |
1043 } | 1030 } |
1044 | 1031 |
1045 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength) | 1032 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength) |
1046 { | 1033 { |
1047 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this); | 1034 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this); |
1048 | 1035 |
1049 // The request error steps for event 'type' and exception 'exceptionCode'. | 1036 // The request error steps for event 'type' and exception 'exceptionCode'. |
1050 | 1037 |
1051 if (!m_async && exceptionCode) { | 1038 if (!m_async && exceptionCode) { |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1451 { | 1438 { |
1452 WTF_LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this); | 1439 WTF_LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this); |
1453 | 1440 |
1454 // Response is cleared next, save needed progress event data. | 1441 // Response is cleared next, save needed progress event data. |
1455 long long expectedLength = m_response.expectedContentLength(); | 1442 long long expectedLength = m_response.expectedContentLength(); |
1456 long long receivedLength = m_receivedLength; | 1443 long long receivedLength = m_receivedLength; |
1457 | 1444 |
1458 if (!internalAbort()) | 1445 if (!internalAbort()) |
1459 return; | 1446 return; |
1460 | 1447 |
1461 handleDidFailGeneric(); | |
1462 handleRequestError(TimeoutError, EventTypeNames::timeout, receivedLength, ex pectedLength); | 1448 handleRequestError(TimeoutError, EventTypeNames::timeout, receivedLength, ex pectedLength); |
1463 } | 1449 } |
1464 | 1450 |
1465 void XMLHttpRequest::suspend() | 1451 void XMLHttpRequest::suspend() |
1466 { | 1452 { |
1467 m_progressEventThrottle.suspend(); | 1453 m_progressEventThrottle.suspend(); |
1468 } | 1454 } |
1469 | 1455 |
1470 void XMLHttpRequest::resume() | 1456 void XMLHttpRequest::resume() |
1471 { | 1457 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1508 visitor->trace(m_responseStream); | 1494 visitor->trace(m_responseStream); |
1509 visitor->trace(m_streamSource); | 1495 visitor->trace(m_streamSource); |
1510 visitor->trace(m_responseDocument); | 1496 visitor->trace(m_responseDocument); |
1511 visitor->trace(m_responseDocumentParser); | 1497 visitor->trace(m_responseDocumentParser); |
1512 visitor->trace(m_progressEventThrottle); | 1498 visitor->trace(m_progressEventThrottle); |
1513 visitor->trace(m_upload); | 1499 visitor->trace(m_upload); |
1514 XMLHttpRequestEventTarget::trace(visitor); | 1500 XMLHttpRequestEventTarget::trace(visitor); |
1515 } | 1501 } |
1516 | 1502 |
1517 } // namespace blink | 1503 } // namespace blink |
OLD | NEW |