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

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

Issue 663693003: Place RefPtr for protection not in internalAbort() but in its caller. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | 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 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 if (!m_loader) 1013 if (!m_loader)
1014 return true; 1014 return true;
1015 1015
1016 // Cancelling the ThreadableLoader m_loader may result in calling 1016 // Cancelling the ThreadableLoader m_loader may result in calling
1017 // window.onload synchronously. If such an onload handler contains open() 1017 // window.onload synchronously. If such an onload handler contains open()
1018 // call on the same XMLHttpRequest object, reentry happens. 1018 // call on the same XMLHttpRequest object, reentry happens.
1019 // 1019 //
1020 // If, window.onload contains open() and send(), m_loader will be set to 1020 // If, window.onload contains open() and send(), m_loader will be set to
1021 // non 0 value. So, we cannot continue the outer open(). In such case, 1021 // non 0 value. So, we cannot continue the outer open(). In such case,
1022 // just abort the outer open() by returning false. 1022 // just abort the outer open() by returning false.
1023 RefPtrWillBeRawPtr<XMLHttpRequest> protect(this);
1024 RefPtr<ThreadableLoader> loader = m_loader.release(); 1023 RefPtr<ThreadableLoader> loader = m_loader.release();
1025 loader->cancel(); 1024 loader->cancel();
1026 1025
1027 // If abort() called internalAbort() and a nested open() ended up 1026 // If abort() called internalAbort() and a nested open() ended up
1028 // clearing the error flag, but didn't send(), make sure the error 1027 // clearing the error flag, but didn't send(), make sure the error
1029 // flag is still set. 1028 // flag is still set.
1030 bool newLoadStarted = hasPendingActivity(); 1029 bool newLoadStarted = hasPendingActivity();
1031 if (!newLoadStarted) 1030 if (!newLoadStarted)
1032 m_error = true; 1031 m_error = true;
1033 1032
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 } 1083 }
1085 1084
1086 void XMLHttpRequest::handleNetworkError() 1085 void XMLHttpRequest::handleNetworkError()
1087 { 1086 {
1088 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); 1087 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this);
1089 1088
1090 // Response is cleared next, save needed progress event data. 1089 // Response is cleared next, save needed progress event data.
1091 long long expectedLength = m_response.expectedContentLength(); 1090 long long expectedLength = m_response.expectedContentLength();
1092 long long receivedLength = m_receivedLength; 1091 long long receivedLength = m_receivedLength;
1093 1092
1093 // Prevent the XMLHttpRequest instance from being destoryed during
1094 // |internalAbort()|.
1095 RefPtrWillBeRawPtr<XMLHttpRequest> protect(this);
1096
1094 if (!internalAbort()) 1097 if (!internalAbort())
1095 return; 1098 return;
1096 1099
1097 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength); 1100 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength);
1098 } 1101 }
1099 1102
1100 void XMLHttpRequest::handleDidCancel() 1103 void XMLHttpRequest::handleDidCancel()
1101 { 1104 {
1102 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); 1105 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this);
1103 1106
1104 // Response is cleared next, save needed progress event data. 1107 // Response is cleared next, save needed progress event data.
1105 long long expectedLength = m_response.expectedContentLength(); 1108 long long expectedLength = m_response.expectedContentLength();
1106 long long receivedLength = m_receivedLength; 1109 long long receivedLength = m_receivedLength;
1107 1110
1111 // Prevent the XMLHttpRequest instance from being destoryed during
1112 // |internalAbort()|.
1113 RefPtrWillBeRawPtr<XMLHttpRequest> protect(this);
1114
1108 if (!internalAbort()) 1115 if (!internalAbort())
1109 return; 1116 return;
1110 1117
1111 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength); 1118 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength);
1112 } 1119 }
1113 1120
1114 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength) 1121 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength)
1115 { 1122 {
1116 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this); 1123 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this);
1117 1124
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 void XMLHttpRequest::didFail(const ResourceError& error) 1311 void XMLHttpRequest::didFail(const ResourceError& error)
1305 { 1312 {
1306 WTF_LOG(Network, "XMLHttpRequest %p didFail()", this); 1313 WTF_LOG(Network, "XMLHttpRequest %p didFail()", this);
1307 1314
1308 // If we are already in an error state, for instance we called abort(), bail out early. 1315 // If we are already in an error state, for instance we called abort(), bail out early.
1309 if (m_error) 1316 if (m_error)
1310 return; 1317 return;
1311 1318
1312 if (error.isCancellation()) { 1319 if (error.isCancellation()) {
1313 handleDidCancel(); 1320 handleDidCancel();
1321 // Now the XMLHttpRequest instance may be dead.
1314 return; 1322 return;
1315 } 1323 }
1316 1324
1317 if (error.isTimeout()) { 1325 if (error.isTimeout()) {
1318 handleDidTimeout(); 1326 handleDidTimeout();
1327 // Now the XMLHttpRequest instance may be dead.
1319 return; 1328 return;
1320 } 1329 }
1321 1330
1322 // Network failures are already reported to Web Inspector by ResourceLoader. 1331 // Network failures are already reported to Web Inspector by ResourceLoader.
1323 if (error.domain() == errorDomainBlinkInternal) 1332 if (error.domain() == errorDomainBlinkInternal)
1324 logConsoleError(executionContext(), "XMLHttpRequest cannot load " + erro r.failingURL() + ". " + error.localizedDescription()); 1333 logConsoleError(executionContext(), "XMLHttpRequest cannot load " + erro r.failingURL() + ". " + error.localizedDescription());
1325 1334
1326 handleNetworkError(); 1335 handleNetworkError();
1336 // Now the XMLHttpRequest instance may be dead.
1327 } 1337 }
1328 1338
1329 void XMLHttpRequest::didFailRedirectCheck() 1339 void XMLHttpRequest::didFailRedirectCheck()
1330 { 1340 {
1331 WTF_LOG(Network, "XMLHttpRequest %p didFailRedirectCheck()", this); 1341 WTF_LOG(Network, "XMLHttpRequest %p didFailRedirectCheck()", this);
1332 1342
1333 handleNetworkError(); 1343 handleNetworkError();
1344 // Now the XMLHttpRequest instance may be dead.
1334 } 1345 }
1335 1346
1336 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) 1347 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double)
1337 { 1348 {
1338 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier ); 1349 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier );
1339 1350
1340 if (m_error) 1351 if (m_error)
1341 return; 1352 return;
1342 1353
1343 if (m_state < HEADERS_RECEIVED) 1354 if (m_state < HEADERS_RECEIVED)
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 } 1606 }
1596 1607
1597 void XMLHttpRequest::handleDidTimeout() 1608 void XMLHttpRequest::handleDidTimeout()
1598 { 1609 {
1599 WTF_LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this); 1610 WTF_LOG(Network, "XMLHttpRequest %p handleDidTimeout()", this);
1600 1611
1601 // Response is cleared next, save needed progress event data. 1612 // Response is cleared next, save needed progress event data.
1602 long long expectedLength = m_response.expectedContentLength(); 1613 long long expectedLength = m_response.expectedContentLength();
1603 long long receivedLength = m_receivedLength; 1614 long long receivedLength = m_receivedLength;
1604 1615
1616 // Prevent the XMLHttpRequest instance from being destoryed during
1617 // |internalAbort()|.
1618 RefPtrWillBeRawPtr<XMLHttpRequest> protect(this);
1619
1605 if (!internalAbort()) 1620 if (!internalAbort())
1606 return; 1621 return;
1607 1622
1608 handleRequestError(TimeoutError, EventTypeNames::timeout, receivedLength, ex pectedLength); 1623 handleRequestError(TimeoutError, EventTypeNames::timeout, receivedLength, ex pectedLength);
1609 } 1624 }
1610 1625
1611 void XMLHttpRequest::suspend() 1626 void XMLHttpRequest::suspend()
1612 { 1627 {
1613 m_progressEventThrottle.suspend(); 1628 m_progressEventThrottle.suspend();
1614 } 1629 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 visitor->trace(m_streamSource); 1673 visitor->trace(m_streamSource);
1659 visitor->trace(m_responseDocument); 1674 visitor->trace(m_responseDocument);
1660 visitor->trace(m_responseDocumentParser); 1675 visitor->trace(m_responseDocumentParser);
1661 visitor->trace(m_progressEventThrottle); 1676 visitor->trace(m_progressEventThrottle);
1662 visitor->trace(m_upload); 1677 visitor->trace(m_upload);
1663 visitor->trace(m_blobLoader); 1678 visitor->trace(m_blobLoader);
1664 XMLHttpRequestEventTarget::trace(visitor); 1679 XMLHttpRequestEventTarget::trace(visitor);
1665 } 1680 }
1666 1681
1667 } // namespace blink 1682 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698