Diff
Modified: trunk/Source/WebKit2/ChangeLog (214296 => 214297)
--- trunk/Source/WebKit2/ChangeLog 2017-03-23 06:01:39 UTC (rev 214296)
+++ trunk/Source/WebKit2/ChangeLog 2017-03-23 06:21:25 UTC (rev 214297)
@@ -1,3 +1,30 @@
+2017-03-22 Andy Estes <[email protected]>
+
+ [Cocoa] Add an option to exclude overflow when snapshotting a WKWebProcessPlugInNodeHandle
+ https://bugs.webkit.org/show_bug.cgi?id=169991
+ <rdar://problem/30141083>
+
+ Reviewed by Tim Horton.
+
+ When snapshotting an element using -[WKWebProcessPlugInNodeHandle renderedImageWithOptions:],
+ the image is sized to encompass all descendants, even if the element is styled with
+ overflow:hidden. This patch adds a WKSnapshotOption to exclude overflow, resulting in an
+ image that's always sized to the node's bounding box.
+
+ * Shared/API/c/WKImage.h: Defined kWKSnapshotOptionsExcludeOverflow.
+ * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:
+ (-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:]): Converted the
+ WKSnapshotOptions argument to a SnapshotOptions using toSnapshotOptions(), and called
+ InjectedBundleNodeHandle::renderedImage() with shouldExcludeOverflow set to true if the
+ WKSnapshotOptions included kWKSnapshotOptionsExcludeOverflow.
+ * WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:
+ (WKBundleNodeHandleCopySnapshotWithOptions): Ditto.
+ * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
+ (WebKit::InjectedBundleNodeHandle::renderedImage): If shouldExcludeOverflow is true, use
+ RenderObject::absoluteBoundingBoxRectIgnoringTransforms() as the paintingRect for
+ imageForRect().
+ * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h:
+
2017-03-22 Wenson Hsieh <[email protected]>
WKScrollView should not require data interaction gestures to fail before panning
Modified: trunk/Source/WebKit2/Shared/API/c/WKImage.h (214296 => 214297)
--- trunk/Source/WebKit2/Shared/API/c/WKImage.h 2017-03-23 06:01:39 UTC (rev 214296)
+++ trunk/Source/WebKit2/Shared/API/c/WKImage.h 2017-03-23 06:21:25 UTC (rev 214297)
@@ -46,6 +46,7 @@
kWKSnapshotOptionsForceBlackText = 1 << 4,
kWKSnapshotOptionsForceWhiteText = 1 << 5,
kWKSnapshotOptionsPrinting = 1 << 6,
+ kWKSnapshotOptionsExcludeOverflow = 1 << 7,
};
typedef uint32_t WKSnapshotOptions;
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm (214296 => 214297)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm 2017-03-23 06:01:39 UTC (rev 214296)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm 2017-03-23 06:21:25 UTC (rev 214297)
@@ -26,6 +26,7 @@
#import "config.h"
#import "WKWebProcessPlugInNodeHandleInternal.h"
+#import "WKSharedAPICast.h"
#import "WKWebProcessPlugInFrameInternal.h"
#import <WebCore/IntRect.h>
#import <WebKit/WebImage.h>
@@ -67,7 +68,7 @@
#if PLATFORM(IOS)
- (UIImage *)renderedImageWithOptions:(WKSnapshotOptions)options
{
- RefPtr<WebImage> image = _nodeHandle->renderedImage(options);
+ RefPtr<WebImage> image = _nodeHandle->renderedImage(toSnapshotOptions(options), options & kWKSnapshotOptionsExcludeOverflow);
if (!image)
return nil;
@@ -78,7 +79,7 @@
#if PLATFORM(MAC)
- (NSImage *)renderedImageWithOptions:(WKSnapshotOptions)options
{
- RefPtr<WebImage> image = _nodeHandle->renderedImage(options);
+ RefPtr<WebImage> image = _nodeHandle->renderedImage(toSnapshotOptions(options), options & kWKSnapshotOptionsExcludeOverflow);
if (!image)
return nil;
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp (214296 => 214297)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp 2017-03-23 06:01:39 UTC (rev 214296)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp 2017-03-23 06:21:25 UTC (rev 214297)
@@ -75,7 +75,7 @@
WKImageRef WKBundleNodeHandleCopySnapshotWithOptions(WKBundleNodeHandleRef nodeHandleRef, WKSnapshotOptions options)
{
- RefPtr<WebImage> image = toImpl(nodeHandleRef)->renderedImage(toSnapshotOptions(options));
+ RefPtr<WebImage> image = toImpl(nodeHandleRef)->renderedImage(toSnapshotOptions(options), options & kWKSnapshotOptionsExcludeOverflow);
return toAPI(image.leakRef());
}
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp (214296 => 214297)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp 2017-03-23 06:01:39 UTC (rev 214296)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp 2017-03-23 06:21:25 UTC (rev 214297)
@@ -165,7 +165,7 @@
return snapshot;
}
-RefPtr<WebImage> InjectedBundleNodeHandle::renderedImage(SnapshotOptions options)
+RefPtr<WebImage> InjectedBundleNodeHandle::renderedImage(SnapshotOptions options, bool shouldExcludeOverflow)
{
Frame* frame = m_node->document().frame();
if (!frame)
@@ -181,8 +181,13 @@
if (!renderer)
return nullptr;
- LayoutRect topLevelRect;
- IntRect paintingRect = snappedIntRect(renderer->paintingRootRect(topLevelRect));
+ IntRect paintingRect;
+ if (shouldExcludeOverflow)
+ paintingRect = renderer->absoluteBoundingBoxRectIgnoringTransforms();
+ else {
+ LayoutRect topLevelRect;
+ paintingRect = snappedIntRect(renderer->paintingRootRect(topLevelRect));
+ }
frameView->setNodeToDraw(m_node.ptr());
auto image = imageForRect(frameView, paintingRect, options);
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h (214296 => 214297)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h 2017-03-23 06:01:39 UTC (rev 214296)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h 2017-03-23 06:21:25 UTC (rev 214297)
@@ -61,7 +61,7 @@
// Note: These should only be operations that are not exposed to _javascript_.
WebCore::IntRect elementBounds();
WebCore::IntRect renderRect(bool*);
- RefPtr<WebImage> renderedImage(SnapshotOptions);
+ RefPtr<WebImage> renderedImage(SnapshotOptions, bool shouldExcludeOverflow);
RefPtr<InjectedBundleRangeHandle> visibleRange();
void setHTMLInputElementValueForUser(const String&);
void setHTMLInputElementSpellcheckEnabled(bool);
Modified: trunk/Tools/ChangeLog (214296 => 214297)
--- trunk/Tools/ChangeLog 2017-03-23 06:01:39 UTC (rev 214296)
+++ trunk/Tools/ChangeLog 2017-03-23 06:21:25 UTC (rev 214297)
@@ -1,3 +1,21 @@
+2017-03-22 Andy Estes <[email protected]>
+
+ [Cocoa] Add an option to exclude overflow when snapshotting a WKWebProcessPlugInNodeHandle
+ https://bugs.webkit.org/show_bug.cgi?id=169991
+ <rdar://problem/30141083>
+
+ Reviewed by Tim Horton.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptions.mm: Added.
+ (-[RenderedImageWithOptionsObject didRenderImageWithSize:]):
+ (TEST):
+ * TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptionsPlugIn.mm: Added.
+ (-[RenderedImageWithOptionsPlugIn webProcessPlugIn:didCreateBrowserContextController:]):
+ (-[RenderedImageWithOptionsPlugIn webProcessPlugInBrowserContextController:didFinishLoadForFrame:]):
+ * TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptionsProtocol.h: Added.
+ * TestWebKitAPI/Tests/WebKit2Cocoa/rendered-image-excluding-overflow.html: Added.
+
2017-03-22 Matt Rajca <[email protected]>
Only run volume-related autoplay policy tests on Mac.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (214296 => 214297)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2017-03-23 06:01:39 UTC (rev 214296)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2017-03-23 06:21:25 UTC (rev 214297)
@@ -478,6 +478,9 @@
A10F047E1E3AD29C00C95E19 /* NSFileManagerExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = A10F047C1E3AD29C00C95E19 /* NSFileManagerExtras.mm */; };
A1146A8D1D2D7115000FE710 /* ContentFiltering.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1146A8A1D2D704F000FE710 /* ContentFiltering.mm */; };
A125478F1DB18B9400358564 /* LoadDataWithNilMIMEType.mm in Sources */ = {isa = PBXBuildFile; fileRef = A125478D1DB18B9400358564 /* LoadDataWithNilMIMEType.mm */; };
+ A12DDBFB1E836F0700CF6CAE /* RenderedImageWithOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = A12DDBF91E836F0700CF6CAE /* RenderedImageWithOptions.mm */; };
+ A12DDC001E8373E700CF6CAE /* rendered-image-excluding-overflow.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A12DDBFF1E8373C100CF6CAE /* rendered-image-excluding-overflow.html */; };
+ A12DDC021E837C2400CF6CAE /* RenderedImageWithOptionsPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = A12DDBFC1E836FF100CF6CAE /* RenderedImageWithOptionsPlugIn.mm */; };
A13EBBAA1B87428D00097110 /* WebProcessPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = A13EBBA91B87428D00097110 /* WebProcessPlugIn.mm */; };
A13EBBAB1B87434600097110 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
A13EBBB01B87436F00097110 /* BundleParametersPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = A13EBBAE1B87436F00097110 /* BundleParametersPlugIn.mm */; };
@@ -654,6 +657,7 @@
dstPath = TestWebKitAPI.resources;
dstSubfolderSpec = 7;
files = (
+ A12DDC001E8373E700CF6CAE /* rendered-image-excluding-overflow.html in Copy Resources */,
C99BDF891E80980400C7170E /* autoplay-zero-volume-check.html in Copy Resources */,
A14AAB651E78DC5400C1ADC2 /* encrypted.pdf in Copy Resources */,
A1409AD91E7254D4004949D9 /* password-protected.pages in Copy Resources */,
@@ -1235,6 +1239,10 @@
A10F047C1E3AD29C00C95E19 /* NSFileManagerExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NSFileManagerExtras.mm; sourceTree = "<group>"; };
A1146A8A1D2D704F000FE710 /* ContentFiltering.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentFiltering.mm; sourceTree = "<group>"; };
A125478D1DB18B9400358564 /* LoadDataWithNilMIMEType.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadDataWithNilMIMEType.mm; sourceTree = "<group>"; };
+ A12DDBF91E836F0700CF6CAE /* RenderedImageWithOptions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderedImageWithOptions.mm; sourceTree = "<group>"; };
+ A12DDBFC1E836FF100CF6CAE /* RenderedImageWithOptionsPlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderedImageWithOptionsPlugIn.mm; sourceTree = "<group>"; };
+ A12DDBFF1E8373C100CF6CAE /* rendered-image-excluding-overflow.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "rendered-image-excluding-overflow.html"; sourceTree = "<group>"; };
+ A12DDC011E8374F500CF6CAE /* RenderedImageWithOptionsProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderedImageWithOptionsProtocol.h; sourceTree = "<group>"; };
A13EBB491B87339E00097110 /* TestWebKitAPI.wkbundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestWebKitAPI.wkbundle; sourceTree = BUILT_PRODUCTS_DIR; };
A13EBB521B87346600097110 /* WebProcessPlugIn.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebProcessPlugIn.xcconfig; sourceTree = "<group>"; };
A13EBB541B8734E000097110 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -1650,6 +1658,9 @@
1A4F81C81BDFFD18004E672E /* RemoteObjectRegistry.mm */,
1A4F81CD1BDFFD53004E672E /* RemoteObjectRegistryPlugIn.mm */,
CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */,
+ A12DDBF91E836F0700CF6CAE /* RenderedImageWithOptions.mm */,
+ A12DDBFC1E836FF100CF6CAE /* RenderedImageWithOptionsPlugIn.mm */,
+ A12DDC011E8374F500CF6CAE /* RenderedImageWithOptionsProtocol.h */,
37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */,
@@ -1857,6 +1868,7 @@
CEBCA1371E3A803400C73293 /* page-without-csp.html */,
CEBCA1361E3A803400C73293 /* page-without-csp-iframe.html */,
A1409AD81E7254AC004949D9 /* password-protected.pages */,
+ A12DDBFF1E8373C100CF6CAE /* rendered-image-excluding-overflow.html */,
F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */,
515BE16E1D4288FF00DD7C68 /* StoreBlobToBeDeleted.html */,
51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */,
@@ -2741,6 +2753,7 @@
7A909A831D877480007E10F8 /* IntSize.cpp in Sources */,
7CCE7EEF1A411AE600447C4C /* EphemeralSessionPushStateNoHistoryCallback.cpp in Sources */,
7CCE7EF01A411AE600447C4C /* EvaluateJavaScript.cpp in Sources */,
+ A12DDBFB1E836F0700CF6CAE /* RenderedImageWithOptions.mm in Sources */,
F4D4F3B91E4E36E400BB2767 /* DataInteractionTests.mm in Sources */,
7CCE7EF11A411AE600447C4C /* FailedLoad.cpp in Sources */,
7C83E04F1D0A641800FEBCF3 /* FileSystem.cpp in Sources */,
@@ -2978,6 +2991,7 @@
1A4F81CF1BDFFD53004E672E /* RemoteObjectRegistryPlugIn.mm in Sources */,
7C882E091C80C630006BF731 /* UserContentWorldPlugIn.mm in Sources */,
37A709AF1E3EA97E00CA5969 /* BundleRangeHandlePlugIn.mm in Sources */,
+ A12DDC021E837C2400CF6CAE /* RenderedImageWithOptionsPlugIn.mm in Sources */,
374B7A611DF371CF00ACCB6C /* BundleEditingDelegatePlugIn.mm in Sources */,
7C83E03D1D0A60D600FEBCF3 /* UtilitiesCocoa.mm in Sources */,
A13EBBAA1B87428D00097110 /* WebProcessPlugIn.mm in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptions.mm (0 => 214297)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptions.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptions.mm 2017-03-23 06:21:25 UTC (rev 214297)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017 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"
+
+#if WK_API_ENABLED
+
+#import "RenderedImageWithOptionsProtocol.h"
+#import "Utilities.h"
+#import "WKWebViewConfigurationExtras.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/WebKit.h>
+#import <WebKit/_WKRemoteObjectInterface.h>
+#import <WebKit/_WKRemoteObjectRegistry.h>
+#import <wtf/RetainPtr.h>
+
+using namespace TestWebKitAPI;
+
+static bool testFinished;
+
+@interface RenderedImageWithOptionsObject : NSObject <RenderedImageWithOptionsProtocol>
+@end
+
+@implementation RenderedImageWithOptionsObject
+
+- (void)didRenderImageWithSize:(CGSize)size
+{
+#if PLATFORM(IOS)
+ CGFloat scale = [UIScreen mainScreen].scale;
+#elif PLATFORM(MAC)
+ CGFloat scale = [NSScreen mainScreen].backingScaleFactor;
+#endif
+ EXPECT_EQ(720, size.width / scale);
+ EXPECT_EQ(540, size.height / scale);
+ testFinished = true;
+}
+
+@end
+
+TEST(WebKit2, RenderedImageExcludingOverflow)
+{
+ WKWebViewConfiguration *configuration = [WKWebViewConfiguration testwebkitapi_configurationWithTestPlugInClassName:@"RenderedImageWithOptionsPlugIn"];
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
+
+ auto object = adoptNS([[RenderedImageWithOptionsObject alloc] init]);
+ _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(RenderedImageWithOptionsProtocol)];
+ [[webView _remoteObjectRegistry] registerExportedObject:object.get() interface:interface];
+
+ [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"rendered-image-excluding-overflow" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+
+ Util::run(&testFinished);
+}
+
+#endif // WK_API_ENABLED
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptionsPlugIn.mm (0 => 214297)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptionsPlugIn.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptionsPlugIn.mm 2017-03-23 06:21:25 UTC (rev 214297)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 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"
+
+#if WK_API_ENABLED
+
+#import "RenderedImageWithOptionsProtocol.h"
+#import <_javascript_Core/_javascript_Core.h>
+#import <WebKit/WKWebProcessPlugIn.h>
+#import <WebKit/WKWebProcessPlugInBrowserContextControllerPrivate.h>
+#import <WebKit/WKWebProcessPlugInFrame.h>
+#import <WebKit/WKWebProcessPlugInLoadDelegate.h>
+#import <WebKit/WKWebProcessPlugInNodeHandle.h>
+#import <WebKit/WKWebProcessPlugInScriptWorld.h>
+#import <WebKit/_WKRemoteObjectInterface.h>
+#import <WebKit/_WKRemoteObjectRegistry.h>
+#import <wtf/RetainPtr.h>
+
+@interface RenderedImageWithOptionsPlugIn : NSObject <WKWebProcessPlugIn, WKWebProcessPlugInLoadDelegate>
+@end
+
+@implementation RenderedImageWithOptionsPlugIn {
+ RetainPtr<id <RenderedImageWithOptionsProtocol>> _remoteObject;
+}
+
+- (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController
+{
+ browserContextController.loadDelegate = self;
+
+ _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(RenderedImageWithOptionsProtocol)];
+ _remoteObject = [browserContextController._remoteObjectRegistry remoteObjectProxyWithInterface:interface];
+}
+
+- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller didFinishLoadForFrame:(WKWebProcessPlugInFrame *)frame
+{
+ JSContext *context = [frame jsContextForWorld:[WKWebProcessPlugInScriptWorld normalWorld]];
+ JSValue *containerValue = [context evaluateScript:@"document.querySelector('.container')"];
+ WKWebProcessPlugInNodeHandle *containerNode = [WKWebProcessPlugInNodeHandle nodeHandleWithJSValue:containerValue inContext:context];
+#if PLATFORM(IOS)
+ UIImage *image = [containerNode renderedImageWithOptions:kWKSnapshotOptionsExcludeOverflow];
+#elif PLATFORM(MAC)
+ NSImage *image = [containerNode renderedImageWithOptions:kWKSnapshotOptionsExcludeOverflow];
+#endif
+ [_remoteObject didRenderImageWithSize:image.size];
+}
+
+@end
+
+#endif // WK_API_ENABLED
Copied: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptionsProtocol.h (from rev 214296, trunk/Source/WebKit2/Shared/API/c/WKImage.h) (0 => 214297)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptionsProtocol.h (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RenderedImageWithOptionsProtocol.h 2017-03-23 06:21:25 UTC (rev 214297)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+@protocol RenderedImageWithOptionsProtocol
+- (void)didRenderImageWithSize:(CGSize)size;
+@end
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/rendered-image-excluding-overflow.html (0 => 214297)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/rendered-image-excluding-overflow.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/rendered-image-excluding-overflow.html 2017-03-23 06:21:25 UTC (rev 214297)
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+ <style>
+ .container {
+ position: absolute;
+ overflow: hidden;
+ width: 720px;
+ height: 540px;
+ background-color: green;
+ }
+ .inner {
+ position: absolute;
+ width: 360px;
+ height: 10540px;
+ top: -10000px;
+ background-color: red;
+ }
+ </style>
+ <div class=container>
+ <div class=inner>
+ </div>
+ </div>
+</html>