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

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

Issue 521363002: Make XHR use the background HTML parser (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove 521403002 changes from diff Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 250
243 if (m_error || m_state != DONE) 251 if (m_error || m_state != DONE)
244 return 0; 252 return 0;
245 253
246 if (!m_parsedResponse) { 254 if (!m_parsedResponse) {
247 initResponseDocument(); 255 initResponseDocument();
248 if (!m_responseDocument) 256 if (!m_responseDocument)
249 return nullptr; 257 return nullptr;
250 258
251 m_responseDocument->setContent(m_responseText.flattenToString()); 259 m_responseDocument->setContent(m_responseText.flattenToString());
252 if (!m_responseDocument->wellFormed()) 260 if (!m_responseDocument->wellFormed()) {
tyoshino (SeeGerritForStatus) 2014/09/01 05:28:02 maybe you left this after removing additional line
kouhei (in TOK) 2014/09/01 20:44:28 Done.
253 m_responseDocument = nullptr; 261 m_responseDocument = nullptr;
262 }
254 263
255 m_parsedResponse = true; 264 m_parsedResponse = true;
256 } 265 }
257 266
258 return m_responseDocument.get(); 267 return m_responseDocument.get();
259 } 268 }
260 269
261 Blob* XMLHttpRequest::responseBlob() 270 Blob* XMLHttpRequest::responseBlob()
262 { 271 {
263 ASSERT(m_responseTypeCode == ResponseTypeBlob); 272 ASSERT(m_responseTypeCode == ResponseTypeBlob);
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 { 937 {
929 m_error = true; 938 m_error = true;
930 939
931 if (m_responseDocumentParser && m_responseDocumentParser->isStopped()) 940 if (m_responseDocumentParser && m_responseDocumentParser->isStopped())
932 m_responseDocumentParser->stopParsing(); 941 m_responseDocumentParser->stopParsing();
933 942
934 clearVariablesForLoading(); 943 clearVariablesForLoading();
935 944
936 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this); 945 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this);
937 946
947 // FIXME: abort parser
kouhei (in TOK) 2014/09/01 20:44:28 Removed this comment, as this is addressed in the
948 HashMap<Document*, XMLHttpRequest*>& map = xhrPendingDocumentParseMap();
949 for (HashMap<Document*, XMLHttpRequest*>::iterator it = map.begin(), itEnd = map.end(); it != itEnd; ++it) {
950 if (it->value == this) {
951 map.remove(it);
952 break;
953 }
954 }
955
938 if (m_responseLegacyStream && m_state != DONE) 956 if (m_responseLegacyStream && m_state != DONE)
939 m_responseLegacyStream->abort(); 957 m_responseLegacyStream->abort();
940 958
941 if (m_responseStream) { 959 if (m_responseStream) {
942 // When the stream is already closed (including canceled from the 960 // When the stream is already closed (including canceled from the
943 // user), |error| does nothing. 961 // user), |error| does nothing.
944 // FIXME: Create a more specific error. 962 // FIXME: Create a more specific error.
945 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort")); 963 m_responseStream->error(DOMException::create(!m_async && m_exceptionCode ? m_exceptionCode : AbortError, "XMLHttpRequest::abort"));
946 } 964 }
947 965
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double) 1294 void XMLHttpRequest::didFinishLoading(unsigned long identifier, double)
1277 { 1295 {
1278 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier ); 1296 WTF_LOG(Network, "XMLHttpRequest %p didFinishLoading(%lu)", this, identifier );
1279 1297
1280 if (m_error) 1298 if (m_error)
1281 return; 1299 return;
1282 1300
1283 if (m_state < HEADERS_RECEIVED) 1301 if (m_state < HEADERS_RECEIVED)
1284 changeState(HEADERS_RECEIVED); 1302 changeState(HEADERS_RECEIVED);
1285 1303
1304 m_loaderIdentifier = identifier;
1305
1286 if (m_responseDocumentParser) { 1306 if (m_responseDocumentParser) {
1287 m_responseDocumentParser->finish(); 1307 m_responseDocumentParser->finish();
1288 m_responseDocumentParser = nullptr; 1308 ASSERT(m_responseDocument);
1289 1309
1290 m_responseDocument->implicitClose(); 1310 HashMap<Document*, XMLHttpRequest*>& map = xhrPendingDocumentParseMap();
1311 HashMap<Document*, XMLHttpRequest*>::AddResult result = map.set(m_respon seDocument.get(), this);
1312 ASSERT_UNUSED(result, result.isNewEntry);
1313 // progress state in didFinishParsingDocument
1314 return;
1315 }
1291 1316
1292 if (!m_responseDocument->wellFormed()) 1317 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()); 1318 m_responseText = m_responseText.concatenateWith(m_decoder->flush());
1298 }
1299 1319
1300 if (m_responseLegacyStream) 1320 if (m_responseLegacyStream)
1301 m_responseLegacyStream->finalize(); 1321 m_responseLegacyStream->finalize();
1302 1322
1303 if (m_responseStream) 1323 if (m_responseStream)
1304 m_responseStream->close(); 1324 m_responseStream->close();
1305 1325
1326 endLoading();
1327 }
1328
1329 XMLHttpRequest* XMLHttpRequest::findInstancePendingDocumentParse(Document* docum ent)
1330 {
1331 return xhrPendingDocumentParseMap().get(document);
1332 }
1333
1334 void XMLHttpRequest::didFinishParsingDocument()
1335 {
1336 // This should only be called when response document is asynchronous parsed.
tyoshino (SeeGerritForStatus) 2014/09/01 05:28:03 asynchronously
1337 ASSERT(m_responseDocumentParser);
1338 ASSERT(!m_responseDocumentParser->isParsing());
1339 ASSERT(!m_responseLegacyStream);
1340 ASSERT(!m_responseStream);
1341
1342 m_responseDocumentParser = nullptr;
1343 m_responseDocument->implicitClose();
1344
1345 if (!m_responseDocument->wellFormed())
1346 m_responseDocument = nullptr;
1347
1348 m_parsedResponse = true;
1349
1350 endLoading();
1351 }
1352
1353 void XMLHttpRequest::endLoading()
1354 {
1306 clearVariablesForLoading(); 1355 clearVariablesForLoading();
1307 1356
1308 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this , identifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSendLineNumb er); 1357 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this , m_loaderIdentifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSend LineNumber);
1309 1358
1310 if (m_loader) 1359 if (m_loader)
1311 m_loader = nullptr; 1360 m_loader = nullptr;
1361 m_loaderIdentifier = 0;
1312 1362
1313 changeState(DONE); 1363 changeState(DONE);
1314 } 1364 }
1315 1365
1316 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) 1366 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent)
1317 { 1367 {
1318 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent); 1368 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent);
1319 1369
1320 if (!m_upload) 1370 if (!m_upload)
1321 return; 1371 return;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 visitor->trace(m_responseStream); 1567 visitor->trace(m_responseStream);
1518 visitor->trace(m_streamSource); 1568 visitor->trace(m_streamSource);
1519 visitor->trace(m_responseDocument); 1569 visitor->trace(m_responseDocument);
1520 visitor->trace(m_responseDocumentParser); 1570 visitor->trace(m_responseDocumentParser);
1521 visitor->trace(m_progressEventThrottle); 1571 visitor->trace(m_progressEventThrottle);
1522 visitor->trace(m_upload); 1572 visitor->trace(m_upload);
1523 XMLHttpRequestEventTarget::trace(visitor); 1573 XMLHttpRequestEventTarget::trace(visitor);
1524 } 1574 }
1525 1575
1526 } // namespace blink 1576 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698