Skip to content
Permalink
Browse files
[PlayStation][WinCairo] Enable WebDriver target on PlayStation and cl…
…ient for WinCairo

https://bugs.webkit.org/show_bug.cgi?id=216908

Reviewed by Don Olmstead.

Source/JavaScriptCore:

Implement automation session correctly for PlayStation and WinCairo.

* inspector/remote/RemoteInspector.h:
* inspector/remote/socket/RemoteInspectorConnectionClient.cpp:
(Inspector::RemoteInspectorConnectionClient::parseTargetListJSON):
* inspector/remote/socket/RemoteInspectorConnectionClient.h:
* inspector/remote/socket/RemoteInspectorSocket.cpp:
(Inspector::RemoteInspector::stopInternal):
(Inspector::RemoteInspector::requestAutomationSession):
(Inspector::RemoteInspector::startAutomationSession):

Source/WebDriver:

Extend WebDriver client binary to support connection to remote device for both PlayStation
and WinCairo. We've implemented a simple web server to accept WebDriver request natively and bypass them
to RemoteInspector.

* Capabilities.h:
* HTTPServer.h:
* PlatformPlayStation.cmake: Added.
* PlatformWin.cmake:
* SessionHost.h:
(WebDriver::SessionHost::setHostAddress):
* WebDriverMain.cpp:
(main):
(dllLauncherEntryPoint):
* WebDriverService.cpp:
(WebDriver::printUsageStatement):
(WebDriver::WebDriverService::run):
(WebDriver::WebDriverService::connectToBrowser):
* WebDriverService.h:
* gtk/WebDriverServiceGtk.cpp:
(WebDriver::WebDriverService::platformInit):
* playstation/WebDriverServicePlayStation.cpp: Copied from Source\WebDriver\win\WebDriverServiceWin.cpp.
(WebDriver::WebDriverService::platformInit):
(WebDriver::WebDriverService::platformCapabilities):
(WebDriver::WebDriverService::platformCompareBrowserVersions):
(WebDriver::WebDriverService::platformValidateCapability const):
(WebDriver::WebDriverService::platformMatchCapability const):
(WebDriver::WebDriverService::platformParseCapabilities const):
(WebDriver::WebDriverService::platformSupportProxyType const):
* socket/CapabilitiesSocket.cpp: Copied from Source\WebDriver\socket\SessionHostSocket.cpp.
(WebDriver::CapabilitiesSocket::parseCapabilities):
* socket/CapabilitiesSocket.h: Copied from Source\WebDriver\socket\HTTPServerSocket.cpp.
* socket/HTTPParser.cpp: Added.
(WebDriver::HTTPParser::parse):
(WebDriver::HTTPParser::handlePhase):
(WebDriver::HTTPParser::abortProcess):
(WebDriver::HTTPParser::parseFirstLine):
(WebDriver::HTTPParser::readLine):
(WebDriver::HTTPParser::expectedBodyLength const):
* socket/HTTPParser.h: Copied from Source\WebDriver\HTTPServer.h.
(WebDriver::HTTPParser::pullMessage):
* socket/HTTPServerSocket.cpp:
(WebDriver::HTTPServer::listen):
(WebDriver::HTTPServer::disconnect):
(WebDriver::HTTPServer::doAccept):
(WebDriver::HTTPServer::didClose):
(WebDriver::HTTPRequestHandler::connect):
(WebDriver::HTTPRequestHandler::reset):
(WebDriver::HTTPRequestHandler::didReceive):
(WebDriver::HTTPRequestHandler::sendResponse):
(WebDriver::HTTPRequestHandler::packHTTPMessage const):
(WebDriver::HTTPRequestHandler::didClose):
* socket/SessionHostSocket.cpp:
(WebDriver::SessionHost::dispatchMap):
(WebDriver::SessionHost::sendWebInspectorEvent):
(WebDriver::SessionHost::connectToBrowser):
(WebDriver::SessionHost::isConnected const):
(WebDriver::SessionHost::didClose):
(WebDriver::SessionHost::parseTargetList):
(WebDriver::SessionHost::receivedSetTargetList):
(WebDriver::SessionHost::receivedSendMessageToFrontend):
(WebDriver::SessionHost::startAutomationSession):
(WebDriver::SessionHost::setTargetList):
(WebDriver::SessionHost::sendMessageToBackend):
* win/WebDriverServiceWin.cpp:
(WebDriver::WebDriverService::platformInit):
(WebDriver::WebDriverService::platformParseCapabilities const):
* wpe/WebDriverServiceWPE.cpp:
(WebDriver::WebDriverService::platformInit):


