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