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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 UnderlyingSource::trace(visitor); | 124 UnderlyingSource::trace(visitor); |
125 } | 125 } |
126 | 126 |
127 private: | 127 private: |
128 // This is RawPtr in non-oilpan build to avoid the reference cycle. To | 128 // This is RawPtr in non-oilpan build to avoid the reference cycle. To |
129 // avoid use-after free, the associated ReadableStream must be closed | 129 // avoid use-after free, the associated ReadableStream must be closed |
130 // or errored when m_owner is gone. | 130 // or errored when m_owner is gone. |
131 RawPtrWillBeMember<XMLHttpRequest> m_owner; | 131 RawPtrWillBeMember<XMLHttpRequest> m_owner; |
132 }; | 132 }; |
133 | 133 |
134 HashMap<Document*, XMLHttpRequest*>& xhrPendingDocumentParseMap() | |
135 { | |
136 typedef HashMap<Document*, XMLHttpRequest*> XHRPendingDocumentParseMap; | |
137 DEFINE_STATIC_LOCAL(XHRPendingDocumentParseMap, map, ()); | |
138 return map; | |
139 } | |
140 | |
134 } // namespace | 141 } // namespace |
135 | 142 |
136 PassRefPtrWillBeRawPtr<XMLHttpRequest> XMLHttpRequest::create(ExecutionContext* context, PassRefPtr<SecurityOrigin> securityOrigin) | 143 PassRefPtrWillBeRawPtr<XMLHttpRequest> XMLHttpRequest::create(ExecutionContext* context, PassRefPtr<SecurityOrigin> securityOrigin) |
137 { | 144 { |
138 RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = adoptRefWillBeNoop(new X MLHttpRequest(context, securityOrigin)); | 145 RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = adoptRefWillBeNoop(new X MLHttpRequest(context, securityOrigin)); |
139 xmlHttpRequest->suspendIfNeeded(); | 146 xmlHttpRequest->suspendIfNeeded(); |
140 | 147 |
141 return xmlHttpRequest.release(); | 148 return xmlHttpRequest.release(); |
142 } | 149 } |
143 | 150 |
144 XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOri gin> securityOrigin) | 151 XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOri gin> securityOrigin) |
145 : ActiveDOMObject(context) | 152 : ActiveDOMObject(context) |
146 , m_timeoutMilliseconds(0) | 153 , m_timeoutMilliseconds(0) |
154 , m_loaderIdentifier(0) | |
147 , m_state(UNSENT) | 155 , m_state(UNSENT) |
148 , m_downloadedBlobLength(0) | 156 , m_downloadedBlobLength(0) |
149 , m_receivedLength(0) | 157 , m_receivedLength(0) |
150 , m_lastSendLineNumber(0) | 158 , m_lastSendLineNumber(0) |
151 , m_exceptionCode(0) | 159 , m_exceptionCode(0) |
152 , m_progressEventThrottle(this) | 160 , m_progressEventThrottle(this) |
153 , m_responseTypeCode(ResponseTypeDefault) | 161 , m_responseTypeCode(ResponseTypeDefault) |
154 , m_securityOrigin(securityOrigin) | 162 , m_securityOrigin(securityOrigin) |
155 , m_async(true) | 163 , m_async(true) |
156 , m_includeCredentials(false) | 164 , m_includeCredentials(false) |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
928 { | 936 { |
929 m_error = true; | 937 m_error = true; |
930 | 938 |
931 if (m_responseDocumentParser && m_responseDocumentParser->isStopped()) | 939 if (m_responseDocumentParser && m_responseDocumentParser->isStopped()) |
932 m_responseDocumentParser->stopParsing(); | 940 m_responseDocumentParser->stopParsing(); |
933 | 941 |
934 clearVariablesForLoading(); | 942 clearVariablesForLoading(); |
935 | 943 |
936 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this); | 944 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this); |
937 | 945 |
946 HashMap<Document*, XMLHttpRequest*>& map = xhrPendingDocumentParseMap(); | |
947 for (HashMap<Document*, XMLHttpRequest*>::iterator it = map.begin(), itEnd = map.end(); it != itEnd; ++it) { | |
948 if (it->value == this) { | |
949 map.remove(it); | |
950 break; | |
951 } | |
952 } | |
tyoshino (SeeGerritForStatus)
2014/09/02 04:12:16
I recommend that we place this close to stopParsin
kouhei (in TOK)
2014/09/02 16:17:27
Done.
| |
953 | |
938 if (m_responseLegacyStream && m_state != DONE) | 954 if (m_responseLegacyStream && m_state != DONE) |
939 m_responseLegacyStream->abort(); | 955 m_responseLegacyStream->abort(); |
940 | 956 |
941 if (m_responseStream) { | 957 if (m_responseStream) { |
942 // When the stream is already closed (including canceled from the | 958 // When the stream is already closed (including canceled from the |
943 // user), |error| does nothing. | 959 // user), |error| does nothing. |
944 // FIXME: Create a more specific error. | 960 // FIXME: Create a more specific error. |
945 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort")); | 961 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort")); |
946 } | 962 } |
947 | 963 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1276 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) | 1292 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) |
1277 { | 1293 { |
1278 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier ); | 1294 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier ); |
1279 | 1295 |
1280 if (m_error) | 1296 if (m_error) |
1281 return; | 1297 return; |
1282 | 1298 |
1283 if (m_state < HEADERS_RECEIVED) | 1299 if (m_state < HEADERS_RECEIVED) |
1284 changeState(HEADERS_RECEIVED); | 1300 changeState(HEADERS_RECEIVED); |
1285 | 1301 |
1302 m_loaderIdentifier = identifier; | |
1303 | |
1286 if (m_responseDocumentParser) { | 1304 if (m_responseDocumentParser) { |
1305 // |DocumentParser::finish()| tells the parser that we have reached end of the data. | |
1306 // When using |HTMLDocumentParser|, which works asynchronously, we do no t have the | |
1307 // complete document just after the |DocumentParser::finish()| call. | |
1287 m_responseDocumentParser->finish(); | 1308 m_responseDocumentParser->finish(); |
tyoshino (SeeGerritForStatus)
2014/09/02 04:19:19
We are never notified of completion synchronously?
kouhei (in TOK)
2014/09/02 16:17:27
Great catch. Done.
| |
1288 m_responseDocumentParser = nullptr; | 1309 ASSERT(m_responseDocument); |
1289 | 1310 |
1290 m_responseDocument->implicitClose(); | 1311 // Record |this| as a XHR waiting for document parse to complete, and wa it for |
1312 // |Document::finishedParsing| to call us back in |didFinishParsingDocum ent| to progress state. | |
1313 HashMap<Document*, XMLHttpRequest*>& map = xhrPendingDocumentParseMap(); | |
1314 HashMap<Document*, XMLHttpRequest*>::AddResult result = map.set(m_respon seDocument.get(), this); | |
1315 ASSERT_UNUSED(result, result.isNewEntry); | |
1316 return; | |
1317 } | |
1291 | 1318 |
1292 if (!m_responseDocument->wellFormed()) | 1319 if (m_decoder) |
1293 m_responseDocument = nullptr; | |
1294 | |
1295 m_parsedResponse = true; | |
1296 } else if (m_decoder) { | |
1297 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); | 1320 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); |
1298 } | |
1299 | 1321 |
1300 if (m_responseLegacyStream) | 1322 if (m_responseLegacyStream) |
1301 m_responseLegacyStream->finalize(); | 1323 m_responseLegacyStream->finalize(); |
1302 | 1324 |
1303 if (m_responseStream) | 1325 if (m_responseStream) |
1304 m_responseStream->close(); | 1326 m_responseStream->close(); |
1305 | 1327 |
1328 endLoading(); | |
1329 } | |
1330 | |
1331 XMLHttpRequest* XMLHttpRequest::findInstancePendingDocumentParse(Document* docum ent) | |
1332 { | |
1333 return xhrPendingDocumentParseMap().get(document); | |
1334 } | |
1335 | |
1336 void XMLHttpRequest::didFinishParsingDocument() | |
1337 { | |
1338 // This should only be called when response document is parsed asynchronousl y. | |
1339 ASSERT(m_responseDocumentParser); | |
1340 ASSERT(!m_responseDocumentParser->isParsing()); | |
1341 ASSERT(!m_responseLegacyStream); | |
1342 ASSERT(!m_responseStream); | |
1343 | |
1344 m_responseDocumentParser = nullptr; | |
1345 m_responseDocument->implicitClose(); | |
1346 | |
1347 if (!m_responseDocument->wellFormed()) | |
1348 m_responseDocument = nullptr; | |
1349 | |
1350 m_parsedResponse = true; | |
1351 | |
1352 endLoading(); | |
1353 } | |
1354 | |
1355 void XMLHttpRequest::endLoading() | |
1356 { | |
1306 clearVariablesForLoading(); | 1357 clearVariablesForLoading(); |
1307 | 1358 |
1308 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this , identifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSendLineNumb er); | 1359 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this , m_loaderIdentifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSend LineNumber); |
1309 | 1360 |
1310 if (m_loader) | 1361 if (m_loader) |
1311 m_loader = nullptr; | 1362 m_loader = nullptr; |
1363 m_loaderIdentifier = 0; | |
1312 | 1364 |
1313 changeState(DONE); | 1365 changeState(DONE); |
1314 } | 1366 } |
1315 | 1367 |
1316 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) | 1368 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) |
1317 { | 1369 { |
1318 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent); | 1370 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent); |
1319 | 1371 |
1320 if (!m_upload) | 1372 if (!m_upload) |
1321 return; | 1373 return; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 visitor->trace(m_responseStream); | 1569 visitor->trace(m_responseStream); |
1518 visitor->trace(m_streamSource); | 1570 visitor->trace(m_streamSource); |
1519 visitor->trace(m_responseDocument); | 1571 visitor->trace(m_responseDocument); |
1520 visitor->trace(m_responseDocumentParser); | 1572 visitor->trace(m_responseDocumentParser); |
1521 visitor->trace(m_progressEventThrottle); | 1573 visitor->trace(m_progressEventThrottle); |
1522 visitor->trace(m_upload); | 1574 visitor->trace(m_upload); |
1523 XMLHttpRequestEventTarget::trace(visitor); | 1575 XMLHttpRequestEventTarget::trace(visitor); |
1524 } | 1576 } |
1525 | 1577 |
1526 } // namespace blink | 1578 } // namespace blink |
OLD | NEW |