Canonical link: https://commits.webkit.org/229926@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@267807 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
basuke committed Sep 30, 2020
1 parent 0b3612e commit 687d6eeb76e513a84c4eb0a6dd2e697a61903bd4
Showing 24 changed files with 978 additions and 17 deletions.
@@ -1,3 +1,21 @@
2020-09-30 Basuke Suzuki <basuke.suzuki@sony.com>

[PlayStation][WinCairo] Enable WebDriver target on PlayStation and client for WinCairo
https://bugs.webkit.org/show_bug.cgi?id=216908

Reviewed by Don Olmstead.

Implement automation session correctly for PlayStation and WinCairo.

* inspector/remote/RemoteInspector.h:
* inspector/remote/socket/RemoteInspectorConnectionClient.cpp:
(Inspector::RemoteInspectorConnectionClient::parseTargetListJSON):
* inspector/remote/socket/RemoteInspectorConnectionClient.h:
* inspector/remote/socket/RemoteInspectorSocket.cpp:
(Inspector::RemoteInspector::stopInternal):
(Inspector::RemoteInspector::requestAutomationSession):
(Inspector::RemoteInspector::startAutomationSession):

2020-09-30 Commit Queue <commit-queue@webkit.org>

Unreviewed, reverting r267795.
@@ -89,7 +89,7 @@ class JS_EXPORT_PRIVATE RemoteInspector final

struct SessionCapabilities {
bool acceptInsecureCertificates { false };
#if USE(GLIB)
#if USE(GLIB) || USE(INSPECTOR_SOCKET_SERVER)
Vector<std::pair<String, String>> certificates;
struct Proxy {
String type;
@@ -112,6 +112,9 @@ class JS_EXPORT_PRIVATE RemoteInspector final
virtual String browserName() const { return { }; }
virtual String browserVersion() const { return { }; }
virtual void requestAutomationSession(const String& sessionIdentifier, const SessionCapabilities&) = 0;
#if USE(INSPECTOR_SOCKET_SERVER)
virtual void closeAutomationSession() = 0;
#endif
};

#if PLATFORM(COCOA)
@@ -160,7 +163,7 @@ class JS_EXPORT_PRIVATE RemoteInspector final
void sendMessageToTarget(TargetID, const char* message);
#endif
#if USE(INSPECTOR_SOCKET_SERVER)
void requestAutomationSession(const String& sessionID, const Client::SessionCapabilities&);
void requestAutomationSession(String&& sessionID, const Client::SessionCapabilities&);

bool isConnected() const { return !!m_clientConnection; }
void connect(ConnectionID);
@@ -119,6 +119,26 @@ Optional<RemoteInspectorConnectionClient::Event> RemoteInspectorConnectionClient
return event;
}

Optional<Vector<Ref<JSON::Object>>> RemoteInspectorConnectionClient::parseTargetListJSON(const String& message)
{
auto messageValue = JSON::Value::parseJSON(message);
if (!messageValue)
return WTF::nullopt;

auto messageArray = messageValue->asArray();
if (!messageArray)
return WTF::nullopt;

Vector<Ref<JSON::Object>> targetList;
for (auto& itemValue : *messageArray) {
if (auto itemObject = itemValue->asObject())
targetList.append(itemObject.releaseNonNull());
else
LOG_ERROR("Invalid type of value in targetList. It must be object.");
}
return targetList;
}

} // namespace Inspector

