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 } | |
abarth-chromium
2014/09/02 20:13:19
Rather than using a HashMap, we should use a clien
| |
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 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
919 m_responseDocumentParser = nullptr; | 927 m_responseDocumentParser = nullptr; |
920 } | 928 } |
921 | 929 |
922 m_finalResponseCharset = String(); | 930 m_finalResponseCharset = String(); |
923 } | 931 } |
924 | 932 |
925 bool XMLHttpRequest::internalAbort() | 933 bool XMLHttpRequest::internalAbort() |
926 { | 934 { |
927 m_error = true; | 935 m_error = true; |
928 | 936 |
929 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped()) | 937 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped()) { |
930 m_responseDocumentParser->stopParsing(); | 938 m_responseDocumentParser->stopParsing(); |
931 | 939 |
940 HashMap<Document*, XMLHttpRequest*>& map = xhrPendingDocumentParseMap(); | |
941 for (HashMap<Document*, XMLHttpRequest*>::iterator it = map.begin(), itE nd = map.end(); it != itEnd; ++it) { | |
942 if (it->value == this) { | |
943 map.remove(it); | |
944 break; | |
945 } | |
946 } | |
947 } | |
948 | |
932 clearVariablesForLoading(); | 949 clearVariablesForLoading(); |
933 | 950 |
934 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this); | 951 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this); |
935 | 952 |
936 if (m_responseLegacyStream && m_state != DONE) | 953 if (m_responseLegacyStream && m_state != DONE) |
937 m_responseLegacyStream->abort(); | 954 m_responseLegacyStream->abort(); |
938 | 955 |
939 if (m_responseStream) { | 956 if (m_responseStream) { |
940 // When the stream is already closed (including canceled from the | 957 // When the stream is already closed (including canceled from the |
941 // user), |error| does nothing. | 958 // user), |error| does nothing. |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1274 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) | 1291 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) |
1275 { | 1292 { |
1276 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier ); | 1293 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier ); |
1277 | 1294 |
1278 if (m_error) | 1295 if (m_error) |
1279 return; | 1296 return; |
1280 | 1297 |
1281 if (m_state < HEADERS_RECEIVED) | 1298 if (m_state < HEADERS_RECEIVED) |
1282 changeState(HEADERS_RECEIVED); | 1299 changeState(HEADERS_RECEIVED); |
1283 | 1300 |
1301 m_loaderIdentifier = identifier; | |
1302 | |
1284 if (m_responseDocumentParser) { | 1303 if (m_responseDocumentParser) { |
1304 // |DocumentParser::finish()| tells the parser that we have reached end of the data. | |
1305 // When using |HTMLDocumentParser|, which works asynchronously, we do no t have the | |
1306 // complete document just after the |DocumentParser::finish()| call. | |
1307 // Record |this| as a XHR waiting for document parse to complete, and wa it for | |
1308 // |Document::finishedParsing| to call us back in |didFinishParsingDocum ent| to progress state. | |
1309 HashMap<Document*, XMLHttpRequest*>& map = xhrPendingDocumentParseMap(); | |
1310 HashMap<Document*, XMLHttpRequest*>::AddResult result = map.set(m_respon seDocument.get(), this); | |
1311 ASSERT_UNUSED(result, result.isNewEntry); | |
1312 | |
1285 m_responseDocumentParser->finish(); | 1313 m_responseDocumentParser->finish(); |
1286 m_responseDocumentParser = nullptr; | 1314 ASSERT(m_responseDocument); |
1315 return; | |
1316 } | |
1287 | 1317 |
1288 m_responseDocument->implicitClose(); | 1318 if (m_decoder) |
1289 | |
1290 if (!m_responseDocument->wellFormed()) | |
1291 m_responseDocument = nullptr; | |
1292 | |
1293 m_parsedResponse = true; | |
1294 } else if (m_decoder) { | |
1295 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); | 1319 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); |
1296 } | |
1297 | 1320 |
1298 if (m_responseLegacyStream) | 1321 if (m_responseLegacyStream) |
1299 m_responseLegacyStream->finalize(); | 1322 m_responseLegacyStream->finalize(); |
1300 | 1323 |
1301 if (m_responseStream) | 1324 if (m_responseStream) |
1302 m_responseStream->close(); | 1325 m_responseStream->close(); |
1303 | 1326 |
1327 endLoading(); | |
1328 } | |
1329 | |
1330 XMLHttpRequest* XMLHttpRequest::findInstancePendingDocumentParse(Document* docum ent) | |
1331 { | |
1332 return xhrPendingDocumentParseMap().get(document); | |
1333 } | |
1334 | |
1335 void XMLHttpRequest::didFinishParsingDocument() | |
1336 { | |
1337 // This should only be called when response document is parsed asynchronousl y. | |
1338 ASSERT(m_responseDocumentParser); | |
1339 ASSERT(!m_responseDocumentParser->isParsing()); | |
1340 ASSERT(!m_responseLegacyStream); | |
1341 ASSERT(!m_responseStream); | |
1342 | |
1343 m_responseDocumentParser = nullptr; | |
1344 m_responseDocument->implicitClose(); | |
1345 | |
1346 if (!m_responseDocument->wellFormed()) | |
1347 m_responseDocument = nullptr; | |
1348 | |
1349 m_parsedResponse = true; | |
1350 | |
1351 endLoading(); | |
1352 } | |
1353 | |
1354 void XMLHttpRequest::endLoading() | |
1355 { | |
1304 clearVariablesForLoading(); | 1356 clearVariablesForLoading(); |
1305 | 1357 |
1306 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this , identifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSendLineNumb er); | 1358 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this , m_loaderIdentifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSend LineNumber); |
1307 | 1359 |
1308 if (m_loader) | 1360 if (m_loader) |
1309 m_loader = nullptr; | 1361 m_loader = nullptr; |
1362 m_loaderIdentifier = 0; | |
1310 | 1363 |
1311 changeState(DONE); | 1364 changeState(DONE); |
1312 } | 1365 } |
1313 | 1366 |
1314 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) | 1367 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) |
1315 { | 1368 { |
1316 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent); | 1369 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent); |
1317 | 1370 |
1318 if (!m_upload) | 1371 if (!m_upload) |
1319 return; | 1372 return; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1515 visitor->trace(m_responseStream); | 1568 visitor->trace(m_responseStream); |
1516 visitor->trace(m_streamSource); | 1569 visitor->trace(m_streamSource); |
1517 visitor->trace(m_responseDocument); | 1570 visitor->trace(m_responseDocument); |
1518 visitor->trace(m_responseDocumentParser); | 1571 visitor->trace(m_responseDocumentParser); |
1519 visitor->trace(m_progressEventThrottle); | 1572 visitor->trace(m_progressEventThrottle); |
1520 visitor->trace(m_upload); | 1573 visitor->trace(m_upload); |
1521 XMLHttpRequestEventTarget::trace(visitor); | 1574 XMLHttpRequestEventTarget::trace(visitor); |
1522 } | 1575 } |
1523 | 1576 |
1524 } // namespace blink | 1577 } // namespace blink |
OLD | NEW |