Detach frame from document when entering page cache
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Feb 2017 02:53:53 +0000 (02:53 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Feb 2017 02:53:53 +0000 (02:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166774
<rdar://problem/29904368>

Reviewed by Chris Dumez.

Source/WebCore:

When a page enters the page cache it is unnecessary for it to hold a reference to its
associated frame because subsequent interactions with the page do not need to make use
of it. Once a page exits the page cache we associate it with its frame.

* dom/Document.cpp:
(WebCore::Document::frameDestroyed): Update comment to reflect the renaming of disconnectFromFrame().
(WebCore::Document::attachToCachedFrame): Added.
(WebCore::Document::detachFromCachedFrame): Added.
(WebCore::Document::prepareForDestruction): Only call CSSAnimationController::detachFromDocument() if
we have a frame. Substitute detachFromFrame() for disconnectFromFrame() as the latter was renamed to
the former.
(WebCore::Document::hasEverCalledWindowOpen): Deleted.
(WebCore::Document::markHasCalledWindowOpen): Deleted.
(WebCore::Document::disconnectFromFrame): Renamed to detachFromFrame.
* dom/Document.h:
(WebCore::Document::detachFromFrame): Renamed; formerly named disconnectFromFrame(). Changed
visibility from public to private and made this function inline.
* history/CachedFrame.cpp:
(WebCore::CachedFrameBase::pruneDetachedChildFrames): Remove cached child frames that were
removed from the page when it was in the page cache as there is no need to restore such frames.
(WebCore::CachedFrameBase::restore): Call pruneDetachedChildFrames() before restoring the
frame tree.
(WebCore::CachedFrame::CachedFrame): Detach from the frame.
(WebCore::CachedFrame::open): Assert that we have a document and re-attach the frame.
(WebCore::CachedFrame::destroy): Update assertion as this function should only be called for a
frameless document. Only detach the FrameView, DocumentLoader, and Page when the cached frame is for
subframe and is associated with a Page object. Call CSSAnimationController::detachFromDocument() to
detach the animation controller from the document as it is being destroyed. We have to do this here
because the document does not have a frame. And Document::prepareForDestruction() only calls
CSSAnimationController::detachFromDocument() if the document has a frame.
* history/CachedFrame.h:
* history/PageCache.cpp:
(WebCore::canCachePage): Remove logic that prevents caching of a page that called window.open()
or has an opener as it is feasible to keep such pages in the page cache.
* html/HTMLFrameElementBase.cpp:
(WebCore::HTMLFrameElementBase::finishedInsertingSubtree): Fix style nit.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::frameDetached): Only stop all loaders and stop active DOM objects if the
page is not in- or about to enter- the page cache. A page in the page cache has finished loading
and its active DOM objects are suspended. Also fix style nit in comment.
(WebCore::FrameLoader::detachFromParent): Only stop all loaders if the page is not in- or about to
enter- the page cache. A page in the page cache has finished loading. Also added a comment to explain
that we protect the frame because stopAllLoaders() can cause the frame to be deallocated.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::createWindow): Remove logic to call markHasCalledWindowOpen() as this
function will be removed.
* page/DiagnosticLoggingKeys.cpp:
(WebCore::DiagnosticLoggingKeys::hasCalledWindowOpenKey): Deleted.
(WebCore::DiagnosticLoggingKeys::hasOpenerKey): Deleted.
* page/DiagnosticLoggingKeys.h:
* page/Page.cpp:
(WebCore::Page::openedByWindowOpen): Deleted.
* page/Page.h:
* page/Settings.in: Remove setting allowsPageCacheWithWindowOpener.

Source/WebKit/mac:

* WebView/WebPreferenceKeysPrivate.h:
* WebView/WebPreferences.mm:
(+[WebPreferences initialize]):
(-[WebPreferences allowsPageCacheWithWindowOpener]): Deleted.
(-[WebPreferences setAllowsPageCacheWithWindowOpener:]): Deleted.
* WebView/WebPreferencesPrivate.h:
* WebView/WebView.mm:
(-[WebView _preferencesChanged:]):

Source/WebKit/win:

* Interfaces/IWebPreferencesPrivate.idl:
* WebPreferenceKeysPrivate.h:
* WebPreferences.cpp:
(WebPreferences::initializeDefaultSettings):
(WebPreferences::setAllowsPageCacheWithWindowOpener): Deleted.
(WebPreferences::allowsPageCacheWithWindowOpener): Deleted.
* WebPreferences.h:
* WebView.cpp:
(WebView::notifyPreferencesChanged):

Source/WebKit2:

* Shared/WebPreferencesDefinitions.h:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetAllowsPageCacheWithWindowOpener): Deleted.
(WKPreferencesGetAllowsPageCacheWithWindowOpener): Deleted.
* UIProcess/API/C/WKPreferencesRefPrivate.h:
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::overrideBoolPreferenceForTestRunner):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

Tools:

* DumpRenderTree/mac/DumpRenderTree.mm:
(resetWebPreferencesToConsistentValues):
* DumpRenderTree/win/DumpRenderTree.cpp:
(resetWebPreferencesToConsistentValues):
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::resetPreferencesToConsistentValues):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212173 268f45cc-cd09-0410-ab3c-d52691b4dbfc

