<!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>[210927] 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/210927">210927</a></dd>
<dt>Author</dt> <dd>bburg@apple.com</dd>
<dt>Date</dt> <dd>2017-01-19 09:52:36 -0800 (Thu, 19 Jan 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>Web Inspector: move Mac-specific automation commands to a separate implementation file
https://bugs.webkit.org/show_bug.cgi?id=163297
<rdar://problem/28718990>
Reviewed by Timothy Hatcher.
Not all Automation commands are available on all platforms. Start splitting out
command declarations and implementations based on the target platform.
* DerivedSources.make:
Set an appropriate --platform so the correct backend interface is generated.
* UIProcess/Automation/Automation.json:
Guard commands that should not be available on iOS:
- resizeWindowOfBrowsingContext
- moveWindowOfBrowsingContext
- inspectBrowsingContext
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::platformSimulateKeySequence): Deleted.
- Move shared convenience macros to header file.
- Move out Cocoa-only or Mac-only command implementations.
* UIProcess/Automation/WebAutomationSession.h:
Rearrange some declarations and switch from USE(APPKIT) to PLATFORM(MAC).
* UIProcess/Automation/WebAutomationSessionMacros.h: Added.
* UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm: Added.
(WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):
Moved from WebAutomationSessionCocoa.mm. Add iOS-specific header includes.
* UIProcess/Automation/mac/WebAutomationSessionMac.mm: Renamed from Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm.
(WebKit::WebAutomationSession::resizeWindowOfBrowsingContext):
(WebKit::WebAutomationSession::moveWindowOfBrowsingContext):
(WebKit::WebAutomationSession::inspectBrowsingContext):
Move macOS platform command implementations to here. If other desktop ports want
to use these commands, we can move them somewhere else later.
(WebKit::WebAutomationSession::sendSynthesizedEventsToPage):
(WebKit::WebAutomationSession::markEventAsSynthesizedForAutomation):
(WebKit::WebAutomationSession::wasEventSynthesizedForAutomation):
Move out AppKit-specific event simulation code to here.
(WebKit::WebAutomationSession::platformSimulateMouseInteraction):
(WebKit::WebAutomationSession::platformSimulateKeyStroke):
(WebKit::WebAutomationSession::platformSimulateKeySequence):
Move out Mac platformFoo implementations to here.
* WebKit2.xcodeproj/project.pbxproj:
- Added UIProcess/Automation/{mac,cocoa} groups.
- Add new platform-specific implementation files.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2DerivedSourcesmake">trunk/Source/WebKit2/DerivedSources.make</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="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2UIProcessAutomationWebAutomationSessionMacrosh">trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSessionMacros.h</a></li>
<li>trunk/Source/WebKit2/UIProcess/Automation/cocoa/</li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationcocoaWebAutomationSessionCocoamm">trunk/Source/WebKit2/UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm</a></li>
<li>trunk/Source/WebKit2/UIProcess/Automation/mac/</li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationmacWebAutomationSessionMacmm">trunk/Source/WebKit2/UIProcess/Automation/mac/WebAutomationSessionMac.mm</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebAutomationSessionCocoamm">trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (210926 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-01-19 17:28:24 UTC (rev 210926)
+++ trunk/Source/WebKit2/ChangeLog        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -1,3 +1,58 @@
</span><ins>+2017-01-19 Brian Burg <bburg@apple.com>
+
+ Web Inspector: move Mac-specific automation commands to a separate implementation file
+ https://bugs.webkit.org/show_bug.cgi?id=163297
+ <rdar://problem/28718990>
+
+ Reviewed by Timothy Hatcher.
+
+ Not all Automation commands are available on all platforms. Start splitting out
+ command declarations and implementations based on the target platform.
+
+ * DerivedSources.make:
+ Set an appropriate --platform so the correct backend interface is generated.
+
+ * UIProcess/Automation/Automation.json:
+ Guard commands that should not be available on iOS:
+ - resizeWindowOfBrowsingContext
+ - moveWindowOfBrowsingContext
+ - inspectBrowsingContext
+
+ * UIProcess/Automation/WebAutomationSession.cpp:
+ (WebKit::WebAutomationSession::platformSimulateKeySequence): Deleted.
+ - Move shared convenience macros to header file.
+ - Move out Cocoa-only or Mac-only command implementations.
+
+ * UIProcess/Automation/WebAutomationSession.h:
+ Rearrange some declarations and switch from USE(APPKIT) to PLATFORM(MAC).
+
+ * UIProcess/Automation/WebAutomationSessionMacros.h: Added.
+
+ * UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm: Added.
+ (WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):
+ Moved from WebAutomationSessionCocoa.mm. Add iOS-specific header includes.
+
+ * UIProcess/Automation/mac/WebAutomationSessionMac.mm: Renamed from Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm.
+ (WebKit::WebAutomationSession::resizeWindowOfBrowsingContext):
+ (WebKit::WebAutomationSession::moveWindowOfBrowsingContext):
+ (WebKit::WebAutomationSession::inspectBrowsingContext):
+ Move macOS platform command implementations to here. If other desktop ports want
+ to use these commands, we can move them somewhere else later.
+
+ (WebKit::WebAutomationSession::sendSynthesizedEventsToPage):
+ (WebKit::WebAutomationSession::markEventAsSynthesizedForAutomation):
+ (WebKit::WebAutomationSession::wasEventSynthesizedForAutomation):
+ Move out AppKit-specific event simulation code to here.
+
+ (WebKit::WebAutomationSession::platformSimulateMouseInteraction):
+ (WebKit::WebAutomationSession::platformSimulateKeyStroke):
+ (WebKit::WebAutomationSession::platformSimulateKeySequence):
+ Move out Mac platformFoo implementations to here.
+
+ * WebKit2.xcodeproj/project.pbxproj:
+ - Added UIProcess/Automation/{mac,cocoa} groups.
+ - Add new platform-specific implementation files.
+
</ins><span class="cx"> 2017-01-19 Carlos Garcia Campos <cgarcia@igalia.com>
</span><span class="cx">
</span><span class="cx"> [GTK] Provide API to set proxy settings
</span></span></pre></div>
<a id="trunkSourceWebKit2DerivedSourcesmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DerivedSources.make (210926 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DerivedSources.make        2017-01-19 17:28:24 UTC (rev 210926)
+++ trunk/Source/WebKit2/DerivedSources.make        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -234,9 +234,17 @@
</span><span class="cx"> AutomationBackendDispatchers.cpp \
</span><span class="cx"> #
</span><span class="cx">
</span><ins>+ifeq ($(OS),MACOS)
+ifeq ($(shell $(CC) -std=gnu++11 -x c++ -E -P -dM $(SDK_FLAGS) $(FRAMEWORK_FLAGS) $(HEADER_FLAGS) -include "wtf/Platform.h" /dev/null | grep ' WTF_PLATFORM_IOS ' | cut -d' ' -f3), 1)
+        AUTOMATION_BACKEND_PLATFORM_ARGUMENTS = --platform iOS
+else
+        AUTOMATION_BACKEND_PLATFORM_ARGUMENTS = --platform macOS
+endif
+endif # MACOS
+
</ins><span class="cx"> # JSON-RPC Backend Dispatchers, Type Builders
</span><span class="cx"> $(firstword $(AUTOMATION_PROTOCOL_OUTPUT_FILES)) : $(AUTOMATION_PROTOCOL_INPUT_FILES) $(AUTOMATION_PROTOCOL_GENERATOR_SCRIPTS)
</span><del>-        $(PYTHON) $(JavaScriptCore_SCRIPTS_DIR)/generate-inspector-protocol-bindings.py --framework WebKit --backend --outputDir . $(AUTOMATION_PROTOCOL_INPUT_FILES)
</del><ins>+        $(PYTHON) $(JavaScriptCore_SCRIPTS_DIR)/generate-inspector-protocol-bindings.py --framework WebKit $(AUTOMATION_BACKEND_PLATFORM_ARGUMENTS) --backend --outputDir . $(AUTOMATION_PROTOCOL_INPUT_FILES)
</ins><span class="cx">
</span><span class="cx"> all : $(firstword $(AUTOMATION_PROTOCOL_OUTPUT_FILES))
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationAutomationjson"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/Automation.json (210926 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/Automation.json        2017-01-19 17:28:24 UTC (rev 210926)
+++ trunk/Source/WebKit2/UIProcess/Automation/Automation.json        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -248,6 +248,7 @@
</span><span class="cx"> {
</span><span class="cx"> "name": "resizeWindowOfBrowsingContext",
</span><span class="cx"> "description": "Resizes the window of the specified browsing context to the specified size.",
</span><ins>+ "platform": "macOS",
</ins><span class="cx"> "parameters": [
</span><span class="cx"> { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context to be resized." },
</span><span class="cx"> { "name": "size", "$ref": "Size", "description": "The new size for the browsing context's window." }
</span><span class="lines">@@ -256,6 +257,7 @@
</span><span class="cx"> {
</span><span class="cx"> "name": "moveWindowOfBrowsingContext",
</span><span class="cx"> "description": "Moves the window of the specified browsing context to the specified position.",
</span><ins>+ "platform": "macOS",
</ins><span class="cx"> "parameters": [
</span><span class="cx"> { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context to be moved." },
</span><span class="cx"> { "name": "origin", "$ref": "Point", "description": "The new origin for the browsing context's window. The position is interpreted in screen coordinate space, relative to the upper left corner of the screen." }
</span><span class="lines">@@ -297,6 +299,7 @@
</span><span class="cx"> {
</span><span class="cx"> "name": "inspectBrowsingContext",
</span><span class="cx"> "description": "Inspect the specified browsing context using Web Inspector.",
</span><ins>+ "platform": "macOS",
</ins><span class="cx"> "parameters": [
</span><span class="cx"> { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context that should be inspected." },
</span><span class="cx"> { "name": "enableAutoCapturing", "type": "boolean", "optional": true, "description": "If this option is present and set to true, the Web Inspector will automatically start a timeline recording of the specified browsing context once it is attached. Note that this disables the debugger for the duration of the recording." }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (210926 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp        2017-01-19 17:28:24 UTC (rev 210926)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016, 2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx">
</span><span class="cx"> #include "APIAutomationSessionClient.h"
</span><span class="cx"> #include "AutomationProtocolObjects.h"
</span><ins>+#include "WebAutomationSessionMacros.h"
</ins><span class="cx"> #include "WebAutomationSessionMessages.h"
</span><span class="cx"> #include "WebAutomationSessionProxyMessages.h"
</span><span class="cx"> #include "WebCookieManagerProxy.h"
</span><span class="lines">@@ -44,32 +45,6 @@
</span><span class="cx">
</span><span class="cx"> using namespace Inspector;
</span><span class="cx">
</span><del>-static const char* const errorNameAndDetailsSeparator = ";";
-
-// Make sure the predefined error name is valid, otherwise use InternalError.
-#define VALIDATED_ERROR_MESSAGE(errorString) Inspector::Protocol::AutomationHelpers::parseEnumValueFromString<Inspector::Protocol::Automation::ErrorMessage>(errorString).value_or(Inspector::Protocol::Automation::ErrorMessage::InternalError)
-
-// If the error name is incorrect for these macros, it will be a compile-time error.
-#define STRING_FOR_PREDEFINED_ERROR_NAME(errorName) Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::errorName)
-#define STRING_FOR_PREDEFINED_ERROR_NAME_AND_DETAILS(errorName, detailsString) makeString(Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::errorName), errorNameAndDetailsSeparator, detailsString)
-
-// If the error message is not a predefined error, InternalError will be used instead.
-#define STRING_FOR_PREDEFINED_ERROR_MESSAGE(errorMessage) Inspector::Protocol::AutomationHelpers::getEnumConstantValue(VALIDATED_ERROR_MESSAGE(errorMessage))
-#define STRING_FOR_PREDEFINED_ERROR_MESSAGE_AND_DETAILS(errorMessage, detailsString) makeString(Inspector::Protocol::AutomationHelpers::getEnumConstantValue(VALIDATED_ERROR_MESSAGE(errorMessage)), errorNameAndDetailsSeparator, detailsString)
-
-// Convenience macros for filling in the error string of synchronous commands in bailout branches.
-#define FAIL_WITH_PREDEFINED_ERROR(errorName) \
-do { \
- errorString = STRING_FOR_PREDEFINED_ERROR_NAME(errorName); \
- return; \
-} while (false)
-
-#define FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(errorName, detailsString) \
-do { \
- errorString = STRING_FOR_PREDEFINED_ERROR_NAME_AND_DETAILS(errorName, detailsString); \
- return; \
-} while (false)
-
</del><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><span class="cx"> WebAutomationSession::WebAutomationSession()
</span><span class="lines">@@ -245,6 +220,8 @@
</span><span class="cx"> .release();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+// Platform-independent Commands.
+
</ins><span class="cx"> void WebAutomationSession::getBrowsingContexts(Inspector::ErrorString& errorString, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>>& contexts)
</span><span class="cx"> {
</span><span class="cx"> contexts = Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>::create();
</span><span class="lines">@@ -311,80 +288,6 @@
</span><span class="cx"> page->process().send(Messages::WebAutomationSessionProxy::FocusFrame(page->pageID(), frameID.value()), 0);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void WebAutomationSession::resizeWindowOfBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const Inspector::InspectorObject& sizeObject)
-{
- float width;
- if (!sizeObject.getDouble(WTF::ASCIILiteral("width"), width))
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The 'width' parameter was not found or invalid.");
-
- float height;
- if (!sizeObject.getDouble(WTF::ASCIILiteral("height"), height))
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The 'height' parameter was not found or invalid.");
-
- if (width < 0)
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The 'width' parameter had an invalid value.");
-
- if (height < 0)
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The 'height' parameter had an invalid value.");
-
- WebPageProxy* page = webPageProxyForHandle(handle);
- if (!page)
- FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
-
- WebCore::FloatRect originalFrame;
- page->getWindowFrame(originalFrame);
-
- WebCore::FloatRect newFrame = WebCore::FloatRect(originalFrame.location(), WebCore::FloatSize(width, height));
- if (newFrame == originalFrame)
- return;
-
- page->setWindowFrame(newFrame);
-
- // If nothing changed at all, it's probably fair to report that something went wrong.
- // (We can't assume that the requested frame size will be honored exactly, however.)
- WebCore::FloatRect updatedFrame;
- page->getWindowFrame(updatedFrame);
- if (originalFrame == updatedFrame)
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InternalError, "The window size was expected to have changed, but did not.");
-}
-
-void WebAutomationSession::moveWindowOfBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const Inspector::InspectorObject& positionObject)
-{
- float x;
- if (!positionObject.getDouble(WTF::ASCIILiteral("x"), x))
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The 'x' parameter was not found or invalid.");
-
- float y;
- if (!positionObject.getDouble(WTF::ASCIILiteral("y"), y))
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The 'y' parameter was not found or invalid.");
-
- if (x < 0)
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The 'x' parameter had an invalid value.");
-
- if (y < 0)
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The 'y' parameter had an invalid value.");
-
- WebPageProxy* page = webPageProxyForHandle(handle);
- if (!page)
- FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
-
- WebCore::FloatRect originalFrame;
- page->getWindowFrame(originalFrame);
-
- WebCore::FloatRect newFrame = WebCore::FloatRect(WebCore::FloatPoint(x, y), originalFrame.size());
- if (newFrame == originalFrame)
- return;
-
- page->setWindowFrame(newFrame);
-
- // If nothing changed at all, it's probably fair to report that something went wrong.
- // (We can't assume that the requested frame size will be honored exactly, however.)
- WebCore::FloatRect updatedFrame;
- page->getWindowFrame(updatedFrame);
- if (originalFrame == updatedFrame)
- FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InternalError, "The window position was expected to have changed, but did not.");
-}
-
</del><span class="cx"> void WebAutomationSession::navigateBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const String& url, Ref<NavigateBrowsingContextCallback>&& callback)
</span><span class="cx"> {
</span><span class="cx"> WebPageProxy* page = webPageProxyForHandle(handle);
</span><span class="lines">@@ -438,27 +341,6 @@
</span><span class="cx"> page->reload(reloadFromOrigin, { });
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void WebAutomationSession::inspectBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const bool* optionalEnableAutoCapturing, Ref<InspectBrowsingContextCallback>&& callback)
-{
- WebPageProxy* page = webPageProxyForHandle(handle);
- if (!page)
- FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
-
- if (auto callback = m_pendingInspectorCallbacksPerPage.take(page->pageID()))
- callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_NAME(Timeout));
- m_pendingInspectorCallbacksPerPage.set(page->pageID(), WTFMove(callback));
-
- // Don't bring the inspector to front since this may be done automatically.
- // We just want it loaded so it can pause if a breakpoint is hit during a command.
- if (page->inspector()) {
- page->inspector()->connect();
-
- // Start collecting profile information immediately so the entire session is captured.
- if (optionalEnableAutoCapturing && *optionalEnableAutoCapturing)
- page->inspector()->togglePageProfiling();
- }
-}
-
</del><span class="cx"> void WebAutomationSession::navigationOccurredForPage(const WebPageProxy& page)
</span><span class="cx"> {
</span><span class="cx"> if (auto callback = m_pendingNavigationInBrowsingContextCallbacksPerPage.take(page.pageID()))
</span><span class="lines">@@ -1043,7 +925,9 @@
</span><span class="cx"> callback->sendSuccess(base64EncodedData);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#if !USE(APPKIT)
</del><ins>+// Platform-dependent Implementation Stubs.
+
+#if !PLATFORM(MAC)
</ins><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="cx"> }
</span><span class="lines">@@ -1055,11 +939,13 @@
</span><span class="cx"> void WebAutomationSession::platformSimulateKeySequence(WebPageProxy&, const String&)
</span><span class="cx"> {
</span><span class="cx"> }
</span><ins>+#endif // !PLATFORM(MAC)
</ins><span class="cx">
</span><ins>+#if !PLATFORM(COCOA)
</ins><span class="cx"> String WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&)
</span><span class="cx"> {
</span><span class="cx"> return String();
</span><span class="cx"> }
</span><del>-#endif // !USE(APPKIT)
</del><ins>+#endif // !PLATFORM(COCOA)
</ins><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 (210926 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h        2017-01-19 17:28:24 UTC (rev 210926)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2016 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2016, 2017 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -96,18 +96,19 @@
</span><span class="cx"> void terminate();
</span><span class="cx">
</span><span class="cx"> // Inspector::AutomationBackendDispatcherHandler API
</span><ins>+ // NOTE: the set of declarations included in this interface depend on the "platform" property in Automation.json
+ // and the --platform argument passed to the protocol bindings generator.
+
+ // Platform: Generic
</ins><span class="cx"> void getBrowsingContexts(Inspector::ErrorString&, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>>&) override;
</span><span class="cx"> void getBrowsingContext(Inspector::ErrorString&, const String&, RefPtr<Inspector::Protocol::Automation::BrowsingContext>&) override;
</span><span class="cx"> void createBrowsingContext(Inspector::ErrorString&, String*) override;
</span><span class="cx"> void closeBrowsingContext(Inspector::ErrorString&, const String&) override;
</span><span class="cx"> void switchToBrowsingContext(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle) override;
</span><del>- void resizeWindowOfBrowsingContext(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& size) override;
- void moveWindowOfBrowsingContext(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& position) override;
</del><span class="cx"> void navigateBrowsingContext(Inspector::ErrorString&, const String& handle, const String& url, Ref<NavigateBrowsingContextCallback>&&) override;
</span><span class="cx"> void goBackInBrowsingContext(Inspector::ErrorString&, const String&, Ref<GoBackInBrowsingContextCallback>&&) override;
</span><span class="cx"> void goForwardInBrowsingContext(Inspector::ErrorString&, const String&, Ref<GoForwardInBrowsingContextCallback>&&) override;
</span><span class="cx"> void reloadBrowsingContext(Inspector::ErrorString&, const String&, Ref<ReloadBrowsingContextCallback>&&) override;
</span><del>- void inspectBrowsingContext(Inspector::ErrorString&, const String&, const bool* optionalEnableAutoCapturing, Ref<InspectBrowsingContextCallback>&&) override;
</del><span class="cx"> void evaluateJavaScriptFunction(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, const bool* optionalExpectsImplicitCallbackArgument, const int* optionalCallbackTimeout, 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, Ref<PerformKeyboardInteractionsCallback>&&) override;
</span><span class="lines">@@ -124,7 +125,16 @@
</span><span class="cx"> void deleteSingleCookie(Inspector::ErrorString&, const String& browsingContextHandle, const String& cookieName, Ref<DeleteSingleCookieCallback>&&) override;
</span><span class="cx"> void addSingleCookie(Inspector::ErrorString&, const String& browsingContextHandle, const Inspector::InspectorObject& cookie, Ref<AddSingleCookieCallback>&&) override;
</span><span class="cx"> void deleteAllCookies(Inspector::ErrorString&, const String& browsingContextHandle) override;
</span><del>-#if USE(APPKIT)
</del><ins>+
+ // Platform: macOS
+#if PLATFORM(MAC)
+ void resizeWindowOfBrowsingContext(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& size) override;
+ void moveWindowOfBrowsingContext(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& position) override;
+ void inspectBrowsingContext(Inspector::ErrorString&, const String&, const bool* optionalEnableAutoCapturing, Ref<InspectBrowsingContextCallback>&&) override;
+#endif
+
+ // Event Simulation Support.
+#if PLATFORM(MAC)
</ins><span class="cx"> bool wasEventSynthesizedForAutomation(NSEvent *);
</span><span class="cx"> void markEventAsSynthesizedForAutomation(NSEvent *);
</span><span class="cx"> #endif
</span><span class="lines">@@ -138,10 +148,10 @@
</span><span class="cx"> String handleForWebFrameID(uint64_t frameID);
</span><span class="cx"> String handleForWebFrameProxy(const WebFrameProxy&);
</span><span class="cx">
</span><del>- // Implemented in generated WebAutomationSessionMessageReceiver.cpp
</del><ins>+ // Implemented in generated WebAutomationSessionMessageReceiver.cpp.
</ins><span class="cx"> void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
</span><span class="cx">
</span><del>- // Called by WebAutomationSession messages
</del><ins>+ // Called by WebAutomationSession messages.
</ins><span class="cx"> void didEvaluateJavaScriptFunction(uint64_t callbackID, const String& result, const String& errorType);
</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="lines">@@ -150,7 +160,7 @@
</span><span class="cx"> void didGetCookiesForFrame(uint64_t callbackID, Vector<WebCore::Cookie>, const String& errorType);
</span><span class="cx"> void didDeleteCookie(uint64_t callbackID, const String& errorType);
</span><span class="cx">
</span><del>- // Platform-specific helper methods.
</del><ins>+ // Platform-dependent implementations.
</ins><span class="cx"> void platformSimulateMouseInteraction(WebPageProxy&, const WebCore::IntPoint& viewPosition, Inspector::Protocol::Automation::MouseInteraction, Inspector::Protocol::Automation::MouseButton, WebEvent::Modifiers);
</span><span class="cx"> // Simulates a single virtual key being pressed, such as Control, F-keys, Numpad keys, etc. as allowed by the protocol.
</span><span class="cx"> void platformSimulateKeyStroke(WebPageProxy&, Inspector::Protocol::Automation::KeyboardInteractionType, Inspector::Protocol::Automation::VirtualKey);
</span><span class="lines">@@ -159,7 +169,7 @@
</span><span class="cx"> // Get base64 encoded PNG data from a bitmap.
</span><span class="cx"> String platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&);
</span><span class="cx">
</span><del>-#if USE(APPKIT)
</del><ins>+#if PLATFORM(MAC)
</ins><span class="cx"> void sendSynthesizedEventsToPage(WebPageProxy&, NSArray *eventsToSend);
</span><span class="cx"> #endif
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessionMacrosh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSessionMacros.h (0 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSessionMacros.h         (rev 0)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSessionMacros.h        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -0,0 +1,52 @@
</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.
+ */
+
+#pragma once
+
+#define errorNameAndDetailsSeparator ";"
+
+// Make sure the predefined error name is valid, otherwise use InternalError.
+#define VALIDATED_ERROR_MESSAGE(errorString) Inspector::Protocol::AutomationHelpers::parseEnumValueFromString<Inspector::Protocol::Automation::ErrorMessage>(errorString).value_or(Inspector::Protocol::Automation::ErrorMessage::InternalError)
+
+// If the error name is incorrect for these macros, it will be a compile-time error.
+#define STRING_FOR_PREDEFINED_ERROR_NAME(errorName) Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::errorName)
+#define STRING_FOR_PREDEFINED_ERROR_NAME_AND_DETAILS(errorName, detailsString) makeString(Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::errorName), errorNameAndDetailsSeparator, detailsString)
+
+// If the error message is not a predefined error, InternalError will be used instead.
+#define STRING_FOR_PREDEFINED_ERROR_MESSAGE(errorMessage) Inspector::Protocol::AutomationHelpers::getEnumConstantValue(VALIDATED_ERROR_MESSAGE(errorMessage))
+#define STRING_FOR_PREDEFINED_ERROR_MESSAGE_AND_DETAILS(errorMessage, detailsString) makeString(Inspector::Protocol::AutomationHelpers::getEnumConstantValue(VALIDATED_ERROR_MESSAGE(errorMessage)), errorNameAndDetailsSeparator, detailsString)
+
+// Convenience macros for filling in the error string of synchronous commands in bailout branches.
+#define FAIL_WITH_PREDEFINED_ERROR(errorName) \
+do { \
+ errorString = STRING_FOR_PREDEFINED_ERROR_NAME(errorName); \
+ return; \
+} while (false)
+
+#define FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(errorName, detailsString) \
+do { \
+ errorString = STRING_FOR_PREDEFINED_ERROR_NAME_AND_DETAILS(errorName, detailsString); \
+ return; \
+} while (false)
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationcocoaWebAutomationSessionCocoamm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm (0 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm         (rev 0)
+++ trunk/Source/WebKit2/UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -0,0 +1,57 @@
</span><ins>+/*
+ * Copyright (C) 2016, 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebAutomationSession.h"
+
+#if PLATFORM(COCOA)
+
+#if PLATFORM(IOS)
+#include <ImageIO/CGImageDestination.h>
+#include <MobileCoreServices/UTCoreTypes.h>
+#endif
+
+using namespace WebCore;
+
+namespace WebKit {
+
+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];
+}
+
+} // namespace WebKit
+
+#endif // PLATFORM(COCOA)
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationmacWebAutomationSessionMacmmfromrev210926trunkSourceWebKit2UIProcessCocoaWebAutomationSessionCocoamm"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebKit2/UIProcess/Automation/mac/WebAutomationSessionMac.mm (from rev 210926, trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm) (0 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/mac/WebAutomationSessionMac.mm         (rev 0)
+++ trunk/Source/WebKit2/UIProcess/Automation/mac/WebAutomationSessionMac.mm        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -0,0 +1,594 @@
</span><ins>+/*
+ * Copyright (C) 2016, 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebAutomationSession.h"
+
+#if PLATFORM(MAC)
+
+#import "WebAutomationSessionMacros.h"
+#import "WebInspectorProxy.h"
+#import "WebPageProxy.h"
+#import "_WKAutomationSession.h"
+#import <HIToolbox/Events.h>
+#import <WebCore/IntPoint.h>
+#import <WebCore/IntSize.h>
+#import <WebCore/PlatformMouseEvent.h>
+#import <objc/runtime.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+#pragma mark Commands for Platform: 'macOS'
+
+void WebAutomationSession::resizeWindowOfBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const Inspector::InspectorObject& sizeObject)
+{
+ float width;
+ if (!sizeObject.getDouble(WTF::ASCIILiteral("width"), width))
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The 'width' parameter was not found or invalid.");
+
+ float height;
+ if (!sizeObject.getDouble(WTF::ASCIILiteral("height"), height))
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The 'height' parameter was not found or invalid.");
+
+ if (width < 0)
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The 'width' parameter had an invalid value.");
+
+ if (height < 0)
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The 'height' parameter had an invalid value.");
+
+ WebPageProxy* page = webPageProxyForHandle(handle);
+ if (!page)
+ FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
+
+ WebCore::FloatRect originalFrame;
+ page->getWindowFrame(originalFrame);
+
+ WebCore::FloatRect newFrame = WebCore::FloatRect(originalFrame.location(), WebCore::FloatSize(width, height));
+ if (newFrame == originalFrame)
+ return;
+
+ page->setWindowFrame(newFrame);
+
+ // If nothing changed at all, it's probably fair to report that something went wrong.
+ // (We can't assume that the requested frame size will be honored exactly, however.)
+ WebCore::FloatRect updatedFrame;
+ page->getWindowFrame(updatedFrame);
+ if (originalFrame == updatedFrame)
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InternalError, "The window size was expected to have changed, but did not.");
+}
+
+void WebAutomationSession::moveWindowOfBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const Inspector::InspectorObject& positionObject)
+{
+ float x;
+ if (!positionObject.getDouble(WTF::ASCIILiteral("x"), x))
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The 'x' parameter was not found or invalid.");
+
+ float y;
+ if (!positionObject.getDouble(WTF::ASCIILiteral("y"), y))
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The 'y' parameter was not found or invalid.");
+
+ if (x < 0)
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The 'x' parameter had an invalid value.");
+
+ if (y < 0)
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The 'y' parameter had an invalid value.");
+
+ WebPageProxy* page = webPageProxyForHandle(handle);
+ if (!page)
+ FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
+
+ WebCore::FloatRect originalFrame;
+ page->getWindowFrame(originalFrame);
+
+ WebCore::FloatRect newFrame = WebCore::FloatRect(WebCore::FloatPoint(x, y), originalFrame.size());
+ if (newFrame == originalFrame)
+ return;
+
+ page->setWindowFrame(newFrame);
+
+ // If nothing changed at all, it's probably fair to report that something went wrong.
+ // (We can't assume that the requested frame size will be honored exactly, however.)
+ WebCore::FloatRect updatedFrame;
+ page->getWindowFrame(updatedFrame);
+ if (originalFrame == updatedFrame)
+ FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InternalError, "The window position was expected to have changed, but did not.");
+}
+
+void WebAutomationSession::inspectBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const bool* optionalEnableAutoCapturing, Ref<InspectBrowsingContextCallback>&& callback)
+{
+ WebPageProxy* page = webPageProxyForHandle(handle);
+ if (!page)
+ FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
+
+ if (auto callback = m_pendingInspectorCallbacksPerPage.take(page->pageID()))
+ callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_NAME(Timeout));
+ m_pendingInspectorCallbacksPerPage.set(page->pageID(), WTFMove(callback));
+
+ // Don't bring the inspector to front since this may be done automatically.
+ // We just want it loaded so it can pause if a breakpoint is hit during a command.
+ if (page->inspector()) {
+ page->inspector()->connect();
+
+ // Start collecting profile information immediately so the entire session is captured.
+ if (optionalEnableAutoCapturing && *optionalEnableAutoCapturing)
+ page->inspector()->togglePageProfiling();
+ }
+}
+
+#pragma mark AppKit Event Simulation Support
+
+static const NSInteger synthesizedMouseEventMagicEventNumber = 0;
+static const void *synthesizedAutomationEventAssociatedObjectKey = &synthesizedAutomationEventAssociatedObjectKey;
+
+void WebAutomationSession::sendSynthesizedEventsToPage(WebPageProxy& page, NSArray *eventsToSend)
+{
+ NSWindow *window = page.platformWindow();
+
+ for (NSEvent *event in eventsToSend) {
+ // Take focus back in case the Inspector became focused while the prior command or
+ // NSEvent was delivered to the window.
+ [window makeKeyAndOrderFront:nil];
+
+ markEventAsSynthesizedForAutomation(event);
+ [window sendEvent:event];
+ }
+}
+
+void WebAutomationSession::markEventAsSynthesizedForAutomation(NSEvent *event)
+{
+ objc_setAssociatedObject(event, &synthesizedAutomationEventAssociatedObjectKey, m_sessionIdentifier, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+bool WebAutomationSession::wasEventSynthesizedForAutomation(NSEvent *event)
+{
+ NSString *senderSessionIdentifier = objc_getAssociatedObject(event, &synthesizedAutomationEventAssociatedObjectKey);
+ if ([senderSessionIdentifier isEqualToString:m_sessionIdentifier])
+ return true;
+
+ switch (event.type) {
+ case NSEventTypeLeftMouseDown:
+ case NSEventTypeLeftMouseDragged:
+ case NSEventTypeLeftMouseUp:
+ case NSEventTypeMouseMoved:
+ case NSEventTypeOtherMouseDown:
+ case NSEventTypeOtherMouseDragged:
+ case NSEventTypeOtherMouseUp:
+ case NSEventTypeRightMouseDown:
+ case NSEventTypeRightMouseDragged:
+ case NSEventTypeRightMouseUp:
+ // Use this as a backup for checking mouse events, which are frequently copied
+ // and/or faked by AppKit, causing them to lose their associated object tag.
+ return event.eventNumber == synthesizedMouseEventMagicEventNumber;
+ default:
+ break;
+ }
+
+ return false;
+}
+
+#pragma mark Platform-dependent Implementations
+
+void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, const WebCore::IntPoint& viewPosition, Inspector::Protocol::Automation::MouseInteraction interaction, Inspector::Protocol::Automation::MouseButton button, WebEvent::Modifiers keyModifiers)
+{
+ IntRect windowRect;
+ page.rootViewToWindow(IntRect(viewPosition, IntSize()), windowRect);
+ IntPoint windowPosition = windowRect.location();
+
+ NSEventModifierFlags modifiers = 0;
+ if (keyModifiers & WebEvent::MetaKey)
+ modifiers |= NSEventModifierFlagCommand;
+ if (keyModifiers & WebEvent::AltKey)
+ modifiers |= NSEventModifierFlagOption;
+ if (keyModifiers & WebEvent::ControlKey)
+ modifiers |= NSEventModifierFlagControl;
+ if (keyModifiers & WebEvent::ShiftKey)
+ modifiers |= NSEventModifierFlagShift;
+ if (keyModifiers & WebEvent::CapsLockKey)
+ modifiers |= NSEventModifierFlagCapsLock;
+
+ NSTimeInterval timestamp = [NSDate timeIntervalSinceReferenceDate];
+ NSWindow *window = page.platformWindow();
+ NSInteger windowNumber = window.windowNumber;
+
+ NSEventType downEventType;
+ NSEventType dragEventType;
+ NSEventType upEventType;
+ switch (button) {
+ case Inspector::Protocol::Automation::MouseButton::None:
+ downEventType = upEventType = dragEventType = NSEventTypeMouseMoved;
+ break;
+ case Inspector::Protocol::Automation::MouseButton::Left:
+ downEventType = NSEventTypeLeftMouseDown;
+ dragEventType = NSEventTypeLeftMouseDragged;
+ upEventType = NSEventTypeLeftMouseUp;
+ break;
+ case Inspector::Protocol::Automation::MouseButton::Middle:
+ downEventType = NSEventTypeOtherMouseDown;
+ dragEventType = NSEventTypeLeftMouseDragged;
+ upEventType = NSEventTypeOtherMouseUp;
+ break;
+ case Inspector::Protocol::Automation::MouseButton::Right:
+ downEventType = NSEventTypeRightMouseDown;
+ upEventType = NSEventTypeRightMouseUp;
+ break;
+ }
+
+ auto eventsToBeSent = adoptNS([[NSMutableArray alloc] init]);
+
+ NSInteger eventNumber = synthesizedMouseEventMagicEventNumber;
+
+ switch (interaction) {
+ case Inspector::Protocol::Automation::MouseInteraction::Move:
+ [eventsToBeSent addObject:[NSEvent mouseEventWithType:dragEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:0 pressure:0.0f]];
+ break;
+ case Inspector::Protocol::Automation::MouseInteraction::Down:
+ // Hard-code the click count to one, since clients don't expect successive simulated
+ // down/up events to be potentially counted as a double click event.
+ [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
+ break;
+ case Inspector::Protocol::Automation::MouseInteraction::Up:
+ // Hard-code the click count to one, since clients don't expect successive simulated
+ // down/up events to be potentially counted as a double click event.
+ [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
+ break;
+ case Inspector::Protocol::Automation::MouseInteraction::SingleClick:
+ // Send separate down and up events. WebCore will see this as a single-click event.
+ [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
+ [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
+ break;
+ case Inspector::Protocol::Automation::MouseInteraction::DoubleClick:
+ // Send multiple down and up events with proper click count.
+ // WebCore will see this as a single-click event then double-click event.
+ [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
+ [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
+ [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:2 pressure:WebCore::ForceAtClick]];
+ [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:2 pressure:0.0f]];
+ }
+
+ sendSynthesizedEventsToPage(page, eventsToBeSent.get());
+}
+
+void WebAutomationSession::platformSimulateKeyStroke(WebPageProxy& page, Inspector::Protocol::Automation::KeyboardInteractionType interaction, Inspector::Protocol::Automation::VirtualKey key)
+{
+ // If true, the key's modifier flags should affect other events while pressed down.
+ bool isStickyModifier = false;
+ // The modifiers changed by the virtual key when it is pressed or released.
+ // The mapping from keys to modifiers is specified in the documentation for NSEvent.
+ NSEventModifierFlags changedModifiers = 0;
+ // The likely keyCode for the virtual key as defined in <HIToolbox/Events.h>.
+ int keyCode = 0;
+ // Typical characters produced by the virtual key, if any.
+ NSString *characters = @"";
+
+ // FIXME: this function and the Automation protocol enum should probably adopt key names
+ // from W3C UIEvents standard. For more details: https://w3c.github.io/uievents-code/
+
+ switch (key) {
+ case Inspector::Protocol::Automation::VirtualKey::Shift:
+ isStickyModifier = true;
+ changedModifiers |= NSEventModifierFlagShift;
+ keyCode = kVK_Shift;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Control:
+ isStickyModifier = true;
+ changedModifiers |= NSEventModifierFlagControl;
+ keyCode = kVK_Control;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Alternate:
+ isStickyModifier = true;
+ changedModifiers |= NSEventModifierFlagOption;
+ keyCode = kVK_Option;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Meta:
+ // The 'meta' key does not exist on Apple keyboards and is usually
+ // mapped to the Command key when using third-party keyboards.
+ case Inspector::Protocol::Automation::VirtualKey::Command:
+ isStickyModifier = true;
+ changedModifiers |= NSEventModifierFlagCommand;
+ keyCode = kVK_Command;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Help:
+ changedModifiers |= NSEventModifierFlagHelp | NSEventModifierFlagFunction;
+ keyCode = kVK_Help;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Backspace:
+ keyCode = kVK_Delete;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Tab:
+ keyCode = kVK_Tab;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Clear:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_KeypadClear;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Enter:
+ keyCode = kVK_ANSI_KeypadEnter;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Pause:
+ // The 'pause' key does not exist on Apple keyboards and has no keycode.
+ // The semantics are unclear so just abort and do nothing.
+ return;
+ case Inspector::Protocol::Automation::VirtualKey::Cancel:
+ // The 'cancel' key does not exist on Apple keyboards and has no keycode.
+ // According to the internet its functionality is similar to 'Escape'.
+ case Inspector::Protocol::Automation::VirtualKey::Escape:
+ keyCode = kVK_Escape;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::PageUp:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_PageUp;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::PageDown:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_PageDown;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::End:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_End;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Home:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_Home;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::LeftArrow:
+ changedModifiers |= NSEventModifierFlagNumericPad | NSEventModifierFlagFunction;
+ keyCode = kVK_LeftArrow;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::UpArrow:
+ changedModifiers |= NSEventModifierFlagNumericPad | NSEventModifierFlagFunction;
+ keyCode = kVK_UpArrow;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::RightArrow:
+ changedModifiers |= NSEventModifierFlagNumericPad | NSEventModifierFlagFunction;
+ keyCode = kVK_RightArrow;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::DownArrow:
+ changedModifiers |= NSEventModifierFlagNumericPad | NSEventModifierFlagFunction;
+ keyCode = kVK_DownArrow;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Insert:
+ // The 'insert' key does not exist on Apple keyboards and has no keycode.
+ // The semantics are unclear so just abort and do nothing.
+ return;
+ case Inspector::Protocol::Automation::VirtualKey::Delete:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_ForwardDelete;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Space:
+ keyCode = kVK_Space;
+ characters = @" ";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Semicolon:
+ keyCode = kVK_ANSI_Semicolon;
+ characters = @";";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Equals:
+ keyCode = kVK_ANSI_Equal;
+ characters = @"=";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Return:
+ keyCode = kVK_Return;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad0:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad0;
+ characters = @"0";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad1:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad1;
+ characters = @"1";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad2:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad2;
+ characters = @"2";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad3:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad3;
+ characters = @"3";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad4:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad4;
+ characters = @"4";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad5:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad5;
+ characters = @"5";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad6:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad6;
+ characters = @"6";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad7:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad7;
+ characters = @"7";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad8:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad8;
+ characters = @"8";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPad9:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_Keypad9;
+ characters = @"9";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPadMultiply:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_KeypadMultiply;
+ characters = @"*";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPadAdd:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_KeypadPlus;
+ characters = @"+";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPadSubtract:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_KeypadMinus;
+ characters = @"-";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPadSeparator:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ // The 'Separator' key is only present on a few international keyboards.
+ // It is usually mapped to the same character as Decimal ('.' or ',').
+ FALLTHROUGH;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPadDecimal:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_KeypadDecimal;
+ // FIXME: this might be locale-dependent. See the above comment.
+ characters = @".";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::NumberPadDivide:
+ changedModifiers |= NSEventModifierFlagNumericPad;
+ keyCode = kVK_ANSI_KeypadDivide;
+ characters = @"/";
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function1:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F1;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function2:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F2;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function3:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F3;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function4:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F4;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function5:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F5;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function6:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F6;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function7:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F7;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function8:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F8;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function9:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F9;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function10:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F10;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function11:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F11;
+ break;
+ case Inspector::Protocol::Automation::VirtualKey::Function12:
+ changedModifiers |= NSEventModifierFlagFunction;
+ keyCode = kVK_F12;
+ break;
+ }
+
+ auto eventsToBeSent = adoptNS([[NSMutableArray alloc] init]);
+
+ ASSERT(isStickyModifier || interaction == Inspector::Protocol::Automation::KeyboardInteractionType::KeyPress);
+
+ NSEventModifierFlags existingModifiers = [NSEvent modifierFlags];
+ NSEventModifierFlags updatedModifiers = 0;
+ NSTimeInterval timestamp = [NSDate timeIntervalSinceReferenceDate];
+ NSWindow *window = page.platformWindow();
+ NSInteger windowNumber = window.windowNumber;
+ NSPoint eventPosition = NSMakePoint(0, window.frame.size.height);
+
+ switch (interaction) {
+ case Inspector::Protocol::Automation::KeyboardInteractionType::KeyPress: {
+ NSEventType eventType = isStickyModifier ? NSEventTypeFlagsChanged : NSEventTypeKeyDown;
+ updatedModifiers = existingModifiers | changedModifiers;
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:eventType location:eventPosition modifierFlags:updatedModifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode]];
+ break;
+ }
+ case Inspector::Protocol::Automation::KeyboardInteractionType::KeyRelease: {
+ NSEventType eventType = isStickyModifier ? NSEventTypeFlagsChanged : NSEventTypeKeyUp;
+ updatedModifiers = existingModifiers & ~changedModifiers;
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:eventType location:eventPosition modifierFlags:updatedModifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode]];
+ break;
+ }
+ case Inspector::Protocol::Automation::KeyboardInteractionType::InsertByKey: {
+ // Sticky modifiers should either be 'KeyPress' or 'KeyRelease'.
+ ASSERT(!isStickyModifier);
+ if (isStickyModifier)
+ return;
+
+ updatedModifiers = existingModifiers | changedModifiers;
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyDown location:eventPosition modifierFlags:updatedModifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode]];
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyUp location:eventPosition modifierFlags:updatedModifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode]];
+ break;
+ }
+ }
+
+ sendSynthesizedEventsToPage(page, eventsToBeSent.get());
+}
+
+void WebAutomationSession::platformSimulateKeySequence(WebPageProxy& page, const String& keySequence)
+{
+ auto eventsToBeSent = adoptNS([[NSMutableArray alloc] init]);
+
+ // Split the text into combining character sequences and send each separately.
+ // This has no similarity to how keyboards work when inputting complex text.
+ // This command is more similar to the 'insertText:' editing command, except
+ // that this emits keyup/keydown/keypress events for roughly each character.
+ // This API should move more towards that direction in the future.
+ NSString *text = keySequence;
+
+ NSEventModifierFlags modifiers = [NSEvent modifierFlags];
+ NSTimeInterval timestamp = [NSDate timeIntervalSinceReferenceDate];
+ NSWindow *window = page.platformWindow();
+ NSInteger windowNumber = window.windowNumber;
+ NSPoint eventPosition = NSMakePoint(0, window.frame.size.height);
+
+ [text enumerateSubstringsInRange:NSMakeRange(0, text.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyDown location:eventPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:substring charactersIgnoringModifiers:substring isARepeat:NO keyCode:0]];
+ [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyUp location:eventPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:substring charactersIgnoringModifiers:substring isARepeat:NO keyCode:0]];
+ }];
+
+ sendSynthesizedEventsToPage(page, eventsToBeSent.get());
+}
+
+} // namespace WebKit
+
+#endif // PLATFORM(MAC)
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebAutomationSessionCocoamm"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm (210926 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm        2017-01-19 17:28:24 UTC (rev 210926)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -1,509 +0,0 @@
</span><del>-/*
- * 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 "config.h"
-#import "WebAutomationSession.h"
-
-#import "WebPageProxy.h"
-#import "_WKAutomationSession.h"
-#import <WebCore/IntPoint.h>
-#import <WebCore/IntSize.h>
-#import <WebCore/PlatformMouseEvent.h>
-#import <objc/runtime.h>
-
-#if USE(APPKIT)
-#import <HIToolbox/Events.h>
-#endif
-
-using namespace WebCore;
-
-namespace WebKit {
-
-#if USE(APPKIT)
-
-static const NSInteger synthesizedMouseEventMagicEventNumber = 0;
-static const void *synthesizedAutomationEventAssociatedObjectKey = &synthesizedAutomationEventAssociatedObjectKey;
-
-void WebAutomationSession::sendSynthesizedEventsToPage(WebPageProxy& page, NSArray *eventsToSend)
-{
- NSWindow *window = page.platformWindow();
-
- for (NSEvent *event in eventsToSend) {
- // Take focus back in case the Inspector became focused while the prior command or
- // NSEvent was delivered to the window.
- [window makeKeyAndOrderFront:nil];
-
- markEventAsSynthesizedForAutomation(event);
- [window sendEvent:event];
- }
-}
-
-void WebAutomationSession::markEventAsSynthesizedForAutomation(NSEvent *event)
-{
- objc_setAssociatedObject(event, &synthesizedAutomationEventAssociatedObjectKey, m_sessionIdentifier, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
-}
-
-bool WebAutomationSession::wasEventSynthesizedForAutomation(NSEvent *event)
-{
- NSString *senderSessionIdentifier = objc_getAssociatedObject(event, &synthesizedAutomationEventAssociatedObjectKey);
- if ([senderSessionIdentifier isEqualToString:m_sessionIdentifier])
- return true;
-
- switch (event.type) {
- case NSEventTypeLeftMouseDown:
- case NSEventTypeLeftMouseDragged:
- case NSEventTypeLeftMouseUp:
- case NSEventTypeMouseMoved:
- case NSEventTypeOtherMouseDown:
- case NSEventTypeOtherMouseDragged:
- case NSEventTypeOtherMouseUp:
- case NSEventTypeRightMouseDown:
- case NSEventTypeRightMouseDragged:
- case NSEventTypeRightMouseUp:
- // Use this as a backup for checking mouse events, which are frequently copied
- // and/or faked by AppKit, causing them to lose their associated object tag.
- return event.eventNumber == synthesizedMouseEventMagicEventNumber;
- default:
- break;
- }
-
- return false;
-}
-
-void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, const WebCore::IntPoint& viewPosition, Inspector::Protocol::Automation::MouseInteraction interaction, Inspector::Protocol::Automation::MouseButton button, WebEvent::Modifiers keyModifiers)
-{
- IntRect windowRect;
- page.rootViewToWindow(IntRect(viewPosition, IntSize()), windowRect);
- IntPoint windowPosition = windowRect.location();
-
- NSEventModifierFlags modifiers = 0;
- if (keyModifiers & WebEvent::MetaKey)
- modifiers |= NSEventModifierFlagCommand;
- if (keyModifiers & WebEvent::AltKey)
- modifiers |= NSEventModifierFlagOption;
- if (keyModifiers & WebEvent::ControlKey)
- modifiers |= NSEventModifierFlagControl;
- if (keyModifiers & WebEvent::ShiftKey)
- modifiers |= NSEventModifierFlagShift;
- if (keyModifiers & WebEvent::CapsLockKey)
- modifiers |= NSEventModifierFlagCapsLock;
-
- NSTimeInterval timestamp = [NSDate timeIntervalSinceReferenceDate];
- NSWindow *window = page.platformWindow();
- NSInteger windowNumber = window.windowNumber;
-
- NSEventType downEventType;
- NSEventType dragEventType;
- NSEventType upEventType;
- switch (button) {
- case Inspector::Protocol::Automation::MouseButton::None:
- downEventType = upEventType = dragEventType = NSEventTypeMouseMoved;
- break;
- case Inspector::Protocol::Automation::MouseButton::Left:
- downEventType = NSEventTypeLeftMouseDown;
- dragEventType = NSEventTypeLeftMouseDragged;
- upEventType = NSEventTypeLeftMouseUp;
- break;
- case Inspector::Protocol::Automation::MouseButton::Middle:
- downEventType = NSEventTypeOtherMouseDown;
- dragEventType = NSEventTypeLeftMouseDragged;
- upEventType = NSEventTypeOtherMouseUp;
- break;
- case Inspector::Protocol::Automation::MouseButton::Right:
- downEventType = NSEventTypeRightMouseDown;
- upEventType = NSEventTypeRightMouseUp;
- break;
- }
-
- auto eventsToBeSent = adoptNS([[NSMutableArray alloc] init]);
-
- NSInteger eventNumber = synthesizedMouseEventMagicEventNumber;
-
- switch (interaction) {
- case Inspector::Protocol::Automation::MouseInteraction::Move:
- [eventsToBeSent addObject:[NSEvent mouseEventWithType:dragEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:0 pressure:0.0f]];
- break;
- case Inspector::Protocol::Automation::MouseInteraction::Down:
- // Hard-code the click count to one, since clients don't expect successive simulated
- // down/up events to be potentially counted as a double click event.
- [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
- break;
- case Inspector::Protocol::Automation::MouseInteraction::Up:
- // Hard-code the click count to one, since clients don't expect successive simulated
- // down/up events to be potentially counted as a double click event.
- [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
- break;
- case Inspector::Protocol::Automation::MouseInteraction::SingleClick:
- // Send separate down and up events. WebCore will see this as a single-click event.
- [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
- [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
- break;
- case Inspector::Protocol::Automation::MouseInteraction::DoubleClick:
- // Send multiple down and up events with proper click count.
- // WebCore will see this as a single-click event then double-click event.
- [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
- [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
- [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:2 pressure:WebCore::ForceAtClick]];
- [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:2 pressure:0.0f]];
- }
-
- sendSynthesizedEventsToPage(page, eventsToBeSent.get());
-}
-
-void WebAutomationSession::platformSimulateKeyStroke(WebPageProxy& page, Inspector::Protocol::Automation::KeyboardInteractionType interaction, Inspector::Protocol::Automation::VirtualKey key)
-{
- // If true, the key's modifier flags should affect other events while pressed down.
- bool isStickyModifier = false;
- // The modifiers changed by the virtual key when it is pressed or released.
- // The mapping from keys to modifiers is specified in the documentation for NSEvent.
- NSEventModifierFlags changedModifiers = 0;
- // The likely keyCode for the virtual key as defined in <HIToolbox/Events.h>.
- int keyCode = 0;
- // Typical characters produced by the virtual key, if any.
- NSString *characters = @"";
-
- // FIXME: this function and the Automation protocol enum should probably adopt key names
- // from W3C UIEvents standard. For more details: https://w3c.github.io/uievents-code/
-
- switch (key) {
- case Inspector::Protocol::Automation::VirtualKey::Shift:
- isStickyModifier = true;
- changedModifiers |= NSEventModifierFlagShift;
- keyCode = kVK_Shift;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Control:
- isStickyModifier = true;
- changedModifiers |= NSEventModifierFlagControl;
- keyCode = kVK_Control;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Alternate:
- isStickyModifier = true;
- changedModifiers |= NSEventModifierFlagOption;
- keyCode = kVK_Option;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Meta:
- // The 'meta' key does not exist on Apple keyboards and is usually
- // mapped to the Command key when using third-party keyboards.
- case Inspector::Protocol::Automation::VirtualKey::Command:
- isStickyModifier = true;
- changedModifiers |= NSEventModifierFlagCommand;
- keyCode = kVK_Command;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Help:
- changedModifiers |= NSEventModifierFlagHelp | NSEventModifierFlagFunction;
- keyCode = kVK_Help;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Backspace:
- keyCode = kVK_Delete;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Tab:
- keyCode = kVK_Tab;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Clear:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_KeypadClear;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Enter:
- keyCode = kVK_ANSI_KeypadEnter;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Pause:
- // The 'pause' key does not exist on Apple keyboards and has no keycode.
- // The semantics are unclear so just abort and do nothing.
- return;
- case Inspector::Protocol::Automation::VirtualKey::Cancel:
- // The 'cancel' key does not exist on Apple keyboards and has no keycode.
- // According to the internet its functionality is similar to 'Escape'.
- case Inspector::Protocol::Automation::VirtualKey::Escape:
- keyCode = kVK_Escape;
- break;
- case Inspector::Protocol::Automation::VirtualKey::PageUp:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_PageUp;
- break;
- case Inspector::Protocol::Automation::VirtualKey::PageDown:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_PageDown;
- break;
- case Inspector::Protocol::Automation::VirtualKey::End:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_End;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Home:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_Home;
- break;
- case Inspector::Protocol::Automation::VirtualKey::LeftArrow:
- changedModifiers |= NSEventModifierFlagNumericPad | NSEventModifierFlagFunction;
- keyCode = kVK_LeftArrow;
- break;
- case Inspector::Protocol::Automation::VirtualKey::UpArrow:
- changedModifiers |= NSEventModifierFlagNumericPad | NSEventModifierFlagFunction;
- keyCode = kVK_UpArrow;
- break;
- case Inspector::Protocol::Automation::VirtualKey::RightArrow:
- changedModifiers |= NSEventModifierFlagNumericPad | NSEventModifierFlagFunction;
- keyCode = kVK_RightArrow;
- break;
- case Inspector::Protocol::Automation::VirtualKey::DownArrow:
- changedModifiers |= NSEventModifierFlagNumericPad | NSEventModifierFlagFunction;
- keyCode = kVK_DownArrow;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Insert:
- // The 'insert' key does not exist on Apple keyboards and has no keycode.
- // The semantics are unclear so just abort and do nothing.
- return;
- case Inspector::Protocol::Automation::VirtualKey::Delete:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_ForwardDelete;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Space:
- keyCode = kVK_Space;
- characters = @" ";
- break;
- case Inspector::Protocol::Automation::VirtualKey::Semicolon:
- keyCode = kVK_ANSI_Semicolon;
- characters = @";";
- break;
- case Inspector::Protocol::Automation::VirtualKey::Equals:
- keyCode = kVK_ANSI_Equal;
- characters = @"=";
- break;
- case Inspector::Protocol::Automation::VirtualKey::Return:
- keyCode = kVK_Return;
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad0:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad0;
- characters = @"0";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad1:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad1;
- characters = @"1";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad2:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad2;
- characters = @"2";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad3:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad3;
- characters = @"3";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad4:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad4;
- characters = @"4";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad5:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad5;
- characters = @"5";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad6:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad6;
- characters = @"6";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad7:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad7;
- characters = @"7";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad8:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad8;
- characters = @"8";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPad9:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_Keypad9;
- characters = @"9";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPadMultiply:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_KeypadMultiply;
- characters = @"*";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPadAdd:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_KeypadPlus;
- characters = @"+";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPadSubtract:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_KeypadMinus;
- characters = @"-";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPadSeparator:
- changedModifiers |= NSEventModifierFlagNumericPad;
- // The 'Separator' key is only present on a few international keyboards.
- // It is usually mapped to the same character as Decimal ('.' or ',').
- FALLTHROUGH;
- case Inspector::Protocol::Automation::VirtualKey::NumberPadDecimal:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_KeypadDecimal;
- // FIXME: this might be locale-dependent. See the above comment.
- characters = @".";
- break;
- case Inspector::Protocol::Automation::VirtualKey::NumberPadDivide:
- changedModifiers |= NSEventModifierFlagNumericPad;
- keyCode = kVK_ANSI_KeypadDivide;
- characters = @"/";
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function1:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F1;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function2:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F2;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function3:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F3;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function4:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F4;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function5:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F5;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function6:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F6;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function7:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F7;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function8:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F8;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function9:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F9;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function10:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F10;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function11:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F11;
- break;
- case Inspector::Protocol::Automation::VirtualKey::Function12:
- changedModifiers |= NSEventModifierFlagFunction;
- keyCode = kVK_F12;
- break;
- }
-
- auto eventsToBeSent = adoptNS([[NSMutableArray alloc] init]);
-
- ASSERT(isStickyModifier || interaction == Inspector::Protocol::Automation::KeyboardInteractionType::KeyPress);
-
- NSEventModifierFlags existingModifiers = [NSEvent modifierFlags];
- NSEventModifierFlags updatedModifiers = 0;
- NSTimeInterval timestamp = [NSDate timeIntervalSinceReferenceDate];
- NSWindow *window = page.platformWindow();
- NSInteger windowNumber = window.windowNumber;
- NSPoint eventPosition = NSMakePoint(0, window.frame.size.height);
-
- switch (interaction) {
- case Inspector::Protocol::Automation::KeyboardInteractionType::KeyPress: {
- NSEventType eventType = isStickyModifier ? NSEventTypeFlagsChanged : NSEventTypeKeyDown;
- updatedModifiers = existingModifiers | changedModifiers;
- [eventsToBeSent addObject:[NSEvent keyEventWithType:eventType location:eventPosition modifierFlags:updatedModifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode]];
- break;
- }
- case Inspector::Protocol::Automation::KeyboardInteractionType::KeyRelease: {
- NSEventType eventType = isStickyModifier ? NSEventTypeFlagsChanged : NSEventTypeKeyUp;
- updatedModifiers = existingModifiers & ~changedModifiers;
- [eventsToBeSent addObject:[NSEvent keyEventWithType:eventType location:eventPosition modifierFlags:updatedModifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode]];
- break;
- }
- case Inspector::Protocol::Automation::KeyboardInteractionType::InsertByKey: {
- // Sticky modifiers should either be 'KeyPress' or 'KeyRelease'.
- ASSERT(!isStickyModifier);
- if (isStickyModifier)
- return;
-
- updatedModifiers = existingModifiers | changedModifiers;
- [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyDown location:eventPosition modifierFlags:updatedModifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode]];
- [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyUp location:eventPosition modifierFlags:updatedModifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:characters charactersIgnoringModifiers:characters isARepeat:NO keyCode:keyCode]];
- break;
- }
- }
-
- sendSynthesizedEventsToPage(page, eventsToBeSent.get());
-}
-
-void WebAutomationSession::platformSimulateKeySequence(WebPageProxy& page, const String& keySequence)
-{
- auto eventsToBeSent = adoptNS([[NSMutableArray alloc] init]);
-
- // Split the text into combining character sequences and send each separately.
- // This has no similarity to how keyboards work when inputting complex text.
- // This command is more similar to the 'insertText:' editing command, except
- // that this emits keyup/keydown/keypress events for roughly each character.
- // This API should move more towards that direction in the future.
- NSString *text = keySequence;
-
- NSEventModifierFlags modifiers = [NSEvent modifierFlags];
- NSTimeInterval timestamp = [NSDate timeIntervalSinceReferenceDate];
- NSWindow *window = page.platformWindow();
- NSInteger windowNumber = window.windowNumber;
- NSPoint eventPosition = NSMakePoint(0, window.frame.size.height);
-
- [text enumerateSubstringsInRange:NSMakeRange(0, text.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
- [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyDown location:eventPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:substring charactersIgnoringModifiers:substring isARepeat:NO keyCode:0]];
- [eventsToBeSent addObject:[NSEvent keyEventWithType:NSEventTypeKeyUp location:eventPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil characters:substring charactersIgnoringModifiers:substring isARepeat:NO keyCode:0]];
- }];
-
- sendSynthesizedEventsToPage(page, eventsToBeSent.get());
-}
-
-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];
-}
-
-#endif // USE(APPKIT)
-
-} // namespace WebKit
</del></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (210926 => 210927)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2017-01-19 17:28:24 UTC (rev 210926)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2017-01-19 17:52:36 UTC (rev 210927)
</span><span class="lines">@@ -1323,7 +1323,9 @@
</span><span class="cx">                 9955A6F51C7986E000EB6A93 /* AutomationBackendDispatchers.h in Headers */ = {isa = PBXBuildFile; fileRef = 9955A6F11C79866400EB6A93 /* AutomationBackendDispatchers.h */; };
</span><span class="cx">                 9955A6F61C7986E300EB6A93 /* AutomationProtocolObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9955A6F21C79866400EB6A93 /* AutomationProtocolObjects.cpp */; };
</span><span class="cx">                 9955A6F71C7986E500EB6A93 /* AutomationProtocolObjects.h in Headers */ = {isa = PBXBuildFile; fileRef = 9955A6F31C79866400EB6A93 /* AutomationProtocolObjects.h */; };
</span><del>-                9986BDD71CA9A22C004800AA /* WebAutomationSessionCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */; };
</del><ins>+                99C3AE241DAD8E3700AF5C16 /* WebAutomationSessionMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 99C3AE231DAD8E3400AF5C16 /* WebAutomationSessionMac.mm */; };
+                99C3AE271DAD948900AF5C16 /* WebAutomationSessionCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 99C3AE261DAD948500AF5C16 /* WebAutomationSessionCocoa.mm */; };
+                99C3AE2D1DADA6AD00AF5C16 /* WebAutomationSessionMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 99C3AE2C1DADA6A700AF5C16 /* WebAutomationSessionMacros.h */; };
</ins><span class="cx">                 99C81D591C20E1E5005C4C82 /* AutomationClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 99C81D561C20DFBE005C4C82 /* AutomationClient.mm */; };
</span><span class="cx">                 99C81D5A1C20E7E2005C4C82 /* AutomationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 99C81D551C20DFBE005C4C82 /* AutomationClient.h */; };
</span><span class="cx">                 99C81D5D1C21F38B005C4C82 /* APIAutomationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 99C81D5B1C20E817005C4C82 /* APIAutomationClient.h */; };
</span><span class="lines">@@ -3475,7 +3477,9 @@
</span><span class="cx">                 9955A6F11C79866400EB6A93 /* AutomationBackendDispatchers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationBackendDispatchers.h; sourceTree = "<group>"; };
</span><span class="cx">                 9955A6F21C79866400EB6A93 /* AutomationProtocolObjects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutomationProtocolObjects.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 9955A6F31C79866400EB6A93 /* AutomationProtocolObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationProtocolObjects.h; sourceTree = "<group>"; };
</span><del>-                9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAutomationSessionCocoa.mm; sourceTree = "<group>"; };
</del><ins>+                99C3AE231DAD8E3400AF5C16 /* WebAutomationSessionMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAutomationSessionMac.mm; sourceTree = "<group>"; };
+                99C3AE261DAD948500AF5C16 /* WebAutomationSessionCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAutomationSessionCocoa.mm; sourceTree = "<group>"; };
+                99C3AE2C1DADA6A700AF5C16 /* WebAutomationSessionMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAutomationSessionMacros.h; sourceTree = "<group>"; };
</ins><span class="cx">                 99C81D551C20DFBE005C4C82 /* AutomationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationClient.h; sourceTree = "<group>"; };
</span><span class="cx">                 99C81D561C20DFBE005C4C82 /* AutomationClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutomationClient.mm; sourceTree = "<group>"; };
</span><span class="cx">                 99C81D5B1C20E817005C4C82 /* APIAutomationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIAutomationClient.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -4914,7 +4918,6 @@
</span><span class="cx">                                 2DAF4FFA1B636181006013D6 /* ViewGestureController.cpp */,
</span><span class="cx">                                 2D125C5C1857EA05003BA3CB /* ViewGestureController.h */,
</span><span class="cx">                                 2D1B5D5A18586599006C6596 /* ViewGestureController.messages.in */,
</span><del>-                                9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */,
</del><span class="cx">                                 1AC0273E196622D600C12B75 /* WebPageProxyCocoa.mm */,
</span><span class="cx">                                 7C4694CB1A4B510A00AD5845 /* WebPasteboardProxyCocoa.mm */,
</span><span class="cx">                                 CDA29A1E1CBEB5FB00901CCF /* WebPlaybackSessionManagerProxy.h */,
</span><span class="lines">@@ -6025,13 +6028,32 @@
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><span class="cx">                                 9955A6E91C7980BB00EB6A93 /* Automation.json */,
</span><ins>+                                99C3AE251DAD946700AF5C16 /* cocoa */,
+                                99C3AE221DAD8E1400AF5C16 /* mac */,
</ins><span class="cx">                                 9955A6EA1C7980BB00EB6A93 /* WebAutomationSession.cpp */,
</span><span class="cx">                                 9955A6EB1C7980BB00EB6A93 /* WebAutomationSession.h */,
</span><span class="cx">                                 1C0A19591C9006EA00FE0EBB /* WebAutomationSession.messages.in */,
</span><ins>+                                99C3AE2C1DADA6A700AF5C16 /* WebAutomationSessionMacros.h */,
</ins><span class="cx">                         );
</span><span class="cx">                         path = Automation;
</span><span class="cx">                         sourceTree = "<group>";
</span><span class="cx">                 };
</span><ins>+                99C3AE221DAD8E1400AF5C16 /* mac */ = {
+                        isa = PBXGroup;
+                        children = (
+                                99C3AE231DAD8E3400AF5C16 /* WebAutomationSessionMac.mm */,
+                        );
+                        path = mac;
+                        sourceTree = "<group>";
+                };
+                99C3AE251DAD946700AF5C16 /* cocoa */ = {
+                        isa = PBXGroup;
+                        children = (
+                                99C3AE261DAD948500AF5C16 /* WebAutomationSessionCocoa.mm */,
+                        );
+                        path = cocoa;
+                        sourceTree = "<group>";
+                };
</ins><span class="cx">                 A182D5B11BE6BCF40087A7CC /* ios */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><span class="lines">@@ -8301,6 +8323,7 @@
</span><span class="cx">                                 BC49862F124D18C100D834E1 /* WKBundleHitTestResult.h in Headers */,
</span><span class="cx">                                 BC204EF211C83EC8008F3375 /* WKBundleInitialize.h in Headers */,
</span><span class="cx">                                 65B86F1E12F11DE300B7DD8A /* WKBundleInspector.h in Headers */,
</span><ins>+                                99C3AE2D1DADA6AD00AF5C16 /* WebAutomationSessionMacros.h in Headers */,
</ins><span class="cx">                                 1A8B66B41BC45B010082DF77 /* WKBundleMac.h in Headers */,
</span><span class="cx">                                 BC7043CC12F75EE0006472B9 /* WKBundleNavigationAction.h in Headers */,
</span><span class="cx">                                 51A728DE1B1BAD3800102EEE /* WKBundleNavigationActionPrivate.h in Headers */,
</span><span class="lines">@@ -9434,6 +9457,7 @@
</span><span class="cx">                                 51FD18B51651FBAD00DBE1CE /* NetworkResourceLoader.cpp in Sources */,
</span><span class="cx">                                 E152551A17011819003D7ADB /* NetworkResourceLoaderMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 5C1426EF1C23F80900D41183 /* NetworkResourceLoadParameters.cpp in Sources */,
</span><ins>+                                99C3AE271DAD948900AF5C16 /* WebAutomationSessionCocoa.mm in Sources */,
</ins><span class="cx">                                 BC8283AC16B4BF3F00A278FE /* NetworkServiceEntryPoint.mm in Sources */,
</span><span class="cx">                                 532159531DBAE7180054AA3C /* NetworkSession.cpp in Sources */,
</span><span class="cx">                                 5C20CB9D1BB0DCFA00895BB1 /* NetworkSessionCocoa.mm in Sources */,
</span><span class="lines">@@ -9600,7 +9624,6 @@
</span><span class="cx">                                 1A8E7D3C18C15149005A702A /* VisitedLinkTableControllerMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 CEDA12E2152CD1AE00D9E08D /* WebAlternativeTextClient.cpp in Sources */,
</span><span class="cx">                                 9955A6ED1C7980CA00EB6A93 /* WebAutomationSession.cpp in Sources */,
</span><del>-                                9986BDD71CA9A22C004800AA /* WebAutomationSessionCocoa.mm in Sources */,
</del><span class="cx">                                 1C0A19571C90068F00FE0EBB /* WebAutomationSessionMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 1C0A19461C8FF1A800FE0EBB /* WebAutomationSessionProxy.cpp in Sources */,
</span><span class="cx">                                 1C0A19531C8FFDFB00FE0EBB /* WebAutomationSessionProxyMessageReceiver.cpp in Sources */,
</span><span class="lines">@@ -9744,6 +9767,7 @@
</span><span class="cx">                                 BCBD3914125BB1A800D2C29F /* WebPageProxyMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 512127C31908239A00DAF35C /* WebPasteboardOverrides.cpp in Sources */,
</span><span class="cx">                                 7C4694D01A51E36800AD5845 /* WebPasteboardProxy.cpp in Sources */,
</span><ins>+                                99C3AE241DAD8E3700AF5C16 /* WebAutomationSessionMac.mm in Sources */,
</ins><span class="cx">                                 7C4694CC1A4B510A00AD5845 /* WebPasteboardProxyCocoa.mm in Sources */,
</span><span class="cx">                                 7C4694C91A4B4EA100AD5845 /* WebPasteboardProxyMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 1AB1F7741D1B2F8A007C9BD1 /* WebPaymentCoordinator.cpp in Sources */,
</span></span></pre>
</div>
</div>
</body>
</html>