diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-04-11 10:54:11 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-11 18:24:34 +0200 |
commit | 1ef48d50ff9b6adeb13186799555ff11d6c7af9d (patch) | |
tree | d1b3c9e66976d592b46527a44605fa1d8cb9db09 /Userland/Libraries | |
parent | e54837add5e260e2546a1a43966607b2ef039816 (diff) | |
download | serenity-1ef48d50ff9b6adeb13186799555ff11d6c7af9d.zip |
LibWeb+WebContent: Hook document.cookie to the backend cookie storage
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/InProcessWebView.cpp | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/InProcessWebView.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/OutOfProcessWebView.cpp | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/OutOfProcessWebView.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Page/Page.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/WebContentClient.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/WebContentClient.h | 2 |
9 files changed, 52 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index b1f5348c6f..68cf4fed8d 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 4227ed10c5..f3fa83b674 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 758f9a47a4..4c2b49bdf8 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 7b20928bbf..f718c63690 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 f417e7814c..09b49014d6 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<WebContentClient>, const URL& url) +{ + if (on_get_cookie) + return on_get_cookie(url); + return {}; +} + +void OutOfProcessWebView::notify_server_did_set_cookie(Badge<WebContentClient>, 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 d9918a8ad7..5c603b6a6d 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<WebContentClient>, const URL& url); + void notify_server_did_set_cookie(Badge<WebContentClient>, 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 6dfe853013..c831efddaa 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 aac858b3d7..d7e95be831 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<Messages::WebContentClient::DidRequestCookieResponse> WebContentClient::handle(const Messages::WebContentClient::DidRequestCookie& message) +{ + auto result = m_view.notify_server_did_request_cookie({}, message.url()); + return make<Messages::WebContentClient::DidRequestCookieResponse>(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 a519734148..54e4a34dbc 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.h +++ b/Userland/Libraries/LibWeb/WebContentClient.h @@ -75,6 +75,8 @@ private: virtual OwnPtr<Messages::WebContentClient::DidRequestAlertResponse> handle(const Messages::WebContentClient::DidRequestAlert&) override; virtual OwnPtr<Messages::WebContentClient::DidRequestConfirmResponse> handle(const Messages::WebContentClient::DidRequestConfirm&) override; virtual OwnPtr<Messages::WebContentClient::DidRequestPromptResponse> handle(const Messages::WebContentClient::DidRequestPrompt&) override; + virtual OwnPtr<Messages::WebContentClient::DidRequestCookieResponse> handle(const Messages::WebContentClient::DidRequestCookie&) override; + virtual void handle(const Messages::WebContentClient::DidSetCookie&) override; OutOfProcessWebView& m_view; }; |