#endif // ENABLE(REMOTE_INSPECTOR)
@@ -31,6 +31,7 @@
#include "RemoteInspectorMessageParser.h"
#include "RemoteInspectorSocketEndpoint.h"
#include <wtf/HashMap.h>
#include <wtf/JSONValues.h>
#include <wtf/Lock.h>
#include <wtf/text/WTFString.h>

@@ -46,7 +47,7 @@ class JS_EXPORT_PRIVATE RemoteInspectorConnectionClient : public RemoteInspector
Optional<ConnectionID> createClient(PlatformSocketType);
void send(ConnectionID, const uint8_t* data, size_t);

void didReceive(RemoteInspectorSocketEndpoint&, ConnectionID, Vector<uint8_t>&&) override;
void didReceive(RemoteInspectorSocketEndpoint&, ConnectionID, Vector<uint8_t>&&) final;

struct Event {
String methodName;
@@ -60,6 +61,8 @@ class JS_EXPORT_PRIVATE RemoteInspectorConnectionClient : public RemoteInspector
virtual HashMap<String, CallHandler>& dispatchMap() = 0;

protected:
Optional<Vector<Ref<JSON::Object>>> parseTargetListJSON(const String&);

static Optional<Event> extractEvent(ConnectionID, Vector<uint8_t>&&);

HashMap<ConnectionID, MessageParser> m_parsers;
@@ -107,6 +107,9 @@ void RemoteInspector::stopInternal(StopSource)
targetConnection->close();
m_targetConnectionMap.clear();

if (m_client)
m_client->closeAutomationSession();

updateHasActiveDebugSession();

m_automaticInspectionPaused = false;
@@ -194,7 +197,7 @@ void RemoteInspector::sendAutomaticInspectionCandidateMessage()
// FIXME: Implement automatic inspection.
}

void RemoteInspector::requestAutomationSession(const String& sessionID, const Client::SessionCapabilities& capabilities)
void RemoteInspector::requestAutomationSession(String&& sessionID, const Client::SessionCapabilities& capabilities)
{
if (!m_client)
return;
@@ -209,7 +212,7 @@ void RemoteInspector::requestAutomationSession(const String& sessionID, const Cl
return;
}

m_client->requestAutomationSession(sessionID, capabilities);
m_client->requestAutomationSession(WTFMove(sessionID), capabilities);
updateClientCapabilities();
}

@@ -359,13 +362,17 @@ void RemoteInspector::startAutomationSession(const Event& event)
{
ASSERT(isMainThread());

if (!m_clientConnection)
return;

if (!event.message)
return;

requestAutomationSession(event.message.value(), { });
String sessionID = *event.message;
requestAutomationSession(WTFMove(sessionID), { });

auto sendEvent = JSON::Object::create();
sendEvent->setString("event"_s, "SetCapabilities"_s);
sendEvent->setString("event"_s, "StartAutomationSession_Return"_s);

auto capability = clientCapabilities();

@@ -83,6 +83,10 @@ struct Capabilities {
#if PLATFORM(GTK)
Optional<bool> useOverlayScrollbars;
#endif
#if USE(INSPECTOR_SOCKET_SERVER)
Optional<String> targetAddr;
Optional<int> targetPort;
#endif
};

} // namespace WebDriver
@@ -1,3 +1,79 @@
2020-09-30 Basuke Suzuki <basuke.suzuki@sony.com>

[PlayStation][WinCairo] Enable WebDriver target on PlayStation and client for WinCairo
https://bugs.webkit.org/show_bug.cgi?id=216908

Reviewed by Don Olmstead.

Extend WebDriver client binary to support connection to remote device for both PlayStation
and WinCairo. We've implemented a simple web server to accept WebDriver request natively and bypass them
to RemoteInspector.

* Capabilities.h:
* HTTPServer.h:
* PlatformPlayStation.cmake: Added.
* PlatformWin.cmake:
* SessionHost.h:
(WebDriver::SessionHost::setHostAddress):
* WebDriverMain.cpp:
(main):
(dllLauncherEntryPoint):
* WebDriverService.cpp:
(WebDriver::printUsageStatement):
(WebDriver::WebDriverService::run):
(WebDriver::WebDriverService::connectToBrowser):
* WebDriverService.h:
* gtk/WebDriverServiceGtk.cpp:
(WebDriver::WebDriverService::platformInit):
* playstation/WebDriverServicePlayStation.cpp: Copied from Source\WebDriver\win\WebDriverServiceWin.cpp.
(WebDriver::WebDriverService::platformInit):
(WebDriver::WebDriverService::platformCapabilities):
(WebDriver::WebDriverService::platformCompareBrowserVersions):
(WebDriver::WebDriverService::platformValidateCapability const):
(WebDriver::WebDriverService::platformMatchCapability const):
(WebDriver::WebDriverService::platformParseCapabilities const):
(WebDriver::WebDriverService::platformSupportProxyType const):
* socket/CapabilitiesSocket.cpp: Copied from Source\WebDriver\socket\SessionHostSocket.cpp.
(WebDriver::CapabilitiesSocket::parseCapabilities):
* socket/CapabilitiesSocket.h: Copied from Source\WebDriver\socket\HTTPServerSocket.cpp.
* socket/HTTPParser.cpp: Added.
(WebDriver::HTTPParser::parse):
(WebDriver::HTTPParser::handlePhase):
(WebDriver::HTTPParser::abortProcess):
(WebDriver::HTTPParser::parseFirstLine):
(WebDriver::HTTPParser::readLine):
(WebDriver::HTTPParser::expectedBodyLength const):
* socket/HTTPParser.h: Copied from Source\WebDriver\HTTPServer.h.
(WebDriver::HTTPParser::pullMessage):
* socket/HTTPServerSocket.cpp:
(WebDriver::HTTPServer::listen):
(WebDriver::HTTPServer::disconnect):
(WebDriver::HTTPServer::doAccept):
(WebDriver::HTTPServer::didClose):
(WebDriver::HTTPRequestHandler::connect):
(WebDriver::HTTPRequestHandler::reset):
(WebDriver::HTTPRequestHandler::didReceive):
(WebDriver::HTTPRequestHandler::sendResponse):
(WebDriver::HTTPRequestHandler::packHTTPMessage const):
(WebDriver::HTTPRequestHandler::didClose):
* socket/SessionHostSocket.cpp:
(WebDriver::SessionHost::dispatchMap):
(WebDriver::SessionHost::sendWebInspectorEvent):
(WebDriver::SessionHost::connectToBrowser):
(WebDriver::SessionHost::isConnected const):
(WebDriver::SessionHost::didClose):
(WebDriver::SessionHost::parseTargetList):
(WebDriver::SessionHost::receivedSetTargetList):
(WebDriver::SessionHost::receivedSendMessageToFrontend):
(WebDriver::SessionHost::startAutomationSession):
(WebDriver::SessionHost::setTargetList):
(WebDriver::SessionHost::sendMessageToBackend):
* win/WebDriverServiceWin.cpp:
(WebDriver::WebDriverService::platformInit):
(WebDriver::WebDriverService::platformParseCapabilities const):
* wpe/WebDriverServiceWPE.cpp:
(WebDriver::WebDriverService::platformInit):

2020-09-14 Carlos Garcia Campos <cgarcia@igalia.com>

REGRESSION(r266885): WebDriver is broken since r266885
@@ -32,11 +32,22 @@
#if USE(SOUP)
#include <wtf/glib/GRefPtr.h>
typedef struct _SoupServer SoupServer;
#elif USE(INSPECTOR_SOCKET_SERVER)
#include "HTTPParser.h"
#include <JavaScriptCore/RemoteInspectorSocketEndpoint.h>

using Inspector::ConnectionID;
using Inspector::PlatformSocketType;
using Inspector::RemoteInspectorSocketEndpoint;
#endif

