<!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>[248244] releases/WebKitGTK/webkit-2.24/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/248244">248244</a></dd>
<dt>Author</dt> <dd>mcatanzaro@igalia.com</dd>
<dt>Date</dt> <dd>2019-08-03 20:23:42 -0700 (Sat, 03 Aug 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/247017">r247017</a> - More judiciously handle clearing/creation of DOMWindows for new Documents.
<rdar://problem/51665406> and https://bugs.webkit.org/show_bug.cgi?id=198786

Reviewed by Chris Dumez.

* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::executeIfJavaScriptURL):

* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::replaceDocumentWithResultOfExecutingJavascriptURL): Rename for clarity.
(WebCore::DocumentWriter::begin): Handle DOMWindow taking/creation inside FrameLoader::clear via a lambda.
(WebCore::DocumentWriter::replaceDocument): Deleted.
* loader/DocumentWriter.h:

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::clear): Take a "handleDOMWindowCreation" lambda to run after clearing the previous document.
* loader/FrameLoader.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit224SourceWebCoreChangeLog">releases/WebKitGTK/webkit-2.24/Source/WebCore/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit224SourceWebCorebindingsjsScriptControllercpp">releases/WebKitGTK/webkit-2.24/Source/WebCore/bindings/js/ScriptController.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit224SourceWebCoreloaderDocumentWritercpp">releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/DocumentWriter.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit224SourceWebCoreloaderDocumentWriterh">releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/DocumentWriter.h</a></li>
<li><a href="#releasesWebKitGTKwebkit224SourceWebCoreloaderFrameLoadercpp">releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/FrameLoader.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit224SourceWebCoreloaderFrameLoaderh">releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/FrameLoader.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit224SourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/ChangeLog (248243 => 248244)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.24/Source/WebCore/ChangeLog  2019-08-04 03:23:39 UTC (rev 248243)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/ChangeLog     2019-08-04 03:23:42 UTC (rev 248244)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2019-07-01  Brady Eidson  <beidson@apple.com>
+
+        More judiciously handle clearing/creation of DOMWindows for new Documents.
+        <rdar://problem/51665406> and https://bugs.webkit.org/show_bug.cgi?id=198786
+
+        Reviewed by Chris Dumez.
+
+        * bindings/js/ScriptController.cpp:
+        (WebCore::ScriptController::executeIfJavaScriptURL):
+
+        * loader/DocumentWriter.cpp:
+        (WebCore::DocumentWriter::replaceDocumentWithResultOfExecutingJavascriptURL): Rename for clarity.
+        (WebCore::DocumentWriter::begin): Handle DOMWindow taking/creation inside FrameLoader::clear via a lambda. 
+        (WebCore::DocumentWriter::replaceDocument): Deleted.
+        * loader/DocumentWriter.h:
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::clear): Take a "handleDOMWindowCreation" lambda to run after clearing the previous document.
+        * loader/FrameLoader.h:
+
</ins><span class="cx"> 2019-06-26  Ryosuke Niwa  <rniwa@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         ReplacementFragment should not have script observable side effects
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit224SourceWebCorebindingsjsScriptControllercpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/bindings/js/ScriptController.cpp (248243 => 248244)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.24/Source/WebCore/bindings/js/ScriptController.cpp   2019-08-04 03:23:39 UTC (rev 248243)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/bindings/js/ScriptController.cpp      2019-08-04 03:23:42 UTC (rev 248244)
</span><span class="lines">@@ -626,7 +626,7 @@
</span><span class="cx">         // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref'ed and possible destroyed,
</span><span class="cx">         // so protect it with a RefPtr.
</span><span class="cx">         if (RefPtr<DocumentLoader> loader = m_frame.document()->loader())
</span><del>-            loader->writer().replaceDocument(scriptResult, ownerDocument.get());
</del><ins>+            loader->writer().replaceDocumentWithResultOfExecutingJavascriptURL(scriptResult, ownerDocument.get());
</ins><span class="cx">     }
</span><span class="cx">     return true;
</span><span class="cx"> }
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit224SourceWebCoreloaderDocumentWritercpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/DocumentWriter.cpp (248243 => 248244)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/DocumentWriter.cpp  2019-08-04 03:23:39 UTC (rev 248243)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/DocumentWriter.cpp     2019-08-04 03:23:42 UTC (rev 248244)
</span><span class="lines">@@ -61,7 +61,7 @@
</span><span class="cx"> // This is only called by ScriptController::executeIfJavaScriptURL
</span><span class="cx"> // and always contains the result of evaluating a javascript: url.
</span><span class="cx"> // This is the <iframe src="javascript:'html'"> case.
</span><del>-void DocumentWriter::replaceDocument(const String& source, Document* ownerDocument)
</del><ins>+void DocumentWriter::replaceDocumentWithResultOfExecutingJavascriptURL(const String& source, Document* ownerDocument)
</ins><span class="cx"> {
</span><span class="cx">     m_frame->loader().stopAllLoaders();
</span><span class="cx"> 
</span><span class="lines">@@ -137,10 +137,6 @@
</span><span class="cx">     // FIXME: Do we need to consult the content security policy here about blocked plug-ins?
</span><span class="cx"> 
</span><span class="cx">     bool shouldReuseDefaultView = m_frame->loader().stateMachine().isDisplayingInitialEmptyDocument() && m_frame->document()->isSecureTransitionTo(url);
</span><del>-    if (shouldReuseDefaultView)
-        document->takeDOMWindowFrom(*m_frame->document());
-    else
-        document->createDOMWindow();
</del><span class="cx"> 
</span><span class="cx">     // Temporarily extend the lifetime of the existing document so that FrameLoader::clear() doesn't destroy it as
</span><span class="cx">     // we need to retain its ongoing set of upgraded requests in new navigation contexts per <http://www.w3.org/TR/upgrade-insecure-requests/>
</span><span class="lines">@@ -148,7 +144,14 @@
</span><span class="cx">     RefPtr<Document> existingDocument = m_frame->document();
</span><span class="cx">     auto* previousContentSecurityPolicy = existingDocument ? existingDocument->contentSecurityPolicy() : nullptr;
</span><span class="cx"> 
</span><del>-    m_frame->loader().clear(document.ptr(), !shouldReuseDefaultView, !shouldReuseDefaultView);
</del><ins>+    WTF::Function<void()> handleDOMWindowCreation = [this, document = document.copyRef(), url] {
+        if (m_frame->loader().stateMachine().isDisplayingInitialEmptyDocument() && m_frame->document()->isSecureTransitionTo(url))
+            document->takeDOMWindowFrom(*m_frame->document());
+        else
+            document->createDOMWindow();
+    };
+
+    m_frame->loader().clear(document.ptr(), !shouldReuseDefaultView, !shouldReuseDefaultView, true, WTFMove(handleDOMWindowCreation));
</ins><span class="cx">     clear();
</span><span class="cx"> 
</span><span class="cx">     // m_frame->loader().clear() might fire unload event which could remove the view of the document.
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit224SourceWebCoreloaderDocumentWriterh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/DocumentWriter.h (248243 => 248244)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/DocumentWriter.h    2019-08-04 03:23:39 UTC (rev 248243)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/DocumentWriter.h       2019-08-04 03:23:42 UTC (rev 248244)
</span><span class="lines">@@ -42,9 +42,7 @@
</span><span class="cx"> public:
</span><span class="cx">     DocumentWriter() = default;
</span><span class="cx"> 
</span><del>-    // This is only called by ScriptController::executeIfJavaScriptURL
-    // and always contains the result of evaluating a javascript: url.
-    void replaceDocument(const String&, Document* ownerDocument);
</del><ins>+    void replaceDocumentWithResultOfExecutingJavascriptURL(const String&, Document* ownerDocument);
</ins><span class="cx"> 
</span><span class="cx">     bool begin();
</span><span class="cx">     bool begin(const URL&, bool dispatchWindowObjectAvailable = true, Document* ownerDocument = nullptr);
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit224SourceWebCoreloaderFrameLoadercpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/FrameLoader.cpp (248243 => 248244)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/FrameLoader.cpp     2019-08-04 03:23:39 UTC (rev 248243)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/FrameLoader.cpp        2019-08-04 03:23:42 UTC (rev 248244)
</span><span class="lines">@@ -623,15 +623,14 @@
</span><span class="cx">     return !newDocument.securityOrigin().isSameOriginAs(frame.document()->securityOrigin());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void FrameLoader::clear(Document* newDocument, bool clearWindowProperties, bool clearScriptObjects, bool clearFrameView)
</del><ins>+void FrameLoader::clear(Document* newDocument, bool clearWindowProperties, bool clearScriptObjects, bool clearFrameView, WTF::Function<void()>&& handleDOMWindowCreation)
</ins><span class="cx"> {
</span><span class="cx">     m_frame.editor().clear();
</span><span class="cx"> 
</span><del>-    if (!m_needsClear)
-        return;
</del><ins>+    bool neededClear = m_needsClear;
</ins><span class="cx">     m_needsClear = false;
</span><del>-    
-    if (m_frame.document()->pageCacheState() != Document::InPageCache) {
</del><ins>+
+    if (neededClear && m_frame.document()->pageCacheState() != Document::InPageCache) {
</ins><span class="cx">         m_frame.document()->cancelParsing();
</span><span class="cx">         m_frame.document()->stopActiveDOMObjects();
</span><span class="cx">         bool hadLivingRenderTree = m_frame.document()->hasLivingRenderTree();
</span><span class="lines">@@ -640,6 +639,12 @@
</span><span class="cx">             m_frame.document()->adjustFocusedNodeOnNodeRemoval(*m_frame.document());
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    if (handleDOMWindowCreation)
+        handleDOMWindowCreation();
+
+    if (!neededClear)
+        return;
+    
</ins><span class="cx">     // Do this after detaching the document so that the unload event works.
</span><span class="cx">     if (clearWindowProperties) {
</span><span class="cx">         InspectorInstrumentation::frameWindowDiscarded(m_frame, m_frame.document()->domWindow());
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit224SourceWebCoreloaderFrameLoaderh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/FrameLoader.h (248243 => 248244)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/FrameLoader.h       2019-08-04 03:23:39 UTC (rev 248243)
+++ releases/WebKitGTK/webkit-2.24/Source/WebCore/loader/FrameLoader.h  2019-08-04 03:23:42 UTC (rev 248244)
</span><span class="lines">@@ -152,7 +152,7 @@
</span><span class="cx">     void cancelAndClear();
</span><span class="cx">     void clearProvisionalLoadForPolicyCheck();
</span><span class="cx">     // FIXME: clear() is trying to do too many things. We should break it down into smaller functions (ideally with fewer raw Boolean parameters).
</span><del>-    void clear(Document* newDocument, bool clearWindowProperties = true, bool clearScriptObjects = true, bool clearFrameView = true);
</del><ins>+    void clear(Document* newDocument, bool clearWindowProperties = true, bool clearScriptObjects = true, bool clearFrameView = true, WTF::Function<void()>&& handleDOMWindowCreation = nullptr);
</ins><span class="cx"> 
</span><span class="cx">     bool isLoading() const;
</span><span class="cx">     WEBCORE_EXPORT bool frameHasLoaded() const;
</span></span></pre>
</div>
</div>

</body>
</html>