+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.
+
2017-01-19 Carlos Garcia Campos <cgarcia@igalia.com>
[GTK] Provide API to set proxy settings
AutomationBackendDispatchers.cpp \
#
+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
+
# JSON-RPC Backend Dispatchers, Type Builders
$(firstword $(AUTOMATION_PROTOCOL_OUTPUT_FILES)) : $(AUTOMATION_PROTOCOL_INPUT_FILES) $(AUTOMATION_PROTOCOL_GENERATOR_SCRIPTS)
- $(PYTHON) $(JavaScriptCore_SCRIPTS_DIR)/generate-inspector-protocol-bindings.py --framework WebKit --backend --outputDir . $(AUTOMATION_PROTOCOL_INPUT_FILES)
+ $(PYTHON) $(JavaScriptCore_SCRIPTS_DIR)/generate-inspector-protocol-bindings.py --framework WebKit $(AUTOMATION_BACKEND_PLATFORM_ARGUMENTS) --backend --outputDir . $(AUTOMATION_PROTOCOL_INPUT_FILES)
all : $(firstword $(AUTOMATION_PROTOCOL_OUTPUT_FILES))
{
"name": "resizeWindowOfBrowsingContext",
"description": "Resizes the window of the specified browsing context to the specified size.",
+ "platform": "macOS",
"parameters": [
{ "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context to be resized." },
{ "name": "size", "$ref": "Size", "description": "The new size for the browsing context's window." }
{
"name": "moveWindowOfBrowsingContext",
"description": "Moves the window of the specified browsing context to the specified position.",
+ "platform": "macOS",
"parameters": [
{ "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context to be moved." },
{ "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." }
{
"name": "inspectBrowsingContext",
"description": "Inspect the specified browsing context using Web Inspector.",
+ "platform": "macOS",
"parameters": [
{ "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context that should be inspected." },
{ "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." }
/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * 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
#include "APIAutomationSessionClient.h"
#include "AutomationProtocolObjects.h"
+#include "WebAutomationSessionMacros.h"
#include "WebAutomationSessionMessages.h"
#include "WebAutomationSessionProxyMessages.h"
#include "WebCookieManagerProxy.h"
using namespace Inspector;
-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)
-
namespace WebKit {
WebAutomationSession::WebAutomationSession()
.release();
}
+// Platform-independent Commands.
+
void WebAutomationSession::getBrowsingContexts(Inspector::ErrorString& errorString, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>>& contexts)
{
contexts = Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>::create();
page->process().send(Messages::WebAutomationSessionProxy::FocusFrame(page->pageID(), frameID.value()), 0);
}
-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::navigateBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const String& url, Ref<NavigateBrowsingContextCallback>&& callback)
{
WebPageProxy* page = webPageProxyForHandle(handle);
page->reload(reloadFromOrigin, { });
}
-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();
- }
-}
-
void WebAutomationSession::navigationOccurredForPage(const WebPageProxy& page)
{
if (auto callback = m_pendingNavigationInBrowsingContextCallbacksPerPage.take(page.pageID()))
callback->sendSuccess(base64EncodedData);
}
-#if !USE(APPKIT)
+// Platform-dependent Implementation Stubs.
+
+#if !PLATFORM(MAC)
void WebAutomationSession::platformSimulateMouseInteraction(WebKit::WebPageProxy&, const WebCore::IntPoint&, Inspector::Protocol::Automation::MouseInteraction, Inspector::Protocol::Automation::MouseButton, WebEvent::Modifiers)
{
}
void WebAutomationSession::platformSimulateKeySequence(WebPageProxy&, const String&)
{
}
+#endif // !PLATFORM(MAC)
+#if !PLATFORM(COCOA)
String WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&)
{
return String();
}
-#endif // !USE(APPKIT)
+#endif // !PLATFORM(COCOA)
} // namespace WebKit
/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * 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
void terminate();
// Inspector::AutomationBackendDispatcherHandler API
+ // 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
void getBrowsingContexts(Inspector::ErrorString&, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>>&) override;
void getBrowsingContext(Inspector::ErrorString&, const String&, RefPtr<Inspector::Protocol::Automation::BrowsingContext>&) override;
void createBrowsingContext(Inspector::ErrorString&, String*) override;
void closeBrowsingContext(Inspector::ErrorString&, const String&) override;
void switchToBrowsingContext(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle) override;
- 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 navigateBrowsingContext(Inspector::ErrorString&, const String& handle, const String& url, Ref<NavigateBrowsingContextCallback>&&) override;
void goBackInBrowsingContext(Inspector::ErrorString&, const String&, Ref<GoBackInBrowsingContextCallback>&&) override;
void goForwardInBrowsingContext(Inspector::ErrorString&, const String&, Ref<GoForwardInBrowsingContextCallback>&&) override;
void reloadBrowsingContext(Inspector::ErrorString&, const String&, Ref<ReloadBrowsingContextCallback>&&) override;
- void inspectBrowsingContext(Inspector::ErrorString&, const String&, const bool* optionalEnableAutoCapturing, Ref<InspectBrowsingContextCallback>&&) override;
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;
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;
void performKeyboardInteractions(Inspector::ErrorString&, const String& handle, const Inspector::InspectorArray& interactions, Ref<PerformKeyboardInteractionsCallback>&&) override;
void deleteSingleCookie(Inspector::ErrorString&, const String& browsingContextHandle, const String& cookieName, Ref<DeleteSingleCookieCallback>&&) override;
void addSingleCookie(Inspector::ErrorString&, const String& browsingContextHandle, const Inspector::InspectorObject& cookie, Ref<AddSingleCookieCallback>&&) override;
void deleteAllCookies(Inspector::ErrorString&, const String& browsingContextHandle) override;
-#if USE(APPKIT)
+
+ // 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)
bool wasEventSynthesizedForAutomation(NSEvent *);
void markEventAsSynthesizedForAutomation(NSEvent *);
#endif
String handleForWebFrameID(uint64_t frameID);
String handleForWebFrameProxy(const WebFrameProxy&);
- // Implemented in generated WebAutomationSessionMessageReceiver.cpp
+ // Implemented in generated WebAutomationSessionMessageReceiver.cpp.
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
- // Called by WebAutomationSession messages
+ // Called by WebAutomationSession messages.
void didEvaluateJavaScriptFunction(uint64_t callbackID, const String& result, const String& errorType);
void didResolveChildFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
void didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
void didGetCookiesForFrame(uint64_t callbackID, Vector<WebCore::Cookie>, const String& errorType);
void didDeleteCookie(uint64_t callbackID, const String& errorType);
- // Platform-specific helper methods.
+ // Platform-dependent implementations.
void platformSimulateMouseInteraction(WebPageProxy&, const WebCore::IntPoint& viewPosition, Inspector::Protocol::Automation::MouseInteraction, Inspector::Protocol::Automation::MouseButton, WebEvent::Modifiers);
// Simulates a single virtual key being pressed, such as Control, F-keys, Numpad keys, etc. as allowed by the protocol.
void platformSimulateKeyStroke(WebPageProxy&, Inspector::Protocol::Automation::KeyboardInteractionType, Inspector::Protocol::Automation::VirtualKey);
// Get base64 encoded PNG data from a bitmap.
String platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&);
-#if USE(APPKIT)
+#if PLATFORM(MAC)
void sendSynthesizedEventsToPage(WebPageProxy&, NSArray *eventsToSend);
#endif
--- /dev/null
+/*
+ * 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)
--- /dev/null
+/*
+ * 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)
/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * 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
#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>
-#if USE(APPKIT)
-#import <HIToolbox/Events.h>
-#endif
-
using namespace WebCore;
namespace WebKit {
-#if USE(APPKIT)
+#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;
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;
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
+
+#endif // PLATFORM(MAC)
9955A6F51C7986E000EB6A93 /* AutomationBackendDispatchers.h in Headers */ = {isa = PBXBuildFile; fileRef = 9955A6F11C79866400EB6A93 /* AutomationBackendDispatchers.h */; };
9955A6F61C7986E300EB6A93 /* AutomationProtocolObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9955A6F21C79866400EB6A93 /* AutomationProtocolObjects.cpp */; };
9955A6F71C7986E500EB6A93 /* AutomationProtocolObjects.h in Headers */ = {isa = PBXBuildFile; fileRef = 9955A6F31C79866400EB6A93 /* AutomationProtocolObjects.h */; };
- 9986BDD71CA9A22C004800AA /* WebAutomationSessionCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */; };
+ 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 */; };
99C81D591C20E1E5005C4C82 /* AutomationClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 99C81D561C20DFBE005C4C82 /* AutomationClient.mm */; };
99C81D5A1C20E7E2005C4C82 /* AutomationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 99C81D551C20DFBE005C4C82 /* AutomationClient.h */; };
99C81D5D1C21F38B005C4C82 /* APIAutomationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 99C81D5B1C20E817005C4C82 /* APIAutomationClient.h */; };
9955A6F11C79866400EB6A93 /* AutomationBackendDispatchers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationBackendDispatchers.h; sourceTree = "<group>"; };
9955A6F21C79866400EB6A93 /* AutomationProtocolObjects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutomationProtocolObjects.cpp; sourceTree = "<group>"; };
9955A6F31C79866400EB6A93 /* AutomationProtocolObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationProtocolObjects.h; sourceTree = "<group>"; };
- 9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAutomationSessionCocoa.mm; sourceTree = "<group>"; };
+ 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>"; };
99C81D551C20DFBE005C4C82 /* AutomationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationClient.h; sourceTree = "<group>"; };
99C81D561C20DFBE005C4C82 /* AutomationClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutomationClient.mm; sourceTree = "<group>"; };
99C81D5B1C20E817005C4C82 /* APIAutomationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIAutomationClient.h; sourceTree = "<group>"; };
2DAF4FFA1B636181006013D6 /* ViewGestureController.cpp */,
2D125C5C1857EA05003BA3CB /* ViewGestureController.h */,
2D1B5D5A18586599006C6596 /* ViewGestureController.messages.in */,
- 9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */,
1AC0273E196622D600C12B75 /* WebPageProxyCocoa.mm */,
7C4694CB1A4B510A00AD5845 /* WebPasteboardProxyCocoa.mm */,
CDA29A1E1CBEB5FB00901CCF /* WebPlaybackSessionManagerProxy.h */,
isa = PBXGroup;
children = (
9955A6E91C7980BB00EB6A93 /* Automation.json */,
+ 99C3AE251DAD946700AF5C16 /* cocoa */,
+ 99C3AE221DAD8E1400AF5C16 /* mac */,
9955A6EA1C7980BB00EB6A93 /* WebAutomationSession.cpp */,
9955A6EB1C7980BB00EB6A93 /* WebAutomationSession.h */,
1C0A19591C9006EA00FE0EBB /* WebAutomationSession.messages.in */,
+ 99C3AE2C1DADA6A700AF5C16 /* WebAutomationSessionMacros.h */,
);
path = Automation;
sourceTree = "<group>";
};
+ 99C3AE221DAD8E1400AF5C16 /* mac */ = {
+ isa = PBXGroup;
+ children = (
+ 99C3AE231DAD8E3400AF5C16 /* WebAutomationSessionMac.mm */,
+ );
+ path = mac;
+ sourceTree = "<group>";
+ };
+ 99C3AE251DAD946700AF5C16 /* cocoa */ = {
+ isa = PBXGroup;
+ children = (
+ 99C3AE261DAD948500AF5C16 /* WebAutomationSessionCocoa.mm */,
+ );
+ path = cocoa;
+ sourceTree = "<group>";
+ };
A182D5B11BE6BCF40087A7CC /* ios */ = {
isa = PBXGroup;
children = (
BC49862F124D18C100D834E1 /* WKBundleHitTestResult.h in Headers */,
BC204EF211C83EC8008F3375 /* WKBundleInitialize.h in Headers */,
65B86F1E12F11DE300B7DD8A /* WKBundleInspector.h in Headers */,
+ 99C3AE2D1DADA6AD00AF5C16 /* WebAutomationSessionMacros.h in Headers */,
1A8B66B41BC45B010082DF77 /* WKBundleMac.h in Headers */,
BC7043CC12F75EE0006472B9 /* WKBundleNavigationAction.h in Headers */,
51A728DE1B1BAD3800102EEE /* WKBundleNavigationActionPrivate.h in Headers */,
51FD18B51651FBAD00DBE1CE /* NetworkResourceLoader.cpp in Sources */,
E152551A17011819003D7ADB /* NetworkResourceLoaderMessageReceiver.cpp in Sources */,
5C1426EF1C23F80900D41183 /* NetworkResourceLoadParameters.cpp in Sources */,
+ 99C3AE271DAD948900AF5C16 /* WebAutomationSessionCocoa.mm in Sources */,
BC8283AC16B4BF3F00A278FE /* NetworkServiceEntryPoint.mm in Sources */,
532159531DBAE7180054AA3C /* NetworkSession.cpp in Sources */,
5C20CB9D1BB0DCFA00895BB1 /* NetworkSessionCocoa.mm in Sources */,
1A8E7D3C18C15149005A702A /* VisitedLinkTableControllerMessageReceiver.cpp in Sources */,
CEDA12E2152CD1AE00D9E08D /* WebAlternativeTextClient.cpp in Sources */,
9955A6ED1C7980CA00EB6A93 /* WebAutomationSession.cpp in Sources */,
- 9986BDD71CA9A22C004800AA /* WebAutomationSessionCocoa.mm in Sources */,
1C0A19571C90068F00FE0EBB /* WebAutomationSessionMessageReceiver.cpp in Sources */,
1C0A19461C8FF1A800FE0EBB /* WebAutomationSessionProxy.cpp in Sources */,
1C0A19531C8FFDFB00FE0EBB /* WebAutomationSessionProxyMessageReceiver.cpp in Sources */,
BCBD3914125BB1A800D2C29F /* WebPageProxyMessageReceiver.cpp in Sources */,
512127C31908239A00DAF35C /* WebPasteboardOverrides.cpp in Sources */,
7C4694D01A51E36800AD5845 /* WebPasteboardProxy.cpp in Sources */,
+ 99C3AE241DAD8E3700AF5C16 /* WebAutomationSessionMac.mm in Sources */,
7C4694CC1A4B510A00AD5845 /* WebPasteboardProxyCocoa.mm in Sources */,
7C4694C91A4B4EA100AD5845 /* WebPasteboardProxyMessageReceiver.cpp in Sources */,
1AB1F7741D1B2F8A007C9BD1 /* WebPaymentCoordinator.cpp in Sources */,