41 files changed:
LayoutTests/editing/mac/input/unconfirmed-text-navigation-with-page-cache.html
LayoutTests/fast/harness/page-cache-crash-on-data-urls.html
LayoutTests/fast/harness/use-page-cache.html
LayoutTests/fast/loader/stateobjects/no-popstate-when-back-to-stateless-entry-with-page-cache.html
LayoutTests/fast/loader/stateobjects/popstate-fires-with-page-cache.html
LayoutTests/tiled-drawing/tiled-drawing-scroll-position-page-cache-restoration.html
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/history/CachedFrame.cpp
Source/WebCore/history/CachedFrame.h
Source/WebCore/history/PageCache.cpp
Source/WebCore/html/HTMLFrameElementBase.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DiagnosticLoggingKeys.cpp
Source/WebCore/page/DiagnosticLoggingKeys.h
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/Settings.in
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebPreferenceKeysPrivate.h
Source/WebKit/mac/WebView/WebPreferences.mm
Source/WebKit/mac/WebView/WebPreferencesPrivate.h
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/Interfaces/IWebPreferencesPrivate.idl
Source/WebKit/win/WebPreferenceKeysPrivate.h
Source/WebKit/win/WebPreferences.cpp
Source/WebKit/win/WebPreferences.h
Source/WebKit/win/WebView.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPreferencesDefinitions.h
Source/WebKit2/UIProcess/API/C/WKPreferences.cpp
Source/WebKit2/UIProcess/API/C/WKPreferencesRefPrivate.h
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/DumpRenderTree/win/DumpRenderTree.cpp
Tools/WebKitTestRunner/TestController.cpp

index ba4fef1..4af33ab 100644 (file)
@@ -10,7 +10,6 @@ jsTestIsAsync = true;
 if (window.testRunner) {
     testRunner.setCanOpenWindows();
     testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
-    testRunner.overridePreference("WebKitAllowsPageCacheWithWindowOpenerKey", 1);
 }
 
 // Window we will be controlling.
index 87688c3..737e4ca 100644 (file)
@@ -22,7 +22,6 @@ function test()
         testRunner.waitUntilDone();
         testRunner.setCanOpenWindows();
         testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
-        testRunner.overridePreference("WebKitAllowsPageCacheWithWindowOpenerKey", 1);
     }
     log("open page with data urls");
     window.open("resources/cached-page-with-data-urls.html");
index 487127d..2564b60 100644 (file)
@@ -28,7 +28,6 @@ function test()
         testRunner.waitUntilDone();
         testRunner.setCanOpenWindows();
         testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
-        testRunner.overridePreference("WebKitAllowsPageCacheWithWindowOpenerKey", 1);
     }
     log("open page-1");
     window.open("resources/cached-page-1.html");
index 3888e15..4762ca5 100644 (file)
@@ -14,7 +14,6 @@ onload = function()
     if (window.testRunner) {
         testRunner.setCanOpenWindows();
         testRunner.overridePreference('WebKitUsesPageCachePreferenceKey', 1);
-        testRunner.overridePreference("WebKitAllowsPageCacheWithWindowOpenerKey", 1);
     }
     testWindow = window.open('resources/no-popstate-when-back-to-stateless-entry-1.html');
     if (!testWindow)
index ccb0a2d..61df09b 100644 (file)
@@ -14,7 +14,6 @@ onload = function()
     if (window.testRunner) {
         testRunner.setCanOpenWindows();
         testRunner.overridePreference('WebKitUsesPageCachePreferenceKey', 1);
-        testRunner.overridePreference("WebKitAllowsPageCacheWithWindowOpenerKey", 1);
     }
     testWindow = window.open('resources/popstate-fires-with-page-cache-1.html');
     if (!testWindow)
index ce22332..6a2851f 100644 (file)
@@ -7,7 +7,6 @@
             testRunner.waitUntilDone();
             testRunner.setCanOpenWindows();
             testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
-            testRunner.overridePreference("WebKitAllowsPageCacheWithWindowOpenerKey", 1);
         }
 
         window.finishedTest = function (layerTree)
index ab6c47c..c77b950 100644 (file)
@@ -1,3 +1,66 @@
+2017-02-10  Daniel Bates  <dabates@apple.com>
+
+        Detach frame from document when entering page cache
+        https://bugs.webkit.org/show_bug.cgi?id=166774
+        <rdar://problem/29904368>
+
+        Reviewed by Chris Dumez.
+
+        When a page enters the page cache it is unnecessary for it to hold a reference to its
+        associated frame because subsequent interactions with the page do not need to make use
+        of it. Once a page exits the page cache we associate it with its frame.
+
+        * dom/Document.cpp:
+        (WebCore::Document::frameDestroyed): Update comment to reflect the renaming of disconnectFromFrame().
+        (WebCore::Document::attachToCachedFrame): Added.
+        (WebCore::Document::detachFromCachedFrame): Added.
+        (WebCore::Document::prepareForDestruction): Only call CSSAnimationController::detachFromDocument() if
+        we have a frame. Substitute detachFromFrame() for disconnectFromFrame() as the latter was renamed to
+        the former.
+        (WebCore::Document::hasEverCalledWindowOpen): Deleted.
+        (WebCore::Document::markHasCalledWindowOpen): Deleted.
+        (WebCore::Document::disconnectFromFrame): Renamed to detachFromFrame.
+        * dom/Document.h:
+        (WebCore::Document::detachFromFrame): Renamed; formerly named disconnectFromFrame(). Changed
+        visibility from public to private and made this function inline.
+        * history/CachedFrame.cpp:
+        (WebCore::CachedFrameBase::pruneDetachedChildFrames): Remove cached child frames that were
+        removed from the page when it was in the page cache as there is no need to restore such frames.
+        (WebCore::CachedFrameBase::restore): Call pruneDetachedChildFrames() before restoring the
+        frame tree.
+        (WebCore::CachedFrame::CachedFrame): Detach from the frame.
+        (WebCore::CachedFrame::open): Assert that we have a document and re-attach the frame.
+        (WebCore::CachedFrame::destroy): Update assertion as this function should only be called for a
+        frameless document. Only detach the FrameView, DocumentLoader, and Page when the cached frame is for
+        subframe and is associated with a Page object. Call CSSAnimationController::detachFromDocument() to
+        detach the animation controller from the document as it is being destroyed. We have to do this here
+        because the document does not have a frame. And Document::prepareForDestruction() only calls
+        CSSAnimationController::detachFromDocument() if the document has a frame.
+        * history/CachedFrame.h:
+        * history/PageCache.cpp:
+        (WebCore::canCachePage): Remove logic that prevents caching of a page that called window.open()
+        or has an opener as it is feasible to keep such pages in the page cache.
+        * html/HTMLFrameElementBase.cpp:
+        (WebCore::HTMLFrameElementBase::finishedInsertingSubtree): Fix style nit.
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::frameDetached): Only stop all loaders and stop active DOM objects if the
+        page is not in- or about to enter- the page cache. A page in the page cache has finished loading
+        and its active DOM objects are suspended. Also fix style nit in comment.
+        (WebCore::FrameLoader::detachFromParent): Only stop all loaders if the page is not in- or about to
+        enter- the page cache. A page in the page cache has finished loading. Also added a comment to explain
+        that we protect the frame because stopAllLoaders() can cause the frame to be deallocated.
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::createWindow): Remove logic to call markHasCalledWindowOpen() as this
+        function will be removed.
+        * page/DiagnosticLoggingKeys.cpp:
+        (WebCore::DiagnosticLoggingKeys::hasCalledWindowOpenKey): Deleted.
+        (WebCore::DiagnosticLoggingKeys::hasOpenerKey): Deleted.
+        * page/DiagnosticLoggingKeys.h:
+        * page/Page.cpp:
+        (WebCore::Page::openedByWindowOpen): Deleted.
+        * page/Page.h:
+        * page/Settings.in: Remove setting allowsPageCacheWithWindowOpener.
+
 2017-02-10  Simon Fraser  <simon.fraser@apple.com>
 
         REGRESSION (r211845): [ios-simulator] LayoutTest compositing/masks/solid-color-masked.html is a flaky failure
index 7d93663..bf26b04 100644 (file)
@@ -36,6 +36,7 @@
 #include "CSSStyleDeclaration.h"
 #include "CSSStyleSheet.h"
 #include "CachedCSSStyleSheet.h"
+#include "CachedFrame.h"
 #include "CachedResourceLoader.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
@@ -836,23 +837,6 @@ bool Document::hasManifest() const
     return documentElement() && documentElement()->hasTagName(htmlTag) && documentElement()->hasAttributeWithoutSynchronization(manifestAttr);
 }
 
-bool Document::hasEverCalledWindowOpen() const
-{
-    auto& topDocument = this->topDocument();
-    if (&topDocument == this)
-        return m_hasEverCalledWindowOpen;
-    return topDocument.hasEverCalledWindowOpen();
-}
-
-void Document::markHasCalledWindowOpen()
-{
-    auto& topDocument = this->topDocument();
-    if (&topDocument == this)
-        m_hasEverCalledWindowOpen = true;
-    else
-        topDocument.markHasCalledWindowOpen();
-}
-
 DocumentType* Document::doctype() const
 {
     for (Node* node = firstChild(); node; node = node->nextSibling()) {
@@ -2190,18 +2174,30 @@ void Document::didBecomeCurrentDocumentInFrame()
     }
 }
 
-void Document::disconnectFromFrame()
-{
-    observeFrame(nullptr);
-}
-
 void Document::frameDestroyed()
 {
-    // disconnectFromFrame() must be called before destroying the Frame.
+    // detachFromFrame() must be called before destroying the Frame.
     ASSERT_WITH_SECURITY_IMPLICATION(!m_frame);
     FrameDestructionObserver::frameDestroyed();
 }
 
+void Document::attachToCachedFrame(CachedFrameBase& cachedFrame)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(cachedFrame.document() == this);
+    ASSERT(cachedFrame.view());
+    ASSERT(m_pageCacheState == Document::InPageCache);
+    observeFrame(&cachedFrame.view()->frame());
+}
+
+void Document::detachFromCachedFrame(CachedFrameBase& cachedFrame)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(cachedFrame.document() == this);
+    ASSERT(cachedFrame.view());
+    ASSERT(m_frame == &cachedFrame.view()->frame());
+    ASSERT(m_pageCacheState == Document::InPageCache);
+    detachFromFrame();
+}
+
 void Document::destroyRenderTree()
 {
     ASSERT(hasLivingRenderTree());
@@ -2259,7 +2255,8 @@ void Document::prepareForDestruction()
     if (m_hasPreparedForDestruction)
         return;
 
-    m_frame->animation().detachFromDocument(this);
+    if (m_frame)
+        m_frame->animation().detachFromDocument(this);
 
 #if ENABLE(IOS_TOUCH_EVENTS)
     clearTouchEventHandlersAndListeners();
@@ -2324,7 +2321,7 @@ void Document::prepareForDestruction()
     }
 #endif
 
-    disconnectFromFrame();
+    detachFromFrame();
 
     m_hasPreparedForDestruction = true;
 }
index 07304ea..400dbad 100644 (file)
@@ -78,6 +78,7 @@ class CSSFontSelector;
 class CSSStyleDeclaration;
 class CSSStyleSheet;
 class CachedCSSStyleSheet;
+class CachedFrameBase;
 class CachedResourceLoader;
 class CachedScript;
 class CanvasRenderingContext;
@@ -367,9 +368,6 @@ public:
     WEBCORE_EXPORT bool hasFocus() const;
 
     bool hasManifest() const;
-
-    bool hasEverCalledWindowOpen() const;
-    void markHasCalledWindowOpen();
     
     WEBCORE_EXPORT ExceptionOr<Ref<Element>> createElementForBindings(const AtomicString& tagName);
     WEBCORE_EXPORT Ref<DocumentFragment> createDocumentFragment();
