Web Inspector: add 'Automation' protocol domain and generate its backend classes separately in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=154509
<rdar://problem/24759098>
Reviewed by Timothy Hatcher.
Source/JavaScriptCore:
Add a new 'WebKit' framework, which is used to generate protocol code
in WebKit2.
Add --backend and --frontend flags to the main generator script.
These allow a framework to trigger two different sets of generators
so they can be separately generated and compiled.
* inspector/scripts/codegen/models.py:
(Framework.fromString):
(Frameworks): Add new framework.
* inspector/scripts/generate-inspector-protocol-bindings.py:
If neither --backend or --frontend is specified, assume both are wanted.
This matches the behavior for JavaScriptCore and WebInspector frameworks.
(generate_from_specification):
Generate C++ files for the backend and Objective-C files for the frontend.
Source/WebKit2:
Add a new 'Automation' domain which presents an RPC interface
for sending automation commands to an active WebAutomationSession
in the UIProcess via RemoteInspector. This is similar to how the
Inspector backend communicates bidirectionally with a remote
Inspector frontend.
Add build system logic to generate JSON-RPC protocol bindings
for the 'Automation' domain using the inspector code generators.
Move automation-related files that are not API or SPI into their
own directory.
* Configurations/BaseTarget.xcconfig: Tell where JavaScriptCore's
private headers are, since that's where the code generators live.
* CMakeLists.txt: Look in UIProcess/Automation directory.
* PlatformMac.cmake:
* DerivedSources.make: Generate protocol bindings for a single domain.
The names of the generated files will be improved in a follow-up patch
so that they do not clash with generated files in JavaScriptCore.
* UIProcess/Automation/Automation.json: Added.
* UIProcess/Automation/WebAutomationSession.cpp: Renamed from Source/WebKit2/UIProcess/WebAutomationSession.cpp.
(WebKit::WebAutomationSession::WebAutomationSession):
(WebKit::WebAutomationSession::~WebAutomationSession):
Set up a backend dispatcher and frontend router. They will be used later.
(WebKit::WebAutomationSession::dispatchMessageFromRemote):
Forward messages from the remote to the backend dispatcher. When
an agent / command handler is registered, it will receive the message.
(WebKit::WebAutomationSession::connect):
(WebKit::WebAutomationSession::disconnect):
Connenct and disconnect the frontend router to the remote channel.
* UIProcess/Automation/WebAutomationSession.h: Renamed from Source/WebKit2/UIProcess/WebAutomationSession.h.
* WebKit2.xcodeproj/project.pbxproj: Add and move files.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@196970 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h b/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h
new file mode 100644
index 0000000..7c39a7f
--- /dev/null
+++ b/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+#ifndef WebAutomationSession_h
+#define WebAutomationSession_h
+
+#include "APIObject.h"
+#include <wtf/Forward.h>
+
+#if ENABLE(REMOTE_INSPECTOR)
+#include <JavaScriptCore/RemoteAutomationTarget.h>
+#endif
+
+namespace API {
+class AutomationSessionClient;
+}
+
+namespace Inspector {
+class BackendDispatcher;
+class FrontendRouter;
+}
+
+namespace WebKit {
+
+class WebAutomationSessionClient;
+
+class WebAutomationSession final : public API::ObjectImpl<API::Object::Type::AutomationSession>
+#if ENABLE(REMOTE_INSPECTOR)
+ , public Inspector::RemoteAutomationTarget
+#endif
+{
+public:
+ WebAutomationSession();
+ ~WebAutomationSession();
+
+ void setClient(std::unique_ptr<API::AutomationSessionClient>);
+
+ void setSessionIdentifier(const String& sessionIdentifier) { m_sessionIdentifier = sessionIdentifier; }
+ String sessionIdentifier() const { return m_sessionIdentifier; }
+
+#if ENABLE(REMOTE_INSPECTOR)
+ // Inspector::RemoteAutomationTarget API
+ virtual String name() const override { return m_sessionIdentifier; }
+ virtual void dispatchMessageFromRemote(const String& message) override;
+ virtual void connect(Inspector::FrontendChannel*, bool isAutomaticConnection = false) override;
+ virtual void disconnect(Inspector::FrontendChannel*) override;
+#endif
+
+private:
+ std::unique_ptr<API::AutomationSessionClient> m_client;
+ String m_sessionIdentifier { ASCIILiteral("Untitled Session") };
+ Ref<Inspector::FrontendRouter> m_frontendRouter;
+ Ref<Inspector::BackendDispatcher> m_backendDispatcher;
+
+#if ENABLE(REMOTE_INSPECTOR)
+ Inspector::FrontendChannel* m_remoteChannel { nullptr };
+#endif
+};
+
+} // namespace WebKit
+
+#endif // WebAutomationSession_h