diff --git a/Userland/Applications/Browser/StorageModel.cpp b/Userland/Applications/Browser/StorageModel.cpp index c9aadeb4bf..724914ef54 100644 --- a/Userland/Applications/Browser/StorageModel.cpp +++ b/Userland/Applications/Browser/StorageModel.cpp @@ -10,10 +10,10 @@ namespace Browser { -void StorageModel::set_items(OrderedHashMap map) +void StorageModel::set_items(OrderedHashMap map) { 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(); did_update(DontInvalidateIndices); diff --git a/Userland/Applications/Browser/StorageModel.h b/Userland/Applications/Browser/StorageModel.h index b081bc887d..2479f3a018 100644 --- a/Userland/Applications/Browser/StorageModel.h +++ b/Userland/Applications/Browser/StorageModel.h @@ -18,7 +18,7 @@ public: __Count, }; - void set_items(OrderedHashMap map); + void set_items(OrderedHashMap map); void clear_items(); virtual int row_count(GUI::ModelIndex const&) const override; 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; private: - OrderedHashMap m_local_storage_entries; + OrderedHashMap m_local_storage_entries; }; } diff --git a/Userland/Applications/Browser/StorageWidget.cpp b/Userland/Applications/Browser/StorageWidget.cpp index 2d3ce71b16..3b538fb106 100644 --- a/Userland/Applications/Browser/StorageWidget.cpp +++ b/Userland/Applications/Browser/StorageWidget.cpp @@ -107,7 +107,7 @@ void StorageWidget::clear_cookies() m_cookies_model->clear_items(); } -void StorageWidget::set_local_storage_entries(OrderedHashMap entries) +void StorageWidget::set_local_storage_entries(OrderedHashMap 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(); } -void StorageWidget::set_session_storage_entries(OrderedHashMap entries) +void StorageWidget::set_session_storage_entries(OrderedHashMap entries) { m_session_storage_model->set_items(move(entries)); } diff --git a/Userland/Applications/Browser/StorageWidget.h b/Userland/Applications/Browser/StorageWidget.h index f04001e4c2..11160fb822 100644 --- a/Userland/Applications/Browser/StorageWidget.h +++ b/Userland/Applications/Browser/StorageWidget.h @@ -26,10 +26,10 @@ public: Function on_update_cookie; - void set_local_storage_entries(OrderedHashMap entries); + void set_local_storage_entries(OrderedHashMap entries); void clear_local_storage_entries(); - void set_session_storage_entries(OrderedHashMap entries); + void set_session_storage_entries(OrderedHashMap entries); void clear_session_storage_entries(); private: diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index 99015ce242..1478695f8c 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -76,8 +76,8 @@ public: Function on_dump_cookies; Function on_update_cookie; Function()> on_get_cookies_entries; - Function()> on_get_local_storage_entries; - Function()> on_get_session_storage_entries; + Function()> on_get_local_storage_entries; + Function()> on_get_session_storage_entries; void enable_webdriver_mode(); diff --git a/Userland/Libraries/LibWeb/HTML/Storage.cpp b/Userland/Libraries/LibWeb/HTML/Storage.cpp index f10bb8e690..66a2124965 100644 --- a/Userland/Libraries/LibWeb/HTML/Storage.cpp +++ b/Userland/Libraries/LibWeb/HTML/Storage.cpp @@ -5,7 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include @@ -37,7 +37,7 @@ size_t Storage::length() const } // https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-key -DeprecatedString Storage::key(size_t index) +Optional Storage::key(size_t index) { // 1. If index is greater than or equal to this's map's size, then return null. 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 -DeprecatedString Storage::get_item(DeprecatedString const& key) const +Optional Storage::get_item(StringView key) const { // 1. If this's map[key] does not exist, then return null. 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 -WebIDL::ExceptionOr Storage::set_item(DeprecatedString const& key, DeprecatedString const& value) +WebIDL::ExceptionOr Storage::set_item(String const& key, String const& value) { // 1. Let oldValue be null. - DeprecatedString old_value; + String old_value; // 2. Let reorder be true. bool reorder = true; @@ -100,7 +100,7 @@ WebIDL::ExceptionOr Storage::set_item(DeprecatedString const& key, Depreca } // 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. // FIXME: Return null? @@ -139,7 +139,7 @@ void Storage::reorder() } // 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)old_value; @@ -150,15 +150,19 @@ void Storage::broadcast(DeprecatedString const& key, DeprecatedString const& old Vector 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. - return m_map.keys(); + Vector 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 Storage::named_item_value(DeprecatedFlyString const& name) const { auto value = get_item(name); - if (value.is_null()) + if (!value.has_value()) return JS::js_null(); - return JS::PrimitiveString::create(vm(), value); + return JS::PrimitiveString::create(vm(), value.release_value()); } WebIDL::ExceptionOr Storage::delete_value(DeprecatedString const& name) @@ -171,8 +175,8 @@ WebIDL::ExceptionOr Storage::set_value_of_named_property(DeprecatedString { // NOTE: Since LegacyPlatformObject does not know the type of value, we must convert it ourselves. // The type of `value` is `DOMString`. - auto value = TRY(unconverted_value.to_deprecated_string(vm())); - return set_item(key, value); + auto value = TRY(unconverted_value.to_string(vm())); + return set_item(String::from_deprecated_string(key).release_value(), value); } void Storage::dump() const diff --git a/Userland/Libraries/LibWeb/HTML/Storage.h b/Userland/Libraries/LibWeb/HTML/Storage.h index 86128a96aa..d1a523a026 100644 --- a/Userland/Libraries/LibWeb/HTML/Storage.h +++ b/Userland/Libraries/LibWeb/HTML/Storage.h @@ -21,10 +21,10 @@ public: ~Storage(); size_t length() const; - DeprecatedString key(size_t index); - DeprecatedString get_item(DeprecatedString const& key) const; - WebIDL::ExceptionOr set_item(DeprecatedString const& key, DeprecatedString const& value); - void remove_item(DeprecatedString const& key); + Optional key(size_t index); + Optional get_item(StringView key) const; + WebIDL::ExceptionOr set_item(String const& key, String const& value); + void remove_item(StringView key); void clear(); auto const& map() const { return m_map; } @@ -55,9 +55,9 @@ private: virtual bool named_property_deleter_has_identifier() const override { return true; } 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 m_map; + OrderedHashMap m_map; }; } diff --git a/Userland/Libraries/LibWeb/HTML/Storage.idl b/Userland/Libraries/LibWeb/HTML/Storage.idl index 4c1005e17a..8794f8edee 100644 --- a/Userland/Libraries/LibWeb/HTML/Storage.idl +++ b/Userland/Libraries/LibWeb/HTML/Storage.idl @@ -1,4 +1,4 @@ -[Exposed=Window] +[Exposed=Window, UseNewAKString] interface Storage { readonly attribute unsigned long length; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 9564b4bd77..c8f9d04f3f 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -224,12 +224,12 @@ DeprecatedString OutOfProcessWebView::dump_layout_tree() return client().dump_layout_tree(); } -OrderedHashMap OutOfProcessWebView::get_local_storage_entries() +OrderedHashMap OutOfProcessWebView::get_local_storage_entries() { return client().get_local_storage_entries(); } -OrderedHashMap OutOfProcessWebView::get_session_storage_entries() +OrderedHashMap OutOfProcessWebView::get_session_storage_entries() { return client().get_session_storage_entries(); } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index f19c35d40b..d6f3c41c02 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -36,8 +36,8 @@ public: DeprecatedString dump_layout_tree(); - OrderedHashMap get_local_storage_entries(); - OrderedHashMap get_session_storage_entries(); + OrderedHashMap get_local_storage_entries(); + OrderedHashMap get_session_storage_entries(); void set_content_filters(Vector); void set_autoplay_allowed_on_all_websites(); diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index ff497f7068..3181af21e9 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -68,8 +68,8 @@ endpoint WebContentServer set_window_position(Gfx::IntPoint position) =| set_window_size(Gfx::IntSize size) =| - get_local_storage_entries() => (OrderedHashMap entries) - get_session_storage_entries() => (OrderedHashMap entries) + get_local_storage_entries() => (OrderedHashMap entries) + get_session_storage_entries() => (OrderedHashMap entries) handle_file_return(i32 error, Optional file, i32 request_id) =|