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

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: address tyoshino-san review / more comments Created 6 years, 4 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/xml/XMLHttpRequest.h ('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 5d1979176606a13ed6a09d9ed92e6b2ea6dbbf97..4698049962df7fcdf463adcd55703994309f4819 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;
+}
+
} // 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)
@@ -935,6 +943,14 @@ bool XMLHttpRequest::internalAbort()
InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this);
+ 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;
+ }
+ }
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.
+
if (m_responseLegacyStream && m_state != DONE)
m_responseLegacyStream->abort();
@@ -1283,19 +1299,25 @@ void XMLHttpRequest::didFinishLoading(unsigned long identifier, double)
if (m_state < HEADERS_RECEIVED)
changeState(HEADERS_RECEIVED);
+ m_loaderIdentifier = identifier;
+
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.
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.
- m_responseDocumentParser = nullptr;
+ ASSERT(m_responseDocument);
- m_responseDocument->implicitClose();
-
- if (!m_responseDocument->wellFormed())
- m_responseDocument = nullptr;
+ // 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);
+ 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();
@@ -1303,12 +1325,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/xml/XMLHttpRequest.h ('K') | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698