mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00
AK: Port URL scheme from DeprecatedString to String
This commit is contained in:
parent
21fe86d235
commit
c25485700a
16 changed files with 30 additions and 30 deletions
|
@ -80,7 +80,7 @@ static DeprecatedString deprecated_string_percent_encode(DeprecatedString const&
|
|||
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_valid = compute_validity();
|
||||
|
@ -213,7 +213,7 @@ URL URL::create_with_file_scheme(DeprecatedString const& path, DeprecatedString
|
|||
return {};
|
||||
|
||||
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.
|
||||
// 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());
|
||||
|
@ -229,7 +229,7 @@ URL URL::create_with_help_scheme(DeprecatedString const& path, DeprecatedString
|
|||
LexicalPath lexical_path(path);
|
||||
|
||||
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.
|
||||
// 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());
|
||||
|
@ -255,7 +255,7 @@ URL URL::create_with_data(StringView mime_type, StringView payload, bool is_base
|
|||
{
|
||||
URL url;
|
||||
url.set_cannot_be_a_base_url(true);
|
||||
url.set_scheme("data"sv);
|
||||
url.set_scheme("data"_string);
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(mime_type);
|
||||
|
|
6
AK/URL.h
6
AK/URL.h
|
@ -76,7 +76,7 @@ public:
|
|||
Yes,
|
||||
No
|
||||
};
|
||||
DeprecatedString const& scheme() const { return m_scheme; }
|
||||
String const& scheme() const { return m_scheme; }
|
||||
ErrorOr<String> username() const;
|
||||
ErrorOr<String> password() const;
|
||||
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 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_password(StringView);
|
||||
void set_host(Host);
|
||||
|
@ -163,7 +163,7 @@ private:
|
|||
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.
|
||||
DeprecatedString m_scheme;
|
||||
String m_scheme;
|
||||
|
||||
// A URL’s username is an ASCII string identifying a username. It is initially the empty string.
|
||||
String m_username;
|
||||
|
|
|
@ -850,7 +850,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
|||
}
|
||||
|
||||
// 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:
|
||||
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
|
||||
case State::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.
|
||||
url->m_host = String {};
|
||||
|
|
|
@ -50,7 +50,7 @@ void LocationEdit::highlight_location()
|
|||
QList<QInputMethodEvent::Attribute> attributes;
|
||||
if (url.is_valid() && !hasFocus()) {
|
||||
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();
|
||||
|
||||
// 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({
|
||||
QInputMethodEvent::TextFormat,
|
||||
-cursorPosition(),
|
||||
static_cast<int>(url.scheme().length() + 3),
|
||||
static_cast<int>(url.scheme().bytes_as_string_view().length() + 3),
|
||||
schemeFormat,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
auto request_or_error = Request::create(*m_qnam, method, url, request_headers, request_body, proxy);
|
||||
|
|
|
@ -247,7 +247,7 @@ void URLProvider::query(DeprecatedString const& query, Function<void(Vector<Nonn
|
|||
URL url = URL(query);
|
||||
|
||||
if (url.scheme().is_empty())
|
||||
url.set_scheme("http");
|
||||
url.set_scheme("http"_string);
|
||||
if (url.host().has<Empty>() || url.host() == String {})
|
||||
url.set_host(String::from_deprecated_string(query).release_value_but_fixme_should_propagate_errors());
|
||||
if (url.path_segment_count() == 0)
|
||||
|
|
|
@ -754,7 +754,7 @@ DeprecatedString Position::to_cell_identifier(Sheet const& sheet) const
|
|||
URL Position::to_url(Sheet const& sheet) const
|
||||
{
|
||||
URL url;
|
||||
url.set_scheme("spreadsheet");
|
||||
url.set_scheme("spreadsheet"_string);
|
||||
url.set_host("cell"_string);
|
||||
url.set_paths({ DeprecatedString::number(getpid()) });
|
||||
url.set_fragment(to_cell_identifier(sheet));
|
||||
|
|
|
@ -486,7 +486,7 @@ void MainWidget::drop_event(GUI::DropEvent& drop_event)
|
|||
|
||||
for (auto& url : urls) {
|
||||
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;
|
||||
|
||||
auto lexical_path = LexicalPath(url.serialize_path());
|
||||
|
|
|
@ -180,7 +180,7 @@ void UrlBox::highlight_url()
|
|||
if (url.is_valid() && !is_focused()) {
|
||||
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 host_start = url.scheme().length() + 3;
|
||||
auto host_start = url.scheme().bytes_as_string_view().length() + 3;
|
||||
auto host_length = serialized_host.length();
|
||||
|
||||
// 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;
|
||||
scheme_format.color = palette().color(Gfx::ColorRole::PlaceholderText);
|
||||
spans.append({
|
||||
{ { 0, 0 }, { 0, url.scheme().length() + 3 } },
|
||||
{ { 0, 0 }, { 0, url.scheme().bytes_as_string_view().length() + 3 } },
|
||||
scheme_format,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ WebIDL::ExceptionOr<Optional<JS::NonnullGCPtr<PendingResponse>>> main_fetch(JS::
|
|||
&& 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>> {
|
||||
|
|
|
@ -31,7 +31,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::protocol() const
|
|||
{
|
||||
auto& vm = realm().vm();
|
||||
// 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
|
||||
|
|
|
@ -513,14 +513,14 @@ HTML::Origin url_origin(AK::URL const& url)
|
|||
// -> "wss"
|
||||
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 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"
|
||||
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.
|
||||
// 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
|
||||
|
|
|
@ -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".
|
||||
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".
|
||||
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.
|
||||
if (!url_record.scheme().is_one_of("ws"sv, "wss"sv))
|
||||
|
|
|
@ -17,7 +17,7 @@ bool ConnectionInfo::is_secure() const
|
|||
{
|
||||
// RFC 6455 Section 3 :
|
||||
// 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
|
||||
|
|
|
@ -146,8 +146,8 @@ Vector<DeprecatedString> Launcher::handlers_for_url(const URL& url)
|
|||
return true;
|
||||
});
|
||||
} 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);
|
||||
return true;
|
||||
}
|
||||
|
@ -166,8 +166,8 @@ Vector<DeprecatedString> Launcher::handlers_with_details_for_url(const URL& url)
|
|||
return true;
|
||||
});
|
||||
} 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());
|
||||
return true;
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ bool Launcher::open_url(const URL& url, DeprecatedString const& handler_name)
|
|||
if (url.scheme() == "file")
|
||||
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)
|
||||
|
|
|
@ -42,7 +42,7 @@ Messages::RequestServer::StartRequestResponse ConnectionFromClient::start_reques
|
|||
dbgln("StartRequest: Invalid URL requested: '{}'", url);
|
||||
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) {
|
||||
dbgln("StartRequest: No protocol handler for URL: '{}'", url);
|
||||
return { -1, Optional<IPC::File> {} };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue