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

Side by Side Diff: Source/core/dom/Document.cpp

Issue 774033002: Run Microtasks before dispatching onload (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add comment Created 6 years 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
« no previous file with comments | « no previous file | 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #include "core/dom/DocumentLifecycleObserver.h" 70 #include "core/dom/DocumentLifecycleObserver.h"
71 #include "core/dom/DocumentMarkerController.h" 71 #include "core/dom/DocumentMarkerController.h"
72 #include "core/dom/DocumentType.h" 72 #include "core/dom/DocumentType.h"
73 #include "core/dom/Element.h" 73 #include "core/dom/Element.h"
74 #include "core/dom/ElementDataCache.h" 74 #include "core/dom/ElementDataCache.h"
75 #include "core/dom/ElementRegistrationOptions.h" 75 #include "core/dom/ElementRegistrationOptions.h"
76 #include "core/dom/ElementTraversal.h" 76 #include "core/dom/ElementTraversal.h"
77 #include "core/dom/ExceptionCode.h" 77 #include "core/dom/ExceptionCode.h"
78 #include "core/dom/ExecutionContextTask.h" 78 #include "core/dom/ExecutionContextTask.h"
79 #include "core/dom/MainThreadTaskRunner.h" 79 #include "core/dom/MainThreadTaskRunner.h"
80 #include "core/dom/Microtask.h"
80 #include "core/dom/MutationObserver.h" 81 #include "core/dom/MutationObserver.h"
81 #include "core/dom/NodeChildRemovalTracker.h" 82 #include "core/dom/NodeChildRemovalTracker.h"
82 #include "core/dom/NodeFilter.h" 83 #include "core/dom/NodeFilter.h"
83 #include "core/dom/NodeIterator.h" 84 #include "core/dom/NodeIterator.h"
84 #include "core/dom/NodeRareData.h" 85 #include "core/dom/NodeRareData.h"
85 #include "core/dom/NodeRenderStyle.h" 86 #include "core/dom/NodeRenderStyle.h"
86 #include "core/dom/NodeRenderingTraversal.h" 87 #include "core/dom/NodeRenderingTraversal.h"
87 #include "core/dom/NodeTraversal.h" 88 #include "core/dom/NodeTraversal.h"
88 #include "core/dom/NodeWithIndex.h" 89 #include "core/dom/NodeWithIndex.h"
89 #include "core/dom/ProcessingInstruction.h" 90 #include "core/dom/ProcessingInstruction.h"
(...skipping 4519 matching lines...) Expand 10 before | Expand all | Expand 10 after
4609 PassRefPtrWillBeRawPtr<DocumentNameCollection> Document::documentNamedItems(cons t AtomicString& name) 4610 PassRefPtrWillBeRawPtr<DocumentNameCollection> Document::documentNamedItems(cons t AtomicString& name)
4610 { 4611 {
4611 return ensureCachedCollection<DocumentNameCollection>(DocumentNamedItems, na me); 4612 return ensureCachedCollection<DocumentNameCollection>(DocumentNamedItems, na me);
4612 } 4613 }
4613 4614
4614 void Document::finishedParsing() 4615 void Document::finishedParsing()
4615 { 4616 {
4616 ASSERT(!scriptableDocumentParser() || !m_parser->isParsing()); 4617 ASSERT(!scriptableDocumentParser() || !m_parser->isParsing());
4617 ASSERT(!scriptableDocumentParser() || m_readyState != Loading); 4618 ASSERT(!scriptableDocumentParser() || m_readyState != Loading);
4618 setParsingState(InDOMContentLoaded); 4619 setParsingState(InDOMContentLoaded);
4620
4621 // FIXME: DOMContentLoaded should be dispatched in a queued task,
dominicc (has gone to gerrit) 2015/01/05 07:29:39 I think a good FIXME does three things: 1. Keeps
kouhei (in TOK) 2015/01/06 01:37:05 Done.
4622 // but we are dispatching this synchronously at the moment.
4623 // Spec: Section 12.2.6 "The end" step 4 and 5:
4624 // https://html.spec.whatwg.org/multipage/syntax.html#the-end
4625 // See https://crbug.com/425790
4619 if (!m_documentTiming.domContentLoadedEventStart) 4626 if (!m_documentTiming.domContentLoadedEventStart)
4620 m_documentTiming.domContentLoadedEventStart = monotonicallyIncreasingTim e(); 4627 m_documentTiming.domContentLoadedEventStart = monotonicallyIncreasingTim e();
4621 dispatchEvent(Event::createBubble(EventTypeNames::DOMContentLoaded)); 4628 dispatchEvent(Event::createBubble(EventTypeNames::DOMContentLoaded));
4622 if (!m_documentTiming.domContentLoadedEventEnd) 4629 if (!m_documentTiming.domContentLoadedEventEnd)
4623 m_documentTiming.domContentLoadedEventEnd = monotonicallyIncreasingTime( ); 4630 m_documentTiming.domContentLoadedEventEnd = monotonicallyIncreasingTime( );
4624 setParsingState(FinishedParsing); 4631 setParsingState(FinishedParsing);
4632 // Perform microtask checkpoint here as a partial fix to make this closer to spec.
4633 // FIXME: This should be removed once the above dispatchEvent(DOMContentLoad ed) is done asynchronously.
4634 // Spec: Section 12.2.6 "Spin the event loop" step 5 says we should spin the event loop here:
4635 // https://html.spec.whatwg.org/multipage/syntax.html#the-end
4636 // Spinning the event loop includes performing a microtask checkpoint:
4637 // https://html.spec.whatwg.org/multipage/webappapis.html#spin-the-event-loo p
4638 Microtask::performCheckpoint();
4625 4639
4626 // The loader's finishedParsing() method may invoke script that causes this object to 4640 // The loader's finishedParsing() method may invoke script that causes this object to
4627 // be dereferenced (when this document is in an iframe and the onload causes the iframe's src to change). 4641 // be dereferenced (when this document is in an iframe and the onload causes the iframe's src to change).
4628 // Keep it alive until we are done. 4642 // Keep it alive until we are done.
4629 RefPtrWillBeRawPtr<Document> protect(this); 4643 RefPtrWillBeRawPtr<Document> protect(this);
dominicc (has gone to gerrit) 2015/01/05 07:29:39 Why doesn't this protect need to be moved to befor
kouhei (in TOK) 2015/01/06 01:37:05 Done.
4630 4644
4631 if (RefPtrWillBeRawPtr<LocalFrame> frame = this->frame()) { 4645 if (RefPtrWillBeRawPtr<LocalFrame> frame = this->frame()) {
4632 // Don't update the render tree if we haven't requested the main resourc e yet to avoid 4646 // Don't update the render tree if we haven't requested the main resourc e yet to avoid
4633 // adding extra latency. Note that the first render tree update can be e xpensive since it 4647 // adding extra latency. Note that the first render tree update can be e xpensive since it
4634 // triggers the parsing of the default stylesheets which are compiled-in . 4648 // triggers the parsing of the default stylesheets which are compiled-in .
4635 const bool mainResourceWasAlreadyRequested = frame->loader().stateMachin e()->committedFirstRealDocumentLoad(); 4649 const bool mainResourceWasAlreadyRequested = frame->loader().stateMachin e()->committedFirstRealDocumentLoad();
4636 4650
4637 // FrameLoader::finishedParsing() might end up calling Document::implici tClose() if all 4651 // FrameLoader::finishedParsing() might end up calling Document::implici tClose() if all
4638 // resource loads are complete. HTMLObjectElements can start loading the ir resources from 4652 // resource loads are complete. HTMLObjectElements can start loading the ir resources from
4639 // post attach callbacks triggered by recalcStyle(). This means if we p arse out an <object> 4653 // post attach callbacks triggered by recalcStyle(). This means if we p arse out an <object>
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
5841 #ifndef NDEBUG 5855 #ifndef NDEBUG
5842 using namespace blink; 5856 using namespace blink;
5843 void showLiveDocumentInstances() 5857 void showLiveDocumentInstances()
5844 { 5858 {
5845 WeakDocumentSet& set = liveDocumentSet(); 5859 WeakDocumentSet& set = liveDocumentSet();
5846 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5860 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5847 for (Document* document : set) 5861 for (Document* document : set)
5848 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); 5862 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data());
5849 } 5863 }
5850 #endif 5864 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698