<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[212614] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/212614">212614</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2017-02-19 04:12:07 -0800 (Sun, 19 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Execute pending scripts asynchronously after stylesheet loads complete
https://bugs.webkit.org/show_bug.cgi?id=168367
rdar://problem/30561379

Reviewed by Andreas Kling.

The current synchronous execution is fragile and creates various problems.

* css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::checkLoaded):
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::takeAllChildrenFrom):
(WebCore::ContainerNode::notifyChildInserted):
(WebCore::ContainerNode::removeChild):
(WebCore::ContainerNode::parserRemoveChild):
(WebCore::ContainerNode::removeChildren):

    Remove various places where we would trigger delayed synchronous execution.

* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::recalcStyle):

    Trigger scroll to anchor at the end of style resolution instead of when style sheet load completes.

(WebCore::Document::didRemoveAllPendingStylesheet):

    Call asynchronous script execution function.

* dom/Document.h:
(WebCore::Document::setNeedsNotifyRemoveAllPendingStylesheet): Deleted.
(WebCore::Document::notifyRemovePendingSheetIfNeeded): Deleted.
* dom/ScriptableDocumentParser.cpp:
(WebCore::ScriptableDocumentParser::ScriptableDocumentParser):
(WebCore::ScriptableDocumentParser::executeScriptsWaitingForStylesheetsSoon):
(WebCore::ScriptableDocumentParser::scriptsWaitingForStylesheetsExecutionTimerFired):

    Add a timer for executing pending scripts.

(WebCore::ScriptableDocumentParser::detach):
* dom/ScriptableDocumentParser.h:
(WebCore::ScriptableDocumentParser::executeScriptsWaitingForStylesheets):
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::removedFrom):
(WebCore::HTMLLinkElement::removePendingSheet):
* html/HTMLLinkElement.h:
* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::detach):
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::isLoadingInAPISense):

    Stay in loading state if we have a pending script. This matches existing behavior.

