<!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
<rdar://problem/25468646>
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 <pecoraro@apple.com>
+
+ Web Automation: Add Automation.screenshot
+ https://bugs.webkit.org/show_bug.cgi?id=156073
+ <rdar://problem/25468646>
+
+ 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 <timothy@apple.com>
</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"> "name": "performKeyboardInteractions",
</span><span class="cx"> "description": "Simulates delivering the results of pressing one or more keyboard keys together or successively.",
</span><span class="cx"> "parameters": [
</span><del>- { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context which should recieve key." },
</del><ins>+ { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context which should receive key." },
</ins><span class="cx"> { "name": "interactions", "type": "array", "items": { "$ref": "KeyboardInteraction" }, "description": "An ordered list of key sequences to be delivered using native key events." }
</span><span class="cx"> ]
</span><span class="cx"> },
</span><span class="cx"> {
</span><ins>+ "name": "takeScreenshot",
+ "description": "Take a screenshot of the current page in a browsing context.",
+ "parameters": [
+ { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context to take a screenshot of." }
+ ],
+ "returns": [
+ { "name": "data", "type": "string", "description": "Base64-encoded image data (PNG)." }
+ ],
+ "async": true
+ },
+ {
</ins><span class="cx"> "name": "resolveChildFrameHandle",
</span><span class="cx"> "description": "Determines the <code>FrameHandle</code> based on the ordinal, name or node handle of a child frame.",
</span><span class="cx"> "parameters": [
</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& 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& errorString, const String& handle, Ref<TakeScreenshotCallback>&& 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->process().send(Messages::WebAutomationSessionProxy::TakeScreenshot(page->pageID(), callbackID), 0);
+}
+
+void WebAutomationSession::didTakeScreenshot(uint64_t callbackID, const ShareableBitmap::Handle& imageDataHandle, const String& errorType)
+{
+ auto callback = m_screenshotCallbacks.take(callbackID);
+ if (!callback)
+ return;
+
+ if (!errorType.isEmpty()) {
+ callback->sendFailure(errorType);
+ return;
+ }
+
+ String base64EncodedData = platformGetBase64EncodedPNGData(imageDataHandle);
+ if (base64EncodedData.isEmpty()) {
+ callback->sendFailure(Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InternalError));
+ return;
+ }
+
+ callback->sendSuccess(base64EncodedData);
+}
+
</ins><span class="cx"> #if !USE(APPKIT)
</span><span class="cx"> void WebAutomationSession::platformSimulateMouseInteraction(WebKit::WebPageProxy&, const WebCore::IntPoint&, 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&, const String&)
</span><span class="cx"> {
</span><span class="cx"> }
</span><ins>+
+String WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&)
+{
+ 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 "APIObject.h"
</span><span class="cx"> #include "AutomationBackendDispatchers.h"
</span><span class="cx"> #include "Connection.h"
</span><ins>+#include "ShareableBitmap.h"
</ins><span class="cx"> #include "WebEvent.h"
</span><span class="cx"> #include <wtf/Forward.h>
</span><span class="cx">
</span><span class="lines">@@ -105,6 +106,7 @@
</span><span class="cx"> void evaluateJavaScriptFunction(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, bool expectsImplicitCallbackArgument, Ref<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>&&) override;
</span><span class="cx"> void performMouseInteraction(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& requestedPosition, const String& mouseButton, const String& mouseInteraction, const Inspector::InspectorArray& keyModifiers, RefPtr<Inspector::Protocol::Automation::Point>& updatedPosition) override;
</span><span class="cx"> void performKeyboardInteractions(Inspector::ErrorString&, const String& handle, const Inspector::InspectorArray& interactions) override;
</span><ins>+ void takeScreenshot(Inspector::ErrorString&, const String& handle, Ref<Inspector::AutomationBackendDispatcherHandler::TakeScreenshotCallback>&&) override;
</ins><span class="cx"> void resolveChildFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const int* optionalOrdinal, const String* optionalName, const String* optionalNodeHandle, Ref<ResolveChildFrameHandleCallback>&&) override;
</span><span class="cx"> void resolveParentFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, Ref<ResolveParentFrameHandleCallback>&&) override;
</span><span class="cx"> void computeElementLayout(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* useViewportCoordinates, Ref<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>&&) override;
</span><span class="lines">@@ -135,6 +137,7 @@
</span><span class="cx"> void didResolveChildFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
</span><span class="cx"> void didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
</span><span class="cx"> void didComputeElementLayout(uint64_t callbackID, WebCore::IntRect, const String& errorType);
</span><ins>+ void didTakeScreenshot(uint64_t callbackID, const ShareableBitmap::Handle&, const String& errorType);
</ins><span class="cx">
</span><span class="cx"> // Platform-specific helper methods.
</span><span class="cx"> void platformSimulateMouseInteraction(WebPageProxy&, const WebCore::IntPoint& 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&, 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&, const String&);
</span><ins>+ // Get base64 encoded PNG data from a bitmap.
+ String platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&);
</ins><span class="cx">
</span><span class="cx"> #if USE(APPKIT)
</span><span class="cx"> void sendSynthesizedEventsToPage(WebPageProxy&, NSArray *eventsToSend);
</span><span class="lines">@@ -174,6 +179,9 @@
</span><span class="cx"> uint64_t m_nextComputeElementLayoutCallbackID { 1 };
</span><span class="cx"> HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>> m_computeElementLayoutCallbacks;
</span><span class="cx">
</span><ins>+ uint64_t m_nextScreenshotCallbackID { 1 };
+ HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::TakeScreenshotCallback>> 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& imageDataHandle)
+{
+ RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(imageDataHandle, SharedMemory::Protection::ReadOnly);
+ RetainPtr<CGImageRef> cgImage = bitmap->makeCGImage();
+ RetainPtr<NSMutableData> imageData = adoptNS([[NSMutableData alloc] init]);
+ RetainPtr<CGImageDestinationRef> 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 "WebAutomationSessionProxyMessages.h"
</span><span class="cx"> #include "WebAutomationSessionProxyScriptSource.h"
</span><span class="cx"> #include "WebFrame.h"
</span><ins>+#include "WebImage.h"
</ins><span class="cx"> #include "WebPage.h"
</span><span class="cx"> #include "WebProcess.h"
</span><span class="cx"> #include <JavaScriptCore/APICast.h>
</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<JSStringRef> result(Adopt, JSValueToStringCopy(context, arguments[2], exception));
</span><span class="cx">
</span><del>- automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, result->string(), emptyString());
</del><ins>+ automationSessionProxy->didEvaluateJavaScriptFunction(frameID, callbackID, result->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()->send(Messages::WebAutomationSession::DidEvaluateJavaScriptFunction(callbackID, emptyString(), errorType), 0);
</del><ins>+ WebProcess::singleton().parentProcessConnection()->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& function, Vector<String> 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()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame->frameID(), emptyString()), 0);
</del><ins>+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame->frameID(), String()), 0);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void WebAutomationSessionProxy::resolveChildFrameWithNodeHandle(uint64_t frameID, const String& 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()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, frameFromElement->frameID(), emptyString()), 0);
</del><ins>+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, frameFromElement->frameID(), String()), 0);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void WebAutomationSessionProxy::resolveChildFrameWithName(uint64_t frameID, const String& 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()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame->frameID(), emptyString()), 0);
</del><ins>+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame->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()->send(Messages::WebAutomationSession::DidResolveParentFrame(callbackID, parentFrame->frameID(), emptyString()), 0);
</del><ins>+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveParentFrame(callbackID, parentFrame->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->rootViewToContents(rect);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, rect, emptyString()), 0);
</del><ins>+ WebProcess::singleton().parentProcessConnection()->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()->send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, windowNotFoundErrorType), 0);
+ return;
+ }
+
+ WebCore::FrameView* frameView = page->mainFrameView();
+ if (!frameView) {
+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, String()), 0);
+ return;
+ }
+
+ WebCore::IntRect snapshotRect = WebCore::IntRect(WebCore::IntPoint(0, 0), frameView->contentsSize());
+ if (snapshotRect.isEmpty()) {
+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, String()), 0);
+ return;
+ }
+
+ RefPtr<WebImage> image = page->scaledSnapshotWithOptions(snapshotRect, 1, SnapshotOptionsShareable);
+ if (image)
+ image->bitmap()->createHandle(handle, SharedMemory::Protection::ReadOnly);
+
+ WebProcess::singleton().parentProcessConnection()->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>