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

Unified Diff: Source/core/dom/Document.cpp

Issue 672843002: Delay dispatching DOMContentLoaded event to next event loop. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: hmm Created 6 years, 2 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
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/loader/FrameLoader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index 69ac933bf334b8c45e8b1a1b1cc96dcf5aafa332..d80c52c0538aa4b1a946befef87b8e4043bfdb14 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -453,6 +453,8 @@ Document::Document(const DocumentInit& initializer, DocumentClassFlags documentC
, m_paginatedForScreen(false)
, m_compatibilityMode(NoQuirksMode)
, m_compatibilityModeLocked(false)
+ , m_hasFiredDOMContentLoadedEvent(false)
+ , m_dispatchDOMContentLoadedTimer(this, &Document::dispatchDOMContentLoadedTimerFired)
, m_executeScriptsWaitingForResourcesTimer(this, &Document::executeScriptsWaitingForResourcesTimerFired)
, m_hasAutofocused(false)
, m_clearFocusedElementTimer(this, &Document::clearFocusedElementTimerFired)
@@ -4609,17 +4611,33 @@ PassRefPtrWillBeRawPtr<DocumentNameCollection> Document::documentNamedItems(cons
return ensureCachedCollection<DocumentNameCollection>(DocumentNamedItems, name);
}
-void Document::finishedParsing()
+void Document::dispatchDOMContentLoadedTimerFired(Timer<Document>*)
{
- ASSERT(!scriptableDocumentParser() || !m_parser->isParsing());
- ASSERT(!scriptableDocumentParser() || m_readyState != Loading);
- setParsing(false);
if (!m_documentTiming.domContentLoadedEventStart)
m_documentTiming.domContentLoadedEventStart = monotonicallyIncreasingTime();
dispatchEvent(Event::createBubble(EventTypeNames::DOMContentLoaded));
if (!m_documentTiming.domContentLoadedEventEnd)
m_documentTiming.domContentLoadedEventEnd = monotonicallyIncreasingTime();
+ m_hasFiredDOMContentLoadedEvent = true;
+
+ if (RefPtrWillBeRawPtr<LocalFrame> frame = this->frame()) {
+ TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "MarkDOMContent", "data", InspectorMarkLoadEvent::data(frame.get()));
+ // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
+ InspectorInstrumentation::domContentLoadedEventFired(frame.get());
+
+ frame->loader().checkLoadComplete();
+ }
+}
+
+// FIXME: Document should be a DocumentParserClient and this should be replaced with its notifyParserStopped() callback
+void Document::finishedParsing()
+{
+ ASSERT(!scriptableDocumentParser() || !m_parser->isParsing());
+ ASSERT(!scriptableDocumentParser() || m_readyState != Loading);
+ setParsing(false);
+ m_dispatchDOMContentLoadedTimer.startOneShot(0, FROM_HERE);
+
// The loader's finishedParsing() method may invoke script that causes this object to
// be dereferenced (when this document is in an iframe and the onload causes the iframe's src to change).
// Keep it alive until we are done.
@@ -4642,10 +4660,6 @@ void Document::finishedParsing()
updateRenderTreeIfNeeded();
frame->loader().finishedParsing();
-
- TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "MarkDOMContent", "data", InspectorMarkLoadEvent::data(frame.get()));
- // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
- InspectorInstrumentation::domContentLoadedEventFired(frame.get());
}
// Schedule dropping of the ElementDataCache. We keep it alive for a while after parsing finishes
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/loader/FrameLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698