From f5f422304c166ee2a5d1d42454b9165febdf2642 Mon Sep 17 00:00:00 2001 From: "mitz@apple.com" Date: Mon, 7 Jan 2013 23:26:41 +0000 Subject: [PATCH] =?utf8?q?[mac]=20WebKit1=20clients=20can=E2=80=99t=20tell?= =?utf8?q?=20when=20a=20frame=20has=20been=20removed=20from=20the=20hierar?= =?utf8?q?chy=20https://bugs.webkit.org/show=5Fbug.cgi=3Fid=3D106261?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed by Simon Fraser. Source/WebKit/mac: Test: TestWebKitAPI/Tests/mac/WebViewDidRemoveFrameFromHierarchy.mm. Added -[WebFrameLoadDelegate webView:didRemoveFrameFromHierarchy:]. * WebCoreSupport/WebFrameLoaderClient.mm: (WebFrameLoaderClient::detachedFromParent2): Added a call to the new frame load delegate method. * WebView/WebDelegateImplementationCaching.h: (WebFrameLoadDelegateImplementationCache): Added the new method to the cache. * WebView/WebFrameLoadDelegatePrivate.h: Declared the new delegate method. * WebView/WebView.mm: (-[WebView _cacheFrameLoadDelegateImplementations]): Added the new method to the cache. Tools: Added a test for -[WebFrameLoadDelegate webView:didRemoveFrameFromHierarchy:]. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/mac/WebViewDidRemoveFrameFromHierarchy.mm: Added. (-[DidRemoveFrameFromHierarchyFrameLoadDelegate webView:didFinishLoadForFrame:]): (-[DidRemoveFrameFromHierarchyFrameLoadDelegate webView:didRemoveFrameFromHierarchy:]): (TestWebKitAPI): (TestWebKitAPI::TEST): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139000 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebKit/mac/ChangeLog | 20 ++++++ .../mac/WebCoreSupport/WebFrameLoaderClient.mm | 4 ++ .../mac/WebView/WebDelegateImplementationCaching.h | 1 + .../mac/WebView/WebFrameLoadDelegatePrivate.h | 1 + Source/WebKit/mac/WebView/WebView.mm | 1 + Tools/ChangeLog | 16 +++++ .../TestWebKitAPI.xcodeproj/project.pbxproj | 4 ++ .../mac/WebViewDidRemoveFrameFromHierarchy.mm | 83 ++++++++++++++++++++++ 8 files changed, 130 insertions(+) create mode 100644 Tools/TestWebKitAPI/Tests/mac/WebViewDidRemoveFrameFromHierarchy.mm diff --git a/Source/WebKit/mac/ChangeLog b/Source/WebKit/mac/ChangeLog index 97ad5f6..a10a289 100644 --- a/Source/WebKit/mac/ChangeLog +++ b/Source/WebKit/mac/ChangeLog @@ -1,3 +1,23 @@ +2013-01-07 Dan Bernstein + + [mac] WebKit1 clients can’t tell when a frame has been removed from the hierarchy + https://bugs.webkit.org/show_bug.cgi?id=106261 + + Reviewed by Simon Fraser. + + Test: TestWebKitAPI/Tests/mac/WebViewDidRemoveFrameFromHierarchy.mm. + + Added -[WebFrameLoadDelegate webView:didRemoveFrameFromHierarchy:]. + + * WebCoreSupport/WebFrameLoaderClient.mm: + (WebFrameLoaderClient::detachedFromParent2): Added a call to the new frame load delegate + method. + * WebView/WebDelegateImplementationCaching.h: + (WebFrameLoadDelegateImplementationCache): Added the new method to the cache. + * WebView/WebFrameLoadDelegatePrivate.h: Declared the new delegate method. + * WebView/WebView.mm: + (-[WebView _cacheFrameLoadDelegateImplementations]): Added the new method to the cache. + 2013-01-07 Mike West Make the IFRAME_SEAMLESS flag runtime-enabled. diff --git a/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm b/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm index 57c5a68..6e53aff 100644 --- a/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm +++ b/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm @@ -259,6 +259,10 @@ void WebFrameLoaderClient::detachedFromParent2() WebView *webView = getWebView(m_webFrame.get()); [webView removePluginInstanceViewsFor:(m_webFrame.get())]; [m_webFrame->_private->webFrameView _setWebFrame:nil]; // needed for now to be compatible w/ old behavior + + WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView); + if (implementations->didRemoveFrameFromHierarchyFunc) + CallFrameLoadDelegate(implementations->didRemoveFrameFromHierarchyFunc, webView, @selector(webView:didRemoveFrameFromHierarchy:), m_webFrame.get()); } void WebFrameLoaderClient::detachedFromParent3() diff --git a/Source/WebKit/mac/WebView/WebDelegateImplementationCaching.h b/Source/WebKit/mac/WebView/WebDelegateImplementationCaching.h index 5c1b33e..c24d073 100644 --- a/Source/WebKit/mac/WebView/WebDelegateImplementationCaching.h +++ b/Source/WebKit/mac/WebView/WebDelegateImplementationCaching.h @@ -79,6 +79,7 @@ struct WebFrameLoadDelegateImplementationCache { IMP didDisplayInsecureContentFunc; IMP didRunInsecureContentFunc; IMP didDetectXSSFunc; + IMP didRemoveFrameFromHierarchyFunc; }; struct WebScriptDebugDelegateImplementationCache { diff --git a/Source/WebKit/mac/WebView/WebFrameLoadDelegatePrivate.h b/Source/WebKit/mac/WebView/WebFrameLoadDelegatePrivate.h index f3d21d0..02eb850 100644 --- a/Source/WebKit/mac/WebView/WebFrameLoadDelegatePrivate.h +++ b/Source/WebKit/mac/WebView/WebFrameLoadDelegatePrivate.h @@ -40,5 +40,6 @@ - (void)webView:(WebView *)webView didPushStateWithinPageForFrame:(WebFrame *)frame; - (void)webView:(WebView *)webView didReplaceStateWithinPageForFrame:(WebFrame *)frame; - (void)webView:(WebView *)webView didPopStateWithinPageForFrame:(WebFrame *)frame; +- (void)webView:(WebView *)webView didRemoveFrameFromHierarchy:(WebFrame *)frame; @end diff --git a/Source/WebKit/mac/WebView/WebView.mm b/Source/WebKit/mac/WebView/WebView.mm index 438a40b..b5aa7b17 100644 --- a/Source/WebKit/mac/WebView/WebView.mm +++ b/Source/WebKit/mac/WebView/WebView.mm @@ -1659,6 +1659,7 @@ static inline IMP getMethod(id o, SEL s) cache->didDisplayInsecureContentFunc = getMethod(delegate, @selector(webViewDidDisplayInsecureContent:)); cache->didRunInsecureContentFunc = getMethod(delegate, @selector(webView:didRunInsecureContent:)); cache->didDetectXSSFunc = getMethod(delegate, @selector(webView:didDetectXSS:)); + cache->didRemoveFrameFromHierarchyFunc = getMethod(delegate, @selector(webView:didRemoveFrameFromHierarchy:)); // It would be nice to get rid of this code and transition all clients to using didLayout instead of // didFirstLayoutInFrame and didFirstVisuallyNonEmptyLayoutInFrame. In the meantime, this is required diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 7399aa9..1a98f83 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,19 @@ +2013-01-07 Dan Bernstein + + [mac] WebKit1 clients can’t tell when a frame has been removed from the hierarchy + https://bugs.webkit.org/show_bug.cgi?id=106261 + + Reviewed by Simon Fraser. + + Added a test for -[WebFrameLoadDelegate webView:didRemoveFrameFromHierarchy:]. + + * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: + * TestWebKitAPI/Tests/mac/WebViewDidRemoveFrameFromHierarchy.mm: Added. + (-[DidRemoveFrameFromHierarchyFrameLoadDelegate webView:didFinishLoadForFrame:]): + (-[DidRemoveFrameFromHierarchyFrameLoadDelegate webView:didRemoveFrameFromHierarchy:]): + (TestWebKitAPI): + (TestWebKitAPI::TEST): + 2013-01-07 Ojan Vafai Add the Apple MountainLion bots to garden-o-matic. diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj index fd9b75b..756774e 100644 --- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj +++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj @@ -58,6 +58,7 @@ 37DC6791140D7D7600ABCCDB /* DOMRangeOfString.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */; }; 37E1064C1697681800B78BD0 /* DOMHTMLTableCellElementCellAbove.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 37E1064B169767F700B78BD0 /* DOMHTMLTableCellElementCellAbove.html */; }; 37E1064D16976C8500B78BD0 /* DOMHTMLTableCellCellAbove.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37E1064A1697676400B78BD0 /* DOMHTMLTableCellCellAbove.mm */; }; + 37E38C34169B7D010084C28C /* WebViewDidRemoveFrameFromHierarchy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37E38C33169B7D010084C28C /* WebViewDidRemoveFrameFromHierarchy.mm */; }; 440A1D3914A0103A008A66F2 /* KURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 440A1D3814A0103A008A66F2 /* KURL.cpp */; }; 4BB4160216815B2600824238 /* JSWrapperForNodeInWebFrame.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BB4160116815B2600824238 /* JSWrapperForNodeInWebFrame.mm */; }; 4BB4160416815F9100824238 /* ElementAtPointInWebFrame.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BB4160316815F9100824238 /* ElementAtPointInWebFrame.mm */; }; @@ -311,6 +312,7 @@ 37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DOMRangeOfString.html; sourceTree = ""; }; 37E1064A1697676400B78BD0 /* DOMHTMLTableCellCellAbove.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMHTMLTableCellCellAbove.mm; sourceTree = ""; }; 37E1064B169767F700B78BD0 /* DOMHTMLTableCellElementCellAbove.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DOMHTMLTableCellElementCellAbove.html; sourceTree = ""; }; + 37E38C33169B7D010084C28C /* WebViewDidRemoveFrameFromHierarchy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewDidRemoveFrameFromHierarchy.mm; sourceTree = ""; }; 440A1D3814A0103A008A66F2 /* KURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KURL.cpp; sourceTree = ""; }; 44A622C114A0E2B60048515B /* WTFStringUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTFStringUtilities.h; sourceTree = ""; }; 4BB4160116815B2600824238 /* JSWrapperForNodeInWebFrame.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JSWrapperForNodeInWebFrame.mm; sourceTree = ""; }; @@ -785,6 +787,7 @@ 37A6895D148A9B50005100FA /* SubresourceErrorCrash.mm */, E490296714E2E3A4002BEDD1 /* TypingStyleCrash.mm */, 51FBBB4C1513D4E900822738 /* WebViewCanPasteURL.mm */, + 37E38C33169B7D010084C28C /* WebViewDidRemoveFrameFromHierarchy.mm */, A5E2027215B2181900C13E14 /* WindowlessWebViewWithMedia.mm */, 00CD9F6215BE312C002DA2CE /* BackForwardList.mm */, ); @@ -1054,6 +1057,7 @@ 4BB4160416815F9100824238 /* ElementAtPointInWebFrame.mm in Sources */, 3751AF7C169518F800764319 /* DOMNodeFromJSObject.mm in Sources */, 37E1064D16976C8500B78BD0 /* DOMHTMLTableCellCellAbove.mm in Sources */, + 37E38C34169B7D010084C28C /* WebViewDidRemoveFrameFromHierarchy.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tools/TestWebKitAPI/Tests/mac/WebViewDidRemoveFrameFromHierarchy.mm b/Tools/TestWebKitAPI/Tests/mac/WebViewDidRemoveFrameFromHierarchy.mm new file mode 100644 index 0000000..fbe8af5 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/mac/WebViewDidRemoveFrameFromHierarchy.mm @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2013 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "config.h" +#import "PlatformUtilities.h" +#import +#import + +@interface DidRemoveFrameFromHierarchyFrameLoadDelegate : NSObject +@end + +static bool didFinishLoad; +static bool didRemoveFrame; + +@implementation DidRemoveFrameFromHierarchyFrameLoadDelegate + +- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame +{ + didFinishLoad = true; +} + +- (void)webView:(WebView *)sender didRemoveFrameFromHierarchy:(WebFrame *)frame +{ + didRemoveFrame = true; +} + +@end + +namespace TestWebKitAPI { + +TEST(WebKit1, DidRemoveFrameFromHierarchy) +{ + RetainPtr webView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]); + RetainPtr frameLoadDelegate = adoptNS([[DidRemoveFrameFromHierarchyFrameLoadDelegate alloc] init]); + + webView.get().frameLoadDelegate = frameLoadDelegate.get(); + WebFrame *mainFrame = webView.get().mainFrame; + + NSString *bodyWithIFrameString = @""; + NSURL *aboutBlankURL = [NSURL URLWithString:@"about:blank"]; + + [mainFrame loadHTMLString:bodyWithIFrameString baseURL:aboutBlankURL]; + Util::run(&didFinishLoad); + + EXPECT_FALSE(didRemoveFrame); + [webView.get() stringByEvaluatingJavaScriptFromString:@"document.body.removeChild(document.getElementById('iframe'))"]; + EXPECT_TRUE(didRemoveFrame); + + didFinishLoad = false; + didRemoveFrame = false; + + [mainFrame loadHTMLString:bodyWithIFrameString baseURL:aboutBlankURL]; + Util::run(&didFinishLoad); + + // The delegate method is not called when the frame is removed due to navigation in an ancestor frame. + EXPECT_FALSE(didRemoveFrame); + [mainFrame loadHTMLString:@"" baseURL:aboutBlankURL]; + EXPECT_FALSE(didRemoveFrame); +} + +} // namespace TestWebKitAPI -- 1.8.3.1