Commit 7ccffb8e authored by kouhei@chromium.org's avatar kouhei@chromium.org

introduce DocumentParserClient to receive parser stopped notification

This depends on HTMLDocumentParser fix: https://codereview.chromium.org/532343002/

XMLHttpRequest and HTMLImport need callback when document has finished
parsing. This CL introduces an interface DocumentParserClient for receiving the
"parser stopped" notification, and migrates HTMLImportLoader to use the
interface.

BUG=409461

Review URL: https://codereview.chromium.org/535403002

git-svn-id: svn://svn.chromium.org/blink/trunk@181503 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 12c97dea
...@@ -4690,9 +4690,6 @@ void Document::finishedParsing() ...@@ -4690,9 +4690,6 @@ void Document::finishedParsing()
// Parser should have picked up all preloads by now // Parser should have picked up all preloads by now
m_fetcher->clearPreloads(); m_fetcher->clearPreloads();
if (HTMLImportLoader* import = importLoader())
import->didFinishParsing();
} }
void Document::elementDataCacheClearTimerFired(Timer<Document>*) void Document::elementDataCacheClearTimerFired(Timer<Document>*)
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "core/dom/DocumentParser.h" #include "core/dom/DocumentParser.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/dom/DocumentParserClient.h"
#include "core/html/parser/TextResourceDecoder.h" #include "core/html/parser/TextResourceDecoder.h"
#include "wtf/Assertions.h" #include "wtf/Assertions.h"
...@@ -53,6 +54,9 @@ DocumentParser::~DocumentParser() ...@@ -53,6 +54,9 @@ DocumentParser::~DocumentParser()
void DocumentParser::trace(Visitor* visitor) void DocumentParser::trace(Visitor* visitor)
{ {
visitor->trace(m_document); visitor->trace(m_document);
#if ENABLE(OILPAN)
visitor->trace(m_clients);
#endif
} }
void DocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder>) void DocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder>)
...@@ -74,6 +78,18 @@ void DocumentParser::prepareToStopParsing() ...@@ -74,6 +78,18 @@ void DocumentParser::prepareToStopParsing()
void DocumentParser::stopParsing() void DocumentParser::stopParsing()
{ {
m_state = StoppedState; m_state = StoppedState;
// Clients may be removed while in the loop. Make a snapshot for iteration.
WillBeHeapVector<RawPtrWillBeMember<DocumentParserClient> > clientsSnapshot;
copyToVector(m_clients, clientsSnapshot);
for (WillBeHeapVector<RawPtrWillBeMember<DocumentParserClient> >::const_iterator it = clientsSnapshot.begin(), itEnd = clientsSnapshot.end(); it != itEnd; ++it) {
DocumentParserClient* client = *it;
if (!m_clients.contains(client))
continue;
client->notifyParserStopped();
}
} }
void DocumentParser::detach() void DocumentParser::detach()
...@@ -90,5 +106,15 @@ void DocumentParser::resumeScheduledTasks() ...@@ -90,5 +106,15 @@ void DocumentParser::resumeScheduledTasks()
{ {
} }
void DocumentParser::addClient(DocumentParserClient* client)
{
m_clients.add(client);
}
void DocumentParser::removeClient(DocumentParserClient* client)
{
m_clients.remove(client);
}
}; };
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
namespace blink { namespace blink {
class Document; class Document;
class DocumentParserClient;
class SegmentedString; class SegmentedString;
class ScriptableDocumentParser; class ScriptableDocumentParser;
class TextResourceDecoder; class TextResourceDecoder;
...@@ -103,6 +104,9 @@ public: ...@@ -103,6 +104,9 @@ public:
virtual void suspendScheduledTasks(); virtual void suspendScheduledTasks();
virtual void resumeScheduledTasks(); virtual void resumeScheduledTasks();
void addClient(DocumentParserClient*);
void removeClient(DocumentParserClient*);
protected: protected:
explicit DocumentParser(Document*); explicit DocumentParser(Document*);
...@@ -121,6 +125,8 @@ private: ...@@ -121,6 +125,8 @@ private:
// Every DocumentParser needs a pointer back to the document. // Every DocumentParser needs a pointer back to the document.
// m_document will be 0 after the parser is stopped. // m_document will be 0 after the parser is stopped.
RawPtrWillBeMember<Document> m_document; RawPtrWillBeMember<Document> m_document;
WillBeHeapHashSet<RawPtrWillBeWeakMember<DocumentParserClient> > m_clients;
}; };
} // namespace blink } // namespace blink
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DocumentParserClient_h
#define DocumentParserClient_h
#include "platform/heap/Handle.h"
namespace blink {
class DocumentParserClient : public WillBeGarbageCollectedMixin {
public:
// This callback is called when all data pushed to parser has been consumed.
virtual void notifyParserStopped() = 0;
protected:
DocumentParserClient() { }
};
} // namespace blink
#endif // DocumentParserClient_h
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "core/html/imports/HTMLImportLoader.h" #include "core/html/imports/HTMLImportLoader.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/dom/DocumentParser.h"
#include "core/dom/StyleEngine.h" #include "core/dom/StyleEngine.h"
#include "core/dom/custom/CustomElementSyncMicrotaskQueue.h" #include "core/dom/custom/CustomElementSyncMicrotaskQueue.h"
#include "core/html/HTMLDocument.h" #include "core/html/HTMLDocument.h"
...@@ -116,6 +117,10 @@ HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceR ...@@ -116,6 +117,10 @@ HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceR
m_document = HTMLDocument::create(init); m_document = HTMLDocument::create(init);
m_writer = DocumentWriter::create(m_document.get(), response.mimeType(), "UTF-8"); m_writer = DocumentWriter::create(m_document.get(), response.mimeType(), "UTF-8");
DocumentParser* parser = m_document->parser();
ASSERT(parser);
parser->addClient(this);
return StateLoading; return StateLoading;
} }
...@@ -151,11 +156,15 @@ void HTMLImportLoader::setState(State state) ...@@ -151,11 +156,15 @@ void HTMLImportLoader::setState(State state)
didFinishLoading(); didFinishLoading();
} }
void HTMLImportLoader::didFinishParsing() void HTMLImportLoader::notifyParserStopped()
{ {
setState(finishParsing()); setState(finishParsing());
if (!hasPendingResources()) if (!hasPendingResources())
setState(finishLoading()); setState(finishLoading());
DocumentParser* parser = m_document->parser();
ASSERT(parser);
parser->removeClient(this);
} }
void HTMLImportLoader::didRemoveAllPendingStylesheet() void HTMLImportLoader::didRemoveAllPendingStylesheet()
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#ifndef HTMLImportLoader_h #ifndef HTMLImportLoader_h
#define HTMLImportLoader_h #define HTMLImportLoader_h
#include "core/dom/DocumentParserClient.h"
#include "core/fetch/RawResource.h" #include "core/fetch/RawResource.h"
#include "core/fetch/ResourceOwner.h" #include "core/fetch/ResourceOwner.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
...@@ -53,7 +54,7 @@ class HTMLImportsController; ...@@ -53,7 +54,7 @@ class HTMLImportsController;
// HTMLImportLoader is owned by HTMLImportsController. // HTMLImportLoader is owned by HTMLImportsController.
// //
// //
class HTMLImportLoader FINAL : public NoBaseWillBeGarbageCollectedFinalized<HTMLImportLoader>, public ResourceOwner<RawResource> { class HTMLImportLoader FINAL : public NoBaseWillBeGarbageCollectedFinalized<HTMLImportLoader>, public ResourceOwner<RawResource>, public DocumentParserClient {
public: public:
enum State { enum State {
StateLoading, StateLoading,
...@@ -88,9 +89,6 @@ public: ...@@ -88,9 +89,6 @@ public:
#endif #endif
void startLoading(const ResourcePtr<RawResource>&); void startLoading(const ResourcePtr<RawResource>&);
// Tells the loader that the parser is done with this import.
// Called by Document::finishedParsing, after DOMContentLoaded was dispatched.
void didFinishParsing();
// Tells the loader that all of the import's stylesheets finished // Tells the loader that all of the import's stylesheets finished
// loading. // loading.
// Called by Document::didRemoveAllPendingStylesheet. // Called by Document::didRemoveAllPendingStylesheet.
...@@ -108,6 +106,11 @@ private: ...@@ -108,6 +106,11 @@ private:
virtual void dataReceived(Resource*, const char* data, int length) OVERRIDE; virtual void dataReceived(Resource*, const char* data, int length) OVERRIDE;
virtual void notifyFinished(Resource*) OVERRIDE; virtual void notifyFinished(Resource*) OVERRIDE;
// DocumentParserClient
// Called after document parse is complete after DOMContentLoaded was dispatched.
virtual void notifyParserStopped();
State startWritingAndParsing(const ResourceResponse&); State startWritingAndParsing(const ResourceResponse&);
State finishWriting(); State finishWriting();
State finishParsing(); State finishParsing();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment