<!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>[198907] trunk/Source/WebKit2</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/198907">198907</a></dd>
<dt>Author</dt> <dd>joepeck@webkit.org</dd>
<dt>Date</dt> <dd>2016-03-31 12:03:37 -0700 (Thu, 31 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Automation: Add Automation.screenshot
https://bugs.webkit.org/show_bug.cgi?id=156073
&lt;rdar://problem/25468646&gt;

Reviewed by Timothy Hatcher and Brian Burg.

* UIProcess/Automation/Automation.json:
Add Automation.screenshot which returns base64 encoded PNG data.

* WebProcess/Automation/WebAutomationSessionProxy.h:
* WebProcess/Automation/WebAutomationSessionProxy.messages.in:
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::screenshot):
(WebKit::WebAutomationSession::didTakeScreenshot):
(WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):
Send a message to the WebPage to get an Image of the page
and handle the response.

* UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
(WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):
Convert the bitmap data to a base64 encoded PNG.

* UIProcess/Automation/WebAutomationSession.h:
* UIProcess/Automation/WebAutomationSession.messages.in:
* WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::evaluateJavaScriptCallback):
(WebKit::WebAutomationSessionProxy::didClearWindowObjectForFrame):
(WebKit::WebAutomationSessionProxy::resolveChildFrameWithOrdinal):
(WebKit::WebAutomationSessionProxy::resolveChildFrameWithNodeHandle):
(WebKit::WebAutomationSessionProxy::resolveChildFrameWithName):
(WebKit::WebAutomationSessionProxy::resolveParentFrame):
(WebKit::WebAutomationSessionProxy::computeElementLayout):
Use null string where possible for efficiency.