@@ -557,7 +555,6 @@ public:
 
     void didBecomeCurrentDocumentInFrame();
     void destroyRenderTree();
-    void disconnectFromFrame();
     void prepareForDestruction();
 
     // Override ScriptExecutionContext methods to do additional work
@@ -1286,6 +1283,9 @@ public:
     void didRemoveInDocumentShadowRoot(ShadowRoot&);
     const HashSet<ShadowRoot*>& inDocumentShadowRoots() const { return m_inDocumentShadowRoots; }
 
+    void attachToCachedFrame(CachedFrameBase&);
+    void detachFromCachedFrame(CachedFrameBase&);
+
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     Document(Frame*, const URL&, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);
@@ -1299,6 +1299,8 @@ private:
     friend class IgnoreDestructiveWriteCountIncrementer;
     friend class IgnoreOpensDuringUnloadCountIncrementer;
 
+    void detachFromFrame() { observeFrame(nullptr); }
+
     void updateTitleElement(Element* newTitleElement);
     void frameDestroyed() final;
 
@@ -1475,7 +1477,6 @@ private:
     bool m_bParsing;
 
     Timer m_styleRecalcTimer;
-    bool m_hasEverCalledWindowOpen { false };
     bool m_pendingStyleRecalcShouldForce;
     bool m_inStyleRecalc;
     bool m_closeAfterStyleRecalc;
index aa654ad..22245fc 100644 (file)
@@ -75,6 +75,17 @@ CachedFrameBase::~CachedFrameBase()
     ASSERT(!m_document);
 }
 
+void CachedFrameBase::pruneDetachedChildFrames()
+{
+    for (size_t i = m_childFrames.size(); i;) {
+        --i;
+        if (m_childFrames[i]->view()->frame().page())
+            continue;
+        m_childFrames[i]->destroy();
+        m_childFrames.remove(i);
+    }
+}
+
 void CachedFrameBase::restore()
 {
     ASSERT(m_document->view() == m_view);
@@ -98,8 +109,11 @@ void CachedFrameBase::restore()
 
     frame.loader().client().didRestoreFromPageCache();
 
+    pruneDetachedChildFrames();
+
     // Reconstruct the FrameTree. And open the child CachedFrames in their respective FrameLoaders.
     for (auto& childFrame : m_childFrames) {
+        ASSERT(childFrame->view()->frame().page());
         frame.tree().appendChild(childFrame->view()->frame());
         childFrame->open();
     }
@@ -183,15 +197,20 @@ CachedFrame::CachedFrame(Frame& frame)
     }
 #endif
 
+    m_document->detachFromCachedFrame(*this);
+
     ASSERT_WITH_SECURITY_IMPLICATION(!m_documentLoader->isLoading());
 }
 
 void CachedFrame::open()
 {
     ASSERT(m_view);
+    ASSERT(m_document);
     if (!m_isMainFrame)
         m_view->frame().page()->incrementSubframeCount();
 
+    m_document->attachToCachedFrame(*this);
+
     m_view->frame().loader().open(*this);
 }
 
@@ -227,11 +246,11 @@ void CachedFrame::destroy()
     // Only CachedFrames that are still in the PageCache should be destroyed in this manner
     ASSERT(m_document->pageCacheState() == Document::InPageCache);
     ASSERT(m_view);
-    ASSERT(m_document->frame() == &m_view->frame());
+    ASSERT(!m_document->frame());
 
     m_document->domWindow()->willDestroyCachedFrame();
 
