diff options
-rw-r--r-- | Userland/Applications/Browser/CookieJar.cpp | 27 | ||||
-rw-r--r-- | Userland/Applications/Browser/CookieJar.h | 1 | ||||
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 4 | ||||
-rw-r--r-- | Userland/Applications/Browser/Tab.h | 1 | ||||
-rw-r--r-- | Userland/Applications/Browser/main.cpp | 4 |
5 files changed, 37 insertions, 0 deletions
diff --git a/Userland/Applications/Browser/CookieJar.cpp b/Userland/Applications/Browser/CookieJar.cpp index 82bd2880d7..be7fbcdae1 100644 --- a/Userland/Applications/Browser/CookieJar.cpp +++ b/Userland/Applications/Browser/CookieJar.cpp @@ -27,6 +27,7 @@ #include "CookieJar.h" #include <AK/AllOf.h> #include <AK/NumericLimits.h> +#include <AK/StringBuilder.h> #include <AK/URL.h> #include <ctype.h> @@ -77,6 +78,32 @@ void CookieJar::set_cookie(const URL& url, const String& cookie_string) it->value.append(move(*new_cookie)); } +void CookieJar::dump_cookies() const +{ + static const char* url_color = "\033[34;1m"; + static const char* cookie_color = "\033[31m"; + static const char* attribute_color = "\033[33m"; + static const char* no_color = "\033[0m"; + + StringBuilder builder; + builder.appendff("{} URLs with cookies\n", m_cookies.size()); + + for (const auto& url_and_cookies : m_cookies) { + builder.appendff("{}Cookies for:{} {}\n", url_color, no_color, url_and_cookies.key.is_empty() ? "file://" : url_and_cookies.key); + + for (const auto& cookie : url_and_cookies.value) { + builder.appendff("\t{}{}{} = {}{}{}\n", cookie_color, cookie.name, no_color, cookie_color, cookie.value, no_color); + builder.appendff("\t\t{}Expiry{} = {}\n", attribute_color, no_color, cookie.expiry_time.to_string()); + builder.appendff("\t\t{}Domain{} = {}\n", attribute_color, no_color, cookie.domain); + builder.appendff("\t\t{}Path{} = {}\n", attribute_color, no_color, cookie.path); + builder.appendff("\t\t{}Secure{} = {:s}\n", attribute_color, no_color, cookie.secure); + builder.appendff("\t\t{}HttpOnly{} = {:s}\n", attribute_color, no_color, cookie.http_only); + } + } + + dbgln("{}", builder.build()); +} + Optional<String> CookieJar::canonicalize_domain(const URL& url) { // https://tools.ietf.org/html/rfc6265#section-5.1.2 diff --git a/Userland/Applications/Browser/CookieJar.h b/Userland/Applications/Browser/CookieJar.h index fe2e796e5a..6380b6d4f9 100644 --- a/Userland/Applications/Browser/CookieJar.h +++ b/Userland/Applications/Browser/CookieJar.h @@ -48,6 +48,7 @@ class CookieJar { public: String get_cookie(const URL& url) const; void set_cookie(const URL& url, const String& cookie); + void dump_cookies() const; private: static Optional<String> canonicalize_domain(const URL& url); diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index f3f924083f..a24a19a37a 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -440,6 +440,10 @@ Tab::Tab(Type type) debug_menu.add_action(GUI::Action::create("Dump &History", { Mod_Ctrl, Key_H }, [&](auto&) { m_history.dump(); })); + debug_menu.add_action(GUI::Action::create("Dump C&ookies", [&](auto&) { + if (on_dump_cookies) + on_dump_cookies(); + })); debug_menu.add_separator(); auto line_box_borders_action = GUI::Action::create_checkable( "&Line Box Borders", [this](auto& action) { diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index b880eff5f7..8a2c008686 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -72,6 +72,7 @@ public: 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; + Function<void()> on_dump_cookies; const String& title() const { return m_title; } const Gfx::Bitmap* icon() const { return m_icon; } diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index ad28fce092..0d995bf9ca 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -227,6 +227,10 @@ int main(int argc, char** argv) cookie_jar.set_cookie(url, cookie); }; + new_tab.on_dump_cookies = [&]() { + cookie_jar.dump_cookies(); + }; + new_tab.load(url); dbgln("Added new tab {:p}, loading {}", &new_tab, url); |