From 51caa1438190d4ece616142cda23c9a8c0f2ed40 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 19 Sep 2023 19:16:50 +0200 Subject: [PATCH] LibWeb: Remove FrameLoader This class is no longer used, now that we've moved to navigables. --- .../src/main/cpp/WebContentService.cpp | 9 +- Ladybird/WebContent/main.cpp | 9 +- .../Userland/Libraries/LibWeb/Loader/BUILD.gn | 1 - Userland/Libraries/LibWeb/CMakeLists.txt | 1 - Userland/Libraries/LibWeb/CSS/MediaQuery.cpp | 1 + .../CSS/StyleValues/IdentifierStyleValue.cpp | 1 + Userland/Libraries/LibWeb/Forward.h | 1 - .../Libraries/LibWeb/HTML/BrowsingContext.cpp | 1 - .../Libraries/LibWeb/HTML/BrowsingContext.h | 5 - .../LibWeb/HTML/BrowsingContextGroup.cpp | 1 + .../LibWeb/HTML/HTMLHyperlinkElementUtils.cpp | 1 - .../LibWeb/HTML/HTMLInputElement.cpp | 1 + Userland/Libraries/LibWeb/HTML/Navigable.cpp | 1 + .../LibWeb/HTML/TraversableNavigable.cpp | 1 + .../Libraries/LibWeb/Internals/Internals.cpp | 1 + Userland/Libraries/LibWeb/Layout/Node.cpp | 1 + .../LibWeb/Loader/FileDirectoryLoader.cpp | 29 +- .../LibWeb/Loader/FileDirectoryLoader.h | 4 + .../Libraries/LibWeb/Loader/FrameLoader.cpp | 365 ------------------ .../Libraries/LibWeb/Loader/FrameLoader.h | 60 --- Userland/Libraries/LibWeb/Page/Page.cpp | 5 - Userland/Libraries/LibWeb/Page/Page.h | 2 - .../LibWeb/Painting/MediaPaintable.cpp | 1 + .../LibWeb/SVG/SVGDecodedImageData.cpp | 1 + .../Libraries/LibWeb/SVG/SVGTitleElement.cpp | 1 + Userland/Utilities/headless-browser.cpp | 1 - 26 files changed, 47 insertions(+), 458 deletions(-) delete mode 100644 Userland/Libraries/LibWeb/Loader/FrameLoader.cpp delete mode 100644 Userland/Libraries/LibWeb/Loader/FrameLoader.h diff --git a/Ladybird/Android/src/main/cpp/WebContentService.cpp b/Ladybird/Android/src/main/cpp/WebContentService.cpp index f90a7db2ba..d752c94c73 100644 --- a/Ladybird/Android/src/main/cpp/WebContentService.cpp +++ b/Ladybird/Android/src/main/cpp/WebContentService.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -59,8 +59,6 @@ ErrorOr service_main(int ipc_socket, int fd_passing_socket) return Error::from_string_literal("Don't know how to initialize audio in this configuration!"); }); - Web::FrameLoader::set_default_favicon_path(DeprecatedString::formatted("{}/res/icons/16x16/app-browser.png", s_serenity_resource_root)); - auto request_server_client = TRY(bind_request_server_service()); Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create(move(request_server_client)))); @@ -72,9 +70,8 @@ ErrorOr service_main(int ipc_socket, int fd_passing_socket) Web::HTML::Window::set_internals_object_exposed(is_layout_test_mode); Web::Platform::FontPlugin::install(*new Ladybird::FontPlugin(is_layout_test_mode)); - Web::FrameLoader::set_resource_directory_url(DeprecatedString::formatted("file://{}/res", s_serenity_resource_root)); - Web::FrameLoader::set_error_page_url(DeprecatedString::formatted("file://{}/res/html/error.html", s_serenity_resource_root)); - Web::FrameLoader::set_directory_page_url(DeprecatedString::formatted("file://{}/res/html/directory.html", s_serenity_resource_root)); + Web::set_resource_directory_url(DeprecatedString::formatted("file://{}/res", s_serenity_resource_root)); + Web::set_directory_page_url(DeprecatedString::formatted("file://{}/res/html/directory.html", s_serenity_resource_root)); TRY(Web::Bindings::initialize_main_thread_vm()); diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index d78a2971e7..60f521335f 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -70,8 +70,6 @@ ErrorOr serenity_main(Main::Arguments arguments) #endif }); - Web::FrameLoader::set_default_favicon_path(DeprecatedString::formatted("{}/res/icons/16x16/app-browser.png", s_serenity_resource_root)); - int webcontent_fd_passing_socket { -1 }; bool is_layout_test_mode = false; bool use_lagom_networking = false; @@ -98,9 +96,8 @@ ErrorOr serenity_main(Main::Arguments arguments) Web::Platform::FontPlugin::install(*new Ladybird::FontPlugin(is_layout_test_mode)); - Web::FrameLoader::set_resource_directory_url(DeprecatedString::formatted("file://{}/res", s_serenity_resource_root)); - Web::FrameLoader::set_error_page_url(DeprecatedString::formatted("file://{}/res/html/error.html", s_serenity_resource_root)); - Web::FrameLoader::set_directory_page_url(DeprecatedString::formatted("file://{}/res/html/directory.html", s_serenity_resource_root)); + Web::set_resource_directory_url(DeprecatedString::formatted("file://{}/res", s_serenity_resource_root)); + Web::set_directory_page_url(DeprecatedString::formatted("file://{}/res/html/directory.html", s_serenity_resource_root)); TRY(Web::Bindings::initialize_main_thread_vm()); diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/Loader/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/Loader/BUILD.gn index 0e7fedcd1e..be62541597 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/Loader/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/Loader/BUILD.gn @@ -5,7 +5,6 @@ source_set("Loader") { "ContentFilter.cpp", "FileDirectoryLoader.cpp", "FileRequest.cpp", - "FrameLoader.cpp", "LoadRequest.cpp", "ProxyMappings.cpp", "Resource.cpp", diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index e2aad66281..926dca29ff 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -462,7 +462,6 @@ set(SOURCES Loader/ContentFilter.cpp Loader/FileDirectoryLoader.cpp Loader/FileRequest.cpp - Loader/FrameLoader.cpp Loader/LoadRequest.cpp Loader/ProxyMappings.cpp Loader/Resource.cpp diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp index f491b01907..29f6a2b288 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/IdentifierStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/IdentifierStyleValue.cpp index 4afd031017..7adaeb53b2 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/IdentifierStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/IdentifierStyleValue.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index b0d6090b6b..8380604898 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -13,7 +13,6 @@ namespace Web { class EditEventHandler; class EventHandler; -class FrameLoader; class LoadRequest; class Page; class PageClient; diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 3b1d4a5f3b..2607de5492 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -254,7 +254,6 @@ WebIDL::ExceptionOr BrowsingContext BrowsingContext::BrowsingContext(Page& page, HTML::NavigableContainer* container) : m_page(page) - , m_loader(*this) , m_event_handler({}, *this) , m_container(container) { diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h index 0c8047f5a3..df497a8043 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -133,9 +132,6 @@ public: Page* page() { return m_page; } Page const* page() const { return m_page; } - FrameLoader& loader() { return m_loader; } - FrameLoader const& loader() const { return m_loader; } - Web::EventHandler& event_handler() { return m_event_handler; } Web::EventHandler const& event_handler() const { return m_event_handler; } @@ -226,7 +222,6 @@ private: WeakPtr m_page; - FrameLoader m_loader; Web::EventHandler m_event_handler; // https://html.spec.whatwg.org/multipage/history.html#current-entry diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContextGroup.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContextGroup.cpp index c340f1bc73..63f10ec0c0 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContextGroup.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContextGroup.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace Web::HTML { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp b/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp index cdb22be3bf..ffb16cc75e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp @@ -8,7 +8,6 @@ #include #include #include -#include namespace Web::HTML { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index b7768845a2..5f5a3b53b8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp index d2fbc63d6a..a1bf8e8a84 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index 3e0905e2e3..d33b61888e 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace Web::HTML { diff --git a/Userland/Libraries/LibWeb/Internals/Internals.cpp b/Userland/Libraries/LibWeb/Internals/Internals.cpp index bba926c5d0..bb37715285 100644 --- a/Userland/Libraries/LibWeb/Internals/Internals.cpp +++ b/Userland/Libraries/LibWeb/Internals/Internals.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace Web::Internals { diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index e6ba0f095e..a223e4de6b 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include namespace Web::Layout { diff --git a/Userland/Libraries/LibWeb/Loader/FileDirectoryLoader.cpp b/Userland/Libraries/LibWeb/Loader/FileDirectoryLoader.cpp index 1b9e75d23b..6fb627ab52 100644 --- a/Userland/Libraries/LibWeb/Loader/FileDirectoryLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FileDirectoryLoader.cpp @@ -11,10 +11,33 @@ #include #include #include -#include namespace Web { +static DeprecatedString s_resource_directory_url = "file:///res"; + +DeprecatedString resource_directory_url() +{ + return s_resource_directory_url; +} + +void set_resource_directory_url(DeprecatedString resource_directory_url) +{ + s_resource_directory_url = resource_directory_url; +} + +static DeprecatedString s_directory_page_url = "file:///res/html/directory.html"; + +DeprecatedString directory_page_url() +{ + return s_directory_page_url; +} + +void set_directory_page_url(DeprecatedString directory_page_url) +{ + s_directory_page_url = directory_page_url; +} + ErrorOr load_file_directory_page(LoadRequest const& request) { // Generate HTML contents entries table @@ -46,12 +69,12 @@ ErrorOr load_file_directory_page(LoadRequest const& request) // Generate HTML directory page from directory template file // FIXME: Use an actual templating engine (our own one when it's built, preferably with a way to check these usages at compile time) - auto template_path = AK::URL::create_with_url_or_path(FrameLoader::directory_page_url()).serialize_path(); + auto template_path = AK::URL::create_with_url_or_path(directory_page_url()).serialize_path(); auto template_file = TRY(Core::File::open(template_path, Core::File::OpenMode::Read)); auto template_contents = TRY(template_file->read_until_eof()); StringBuilder builder; SourceGenerator generator { builder }; - generator.set("resource_directory_url", FrameLoader::resource_directory_url()); + generator.set("resource_directory_url", resource_directory_url()); generator.set("path", escape_html_entities(lexical_path.string())); generator.set("parent_path", escape_html_entities(lexical_path.parent().string())); generator.set("contents", contents.to_deprecated_string()); diff --git a/Userland/Libraries/LibWeb/Loader/FileDirectoryLoader.h b/Userland/Libraries/LibWeb/Loader/FileDirectoryLoader.h index e7a22e6fab..994cde189b 100644 --- a/Userland/Libraries/LibWeb/Loader/FileDirectoryLoader.h +++ b/Userland/Libraries/LibWeb/Loader/FileDirectoryLoader.h @@ -11,5 +11,9 @@ namespace Web { ErrorOr load_file_directory_page(LoadRequest const&); +DeprecatedString resource_directory_url(); +void set_resource_directory_url(DeprecatedString); +DeprecatedString directory_page_url(); +void set_directory_page_url(DeprecatedString); } diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp deleted file mode 100644 index a3b8bb3ba5..0000000000 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 2020-2022, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Web { - -static DeprecatedString s_default_favicon_path = "/res/icons/16x16/app-browser.png"; -static RefPtr s_default_favicon_bitmap; - -void FrameLoader::set_default_favicon_path(DeprecatedString path) -{ - s_default_favicon_path = move(path); -} - -FrameLoader::FrameLoader(HTML::BrowsingContext& browsing_context) - : m_browsing_context(browsing_context) -{ - if (!s_default_favicon_bitmap) { - s_default_favicon_bitmap = Gfx::Bitmap::load_from_file(s_default_favicon_path).release_value_but_fixme_should_propagate_errors(); - VERIFY(s_default_favicon_bitmap); - } -} - -FrameLoader::~FrameLoader() = default; - -bool FrameLoader::load(LoadRequest& request, Type type) -{ - if (!request.is_valid()) { - load_error_page(request.url(), "Invalid request"); - return false; - } - - if (!m_browsing_context->is_frame_nesting_allowed(request.url())) { - dbgln("No further recursion is allowed for the frame, abort load!"); - return false; - } - - request.set_main_resource(true); - - auto& url = request.url(); - - if (type == Type::Navigation || type == Type::Reload || type == Type::Redirect) { - if (auto* page = browsing_context().page()) { - if (&page->top_level_browsing_context() == m_browsing_context) - page->client().page_did_start_loading(url, type == Type::Redirect); - } - } - - // https://fetch.spec.whatwg.org/#concept-fetch - // Step 12: If request’s header list does not contain `Accept`, then: - // 1. Let value be `*/*`. (NOTE: Not necessary as we're about to override it) - // 2. A user agent should set value to the first matching statement, if any, switching on request’s destination: - // -> "document" - // -> "frame" - // -> "iframe" - // `text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8` - if (!request.headers().contains("Accept")) - request.set_header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); - - // HACK: We're crudely computing the referer value and shoving it into the - // request until fetch infrastructure is used here. - auto referrer_url = ReferrerPolicy::strip_url_for_use_as_referrer(url); - if (referrer_url.has_value() && !request.headers().contains("Referer")) - request.set_header("Referer", referrer_url->serialize()); - - set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request)); - - if (type == Type::IFrame) - return true; - - if (url.scheme() == "http" || url.scheme() == "https") { - AK::URL favicon_url; - 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" }); - - ResourceLoader::the().load( - favicon_url, - [this, favicon_url](auto data, auto&, auto) { - // Always fetch the current document - auto* document = this->browsing_context().active_document(); - if (document && document->has_active_favicon()) - return; - dbgln_if(SPAM_DEBUG, "Favicon downloaded, {} bytes from {}", data.size(), favicon_url); - if (data.is_empty()) - return; - RefPtr favicon_bitmap; - auto decoded_image = Platform::ImageCodecPlugin::the().decode_image(data); - if (!decoded_image.has_value() || decoded_image->frames.is_empty()) { - dbgln("Could not decode favicon {}", favicon_url); - } else { - favicon_bitmap = decoded_image->frames[0].bitmap; - dbgln_if(IMAGE_DECODER_DEBUG, "Decoded favicon, {}", favicon_bitmap->size()); - } - load_favicon(favicon_bitmap); - }, - [this](auto&, auto) { - // Always fetch the current document - auto* document = this->browsing_context().active_document(); - if (document && document->has_active_favicon()) - return; - - load_favicon(); - }); - } else { - load_favicon(); - } - - return true; -} - -bool FrameLoader::load(const AK::URL& url, Type type) -{ - dbgln_if(SPAM_DEBUG, "FrameLoader::load: {}", url); - - if (!url.is_valid()) { - load_error_page(url, "Invalid URL"); - return false; - } - - auto request = LoadRequest::create_for_url_on_page(url, browsing_context().page()); - return load(request, type); -} - -void FrameLoader::load_html(StringView html, const AK::URL& url) -{ - if (auto* page = browsing_context().page()) - page->client().page_did_start_loading(url, false); - - auto& vm = Bindings::main_thread_vm(); - auto response = Fetch::Infrastructure::Response::create(vm); - response->url_list().append(url); - HTML::NavigationParams navigation_params { - .id = {}, - .request = nullptr, - .response = response, - .origin = HTML::Origin {}, - .policy_container = HTML::PolicyContainer {}, - .final_sandboxing_flag_set = HTML::SandboxingFlagSet {}, - .cross_origin_opener_policy = HTML::CrossOriginOpenerPolicy {}, - .coop_enforcement_result = HTML::CrossOriginOpenerPolicyEnforcementResult {}, - .reserved_environment = {}, - .browsing_context = browsing_context(), - .navigable = nullptr, - }; - auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html", navigation_params).release_value_but_fixme_should_propagate_errors(); - // browsing_context().set_active_document(document); - - auto parser = HTML::HTMLParser::create(document, html, "utf-8"); - parser->run(url); - - if (auto* page = browsing_context().page()) - page->client().page_did_finish_loading(url); -} - -static DeprecatedString s_resource_directory_url = "file:///res"; - -DeprecatedString FrameLoader::resource_directory_url() -{ - return s_resource_directory_url; -} - -void FrameLoader::set_resource_directory_url(DeprecatedString resource_directory_url) -{ - s_resource_directory_url = resource_directory_url; -} - -static DeprecatedString s_error_page_url = "file:///res/html/error.html"; - -DeprecatedString FrameLoader::error_page_url() -{ - return s_error_page_url; -} - -void FrameLoader::set_error_page_url(DeprecatedString error_page_url) -{ - s_error_page_url = error_page_url; -} - -static DeprecatedString s_directory_page_url = "file:///res/html/directory.html"; - -DeprecatedString FrameLoader::directory_page_url() -{ - return s_directory_page_url; -} - -void FrameLoader::set_directory_page_url(DeprecatedString directory_page_url) -{ - s_directory_page_url = directory_page_url; -} - -// FIXME: Use an actual templating engine (our own one when it's built, preferably -// with a way to check these usages at compile time) - -void FrameLoader::load_error_page(const AK::URL& failed_url, DeprecatedString const& error) -{ - LoadRequest request = LoadRequest::create_for_url_on_page(s_error_page_url, browsing_context().page()); - - ResourceLoader::the().load( - request, - [this, failed_url, error](auto data, auto&, auto) { - VERIFY(!data.is_null()); - StringBuilder builder; - SourceGenerator generator { builder }; - generator.set("resource_directory_url", resource_directory_url()); - generator.set("failed_url", escape_html_entities(failed_url.to_deprecated_string())); - generator.set("error", escape_html_entities(error)); - generator.append(data); - load_html(generator.as_string_view(), s_error_page_url); - }, - [](auto& error, auto) { - dbgln("Failed to load error page: {}", error); - VERIFY_NOT_REACHED(); - }); -} - -void FrameLoader::load_favicon(RefPtr bitmap) -{ - if (auto* page = browsing_context().page()) { - if (bitmap) - page->client().page_did_change_favicon(*bitmap); - else if (s_default_favicon_bitmap) - page->client().page_did_change_favicon(*s_default_favicon_bitmap); - } -} - -void FrameLoader::resource_did_load() -{ - // This prevents us setting up the document of a removed browsing context container (BCC, e.g.