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

Side by Side Diff: third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp

Issue 2649323005: Cleanly detach XHR and other pending loader clients from Inspector. (Closed)
Patch Set: rebalance XHR disposal steps Created 3 years, 10 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
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 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 DCHECK(!m_loader); 1087 DCHECK(!m_loader);
1088 handleRequestError(0, EventTypeNames::abort, receivedLength, 1088 handleRequestError(0, EventTypeNames::abort, receivedLength,
1089 expectedLength); 1089 expectedLength);
1090 } 1090 }
1091 } 1091 }
1092 if (m_state == kDone) 1092 if (m_state == kDone)
1093 m_state = kUnsent; 1093 m_state = kUnsent;
1094 } 1094 }
1095 1095
1096 void XMLHttpRequest::dispose() { 1096 void XMLHttpRequest::dispose() {
1097 if (m_loader) { 1097 InspectorInstrumentation::detachClientRequest(getExecutionContext(), this);
1098 m_error = true; 1098 m_progressEventThrottle->stop();
1099 m_loader->cancel(); 1099 internalAbort();
1100 }
1101 } 1100 }
1102 1101
1103 void XMLHttpRequest::clearVariablesForLoading() { 1102 void XMLHttpRequest::clearVariablesForLoading() {
1104 if (m_blobLoader) { 1103 if (m_blobLoader) {
1105 m_blobLoader->cancel(); 1104 m_blobLoader->cancel();
1106 m_blobLoader = nullptr; 1105 m_blobLoader = nullptr;
1107 } 1106 }
1108 1107
1109 m_decoder.reset(); 1108 m_decoder.reset();
1110 1109
1111 if (m_responseDocumentParser) { 1110 if (m_responseDocumentParser) {
1112 m_responseDocumentParser->removeClient(this); 1111 m_responseDocumentParser->removeClient(this);
1113 m_responseDocumentParser->detach(); 1112 m_responseDocumentParser->detach();
1114 m_responseDocumentParser = nullptr; 1113 m_responseDocumentParser = nullptr;
1115 } 1114 }
1116 1115
1117 m_finalResponseCharset = String(); 1116 m_finalResponseCharset = String();
1118 } 1117 }
1119 1118
1120 bool XMLHttpRequest::internalAbort() { 1119 bool XMLHttpRequest::internalAbort() {
1120 // Fast path for repeated internalAbort()s; this
1121 // will happen if an XHR object is notified of context
1122 // destruction followed by finalization.
1123 if (m_error && !m_loader)
1124 return true;
1125
1121 m_error = true; 1126 m_error = true;
1122 1127
1123 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped()) 1128 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped())
1124 m_responseDocumentParser->stopParsing(); 1129 m_responseDocumentParser->stopParsing();
1125 1130
1126 clearVariablesForLoading(); 1131 clearVariablesForLoading();
1127 1132
1128 clearResponse(); 1133 clearResponse();
1129 clearRequest(); 1134 clearRequest();
1130 1135
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 1806
1802 void XMLHttpRequest::suspend() { 1807 void XMLHttpRequest::suspend() {
1803 m_progressEventThrottle->suspend(); 1808 m_progressEventThrottle->suspend();
1804 } 1809 }
1805 1810
1806 void XMLHttpRequest::resume() { 1811 void XMLHttpRequest::resume() {
1807 m_progressEventThrottle->resume(); 1812 m_progressEventThrottle->resume();
1808 } 1813 }
1809 1814
1810 void XMLHttpRequest::contextDestroyed(ExecutionContext*) { 1815 void XMLHttpRequest::contextDestroyed(ExecutionContext*) {
1811 InspectorInstrumentation::didFailXHRLoading(getExecutionContext(), this, this, 1816 dispose();
1812 m_method, m_url);
1813 m_progressEventThrottle->stop();
1814 internalAbort();
1815 1817
1816 // In case we are in the middle of send() function, unset the send flag to 1818 // In case we are in the middle of send() function, unset the send flag to
1817 // stop the operation. 1819 // stop the operation.
1818 m_sendFlag = false; 1820 m_sendFlag = false;
1819 } 1821 }
1820 1822
1821 bool XMLHttpRequest::hasPendingActivity() const { 1823 bool XMLHttpRequest::hasPendingActivity() const {
1822 // Neither this object nor the JavaScript wrapper should be deleted while 1824 // Neither this object nor the JavaScript wrapper should be deleted while
1823 // a request is in progress because we need to keep the listeners alive, 1825 // a request is in progress because we need to keep the listeners alive,
1824 // and they are referenced by the JavaScript wrapper. 1826 // and they are referenced by the JavaScript wrapper.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 visitor->traceWrappers(m_responseDocument); 1859 visitor->traceWrappers(m_responseDocument);
1858 visitor->traceWrappers(m_responseArrayBuffer); 1860 visitor->traceWrappers(m_responseArrayBuffer);
1859 XMLHttpRequestEventTarget::traceWrappers(visitor); 1861 XMLHttpRequestEventTarget::traceWrappers(visitor);
1860 } 1862 }
1861 1863
1862 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { 1864 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) {
1863 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); 1865 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr);
1864 } 1866 }
1865 1867
1866 } // namespace blink 1868 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698