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

Side by Side Diff: Source/core/xml/XMLHttpRequest.cpp

Issue 490083002: [XHR] Move the code to clear variables to internalAbort() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 WTF_LOG(Network, "XMLHttpRequest %p open('%s', '%s', %d)", this, method.utf8 ().data(), url.elidedString().utf8().data(), async); 536 WTF_LOG(Network, "XMLHttpRequest %p open('%s', '%s', %d)", this, method.utf8 ().data(), url.elidedString().utf8().data(), async);
537 537
538 if (!internalAbort()) 538 if (!internalAbort())
539 return; 539 return;
540 540
541 State previousState = m_state; 541 State previousState = m_state;
542 m_state = UNSENT; 542 m_state = UNSENT;
543 m_error = false; 543 m_error = false;
544 m_uploadComplete = false; 544 m_uploadComplete = false;
545 545
546 // clear stuff from possible previous load
547 clearResponse();
548 clearRequest();
549
550 ASSERT(m_state == UNSENT);
551
552 if (!isValidHTTPToken(method)) { 546 if (!isValidHTTPToken(method)) {
553 exceptionState.throwDOMException(SyntaxError, "'" + method + "' is not a valid HTTP method."); 547 exceptionState.throwDOMException(SyntaxError, "'" + method + "' is not a valid HTTP method.");
554 return; 548 return;
555 } 549 }
556 550
557 if (FetchUtils::isForbiddenMethod(method)) { 551 if (FetchUtils::isForbiddenMethod(method)) {
558 exceptionState.throwSecurityError("'" + method + "' HTTP method is unsup ported."); 552 exceptionState.throwSecurityError("'" + method + "' HTTP method is unsup ported.");
559 return; 553 return;
560 } 554 }
561 555
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 883
890 bool sendFlag = m_loader; 884 bool sendFlag = m_loader;
891 885
892 // Response is cleared next, save needed progress event data. 886 // Response is cleared next, save needed progress event data.
893 long long expectedLength = m_response.expectedContentLength(); 887 long long expectedLength = m_response.expectedContentLength();
894 long long receivedLength = m_receivedLength; 888 long long receivedLength = m_receivedLength;
895 889
896 if (!internalAbort()) 890 if (!internalAbort())
897 return; 891 return;
898 892
899 clearResponse();
900
901 // Clear headers as required by the spec
902 m_requestHeaders.clear();
903
904 if (!((m_state <= OPENED && !sendFlag) || m_state == DONE)) { 893 if (!((m_state <= OPENED && !sendFlag) || m_state == DONE)) {
905 ASSERT(!m_loader); 894 ASSERT(!m_loader);
906 handleRequestError(0, EventTypeNames::abort, receivedLength, expectedLen gth); 895 handleRequestError(0, EventTypeNames::abort, receivedLength, expectedLen gth);
907 } 896 }
908 m_state = UNSENT; 897 m_state = UNSENT;
909 } 898 }
910 899
911 void XMLHttpRequest::clearVariablesForLoading() 900 void XMLHttpRequest::clearVariablesForLoading()
912 { 901 {
913 m_decoder.clear(); 902 m_decoder.clear();
(...skipping 23 matching lines...) Expand all
937 if (m_responseLegacyStream && m_state != DONE) 926 if (m_responseLegacyStream && m_state != DONE)
938 m_responseLegacyStream->abort(); 927 m_responseLegacyStream->abort();
939 928
940 if (m_responseStream) { 929 if (m_responseStream) {
941 // When the stream is already closed (including canceled from the 930 // When the stream is already closed (including canceled from the
942 // user), |error| does nothing. 931 // user), |error| does nothing.
943 // FIXME: Create a more specific error. 932 // FIXME: Create a more specific error.
944 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort")); 933 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort"));
945 } 934 }
946 935
936 clearResponse();
937 clearRequest();
938
947 if (!m_loader) 939 if (!m_loader)
948 return true; 940 return true;
949 941
950 // Cancelling the ThreadableLoader m_loader may result in calling 942 // Cancelling the ThreadableLoader m_loader may result in calling
951 // window.onload synchronously. If such an onload handler contains open() 943 // window.onload synchronously. If such an onload handler contains open()
952 // call on the same XMLHttpRequest object, reentry happens. 944 // call on the same XMLHttpRequest object, reentry happens.
953 // 945 //
954 // If, window.onload contains open() and send(), m_loader will be set to 946 // If, window.onload contains open() and send(), m_loader will be set to
955 // non 0 value. So, we cannot continue the outer open(). In such case, 947 // non 0 value. So, we cannot continue the outer open(). In such case,
956 // just abort the outer open() by returning false. 948 // just abort the outer open() by returning false.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 // this only when we clear the response holder variables above. 983 // this only when we clear the response holder variables above.
992 m_binaryResponseBuilder.clear(); 984 m_binaryResponseBuilder.clear();
993 m_responseArrayBuffer.clear(); 985 m_responseArrayBuffer.clear();
994 } 986 }
995 987
996 void XMLHttpRequest::clearRequest() 988 void XMLHttpRequest::clearRequest()
997 { 989 {
998 m_requestHeaders.clear(); 990 m_requestHeaders.clear();
999 } 991 }
1000 992
1001 void XMLHttpRequest::handleDidFailGeneric()
1002 {
1003 clearResponse();
1004 clearRequest();
1005
1006 m_error = true;
1007 }
1008
1009 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type, long long r eceivedLength, long long expectedLength) 993 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type, long long r eceivedLength, long long expectedLength)
1010 { 994 {
1011 bool lengthComputable = expectedLength > 0 && receivedLength <= expectedLeng th; 995 bool lengthComputable = expectedLength > 0 && receivedLength <= expectedLeng th;
1012 unsigned long long loaded = receivedLength >= 0 ? static_cast<unsigned long long>(receivedLength) : 0; 996 unsigned long long loaded = receivedLength >= 0 ? static_cast<unsigned long long>(receivedLength) : 0;
1013 unsigned long long total = lengthComputable ? static_cast<unsigned long long >(expectedLength) : 0; 997 unsigned long long total = lengthComputable ? static_cast<unsigned long long >(expectedLength) : 0;
1014 998
1015 m_progressEventThrottle.dispatchProgressEvent(type, lengthComputable, loaded , total); 999 m_progressEventThrottle.dispatchProgressEvent(type, lengthComputable, loaded , total);
1016 1000
1017 if (type == EventTypeNames::loadend) 1001 if (type == EventTypeNames::loadend)
1018 InspectorInstrumentation::didDispatchXHRLoadendEvent(executionContext(), this); 1002 InspectorInstrumentation::didDispatchXHRLoadendEvent(executionContext(), this);
1019 } 1003 }
1020 1004
1021 void XMLHttpRequest::dispatchProgressEventFromSnapshot(const AtomicString& type) 1005 void XMLHttpRequest::dispatchProgressEventFromSnapshot(const AtomicString& type)
1022 { 1006 {
1023 dispatchProgressEvent(type, m_receivedLength, m_response.expectedContentLeng th()); 1007 dispatchProgressEvent(type, m_receivedLength, m_response.expectedContentLeng th());
1024 } 1008 }
1025 1009
1026 void XMLHttpRequest::handleNetworkError() 1010 void XMLHttpRequest::handleNetworkError()
1027 { 1011 {
1028 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); 1012 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this);
1029 1013
1030 // Response is cleared next, save needed progress event data. 1014 // Response is cleared next, save needed progress event data.
1031 long long expectedLength = m_response.expectedContentLength(); 1015 long long expectedLength = m_response.expectedContentLength();
1032 long long receivedLength = m_receivedLength; 1016 long long receivedLength = m_receivedLength;
1033 1017
1034 if (!internalAbort()) 1018 if (!internalAbort())
1035 return; 1019 return;
1036 1020
1037 handleDidFailGeneric();
1038 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength); 1021 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength);
1039 } 1022 }
1040 1023
1041 void XMLHttpRequest::handleDidCancel() 1024 void XMLHttpRequest::handleDidCancel()
1042 { 1025 {
1043 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); 1026 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this);
1044 1027
1045 // Response is cleared next, save needed progress event data. 1028 // Response is cleared next, save needed progress event data.
1046 long long expectedLength = m_response.expectedContentLength(); 1029 long long expectedLength = m_response.expectedContentLength();
1047 long long receivedLength = m_receivedLength; 1030 long long receivedLength = m_receivedLength;
1048 1031
1049 handleDidFailGeneric(); 1032 if (!internalAbort())
1033 return;
1034
1050 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength); 1035 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength);
1051 } 1036 }
1052 1037
1053 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength) 1038 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength)
1054 { 1039 {
1055 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this); 1040 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this);
1056 1041
1057 // The request error steps for event 'type' and exception 'exceptionCode'. 1042 // The request error steps for event 'type' and exception 'exceptionCode'.
1058 1043
1059 if (!m_async && exceptionCode) { 1044 if (!m_async && exceptionCode) {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 { 1475 {
1491 WTF_LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this); 1476 WTF_LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this);
1492 1477
1493 // Response is cleared next, save needed progress event data. 1478 // Response is cleared next, save needed progress event data.
1494 long long expectedLength = m_response.expectedContentLength(); 1479 long long expectedLength = m_response.expectedContentLength();
1495 long long receivedLength = m_receivedLength; 1480 long long receivedLength = m_receivedLength;
1496 1481
1497 if (!internalAbort()) 1482 if (!internalAbort())
1498 return; 1483 return;
1499 1484
1500 handleDidFailGeneric();
1501 handleRequestError(TimeoutError, EventTypeNames::timeout, receivedLength, ex pectedLength); 1485 handleRequestError(TimeoutError, EventTypeNames::timeout, receivedLength, ex pectedLength);
1502 } 1486 }
1503 1487
1504 void XMLHttpRequest::suspend() 1488 void XMLHttpRequest::suspend()
1505 { 1489 {
1506 m_progressEventThrottle.suspend(); 1490 m_progressEventThrottle.suspend();
1507 } 1491 }
1508 1492
1509 void XMLHttpRequest::resume() 1493 void XMLHttpRequest::resume()
1510 { 1494 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 visitor->trace(m_responseStream); 1531 visitor->trace(m_responseStream);
1548 visitor->trace(m_streamSource); 1532 visitor->trace(m_streamSource);
1549 visitor->trace(m_responseDocument); 1533 visitor->trace(m_responseDocument);
1550 visitor->trace(m_responseDocumentParser); 1534 visitor->trace(m_responseDocumentParser);
1551 visitor->trace(m_progressEventThrottle); 1535 visitor->trace(m_progressEventThrottle);
1552 visitor->trace(m_upload); 1536 visitor->trace(m_upload);
1553 XMLHttpRequestEventTarget::trace(visitor); 1537 XMLHttpRequestEventTarget::trace(visitor);
1554 } 1538 }
1555 1539
1556 } // namespace blink 1540 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698