Title: [205783] trunk
Revision
205783
Author
timothy_hor...@apple.com
Date
2016-09-09 19:20:11 -0700 (Fri, 09 Sep 2016)

Log Message

WKThumbnailView should expose a mode where it can be reparented without resnapshotting
https://bugs.webkit.org/show_bug.cgi?id=161828
<rdar://problem/28229756>

Reviewed by Alex Christensen.

* UIProcess/API/Cocoa/_WKThumbnailView.h:
* UIProcess/API/Cocoa/_WKThumbnailView.mm:
(-[_WKThumbnailView initWithFrame:fromWKView:]):
(-[_WKThumbnailView _viewWasUnparented]):
Add such a mode. Bail from snapshot teardown when unparented if it is on.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/WKThumbnailView.mm: Added.
(-[SnapshotSizeObserver observeValueForKeyPath:ofObject:change:context:]):
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::setPageLoaderClient):
(TestWebKitAPI::TEST):
Add a test ensuring that this behaves correctly.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (205782 => 205783)


--- trunk/Source/WebKit2/ChangeLog	2016-09-10 02:06:39 UTC (rev 205782)
+++ trunk/Source/WebKit2/ChangeLog	2016-09-10 02:20:11 UTC (rev 205783)
@@ -1,3 +1,17 @@
+2016-09-09  Tim Horton  <timothy_hor...@apple.com>
+
+        WKThumbnailView should expose a mode where it can be reparented without resnapshotting
+        https://bugs.webkit.org/show_bug.cgi?id=161828
+        <rdar://problem/28229756>
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/Cocoa/_WKThumbnailView.h:
+        * UIProcess/API/Cocoa/_WKThumbnailView.mm:
+        (-[_WKThumbnailView initWithFrame:fromWKView:]):
+        (-[_WKThumbnailView _viewWasUnparented]):
+        Add such a mode. Bail from snapshot teardown when unparented if it is on.
+
 2016-09-08  Dean Jackson  <d...@apple.com>
 
         Expose Apple Pencil data to Touch events

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.h (205782 => 205783)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.h	2016-09-10 02:06:39 UTC (rev 205782)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.h	2016-09-10 02:20:11 UTC (rev 205783)
@@ -42,6 +42,9 @@
 @property (nonatomic, readonly) CGSize snapshotSize;
 @property (nonatomic) BOOL exclusivelyUsesSnapshot;
 
+// Defaults to NO.
+@property (nonatomic) BOOL shouldKeepSnapshotWhenRemovedFromSuperview;
+
 // This should be removed when all clients go away; it is always YES now.
 @property (nonatomic) BOOL usesSnapshot;
 

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.mm (205782 => 205783)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.mm	2016-09-10 02:06:39 UTC (rev 205782)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKThumbnailView.mm	2016-09-10 02:20:11 UTC (rev 205783)
@@ -59,6 +59,7 @@
 @synthesize snapshotSize=_snapshotSize;
 @synthesize _waitingForSnapshot=_waitingForSnapshot;
 @synthesize exclusivelyUsesSnapshot=_exclusivelyUsesSnapshot;
+@synthesize shouldKeepSnapshotWhenRemovedFromSuperview=_shouldKeepSnapshotWhenRemovedFromSuperview;
 
 - (instancetype)initWithFrame:(NSRect)frame fromWKView:(WKView *)wkView
 {
@@ -109,6 +110,9 @@
         _webPageProxy->setMayStartMediaWhenInWindow(_originalMayStartMediaWhenInWindow);
     }
 
+    if (_shouldKeepSnapshotWhenRemovedFromSuperview)
+        return;
+
     self.layer.contents = nil;
     _lastSnapshotScale = NAN;
 }

Modified: trunk/Tools/ChangeLog (205782 => 205783)


--- trunk/Tools/ChangeLog	2016-09-10 02:06:39 UTC (rev 205782)
+++ trunk/Tools/ChangeLog	2016-09-10 02:20:11 UTC (rev 205783)
@@ -1,3 +1,19 @@
+2016-09-09  Tim Horton  <timothy_hor...@apple.com>
+
+        WKThumbnailView should expose a mode where it can be reparented without resnapshotting
+        https://bugs.webkit.org/show_bug.cgi?id=161828
+        <rdar://problem/28229756>
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/WKThumbnailView.mm: Added.
+        (-[SnapshotSizeObserver observeValueForKeyPath:ofObject:change:context:]):
+        (TestWebKitAPI::didFinishLoadForFrame):
+        (TestWebKitAPI::setPageLoaderClient):
+        (TestWebKitAPI::TEST):
+        Add a test ensuring that this behaves correctly.
+
 2016-09-09  Alex Christensen  <achristen...@webkit.org>
 
         URLParser: Keep track of cannot-be-a-base-url according to spec

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (205782 => 205783)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-09-10 02:06:39 UTC (rev 205782)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-09-10 02:20:11 UTC (rev 205783)
@@ -53,6 +53,7 @@
 		2D00065F1C1F589A0088E6A7 /* WKPDFViewResizeCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */; };
 		2D1646E21D1862CD00015A1A /* DeferredViewInWindowStateChange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1646E11D1862CD00015A1A /* DeferredViewInWindowStateChange.mm */; };
 		2D1C04A71D76298B000A6816 /* TestNavigationDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */; };
+		2D4CF8BD1D8360CC0001CE8D /* WKThumbnailView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.mm */; };
 		2D51A0C71C8BF00C00765C45 /* DOMHTMLVideoElementWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */; };
 		2DC4CF771D2D9DD800ECCC94 /* DataDetection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DC4CF761D2D9DD800ECCC94 /* DataDetection.mm */; };
 		2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
