Browser+LibWeb+WebContent: Add ability to inspect session storage

This commit is contained in:
Rafał Babiarz 2022-05-07 22:45:43 +02:00 committed by Linus Groh
parent 1ffba0b8b4
commit b162b7eec6
Notes: sideshowbarker 2024-07-17 10:36:38 +09:00
14 changed files with 97 additions and 15 deletions

View file

@ -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);

View file

@ -23,7 +23,7 @@ set(SOURCES
History.cpp
IconBag.cpp
InspectorWidget.cpp
LocalStorageModel.cpp
StorageModel.cpp
StorageWidget.cpp
StorageWidgetGML.h
Tab.cpp

View file

@ -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())

View file

@ -10,7 +10,7 @@
namespace Browser {
class LocalStorageModel final : public GUI::Model {
class StorageModel final : public GUI::Model {
public:
enum Column {
Key,

View file

@ -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();
}
}

View file

@ -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"
}
}
}
}
}

View file

@ -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;
};
}

View file

@ -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();

View file

@ -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,

View file

@ -495,6 +495,11 @@ OrderedHashMap<String, String> OutOfProcessWebView::get_local_storage_entries()
return client().get_local_storage_entries();
}
OrderedHashMap<String, String> OutOfProcessWebView::get_session_storage_entries()
{
return client().get_session_storage_entries();
}
void OutOfProcessWebView::set_content_filters(Vector<String> filters)
{
client().async_set_content_filters(filters);

View file

@ -53,6 +53,7 @@ public:
String dump_layout_tree();
OrderedHashMap<String, String> get_local_storage_entries();
OrderedHashMap<String, String> get_session_storage_entries();
void set_content_filters(Vector<String>);
void set_proxy_mappings(Vector<String> proxies, HashMap<String, size_t> mappings);

View file

@ -493,4 +493,11 @@ Messages::WebContentServer::GetLocalStorageEntriesResponse ConnectionFromClient:
auto local_storage = document->window().local_storage();
return local_storage->map();
}
Messages::WebContentServer::GetSessionStorageEntriesResponse ConnectionFromClient::get_session_storage_entries()
{
auto* document = page().top_level_browsing_context().active_document();
auto session_storage = document->window().session_storage();
return session_storage->map();
}
}

View file

@ -69,6 +69,7 @@ private:
virtual void js_console_request_messages(i32) override;
virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override;
virtual Messages::WebContentServer::GetSessionStorageEntriesResponse get_session_storage_entries() override;
virtual Messages::WebContentServer::GetSelectedTextResponse get_selected_text() override;
virtual void select_all() override;

View file

@ -49,5 +49,5 @@ endpoint WebContentServer
set_is_scripting_enabled(bool is_scripting_enabled) =|
get_local_storage_entries() => (OrderedHashMap<String,String> entries)
get_session_storage_entries() => (OrderedHashMap<String,String> entries)
}