mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
Browser: Add ability to delete cookies from Storage Inspector
Adds actions to delete either a single cookie, or all of them. This looks weird, because the GUI doesn't update until you "Inspect > Open Storage Inspector", but it does function. :^)
This commit is contained in:
parent
c11462f40e
commit
4d9c0c7b22
5 changed files with 53 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -7,8 +8,8 @@
|
|||
#include "StorageWidget.h"
|
||||
#include "CookiesModel.h"
|
||||
#include "StorageModel.h"
|
||||
#include <AK/Variant.h>
|
||||
#include <Applications/Browser/StorageWidgetGML.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/TabWidget.h>
|
||||
#include <LibGUI/TableView.h>
|
||||
#include <LibWeb/Cookie/Cookie.h>
|
||||
|
@ -37,6 +38,32 @@ StorageWidget::StorageWidget()
|
|||
m_cookies_table_view->set_column_headers_visible(true);
|
||||
m_cookies_table_view->set_alternating_row_colors(true);
|
||||
|
||||
auto delete_cookie_action = GUI::Action::create(
|
||||
"&Delete Cookie", { Key_Delete }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto const&) {
|
||||
auto cookie_index = m_cookies_table_view->selection().first();
|
||||
delete_cookie(m_cookies_model->get_cookie(cookie_index));
|
||||
},
|
||||
m_cookies_table_view);
|
||||
|
||||
auto delete_all_cookies_action = GUI::Action::create(
|
||||
"Delete &All Cookies", [&](auto const&) {
|
||||
auto cookie_count = m_cookies_model->row_count({});
|
||||
for (auto i = 0; i < cookie_count; ++i) {
|
||||
auto cookie_index = m_cookies_model->index(i);
|
||||
if (cookie_index.is_valid())
|
||||
delete_cookie(m_cookies_model->get_cookie(cookie_index));
|
||||
}
|
||||
},
|
||||
m_cookies_table_view);
|
||||
|
||||
m_cookies_context_menu = GUI::Menu::construct();
|
||||
m_cookies_context_menu->add_action(delete_cookie_action);
|
||||
m_cookies_context_menu->add_action(delete_all_cookies_action);
|
||||
m_cookies_table_view->on_context_menu_request = [&](auto& index, auto& event) {
|
||||
if (index.is_valid())
|
||||
m_cookies_context_menu->popup(event.screen_position());
|
||||
};
|
||||
|
||||
m_local_storage_table_view = tab_widget.find_descendant_of_type_named<GUI::TableView>("local_storage_tableview");
|
||||
m_local_storage_textbox = tab_widget.find_descendant_of_type_named<GUI::TextBox>("local_storage_filter_textbox");
|
||||
m_local_storage_model = adopt_ref(*new StorageModel());
|
||||
|
@ -102,4 +129,12 @@ void StorageWidget::clear_session_storage_entries()
|
|||
m_session_storage_model->clear_items();
|
||||
}
|
||||
|
||||
void StorageWidget::delete_cookie(Web::Cookie::Cookie cookie)
|
||||
{
|
||||
// Delete cookie by making its expiry time in the past.
|
||||
cookie.expiry_time = Core::DateTime::from_timestamp(0);
|
||||
if (on_update_cookie)
|
||||
on_update_cookie(move(cookie));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue