diff options
author | Rafał Babiarz <5783815+Sauler@users.noreply.github.com> | 2022-05-07 22:45:43 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-28 23:54:06 +0100 |
commit | b162b7eec68c1b75ded1923fcd2be968183447e3 (patch) | |
tree | ab8d61dc6b1e49203ddbd289cc024e302da8e9b8 /Userland/Applications/Browser | |
parent | 1ffba0b8b4aa26c28288f9191782523c7e9b7017 (diff) | |
download | serenity-b162b7eec68c1b75ded1923fcd2be968183447e3.zip |
Browser+LibWeb+WebContent: Add ability to inspect session storage
Diffstat (limited to 'Userland/Applications/Browser')
-rw-r--r-- | Userland/Applications/Browser/BrowserWindow.cpp | 4 | ||||
-rw-r--r-- | Userland/Applications/Browser/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Applications/Browser/StorageModel.cpp (renamed from Userland/Applications/Browser/LocalStorageModel.cpp) | 16 | ||||
-rw-r--r-- | Userland/Applications/Browser/StorageModel.h (renamed from Userland/Applications/Browser/LocalStorageModel.h) | 2 | ||||
-rw-r--r-- | Userland/Applications/Browser/StorageWidget.cpp | 31 | ||||
-rw-r--r-- | Userland/Applications/Browser/StorageWidget.gml | 22 | ||||
-rw-r--r-- | Userland/Applications/Browser/StorageWidget.h | 12 | ||||
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 6 | ||||
-rw-r--r-- | Userland/Applications/Browser/Tab.h | 1 |
9 files changed, 82 insertions, 14 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 8f66fef667..f07ab53d1b 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -566,6 +566,10 @@ void BrowserWindow::create_new_tab(URL url, bool activate) return active_tab().view().get_local_storage_entries(); }; + new_tab.on_get_session_storage_entries = [this]() { + return active_tab().view().get_session_storage_entries(); + }; + new_tab.load(url); dbgln_if(SPAM_DEBUG, "Added new tab {:p}, loading {}", &new_tab, url); diff --git a/Userland/Applications/Browser/CMakeLists.txt b/Userland/Applications/Browser/CMakeLists.txt index b4d2b20df9..73a2f8560b 100644 --- a/Userland/Applications/Browser/CMakeLists.txt +++ b/Userland/Applications/Browser/CMakeLists.txt @@ -23,7 +23,7 @@ set(SOURCES History.cpp IconBag.cpp InspectorWidget.cpp - LocalStorageModel.cpp + StorageModel.cpp StorageWidget.cpp StorageWidgetGML.h Tab.cpp diff --git a/Userland/Applications/Browser/LocalStorageModel.cpp b/Userland/Applications/Browser/StorageModel.cpp index 8f199a0767..490960118f 100644 --- a/Userland/Applications/Browser/LocalStorageModel.cpp +++ b/Userland/Applications/Browser/StorageModel.cpp @@ -4,13 +4,13 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "LocalStorageModel.h" +#include "StorageModel.h" #include <AK/FuzzyMatch.h> namespace Browser { -void LocalStorageModel::set_items(OrderedHashMap<String, String> map) +void StorageModel::set_items(OrderedHashMap<String, String> map) { begin_insert_rows({}, m_local_storage_entries.size(), m_local_storage_entries.size()); m_local_storage_entries = map; @@ -19,7 +19,7 @@ void LocalStorageModel::set_items(OrderedHashMap<String, String> map) did_update(DontInvalidateIndices); } -void LocalStorageModel::clear_items() +void StorageModel::clear_items() { begin_insert_rows({}, m_local_storage_entries.size(), m_local_storage_entries.size()); m_local_storage_entries.clear(); @@ -28,14 +28,14 @@ void LocalStorageModel::clear_items() did_update(DontInvalidateIndices); } -int LocalStorageModel::row_count(GUI::ModelIndex const& index) const +int StorageModel::row_count(GUI::ModelIndex const& index) const { if (!index.is_valid()) return m_local_storage_entries.size(); return 0; } -String LocalStorageModel::column_name(int column) const +String StorageModel::column_name(int column) const { switch (column) { case Column::Key: @@ -49,14 +49,14 @@ String LocalStorageModel::column_name(int column) const return {}; } -GUI::ModelIndex LocalStorageModel::index(int row, int column, GUI::ModelIndex const&) const +GUI::ModelIndex StorageModel::index(int row, int column, GUI::ModelIndex const&) const { if (static_cast<size_t>(row) < m_local_storage_entries.size()) return create_index(row, column, NULL); return {}; } -GUI::Variant LocalStorageModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const +GUI::Variant StorageModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const { if (role != GUI::ModelRole::Display) return {}; @@ -75,7 +75,7 @@ GUI::Variant LocalStorageModel::data(GUI::ModelIndex const& index, GUI::ModelRol VERIFY_NOT_REACHED(); } -TriState LocalStorageModel::data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const +TriState StorageModel::data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const { auto needle = term.as_string(); if (needle.is_empty()) diff --git a/Userland/Applications/Browser/LocalStorageModel.h b/Userland/Applications/Browser/StorageModel.h index 12870f4b28..f4d9ee592d 100644 --- a/Userland/Applications/Browser/LocalStorageModel.h +++ b/Userland/Applications/Browser/StorageModel.h @@ -10,7 +10,7 @@ namespace Browser { -class LocalStorageModel final : public GUI::Model { +class StorageModel final : public GUI::Model { public: enum Column { Key, diff --git a/Userland/Applications/Browser/StorageWidget.cpp b/Userland/Applications/Browser/StorageWidget.cpp index 4d1799de6a..56991ba06d 100644 --- a/Userland/Applications/Browser/StorageWidget.cpp +++ b/Userland/Applications/Browser/StorageWidget.cpp @@ -6,7 +6,7 @@ #include "StorageWidget.h" #include "CookiesModel.h" -#include "LocalStorageModel.h" +#include "StorageModel.h" #include <AK/Variant.h> #include <Applications/Browser/StorageWidgetGML.h> #include <LibGUI/TabWidget.h> @@ -39,7 +39,7 @@ StorageWidget::StorageWidget() 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 LocalStorageModel()); + m_local_storage_model = adopt_ref(*new StorageModel()); m_local_storage_filtering_model = MUST(GUI::FilteringProxyModel::create(*m_local_storage_model)); m_local_storage_filtering_model->set_filter_term(""); @@ -53,6 +53,23 @@ StorageWidget::StorageWidget() m_local_storage_table_view->set_model(m_local_storage_filtering_model); m_local_storage_table_view->set_column_headers_visible(true); m_local_storage_table_view->set_alternating_row_colors(true); + + m_session_storage_table_view = tab_widget.find_descendant_of_type_named<GUI::TableView>("session_storage_tableview"); + m_session_storage_textbox = tab_widget.find_descendant_of_type_named<GUI::TextBox>("session_storage_filter_textbox"); + m_session_storage_model = adopt_ref(*new StorageModel()); + + m_session_storage_filtering_model = MUST(GUI::FilteringProxyModel::create(*m_session_storage_model)); + m_session_storage_filtering_model->set_filter_term(""); + + m_session_storage_textbox->on_change = [this] { + m_session_storage_filtering_model->set_filter_term(m_session_storage_textbox->text()); + if (m_session_storage_filtering_model->row_count() != 0) + m_session_storage_table_view->set_cursor(m_session_storage_filtering_model->index(0, 0), GUI::AbstractView::SelectionUpdate::Set); + }; + + m_session_storage_table_view->set_model(m_session_storage_filtering_model); + m_session_storage_table_view->set_column_headers_visible(true); + m_session_storage_table_view->set_alternating_row_colors(true); } void StorageWidget::set_cookies_entries(Vector<Web::Cookie::Cookie> entries) @@ -75,4 +92,14 @@ void StorageWidget::clear_local_storage_entries() m_local_storage_model->clear_items(); } +void StorageWidget::set_session_storage_entries(OrderedHashMap<String, String> entries) +{ + m_session_storage_model->set_items(entries); +} + +void StorageWidget::clear_session_storage_entries() +{ + m_session_storage_model->clear_items(); +} + } diff --git a/Userland/Applications/Browser/StorageWidget.gml b/Userland/Applications/Browser/StorageWidget.gml index cb76eeb647..e201499e4c 100644 --- a/Userland/Applications/Browser/StorageWidget.gml +++ b/Userland/Applications/Browser/StorageWidget.gml @@ -50,5 +50,27 @@ } } } + + @GUI::Widget { + title: "Session Storage" + layout: @GUI::VerticalBoxLayout { + margins: [4] + } + + @GUI::TextBox { + name: "session_storage_filter_textbox" + placeholder: "Filter" + } + + @GUI::GroupBox { + layout: @GUI::VerticalBoxLayout { + margins: [6] + } + + @GUI::TableView { + name: "session_storage_tableview" + } + } + } } } diff --git a/Userland/Applications/Browser/StorageWidget.h b/Userland/Applications/Browser/StorageWidget.h index 69397aa0d3..cfde2c7295 100644 --- a/Userland/Applications/Browser/StorageWidget.h +++ b/Userland/Applications/Browser/StorageWidget.h @@ -7,7 +7,7 @@ #pragma once #include "CookiesModel.h" -#include "LocalStorageModel.h" +#include "StorageModel.h" #include "Tab.h" #include <LibGUI/FilteringProxyModel.h> #include <LibGUI/TextBox.h> @@ -27,6 +27,9 @@ public: void set_local_storage_entries(OrderedHashMap<String, String> entries); void clear_local_storage_entries(); + void set_session_storage_entries(OrderedHashMap<String, String> entries); + void clear_session_storage_entries(); + private: StorageWidget(); @@ -37,8 +40,13 @@ private: RefPtr<GUI::TableView> m_local_storage_table_view; RefPtr<GUI::TextBox> m_local_storage_textbox; - RefPtr<LocalStorageModel> m_local_storage_model; + RefPtr<StorageModel> m_local_storage_model; RefPtr<GUI::FilteringProxyModel> m_local_storage_filtering_model; + + RefPtr<GUI::TableView> m_session_storage_table_view; + RefPtr<GUI::TextBox> m_session_storage_textbox; + RefPtr<StorageModel> m_session_storage_model; + RefPtr<GUI::FilteringProxyModel> m_session_storage_filtering_model; }; } diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 07355893f4..e17915f640 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -615,6 +615,12 @@ void Tab::show_storage_inspector() m_storage_widget->set_local_storage_entries(local_storage_entries); } + if (on_get_session_storage_entries) { + auto session_storage_entries = on_get_session_storage_entries(); + m_storage_widget->clear_session_storage_entries(); + m_storage_widget->set_session_storage_entries(session_storage_entries); + } + auto* window = m_storage_widget->window(); window->show(); window->move_to_front(); diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index 3a93437b33..1a49c08a34 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -66,6 +66,7 @@ public: Function<void()> on_dump_cookies; Function<Vector<Web::Cookie::Cookie>()> on_get_cookies_entries; Function<OrderedHashMap<String, String>()> on_get_local_storage_entries; + Function<OrderedHashMap<String, String>()> on_get_session_storage_entries; enum class InspectorTarget { Document, |