mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 07:44:59 +00:00
LibWeb: Port Storage interface from DeprecatedString to String
Which ends up bubbling all the way up to the Browser storage model.
This commit is contained in:
parent
6f85be501d
commit
901220c588
11 changed files with 39 additions and 35 deletions
|
@ -10,10 +10,10 @@
|
||||||
|
|
||||||
namespace Browser {
|
namespace Browser {
|
||||||
|
|
||||||
void StorageModel::set_items(OrderedHashMap<DeprecatedString, DeprecatedString> map)
|
void StorageModel::set_items(OrderedHashMap<String, String> map)
|
||||||
{
|
{
|
||||||
begin_insert_rows({}, m_local_storage_entries.size(), m_local_storage_entries.size());
|
begin_insert_rows({}, m_local_storage_entries.size(), m_local_storage_entries.size());
|
||||||
m_local_storage_entries = map;
|
m_local_storage_entries = move(map);
|
||||||
end_insert_rows();
|
end_insert_rows();
|
||||||
|
|
||||||
did_update(DontInvalidateIndices);
|
did_update(DontInvalidateIndices);
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
__Count,
|
__Count,
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_items(OrderedHashMap<DeprecatedString, DeprecatedString> map);
|
void set_items(OrderedHashMap<String, String> map);
|
||||||
void clear_items();
|
void clear_items();
|
||||||
virtual int row_count(GUI::ModelIndex const&) const override;
|
virtual int row_count(GUI::ModelIndex const&) const override;
|
||||||
virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; }
|
virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; }
|
||||||
|
@ -28,7 +28,7 @@ public:
|
||||||
virtual GUI::Model::MatchResult data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override;
|
virtual GUI::Model::MatchResult data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OrderedHashMap<DeprecatedString, DeprecatedString> m_local_storage_entries;
|
OrderedHashMap<String, String> m_local_storage_entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ void StorageWidget::clear_cookies()
|
||||||
m_cookies_model->clear_items();
|
m_cookies_model->clear_items();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StorageWidget::set_local_storage_entries(OrderedHashMap<DeprecatedString, DeprecatedString> entries)
|
void StorageWidget::set_local_storage_entries(OrderedHashMap<String, String> entries)
|
||||||
{
|
{
|
||||||
m_local_storage_model->set_items(move(entries));
|
m_local_storage_model->set_items(move(entries));
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ void StorageWidget::clear_local_storage_entries()
|
||||||
m_local_storage_model->clear_items();
|
m_local_storage_model->clear_items();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StorageWidget::set_session_storage_entries(OrderedHashMap<DeprecatedString, DeprecatedString> entries)
|
void StorageWidget::set_session_storage_entries(OrderedHashMap<String, String> entries)
|
||||||
{
|
{
|
||||||
m_session_storage_model->set_items(move(entries));
|
m_session_storage_model->set_items(move(entries));
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,10 @@ public:
|
||||||
|
|
||||||
Function<void(Web::Cookie::Cookie)> on_update_cookie;
|
Function<void(Web::Cookie::Cookie)> on_update_cookie;
|
||||||
|
|
||||||
void set_local_storage_entries(OrderedHashMap<DeprecatedString, DeprecatedString> entries);
|
void set_local_storage_entries(OrderedHashMap<String, String> entries);
|
||||||
void clear_local_storage_entries();
|
void clear_local_storage_entries();
|
||||||
|
|
||||||
void set_session_storage_entries(OrderedHashMap<DeprecatedString, DeprecatedString> entries);
|
void set_session_storage_entries(OrderedHashMap<String, String> entries);
|
||||||
void clear_session_storage_entries();
|
void clear_session_storage_entries();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -76,8 +76,8 @@ public:
|
||||||
Function<void()> on_dump_cookies;
|
Function<void()> on_dump_cookies;
|
||||||
Function<void(Web::Cookie::Cookie)> on_update_cookie;
|
Function<void(Web::Cookie::Cookie)> on_update_cookie;
|
||||||
Function<Vector<Web::Cookie::Cookie>()> on_get_cookies_entries;
|
Function<Vector<Web::Cookie::Cookie>()> on_get_cookies_entries;
|
||||||
Function<OrderedHashMap<DeprecatedString, DeprecatedString>()> on_get_local_storage_entries;
|
Function<OrderedHashMap<String, String>()> on_get_local_storage_entries;
|
||||||
Function<OrderedHashMap<DeprecatedString, DeprecatedString>()> on_get_session_storage_entries;
|
Function<OrderedHashMap<String, String>()> on_get_session_storage_entries;
|
||||||
|
|
||||||
void enable_webdriver_mode();
|
void enable_webdriver_mode();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/String.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
#include <LibWeb/HTML/Storage.h>
|
#include <LibWeb/HTML/Storage.h>
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ size_t Storage::length() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-key
|
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-key
|
||||||
DeprecatedString Storage::key(size_t index)
|
Optional<String> Storage::key(size_t index)
|
||||||
{
|
{
|
||||||
// 1. If index is greater than or equal to this's map's size, then return null.
|
// 1. If index is greater than or equal to this's map's size, then return null.
|
||||||
if (index >= m_map.size())
|
if (index >= m_map.size())
|
||||||
|
@ -51,7 +51,7 @@ DeprecatedString Storage::key(size_t index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-getitem
|
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-getitem
|
||||||
DeprecatedString Storage::get_item(DeprecatedString const& key) const
|
Optional<String> Storage::get_item(StringView key) const
|
||||||
{
|
{
|
||||||
// 1. If this's map[key] does not exist, then return null.
|
// 1. If this's map[key] does not exist, then return null.
|
||||||
auto it = m_map.find(key);
|
auto it = m_map.find(key);
|
||||||
|
@ -63,10 +63,10 @@ DeprecatedString Storage::get_item(DeprecatedString const& key) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-setitem
|
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-setitem
|
||||||
WebIDL::ExceptionOr<void> Storage::set_item(DeprecatedString const& key, DeprecatedString const& value)
|
WebIDL::ExceptionOr<void> Storage::set_item(String const& key, String const& value)
|
||||||
{
|
{
|
||||||
// 1. Let oldValue be null.
|
// 1. Let oldValue be null.
|
||||||
DeprecatedString old_value;
|
String old_value;
|
||||||
|
|
||||||
// 2. Let reorder be true.
|
// 2. Let reorder be true.
|
||||||
bool reorder = true;
|
bool reorder = true;
|
||||||
|
@ -100,7 +100,7 @@ WebIDL::ExceptionOr<void> Storage::set_item(DeprecatedString const& key, Depreca
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-removeitem
|
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-removeitem
|
||||||
void Storage::remove_item(DeprecatedString const& key)
|
void Storage::remove_item(StringView key)
|
||||||
{
|
{
|
||||||
// 1. If this's map[key] does not exist, then return null.
|
// 1. If this's map[key] does not exist, then return null.
|
||||||
// FIXME: Return null?
|
// FIXME: Return null?
|
||||||
|
@ -139,7 +139,7 @@ void Storage::reorder()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webstorage.html#concept-storage-broadcast
|
// https://html.spec.whatwg.org/multipage/webstorage.html#concept-storage-broadcast
|
||||||
void Storage::broadcast(DeprecatedString const& key, DeprecatedString const& old_value, DeprecatedString const& new_value)
|
void Storage::broadcast(StringView key, StringView old_value, StringView new_value)
|
||||||
{
|
{
|
||||||
(void)key;
|
(void)key;
|
||||||
(void)old_value;
|
(void)old_value;
|
||||||
|
@ -150,15 +150,19 @@ void Storage::broadcast(DeprecatedString const& key, DeprecatedString const& old
|
||||||
Vector<DeprecatedString> Storage::supported_property_names() const
|
Vector<DeprecatedString> Storage::supported_property_names() const
|
||||||
{
|
{
|
||||||
// The supported property names on a Storage object storage are the result of running get the keys on storage's map.
|
// The supported property names on a Storage object storage are the result of running get the keys on storage's map.
|
||||||
return m_map.keys();
|
Vector<DeprecatedString> names;
|
||||||
|
names.ensure_capacity(m_map.size());
|
||||||
|
for (auto const& key : m_map.keys())
|
||||||
|
names.unchecked_append(key.to_deprecated_string());
|
||||||
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebIDL::ExceptionOr<JS::Value> Storage::named_item_value(DeprecatedFlyString const& name) const
|
WebIDL::ExceptionOr<JS::Value> Storage::named_item_value(DeprecatedFlyString const& name) const
|
||||||
{
|
{
|
||||||
auto value = get_item(name);
|
auto value = get_item(name);
|
||||||
if (value.is_null())
|
if (!value.has_value())
|
||||||
return JS::js_null();
|
return JS::js_null();
|
||||||
return JS::PrimitiveString::create(vm(), value);
|
return JS::PrimitiveString::create(vm(), value.release_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
WebIDL::ExceptionOr<Bindings::LegacyPlatformObject::DidDeletionFail> Storage::delete_value(DeprecatedString const& name)
|
WebIDL::ExceptionOr<Bindings::LegacyPlatformObject::DidDeletionFail> Storage::delete_value(DeprecatedString const& name)
|
||||||
|
@ -171,8 +175,8 @@ WebIDL::ExceptionOr<void> Storage::set_value_of_named_property(DeprecatedString
|
||||||
{
|
{
|
||||||
// NOTE: Since LegacyPlatformObject does not know the type of value, we must convert it ourselves.
|
// NOTE: Since LegacyPlatformObject does not know the type of value, we must convert it ourselves.
|
||||||
// The type of `value` is `DOMString`.
|
// The type of `value` is `DOMString`.
|
||||||
auto value = TRY(unconverted_value.to_deprecated_string(vm()));
|
auto value = TRY(unconverted_value.to_string(vm()));
|
||||||
return set_item(key, value);
|
return set_item(String::from_deprecated_string(key).release_value(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Storage::dump() const
|
void Storage::dump() const
|
||||||
|
|
|
@ -21,10 +21,10 @@ public:
|
||||||
~Storage();
|
~Storage();
|
||||||
|
|
||||||
size_t length() const;
|
size_t length() const;
|
||||||
DeprecatedString key(size_t index);
|
Optional<String> key(size_t index);
|
||||||
DeprecatedString get_item(DeprecatedString const& key) const;
|
Optional<String> get_item(StringView key) const;
|
||||||
WebIDL::ExceptionOr<void> set_item(DeprecatedString const& key, DeprecatedString const& value);
|
WebIDL::ExceptionOr<void> set_item(String const& key, String const& value);
|
||||||
void remove_item(DeprecatedString const& key);
|
void remove_item(StringView key);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
auto const& map() const { return m_map; }
|
auto const& map() const { return m_map; }
|
||||||
|
@ -55,9 +55,9 @@ private:
|
||||||
virtual bool named_property_deleter_has_identifier() const override { return true; }
|
virtual bool named_property_deleter_has_identifier() const override { return true; }
|
||||||
|
|
||||||
void reorder();
|
void reorder();
|
||||||
void broadcast(DeprecatedString const& key, DeprecatedString const& old_value, DeprecatedString const& new_value);
|
void broadcast(StringView key, StringView old_value, StringView new_value);
|
||||||
|
|
||||||
OrderedHashMap<DeprecatedString, DeprecatedString> m_map;
|
OrderedHashMap<String, String> m_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[Exposed=Window]
|
[Exposed=Window, UseNewAKString]
|
||||||
interface Storage {
|
interface Storage {
|
||||||
|
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
|
|
|
@ -224,12 +224,12 @@ DeprecatedString OutOfProcessWebView::dump_layout_tree()
|
||||||
return client().dump_layout_tree();
|
return client().dump_layout_tree();
|
||||||
}
|
}
|
||||||
|
|
||||||
OrderedHashMap<DeprecatedString, DeprecatedString> OutOfProcessWebView::get_local_storage_entries()
|
OrderedHashMap<String, String> OutOfProcessWebView::get_local_storage_entries()
|
||||||
{
|
{
|
||||||
return client().get_local_storage_entries();
|
return client().get_local_storage_entries();
|
||||||
}
|
}
|
||||||
|
|
||||||
OrderedHashMap<DeprecatedString, DeprecatedString> OutOfProcessWebView::get_session_storage_entries()
|
OrderedHashMap<String, String> OutOfProcessWebView::get_session_storage_entries()
|
||||||
{
|
{
|
||||||
return client().get_session_storage_entries();
|
return client().get_session_storage_entries();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@ public:
|
||||||
|
|
||||||
DeprecatedString dump_layout_tree();
|
DeprecatedString dump_layout_tree();
|
||||||
|
|
||||||
OrderedHashMap<DeprecatedString, DeprecatedString> get_local_storage_entries();
|
OrderedHashMap<String, String> get_local_storage_entries();
|
||||||
OrderedHashMap<DeprecatedString, DeprecatedString> get_session_storage_entries();
|
OrderedHashMap<String, String> get_session_storage_entries();
|
||||||
|
|
||||||
void set_content_filters(Vector<String>);
|
void set_content_filters(Vector<String>);
|
||||||
void set_autoplay_allowed_on_all_websites();
|
void set_autoplay_allowed_on_all_websites();
|
||||||
|
|
|
@ -68,8 +68,8 @@ endpoint WebContentServer
|
||||||
set_window_position(Gfx::IntPoint position) =|
|
set_window_position(Gfx::IntPoint position) =|
|
||||||
set_window_size(Gfx::IntSize size) =|
|
set_window_size(Gfx::IntSize size) =|
|
||||||
|
|
||||||
get_local_storage_entries() => (OrderedHashMap<DeprecatedString,DeprecatedString> entries)
|
get_local_storage_entries() => (OrderedHashMap<String,String> entries)
|
||||||
get_session_storage_entries() => (OrderedHashMap<DeprecatedString,DeprecatedString> entries)
|
get_session_storage_entries() => (OrderedHashMap<String,String> entries)
|
||||||
|
|
||||||
handle_file_return(i32 error, Optional<IPC::File> file, i32 request_id) =|
|
handle_file_return(i32 error, Optional<IPC::File> file, i32 request_id) =|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue