1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "WebDriverConnection.h"
#include "BrowserWindow.h"
#include <AK/Vector.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Cookie/ParsedCookie.h>
namespace Browser {
WebDriverConnection::WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window)
: IPC::ConnectionToServer<WebDriverSessionClientEndpoint, WebDriverSessionServerEndpoint>(*this, move(socket))
, m_browser_window(move(browser_window))
{
}
void WebDriverConnection::quit()
{
dbgln("WebDriverConnection: quit");
if (auto browser_window = m_browser_window.strong_ref())
browser_window->close();
}
Messages::WebDriverSessionClient::GetUrlResponse WebDriverConnection::get_url()
{
dbgln("WebDriverConnection: get_url");
if (auto browser_window = m_browser_window.strong_ref())
return { browser_window->active_tab().url() };
return { URL("") };
}
void WebDriverConnection::set_url(AK::URL const& url)
{
dbgln("WebDriverConnection: set_url {}", url);
if (auto browser_window = m_browser_window.strong_ref())
browser_window->active_tab().load(url);
}
Messages::WebDriverSessionClient::GetTitleResponse WebDriverConnection::get_title()
{
dbgln("WebDriverConnection: get_title");
if (auto browser_window = m_browser_window.strong_ref())
return { browser_window->active_tab().title() };
return { "" };
}
void WebDriverConnection::refresh()
{
dbgln("WebDriverConnection: refresh");
if (auto browser_window = m_browser_window.strong_ref())
browser_window->active_tab().reload();
}
void WebDriverConnection::back()
{
dbgln("WebDriverConnection: back");
if (auto browser_window = m_browser_window.strong_ref())
browser_window->active_tab().go_back();
}
void WebDriverConnection::forward()
{
dbgln("WebDriverConnection: forward");
if (auto browser_window = m_browser_window.strong_ref())
browser_window->active_tab().go_forward();
}
Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies()
{
dbgln("WebDriverConnection: get_cookies");
if (auto browser_window = m_browser_window.strong_ref()) {
if (browser_window->active_tab().on_get_cookies_entries) {
return { browser_window->active_tab().on_get_cookies_entries() };
}
}
return { {} };
}
Messages::WebDriverSessionClient::GetNamedCookieResponse WebDriverConnection::get_named_cookie(String const& name)
{
dbgln("WebDriverConnection: get_named_cookie {}", name);
if (auto browser_window = m_browser_window.strong_ref()) {
if (browser_window->active_tab().on_get_cookies_entries) {
for (auto cookie : browser_window->active_tab().on_get_cookies_entries()) {
if (cookie.name == name)
return { cookie };
}
return Optional<Web::Cookie::Cookie> {};
}
}
return { {} };
}
void WebDriverConnection::add_cookie(Web::Cookie::ParsedCookie const& cookie)
{
dbgln("WebDriverConnection: add_cookie {}", cookie.name);
if (auto browser_window = m_browser_window.strong_ref()) {
auto& tab = browser_window->active_tab();
if (tab.on_set_cookie) {
// FIXME: The spec doesn't say anything about the source
// but can we assume a cookie created through a HTTP-request to the WebDriver
// to be (source) from an HTTP-API?
tab.on_set_cookie(tab.url(), cookie, Web::Cookie::Source::Http);
}
}
}
void WebDriverConnection::update_cookie(Web::Cookie::Cookie const& cookie)
{
dbgln("WebDriverConnection: update_cookie {}", cookie.name);
if (auto browser_window = m_browser_window.strong_ref()) {
auto& tab = browser_window->active_tab();
if (tab.on_update_cookie) {
tab.on_update_cookie(tab.url(), cookie);
}
}
}
Messages::WebDriverSessionClient::GetDocumentElementResponse WebDriverConnection::get_document_element()
{
dbgln("WebDriverConnection: get_document_element");
if (auto browser_window = m_browser_window.strong_ref()) {
auto& tab = browser_window->active_tab();
if (tab.on_get_document_element)
return { tab.on_get_document_element() };
}
return { {} };
}
Messages::WebDriverSessionClient::QuerySelectorAllResponse WebDriverConnection::query_selector_all(i32 start_node_id, String const& selector)
{
dbgln("WebDriverConnection: query_selector_all");
if (auto browser_window = m_browser_window.strong_ref()) {
auto& tab = browser_window->active_tab();
if (tab.on_query_selector_all)
return { tab.on_query_selector_all(start_node_id, selector) };
}
return { {} };
}
}
|