blob: 5f525fe706ec01e4327789c97d0c8a9e165933b5 [file] [log] [blame]
bburg@apple.com5adb8092016-02-12 19:28:29 +00001/*
2 * Copyright (C) 2016 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef WebAutomationSession_h
27#define WebAutomationSession_h
28
29#include "APIObject.h"
bburg@apple.come17bd1d2016-03-25 18:18:50 +000030#include "AutomationBackendDispatchers.h"
bburg@apple.com5adb8092016-02-12 19:28:29 +000031#include <wtf/Forward.h>
32
33#if ENABLE(REMOTE_INSPECTOR)
34#include <JavaScriptCore/RemoteAutomationTarget.h>
35#endif
36
37namespace API {
38class AutomationSessionClient;
39}
40
bburg@apple.com0160e892016-02-23 07:18:41 +000041namespace Inspector {
42class BackendDispatcher;
43class FrontendRouter;
44}
45
bburg@apple.com5adb8092016-02-12 19:28:29 +000046namespace WebKit {
47
48class WebAutomationSessionClient;
timothy@apple.com74f070b2016-03-06 00:40:09 +000049class WebPageProxy;
50class WebProcessPool;
bburg@apple.com5adb8092016-02-12 19:28:29 +000051
52class WebAutomationSession final : public API::ObjectImpl<API::Object::Type::AutomationSession>
53#if ENABLE(REMOTE_INSPECTOR)
54 , public Inspector::RemoteAutomationTarget
55#endif
bburg@apple.coma9cfd0d2016-02-23 17:40:20 +000056 , public Inspector::AutomationBackendDispatcherHandler
bburg@apple.com5adb8092016-02-12 19:28:29 +000057{
58public:
timothy@apple.com74f070b2016-03-06 00:40:09 +000059 typedef HashMap<uint64_t, String> WebPageHandleMap;
60 typedef HashMap<String, uint64_t> HandleWebPageMap;
61
bburg@apple.com5adb8092016-02-12 19:28:29 +000062 WebAutomationSession();
63 ~WebAutomationSession();
64
65 void setClient(std::unique_ptr<API::AutomationSessionClient>);
66
67 void setSessionIdentifier(const String& sessionIdentifier) { m_sessionIdentifier = sessionIdentifier; }
68 String sessionIdentifier() const { return m_sessionIdentifier; }
69
timothy@apple.com74f070b2016-03-06 00:40:09 +000070 WebKit::WebProcessPool* processPool() const { return m_processPool; }
71 void setProcessPool(WebKit::WebProcessPool* processPool) { m_processPool = processPool; }
72
bburg@apple.com5adb8092016-02-12 19:28:29 +000073#if ENABLE(REMOTE_INSPECTOR)
74 // Inspector::RemoteAutomationTarget API
darin@apple.com11ff47c2016-03-04 16:47:55 +000075 String name() const override { return m_sessionIdentifier; }
76 void dispatchMessageFromRemote(const String& message) override;
77 void connect(Inspector::FrontendChannel*, bool isAutomaticConnection = false) override;
78 void disconnect(Inspector::FrontendChannel*) override;
bburg@apple.com5adb8092016-02-12 19:28:29 +000079#endif
80
bburg@apple.coma9cfd0d2016-02-23 17:40:20 +000081 // Inspector::AutomationBackendDispatcherHandler API
timothy@apple.com4ef6bcf2016-03-06 00:40:01 +000082 void getBrowsingContexts(Inspector::ErrorString&, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>>&) override;
timothy@apple.com3d3df2f2016-03-08 17:55:01 +000083 void getBrowsingContext(Inspector::ErrorString&, const String&, RefPtr<Inspector::Protocol::Automation::BrowsingContext>&) override;
timothy@apple.com4ef6bcf2016-03-06 00:40:01 +000084 void createBrowsingContext(Inspector::ErrorString&, String*) override;
85 void closeBrowsingContext(Inspector::ErrorString&, const String&) override;
86 void switchToBrowsingContext(Inspector::ErrorString&, const String&) override;
timothy@apple.com3d3df2f2016-03-08 17:55:01 +000087 void navigateBrowsingContext(Inspector::ErrorString&, const String& handle, const String& url) override;
88 void goBackInBrowsingContext(Inspector::ErrorString&, const String&) override;
89 void goForwardInBrowsingContext(Inspector::ErrorString&, const String&) override;
90 void reloadBrowsingContext(Inspector::ErrorString&, const String&) override;
bburg@apple.coma9cfd0d2016-02-23 17:40:20 +000091
bburg@apple.com5adb8092016-02-12 19:28:29 +000092private:
timothy@apple.com74f070b2016-03-06 00:40:09 +000093 WebKit::WebPageProxy* webPageProxyForHandle(const String&);
94 String handleForWebPageProxy(WebKit::WebPageProxy*);
95
96 WebKit::WebProcessPool* m_processPool { nullptr };
bburg@apple.com5adb8092016-02-12 19:28:29 +000097 std::unique_ptr<API::AutomationSessionClient> m_client;
98 String m_sessionIdentifier { ASCIILiteral("Untitled Session") };
bburg@apple.com0160e892016-02-23 07:18:41 +000099 Ref<Inspector::FrontendRouter> m_frontendRouter;
100 Ref<Inspector::BackendDispatcher> m_backendDispatcher;
bburg@apple.coma9cfd0d2016-02-23 17:40:20 +0000101 Ref<Inspector::AutomationBackendDispatcher> m_domainDispatcher;
bburg@apple.com5adb8092016-02-12 19:28:29 +0000102
timothy@apple.com74f070b2016-03-06 00:40:09 +0000103 WebPageHandleMap m_webPageHandleMap;
104 HandleWebPageMap m_handleWebPageMap;
105 String m_activeBrowsingContextHandle;
106
bburg@apple.com5adb8092016-02-12 19:28:29 +0000107#if ENABLE(REMOTE_INSPECTOR)
108 Inspector::FrontendChannel* m_remoteChannel { nullptr };
109#endif
110};
111
112} // namespace WebKit
113
114#endif // WebAutomationSession_h