diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index b1f5348c6fb..68cf4fed8d3 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 4227ed10c5a..f3fa83b6742 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 758f9a47a44..4c2b49bdf8d 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 7b20928bbf1..f718c636905 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 f417e7814c5..09b49014d62 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 d9918a8ad79..5c603b6a6df 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 6dfe8530138..c831efddaab 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 aac858b3d7f..d7e95be8312 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 a519734148c..54e4a34dbc6 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 e67ba3d366a..c470295a134 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 38c74744b82..aaa41b61be5 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 b78a88bef91..c9b7bfc6cf6 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) =| }