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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 { | 137 { |
138 RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = adoptRefWillBeNoop(new X MLHttpRequest(context, securityOrigin)); | 138 RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = adoptRefWillBeNoop(new X MLHttpRequest(context, securityOrigin)); |
139 xmlHttpRequest->suspendIfNeeded(); | 139 xmlHttpRequest->suspendIfNeeded(); |
140 | 140 |
141 return xmlHttpRequest.release(); | 141 return xmlHttpRequest.release(); |
142 } | 142 } |
143 | 143 |
144 XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOri gin> securityOrigin) | 144 XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOri gin> securityOrigin) |
145 : ActiveDOMObject(context) | 145 : ActiveDOMObject(context) |
146 , m_timeoutMilliseconds(0) | 146 , m_timeoutMilliseconds(0) |
147 , m_loaderIdentifier(0) | |
147 , m_state(UNSENT) | 148 , m_state(UNSENT) |
148 , m_downloadedBlobLength(0) | 149 , m_downloadedBlobLength(0) |
149 , m_receivedLength(0) | 150 , m_receivedLength(0) |
150 , m_lastSendLineNumber(0) | 151 , m_lastSendLineNumber(0) |
151 , m_exceptionCode(0) | 152 , m_exceptionCode(0) |
152 , m_progressEventThrottle(this) | 153 , m_progressEventThrottle(this) |
153 , m_responseTypeCode(ResponseTypeDefault) | 154 , m_responseTypeCode(ResponseTypeDefault) |
154 , m_securityOrigin(securityOrigin) | 155 , m_securityOrigin(securityOrigin) |
155 , m_async(true) | 156 , m_async(true) |
156 , m_includeCredentials(false) | 157 , m_includeCredentials(false) |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
905 handleRequestError(0, EventTypeNames::abort, receivedLength, expectedLen gth); | 906 handleRequestError(0, EventTypeNames::abort, receivedLength, expectedLen gth); |
906 } | 907 } |
907 m_state = UNSENT; | 908 m_state = UNSENT; |
908 } | 909 } |
909 | 910 |
910 void XMLHttpRequest::clearVariablesForLoading() | 911 void XMLHttpRequest::clearVariablesForLoading() |
911 { | 912 { |
912 m_decoder.clear(); | 913 m_decoder.clear(); |
913 | 914 |
914 if (m_responseDocumentParser) { | 915 if (m_responseDocumentParser) { |
916 m_responseDocumentParser->removeClient(this); | |
915 #if !ENABLE(OILPAN) | 917 #if !ENABLE(OILPAN) |
916 m_responseDocumentParser->detach(); | 918 m_responseDocumentParser->detach(); |
917 #endif | 919 #endif |
918 m_responseDocumentParser = nullptr; | 920 m_responseDocumentParser = nullptr; |
919 } | 921 } |
920 | 922 |
921 m_finalResponseCharset = String(); | 923 m_finalResponseCharset = String(); |
922 } | 924 } |
923 | 925 |
924 bool XMLHttpRequest::internalAbort() | 926 bool XMLHttpRequest::internalAbort() |
925 { | 927 { |
926 m_error = true; | 928 m_error = true; |
927 | 929 |
928 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped()) | 930 if (m_responseDocumentParser && !m_responseDocumentParser->isStopped()) |
tyoshino (SeeGerritForStatus)
2014/09/10 06:46:36
how about calling
m_responseDocumentParser->remove
kouhei (in TOK)
2014/09/10 20:50:42
Would you elabolate on it? I want to know why you
tyoshino (SeeGerritForStatus)
2014/09/11 02:58:00
I saw "notifyParserStopped" checking m_error and i
| |
929 m_responseDocumentParser->stopParsing(); | 931 m_responseDocumentParser->stopParsing(); |
930 | 932 |
931 clearVariablesForLoading(); | 933 clearVariablesForLoading(); |
932 | 934 |
933 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this); | 935 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this); |
934 | 936 |
935 if (m_responseLegacyStream && m_state != DONE) | 937 if (m_responseLegacyStream && m_state != DONE) |
936 m_responseLegacyStream->abort(); | 938 m_responseLegacyStream->abort(); |
937 | 939 |
938 if (m_responseStream) { | 940 if (m_responseStream) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1036 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength); | 1038 handleRequestError(NetworkError, EventTypeNames::error, receivedLength, expe ctedLength); |
1037 } | 1039 } |
1038 | 1040 |
1039 void XMLHttpRequest::handleDidCancel() | 1041 void XMLHttpRequest::handleDidCancel() |
1040 { | 1042 { |
1041 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); | 1043 WTF_LOG(Network, "XMLHttpRequest %p handleDidCancel()", this); |
1042 | 1044 |
1043 // Response is cleared next, save needed progress event data. | 1045 // Response is cleared next, save needed progress event data. |
1044 long long expectedLength = m_response.expectedContentLength(); | 1046 long long expectedLength = m_response.expectedContentLength(); |
1045 long long receivedLength = m_receivedLength; | 1047 long long receivedLength = m_receivedLength; |
1046 | 1048 |
tyoshino (SeeGerritForStatus)
2014/09/10 06:46:36
if the loader is cancelled by someone else than th
kouhei (in TOK)
2014/09/10 20:50:42
Hmm. I guess you mean that handleDidFailGeneric do
tyoshino (SeeGerritForStatus)
2014/09/11 03:41:32
Right!
| |
1047 handleDidFailGeneric(); | 1049 handleDidFailGeneric(); |
1048 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength); | 1050 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength); |
1049 } | 1051 } |
1050 | 1052 |
1051 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength) | 1053 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength) |
1052 { | 1054 { |
1053 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this); | 1055 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this); |
1054 | 1056 |
1055 // The request error steps for event 'type' and exception 'exceptionCode'. | 1057 // The request error steps for event 'type' and exception 'exceptionCode'. |
1056 | 1058 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1273 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) | 1275 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) |
1274 { | 1276 { |
1275 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier ); | 1277 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier ); |
1276 | 1278 |
1277 if (m_error) | 1279 if (m_error) |
1278 return; | 1280 return; |
1279 | 1281 |
1280 if (m_state < HEADERS_RECEIVED) | 1282 if (m_state < HEADERS_RECEIVED) |
1281 changeState(HEADERS_RECEIVED); | 1283 changeState(HEADERS_RECEIVED); |
1282 | 1284 |
1285 m_loaderIdentifier = identifier; | |
1286 | |
1283 if (m_responseDocumentParser) { | 1287 if (m_responseDocumentParser) { |
1288 // |DocumentParser::finish()| tells the parser that we have reached end of the data. | |
1289 // When using |HTMLDocumentParser|, which works asynchronously, we do no t have the | |
1290 // complete document just after the |DocumentParser::finish()| call. | |
1291 // Wait for the parser to call us back in |notifyParserStopped| to progr ess state. | |
1284 m_responseDocumentParser->finish(); | 1292 m_responseDocumentParser->finish(); |
1285 m_responseDocumentParser = nullptr; | 1293 ASSERT(m_responseDocument); |
1294 return; | |
1295 } | |
1286 | 1296 |
1287 m_responseDocument->implicitClose(); | 1297 if (m_decoder) |
1288 | |
1289 if (!m_responseDocument->wellFormed()) | |
1290 m_responseDocument = nullptr; | |
1291 | |
1292 m_parsedResponse = true; | |
1293 } else if (m_decoder) { | |
1294 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); | 1298 m_responseText = m_responseText.concatenateWith(m_decoder->flush()); |
1295 } | |
1296 | 1299 |
1297 if (m_responseLegacyStream) | 1300 if (m_responseLegacyStream) |
1298 m_responseLegacyStream->finalize(); | 1301 m_responseLegacyStream->finalize(); |
1299 | 1302 |
1300 if (m_responseStream) | 1303 if (m_responseStream) |
1301 m_responseStream->close(); | 1304 m_responseStream->close(); |
1302 | 1305 |
1303 clearVariablesForLoading(); | 1306 clearVariablesForLoading(); |
1307 endLoading(); | |
1308 } | |
1304 | 1309 |
1305 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this , identifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSendLineNumb er); | 1310 void XMLHttpRequest::notifyParserStopped() |
1311 { | |
1312 // This should only be called when response document is parsed asynchronousl y. | |
1313 ASSERT(m_responseDocumentParser); | |
1314 ASSERT(!m_responseDocumentParser->isParsing()); | |
1315 ASSERT(!m_responseLegacyStream); | |
1316 ASSERT(!m_responseStream); | |
1317 | |
1318 // Do nothing if we are called from |internalAbort()|. | |
1319 if (m_error) | |
1320 return; | |
1321 | |
1322 clearVariablesForLoading(); | |
1323 | |
1324 m_responseDocument->implicitClose(); | |
1325 | |
1326 if (!m_responseDocument->wellFormed()) | |
1327 m_responseDocument = nullptr; | |
1328 | |
1329 m_parsedResponse = true; | |
1330 | |
1331 endLoading(); | |
1332 } | |
1333 | |
1334 void XMLHttpRequest::endLoading() | |
1335 { | |
1336 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this , m_loaderIdentifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSend LineNumber); | |
1306 | 1337 |
1307 if (m_loader) | 1338 if (m_loader) |
1308 m_loader = nullptr; | 1339 m_loader = nullptr; |
1340 m_loaderIdentifier = 0; | |
1309 | 1341 |
1310 changeState(DONE); | 1342 changeState(DONE); |
1311 } | 1343 } |
1312 | 1344 |
1313 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) | 1345 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) |
1314 { | 1346 { |
1315 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent); | 1347 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent); |
1316 | 1348 |
1317 if (!m_upload) | 1349 if (!m_upload) |
1318 return; | 1350 return; |
(...skipping 24 matching lines...) Expand all Loading... | |
1343 | 1375 |
1344 void XMLHttpRequest::parseDocumentChunk(const char* data, int len) | 1376 void XMLHttpRequest::parseDocumentChunk(const char* data, int len) |
1345 { | 1377 { |
1346 if (!m_responseDocumentParser) { | 1378 if (!m_responseDocumentParser) { |
1347 ASSERT(!m_responseDocument); | 1379 ASSERT(!m_responseDocument); |
1348 initResponseDocument(); | 1380 initResponseDocument(); |
1349 if (!m_responseDocument) | 1381 if (!m_responseDocument) |
1350 return; | 1382 return; |
1351 | 1383 |
1352 m_responseDocumentParser = m_responseDocument->implicitOpen(); | 1384 m_responseDocumentParser = m_responseDocument->implicitOpen(); |
1385 m_responseDocumentParser->addClient(this); | |
1353 } | 1386 } |
1354 ASSERT(m_responseDocumentParser); | 1387 ASSERT(m_responseDocumentParser); |
1355 | 1388 |
1356 if (m_responseDocumentParser->needsDecoder()) | 1389 if (m_responseDocumentParser->needsDecoder()) |
1357 m_responseDocumentParser->setDecoder(createDecoder()); | 1390 m_responseDocumentParser->setDecoder(createDecoder()); |
1358 | 1391 |
1359 m_responseDocumentParser->appendBytes(data, len); | 1392 m_responseDocumentParser->appendBytes(data, len); |
1360 } | 1393 } |
1361 | 1394 |
1362 PassOwnPtr<TextResourceDecoder> XMLHttpRequest::createDecoder() const | 1395 PassOwnPtr<TextResourceDecoder> XMLHttpRequest::createDecoder() const |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1514 visitor->trace(m_responseStream); | 1547 visitor->trace(m_responseStream); |
1515 visitor->trace(m_streamSource); | 1548 visitor->trace(m_streamSource); |
1516 visitor->trace(m_responseDocument); | 1549 visitor->trace(m_responseDocument); |
1517 visitor->trace(m_responseDocumentParser); | 1550 visitor->trace(m_responseDocumentParser); |
1518 visitor->trace(m_progressEventThrottle); | 1551 visitor->trace(m_progressEventThrottle); |
1519 visitor->trace(m_upload); | 1552 visitor->trace(m_upload); |
1520 XMLHttpRequestEventTarget::trace(visitor); | 1553 XMLHttpRequestEventTarget::trace(visitor); |
1521 } | 1554 } |
1522 | 1555 |
1523 } // namespace blink | 1556 } // namespace blink |
OLD | NEW |