/* * Copyright (C) 2017 Igalia S.L. * * 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 #include "HTTPServer.h" #include "Session.h" #include #include #include #include namespace WebDriver { struct Capabilities; class CommandResult; class Session; class WebDriverService final : public HTTPRequestHandler { public: WebDriverService(); ~WebDriverService() = default; int run(int argc, char** argv); static void platformInit(); static bool platformCompareBrowserVersions(const String&, const String&); private: enum class HTTPMethod { Get, Post, Delete }; typedef void (WebDriverService::*CommandHandler)(RefPtr&&, Function&&); struct Command { HTTPMethod method; const char* uriTemplate; CommandHandler handler; }; static const Command s_commands[]; static std::optional toCommandHTTPMethod(const String& method); static bool findCommand(HTTPMethod, const String& path, CommandHandler*, HashMap& parameters); void newSession(RefPtr&&, Function&&); void deleteSession(RefPtr&&, Function&&); void status(RefPtr&&, Function&&); void getTimeouts(RefPtr&&, Function&&); void setTimeouts(RefPtr&&, Function&&); void go(RefPtr&&, Function&&); void getCurrentURL(RefPtr&&, Function&&); void back(RefPtr&&, Function&&); void forward(RefPtr&&, Function&&); void refresh(RefPtr&&, Function&&); void getTitle(RefPtr&&, Function&&); void getWindowHandle(RefPtr&&, Function&&); void closeWindow(RefPtr&&, Function&&); void switchToWindow(RefPtr&&, Function&&); void getWindowHandles(RefPtr&&, Function&&); void newWindow(RefPtr&&, Function&&); void switchToFrame(RefPtr&&, Function&&); void switchToParentFrame(RefPtr&&, Function&&); void getWindowRect(RefPtr&&, Function&&); void setWindowRect(RefPtr&&, Function&&); void maximizeWindow(RefPtr&&, Function&&); void minimizeWindow(RefPtr&&, Function&&); void fullscreenWindow(RefPtr&&, Function&&); void findElement(RefPtr&&, Function&&); void findElements(RefPtr&&, Function&&); void findElementFromElement(RefPtr&&, Function&&); void findElementsFromElement(RefPtr&&, Function&&); void getActiveElement(RefPtr&&, Function&&); void isElementSelected(RefPtr&&, Function&&); void getElementAttribute(RefPtr&&, Function&&); void getElementProperty(RefPtr&&, Function&&); void getElementCSSValue(RefPtr&&, Function&&); void getElementText(RefPtr&&, Function&&); void getElementTagName(RefPtr&&, Function&&); void getElementRect(RefPtr&&, Function&&); void isElementEnabled(RefPtr&&, Function&&); void isElementDisplayed(RefPtr&&, Function&&); void elementClick(RefPtr&&, Function&&); void elementClear(RefPtr&&, Function&&); void elementSendKeys(RefPtr&&, Function&&); void getPageSource(RefPtr&&, Function&&); void executeScript(RefPtr&&, Function&&); void executeAsyncScript(RefPtr&&, Function&&); void getAllCookies(RefPtr&&, Function&&); void getNamedCookie(RefPtr&&, Function&&); void addCookie(RefPtr&&, Function&&); void deleteCookie(RefPtr&&, Function&&); void deleteAllCookies(RefPtr&&, Function&&); void performActions(RefPtr&&, Function&&); void releaseActions(RefPtr&&, Function&&); void dismissAlert(RefPtr&&, Function&&); void acceptAlert(RefPtr&&, Function&&); void getAlertText(RefPtr&&, Function&&); void sendAlertText(RefPtr&&, Function&&); void takeScreenshot(RefPtr&&, Function&&); void takeElementScreenshot(RefPtr&&, Function&&); static Capabilities platformCapabilities(); Vector processCapabilities(const JSON::Object&, Function&) const; RefPtr validatedCapabilities(const JSON::Object&) const; RefPtr mergeCapabilities(const JSON::Object&, const JSON::Object&) const; RefPtr matchCapabilities(const JSON::Object&) const; bool platformValidateCapability(const String&, const Ref&) const; bool platformMatchCapability(const String&, const Ref&) const; bool platformSupportProxyType(const String&) const; void parseCapabilities(const JSON::Object& desiredCapabilities, Capabilities&) const; void platformParseCapabilities(const JSON::Object& desiredCapabilities, Capabilities&) const; void connectToBrowser(Vector&&, Function&&); void createSession(Vector&&, std::unique_ptr&&, Function&&); bool findSessionOrCompleteWithError(JSON::Object&, Function&); void handleRequest(HTTPRequestHandler::Request&&, Function&& replyHandler) override; void sendResponse(Function&& replyHandler, CommandResult&&) const; HTTPServer m_server; RefPtr m_session; #if USE(INSPECTOR_SOCKET_SERVER) String m_targetAddress; uint16_t m_targetPort { 0 }; #endif }; } // namespace WebDriver