diff options
author | Andreas Kling <kling@serenityos.org> | 2023-03-22 23:56:11 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-22 23:34:32 +0000 |
commit | d005b1ad1b085fc1758854084609a9006c6df7f9 (patch) | |
tree | ee4fe88d75690a72cb6efeaaf262c13a89a117f0 | |
parent | 652676fdc101cebbafcafd230047027625ec1d70 (diff) | |
download | serenity-d005b1ad1b085fc1758854084609a9006c6df7f9.zip |
LibWeb: Support loading file:// URLs via fetch (through ResourceLoader)
This builds on the existing ad-hoc ResourceLoader code for HTTP fetches
which works for files as well.
This also includes a test that checks that stylesheets loaded with the
"file" URL scheme actually work.
-rw-r--r-- | Tests/LibWeb/Layout/expected/link-sheet.txt | 4 | ||||
-rw-r--r-- | Tests/LibWeb/Layout/input/link-sheet.css | 7 | ||||
-rw-r--r-- | Tests/LibWeb/Layout/input/link-sheet.html | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h | 2 |
5 files changed, 17 insertions, 5 deletions
diff --git a/Tests/LibWeb/Layout/expected/link-sheet.txt b/Tests/LibWeb/Layout/expected/link-sheet.txt new file mode 100644 index 0000000000..0ef7355308 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/link-sheet.txt @@ -0,0 +1,4 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer <html> at (0,0) content-size 800x16 children: not-inline + BlockContainer <body> at (8,8) content-size 784x0 children: not-inline + BlockContainer <div#foo> at (0,0) content-size 123x456 positioned children: not-inline diff --git a/Tests/LibWeb/Layout/input/link-sheet.css b/Tests/LibWeb/Layout/input/link-sheet.css new file mode 100644 index 0000000000..4feef78b13 --- /dev/null +++ b/Tests/LibWeb/Layout/input/link-sheet.css @@ -0,0 +1,7 @@ +#foo { + position: absolute; + top: 0; + left: 0; + width: 123px; + height: 456px; +} diff --git a/Tests/LibWeb/Layout/input/link-sheet.html b/Tests/LibWeb/Layout/input/link-sheet.html new file mode 100644 index 0000000000..359b136bd4 --- /dev/null +++ b/Tests/LibWeb/Layout/input/link-sheet.html @@ -0,0 +1 @@ +<!DOCTYPE html><head><link rel="stylesheet" href="link-sheet.css"></head><body><div id="foo">
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index 1ab0a658c9..9289f234ed 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -722,8 +722,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> scheme_fetch(JS::Realm& r else if (request->current_url().scheme() == "file"sv) { // For now, unfortunate as it is, file: URLs are left as an exercise for the reader. // When in doubt, return a network error. - // FIXME: Support 'file://' URLs - return PendingResponse::create(vm, request, Infrastructure::Response::network_error(vm, "Request has 'file:' URL which is currently unsupported"sv)); + return TRY(nonstandard_resource_loader_file_or_http_network_fetch(realm, fetch_params)); } // -> HTTP(S) scheme else if (Infrastructure::is_http_or_https_scheme(request->current_url().scheme())) { @@ -1392,7 +1391,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet // 2. Let forwardResponse be the result of running HTTP-network fetch given httpFetchParams, includeCredentials, // and isNewConnectionFetch. - pending_forward_response = TRY(nonstandard_resource_loader_http_network_fetch(realm, *http_fetch_params, include_credentials, is_new_connection_fetch)); + pending_forward_response = TRY(nonstandard_resource_loader_file_or_http_network_fetch(realm, *http_fetch_params, include_credentials, is_new_connection_fetch)); } else { pending_forward_response = PendingResponse::create(vm, request, Infrastructure::Response::create(vm)); } @@ -1598,7 +1597,8 @@ static void log_response(auto const& status_code, auto const& headers, auto cons // https://fetch.spec.whatwg.org/#concept-http-network-fetch // Drop-in replacement for 'HTTP-network fetch', but obviously non-standard :^) -WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_loader_http_network_fetch(JS::Realm& realm, Infrastructure::FetchParams const& fetch_params, IncludeCredentials include_credentials, IsNewConnectionFetch is_new_connection_fetch) +// It also handles file:// URLs since those can also go through ResourceLoader. +WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_loader_file_or_http_network_fetch(JS::Realm& realm, Infrastructure::FetchParams const& fetch_params, IncludeCredentials include_credentials, IsNewConnectionFetch is_new_connection_fetch) { dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'non-standard HTTP-network fetch' with: fetch_params @ {}", &fetch_params); diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h index 06c9df0caf..e1c88aeccb 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h @@ -36,6 +36,6 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> scheme_fetch(JS::Realm&, WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_fetch(JS::Realm&, Infrastructure::FetchParams const&, MakeCORSPreflight make_cors_preflight = MakeCORSPreflight::No); WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_redirect_fetch(JS::Realm&, Infrastructure::FetchParams const&, Infrastructure::Response&); WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fetch(JS::Realm&, Infrastructure::FetchParams const&, IsAuthenticationFetch is_authentication_fetch = IsAuthenticationFetch::No, IsNewConnectionFetch is_new_connection_fetch = IsNewConnectionFetch::No); -WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_loader_http_network_fetch(JS::Realm&, Infrastructure::FetchParams const&, IncludeCredentials include_credentials = IncludeCredentials::No, IsNewConnectionFetch is_new_connection_fetch = IsNewConnectionFetch::No); +WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_loader_file_or_http_network_fetch(JS::Realm&, Infrastructure::FetchParams const&, IncludeCredentials include_credentials = IncludeCredentials::No, IsNewConnectionFetch is_new_connection_fetch = IsNewConnectionFetch::No); WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> cors_preflight_fetch(JS::Realm&, Infrastructure::Request&); } |