-    if (!m_isMainFrame) {
+    if (!m_isMainFrame && m_view->frame().page()) {
         m_view->frame().loader().detachViewsAndDocumentLoader();
         m_view->frame().detachFromPage();
     }
@@ -244,6 +263,8 @@ void CachedFrame::destroy()
 
     Frame::clearTimers(m_view.get(), m_document.get());
 
+    m_view->frame().animation().detachFromDocument(m_document.get());
+
     // FIXME: Why do we need to call removeAllEventListeners here? When the document is in page cache, this method won't work
     // fully anyway, because the document won't be able to access its DOMWindow object (due to being frameless).
     m_document->removeAllEventListeners();
index a8f3732..e0be571 100644 (file)
@@ -52,7 +52,9 @@ public:
 protected:
     CachedFrameBase(Frame&);
     ~CachedFrameBase();
-    
+
+    void pruneDetachedChildFrames();
+
     RefPtr<Document> m_document;
     RefPtr<DocumentLoader> m_documentLoader;
     RefPtr<FrameView> m_view;
index b6743bc..02f8ff4 100644 (file)
@@ -191,19 +191,6 @@ static bool canCachePage(Page& page)
 
     DiagnosticLoggingClient& diagnosticLoggingClient = page.diagnosticLoggingClient();
     bool isCacheable = canCacheFrame(page.mainFrame(), diagnosticLoggingClient, indentLevel + 1);
-
-    if (page.openedByWindowOpen() && !page.settings().allowsPageCacheWithWindowOpener()) {
-        PCLOG("   -Page has been opened via window.open()");
-        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::hasOpenerKey());
-        isCacheable = false;
-    }
-
-    auto* topDocument = page.mainFrame().document();
-    if (topDocument && topDocument->hasEverCalledWindowOpen()) {
-        PCLOG("   -Page has called window.open()");
-        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::hasCalledWindowOpenKey());
-        isCacheable = false;
-    }
     
     if (!page.settings().usesPageCache() || page.isResourceCachingDisabled()) {
         PCLOG("   -Page settings says b/f cache disabled");
index 86cba39..a961e4c 100644 (file)
@@ -145,7 +145,7 @@ void HTMLFrameElementBase::finishedInsertingSubtree()
     if (!isConnected())
         return;
 
-    // DocumentFragments don't kick of any loads.
+    // DocumentFragments don't kick off any loads.
     if (!document().frame())
         return;
 
index c18c29c..296cbc5 100644 (file)
@@ -2496,25 +2496,31 @@ void FrameLoader::dispatchOnloadEvents()
 
 void FrameLoader::frameDetached()
 {
-    // Calling stopAllLoaders can cause the frame to be deallocated, including the frame loader.
+    // Calling stopAllLoaders() can cause the frame to be deallocated, including the frame loader.
     Ref<Frame> protectedFrame(m_frame);
 
-    stopAllLoaders();
-    m_frame.document()->stopActiveDOMObjects();
+    if (m_frame.document()->pageCacheState() != Document::InPageCache) {
+        stopAllLoaders();
+        m_frame.document()->stopActiveDOMObjects();
+    }
+
     detachFromParent();
 }
 
 void FrameLoader::detachFromParent()
 {
+    // Calling stopAllLoaders() can cause the frame to be deallocated, including the frame loader.
     Ref<Frame> protect(m_frame);
 
     closeURL();
     history().saveScrollPositionAndViewStateToItem(history().currentItem());
     detachChildren();
-    // stopAllLoaders() needs to be called after detachChildren(), because detachedChildren()
-    // will trigger the unload event handlers of any child frames, and those event
-    // handlers might start a new subresource load in this frame.
-    stopAllLoaders();
+    if (m_frame.document()->pageCacheState() != Document::InPageCache) {
+        // stopAllLoaders() needs to be called after detachChildren() if the document is not in the page cache,
+        // because detachedChildren() will trigger the unload event handlers of any child frames, and those event
+        // handlers might start a new subresource load in this frame.
+        stopAllLoaders();
+    }
 
     InspectorInstrumentation::frameDetachedFromParent(m_frame);
 
index 75d0497..9b6abb2 100644 (file)
@@ -2186,8 +2186,6 @@ RefPtr<Frame> DOMWindow::createWindow(const String& urlString, const AtomicStrin
 
     newFrame->loader().setOpener(&openerFrame);
     newFrame->page()->setOpenedByDOM();
-    if (auto* openerDocument = openerFrame.document())
-        openerDocument->markHasCalledWindowOpen();
 
     if (newFrame->document()->domWindow()->isInsecureScriptAccess(activeWindow, completedURL))
         return newFrame;
index 4172392..bd555f3 100644 (file)
@@ -648,16 +648,6 @@ String DiagnosticLoggingKeys::fontKey()
     return ASCIILiteral("font");
 }
 
-String DiagnosticLoggingKeys::hasCalledWindowOpenKey()
-{
-    return ASCIILiteral("hasCalledWindowOpen");
-}
-
-String DiagnosticLoggingKeys::hasOpenerKey()
-{
-    return ASCIILiteral("hasOpener");
-}
-
 String DiagnosticLoggingKeys::prunedDueToMemoryPressureKey()
 {
     return ASCIILiteral("pruned.memoryPressure");
index b8c2a0b..39a77c6 100644 (file)
@@ -56,8 +56,6 @@ public:
     WEBCORE_EXPORT static String entryWronglyNotWarmedUpKey();
     static String expiredKey();
     static String fontKey();
-    static String hasCalledWindowOpenKey();
-    static String hasOpenerKey();
     static String hasPluginsKey();
     static String httpsNoStoreKey();
     static String imageKey();
index 98646b8..2f78e6d 100644 (file)
@@ -469,17 +469,6 @@ void Page::setOpenedByDOM()
     m_openedByDOM = true;
 }
 
-bool Page::openedByWindowOpen() const
-{
-    auto* document = m_mainFrame->document();
-    if (!document)
-        return false;
-    auto* window = document->domWindow();
-    if (!window)
-        return false;
-    return window->opener();
-}
-
 void Page::goToItem(HistoryItem& item, FrameLoadType type)
 {
     // stopAllLoaders may end up running onload handlers, which could cause further history traversals that may lead to the passed in HistoryItem
index 1b4c377..4e18fdb 100644 (file)
@@ -179,8 +179,6 @@ public:
     bool openedByDOM() const;
     void setOpenedByDOM();
 
-    bool openedByWindowOpen() const;
-
     WEBCORE_EXPORT void goToItem(HistoryItem&, FrameLoadType);
 
     WEBCORE_EXPORT void setGroupName(const String&);
index c6c3c3e..d38773f 100644 (file)
@@ -287,5 +287,3 @@ animatedImageAsyncDecodingEnabled initial=true
 shouldSuppressKeyboardInputDuringProvisionalNavigation initial=false
 
 langAttributeAwareFormControlUIEnabled initial=false
-
-allowsPageCacheWithWindowOpener initial=false
index b8b98f7..910c9f8 100644 (file)
@@ -1,3 +1,20 @@
+2017-02-10  Daniel Bates  <dabates@apple.com>
+
+        Detach frame from document when entering page cache
+        https://bugs.webkit.org/show_bug.cgi?id=166774
+        <rdar://problem/29904368>
+
+        Reviewed by Chris Dumez.
+
+        * WebView/WebPreferenceKeysPrivate.h:
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences initialize]):
+        (-[WebPreferences allowsPageCacheWithWindowOpener]): Deleted.
+        (-[WebPreferences setAllowsPageCacheWithWindowOpener:]): Deleted.
+        * WebView/WebPreferencesPrivate.h:
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChanged:]):
+
 2017-02-10  Joseph Pecoraro  <pecoraro@apple.com>
 
         [Resource Timing] Enable Resource Timing by default in Tests
