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

Unified 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: register before finish 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 side-by-side diff with in-line comments
Download patch
« Source/core/dom/Document.cpp ('K') | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/xml/XMLHttpRequest.cpp
diff --git a/Source/core/xml/XMLHttpRequest.cpp b/Source/core/xml/XMLHttpRequest.cpp
index 6926b1cfe2439e3fa568afc6c5c0cf8dc6b637ef..0a1ccfd6e13997a780343e9c512fc492242e8709 100644
--- a/Source/core/xml/XMLHttpRequest.cpp
+++ b/Source/core/xml/XMLHttpRequest.cpp
@@ -131,6 +131,13 @@ private:
RawPtrWillBeMember<XMLHttpRequest> m_owner;
};
+HashMap<Document*, XMLHttpRequest*>& xhrPendingDocumentParseMap()
+{
+ typedef HashMap<Document*, XMLHttpRequest*> XHRPendingDocumentParseMap;
+ DEFINE_STATIC_LOCAL(XHRPendingDocumentParseMap, map, ());
+ return map;
+}
abarth-chromium 2014/09/02 20:13:19 Rather than using a HashMap, we should use a clien
+
} // namespace
PassRefPtrWillBeRawPtr<XMLHttpRequest> XMLHttpRequest::create(ExecutionContext* context, PassRefPtr<SecurityOrigin> securityOrigin)
@@ -144,6 +151,7 @@ PassRefPtrWillBeRawPtr<XMLHttpRequest> XMLHttpRequest::create(ExecutionContext*
XMLHttpRequest::XMLHttpRequest(ExecutionContext* context, PassRefPtr<SecurityOrigin> securityOrigin)
: ActiveDOMObject(context)
, m_timeoutMilliseconds(0)
+ , m_loaderIdentifier(0)
, m_state(UNSENT)
, m_downloadedBlobLength(0)
, m_receivedLength(0)
@@ -926,9 +934,18 @@ bool XMLHttpRequest::internalAbort()
{
m_error = true;
- if (m_responseDocumentParser && !m_responseDocumentParser->isStopped())
+ if (m_responseDocumentParser && !m_responseDocumentParser->isStopped()) {
m_responseDocumentParser->stopParsing();
+ HashMap<Document*, XMLHttpRequest*>& map = xhrPendingDocumentParseMap();
+ for (HashMap<Document*, XMLHttpRequest*>::iterator it = map.begin(), itEnd = map.end(); it != itEnd; ++it) {
+ if (it->value == this) {
+ map.remove(it);
+ break;
+ }
+ }
+ }
+
clearVariablesForLoading();
InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this);
@@ -1281,19 +1298,25 @@ void XMLHttpRequest::didFinishLoading(unsigned long identifier, double)
if (m_state < HEADERS_RECEIVED)
changeState(HEADERS_RECEIVED);
- if (m_responseDocumentParser) {
- m_responseDocumentParser->finish();
- m_responseDocumentParser = nullptr;
+ m_loaderIdentifier = identifier;
- m_responseDocument->implicitClose();
+ if (m_responseDocumentParser) {
+ // |DocumentParser::finish()| tells the parser that we have reached end of the data.
+ // When using |HTMLDocumentParser|, which works asynchronously, we do not have the
+ // complete document just after the |DocumentParser::finish()| call.
+ // Record |this| as a XHR waiting for document parse to complete, and wait for
+ // |Document::finishedParsing| to call us back in |didFinishParsingDocument| to progress state.
+ HashMap<Document*, XMLHttpRequest*>& map = xhrPendingDocumentParseMap();
+ HashMap<Document*, XMLHttpRequest*>::AddResult result = map.set(m_responseDocument.get(), this);
+ ASSERT_UNUSED(result, result.isNewEntry);
- if (!m_responseDocument->wellFormed())
- m_responseDocument = nullptr;
+ m_responseDocumentParser->finish();
+ ASSERT(m_responseDocument);
+ return;
+ }
- m_parsedResponse = true;
- } else if (m_decoder) {
+ if (m_decoder)
m_responseText = m_responseText.concatenateWith(m_decoder->flush());
- }
if (m_responseLegacyStream)
m_responseLegacyStream->finalize();
@@ -1301,12 +1324,42 @@ void XMLHttpRequest::didFinishLoading(unsigned long identifier, double)
if (m_responseStream)
m_responseStream->close();
+ endLoading();
+}
+
+XMLHttpRequest* XMLHttpRequest::findInstancePendingDocumentParse(Document* document)
+{
+ return xhrPendingDocumentParseMap().get(document);
+}
+
+void XMLHttpRequest::didFinishParsingDocument()
+{
+ // This should only be called when response document is parsed asynchronously.
+ ASSERT(m_responseDocumentParser);
+ ASSERT(!m_responseDocumentParser->isParsing());
+ ASSERT(!m_responseLegacyStream);
+ ASSERT(!m_responseStream);
+
+ m_responseDocumentParser = nullptr;
+ m_responseDocument->implicitClose();
+
+ if (!m_responseDocument->wellFormed())
+ m_responseDocument = nullptr;
+
+ m_parsedResponse = true;
+
+ endLoading();
+}
+
+void XMLHttpRequest::endLoading()
+{
clearVariablesForLoading();
- InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this, identifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSendLineNumber);
+ InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this, m_loaderIdentifier, m_responseText, m_method, m_url, m_lastSendURL, m_lastSendLineNumber);
if (m_loader)
m_loader = nullptr;
+ m_loaderIdentifier = 0;
changeState(DONE);
}
« Source/core/dom/Document.cpp ('K') | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698