(WebKit::WebAutomationSessionProxy::takeScreenshot):
Take an image of the entire page and pass back to the UIProcess.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationAutomationjson">trunk/Source/WebKit2/UIProcess/Automation/Automation.json</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationWebAutomationSessioncpp">trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationWebAutomationSessionh">trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationWebAutomationSessionmessagesin">trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebAutomationSessionCocoamm">trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxycpp">trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxyh">trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxymessagesin">trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (198906 => 198907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-03-31 18:56:10 UTC (rev 198906)
+++ trunk/Source/WebKit2/ChangeLog        2016-03-31 19:03:37 UTC (rev 198907)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2016-03-31  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        Web Automation: Add Automation.screenshot
+        https://bugs.webkit.org/show_bug.cgi?id=156073
+        &lt;rdar://problem/25468646&gt;
+
+        Reviewed by Timothy Hatcher and Brian Burg.
+
+        * UIProcess/Automation/Automation.json:
+        Add Automation.screenshot which returns base64 encoded PNG data.
+
+        * WebProcess/Automation/WebAutomationSessionProxy.h:
+        * WebProcess/Automation/WebAutomationSessionProxy.messages.in:
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::screenshot):
+        (WebKit::WebAutomationSession::didTakeScreenshot):
+        (WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):
+        Send a message to the WebPage to get an Image of the page
+        and handle the response.
+
+        * UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
+        (WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):
+        Convert the bitmap data to a base64 encoded PNG.
+
+        * UIProcess/Automation/WebAutomationSession.h:
+        * UIProcess/Automation/WebAutomationSession.messages.in:
+        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
+        (WebKit::evaluateJavaScriptCallback):
+        (WebKit::WebAutomationSessionProxy::didClearWindowObjectForFrame):
+        (WebKit::WebAutomationSessionProxy::resolveChildFrameWithOrdinal):
+        (WebKit::WebAutomationSessionProxy::resolveChildFrameWithNodeHandle):
+        (WebKit::WebAutomationSessionProxy::resolveChildFrameWithName):
+        (WebKit::WebAutomationSessionProxy::resolveParentFrame):
+        (WebKit::WebAutomationSessionProxy::computeElementLayout):
+        Use null string where possible for efficiency.
+
+        (WebKit::WebAutomationSessionProxy::takeScreenshot):
+        Take an image of the entire page and pass back to the UIProcess.
+
</ins><span class="cx"> 2016-03-31  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Automation: Handle undefined when calling a function that has no result
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationAutomationjson"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/Automation.json (198906 => 198907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/Automation.json        2016-03-31 18:56:10 UTC (rev 198906)
+++ trunk/Source/WebKit2/UIProcess/Automation/Automation.json        2016-03-31 19:03:37 UTC (rev 198907)
</span><span class="lines">@@ -305,11 +305,22 @@
</span><span class="cx">             &quot;name&quot;: &quot;performKeyboardInteractions&quot;,
</span><span class="cx">             &quot;description&quot;: &quot;Simulates delivering the results of pressing one or more keyboard keys together or successively.&quot;,
</span><span class="cx">             &quot;parameters&quot;: [
</span><del>-                { &quot;name&quot;: &quot;handle&quot;, &quot;$ref&quot;: &quot;BrowsingContextHandle&quot;, &quot;description&quot;: &quot;The handle for the browsing context which should recieve key.&quot; },
</del><ins>+                { &quot;name&quot;: &quot;handle&quot;, &quot;$ref&quot;: &quot;BrowsingContextHandle&quot;, &quot;description&quot;: &quot;The handle for the browsing context which should receive key.&quot; },
</ins><span class="cx">                 { &quot;name&quot;: &quot;interactions&quot;, &quot;type&quot;: &quot;array&quot;, &quot;items&quot;: { &quot;$ref&quot;: &quot;KeyboardInteraction&quot; }, &quot;description&quot;: &quot;An ordered list of key sequences to be delivered using native key events.&quot; }
</span><span class="cx">             ]
</span><span class="cx">         },
</span><span class="cx">         {
</span><ins>+            &quot;name&quot;: &quot;takeScreenshot&quot;,
+            &quot;description&quot;: &quot;Take a screenshot of the current page in a browsing context.&quot;,
+            &quot;parameters&quot;: [
+                { &quot;name&quot;: &quot;handle&quot;, &quot;$ref&quot;: &quot;BrowsingContextHandle&quot;, &quot;description&quot;: &quot;The handle for the browsing context to take a screenshot of.&quot; }
+            ],
+            &quot;returns&quot;: [
+                { &quot;name&quot;: &quot;data&quot;, &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;Base64-encoded image data (PNG).&quot; }
+            ],
+            &quot;async&quot;: true
+        },
+        {
</ins><span class="cx">             &quot;name&quot;: &quot;resolveChildFrameHandle&quot;,
</span><span class="cx">             &quot;description&quot;: &quot;Determines the &lt;code&gt;FrameHandle&lt;/code&gt; based on the ordinal, name or node handle of a child frame.&quot;,
</span><span class="cx">             &quot;parameters&quot;: [
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (198906 => 198907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp        2016-03-31 18:56:10 UTC (rev 198906)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp        2016-03-31 19:03:37 UTC (rev 198907)
</span><span class="lines">@@ -771,10 +771,41 @@
</span><span class="cx">         for (auto&amp; action : actionsToPerform)
</span><span class="cx">             action();
</span><span class="cx">     }
</span><del>-
</del><span class="cx"> #endif // USE(APPKIT)
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebAutomationSession::takeScreenshot(ErrorString&amp; errorString, const String&amp; handle, Ref&lt;TakeScreenshotCallback&gt;&amp;&amp; callback)
+{
+    WebPageProxy* page = webPageProxyForHandle(handle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    uint64_t callbackID = m_nextScreenshotCallbackID++;
+    m_screenshotCallbacks.set(callbackID, WTFMove(callback));
+
+    page-&gt;process().send(Messages::WebAutomationSessionProxy::TakeScreenshot(page-&gt;pageID(), callbackID), 0);
+}
+
+void WebAutomationSession::didTakeScreenshot(uint64_t callbackID, const ShareableBitmap::Handle&amp; imageDataHandle, const String&amp; errorType)
+{
+    auto callback = m_screenshotCallbacks.take(callbackID);
+    if (!callback)
+        return;
+
+    if (!errorType.isEmpty()) {
+        callback-&gt;sendFailure(errorType);
+        return;
+    }
+
+    String base64EncodedData = platformGetBase64EncodedPNGData(imageDataHandle);
+    if (base64EncodedData.isEmpty()) {
+        callback-&gt;sendFailure(Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InternalError));
+        return;
+    }
+
+    callback-&gt;sendSuccess(base64EncodedData);
+}
+
</ins><span class="cx"> #if !USE(APPKIT)
</span><span class="cx"> void WebAutomationSession::platformSimulateMouseInteraction(WebKit::WebPageProxy&amp;, const WebCore::IntPoint&amp;, Inspector::Protocol::Automation::MouseInteraction, Inspector::Protocol::Automation::MouseButton, WebEvent::Modifiers)
</span><span class="cx"> {
</span><span class="lines">@@ -787,6 +818,11 @@
</span><span class="cx"> void WebAutomationSession::platformSimulateKeySequence(WebPageProxy&amp;, const String&amp;)
</span><span class="cx"> {
</span><span class="cx"> }
</span><ins>+
+String WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&amp;)
+{
+    return String();
+}
</ins><span class="cx"> #endif // !USE(APPKIT)
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h (198906 => 198907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h        2016-03-31 18:56:10 UTC (rev 198906)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h        2016-03-31 19:03:37 UTC (rev 198907)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #include &quot;APIObject.h&quot;
</span><span class="cx"> #include &quot;AutomationBackendDispatchers.h&quot;
</span><span class="cx"> #include &quot;Connection.h&quot;
</span><ins>+#include &quot;ShareableBitmap.h&quot;
</ins><span class="cx"> #include &quot;WebEvent.h&quot;
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -105,6 +106,7 @@
</span><span class="cx">     void evaluateJavaScriptFunction(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String* optionalFrameHandle, const String&amp; function, const Inspector::InspectorArray&amp; arguments, bool expectsImplicitCallbackArgument, Ref&lt;Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback&gt;&amp;&amp;) override;
</span><span class="cx">     void performMouseInteraction(Inspector::ErrorString&amp;, const String&amp; handle, const Inspector::InspectorObject&amp; requestedPosition, const String&amp; mouseButton, const String&amp; mouseInteraction, const Inspector::InspectorArray&amp; keyModifiers, RefPtr&lt;Inspector::Protocol::Automation::Point&gt;&amp; updatedPosition) override;
</span><span class="cx">     void performKeyboardInteractions(Inspector::ErrorString&amp;, const String&amp; handle, const Inspector::InspectorArray&amp; interactions) override;
</span><ins>+    void takeScreenshot(Inspector::ErrorString&amp;, const String&amp; handle, Ref&lt;Inspector::AutomationBackendDispatcherHandler::TakeScreenshotCallback&gt;&amp;&amp;) override;
</ins><span class="cx">     void resolveChildFrameHandle(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String* optionalFrameHandle, const int* optionalOrdinal, const String* optionalName, const String* optionalNodeHandle, Ref&lt;ResolveChildFrameHandleCallback&gt;&amp;&amp;) override;
</span><span class="cx">     void resolveParentFrameHandle(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String&amp; frameHandle, Ref&lt;ResolveParentFrameHandleCallback&gt;&amp;&amp;) override;
</span><span class="cx">     void computeElementLayout(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String&amp; frameHandle, const String&amp; nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* useViewportCoordinates, Ref&lt;Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback&gt;&amp;&amp;) override;
</span><span class="lines">@@ -135,6 +137,7 @@
</span><span class="cx">     void didResolveChildFrame(uint64_t callbackID, uint64_t frameID, const String&amp; errorType);
</span><span class="cx">     void didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String&amp; errorType);
</span><span class="cx">     void didComputeElementLayout(uint64_t callbackID, WebCore::IntRect, const String&amp; errorType);
</span><ins>+    void didTakeScreenshot(uint64_t callbackID, const ShareableBitmap::Handle&amp;, const String&amp; errorType);
</ins><span class="cx"> 
</span><span class="cx">     // Platform-specific helper methods.
</span><span class="cx">     void platformSimulateMouseInteraction(WebPageProxy&amp;, const WebCore::IntPoint&amp; viewPosition, Inspector::Protocol::Automation::MouseInteraction, Inspector::Protocol::Automation::MouseButton, WebEvent::Modifiers);
</span><span class="lines">@@ -142,6 +145,8 @@
</span><span class="cx">     void platformSimulateKeyStroke(WebPageProxy&amp;, Inspector::Protocol::Automation::KeyboardInteractionType, Inspector::Protocol::Automation::VirtualKey);
</span><span class="cx">     // Simulates key presses to produce the codepoints in a string. One or more code points are delivered atomically at grapheme cluster boundaries.
</span><span class="cx">     void platformSimulateKeySequence(WebPageProxy&amp;, const String&amp;);
</span><ins>+    // Get base64 encoded PNG data from a bitmap.
+    String platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&amp;);
</ins><span class="cx"> 
</span><span class="cx"> #if USE(APPKIT)
</span><span class="cx">     void sendSynthesizedEventsToPage(WebPageProxy&amp;, NSArray *eventsToSend);
</span><span class="lines">@@ -174,6 +179,9 @@
</span><span class="cx">     uint64_t m_nextComputeElementLayoutCallbackID { 1 };
</span><span class="cx">     HashMap&lt;uint64_t, RefPtr&lt;Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback&gt;&gt; m_computeElementLayoutCallbacks;
</span><span class="cx"> 
</span><ins>+    uint64_t m_nextScreenshotCallbackID { 1 };
+    HashMap&lt;uint64_t, RefPtr&lt;Inspector::AutomationBackendDispatcherHandler::TakeScreenshotCallback&gt;&gt; m_screenshotCallbacks;
+
</ins><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span><span class="cx">     Inspector::FrontendChannel* m_remoteChannel { nullptr };
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessionmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in (198906 => 198907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in        2016-03-31 18:56:10 UTC (rev 198906)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in        2016-03-31 19:03:37 UTC (rev 198907)
</span><span class="lines">@@ -27,4 +27,6 @@
</span><span class="cx">     DidResolveParentFrame(uint64_t callbackID, uint64_t frameID, String errorType)
</span><span class="cx"> 
</span><span class="cx">     DidComputeElementLayout(uint64_t callbackID, WebCore::IntRect rect, String errorType)
</span><ins>+
+    DidTakeScreenshot(uint64_t callbackID, WebKit::ShareableBitmap::Handle imageDataHandle, String errorType)
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebAutomationSessionCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm (198906 => 198907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm        2016-03-31 18:56:10 UTC (rev 198906)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm        2016-03-31 19:03:37 UTC (rev 198907)
</span><span class="lines">@@ -454,6 +454,21 @@
</span><span class="cx">     sendSynthesizedEventsToPage(page, eventsToBeSent.get());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&amp; imageDataHandle)
+{
+    RefPtr&lt;ShareableBitmap&gt; bitmap = ShareableBitmap::create(imageDataHandle, SharedMemory::Protection::ReadOnly);
+    RetainPtr&lt;CGImageRef&gt; cgImage = bitmap-&gt;makeCGImage();
+    RetainPtr&lt;NSMutableData&gt; imageData = adoptNS([[NSMutableData alloc] init]);
+    RetainPtr&lt;CGImageDestinationRef&gt; destination = adoptCF(CGImageDestinationCreateWithData((CFMutableDataRef)imageData.get(), kUTTypePNG, 1, 0));
+    if (!destination)
+        return String();
+
+    CGImageDestinationAddImage(destination.get(), cgImage.get(), 0);
+    CGImageDestinationFinalize(destination.get());
+
+    return [imageData base64EncodedStringWithOptions:0];
+}
+
</ins><span class="cx"> #endif // USE(APPKIT)
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp (198906 => 198907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp        2016-03-31 18:56:10 UTC (rev 198906)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp        2016-03-31 19:03:37 UTC (rev 198907)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;WebAutomationSessionProxyMessages.h&quot;
</span><span class="cx"> #include &quot;WebAutomationSessionProxyScriptSource.h&quot;
</span><span class="cx"> #include &quot;WebFrame.h&quot;
</span><ins>+#include &quot;WebImage.h&quot;
</ins><span class="cx"> #include &quot;WebPage.h&quot;
</span><span class="cx"> #include &quot;WebProcess.h&quot;
</span><span class="cx"> #include &lt;JavaScriptCore/APICast.h&gt;
</span><span class="lines">@@ -138,7 +139,7 @@
</span><span class="cx">     uint64_t callbackID = JSValueToNumber(context, arguments[1], exception);
</span><span class="cx">     JSRetainPtr&lt;JSStringRef&gt; result(Adopt, JSValueToStringCopy(context, arguments[2], exception));
</span><span class="cx"> 
</span><del>-    automationSessionProxy-&gt;didEvaluateJavaScriptFunction(frameID, callbackID, result-&gt;string(), emptyString());
</del><ins>+    automationSessionProxy-&gt;didEvaluateJavaScriptFunction(frameID, callbackID, result-&gt;string(), String());
</ins><span class="cx"> 
</span><span class="cx">     return JSValueMakeUndefined(context);
</span><span class="cx"> }
</span><span class="lines">@@ -208,7 +209,7 @@
</span><span class="cx"> 
</span><span class="cx">     auto pendingFrameCallbacks = m_webFramePendingEvaluateJavaScriptCallbacksMap.take(frameID);
</span><span class="cx">     for (uint64_t callbackID : pendingFrameCallbacks)
</span><del>-        WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidEvaluateJavaScriptFunction(callbackID, emptyString(), errorType), 0);
</del><ins>+        WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidEvaluateJavaScriptFunction(callbackID, String(), errorType), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebAutomationSessionProxy::evaluateJavaScriptFunction(uint64_t frameID, const String&amp; function, Vector&lt;String&gt; arguments, bool expectsImplicitCallbackArgument, uint64_t callbackID)
</span><span class="lines">@@ -303,7 +304,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame-&gt;frameID(), emptyString()), 0);
</del><ins>+    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame-&gt;frameID(), String()), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebAutomationSessionProxy::resolveChildFrameWithNodeHandle(uint64_t frameID, const String&amp; nodeHandle, uint64_t callbackID)
</span><span class="lines">@@ -334,7 +335,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, frameFromElement-&gt;frameID(), emptyString()), 0);
</del><ins>+    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, frameFromElement-&gt;frameID(), String()), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebAutomationSessionProxy::resolveChildFrameWithName(uint64_t frameID, const String&amp; name, uint64_t callbackID)
</span><span class="lines">@@ -365,7 +366,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame-&gt;frameID(), emptyString()), 0);
</del><ins>+    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame-&gt;frameID(), String()), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebAutomationSessionProxy::resolveParentFrame(uint64_t frameID, uint64_t callbackID)
</span><span class="lines">@@ -384,7 +385,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidResolveParentFrame(callbackID, parentFrame-&gt;frameID(), emptyString()), 0);
</del><ins>+    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidResolveParentFrame(callbackID, parentFrame-&gt;frameID(), String()), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebAutomationSessionProxy::focusFrame(uint64_t frameID)
</span><span class="lines">@@ -446,7 +447,37 @@
</span><span class="cx">         rect = coreFrameView-&gt;rootViewToContents(rect);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, rect, emptyString()), 0);
</del><ins>+    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, rect, String()), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebAutomationSessionProxy::takeScreenshot(uint64_t pageID, uint64_t callbackID)
+{
+    ShareableBitmap::Handle handle;
+    String windowNotFoundErrorType = Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
+
+    WebPage* page = WebProcess::singleton().webPage(pageID);
+    if (!page) {
+        WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, windowNotFoundErrorType), 0);
+        return;
+    }
+
+    WebCore::FrameView* frameView = page-&gt;mainFrameView();
+    if (!frameView) {
+        WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, String()), 0);
+        return;
+    }
+
+    WebCore::IntRect snapshotRect = WebCore::IntRect(WebCore::IntPoint(0, 0), frameView-&gt;contentsSize());
+    if (snapshotRect.isEmpty()) {
+        WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, String()), 0);
+        return;
+    }
+
+    RefPtr&lt;WebImage&gt; image = page-&gt;scaledSnapshotWithOptions(snapshotRect, 1, SnapshotOptionsShareable);
+    if (image)
+        image-&gt;bitmap()-&gt;createHandle(handle, SharedMemory::Protection::ReadOnly);
+
+    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, String()), 0);    
+}
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h (198906 => 198907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h        2016-03-31 18:56:10 UTC (rev 198906)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h        2016-03-31 19:03:37 UTC (rev 198907)
</span><span class="lines">@@ -65,6 +65,7 @@
</span><span class="cx">     void resolveParentFrame(uint64_t frameID, uint64_t callbackID);
</span><span class="cx">     void focusFrame(uint64_t frameID);
</span><span class="cx">     void computeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID);
</span><ins>+    void takeScreenshot(uint64_t pageID, uint64_t callbackID);
</ins><span class="cx"> 
</span><span class="cx">     String m_sessionIdentifier;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in (198906 => 198907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in        2016-03-31 18:56:10 UTC (rev 198906)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in        2016-03-31 19:03:37 UTC (rev 198907)
</span><span class="lines">@@ -31,4 +31,6 @@
</span><span class="cx">     FocusFrame(uint64_t frameID)
</span><span class="cx"> 
</span><span class="cx">     ComputeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID)
</span><ins>+
+    TakeScreenshot(uint64_t pageID, uint64_t callbackID)
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>