index 34dc24b..ffaa7d7 100644 (file)
@@ -83,7 +83,6 @@
 #define WebAutomaticSpellingCorrectionEnabled @"WebAutomaticSpellingCorrectionEnabled"
 #define WebKitDOMPasteAllowedPreferenceKey @"WebKitDOMPasteAllowedPreferenceKey"
 #define WebKitUsesPageCachePreferenceKey @"WebKitUsesPageCachePreferenceKey"
-#define WebKitAllowsPageCacheWithWindowOpenerKey @"WebKitAllowsPageCacheWithWindowOpenerKey"
 #define WebKitPageCacheSupportsPluginsPreferenceKey @"WebKitPageCacheSupportsPluginsPreferenceKey"
 #define WebKitFTPDirectoryTemplatePath @"WebKitFTPDirectoryTemplatePath"
 #define WebKitForceFTPDirectoryListings @"WebKitForceFTPDirectoryListings"
index a1ceae6..0afb409 100644 (file)
@@ -478,7 +478,6 @@ public:
         [NSNumber numberWithBool:NO],   WebKitDOMPasteAllowedPreferenceKey,
 #endif
         [NSNumber numberWithBool:YES],  WebKitUsesPageCachePreferenceKey,
-        [NSNumber numberWithBool:NO],   WebKitAllowsPageCacheWithWindowOpenerKey,
         [NSNumber numberWithInt:cacheModelForMainBundle()], WebKitCacheModelPreferenceKey,
         [NSNumber numberWithBool:YES],  WebKitPageCacheSupportsPluginsPreferenceKey,
         [NSNumber numberWithBool:NO],   WebKitDeveloperExtrasEnabledPreferenceKey,
@@ -2448,16 +2447,6 @@ static NSString *classIBCreatorID = nil;
 
 }
 
-- (BOOL)allowsPageCacheWithWindowOpener
-{
-    return [self _boolValueForKey:WebKitAllowsPageCacheWithWindowOpenerKey];
-}
-
-- (void)setAllowsPageCacheWithWindowOpener:(BOOL)flag
-{
-    [self _setBoolValue:flag forKey:WebKitAllowsPageCacheWithWindowOpenerKey];
-}
-
 #if PLATFORM(IOS)
 - (void)_invalidateCachedPreferences
 {
index 62d8a2a..e5c2678 100644 (file)
@@ -298,9 +298,6 @@ extern NSString *WebPreferencesCacheModelChangedInternalNotification;
 - (NSString *)pictographFontFamily;
 - (void)setPictographFontFamily:(NSString *)family;
 
-- (BOOL)allowsPageCacheWithWindowOpener;
-- (void)setAllowsPageCacheWithWindowOpener:(BOOL)flag;
-
 - (BOOL)pageCacheSupportsPlugins;
 - (void)setPageCacheSupportsPlugins:(BOOL)flag;
 
index 0917aa8..df6e35b 100644 (file)
@@ -2671,7 +2671,6 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setTextDirectionSubmenuInclusionBehavior(core([preferences textDirectionSubmenuInclusionBehavior]));
     settings.setDOMPasteAllowed([preferences isDOMPasteAllowed]);
     settings.setUsesPageCache([self usesPageCache]);
-    settings.setAllowsPageCacheWithWindowOpener([preferences allowsPageCacheWithWindowOpener]);
     settings.setPageCacheSupportsPlugins([preferences pageCacheSupportsPlugins]);
     settings.setBackForwardCacheExpirationInterval([preferences _backForwardCacheExpirationInterval]);
 
index a690da5..6280a4b 100644 (file)
@@ -1,3 +1,21 @@
+2017-02-10  Daniel Bates  <dabates@apple.com>
+
+        Detach frame from document when entering page cache
+        https://bugs.webkit.org/show_bug.cgi?id=166774
+        <rdar://problem/29904368>
+
+        Reviewed by Chris Dumez.
+
+        * Interfaces/IWebPreferencesPrivate.idl:
+        * WebPreferenceKeysPrivate.h:
+        * WebPreferences.cpp:
+        (WebPreferences::initializeDefaultSettings):
+        (WebPreferences::setAllowsPageCacheWithWindowOpener): Deleted.
+        (WebPreferences::allowsPageCacheWithWindowOpener): Deleted.
+        * WebPreferences.h:
+        * WebView.cpp:
+        (WebView::notifyPreferencesChanged):
+
 2017-02-10  Joseph Pecoraro  <pecoraro@apple.com>
 
         [Resource Timing] Enable Resource Timing by default in Tests
index 99ae3fb..bcd70e5 100644 (file)
@@ -91,9 +91,6 @@ interface IWebPreferencesPrivate : IUnknown
     HRESULT experimentalNotificationsEnabled([out, retval] BOOL *enabled);
     HRESULT setExperimentalNotificationsEnabled([in] BOOL enabled);
 
-    HRESULT allowsPageCacheWithWindowOpener([out, retval] BOOL* usesPageCache);
-    HRESULT setAllowsPageCacheWithWindowOpener([in] BOOL usesPageCache);
-
     HRESULT setShouldUseHighResolutionTimers([in] BOOL useHighResolutionTimers);
     HRESULT shouldUseHighResolutionTimers([out, retval] BOOL* useHighResolutionTimers);
 
index a9b7670..edf3776 100644 (file)
@@ -68,7 +68,6 @@
 #define WebKitIconDatabaseLocationKey "WebKitIconDatabaseLocation"
 #define WebKitIconDatabaseEnabledPreferenceKey "WebKitIconDatabaseEnabled"
 #define WebKitUsesPageCachePreferenceKey "WebKitUsesPageCachePreferenceKey"
-#define WebKitAllowsPageCacheWithWindowOpenerKey "WebKitAllowsPageCacheWithWindowOpenerKey"
 #define WebKitCacheModelPreferenceKey "WebKitCacheModelPreferenceKey"
 #define WebKitLocalStorageDatabasePathPreferenceKey "WebKitLocalStorageDatabasePath"
 #define WebKitHyperlinkAuditingEnabledPreferenceKey "WebKitHyperlinkAuditingEnabled"
index 71462d9..1eb105c 100644 (file)
@@ -262,7 +262,6 @@ void WebPreferences::initializeDefaultSettings()
     CFDictionaryAddValue(defaults, CFSTR(WebGrammarCheckingEnabledPreferenceKey), kCFBooleanFalse);
     CFDictionaryAddValue(defaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue);
     CFDictionaryAddValue(defaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue);
-    CFDictionaryAddValue(defaults, CFSTR(WebKitAllowsPageCacheWithWindowOpenerKey), kCFBooleanFalse);
     CFDictionaryAddValue(defaults, CFSTR(WebKitLocalStorageDatabasePathPreferenceKey), CFSTR(""));
 
     RetainPtr<CFStringRef> cacheModelRef = adoptCF(CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebCacheModelDocumentViewer));
