瀏覽代碼

AK: Port URL scheme from DeprecatedString to String

Shannon Booth 1 年之前
父節點
當前提交
c25485700a

+ 4 - 4
AK/URL.cpp

@@ -80,7 +80,7 @@ static DeprecatedString deprecated_string_percent_encode(DeprecatedString const&
     return URL::percent_encode(input.view(), set, space_as_plus);
     return URL::percent_encode(input.view(), set, space_as_plus);
 }
 }
 
 
-void URL::set_scheme(DeprecatedString scheme)
+void URL::set_scheme(String scheme)
 {
 {
     m_scheme = move(scheme);
     m_scheme = move(scheme);
     m_valid = compute_validity();
     m_valid = compute_validity();
@@ -213,7 +213,7 @@ URL URL::create_with_file_scheme(DeprecatedString const& path, DeprecatedString
         return {};
         return {};
 
 
     URL url;
     URL url;
-    url.set_scheme("file");
+    url.set_scheme("file"_string);
     // NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string.
     // NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string.
     //       This is because a file URL always needs a non-null hostname.
     //       This is because a file URL always needs a non-null hostname.
     url.set_host(hostname.is_null() || hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors());
     url.set_host(hostname.is_null() || hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors());
@@ -229,7 +229,7 @@ URL URL::create_with_help_scheme(DeprecatedString const& path, DeprecatedString
     LexicalPath lexical_path(path);
     LexicalPath lexical_path(path);
 
 
     URL url;
     URL url;
-    url.set_scheme("help");
+    url.set_scheme("help"_string);
     // NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string.
     // NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string.
     //       This is because a file URL always needs a non-null hostname.
     //       This is because a file URL always needs a non-null hostname.
     url.set_host(hostname.is_null() || hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors());
     url.set_host(hostname.is_null() || hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors());
@@ -255,7 +255,7 @@ URL URL::create_with_data(StringView mime_type, StringView payload, bool is_base
 {
 {
     URL url;
     URL url;
     url.set_cannot_be_a_base_url(true);
     url.set_cannot_be_a_base_url(true);
-    url.set_scheme("data"sv);
+    url.set_scheme("data"_string);
 
 
     StringBuilder builder;
     StringBuilder builder;
     builder.append(mime_type);
     builder.append(mime_type);

+ 3 - 3
AK/URL.h

@@ -76,7 +76,7 @@ public:
         Yes,
         Yes,
         No
         No
     };
     };
-    DeprecatedString const& scheme() const { return m_scheme; }
+    String const& scheme() const { return m_scheme; }
     ErrorOr<String> username() const;
     ErrorOr<String> username() const;
     ErrorOr<String> password() const;
     ErrorOr<String> password() const;
     Host const& host() const { return m_host; }
     Host const& host() const { return m_host; }
@@ -97,7 +97,7 @@ public:
     bool includes_credentials() const { return !m_username.is_empty() || !m_password.is_empty(); }
     bool includes_credentials() const { return !m_username.is_empty() || !m_password.is_empty(); }
     bool is_special() const { return is_special_scheme(m_scheme); }
     bool is_special() const { return is_special_scheme(m_scheme); }
 
 
-    void set_scheme(DeprecatedString);
+    void set_scheme(String);
     ErrorOr<void> set_username(StringView);
     ErrorOr<void> set_username(StringView);
     ErrorOr<void> set_password(StringView);
     ErrorOr<void> set_password(StringView);
     void set_host(Host);
     void set_host(Host);
@@ -163,7 +163,7 @@ private:
     bool m_valid { false };
     bool m_valid { false };
 
 
     // A URL’s scheme is an ASCII string that identifies the type of URL and can be used to dispatch a URL for further processing after parsing. It is initially the empty string.
     // A URL’s scheme is an ASCII string that identifies the type of URL and can be used to dispatch a URL for further processing after parsing. It is initially the empty string.
-    DeprecatedString m_scheme;
+    String m_scheme;
 
 
     // A URL’s username is an ASCII string identifying a username. It is initially the empty string.
     // A URL’s username is an ASCII string identifying a username. It is initially the empty string.
     String m_username;
     String m_username;

+ 2 - 2
AK/URLParser.cpp

@@ -850,7 +850,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
                 }
                 }
 
 
                 // 2. Set url’s scheme to buffer.
                 // 2. Set url’s scheme to buffer.
-                url->m_scheme = buffer.to_deprecated_string();
+                url->m_scheme = buffer.to_string().release_value_but_fixme_should_propagate_errors();
 
 
                 // 3. If state override is given, then:
                 // 3. If state override is given, then:
                 if (state_override.has_value()) {
                 if (state_override.has_value()) {
@@ -1281,7 +1281,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
         // -> file state, https://url.spec.whatwg.org/#file-state
         // -> file state, https://url.spec.whatwg.org/#file-state
         case State::File:
         case State::File:
             // 1. Set url’s scheme to "file".
             // 1. Set url’s scheme to "file".
-            url->m_scheme = "file";
+            url->m_scheme = String::from_utf8("file"sv).release_value_but_fixme_should_propagate_errors();
 
 
             // 2. Set url’s host to the empty string.
             // 2. Set url’s host to the empty string.
             url->m_host = String {};
             url->m_host = String {};

+ 2 - 2
Ladybird/Qt/LocationEdit.cpp

@@ -50,7 +50,7 @@ void LocationEdit::highlight_location()
     QList<QInputMethodEvent::Attribute> attributes;
     QList<QInputMethodEvent::Attribute> attributes;
     if (url.is_valid() && !hasFocus()) {
     if (url.is_valid() && !hasFocus()) {
         if (url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "gemini") {
         if (url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "gemini") {
-            int host_start = (url.scheme().length() + 3) - cursorPosition();
+            int host_start = (url.scheme().bytes_as_string_view().length() + 3) - cursorPosition();
             auto host_length = url.serialized_host().release_value_but_fixme_should_propagate_errors().bytes().size();
             auto host_length = url.serialized_host().release_value_but_fixme_should_propagate_errors().bytes().size();
 
 
             // FIXME: Maybe add a generator to use https://publicsuffix.org/list/public_suffix_list.dat
             // FIXME: Maybe add a generator to use https://publicsuffix.org/list/public_suffix_list.dat
@@ -79,7 +79,7 @@ void LocationEdit::highlight_location()
             attributes.append({
             attributes.append({
                 QInputMethodEvent::TextFormat,
                 QInputMethodEvent::TextFormat,
                 -cursorPosition(),
                 -cursorPosition(),
-                static_cast<int>(url.scheme().length() + 3),
+                static_cast<int>(url.scheme().bytes_as_string_view().length() + 3),
                 schemeFormat,
                 schemeFormat,
             });
             });
         }
         }

+ 1 - 1
Ladybird/Qt/RequestManagerQt.cpp

@@ -26,7 +26,7 @@ void RequestManagerQt::reply_finished(QNetworkReply* reply)
 
 
 RefPtr<Web::ResourceLoaderConnectorRequest> RequestManagerQt::start_request(DeprecatedString const& method, AK::URL const& url, HashMap<DeprecatedString, DeprecatedString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const& proxy)
 RefPtr<Web::ResourceLoaderConnectorRequest> RequestManagerQt::start_request(DeprecatedString const& method, AK::URL const& url, HashMap<DeprecatedString, DeprecatedString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const& proxy)
 {
 {
-    if (!url.scheme().is_one_of_ignoring_ascii_case("http"sv, "https"sv)) {
+    if (!url.scheme().bytes_as_string_view().is_one_of_ignoring_ascii_case("http"sv, "https"sv)) {
         return nullptr;
         return nullptr;
     }
     }
     auto request_or_error = Request::create(*m_qnam, method, url, request_headers, request_body, proxy);
     auto request_or_error = Request::create(*m_qnam, method, url, request_headers, request_body, proxy);

+ 1 - 1
Userland/Applications/Assistant/Providers.cpp

@@ -247,7 +247,7 @@ void URLProvider::query(DeprecatedString const& query, Function<void(Vector<Nonn
     URL url = URL(query);
     URL url = URL(query);
 
 
     if (url.scheme().is_empty())
     if (url.scheme().is_empty())
-        url.set_scheme("http");
+        url.set_scheme("http"_string);
     if (url.host().has<Empty>() || url.host() == String {})
     if (url.host().has<Empty>() || url.host() == String {})
         url.set_host(String::from_deprecated_string(query).release_value_but_fixme_should_propagate_errors());
         url.set_host(String::from_deprecated_string(query).release_value_but_fixme_should_propagate_errors());
     if (url.path_segment_count() == 0)
     if (url.path_segment_count() == 0)

+ 1 - 1
Userland/Applications/Spreadsheet/Spreadsheet.cpp

@@ -754,7 +754,7 @@ DeprecatedString Position::to_cell_identifier(Sheet const& sheet) const
 URL Position::to_url(Sheet const& sheet) const
 URL Position::to_url(Sheet const& sheet) const
 {
 {
     URL url;
     URL url;
-    url.set_scheme("spreadsheet");
+    url.set_scheme("spreadsheet"_string);
     url.set_host("cell"_string);
     url.set_host("cell"_string);
     url.set_paths({ DeprecatedString::number(getpid()) });
     url.set_paths({ DeprecatedString::number(getpid()) });
     url.set_fragment(to_cell_identifier(sheet));
     url.set_fragment(to_cell_identifier(sheet));

+ 1 - 1
Userland/DevTools/SQLStudio/MainWidget.cpp

@@ -486,7 +486,7 @@ void MainWidget::drop_event(GUI::DropEvent& drop_event)
 
 
         for (auto& url : urls) {
         for (auto& url : urls) {
             auto& scheme = url.scheme();
             auto& scheme = url.scheme();
-            if (!scheme.equals_ignoring_ascii_case("file"sv))
+            if (!scheme.bytes_as_string_view().equals_ignoring_ascii_case("file"sv))
                 continue;
                 continue;
 
 
             auto lexical_path = LexicalPath(url.serialize_path());
             auto lexical_path = LexicalPath(url.serialize_path());

+ 2 - 2
Userland/Libraries/LibGUI/TextBox.cpp

@@ -180,7 +180,7 @@ void UrlBox::highlight_url()
     if (url.is_valid() && !is_focused()) {
     if (url.is_valid() && !is_focused()) {
         if (url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "gemini") {
         if (url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "gemini") {
             auto serialized_host = url.serialized_host().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
             auto serialized_host = url.serialized_host().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
-            auto host_start = url.scheme().length() + 3;
+            auto host_start = url.scheme().bytes_as_string_view().length() + 3;
             auto host_length = serialized_host.length();
             auto host_length = serialized_host.length();
 
 
             // FIXME: Maybe add a generator to use https://publicsuffix.org/list/public_suffix_list.dat
             // FIXME: Maybe add a generator to use https://publicsuffix.org/list/public_suffix_list.dat
@@ -208,7 +208,7 @@ void UrlBox::highlight_url()
             Gfx::TextAttributes scheme_format;
             Gfx::TextAttributes scheme_format;
             scheme_format.color = palette().color(Gfx::ColorRole::PlaceholderText);
             scheme_format.color = palette().color(Gfx::ColorRole::PlaceholderText);
             spans.append({
             spans.append({
-                { { 0, 0 }, { 0, url.scheme().length() + 3 } },
+                { { 0, 0 }, { 0, url.scheme().bytes_as_string_view().length() + 3 } },
                 scheme_format,
                 scheme_format,
             });
             });
         }
         }

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp

@@ -266,7 +266,7 @@ WebIDL::ExceptionOr<Optional<JS::NonnullGCPtr<PendingResponse>>> main_fetch(JS::
         && false
         && false
 
 
     ) {
     ) {
-        request->current_url().set_scheme("https"sv);
+        request->current_url().set_scheme("https"_string);
     }
     }
 
 
     JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>>()> get_response = [&realm, &vm, &fetch_params, request]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> {
     JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>>()> get_response = [&realm, &vm, &fetch_params, request]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> {

+ 1 - 1
Userland/Libraries/LibWeb/HTML/WorkerLocation.cpp

@@ -31,7 +31,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::protocol() const
 {
 {
     auto& vm = realm().vm();
     auto& vm = realm().vm();
     // The protocol getter steps are to return this's WorkerGlobalScope object's url's scheme, followed by ":".
     // The protocol getter steps are to return this's WorkerGlobalScope object's url's scheme, followed by ":".
-    return TRY_OR_THROW_OOM(vm, String::formatted("{}:", m_global_scope->url().scheme().view()));
+    return TRY_OR_THROW_OOM(vm, String::formatted("{}:", m_global_scope->url().scheme()));
 }
 }
 
 
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-host
 // https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-host

+ 2 - 2
Userland/Libraries/LibWeb/URL/URL.cpp

@@ -513,14 +513,14 @@ HTML::Origin url_origin(AK::URL const& url)
     // -> "wss"
     // -> "wss"
     if (url.scheme().is_one_of("ftp"sv, "http"sv, "https"sv, "ws"sv, "wss"sv)) {
     if (url.scheme().is_one_of("ftp"sv, "http"sv, "https"sv, "ws"sv, "wss"sv)) {
         // Return the tuple origin (url’s scheme, url’s host, url’s port, null).
         // Return the tuple origin (url’s scheme, url’s host, url’s port, null).
-        return HTML::Origin(url.scheme(), url.host(), url.port().value_or(0));
+        return HTML::Origin(url.scheme().to_deprecated_string(), url.host(), url.port().value_or(0));
     }
     }
 
 
     // -> "file"
     // -> "file"
     if (url.scheme() == "file"sv) {
     if (url.scheme() == "file"sv) {
         // Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.
         // Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.
         // Note: We must return an origin with the `file://' protocol for `file://' iframes to work from `file://' pages.
         // Note: We must return an origin with the `file://' protocol for `file://' iframes to work from `file://' pages.
-        return HTML::Origin(url.scheme(), String {}, 0);
+        return HTML::Origin(url.scheme().to_deprecated_string(), String {}, 0);
     }
     }
 
 
     // -> Otherwise
     // -> Otherwise

+ 2 - 2
Userland/Libraries/LibWeb/WebSockets/WebSocket.cpp

@@ -69,10 +69,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebSocket>> WebSocket::construct_impl(JS::R
 
 
     // 4. If urlRecord’s scheme is "http", then set urlRecord’s scheme to "ws".
     // 4. If urlRecord’s scheme is "http", then set urlRecord’s scheme to "ws".
     if (url_record.scheme() == "http"sv)
     if (url_record.scheme() == "http"sv)
-        url_record.set_scheme("ws"sv);
+        url_record.set_scheme("ws"_string);
     // 5. Otherwise, if urlRecord’s scheme is "https", set urlRecord’s scheme to "wss".
     // 5. Otherwise, if urlRecord’s scheme is "https", set urlRecord’s scheme to "wss".
     else if (url_record.scheme() == "https"sv)
     else if (url_record.scheme() == "https"sv)
-        url_record.set_scheme("wss"sv);
+        url_record.set_scheme("wss"_string);
 
 
     // 6. If urlRecord’s scheme is not "ws" or "wss", then throw a "SyntaxError" DOMException.
     // 6. If urlRecord’s scheme is not "ws" or "wss", then throw a "SyntaxError" DOMException.
     if (!url_record.scheme().is_one_of("ws"sv, "wss"sv))
     if (!url_record.scheme().is_one_of("ws"sv, "wss"sv))

+ 1 - 1
Userland/Libraries/LibWebSocket/ConnectionInfo.cpp

@@ -17,7 +17,7 @@ bool ConnectionInfo::is_secure() const
 {
 {
     // RFC 6455 Section 3 :
     // RFC 6455 Section 3 :
     // The URI is called "secure" if the scheme component matches "wss" case-insensitively.
     // The URI is called "secure" if the scheme component matches "wss" case-insensitively.
-    return m_url.scheme().equals_ignoring_ascii_case("wss"sv);
+    return m_url.scheme().bytes_as_string_view().equals_ignoring_ascii_case("wss"sv);
 }
 }
 
 
 DeprecatedString ConnectionInfo::resource_name() const
 DeprecatedString ConnectionInfo::resource_name() const

+ 5 - 5
Userland/Services/LaunchServer/Launcher.cpp

@@ -146,8 +146,8 @@ Vector<DeprecatedString> Launcher::handlers_for_url(const URL& url)
             return true;
             return true;
         });
         });
     } else {
     } else {
-        for_each_handler(url.scheme(), m_protocol_handlers, [&](auto const& handler) -> bool {
-            if (handler.handler_type != Handler::Type::Default || handler.protocols.contains(url.scheme())) {
+        for_each_handler(url.scheme().to_deprecated_string(), m_protocol_handlers, [&](auto const& handler) -> bool {
+            if (handler.handler_type != Handler::Type::Default || handler.protocols.contains(url.scheme().to_deprecated_string())) {
                 handlers.append(handler.executable);
                 handlers.append(handler.executable);
                 return true;
                 return true;
             }
             }
@@ -166,8 +166,8 @@ Vector<DeprecatedString> Launcher::handlers_with_details_for_url(const URL& url)
             return true;
             return true;
         });
         });
     } else {
     } else {
-        for_each_handler(url.scheme(), m_protocol_handlers, [&](auto const& handler) -> bool {
-            if (handler.handler_type != Handler::Type::Default || handler.protocols.contains(url.scheme())) {
+        for_each_handler(url.scheme().to_deprecated_string(), m_protocol_handlers, [&](auto const& handler) -> bool {
+            if (handler.handler_type != Handler::Type::Default || handler.protocols.contains(url.scheme().to_deprecated_string())) {
                 handlers.append(handler.to_details_str());
                 handlers.append(handler.to_details_str());
                 return true;
                 return true;
             }
             }
@@ -194,7 +194,7 @@ bool Launcher::open_url(const URL& url, DeprecatedString const& handler_name)
     if (url.scheme() == "file")
     if (url.scheme() == "file")
         return open_file_url(url);
         return open_file_url(url);
 
 
-    return open_with_user_preferences(m_protocol_handlers, url.scheme(), { url.to_deprecated_string() });
+    return open_with_user_preferences(m_protocol_handlers, url.scheme().to_deprecated_string(), { url.to_deprecated_string() });
 }
 }
 
 
 bool Launcher::open_with_handler_name(const URL& url, DeprecatedString const& handler_name)
 bool Launcher::open_with_handler_name(const URL& url, DeprecatedString const& handler_name)

+ 1 - 1
Userland/Services/RequestServer/ConnectionFromClient.cpp

@@ -42,7 +42,7 @@ Messages::RequestServer::StartRequestResponse ConnectionFromClient::start_reques
         dbgln("StartRequest: Invalid URL requested: '{}'", url);
         dbgln("StartRequest: Invalid URL requested: '{}'", url);
         return { -1, Optional<IPC::File> {} };
         return { -1, Optional<IPC::File> {} };
     }
     }
-    auto* protocol = Protocol::find_by_name(url.scheme());
+    auto* protocol = Protocol::find_by_name(url.scheme().to_deprecated_string());
     if (!protocol) {
     if (!protocol) {
         dbgln("StartRequest: No protocol handler for URL: '{}'", url);
         dbgln("StartRequest: No protocol handler for URL: '{}'", url);
         return { -1, Optional<IPC::File> {} };
         return { -1, Optional<IPC::File> {} };