1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:27:45 +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

@ -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, {});