Просмотр исходного кода

LibWeb: Port Storage interface from DeprecatedString to String

Which ends up bubbling all the way up to the Browser storage model.
Shannon Booth 1 год назад
Родитель
Сommit
901220c588

+ 2 - 2
Userland/Applications/Browser/StorageModel.cpp

@@ -10,10 +10,10 @@
 
 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());
-    m_local_storage_entries = map;
+    m_local_storage_entries = move(map);
     end_insert_rows();
 
     did_update(DontInvalidateIndices);

+ 2 - 2
Userland/Applications/Browser/StorageModel.h

@@ -18,7 +18,7 @@ public:
         __Count,
     };
 
-    void set_items(OrderedHashMap<DeprecatedString, DeprecatedString> map);
+    void set_items(OrderedHashMap<String, String> 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<DeprecatedString, DeprecatedString> m_local_storage_entries;
+    OrderedHashMap<String, String> m_local_storage_entries;
 };
 
 }

+ 2 - 2
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<DeprecatedString, DeprecatedString> entries)
+void StorageWidget::set_local_storage_entries(OrderedHashMap<String, String> 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<DeprecatedString, DeprecatedString> entries)
+void StorageWidget::set_session_storage_entries(OrderedHashMap<String, String> entries)
 {
     m_session_storage_model->set_items(move(entries));
 }

+ 2 - 2
Userland/Applications/Browser/StorageWidget.h

@@ -26,10 +26,10 @@ public:
 
     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 set_session_storage_entries(OrderedHashMap<DeprecatedString, DeprecatedString> entries);
+    void set_session_storage_entries(OrderedHashMap<String, String> entries);
     void clear_session_storage_entries();
 
 private:

+ 2 - 2
Userland/Applications/Browser/Tab.h

@@ -76,8 +76,8 @@ public:
     Function<void()> on_dump_cookies;
     Function<void(Web::Cookie::Cookie)> on_update_cookie;
     Function<Vector<Web::Cookie::Cookie>()> on_get_cookies_entries;
-    Function<OrderedHashMap<DeprecatedString, DeprecatedString>()> on_get_local_storage_entries;
-    Function<OrderedHashMap<DeprecatedString, DeprecatedString>()> on_get_session_storage_entries;
+    Function<OrderedHashMap<String, String>()> on_get_local_storage_entries;
+    Function<OrderedHashMap<String, String>()> on_get_session_storage_entries;
 
     void enable_webdriver_mode();
 

+ 16 - 12
Userland/Libraries/LibWeb/HTML/Storage.cpp

@@ -5,7 +5,7 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
-#include <AK/DeprecatedString.h>
+#include <AK/String.h>
 #include <LibWeb/Bindings/Intrinsics.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
-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.
     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<String> 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<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.
-    DeprecatedString old_value;
+    String old_value;
 
     // 2. Let reorder be 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
-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<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.
-    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
 {
     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<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.
     //       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

+ 6 - 6
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<void> set_item(DeprecatedString const& key, DeprecatedString const& value);
-    void remove_item(DeprecatedString const& key);
+    Optional<String> key(size_t index);
+    Optional<String> get_item(StringView key) const;
+    WebIDL::ExceptionOr<void> 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<DeprecatedString, DeprecatedString> m_map;
+    OrderedHashMap<String, String> m_map;
 };
 
 }

+ 1 - 1
Userland/Libraries/LibWeb/HTML/Storage.idl

@@ -1,4 +1,4 @@
-[Exposed=Window]
+[Exposed=Window, UseNewAKString]
 interface Storage {
 
     readonly attribute unsigned long length;

+ 2 - 2
Userland/Libraries/LibWebView/OutOfProcessWebView.cpp

@@ -224,12 +224,12 @@ DeprecatedString OutOfProcessWebView::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();
 }
 
-OrderedHashMap<DeprecatedString, DeprecatedString> OutOfProcessWebView::get_session_storage_entries()
+OrderedHashMap<String, String> OutOfProcessWebView::get_session_storage_entries()
 {
     return client().get_session_storage_entries();
 }

+ 2 - 2
Userland/Libraries/LibWebView/OutOfProcessWebView.h

@@ -36,8 +36,8 @@ public:
 
     DeprecatedString dump_layout_tree();
 
-    OrderedHashMap<DeprecatedString, DeprecatedString> get_local_storage_entries();
-    OrderedHashMap<DeprecatedString, DeprecatedString> get_session_storage_entries();
+    OrderedHashMap<String, String> get_local_storage_entries();
+    OrderedHashMap<String, String> get_session_storage_entries();
 
     void set_content_filters(Vector<String>);
     void set_autoplay_allowed_on_all_websites();

+ 2 - 2
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<DeprecatedString,DeprecatedString> entries)
-    get_session_storage_entries() => (OrderedHashMap<DeprecatedString,DeprecatedString> entries)
+    get_local_storage_entries() => (OrderedHashMap<String,String> entries)
+    get_session_storage_entries() => (OrderedHashMap<String,String> entries)
 
     handle_file_return(i32 error, Optional<IPC::File> file, i32 request_id) =|