<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[212929] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/212929">212929</a></dd>
<dt>Author</dt> <dd>bdakin@apple.com</dd>
<dt>Date</dt> <dd>2017-02-23 15:33:57 -0800 (Thu, 23 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>
Source/WebKit2:
No reliable way to get a snapshot of WKWebView
https://bugs.webkit.org/show_bug.cgi?id=161450
-and corresponding-
&lt;rdar://problem/23846039&gt;

Patch by Beth Dakin  &lt;bdakin@apple.com&gt; + Dan Saunders &lt;dasau@microsoft.com&gt; on 2017-02-23
Reviewed by Tim Horton.

This patch adds a new API to WKWebView to snapshot a rect:
takeSnapshotWithConfiguration:completionHandler:

It also adds a new API object WKSnapshotConfiguration.

* UIProcess/API/Cocoa/WKSnapshotConfiguration.h: Added.
* UIProcess/API/Cocoa/WKSnapshotConfiguration.mm: Added.
(-[WKSnapshotConfiguration copyWithZone:]):
* UIProcess/API/Cocoa/WKWebView.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):
* WebKit2.xcodeproj/project.pbxproj:

Tools:
No reliable way to get a snapshot of WKWebView (macOS)
https://bugs.webkit.org/show_bug.cgi?id=161450
-and corresponding-
&lt;rdar://problem/23846039&gt;

Patch by Beth Dakin  &lt;bdakin@apple.com&gt; + Dan Saunders &lt;dasau@microsoft.com&gt; on 2017-02-23
Reviewed by Tim Horton.