@@ -1613,20 +1612,6 @@ HRESULT WebPreferences::experimentalNotificationsEnabled(_Out_ BOOL* enabled)
     return S_OK;
 }
 
-HRESULT WebPreferences::setAllowsPageCacheWithWindowOpener(BOOL value)
-{
-    setBoolValue(WebKitAllowsPageCacheWithWindowOpenerKey, value);
-    return S_OK;
-}
-
-HRESULT WebPreferences::allowsPageCacheWithWindowOpener(_Out_ BOOL* enabled)
-{
-    if (!enabled)
-        return E_POINTER;
-    *enabled = boolValueForKey(WebKitAllowsPageCacheWithWindowOpenerKey);
-    return S_OK;
-}
-
 HRESULT WebPreferences::setZoomsTextOnly(BOOL zoomsTextOnly)
 {
     setBoolValue(WebKitZoomsTextOnlyPreferenceKey, zoomsTextOnly);
index b58b6d6..b498e63 100644 (file)
@@ -159,8 +159,6 @@ public:
     virtual HRESULT STDMETHODCALLTYPE setLocalStorageDatabasePath(_In_ BSTR);
     virtual HRESULT STDMETHODCALLTYPE experimentalNotificationsEnabled(_Out_ BOOL*);
     virtual HRESULT STDMETHODCALLTYPE setExperimentalNotificationsEnabled(BOOL);
-    virtual HRESULT STDMETHODCALLTYPE allowsPageCacheWithWindowOpener(_Out_ BOOL*);
-    virtual HRESULT STDMETHODCALLTYPE setAllowsPageCacheWithWindowOpener(BOOL);
 
     // These two methods are no-ops, and only retained to keep
     // the Interface consistent. DO NOT USE THEM.
index e5511c8..c433b4e 100644 (file)
@@ -5414,11 +5414,6 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification)
         return hr;
     settings.setExperimentalNotificationsEnabled(enabled);
 
-    hr = prefsPrivate->allowsPageCacheWithWindowOpener(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings.setAllowsPageCacheWithWindowOpener(enabled);
-
     hr = prefsPrivate->isWebSecurityEnabled(&enabled);
     if (FAILED(hr))
         return hr;
index 0847ccc..e1c555c 100644 (file)
@@ -1,3 +1,21 @@
+2017-02-10  Daniel Bates  <dabates@apple.com>
+
+        Detach frame from document when entering page cache
+        https://bugs.webkit.org/show_bug.cgi?id=166774
+        <rdar://problem/29904368>
+
+        Reviewed by Chris Dumez.
+
+        * Shared/WebPreferencesDefinitions.h:
+        * UIProcess/API/C/WKPreferences.cpp:
+        (WKPreferencesSetAllowsPageCacheWithWindowOpener): Deleted.
+        (WKPreferencesGetAllowsPageCacheWithWindowOpener): Deleted.
+        * UIProcess/API/C/WKPreferencesRefPrivate.h:
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        (WebKit::InjectedBundle::overrideBoolPreferenceForTestRunner):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updatePreferences):
+
 2017-02-10  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         WebInspector: refactor RemoteInspector to move cocoa specific code to their own files
index eefebb2..a48545d 100644 (file)
     macro(WebArchiveDebugModeEnabled, webArchiveDebugModeEnabled, Bool, bool, false, "", "") \
     macro(LocalFileContentSniffingEnabled, localFileContentSniffingEnabled, Bool, bool, false, "", "") \
     macro(UsesPageCache, usesPageCache, Bool, bool, true, "", "") \
-    macro(AllowsPageCacheWithWindowOpener, allowsPageCacheWithWindowOpener, Bool, bool, false, "", "") \
     macro(PageCacheSupportsPlugins, pageCacheSupportsPlugins, Bool, bool, true, "", "") \
     macro(AuthorAndUserStylesEnabled, authorAndUserStylesEnabled, Bool, bool, true, "", "") \
     macro(PaginateDuringLayoutEnabled, paginateDuringLayoutEnabled, Bool, bool, false, "", "") \
index 3571e41..0d7090e 100644 (file)
@@ -623,16 +623,6 @@ bool WKPreferencesGetPageCacheEnabled(WKPreferencesRef preferencesRef)
     return toImpl(preferencesRef)->usesPageCache();
 }
 
