1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:27:44 +00:00

AK+Everywhere: Replace "protocol" with "scheme" url helpers

URL had properly named replacements for protocol(), set_protocol() and
create_with_file_protocol() already. This patch removes these function
and updates all call sites to use the functions named according to the
specification.

See https://url.spec.whatwg.org/#concept-url-scheme
This commit is contained in:
networkException 2022-09-29 01:30:58 +02:00 committed by Linus Groh
parent 454bf1fde0
commit 4230dbbb21
61 changed files with 113 additions and 116 deletions

View file

@ -204,7 +204,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::protocol_getter)
// FIXME: 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
// 2. Return this's url's scheme, followed by ":".
return JS::js_string(vm, String::formatted("{}:", location_object->url().protocol()));
return JS::js_string(vm, String::formatted("{}:", location_object->url().scheme()));
}
// https://html.spec.whatwg.org/multipage/history.html#dom-location-port

View file

@ -1383,7 +1383,7 @@ void StyleComputer::load_fonts_from_sheet(CSSStyleSheet const& sheet)
if (!source.url.is_valid())
continue;
if (source.url.protocol() != "data") {
if (source.url.scheme() != "data") {
auto path = source.url.path();
if (!path.ends_with(".woff"sv, AK::CaseSensitivity::CaseInsensitive)
&& !path.ends_with(".ttf"sv, AK::CaseSensitivity::CaseInsensitive)) {

View file

@ -56,7 +56,7 @@ static HTML::Origin url_origin(AK::URL const& url)
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.protocol(), String(), 0);
return HTML::Origin(url.scheme(), String(), 0);
}
return HTML::Origin {};

View file

@ -168,7 +168,7 @@ void BrowsingContextContainer::shared_attribute_processing_steps_for_iframe_and_
// FIXME: Set the referrer policy.
// AD-HOC:
if (url.protocol() == "file" && document().origin().protocol() != "file") {
if (url.scheme() == "file" && document().origin().protocol() != "file") {
dbgln("iframe failed to load URL: Security violation: {} may not load {}", document().url(), url);
return;
}

View file

@ -96,8 +96,8 @@ void HTMLFormElement::submit_form(JS::GCPtr<HTMLElement> submitter, bool from_su
return;
}
if (url.protocol() == "file") {
if (document().url().protocol() != "file") {
if (url.scheme() == "file") {
if (document().url().scheme() != "file") {
dbgln("Failed to submit form: Security violation: {} may not submit to {}", document().url(), url);
return;
}
@ -105,7 +105,7 @@ void HTMLFormElement::submit_form(JS::GCPtr<HTMLElement> submitter, bool from_su
dbgln("Failed to submit form: Unsupported form method '{}' for URL: {}", method(), url);
return;
}
} else if (url.protocol() != "http" && url.protocol() != "https") {
} else if (url.scheme() != "http" && url.scheme() != "https") {
dbgln("Failed to submit form: Unsupported protocol for URL: {}", url);
return;
}

View file

@ -117,7 +117,7 @@ void HTMLIFrameElement::load_src(String const& value)
dbgln("iframe failed to load URL: Invalid URL: {}", value);
return;
}
if (url.protocol() == "file" && document().origin().protocol() != "file") {
if (url.scheme() == "file" && document().origin().protocol() != "file") {
dbgln("iframe failed to load URL: Security violation: {} may not load {}", document().url(), url);
return;
}

View file

@ -21,7 +21,7 @@ ContentFilter::~ContentFilter() = default;
bool ContentFilter::is_filtered(const AK::URL& url) const
{
if (url.protocol() == "data")
if (url.scheme() == "data")
return false;
auto url_string = url.to_string();

View file

@ -242,9 +242,9 @@ bool FrameLoader::load(LoadRequest& request, Type type)
if (document && document->has_active_favicon())
return true;
if (url.protocol() == "http" || url.protocol() == "https") {
if (url.scheme() == "http" || url.scheme() == "https") {
AK::URL favicon_url;
favicon_url.set_protocol(url.protocol());
favicon_url.set_scheme(url.scheme());
favicon_url.set_host(url.host());
favicon_url.set_port(url.port_or_default());
favicon_url.set_paths({ "favicon.ico" });

View file

@ -105,7 +105,7 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, HashMap<Strin
// Let's use image/x-qoi for now, which is also what our Core::MimeData uses & would guess.
if (m_mime_type == "application/octet-stream" && url().path().ends_with(".qoi"sv))
m_mime_type = "image/x-qoi";
} else if (url().protocol() == "data" && !url().data_mime_type().is_empty()) {
} else if (url().scheme() == "data" && !url().data_mime_type().is_empty()) {
dbgln_if(RESOURCE_DEBUG, "This is a data URL with mime-type _{}_", url().data_mime_type());
m_mime_type = url().data_mime_type();
} else {

View file

@ -87,7 +87,7 @@ RefPtr<Resource> ResourceLoader::load_resource(Resource::Type type, LoadRequest&
if (!request.is_valid())
return nullptr;
bool use_cache = request.url().protocol() != "file";
bool use_cache = request.url().scheme() != "file";
if (use_cache) {
auto it = s_resource_cache.find(request);
@ -120,7 +120,7 @@ RefPtr<Resource> ResourceLoader::load_resource(Resource::Type type, LoadRequest&
static String sanitized_url_for_logging(AK::URL const& url)
{
if (url.protocol() == "data"sv)
if (url.scheme() == "data"sv)
return String::formatted("[data URL, mime-type={}, size={}]", url.data_mime_type(), url.data_payload().length());
return url.to_string();
}
@ -172,7 +172,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
return;
}
if (url.protocol() == "about") {
if (url.scheme() == "about") {
dbgln_if(SPAM_DEBUG, "Loading about: URL {}", url);
log_success(request);
@ -185,7 +185,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
return;
}
if (url.protocol() == "data") {
if (url.scheme() == "data") {
dbgln_if(SPAM_DEBUG, "ResourceLoader loading a data URL with mime-type: '{}', base64={}, payload='{}'",
url.data_mime_type(),
url.data_payload_is_base64(),
@ -212,7 +212,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
return;
}
if (url.protocol() == "file") {
if (url.scheme() == "file") {
if (request.page().has_value())
m_page = request.page().value();
@ -263,7 +263,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
return;
}
if (url.protocol() == "http" || url.protocol() == "https" || url.protocol() == "gemini") {
if (url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "gemini") {
auto proxy = ProxyMappings::the().proxy_for_url(url);
HashMap<String, String> headers;
@ -326,7 +326,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
return;
}
auto not_implemented_error = String::formatted("Protocol not implemented: {}", url.protocol());
auto not_implemented_error = String::formatted("Protocol not implemented: {}", url.scheme());
log_failure(request, not_implemented_error);
if (error_callback)
error_callback(not_implemented_error, {});

View file

@ -52,7 +52,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebSocket>> WebSocket::create_with_global_o
AK::URL url_record(url);
if (!url_record.is_valid())
return WebIDL::SyntaxError::create(window, "Invalid URL");
if (!url_record.protocol().is_one_of("ws", "wss"))
if (!url_record.scheme().is_one_of("ws", "wss"))
return WebIDL::SyntaxError::create(window, "Invalid protocol");
if (!url_record.fragment().is_empty())
return WebIDL::SyntaxError::create(window, "Presence of URL fragment is invalid");

View file

@ -416,7 +416,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<Fetch::XMLHttpRequestBod
dbgln("XHR send from {} to {}", m_window->associated_document().url(), request_url);
// TODO: Add support for preflight requests to support CORS requests
auto request_url_origin = HTML::Origin(request_url.protocol(), request_url.host(), request_url.port_or_default());
auto request_url_origin = HTML::Origin(request_url.scheme(), request_url.host(), request_url.port_or_default());
bool should_enforce_same_origin_policy = true;
if (auto* page = m_window->page())