namespace WebDriver {

class HTTPRequestHandler {
class HTTPRequestHandler
#if USE(INSPECTOR_SOCKET_SERVER)
: public RemoteInspectorSocketEndpoint::Client
#endif
{
public:
struct Request {
String method;
@@ -50,9 +61,30 @@ class HTTPRequestHandler {
String contentType;
};
virtual void handleRequest(Request&&, Function<void (Response&&)>&& replyHandler) = 0;

#if USE(INSPECTOR_SOCKET_SERVER)
void connect(ConnectionID);
#endif

private:
#if USE(INSPECTOR_SOCKET_SERVER)
void sendResponse(Response&&);
void reset();
String packHTTPMessage(Response&&) const;

void didReceive(RemoteInspectorSocketEndpoint&, ConnectionID, Vector<uint8_t>&&) final;
void didClose(RemoteInspectorSocketEndpoint&, ConnectionID) final;

Optional<ConnectionID> m_client;
HTTPParser m_parser;
#endif
};

class HTTPServer {
class HTTPServer
#if USE(INSPECTOR_SOCKET_SERVER)
: public RemoteInspectorSocketEndpoint::Listener
#endif
{
public:
explicit HTTPServer(HTTPRequestHandler&);
~HTTPServer() = default;
@@ -61,11 +93,20 @@ class HTTPServer {
void disconnect();

private:
#if USE(INSPECTOR_SOCKET_SERVER)
Optional<ConnectionID> doAccept(RemoteInspectorSocketEndpoint&, PlatformSocketType) final;
void didClose(RemoteInspectorSocketEndpoint&, ConnectionID) final;
#endif

HTTPRequestHandler& m_requestHandler;

#if USE(SOUP)
GRefPtr<SoupServer> m_soupServer;
#endif

#if USE(INSPECTOR_SOCKET_SERVER)
Optional<ConnectionID> m_server;
#endif
};

} // namespace WebDriver
@@ -0,0 +1,24 @@
set(WebDriver_OUTPUT_NAME WebDriver)

list(APPEND WebDriver_SOURCES
playstation/WebDriverServicePlayStation.cpp

socket/CapabilitiesSocket.cpp
socket/HTTPParser.cpp
socket/HTTPServerSocket.cpp
socket/SessionHostSocket.cpp
)

list(APPEND WebDriver_PRIVATE_INCLUDE_DIRECTORIES
"${WEBDRIVER_DIR}/socket"
)

list(APPEND WebDriver_PRIVATE_LIBRARIES
WebKit::JavaScriptCore
)

if (ENABLE_STATIC_JSC)
list(APPEND WebDriver_PRIVATE_LIBRARIES
$<TARGET_OBJECTS:JavaScriptCore>
)
endif ()
@@ -1,8 +1,26 @@
set(WebDriver_Process_OUTPUT_NAME WebKitWebDriver)
set(wrapper_DEFINITIONS USE_CONSOLE_ENTRY_POINT WIN_CAIRO)

set(WebDriver_Process_OUTPUT_NAME WebViewDriver)

list(APPEND WebDriver_SOURCES
socket/CapabilitiesSocket.cpp
socket/HTTPParser.cpp
socket/HTTPServerSocket.cpp
socket/SessionHostSocket.cpp

win/WebDriverServiceWin.cpp
)

list(APPEND WebDriver_PRIVATE_INCLUDE_DIRECTORIES
"${WEBDRIVER_DIR}/socket"
)

list(APPEND WebDriver_LIBRARIES
WebKit::JavaScriptCore
)

WEBKIT_WRAP_EXECUTABLE(WebDriver
SOURCES "${JAVASCRIPTCORE_DIR}/shell/DLLLauncherMain.cpp"
LIBRARIES shlwapi
)
target_compile_definitions(WebDriver PRIVATE ${wrapper_DEFINITIONS})

0 comments on commit 687d6ee

Please sign in to comment.