-void WKPreferencesSetAllowsPageCacheWithWindowOpener(WKPreferencesRef preferencesRef, bool enabled)
-{
-    toImpl(preferencesRef)->setAllowsPageCacheWithWindowOpener(enabled);
-}
-
-bool WKPreferencesGetAllowsPageCacheWithWindowOpener(WKPreferencesRef preferencesRef)
-{
-    return toImpl(preferencesRef)->allowsPageCacheWithWindowOpener();
-}
-
 void WKPreferencesSetPageCacheSupportsPlugins(WKPreferencesRef preferencesRef, bool pageCacheSupportsPlugins)
 {
     toImpl(preferencesRef)->setPageCacheSupportsPlugins(pageCacheSupportsPlugins);
index ff135ab..7c25584 100644 (file)
@@ -143,10 +143,6 @@ WK_EXPORT bool WKPreferencesGetLocalFileContentSniffingEnabled(WKPreferencesRef
 WK_EXPORT void WKPreferencesSetPageCacheEnabled(WKPreferencesRef preferences, bool enabled);
 WK_EXPORT bool WKPreferencesGetPageCacheEnabled(WKPreferencesRef preferences);
 
-// Defaults to false.
-WK_EXPORT void WKPreferencesSetAllowsPageCacheWithWindowOpener(WKPreferencesRef preferences, bool enabled);
-WK_EXPORT bool WKPreferencesGetAllowsPageCacheWithWindowOpener(WKPreferencesRef preferences);
-
 // Defaults to true.
 WK_EXPORT void WKPreferencesSetPageCacheSupportsPlugins(WKPreferencesRef preferences, bool pageCacheSupportsPlugins);
 WK_EXPORT bool WKPreferencesGetPageCacheSupportsPlugins(WKPreferencesRef preferences);
index 4ec78ed..c695f89 100644 (file)
@@ -248,7 +248,6 @@ void InjectedBundle::overrideBoolPreferenceForTestRunner(WebPageGroupProxy* page
     macro(WebKitPageCacheSupportsPluginsPreferenceKey, PageCacheSupportsPlugins, pageCacheSupportsPlugins) \
     macro(WebKitPluginsEnabled, PluginsEnabled, pluginsEnabled) \
     macro(WebKitUsesPageCachePreferenceKey, UsesPageCache, usesPageCache) \
-    macro(WebKitAllowsPageCacheWithWindowOpenerKey, AllowsPageCacheWithWindowOpener, allowsPageCacheWithWindowOpener) \
     macro(WebKitWebAudioEnabled, WebAudioEnabled, webAudioEnabled) \
     macro(WebKitWebGLEnabled, WebGLEnabled, webGLEnabled) \
     macro(WebKitXSSAuditorEnabled, XSSAuditorEnabled, xssAuditorEnabled) \
index 7cabe0e..ac877f6 100644 (file)
@@ -2985,7 +2985,6 @@ void WebPage::updatePreferences(const WebPreferencesStore& store)
 #endif
     settings.setLocalFileContentSniffingEnabled(store.getBoolValueForKey(WebPreferencesKey::localFileContentSniffingEnabledKey()));
     settings.setUsesPageCache(store.getBoolValueForKey(WebPreferencesKey::usesPageCacheKey()));
-    settings.setAllowsPageCacheWithWindowOpener(store.getBoolValueForKey(WebPreferencesKey::allowsPageCacheWithWindowOpenerKey()));
     settings.setPageCacheSupportsPlugins(store.getBoolValueForKey(WebPreferencesKey::pageCacheSupportsPluginsKey()));
     settings.setAuthorAndUserStylesEnabled(store.getBoolValueForKey(WebPreferencesKey::authorAndUserStylesEnabledKey()));
     settings.setPaginateDuringLayoutEnabled(store.getBoolValueForKey(WebPreferencesKey::paginateDuringLayoutEnabledKey()));
index 437cb40..2e3b815 100644 (file)
@@ -1,3 +1,18 @@
+2017-02-10  Daniel Bates  <dabates@apple.com>
+
+        Detach frame from document when entering page cache
+        https://bugs.webkit.org/show_bug.cgi?id=166774
+        <rdar://problem/29904368>
+
+        Reviewed by Chris Dumez.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (resetWebPreferencesToConsistentValues):
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (resetWebPreferencesToConsistentValues):
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::resetPreferencesToConsistentValues):
+
 2017-02-10  Tim Horton  <timothy_horton@apple.com>
 
         Infinite UI process hang under ensurePositionInformationIsUpToDate
index 8b107d6..f80a8b1 100644 (file)
@@ -987,7 +987,6 @@ static void resetWebPreferencesToConsistentValues()
     // The back/forward cache is causing problems due to layouts during transition from one page to another.
     // So, turn it off for now, but we might want to turn it back on some day.
     [preferences setUsesPageCache:NO];
-    [preferences setAllowsPageCacheWithWindowOpener:NO];
     [preferences setAcceleratedCompositingEnabled:YES];
 #if USE(CA)
     [preferences setCanvasUsesAcceleratedDrawing:YES];
index 10939ae..a7dff05 100644 (file)
@@ -835,7 +835,6 @@ static void resetWebPreferencesToConsistentValues(IWebPreferences* preferences)
     preferences->setPlugInsEnabled(TRUE);
     preferences->setTextAreasAreResizable(TRUE);
     preferences->setUsesPageCache(FALSE);
-    prefsPrivate->setAllowsPageCacheWithWindowOpener(FALSE);
 
     preferences->setPrivateBrowsingEnabled(FALSE);
     prefsPrivate->setAuthorAndUserStylesEnabled(TRUE);
index b67a571..8d8d91a 100644 (file)
@@ -655,7 +655,6 @@ void TestController::resetPreferencesToConsistentValues(const TestOptions& optio
     WKPreferencesSetFullScreenEnabled(preferences, true);
 #endif
     WKPreferencesSetPageCacheEnabled(preferences, false);
-    WKPreferencesSetAllowsPageCacheWithWindowOpener(preferences, false);
     WKPreferencesSetAsynchronousPluginInitializationEnabled(preferences, false);
     WKPreferencesSetAsynchronousPluginInitializationEnabledForAllPlugins(preferences, false);
     WKPreferencesSetArtificialPluginInitializationDelayEnabled(preferences, false);