diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index b1f5348c6fb35a8b1f56a594ec81615065a379bd..68cf4fed8d3d0d77ed91fb0a116f6a3da511af10 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -825,15 +825,17 @@ void Document::completely_finish_loading() dispatch_event(DOM::Event::create(HTML::EventNames::load)); } -String Document::cookie() const +String Document::cookie() { - // FIXME: Support cookies! + if (auto* page = this->page()) + return page->client().page_did_request_cookie(m_url); return {}; } -void Document::set_cookie(String) +void Document::set_cookie(String cookie) { - // FIXME: Support cookies! + if (auto* page = this->page()) + page->client().page_did_set_cookie(m_url, cookie); } } diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 4227ed10c5a3780947e5437b4e4b017cdd225392..f3fa83b674249cfcc2c4265883de3db823a6ab1f 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -73,7 +73,7 @@ public: virtual ~Document() override; - String cookie() const; + String cookie(); void set_cookie(String); bool should_invalidate_styles_on_attribute_changes() const { return m_should_invalidate_styles_on_attribute_changes; } diff --git a/Userland/Libraries/LibWeb/InProcessWebView.cpp b/Userland/Libraries/LibWeb/InProcessWebView.cpp index 758f9a47a440df6b09b809468bf29591c8b64068..4c2b49bdf8d80534d6ce30cd49cd52de4c514bbb 100644 --- a/Userland/Libraries/LibWeb/InProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/InProcessWebView.cpp @@ -433,4 +433,17 @@ String InProcessWebView::page_did_request_prompt(const String& message, const St return {}; } +String InProcessWebView::page_did_request_cookie(const URL& url) +{ + if (on_get_cookie) + return on_get_cookie(url); + return {}; +} + +void InProcessWebView::page_did_set_cookie(const URL& url, const String& cookie) +{ + if (on_set_cookie) + on_set_cookie(url, cookie); +} + } diff --git a/Userland/Libraries/LibWeb/InProcessWebView.h b/Userland/Libraries/LibWeb/InProcessWebView.h index 7b20928bbf1b8ee7b529332bfcc105f5697112ca..f718c636905df0b980bbb7ea19b988d181ea6512 100644 --- a/Userland/Libraries/LibWeb/InProcessWebView.h +++ b/Userland/Libraries/LibWeb/InProcessWebView.h @@ -111,6 +111,8 @@ private: virtual void page_did_request_alert(const String&) override; virtual bool page_did_request_confirm(const String&) override; virtual String page_did_request_prompt(const String&, const String&) override; + virtual String page_did_request_cookie(const URL&) override; + virtual void page_did_set_cookie(const URL&, const String&) override; void layout_and_sync_size(); diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index f417e7814c512ea8aff025f3d108f668fd1f5d8e..09b49014d62ab05e9edf6cc3ffef36a52450f36e 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -365,6 +365,19 @@ void OutOfProcessWebView::notify_server_did_change_favicon(const Gfx::Bitmap& fa on_favicon_change(favicon); } +String OutOfProcessWebView::notify_server_did_request_cookie(Badge, const URL& url) +{ + if (on_get_cookie) + return on_get_cookie(url); + return {}; +} + +void OutOfProcessWebView::notify_server_did_set_cookie(Badge, const URL& url, const String& cookie) +{ + if (on_set_cookie) + on_set_cookie(url, cookie); +} + void OutOfProcessWebView::did_scroll() { client().post_message(Messages::WebContentServer::SetViewportRect(visible_content_rect())); diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h index d9918a8ad7922dd62399b5fd2f3231346481ec46..5c603b6a6df30974366035af8eceb9e57fafd9b5 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h @@ -79,6 +79,8 @@ public: void notify_server_did_get_source(const URL& url, const String& source); void notify_server_did_js_console_output(const String& method, const String& line); void notify_server_did_change_favicon(const Gfx::Bitmap& favicon); + String notify_server_did_request_cookie(Badge, const URL& url); + void notify_server_did_set_cookie(Badge, const URL& url, const String& cookie); private: OutOfProcessWebView(); diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index 6dfe853013875fa2395951e7ea196612c38ff107..c831efddaab2cf3c7c0af2f102306ba70f5c5b49 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -111,6 +111,8 @@ public: virtual void page_did_request_alert(const String&) { } virtual bool page_did_request_confirm(const String&) { return false; } virtual String page_did_request_prompt(const String&, const String&) { return {}; } + virtual String page_did_request_cookie(const URL&) { return {}; } + virtual void page_did_set_cookie(const URL&, const String&) { } }; } diff --git a/Userland/Libraries/LibWeb/WebContentClient.cpp b/Userland/Libraries/LibWeb/WebContentClient.cpp index aac858b3d7fd91251621f25309bd913b002cc60e..d7e95be8312f5036ae1b21de6f8dc81ab7150daa 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.cpp +++ b/Userland/Libraries/LibWeb/WebContentClient.cpp @@ -197,4 +197,15 @@ void WebContentClient::handle(const Messages::WebContentClient::DidChangeFavicon m_view.notify_server_did_change_favicon(*message.favicon().bitmap()); } +OwnPtr WebContentClient::handle(const Messages::WebContentClient::DidRequestCookie& message) +{ + auto result = m_view.notify_server_did_request_cookie({}, message.url()); + return make(result); +} + +void WebContentClient::handle(const Messages::WebContentClient::DidSetCookie& message) +{ + m_view.notify_server_did_set_cookie({}, message.url(), message.cookie()); +} + } diff --git a/Userland/Libraries/LibWeb/WebContentClient.h b/Userland/Libraries/LibWeb/WebContentClient.h index a519734148cb6cae8aa745851dc13aa0b07bc711..54e4a34dbc6acea0e1bf6842db051852dbe7ea0c 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.h +++ b/Userland/Libraries/LibWeb/WebContentClient.h @@ -75,6 +75,8 @@ private: virtual OwnPtr handle(const Messages::WebContentClient::DidRequestAlert&) override; virtual OwnPtr handle(const Messages::WebContentClient::DidRequestConfirm&) override; virtual OwnPtr handle(const Messages::WebContentClient::DidRequestPrompt&) override; + virtual OwnPtr handle(const Messages::WebContentClient::DidRequestCookie&) override; + virtual void handle(const Messages::WebContentClient::DidSetCookie&) override; OutOfProcessWebView& m_view; }; diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index e67ba3d366a372f3b2675b0b8b862c429a624ca8..c470295a134fb0c1ebe5cb0e1836ec4db4daff5c 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -208,4 +208,14 @@ void PageHost::page_did_request_image_context_menu(const Gfx::IntPoint& content_ m_client.post_message(Messages::WebContentClient::DidRequestImageContextMenu(content_position, url, target, modifiers, bitmap->to_shareable_bitmap())); } +String PageHost::page_did_request_cookie(const URL& url) +{ + return m_client.send_sync(url)->cookie(); +} + +void PageHost::page_did_set_cookie(const URL& url, const String& cookie) +{ + m_client.post_message(Messages::WebContentClient::DidSetCookie(url, cookie)); +} + } diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h index 38c74744b82a81de43dfa1caa913e29930fa9504..aaa41b61be5706e5854fcb9c691c15453ed184ab 100644 --- a/Userland/Services/WebContent/PageHost.h +++ b/Userland/Services/WebContent/PageHost.h @@ -79,6 +79,8 @@ private: virtual String page_did_request_prompt(const String&, const String&) override; virtual void page_did_change_favicon(const Gfx::Bitmap&) override; virtual void page_did_request_image_context_menu(const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers, const Gfx::Bitmap*) override; + virtual String page_did_request_cookie(const URL&) override; + virtual void page_did_set_cookie(const URL&, const String&) override; explicit PageHost(ClientConnection&); diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index b78a88bef91ccb6234f83b20500ff0681f99847d..c9b7bfc6cf63b4dc08dfa9c5fbccca55ecd59c2e 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -25,4 +25,6 @@ endpoint WebContentClient = 90 DidGetSource(URL url, String source) =| DidJSConsoleOutput(String method, String line) =| DidChangeFavicon(Gfx::ShareableBitmap favicon) =| + DidRequestCookie(URL url) => (String cookie) + DidSetCookie(URL url, String cookie) =| }