@@ -741,6 +742,7 @@
 		2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestNavigationDelegate.h; path = cocoa/TestNavigationDelegate.h; sourceTree = "<group>"; };
 		2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestNavigationDelegate.mm; path = cocoa/TestNavigationDelegate.mm; sourceTree = "<group>"; };
 		2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FixedLayoutSize.mm; sourceTree = "<group>"; };
+		2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKThumbnailView.mm; path = WebKit2/WKThumbnailView.mm; sourceTree = "<group>"; };
 		2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMHTMLVideoElementWrapper.mm; sourceTree = "<group>"; };
 		2D640B5417875DFF00BFAF99 /* ScrollPinningBehaviors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollPinningBehaviors.cpp; sourceTree = "<group>"; };
 		2D8104CB1BEC13E70020DA46 /* FindInPage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FindInPage.mm; sourceTree = "<group>"; };
@@ -1505,6 +1507,7 @@
 				2943BE84161DFEB800999E3D /* UserContentTest.mm */,
 				BC3C4C7D14587AA60025FB62 /* WKBrowsingContextGroupTest.mm */,
 				BC3C4C7014575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm */,
+				2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.mm */,
 			);
 			name = "WebKit2 Objective-C";
 			sourceTree = "<group>";
@@ -2390,6 +2393,7 @@
 				7C83E0C61D0A654E00FEBCF3 /* VideoControlsManager.mm in Sources */,
 				0F139E771A423A5B00F590F5 /* WeakObjCPtr.mm in Sources */,
 				7CCE7F191A411AE600447C4C /* WebArchive.cpp in Sources */,
+				2D4CF8BD1D8360CC0001CE8D /* WKThumbnailView.mm in Sources */,
 				7C83E04C1D0A641800FEBCF3 /* WebCoreNSURLSession.mm in Sources */,
 				7CCE7F1A1A411AE600447C4C /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */,
 				7CCE7EAB1A411A2400447C4C /* WebKitAgnosticTest.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKThumbnailView.mm (0 => 205783)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKThumbnailView.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKThumbnailView.mm	2016-09-10 02:20:11 UTC (rev 205783)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI && PLATFORM(MAC) && WK_API_ENABLED
+
+#import "_javascript_Test.h"
+#import "PlatformUtilities.h"
+#import "PlatformWebView.h"
+#import <WebKit/WKViewPrivate.h>
+#import <WebKit/_WKThumbnailView.h>
+#import <wtf/RetainPtr.h>
+
+static bool didFinishLoad;
+static bool didTakeSnapshot;
+
+static void *snapshotSizeChangeKVOContext = &snapshotSizeChangeKVOContext;
+
+@interface SnapshotSizeObserver : NSObject
+@end
+
+@implementation SnapshotSizeObserver
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+    if (context == snapshotSizeChangeKVOContext) {
+        didTakeSnapshot = true;
+        return;
+    }
+
+    [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*)
+{
+    didFinishLoad = true;
+}
+
+static void setPageLoaderClient(WKPageRef page)
+{
+    WKPageLoaderClientV0 loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+
+    loaderClient.base.version = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+
+    WKPageSetPageLoaderClient(page, &loaderClient.base);
+}
+
+TEST(WebKit2, WKThumbnailViewKeepSnapshotWhenRemovedFromSuperview)
+{
+    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("MouseMoveAfterCrashTest"));
+
+    PlatformWebView webView(context.get());
+    WKView *wkView = webView.platformView();
+    setPageLoaderClient(webView.page());
+
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("lots-of-text", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    RetainPtr<_WKThumbnailView> thumbnailView = adoptNS([[_WKThumbnailView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) fromWKView:wkView]);
+
+    RetainPtr<SnapshotSizeObserver> observer = adoptNS([[SnapshotSizeObserver alloc] init]);
+
+    [thumbnailView addObserver:observer.get() forKeyPath:@"snapshotSize" options:NSKeyValueObservingOptionNew context:snapshotSizeChangeKVOContext];
+
+    [wkView.window.contentView addSubview:thumbnailView.get()];
+    Util::run(&didTakeSnapshot);
+    didTakeSnapshot = false;
+
+    EXPECT_EQ([thumbnailView snapshotSize].width, 800);
+    EXPECT_FALSE([thumbnailView layer].contents == nil);
+    [thumbnailView removeFromSuperview];
+
+    // The snapshot should be removed when unparented.
+    EXPECT_TRUE([thumbnailView layer].contents == nil);
+
+    [wkView.window.contentView addSubview:thumbnailView.get()];
+    Util::run(&didTakeSnapshot);
+    didTakeSnapshot = false;
+
+    [thumbnailView setShouldKeepSnapshotWhenRemovedFromSuperview:YES];
+
+    EXPECT_EQ([thumbnailView snapshotSize].width, 800);
+    EXPECT_FALSE([thumbnailView layer].contents == nil);
+    [thumbnailView removeFromSuperview];
+
+    // This time, the snapshot should remain while unparented, because we unset shouldKeepSnapshotWhenRemovedFromSuperview.
+    EXPECT_FALSE([thumbnailView layer].contents == nil);
+
+    [thumbnailView removeObserver:observer.get() forKeyPath:@"snapshotSize" context:snapshotSizeChangeKVOContext];
+}
+
+} // namespace TestWebKitAPI
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to