* style/StyleScope.cpp:
(WebCore::Style::Scope::removePendingSheet):
* style/StyleScope.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssStyleSheetContentscpp">trunk/Source/WebCore/css/StyleSheetContents.cpp</a></li>
<li><a href="#trunkSourceWebCoredomContainerNodecpp">trunk/Source/WebCore/dom/ContainerNode.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
<li><a href="#trunkSourceWebCoredomScriptableDocumentParsercpp">trunk/Source/WebCore/dom/ScriptableDocumentParser.cpp</a></li>
<li><a href="#trunkSourceWebCoredomScriptableDocumentParserh">trunk/Source/WebCore/dom/ScriptableDocumentParser.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLinkElementcpp">trunk/Source/WebCore/html/HTMLLinkElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLinkElementh">trunk/Source/WebCore/html/HTMLLinkElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLDocumentParsercpp">trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLDocumentParserh">trunk/Source/WebCore/html/parser/HTMLDocumentParser.h</a></li>
<li><a href="#trunkSourceWebCoreloaderDocumentLoadercpp">trunk/Source/WebCore/loader/DocumentLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoadercpp">trunk/Source/WebCore/loader/FrameLoader.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleScopecpp">trunk/Source/WebCore/style/StyleScope.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleScopeh">trunk/Source/WebCore/style/StyleScope.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/ChangeLog        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -1,3 +1,62 @@
</span><ins>+2017-02-19  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Execute pending scripts asynchronously after stylesheet loads complete
+        https://bugs.webkit.org/show_bug.cgi?id=168367
+        rdar://problem/30561379
+
+        Reviewed by Andreas Kling.
+
+        The current synchronous execution is fragile and creates various problems.
+
+        * css/StyleSheetContents.cpp:
+        (WebCore::StyleSheetContents::checkLoaded):
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::takeAllChildrenFrom):
+        (WebCore::ContainerNode::notifyChildInserted):
+        (WebCore::ContainerNode::removeChild):
+        (WebCore::ContainerNode::parserRemoveChild):
+        (WebCore::ContainerNode::removeChildren):
+
+            Remove various places where we would trigger delayed synchronous execution.
+
+        * dom/Document.cpp:
+        (WebCore::Document::Document):
+        (WebCore::Document::recalcStyle):
+
+            Trigger scroll to anchor at the end of style resolution instead of when style sheet load completes.
+
+        (WebCore::Document::didRemoveAllPendingStylesheet):
+
+            Call asynchronous script execution function.
+
+        * dom/Document.h:
+        (WebCore::Document::setNeedsNotifyRemoveAllPendingStylesheet): Deleted.
+        (WebCore::Document::notifyRemovePendingSheetIfNeeded): Deleted.
+        * dom/ScriptableDocumentParser.cpp:
+        (WebCore::ScriptableDocumentParser::ScriptableDocumentParser):
+        (WebCore::ScriptableDocumentParser::executeScriptsWaitingForStylesheetsSoon):
+        (WebCore::ScriptableDocumentParser::scriptsWaitingForStylesheetsExecutionTimerFired):
+
+            Add a timer for executing pending scripts.
+
+        (WebCore::ScriptableDocumentParser::detach):
+        * dom/ScriptableDocumentParser.h:
+        (WebCore::ScriptableDocumentParser::executeScriptsWaitingForStylesheets):
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::removedFrom):
+        (WebCore::HTMLLinkElement::removePendingSheet):
+        * html/HTMLLinkElement.h:
+        * html/parser/HTMLDocumentParser.cpp:
+        (WebCore::HTMLDocumentParser::detach):
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::isLoadingInAPISense):
+
+            Stay in loading state if we have a pending script. This matches existing behavior.
+
+        * style/StyleScope.cpp:
+        (WebCore::Style::Scope::removePendingSheet):
+        * style/StyleScope.h:
+
</ins><span class="cx"> 2017-02-18  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         &lt;input type=range readonly&gt; doesn't act per spec
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleSheetContentscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleSheetContents.cpp (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleSheetContents.cpp        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/css/StyleSheetContents.cpp        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -364,9 +364,6 @@
</span><span class="cx">     if (isLoading())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    // Avoid |this| being deleted by scripts that run via
-    // ScriptableDocumentParser::executeScriptsWaitingForStylesheets().
-    // See &lt;rdar://problem/6622300&gt;.
</del><span class="cx">     Ref&lt;StyleSheetContents&gt; protectedThis(*this);
</span><span class="cx">     StyleSheetContents* parentSheet = parentStyleSheet();
</span><span class="cx">     if (parentSheet) {
</span></span></pre></div>
<a id="trunkSourceWebCoredomContainerNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ContainerNode.cpp        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -145,8 +145,6 @@
</span><span class="cx">         childrenChanged(change);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    document().notifyRemovePendingSheetIfNeeded();
-
</del><span class="cx">     // FIXME: assert that we don't dispatch events here since this container node is still disconnected.
</span><span class="cx">     for (auto&amp; child : children) {
</span><span class="cx">         RELEASE_ASSERT(!child-&gt;parentNode() &amp;&amp; &amp;child-&gt;treeScope() == &amp;treeScope());
</span><span class="lines">@@ -364,9 +362,6 @@
</span><span class="cx"> 
</span><span class="cx">     childrenChanged(change);
</span><span class="cx"> 
</span><del>-    // Some call sites may have deleted child nodes. Calling it earlier results in bugs like webkit.org/b/168069.
-    document().notifyRemovePendingSheetIfNeeded();
-
</del><span class="cx">     for (auto&amp; target : postInsertionNotificationTargets)
</span><span class="cx">         target-&gt;finishedInsertingSubtree();
</span><span class="cx"> }
</span><span class="lines">@@ -554,7 +549,6 @@
</span><span class="cx">         notifyChildRemoved(child, prev, next, ChildChangeSourceAPI);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    document().notifyRemovePendingSheetIfNeeded();
</del><span class="cx">     rebuildSVGExtensionsElementsIfNecessary();
</span><span class="cx">     dispatchSubtreeModifiedEvent();
</span><span class="cx"> 
</span><span class="lines">@@ -615,7 +609,6 @@
</span><span class="cx">     removeBetween(prev, next, oldChild);
</span><span class="cx"> 
</span><span class="cx">     notifyChildRemoved(oldChild, prev, next, ChildChangeSourceParser);
</span><del>-    document().notifyRemovePendingSheetIfNeeded();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://dom.spec.whatwg.org/#concept-node-replace-all
</span><span class="lines">@@ -709,7 +702,6 @@
</span><span class="cx">         childrenChanged(change);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    document().notifyRemovePendingSheetIfNeeded();
</del><span class="cx">     rebuildSVGExtensionsElementsIfNecessary();
</span><span class="cx">     dispatchSubtreeModifiedEvent();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/dom/Document.cpp        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -443,7 +443,6 @@
</span><span class="cx">     , m_referencingNodeCount(0)
</span><span class="cx">     , m_settings(frame ? Ref&lt;Settings&gt;(frame-&gt;settings()) : Settings::create(nullptr))
</span><span class="cx">     , m_hasNodesWithPlaceholderStyle(false)
</span><del>-    , m_needsNotifyRemoveAllPendingStylesheet(false)
</del><span class="cx">     , m_ignorePendingStylesheets(false)
</span><span class="cx">     , m_pendingSheetLayout(NoLayoutWithPendingSheets)
</span><span class="cx">     , m_cachedResourceLoader(m_frame ? Ref&lt;CachedResourceLoader&gt;(m_frame-&gt;loader().activeDocumentLoader()-&gt;cachedResourceLoader()) : CachedResourceLoader::create(nullptr))
</span><span class="lines">@@ -1846,6 +1845,9 @@
</span><span class="cx">     // to check if any other elements ended up under the mouse pointer due to re-layout.
</span><span class="cx">     if (m_hoveredElement &amp;&amp; !m_hoveredElement-&gt;renderer())
</span><span class="cx">         frameView.frame().mainFrame().eventHandler().dispatchFakeMouseMoveEventSoon();
</span><ins>+
+    if (m_gotoAnchorNeededAfterStylesheetsLoad &amp;&amp; !styleScope().hasPendingSheets())
+        frameView.scrollToFragment(m_url);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool Document::needsStyleRecalc() const
</span><span class="lines">@@ -2623,7 +2625,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    m_frame-&gt;loader().checkCompleted();
</del><ins>+    checkCompleted();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Document::implicitClose()
</span><span class="lines">@@ -3073,19 +3075,17 @@
</span><span class="cx"> 
</span><span class="cx"> void Document::didRemoveAllPendingStylesheet()
</span><span class="cx"> {
</span><del>-    m_needsNotifyRemoveAllPendingStylesheet = false;
-
</del><span class="cx">     if (m_pendingSheetLayout == DidLayoutWithPendingSheets) {
</span><ins>+        // Painting is disabled when doing layouts with pending sheets to avoid FOUC.
+        // We need to force paint when coming out from this state.
+        // FIXME: This is not very elegant.
</ins><span class="cx">         m_pendingSheetLayout = IgnoreLayoutWithPendingSheets;
</span><span class="cx">         if (renderView())
</span><span class="cx">             renderView()-&gt;repaintViewAndCompositedLayers();
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (ScriptableDocumentParser* parser = scriptableDocumentParser())
-        parser-&gt;executeScriptsWaitingForStylesheets();
-
-    if (m_gotoAnchorNeededAfterStylesheetsLoad &amp;&amp; view())
-        view()-&gt;scrollToFragment(m_url);
</del><ins>+    if (auto* parser = scriptableDocumentParser())
+        parser-&gt;executeScriptsWaitingForStylesheetsSoon();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool Document::usesStyleBasedEditability() const
</span><span class="lines">@@ -6038,10 +6038,15 @@
</span><span class="cx"> 
</span><span class="cx"> void Document::loadEventDelayTimerFired()
</span><span class="cx"> {
</span><del>-    if (frame())
-        frame()-&gt;loader().checkCompleted();
</del><ins>+    checkCompleted();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Document::checkCompleted()
+{
+    if (auto* frame = this-&gt;frame())
+        frame-&gt;loader().checkCompleted();
+}
+
</ins><span class="cx"> double Document::monotonicTimestamp() const
</span><span class="cx"> {
</span><span class="cx">     auto* loader = this-&gt;loader();
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/dom/Document.h        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -486,8 +486,6 @@
</span><span class="cx"> 
</span><span class="cx">     CSSFontSelector&amp; fontSelector() { return m_fontSelector; }
</span><span class="cx"> 
</span><del>-    void notifyRemovePendingSheetIfNeeded();
-
</del><span class="cx">     WEBCORE_EXPORT bool haveStylesheetsLoaded() const;
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT StyleSheetList&amp; styleSheets();
</span><span class="lines">@@ -1116,6 +1114,7 @@
</span><span class="cx">     void incrementLoadEventDelayCount() { ++m_loadEventDelayCount; }
</span><span class="cx">     void decrementLoadEventDelayCount();
</span><span class="cx">     bool isDelayingLoadEvent() const { return m_loadEventDelayCount; }
</span><ins>+    void checkCompleted();
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(IOS_TOUCH_EVENTS)
</span><span class="cx"> #include &lt;WebKitAdditions/DocumentIOS.h&gt;
</span><span class="lines">@@ -1206,7 +1205,6 @@
</span><span class="cx">     DocumentSharedObjectPool* sharedObjectPool() { return m_sharedObjectPool.get(); }
</span><span class="cx"> 
</span><span class="cx">     void didRemoveAllPendingStylesheet();
</span><del>-    void setNeedsNotifyRemoveAllPendingStylesheet() { m_needsNotifyRemoveAllPendingStylesheet = true; }
</del><span class="cx">     void didClearStyleResolver();
</span><span class="cx"> 
</span><span class="cx">     bool inStyleRecalc() const { return m_inStyleRecalc; }
</span><span class="lines">@@ -1391,7 +1389,6 @@
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;StyleResolver&gt; m_userAgentShadowTreeStyleResolver;
</span><span class="cx">     bool m_hasNodesWithPlaceholderStyle;
</span><del>-    bool m_needsNotifyRemoveAllPendingStylesheet;
</del><span class="cx">     // But sometimes you need to ignore pending stylesheet count to
</span><span class="cx">     // force an immediate layout when requested by JS.
</span><span class="cx">     bool m_ignorePendingStylesheets;
</span><span class="lines">@@ -1757,12 +1754,6 @@
</span><span class="cx"> 
</span><span class="cx"> Element* eventTargetElementForDocument(Document*);
</span><span class="cx"> 
</span><del>-inline void Document::notifyRemovePendingSheetIfNeeded()
-{
-    if (m_needsNotifyRemoveAllPendingStylesheet)
-        didRemoveAllPendingStylesheet();
-}
-
</del><span class="cx"> inline TextEncoding Document::textEncoding() const
</span><span class="cx"> {
</span><span class="cx">     if (auto* decoder = this-&gt;decoder())
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptableDocumentParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptableDocumentParser.cpp (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptableDocumentParser.cpp        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/dom/ScriptableDocumentParser.cpp        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;Document.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><ins>+#include &quot;StyleScope.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -35,6 +36,7 @@
</span><span class="cx">     : DecodedDataDocumentParser(document)
</span><span class="cx">     , m_wasCreatedByScript(false)
</span><span class="cx">     , m_parserContentPolicy(parserContentPolicy)
</span><ins>+    , m_scriptsWaitingForStylesheetsExecutionTimer(*this, &amp;ScriptableDocumentParser::scriptsWaitingForStylesheetsExecutionTimerFired)
</ins><span class="cx"> {
</span><span class="cx">     if (!pluginContentIsAllowed(m_parserContentPolicy))
</span><span class="cx">         m_parserContentPolicy = allowPluginContent(m_parserContentPolicy);
</span><span class="lines">@@ -43,4 +45,36 @@
</span><span class="cx">         m_parserContentPolicy = disallowScriptingContent(m_parserContentPolicy);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ScriptableDocumentParser::executeScriptsWaitingForStylesheetsSoon()
+{
+    ASSERT(!document()-&gt;styleScope().hasPendingSheets());
+
+    if (m_scriptsWaitingForStylesheetsExecutionTimer.isActive())
+        return;
+    if (!hasScriptsWaitingForStylesheets())
+        return;
+
+    m_scriptsWaitingForStylesheetsExecutionTimer.startOneShot(0);
+}
+
+void ScriptableDocumentParser::scriptsWaitingForStylesheetsExecutionTimerFired()
+{
+    ASSERT(!isDetached());
+
+    Ref&lt;ScriptableDocumentParser&gt; protectedThis(*this);
+
+    if (!document()-&gt;styleScope().hasPendingSheets())
+        executeScriptsWaitingForStylesheets();
+
+    if (!isDetached())
+        document()-&gt;checkCompleted();
+}
+
+void ScriptableDocumentParser::detach()
+{
+    m_scriptsWaitingForStylesheetsExecutionTimer.stop();
+
+    DecodedDataDocumentParser::detach();
+}
+
</ins><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptableDocumentParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptableDocumentParser.h (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptableDocumentParser.h        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/dom/ScriptableDocumentParser.h        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;DecodedDataDocumentParser.h&quot;
</span><span class="cx"> #include &quot;FragmentScriptingPermission.h&quot;
</span><ins>+#include &quot;Timer.h&quot;
</ins><span class="cx"> #include &lt;wtf/text/TextPosition.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -37,14 +38,14 @@
</span><span class="cx">     // JavaScript document.open() call right now, or it should be ignored.
</span><span class="cx">     virtual bool isExecutingScript() const { return false; }
</span><span class="cx"> 
</span><del>-    // FIXME: Only the HTMLDocumentParser ever blocks script execution on
-    // stylesheet load, which is likely a bug in the XMLDocumentParser.
-    virtual void executeScriptsWaitingForStylesheets() { }
-
</del><span class="cx">     virtual bool isWaitingForScripts() const = 0;
</span><span class="cx"> 
</span><span class="cx">     virtual TextPosition textPosition() const = 0;
</span><span class="cx"> 
</span><ins>+    virtual bool hasScriptsWaitingForStylesheets() const { return false; }
+
+    void executeScriptsWaitingForStylesheetsSoon();
+
</ins><span class="cx">     // Returns true if the parser didn't yield or pause or synchronously execute a script,
</span><span class="cx">     // so calls to PageConsoleClient should be associated with the parser's text position.
</span><span class="cx">     virtual bool shouldAssociateConsoleMessagesWithTextPosition() const = 0;
</span><span class="lines">@@ -57,12 +58,19 @@
</span><span class="cx"> protected:
</span><span class="cx">     explicit ScriptableDocumentParser(Document&amp;, ParserContentPolicy = AllowScriptingContent);
</span><span class="cx"> 
</span><ins>+    virtual void executeScriptsWaitingForStylesheets() { }
+
+    void detach() override;
+
</ins><span class="cx"> private:
</span><span class="cx">     ScriptableDocumentParser* asScriptableDocumentParser() final { return this; }
</span><span class="cx"> 
</span><ins>+    void scriptsWaitingForStylesheetsExecutionTimerFired();
+
</ins><span class="cx">     // http://www.whatwg.org/specs/web-apps/current-work/#script-created-parser
</span><span class="cx">     bool m_wasCreatedByScript;
</span><span class="cx">     ParserContentPolicy m_parserContentPolicy;
</span><ins>+    Timer m_scriptsWaitingForStylesheetsExecutionTimer;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLinkElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLinkElement.cpp        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -327,7 +327,7 @@
</span><span class="cx">         clearSheet();
</span><span class="cx"> 
</span><span class="cx">     if (styleSheetIsLoading())
</span><del>-        removePendingSheet(RemovePendingSheetNotifyLater);
</del><ins>+        removePendingSheet();
</ins><span class="cx">     
</span><span class="cx">     if (m_styleScope) {
</span><span class="cx">         m_styleScope-&gt;removeStyleSheetCandidateNode(*this);
</span><span class="lines">@@ -554,7 +554,7 @@
</span><span class="cx">     m_styleScope-&gt;addPendingSheet();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void HTMLLinkElement::removePendingSheet(RemovePendingSheetNotificationType notification)
</del><ins>+void HTMLLinkElement::removePendingSheet()
</ins><span class="cx"> {
</span><span class="cx">     PendingSheetType type = m_pendingSheetType;
</span><span class="cx">     m_pendingSheetType = Unknown;
</span><span class="lines">@@ -569,10 +569,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    m_styleScope-&gt;removePendingSheet(
-        notification == RemovePendingSheetNotifyImmediately
-        ? Style::Scope::RemovePendingSheetNotifyImmediately
-        : Style::Scope::RemovePendingSheetNotifyLater);
</del><ins>+    m_styleScope-&gt;removePendingSheet();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLinkElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLinkElement.h (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLinkElement.h        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/html/HTMLLinkElement.h        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -111,13 +111,8 @@
</span><span class="cx">     enum PendingSheetType { Unknown, ActiveSheet, InactiveSheet };
</span><span class="cx">     void addPendingSheet(PendingSheetType);
</span><span class="cx"> 
</span><del>-    enum RemovePendingSheetNotificationType {
-        RemovePendingSheetNotifyImmediately,
-        RemovePendingSheetNotifyLater
-    };
</del><ins>+    void removePendingSheet();
</ins><span class="cx"> 
</span><del>-    void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSheetNotifyImmediately);
-
</del><span class="cx">     LinkLoader m_linkLoader;
</span><span class="cx">     Style::Scope* m_styleScope { nullptr };
</span><span class="cx">     CachedResourceHandle&lt;CachedCSSStyleSheet&gt; m_cachedSheet;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLDocumentParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -87,7 +87,7 @@
</span><span class="cx"> 
</span><span class="cx"> void HTMLDocumentParser::detach()
</span><span class="cx"> {
</span><del>-    DocumentParser::detach();
</del><ins>+    ScriptableDocumentParser::detach();
</ins><span class="cx"> 
</span><span class="cx">     if (m_scriptRunner)
</span><span class="cx">         m_scriptRunner-&gt;detach();
</span><span class="lines">@@ -538,6 +538,11 @@
</span><span class="cx">         resumeParsingAfterScriptExecution();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool HTMLDocumentParser::hasScriptsWaitingForStylesheets() const
+{
+    return m_scriptRunner &amp;&amp; m_scriptRunner-&gt;hasScriptsWaitingForStylesheets();
+}
+
</ins><span class="cx"> void HTMLDocumentParser::executeScriptsWaitingForStylesheets()
</span><span class="cx"> {
</span><span class="cx">     // Document only calls this when the Document owns the DocumentParser
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLDocumentParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.h (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.h        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.h        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -83,6 +83,7 @@
</span><span class="cx">     void stopParsing() final;
</span><span class="cx">     bool isWaitingForScripts() const override;
</span><span class="cx">     bool isExecutingScript() const final;
</span><ins>+    bool hasScriptsWaitingForStylesheets() const final;
</ins><span class="cx">     void executeScriptsWaitingForStylesheets() final;
</span><span class="cx">     void suspendScheduledTasks() final;
</span><span class="cx">     void resumeScheduledTasks() final;
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderDocumentLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/DocumentLoader.cpp        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -68,6 +68,7 @@
</span><span class="cx"> #include &quot;ResourceHandle.h&quot;
</span><span class="cx"> #include &quot;ResourceLoadObserver.h&quot;
</span><span class="cx"> #include &quot;SchemeRegistry.h&quot;
</span><ins>+#include &quot;ScriptableDocumentParser.h&quot;
</ins><span class="cx"> #include &quot;SecurityPolicy.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="cx"> #include &quot;SubresourceLoader.h&quot;
</span><span class="lines">@@ -1057,6 +1058,9 @@
</span><span class="cx">             return true;
</span><span class="cx">         if (document.hasActiveParser())
</span><span class="cx">             return true;
</span><ins>+        auto* scriptableParser = document.scriptableDocumentParser();
+        if (scriptableParser &amp;&amp; scriptableParser-&gt;hasScriptsWaitingForStylesheets())
+            return true;
</ins><span class="cx">     }
</span><span class="cx">     return frameLoader()-&gt;subframeIsLoading();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/FrameLoader.cpp        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -787,6 +787,10 @@
</span><span class="cx">     if (m_frame.document()-&gt;isDelayingLoadEvent())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    auto* scriptableParser = m_frame.document()-&gt;scriptableDocumentParser();
+    if (scriptableParser &amp;&amp; scriptableParser-&gt;hasScriptsWaitingForStylesheets())
+        return;
+
</ins><span class="cx">     // Any frame that hasn't completed yet?
</span><span class="cx">     if (!allChildrenAreComplete())
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleScopecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleScope.cpp (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleScope.cpp        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/style/StyleScope.cpp        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -170,7 +170,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // This method is called whenever a top-level stylesheet has finished loading.
</span><del>-void Scope::removePendingSheet(RemovePendingSheetNotificationType notification)
</del><ins>+void Scope::removePendingSheet()
</ins><span class="cx"> {
</span><span class="cx">     // Make sure we knew this sheet was pending, and that our count isn't out of sync.
</span><span class="cx">     ASSERT(m_pendingStyleSheetCount &gt; 0);
</span><span class="lines">@@ -179,11 +179,6 @@
</span><span class="cx">     if (m_pendingStyleSheetCount)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (notification == RemovePendingSheetNotifyLater) {
-        m_document.setNeedsNotifyRemoveAllPendingStylesheet();
-        return;
-    }
-
</del><span class="cx">     didChangeActiveStyleSheetCandidates();
</span><span class="cx"> 
</span><span class="cx">     if (!m_shadowRoot)
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleScopeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleScope.h (212613 => 212614)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleScope.h        2017-02-19 11:54:36 UTC (rev 212613)
+++ trunk/Source/WebCore/style/StyleScope.h        2017-02-19 12:12:07 UTC (rev 212614)
</span><span class="lines">@@ -82,11 +82,7 @@
</span><span class="cx">     void setSelectedStylesheetSetName(const String&amp;);
</span><span class="cx"> 
</span><span class="cx">     void addPendingSheet() { m_pendingStyleSheetCount++; }
</span><del>-    enum RemovePendingSheetNotificationType {
-        RemovePendingSheetNotifyImmediately,
-        RemovePendingSheetNotifyLater
-    };
-    void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSheetNotifyImmediately);
</del><ins>+    void removePendingSheet();
</ins><span class="cx"> 
</span><span class="cx">     bool hasPendingSheets() const { return m_pendingStyleSheetCount &gt; 0; }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>