mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:17:36 +00:00
Browser+LibWeb: Add hooks for getting and setting cookies
This commit is contained in:
parent
f0cdb2bf50
commit
e54837add5
4 changed files with 26 additions and 0 deletions
|
@ -242,6 +242,17 @@ Tab::Tab(Type type)
|
|||
on_favicon_change(icon);
|
||||
};
|
||||
|
||||
hooks().on_get_cookie = [this](auto& url) -> String {
|
||||
if (on_get_cookie)
|
||||
return on_get_cookie(url);
|
||||
return {};
|
||||
};
|
||||
|
||||
hooks().on_set_cookie = [this](auto& url, auto& cookie) {
|
||||
if (on_set_cookie)
|
||||
on_set_cookie(url, cookie);
|
||||
};
|
||||
|
||||
hooks().on_get_source = [this](auto& url, auto& source) {
|
||||
view_source(url, source);
|
||||
};
|
||||
|
|
|
@ -70,6 +70,8 @@ public:
|
|||
Function<void(const URL&)> on_tab_open_request;
|
||||
Function<void(Tab&)> on_tab_close_request;
|
||||
Function<void(const Gfx::Bitmap&)> on_favicon_change;
|
||||
Function<String(const URL& url)> on_get_cookie;
|
||||
Function<void(const URL& url, const String& cookie)> on_set_cookie;
|
||||
|
||||
const String& title() const { return m_title; }
|
||||
const Gfx::Bitmap* icon() const { return m_icon; }
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "BookmarksBarWidget.h"
|
||||
#include "Browser.h"
|
||||
#include "CookieJar.h"
|
||||
#include "Tab.h"
|
||||
#include "WindowActions.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
|
@ -148,6 +149,8 @@ int main(int argc, char** argv)
|
|||
bool bookmarksbar_enabled = true;
|
||||
auto bookmarks_bar = Browser::BookmarksBarWidget::construct(Browser::bookmarks_file_path(), bookmarksbar_enabled);
|
||||
|
||||
Browser::CookieJar cookie_jar;
|
||||
|
||||
auto window = GUI::Window::construct();
|
||||
window->resize(640, 480);
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
@ -216,6 +219,14 @@ int main(int argc, char** argv)
|
|||
});
|
||||
};
|
||||
|
||||
new_tab.on_get_cookie = [&](auto& url) -> String {
|
||||
return cookie_jar.get_cookie(url);
|
||||
};
|
||||
|
||||
new_tab.on_set_cookie = [&](auto& url, auto& cookie) {
|
||||
cookie_jar.set_cookie(url, cookie);
|
||||
};
|
||||
|
||||
new_tab.load(url);
|
||||
|
||||
dbgln("Added new tab {:p}, loading {}", &new_tab, url);
|
||||
|
|
|
@ -48,6 +48,8 @@ public:
|
|||
Function<void(DOM::Document*)> on_set_document;
|
||||
Function<void(const URL&, const String&)> on_get_source;
|
||||
Function<void(const String& method, const String& line)> on_js_console_output;
|
||||
Function<String(const URL& url)> on_get_cookie;
|
||||
Function<void(const URL& url, const String& cookie)> on_set_cookie;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue