<!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>[214392] 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/214392">214392</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2017-03-24 18:13:23 -0700 (Fri, 24 Mar 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>media/restore-from-page-cache.html causes NoEventDispatchAssertion::isEventAllowedInMainThread() assertion failure
https://bugs.webkit.org/show_bug.cgi?id=170087
<rdar://problem/31254822>
Reviewed by Simon Fraser.
Reduce the scope of code that should never dispatch DOM events so as to allow updating contents size
after restoring a page from the page cache.
In <a href="http://trac.webkit.org/projects/webkit/changeset/214014">r214014</a> we instantiate a NoEventDispatchAssertion in FrameLoader::commitProvisionalLoad()
around the call to CachedPage::restore() to assert when a DOM event is dispatched during
page restoration as such events can cause re-entrancy into the page cache. As it turns out
it is sufficient to ensure that no DOM events are dispatched after restoring all cached frames
as opposed to after CachedPage::restore() returns.
Also rename Document::enqueue{Pageshow, Popstate}Event() to dispatch{Pageshow, Popstate}Event(),
respectively, since they synchronously dispatch events :(. We hope in the future to make them
asynchronously dispatch events.
* dom/Document.cpp:
(WebCore::Document::implicitClose): Update for renaming.
(WebCore::Document::statePopped): Ditto.
(WebCore::Document::dispatchPageshowEvent): Renamed; formerly named enqueuePageshowEvent().
(WebCore::Document::dispatchPopstateEvent): Renamed; formerly named enqueuePopstateEvent().
(WebCore::Document::enqueuePageshowEvent): Deleted.
(WebCore::Document::enqueuePopstateEvent): Deleted.
* dom/Document.h:
* history/CachedPage.cpp:
(WebCore::firePageShowAndPopStateEvents): Moved logic from FrameLoader::didRestoreFromCachedPage() to here.
(WebCore::CachedPage::restore): Modified to call firePageShowAndPopStateEvents().
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::commitProvisionalLoad): Removed use of NoEventDispatchAssertion RAII object. We
will instantiate it in CachedPage::restore() with a smaller scope.
(WebCore::FrameLoader::didRestoreFromCachedPage): Deleted; moved logic from here to WebCore::firePageShowAndPopStateEvents().
* loader/FrameLoader.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</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="#trunkSourceWebCorehistoryCachedPagecpp">trunk/Source/WebCore/history/CachedPage.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoadercpp">trunk/Source/WebCore/loader/FrameLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoaderh">trunk/Source/WebCore/loader/FrameLoader.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (214391 => 214392)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-03-25 01:04:32 UTC (rev 214391)
+++ trunk/Source/WebCore/ChangeLog        2017-03-25 01:13:23 UTC (rev 214392)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2017-03-24 Daniel Bates <dabates@apple.com>
+
+ media/restore-from-page-cache.html causes NoEventDispatchAssertion::isEventAllowedInMainThread() assertion failure
+ https://bugs.webkit.org/show_bug.cgi?id=170087
+ <rdar://problem/31254822>
+
+ Reviewed by Simon Fraser.
+
+ Reduce the scope of code that should never dispatch DOM events so as to allow updating contents size
+ after restoring a page from the page cache.
+
+ In r214014 we instantiate a NoEventDispatchAssertion in FrameLoader::commitProvisionalLoad()
+ around the call to CachedPage::restore() to assert when a DOM event is dispatched during
+ page restoration as such events can cause re-entrancy into the page cache. As it turns out
+ it is sufficient to ensure that no DOM events are dispatched after restoring all cached frames
+ as opposed to after CachedPage::restore() returns.
+
+ Also rename Document::enqueue{Pageshow, Popstate}Event() to dispatch{Pageshow, Popstate}Event(),
+ respectively, since they synchronously dispatch events :(. We hope in the future to make them
+ asynchronously dispatch events.
+
+ * dom/Document.cpp:
+ (WebCore::Document::implicitClose): Update for renaming.
+ (WebCore::Document::statePopped): Ditto.
+ (WebCore::Document::dispatchPageshowEvent): Renamed; formerly named enqueuePageshowEvent().
+ (WebCore::Document::dispatchPopstateEvent): Renamed; formerly named enqueuePopstateEvent().
+ (WebCore::Document::enqueuePageshowEvent): Deleted.
+ (WebCore::Document::enqueuePopstateEvent): Deleted.
+ * dom/Document.h:
+ * history/CachedPage.cpp:
+ (WebCore::firePageShowAndPopStateEvents): Moved logic from FrameLoader::didRestoreFromCachedPage() to here.
+ (WebCore::CachedPage::restore): Modified to call firePageShowAndPopStateEvents().
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::commitProvisionalLoad): Removed use of NoEventDispatchAssertion RAII object. We
+ will instantiate it in CachedPage::restore() with a smaller scope.
+ (WebCore::FrameLoader::didRestoreFromCachedPage): Deleted; moved logic from here to WebCore::firePageShowAndPopStateEvents().
+ * loader/FrameLoader.h:
+
</ins><span class="cx"> 2017-03-24 Ryan Haddad <ryanhaddad@apple.com>
</span><span class="cx">
</span><span class="cx"> Unreviewed, rolling out r214361.
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (214391 => 214392)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2017-03-25 01:04:32 UTC (rev 214391)
+++ trunk/Source/WebCore/dom/Document.cpp        2017-03-25 01:13:23 UTC (rev 214392)
</span><span class="lines">@@ -2644,9 +2644,9 @@
</span><span class="cx"> accessSVGExtensions().dispatchSVGLoadEventToOutermostSVGElements();
</span><span class="cx">
</span><span class="cx"> dispatchWindowLoadEvent();
</span><del>- enqueuePageshowEvent(PageshowEventNotPersisted);
</del><ins>+ dispatchPageshowEvent(PageshowEventNotPersisted);
</ins><span class="cx"> if (m_pendingStateObject)
</span><del>- enqueuePopstateEvent(WTFMove(m_pendingStateObject));
</del><ins>+ dispatchPopstateEvent(WTFMove(m_pendingStateObject));
</ins><span class="cx">
</span><span class="cx"> if (f)
</span><span class="cx"> f->loader().dispatchOnloadEvents();
</span><span class="lines">@@ -5235,7 +5235,7 @@
</span><span class="cx"> // Per step 11 of section 6.5.9 (history traversal) of the HTML5 spec, we
</span><span class="cx"> // defer firing of popstate until we're in the complete state.
</span><span class="cx"> if (m_readyState == Complete)
</span><del>- enqueuePopstateEvent(WTFMove(stateObject));
</del><ins>+ dispatchPopstateEvent(WTFMove(stateObject));
</ins><span class="cx"> else
</span><span class="cx"> m_pendingStateObject = WTFMove(stateObject);
</span><span class="cx"> }
</span><span class="lines">@@ -5460,7 +5460,7 @@
</span><span class="cx"> return String { string }.replace('\\', m_decoder->encoding().backslashAsCurrencySymbol());
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void Document::enqueuePageshowEvent(PageshowEventPersistence persisted)
</del><ins>+void Document::dispatchPageshowEvent(PageshowEventPersistence persisted)
</ins><span class="cx"> {
</span><span class="cx"> // FIXME: https://bugs.webkit.org/show_bug.cgi?id=36334 Pageshow event needs to fire asynchronously.
</span><span class="cx"> dispatchWindowEvent(PageTransitionEvent::create(eventNames().pageshowEvent, persisted), this);
</span><span class="lines">@@ -5471,7 +5471,7 @@
</span><span class="cx"> enqueueWindowEvent(HashChangeEvent::create(oldURL, newURL));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void Document::enqueuePopstateEvent(RefPtr<SerializedScriptValue>&& stateObject)
</del><ins>+void Document::dispatchPopstateEvent(RefPtr<SerializedScriptValue>&& stateObject)
</ins><span class="cx"> {
</span><span class="cx"> dispatchWindowEvent(PopStateEvent::create(WTFMove(stateObject), m_domWindow ? m_domWindow->history() : nullptr));
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (214391 => 214392)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2017-03-25 01:04:32 UTC (rev 214391)
+++ trunk/Source/WebCore/dom/Document.h        2017-03-25 01:13:23 UTC (rev 214392)
</span><span class="lines">@@ -1058,9 +1058,9 @@
</span><span class="cx"> void enqueueWindowEvent(Ref<Event>&&);
</span><span class="cx"> void enqueueDocumentEvent(Ref<Event>&&);
</span><span class="cx"> void enqueueOverflowEvent(Ref<Event>&&);
</span><del>- void enqueuePageshowEvent(PageshowEventPersistence);
</del><ins>+ void dispatchPageshowEvent(PageshowEventPersistence);
</ins><span class="cx"> void enqueueHashchangeEvent(const String& oldURL, const String& newURL);
</span><del>- void enqueuePopstateEvent(RefPtr<SerializedScriptValue>&& stateObject);
</del><ins>+ void dispatchPopstateEvent(RefPtr<SerializedScriptValue>&& stateObject);
</ins><span class="cx"> DocumentEventQueue& eventQueue() const final { return m_eventQueue; }
</span><span class="cx">
</span><span class="cx"> WEBCORE_EXPORT void addMediaCanStartListener(MediaCanStartListener*);
</span></span></pre></div>
<a id="trunkSourceWebCorehistoryCachedPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/history/CachedPage.cpp (214391 => 214392)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/history/CachedPage.cpp        2017-03-25 01:04:32 UTC (rev 214391)
+++ trunk/Source/WebCore/history/CachedPage.cpp        2017-03-25 01:13:23 UTC (rev 214392)
</span><span class="lines">@@ -30,9 +30,13 @@
</span><span class="cx"> #include "Element.h"
</span><span class="cx"> #include "FocusController.h"
</span><span class="cx"> #include "FrameView.h"
</span><ins>+#include "HistoryController.h"
+#include "HistoryItem.h"
</ins><span class="cx"> #include "MainFrame.h"
</span><ins>+#include "NoEventDispatchAssertion.h"
</ins><span class="cx"> #include "Node.h"
</span><span class="cx"> #include "Page.h"
</span><ins>+#include "PageTransitionEvent.h"
</ins><span class="cx"> #include "Settings.h"
</span><span class="cx"> #include "VisitedLinkState.h"
</span><span class="cx"> #include <wtf/CurrentTime.h>
</span><span class="lines">@@ -69,6 +73,31 @@
</span><span class="cx"> m_cachedMainFrame->destroy();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static void firePageShowAndPopStateEvents(Page& page)
+{
+ // Dispatching JavaScript events can cause frame destruction.
+ auto& mainFrame = page.mainFrame();
+ Vector<Ref<Frame>> childFrames;
+ for (auto* child = mainFrame.tree().traverseNextInPostOrderWithWrap(true); child; child = child->tree().traverseNextInPostOrderWithWrap(false))
+ childFrames.append(*child);
+
+ for (auto& child : childFrames) {
+ if (!child->tree().isDescendantOf(&mainFrame))
+ continue;
+ auto* document = child->document();
+ if (!document)
+ continue;
+
+ // FIXME: Update Page Visibility state here.
+ // https://bugs.webkit.org/show_bug.cgi?id=116770
+ document->dispatchPageshowEvent(PageshowEventPersisted);
+
+ auto* historyItem = child->loader().history().currentItem();
+ if (historyItem && historyItem->stateObject())
+ document->dispatchPopstateEvent(historyItem->stateObject());
+ }
+}
+
</ins><span class="cx"> void CachedPage::restore(Page& page)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(m_cachedMainFrame);
</span><span class="lines">@@ -75,7 +104,13 @@
</span><span class="cx"> ASSERT(m_cachedMainFrame->view()->frame().isMainFrame());
</span><span class="cx"> ASSERT(!page.subframeCount());
</span><span class="cx">
</span><del>- m_cachedMainFrame->open();
</del><ins>+ {
+ // Do not dispatch DOM events as their JavaScript listeners could cause the page to be put
+ // into the page cache before we have finished restoring it from the page cache.
+ NoEventDispatchAssertion noEventDispatchAssertion;
+
+ m_cachedMainFrame->open();
+ }
</ins><span class="cx">
</span><span class="cx"> // Restore the focus appearance for the focused element.
</span><span class="cx"> // FIXME: Right now we don't support pages w/ frames in the b/f cache. This may need to be tweaked when we add support for that.
</span><span class="lines">@@ -116,6 +151,8 @@
</span><span class="cx"> frameView->updateContentsSize();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ firePageShowAndPopStateEvents(page);
+
</ins><span class="cx"> clear();
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (214391 => 214392)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/FrameLoader.cpp        2017-03-25 01:04:32 UTC (rev 214391)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp        2017-03-25 01:13:23 UTC (rev 214392)
</span><span class="lines">@@ -86,7 +86,6 @@
</span><span class="cx"> #include "MainFrame.h"
</span><span class="cx"> #include "MemoryCache.h"
</span><span class="cx"> #include "MemoryRelease.h"
</span><del>-#include "NoEventDispatchAssertion.h"
</del><span class="cx"> #include "Page.h"
</span><span class="cx"> #include "PageCache.h"
</span><span class="cx"> #include "PageTransitionEvent.h"
</span><span class="lines">@@ -1866,19 +1865,11 @@
</span><span class="cx">
</span><span class="cx"> std::optional<HasInsecureContent> hasInsecureContent = cachedPage->cachedMainFrame()->hasInsecureContent();
</span><span class="cx">
</span><del>- {
- // Do not dispatch DOM events as their JavaScript listeners could cause the page to be put
- // into the page cache before we have finished restoring it from the page cache.
- NoEventDispatchAssertion assertNoEventDispatch;
</del><ins>+ // FIXME: This API should be turned around so that we ground CachedPage into the Page.
+ cachedPage->restore(*m_frame.page());
</ins><span class="cx">
</span><del>- // FIXME: This API should be turned around so that we ground CachedPage into the Page.
- cachedPage->restore(*m_frame.page());
- }
-
</del><span class="cx"> dispatchDidCommitLoad(hasInsecureContent);
</span><span class="cx">
</span><del>- didRestoreFromCachedPage();
-
</del><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> m_frame.page()->chrome().setDispatchViewportDataDidChangeSuppressed(false);
</span><span class="cx"> m_frame.page()->chrome().dispatchViewportPropertiesDidChange(m_frame.page()->viewportArguments());
</span><span class="lines">@@ -2112,31 +2103,6 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void FrameLoader::didRestoreFromCachedPage()
-{
- // Dispatching JavaScript events can cause frame destruction.
- auto& mainFrame = m_frame.page()->mainFrame();
- Vector<Ref<Frame>> childFrames;
- for (auto* child = mainFrame.tree().traverseNextInPostOrderWithWrap(true); child; child = child->tree().traverseNextInPostOrderWithWrap(false))
- childFrames.append(*child);
-
- for (auto& child : childFrames) {
- if (!child->tree().isDescendantOf(&mainFrame))
- continue;
- auto* document = child->document();
- if (!document)
- continue;
-
- // FIXME: Update Page Visibility state here.
- // https://bugs.webkit.org/show_bug.cgi?id=116770
- document->enqueuePageshowEvent(PageshowEventPersisted);
-
- auto* historyItem = child->loader().history().currentItem();
- if (historyItem && historyItem->stateObject())
- document->enqueuePopstateEvent(historyItem->stateObject());
- }
-}
-
</del><span class="cx"> void FrameLoader::open(CachedFrameBase& cachedFrame)
</span><span class="cx"> {
</span><span class="cx"> m_isComplete = false;
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoader.h (214391 => 214392)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/FrameLoader.h        2017-03-25 01:04:32 UTC (rev 214391)
+++ trunk/Source/WebCore/loader/FrameLoader.h        2017-03-25 01:13:23 UTC (rev 214392)
</span><span class="lines">@@ -347,7 +347,6 @@
</span><span class="cx">
</span><span class="cx"> void closeOldDataSources();
</span><span class="cx"> void willRestoreFromCachedPage();
</span><del>- void didRestoreFromCachedPage();
</del><span class="cx">
</span><span class="cx"> bool shouldReloadToHandleUnreachableURL(DocumentLoader*);
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>