[WK2] didRemoveFrameFromHierarchy callback doesn't fire for subframes when evicting...
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Oct 2016 18:55:09 +0000 (18:55 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Oct 2016 18:55:09 +0000 (18:55 +0000)
commit2ef9c9d969b2d24521906a9eb641373f8da5f0d5
tree7000857134c7bd492dfcc1820ae85d4d9ff894b7
parentb020bae25ec32330fc80234ff2fe9abb06f323c8
[WK2] didRemoveFrameFromHierarchy callback doesn't fire for subframes when evicting from PageCache.
<https://webkit.org/b/163098>
<rdar://problem/28663488>

Reviewed by Antti Koivisto.

Source/WebCore:

Fix a bug where WK2 didRemoveFrameFromHierarchy callbacks wouldn't fire for subframes that were getting
kicked out of PageCache. The problem was happening because CachedFrame would disconnect the Frame from
its Page just before calling FrameLoader::detachViewsAndDocumentLoader() where the callbacks are fired.
Without a Page, the WebFrame on WK2 side can't find its WebPage, and so it can't fire its callbacks.

The fix is just to switch the order of those two lines.

This bug was causing frequent DOM and window object leaks in some clients *cough* Safari *cough* that
were relying on didRemoveFrameFromHierarchy to release their isolated worlds.

Test: WebKit2.DidRemoveFrameFromHiearchyInPageCache

* history/CachedFrame.cpp:
(WebCore::CachedFrame::destroy):

Tools:

Add an API test that puts a 10-subframe page into the page cache, then loads other pages
until the first page gets kicked out. The test succeeds if we receive didRemoveFrameFromHierarchy
callbacks for all the subframes.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache.cpp: Added.
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::setPageLoaderClient):
(TestWebKitAPI::didReceivePageMessageFromInjectedBundle):
(TestWebKitAPI::setInjectedBundleClient):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache_Bundle.cpp: Added.
(TestWebKitAPI::didRemoveFrameFromHierarchyCallback):
(TestWebKitAPI::DidRemoveFrameFromHiearchyInPageCacheTest::DidRemoveFrameFromHiearchyInPageCacheTest):
(TestWebKitAPI::DidRemoveFrameFromHiearchyInPageCacheTest::didCreatePage):
* TestWebKitAPI/Tests/WebKit2/many-iframes.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206922 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/history/CachedFrame.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/DidRemoveFrameFromHiearchyInPageCache_Bundle.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/many-iframes.html [new file with mode: 0644]