Test for WKWebView’s new API takeSnapshotWithConfiguration:completionHandler:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm: Added.
(convertToCGImage):
(getPixelIndex):
(TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKSnapshotConfigurationh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKSnapshotConfiguration.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKSnapshotConfigurationmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKSnapshotConfiguration.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaWKWebViewSnapshotmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (212928 => 212929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-02-23 23:05:45 UTC (rev 212928)
+++ trunk/Source/WebKit2/ChangeLog        2017-02-23 23:33:57 UTC (rev 212929)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2017-02-23  Beth Dakin  &lt;bdakin@apple.com&gt; + Dan Saunders  &lt;dasau@microsoft.com&gt;
+
+        No reliable way to get a snapshot of WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=161450
+        -and corresponding-
+        &lt;rdar://problem/23846039&gt;
+
+        Reviewed by Tim Horton.
+
+        This patch adds a new API to WKWebView to snapshot a rect:
+        takeSnapshotWithConfiguration:completionHandler:
+
+        It also adds a new API object WKSnapshotConfiguration.
+
+        * UIProcess/API/Cocoa/WKSnapshotConfiguration.h: Added.
+        * UIProcess/API/Cocoa/WKSnapshotConfiguration.mm: Added.
+        (-[WKSnapshotConfiguration copyWithZone:]):
+        * UIProcess/API/Cocoa/WKWebView.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):
+        * WebKit2.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2017-02-23  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         ASSERT in RTCNetwork::IPAddress::decode()
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKSnapshotConfigurationh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKSnapshotConfiguration.h (0 => 212929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKSnapshotConfiguration.h                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKSnapshotConfiguration.h        2017-02-23 23:33:57 UTC (rev 212929)
</span><span class="lines">@@ -0,0 +1,54 @@
</span><ins>+/*
+ * 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 &lt;WebKit/WKFoundation.h&gt;
+
+#if WK_API_ENABLED
+
+#import &lt;Foundation/Foundation.h&gt;
+
+NS_ASSUME_NONNULL_BEGIN
+
+WK_CLASS_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA))
+@interface WKSnapshotConfiguration : NSObject &lt;NSCopying&gt;
+
+/*! @abstract The rect to snapshot in view coordinates.
+ @discussion This rect should be contained within WKWebView's bounds. If the rect is set to the 
+ null rect, the view's bounds will be used. The initial value is the null rect.
+ */
+@property (nonatomic) CGRect rect;
+
+/*! @abstract Specify a custom width to control the size of image you get back. The height will be 
+ computed to maintain the aspect ratio established by rect.
+ @discussion snapshotWidth represents the width in points. If the snapshotWidth is nil, rect's
+ width will be used.
+ */
+@property (nullable, nonatomic, copy) NSNumber *snapshotWidth;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKSnapshotConfigurationmm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKSnapshotConfiguration.mm (0 => 212929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKSnapshotConfiguration.mm                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKSnapshotConfiguration.mm        2017-02-23 23:33:57 UTC (rev 212929)
</span><span class="lines">@@ -0,0 +1,55 @@
</span><ins>+/*
+ * 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 &quot;config.h&quot;
+#import &quot;WKSnapshotConfiguration.h&quot;
+
+#if WK_API_ENABLED
+
+@implementation WKSnapshotConfiguration
+
+- (instancetype)init
+{
+    if (!(self = [super init]))
+        return nil;
+
+    self.rect = CGRectNull;
+    return self;
+}
+
+
+- (id)copyWithZone:(NSZone *)zone
+{
+    WKSnapshotConfiguration *snapshotConfiguration = [(WKSnapshotConfiguration *)[[self class] allocWithZone:zone] init];
+
+    snapshotConfiguration.rect = self.rect;
+    snapshotConfiguration.snapshotWidth = self.snapshotWidth;
+
+    return snapshotConfiguration;
+}
+
+@end
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h (212928 => 212929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h        2017-02-23 23:05:45 UTC (rev 212928)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h        2017-02-23 23:33:57 UTC (rev 212929)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> @class WKBackForwardList;
</span><span class="cx"> @class WKBackForwardListItem;
</span><span class="cx"> @class WKNavigation;
</span><ins>+@class WKSnapshotConfiguration;
</ins><span class="cx"> @class WKWebViewConfiguration;
</span><span class="cx"> 
</span><span class="cx"> @protocol WKNavigationDelegate;
</span><span class="lines">@@ -220,6 +221,19 @@
</span><span class="cx"> */
</span><span class="cx"> - (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^ _Nullable)(_Nullable id, NSError * _Nullable error))completionHandler;
</span><span class="cx"> 
</span><ins>+/*! @abstract Get a snapshot for the visible viewport of WKWebView.
+ @param snapshotConfiguration An object that specifies how the snapshot is configured.
+ @param completionHandler A block to invoke when the snapshot is ready.
+ @discussion If the WKSnapshotConfiguration is nil, the method will snapshot the bounds of the 
+ WKWebView and create an image that is the width of the bounds of the WKWebView and scaled to the 
+ device scale. The completionHandler is passed the image of the viewport contents or an error.
+ */
+#if TARGET_OS_IPHONE
+- (void)takeSnapshotWithConfiguration:(nullable WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void (^)(UIImage * _Nullable snapshotImage, NSError * _Nullable error))completionHandler WK_API_AVAILABLE(ios(WK_IOS_TBA));
+#else
+- (void)takeSnapshotWithConfiguration:(nullable WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void (^)(NSImage * _Nullable snapshotImage, NSError * _Nullable error))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+#endif
+
</ins><span class="cx"> /*! @abstract A Boolean value indicating whether horizontal swipe gestures
</span><span class="cx">  will trigger back-forward list navigations.
</span><span class="cx">  @discussion The default value is NO.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (212928 => 212929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2017-02-23 23:05:45 UTC (rev 212928)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2017-02-23 23:33:57 UTC (rev 212929)
</span><span class="lines">@@ -61,6 +61,7 @@
</span><span class="cx"> #import &quot;WKPreferencesInternal.h&quot;
</span><span class="cx"> #import &quot;WKProcessPoolInternal.h&quot;
</span><span class="cx"> #import &quot;WKSharedAPICast.h&quot;
</span><ins>+#import &quot;WKSnapshotConfiguration.h&quot;
</ins><span class="cx"> #import &quot;WKUIDelegate.h&quot;
</span><span class="cx"> #import &quot;WKUIDelegatePrivate.h&quot;
</span><span class="cx"> #import &quot;WKUserContentControllerInternal.h&quot;
</span><span class="lines">@@ -932,6 +933,67 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if PLATFORM(MAC)
+- (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(NSImage *, NSError *))completionHandler
+{
+    CGRect rectInViewCoordinates = snapshotConfiguration &amp;&amp; !CGRectIsNull(snapshotConfiguration.rect) ? snapshotConfiguration.rect : self.bounds;
+    CGFloat snapshotWidth;
+    if (snapshotConfiguration)
+        snapshotWidth = snapshotConfiguration.snapshotWidth.doubleValue ?: rectInViewCoordinates.size.width;
+    else
+        snapshotWidth = self.bounds.size.width;
+
+    auto handler = makeBlockPtr(completionHandler);
+    CGFloat imageScale = snapshotWidth / rectInViewCoordinates.size.width;
+    CGFloat imageHeight = imageScale * rectInViewCoordinates.size.height;
+
+    // Need to scale by device scale factor or the image will be distorted.
+    CGFloat deviceScale = _page-&gt;deviceScaleFactor();
+    WebCore::IntSize bitmapSize(snapshotWidth, imageHeight);
+    bitmapSize.scale(deviceScale, deviceScale);
+
+    // Software snapshot will not capture elements rendered with hardware acceleration (WebGL, video, etc).
+    _page-&gt;takeSnapshot(WebCore::enclosingIntRect(rectInViewCoordinates), bitmapSize, WebKit::SnapshotOptionsInViewCoordinates, [handler, snapshotWidth, imageHeight](const WebKit::ShareableBitmap::Handle&amp; imageHandle, WebKit::CallbackBase::Error errorCode) {
+        if (errorCode != WebKit::ScriptValueCallback::Error::None) {
+            auto error = createNSError(callbackErrorCode(errorCode));
+            handler(nil, error.get());
+            return;
+        }
+
+        RefPtr&lt;WebKit::ShareableBitmap&gt; bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly);
+        RetainPtr&lt;CGImageRef&gt; cgImage = bitmap ? bitmap-&gt;makeCGImage() : nullptr;
+        RetainPtr&lt;NSImage&gt; nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:NSMakeSize(snapshotWidth, imageHeight)]);
+        handler(nsImage.get(), nil);
+    });
+}
+
+#elif PLATFORM(IOS)
+- (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(UIImage *, NSError *))completionHandler
+{
+    CGRect rectInViewCoordinates = snapshotConfiguration &amp;&amp; !CGRectIsNull(snapshotConfiguration.rect) ? snapshotConfiguration.rect : self.bounds;
+    CGFloat snapshotWidth;
+    if (snapshotConfiguration)
+        snapshotWidth = snapshotConfiguration.snapshotWidth.doubleValue ?: rectInViewCoordinates.size.width;
+    else
+        snapshotWidth = self.bounds.size.width;
+
+    auto handler = makeBlockPtr(completionHandler);
+    CGFloat deviceScale = _page-&gt;deviceScaleFactor();
+
+    [self _snapshotRect:rectInViewCoordinates intoImageOfWidth:(snapshotWidth * deviceScale) completionHandler:^(CGImageRef snapshotImage) {
+        RetainPtr&lt;NSError&gt; error;
+        RetainPtr&lt;UIImage&gt; uiImage;
+
+        if (!snapshotImage)
+            error = createNSError(WKErrorUnknown);
+        else
+            uiImage = adoptNS([[UIImage alloc] initWithCGImage:snapshotImage scale:deviceScale orientation:UIImageOrientationUp]);
+
+        handler(uiImage.get(), error.get());
+    }];
+}
+#endif
+
</ins><span class="cx"> - (NSString *)customUserAgent
</span><span class="cx"> {
</span><span class="cx">     return _page-&gt;customUserAgent();
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (212928 => 212929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2017-02-23 23:05:45 UTC (rev 212928)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2017-02-23 23:33:57 UTC (rev 212929)
</span><span class="lines">@@ -1354,6 +1354,8 @@
</span><span class="cx">                 93A88B471BC8829700ABA5C2 /* APIHitTestResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93A88B421BC8828C00ABA5C2 /* APIHitTestResult.cpp */; };
</span><span class="cx">                 93BDEB01171DD7AF00BFEE1B /* WKPageLoadTypesPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 93BDEB00171DD7AF00BFEE1B /* WKPageLoadTypesPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 93E6A4EE1BC5DD3900F8A0E7 /* _WKHitTestResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E6A4ED1BC5DD3900F8A0E7 /* _WKHitTestResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                93F549B41E3174B7000E7239 /* WKSnapshotConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 93F549B31E3174B7000E7239 /* WKSnapshotConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
+                93F549B61E3174DA000E7239 /* WKSnapshotConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93F549B51E3174DA000E7239 /* WKSnapshotConfiguration.mm */; };
</ins><span class="cx">                 990D28AB1C6420C600986977 /* _WKAutomationSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 990D28A71C6404B000986977 /* _WKAutomationSession.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 990D28AC1C6420CF00986977 /* _WKAutomationSessionDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 990D28A81C6404B000986977 /* _WKAutomationSessionDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 990D28B11C65208D00986977 /* _WKAutomationSessionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 990D28AF1C65203900986977 /* _WKAutomationSessionInternal.h */; };
</span><span class="lines">@@ -3561,6 +3563,8 @@
</span><span class="cx">                 93A88B431BC8828C00ABA5C2 /* APIHitTestResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIHitTestResult.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 93BDEB00171DD7AF00BFEE1B /* WKPageLoadTypesPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPageLoadTypesPrivate.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 93E6A4ED1BC5DD3900F8A0E7 /* _WKHitTestResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKHitTestResult.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                93F549B31E3174B7000E7239 /* WKSnapshotConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKSnapshotConfiguration.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                93F549B51E3174DA000E7239 /* WKSnapshotConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKSnapshotConfiguration.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 990D28A71C6404B000986977 /* _WKAutomationSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKAutomationSession.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 990D28A81C6404B000986977 /* _WKAutomationSessionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKAutomationSessionDelegate.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 990D28AD1C65190400986977 /* _WKAutomationSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKAutomationSession.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -5504,6 +5508,8 @@
</span><span class="cx">                                 51CD1C5F1B34B9C900142CA5 /* WKSecurityOrigin.h */,
</span><span class="cx">                                 51CD1C601B34B9C900142CA5 /* WKSecurityOrigin.mm */,
</span><span class="cx">                                 51CD1C611B34B9C900142CA5 /* WKSecurityOriginInternal.h */,
</span><ins>+                                93F549B31E3174B7000E7239 /* WKSnapshotConfiguration.h */,
+                                93F549B51E3174DA000E7239 /* WKSnapshotConfiguration.mm */,
</ins><span class="cx">                                 1AD8790918B6C38A006CAFD7 /* WKUIDelegate.h */,
</span><span class="cx">                                 3743925718BC4C60001C8675 /* WKUIDelegatePrivate.h */,
</span><span class="cx">                                 1AFA3AC718E61C61003CCBAE /* WKUserContentController.h */,
</span><span class="lines">@@ -8050,6 +8056,7 @@
</span><span class="cx">                                 413075B21DE85F580039EC69 /* LibWebRTCSocketFactory.h in Headers */,
</span><span class="cx">                                 935EEBA4127761D6003322B8 /* InjectedBundleBackForwardListItem.h in Headers */,
</span><span class="cx">                                 BCEE7DC5128B645D009827DA /* InjectedBundleClient.h in Headers */,
</span><ins>+                                93F549B41E3174B7000E7239 /* WKSnapshotConfiguration.h in Headers */,
</ins><span class="cx">                                 7CBB811D1AA0F8B1006B1942 /* InjectedBundleFileHandle.h in Headers */,
</span><span class="cx">                                 BC498618124D10E200D834E1 /* InjectedBundleHitTestResult.h in Headers */,
</span><span class="cx">                                 84477853176FCC0800CDC7BB /* InjectedBundleHitTestResultMediaType.h in Headers */,
</span><span class="lines">@@ -10141,6 +10148,7 @@
</span><span class="cx">                                 2D3A65E61A7C3AA700CAC637 /* WKFrameInfoRef.cpp in Sources */,
</span><span class="cx">                                 BCB9F6A61123DD0D00A137E0 /* WKFramePolicyListener.cpp in Sources */,
</span><span class="cx">                                 E1AEA23014687BDB00804569 /* WKFullKeyboardAccessWatcher.mm in Sources */,
</span><ins>+                                93F549B61E3174DA000E7239 /* WKSnapshotConfiguration.mm in Sources */,
</ins><span class="cx">                                 CDCA85C8132ABA4E00E961DF /* WKFullScreenWindowController.mm in Sources */,
</span><span class="cx">                                 BC54CC1312D674EE005C67B0 /* WKGeolocationManager.cpp in Sources */,
</span><span class="cx">                                 BC06F44F12DBDF3F002D78DE /* WKGeolocationPermissionRequest.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (212928 => 212929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-02-23 23:05:45 UTC (rev 212928)
+++ trunk/Tools/ChangeLog        2017-02-23 23:33:57 UTC (rev 212929)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2017-02-23  Beth Dakin  &lt;bdakin@apple.com&gt; + Dan Saunders  &lt;dasau@microsoft.com&gt;
+
+        No reliable way to get a snapshot of WKWebView (macOS)
+        https://bugs.webkit.org/show_bug.cgi?id=161450
+        -and corresponding-
+        &lt;rdar://problem/23846039&gt;
+
+        Reviewed by Tim Horton.
+
+        Test for WKWebView’s new API takeSnapshotWithConfiguration:completionHandler:
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm: Added.
+        (convertToCGImage):
+        (getPixelIndex):
+        (TEST):
+
</ins><span class="cx"> 2017-02-23  Saam Barati  &lt;sbarati@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Speculative fix for jsc timing out tests
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (212928 => 212929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-02-23 23:05:45 UTC (rev 212928)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-02-23 23:33:57 UTC (rev 212929)
</span><span class="lines">@@ -451,6 +451,8 @@
</span><span class="cx">                 93CFA8671CEB9E38000565A8 /* autofocused-text-input.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93CFA8661CEB9DE1000565A8 /* autofocused-text-input.html */; };
</span><span class="cx">                 93F1DB3414DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F1DB3314DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp */; };
</span><span class="cx">                 93F1DB5714DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F1DB5614DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp */; };
</span><ins>+                93F56DA71E5F9174003EDE84 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C83E0331D0A5F2700FEBCF3 /* libicucore.dylib */; };
+                93F56DA91E5F919D003EDE84 /* WKWebViewSnapshot.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93F56DA81E5F9181003EDE84 /* WKWebViewSnapshot.mm */; };
</ins><span class="cx">                 93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */; };
</span><span class="cx">                 9984FACC1CFFAF60008D198C /* WKWebViewTextInput.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */; };
</span><span class="cx">                 9984FACE1CFFB090008D198C /* editable-body.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9984FACD1CFFB038008D198C /* editable-body.html */; };
</span><span class="lines">@@ -1175,6 +1177,7 @@
</span><span class="cx">                 93F1DB3314DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayout_Bundle.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 93F1DB5414DB1B730024C362 /* NewFirstVisuallyNonEmptyLayoutFails.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFails.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 93F1DB5614DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                93F56DA81E5F9181003EDE84 /* WKWebViewSnapshot.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewSnapshot.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 93F7E86B14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewTextInput.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1420,7 +1423,7 @@
</span><span class="cx">                         isa = PBXFrameworksBuildPhase;
</span><span class="cx">                         buildActionMask = 2147483647;
</span><span class="cx">                         files = (
</span><del>-                                7C83E03F1D0A61A000FEBCF3 /* libicucore.dylib in Frameworks */,
</del><ins>+                                93F56DA71E5F9174003EDE84 /* libicucore.dylib in Frameworks */,
</ins><span class="cx">                         );
</span><span class="cx">                         runOnlyForDeploymentPostprocessing = 0;
</span><span class="cx">                 };
</span><span class="lines">@@ -1621,6 +1624,7 @@
</span><span class="cx">                                 7C417F311D19E14800B8EF53 /* WKWebViewDefaultNavigationDelegate.mm */,
</span><span class="cx">                                 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
</span><span class="cx">                                 D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */,
</span><ins>+                                93F56DA81E5F9181003EDE84 /* WKWebViewSnapshot.mm */,
</ins><span class="cx">                                 9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */,
</span><span class="cx">                         );
</span><span class="cx">                         name = &quot;WebKit2 Cocoa&quot;;
</span><span class="lines">@@ -2391,7 +2395,7 @@
</span><span class="cx">                                 8DD76F9B0486AA7600D96B5E /* Frameworks */,
</span><span class="cx">                                 8DD76F9E0486AA7600D96B5E /* CopyFiles */,
</span><span class="cx">                                 BCB9F4FB112384C000A137E0 /* Copy Resources */,
</span><del>-                                F471CB8B1E565C0F0028055C /* ShellScript */,
</del><ins>+                                F471CB8B1E565C0F0028055C /* Copy additional resources */,
</ins><span class="cx">                         );
</span><span class="cx">                         buildRules = (
</span><span class="cx">                         );
</span><span class="lines">@@ -2503,7 +2507,7 @@
</span><span class="cx"> /* End PBXResourcesBuildPhase section */
</span><span class="cx"> 
</span><span class="cx"> /* Begin PBXShellScriptBuildPhase section */
</span><del>-                F471CB8B1E565C0F0028055C /* ShellScript */ = {
</del><ins>+                F471CB8B1E565C0F0028055C /* Copy additional resources */ = {
</ins><span class="cx">                         isa = PBXShellScriptBuildPhase;
</span><span class="cx">                         buildActionMask = 2147483647;
</span><span class="cx">                         files = (
</span><span class="lines">@@ -2510,9 +2514,9 @@
</span><span class="cx">                         );
</span><span class="cx">                         inputPaths = (
</span><span class="cx">                         );
</span><ins>+                        name = &quot;Copy additional resources&quot;;
</ins><span class="cx">                         outputPaths = (
</span><span class="cx">                         );
</span><del>-                        name = &quot;Copy additional resources&quot;;
</del><span class="cx">                         runOnlyForDeploymentPostprocessing = 0;
</span><span class="cx">                         shellPath = /bin/sh;
</span><span class="cx">                         shellScript = &quot;ADDITIONAL_RESOURCES_PATH=\&quot;usr/local/include/WebKitAdditions/Resources/TestWebKitAPI\&quot;\nDESTINATION_PATH=\&quot;$TARGET_BUILD_DIR/TestWebKitAPI.resources\&quot;\nif [ -d $TARGET_BUILD_DIR/$ADDITIONAL_RESOURCES_PATH ]; then\n    cp $TARGET_BUILD_DIR/$ADDITIONAL_RESOURCES_PATH/* $DESTINATION_PATH\nelif [ -d $SDKROOT/$ADDITIONAL_RESOURCES_PATH ]; then\n    cp $SDKROOT/$ADDITIONAL_RESOURCES_PATH/* $DESTINATION_PATH\nfi&quot;;
</span><span class="lines">@@ -2593,6 +2597,7 @@
</span><span class="cx">                         isa = PBXSourcesBuildPhase;
</span><span class="cx">                         buildActionMask = 2147483647;
</span><span class="cx">                         files = (
</span><ins>+                                93F56DA91E5F919D003EDE84 /* WKWebViewSnapshot.mm in Sources */,
</ins><span class="cx">                                 7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */,
</span><span class="cx">                                 7CCE7EE41A411AE600447C4C /* AboutBlankLoad.cpp in Sources */,
</span><span class="cx">                                 7CCE7EB31A411A7E00447C4C /* AcceptsFirstMouse.mm in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaWKWebViewSnapshotmm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm (0 => 212929)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewSnapshot.mm        2017-02-23 23:33:57 UTC (rev 212929)
</span><span class="lines">@@ -0,0 +1,247 @@
</span><ins>+/*
+ * 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.
+ */
+
+#import &quot;config.h&quot;
+
+#if WK_API_ENABLED
+
+#import &quot;PlatformUtilities.h&quot;
+#import &quot;Test.h&quot;
+#import &quot;TestNavigationDelegate.h&quot;
+#import &lt;WebKit/WKSnapshotConfiguration.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+
+static bool isDone;
+
+#if PLATFORM(MAC)
+typedef NSImage *PlatformImage;
+typedef NSWindow *PlatformWindow;
+
+static RetainPtr&lt;CGImageRef&gt; convertToCGImage(NSImage *image)
+{
+    return [image CGImageForProposedRect:nil context:nil hints:nil];
+}
+
+#else
+typedef UIImage *PlatformImage;
+typedef UIWindow *PlatformWindow;
+
+static RetainPtr&lt;CGImageRef&gt; convertToCGImage(UIImage *image)
+{
+    return image.CGImage;
+}
+#endif
+
+static NSInteger getPixelIndex(NSInteger x, NSInteger y, NSInteger width)
+{
+    return (y * width + x) * 4;
+}
+
+TEST(WKWebView, SnapshotImageError)
+{
+    CGFloat viewWidth = 800;
+    CGFloat viewHeight = 600;
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, viewWidth, viewHeight)]);
+    
+    [webView loadHTMLString:@&quot;&lt;body style='background-color: red;'&gt;&lt;/body&gt;&quot; baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+    [webView _killWebContentProcessAndResetState];
+
+    RetainPtr&lt;WKSnapshotConfiguration&gt; snapshotConfiguration = adoptNS([[WKSnapshotConfiguration alloc] init]);
+    [snapshotConfiguration setRect:NSMakeRect(0, 0, viewWidth, viewHeight)];
+    [snapshotConfiguration setSnapshotWidth:@(viewWidth)];
+
+    isDone = false;
+    [webView takeSnapshotWithConfiguration:snapshotConfiguration.get() completionHandler:^(PlatformImage snapshotImage, NSError *error) {
+        EXPECT_NULL(snapshotImage);
+        EXPECT_WK_STREQ(@&quot;WKErrorDomain&quot;, error.domain);
+
+        isDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;isDone);
+}
+
+TEST(WKWebView, SnapshotImageBaseCase)
+{
+    NSInteger viewWidth = 800;
+    NSInteger viewHeight = 600;
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, viewWidth, viewHeight)]);
+
+    RetainPtr&lt;PlatformWindow&gt; window;
+    CGFloat backingScaleFactor;
+
+#if PLATFORM(MAC)
+    window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
+    [[window contentView] addSubview:webView.get()];
+    backingScaleFactor = [window backingScaleFactor];
+#elif PLATFORM(IOS)
+    window = adoptNS([[UIWindow alloc] initWithFrame:[webView frame]]);
+    [window addSubview:webView.get()];
+    backingScaleFactor = [[window screen] scale];
+#endif
+
+    [webView loadHTMLString:@&quot;&lt;body style='background-color:red;'&gt;&lt;div style='background-color:blue; position:absolute; width:100px; height:100px; top:50px; left:50px'&gt;&lt;/div&gt;&lt;/body&gt;&quot; baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    RetainPtr&lt;WKSnapshotConfiguration&gt; snapshotConfiguration = adoptNS([[WKSnapshotConfiguration alloc] init]);
+    [snapshotConfiguration setRect:NSMakeRect(0, 0, viewWidth, viewHeight)];
+    [snapshotConfiguration setSnapshotWidth:@(viewWidth)];
+
+    isDone = false;
+    [webView takeSnapshotWithConfiguration:snapshotConfiguration.get() completionHandler:^(PlatformImage snapshotImage, NSError *error) {
+        EXPECT_NULL(error);
+
+        EXPECT_EQ(viewWidth, snapshotImage.size.width);
+
+        RetainPtr&lt;CGImageRef&gt; cgImage = convertToCGImage(snapshotImage);
+        RetainPtr&lt;CGColorSpaceRef&gt; colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
+
+        NSInteger viewWidthInPixels = viewWidth * backingScaleFactor;
+        NSInteger viewHeightInPixels = viewHeight * backingScaleFactor;
+
+        unsigned char rgba[viewWidthInPixels * viewHeightInPixels * 4];
+        CGContextRef context = CGBitmapContextCreate(rgba, viewWidthInPixels, viewHeightInPixels, 8, 4 * viewWidthInPixels, colorSpace.get(), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
+        CGContextDrawImage(context, CGRectMake(0, 0, viewWidthInPixels, viewHeightInPixels), cgImage.get());
+
+        NSInteger pixelIndex = getPixelIndex(0, 0, viewWidthInPixels);
+        EXPECT_EQ(255, rgba[pixelIndex]);
+        EXPECT_EQ(0, rgba[pixelIndex + 1]);
+        EXPECT_EQ(0, rgba[pixelIndex + 2]);
+
+        // Inside the blue div (50, 50, 100, 100)
+        pixelIndex = getPixelIndex(55 * backingScaleFactor, 55 * backingScaleFactor, viewWidthInPixels);
+        EXPECT_EQ(0, rgba[pixelIndex]);
+        EXPECT_EQ(0, rgba[pixelIndex + 1]);
+        EXPECT_EQ(255, rgba[pixelIndex + 2]);
+
+        pixelIndex = getPixelIndex(155 * backingScaleFactor, 155 * backingScaleFactor, viewWidthInPixels);
+        EXPECT_EQ(255, rgba[pixelIndex]);
+        EXPECT_EQ(0, rgba[pixelIndex + 1]);
+        EXPECT_EQ(0, rgba[pixelIndex + 2]);
+
+        CGContextRelease(context);
+        isDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;isDone);
+}
+
+TEST(WKWebView, SnapshotImageScale)
+{
+    CGFloat viewWidth = 800;
+    CGFloat viewHeight = 600;
+    CGFloat scaleFactor = 2;
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, viewWidth, viewHeight)]);
+
+    [webView loadHTMLString:@&quot;&lt;body style='background-color: red;'&gt;&lt;/body&gt;&quot; baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    RetainPtr&lt;WKSnapshotConfiguration&gt; snapshotConfiguration = adoptNS([[WKSnapshotConfiguration alloc] init]);
+    [snapshotConfiguration setRect:NSMakeRect(0, 0, viewWidth, viewHeight)];
+    [snapshotConfiguration setSnapshotWidth:@(viewWidth * scaleFactor)];
+
+    isDone = false;
+    [webView takeSnapshotWithConfiguration:snapshotConfiguration.get() completionHandler:^(PlatformImage snapshotImage, NSError *error) {
+        EXPECT_NULL(error);
+        EXPECT_NOT_NULL(snapshotImage);
+        EXPECT_EQ(viewWidth * scaleFactor, snapshotImage.size.width);
+        EXPECT_EQ(viewHeight * scaleFactor, snapshotImage.size.height);
+
+        isDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;isDone);
+}
+
+TEST(WKWebView, SnapshotImageNilConfiguration)
+{
+    CGFloat viewWidth = 800;
+    CGFloat viewHeight = 600;
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, viewWidth, viewHeight)]);
+
+    [webView loadHTMLString:@&quot;&lt;body style='background-color: red;'&gt;&lt;/body&gt;&quot; baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    isDone = false;
+    [webView takeSnapshotWithConfiguration:nil completionHandler:^(PlatformImage snapshotImage, NSError *error) {
+        EXPECT_NULL(error);
+        EXPECT_NOT_NULL(snapshotImage);
+        EXPECT_EQ([webView bounds].size.width, snapshotImage.size.width);
+
+        isDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;isDone);
+}
+
+TEST(WKWebView, SnapshotImageUninitializedConfiguration)
+{
+    CGFloat viewWidth = 800;
+    CGFloat viewHeight = 600;
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, viewWidth, viewHeight)]);
+
+    [webView loadHTMLString:@&quot;&lt;body style='background-color: red;'&gt;&lt;/body&gt;&quot; baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    RetainPtr&lt;WKSnapshotConfiguration&gt; snapshotConfiguration = adoptNS([[WKSnapshotConfiguration alloc] init]);
+
+    isDone = false;
+    [webView takeSnapshotWithConfiguration:snapshotConfiguration.get() completionHandler:^(PlatformImage snapshotImage, NSError *error) {
+        EXPECT_NULL(error);
+        EXPECT_NOT_NULL(snapshotImage);
+        EXPECT_EQ([webView bounds].size.width, snapshotImage.size.width);
+
+        isDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;isDone);
+}
+
+TEST(WKWebView, SnapshotImageUninitializedSnapshotWidth)
+{
+    CGFloat viewWidth = 800;
+    CGFloat viewHeight = 600;
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, viewWidth, viewHeight)]);
+
+    [webView loadHTMLString:@&quot;&lt;body style='background-color: red;'&gt;&lt;/body&gt;&quot; baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    RetainPtr&lt;WKSnapshotConfiguration&gt; snapshotConfiguration = adoptNS([[WKSnapshotConfiguration alloc] init]);
+    [snapshotConfiguration setRect:NSMakeRect(0, 0, viewWidth, viewHeight)];
+
+    isDone = false;
+    [webView takeSnapshotWithConfiguration:snapshotConfiguration.get() completionHandler:^(PlatformImage snapshotImage, NSError *error) {
+        EXPECT_NULL(error);
+        EXPECT_NOT_NULL(snapshotImage);
+        EXPECT_EQ([snapshotConfiguration rect].size.width, snapshotImage.size.width);
+
+        isDone = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;isDone);
+}
+
+#endif
</ins></span></pre>
</div>
</div>

</body>
</html>