mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
Browser+LibWeb+WebContent: Add ability to inspect local storage
The storage inspector now has a new tab for local storage. The next step would be to persist local storage and receive real-time notifications for changes to update the table view.
This commit is contained in:
parent
f2b4c044db
commit
45a81f5a2c
Notes:
sideshowbarker
2024-07-17 14:33:18 +09:00
Author: https://github.com/vkoskiv
Commit: 45a81f5a2c
Pull-request: https://github.com/SerenityOS/serenity/pull/13421
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/linusg
14 changed files with 168 additions and 4 deletions
69
Userland/Applications/Browser/LocalStorageModel.cpp
Normal file
69
Userland/Applications/Browser/LocalStorageModel.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Valtteri Koskivuori <vkoskiv@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "LocalStorageModel.h"
|
||||
|
||||
namespace Browser {
|
||||
|
||||
void LocalStorageModel::set_items(OrderedHashMap<String, String> map)
|
||||
{
|
||||
begin_insert_rows({}, m_local_storage_entries.size(), m_local_storage_entries.size());
|
||||
m_local_storage_entries = map;
|
||||
end_insert_rows();
|
||||
|
||||
did_update(DontInvalidateIndices);
|
||||
}
|
||||
|
||||
void LocalStorageModel::clear_items()
|
||||
{
|
||||
begin_insert_rows({}, m_local_storage_entries.size(), m_local_storage_entries.size());
|
||||
m_local_storage_entries.clear();
|
||||
end_insert_rows();
|
||||
|
||||
did_update(DontInvalidateIndices);
|
||||
}
|
||||
|
||||
String LocalStorageModel::column_name(int column) const
|
||||
{
|
||||
switch (column) {
|
||||
case Column::Key:
|
||||
return "Key";
|
||||
case Column::Value:
|
||||
return "Value";
|
||||
case Column::__Count:
|
||||
return {};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
GUI::ModelIndex LocalStorageModel::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
|
||||
{
|
||||
if (role != GUI::ModelRole::Display)
|
||||
return {};
|
||||
|
||||
auto const& keys = m_local_storage_entries.keys();
|
||||
auto const& local_storage_key = keys[index.row()];
|
||||
auto const& local_storage_value = m_local_storage_entries.get(local_storage_key).value_or({});
|
||||
|
||||
switch (index.column()) {
|
||||
case Column::Key:
|
||||
return local_storage_key;
|
||||
case Column::Value:
|
||||
return local_storage_value;
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue