From 9072a7caefe529f402ce59c1ba4b9a18538302da Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 15 Feb 2025 23:51:45 +1300 Subject: [PATCH] Everywhere: Use URL::about_XXX factory functions --- Libraries/LibWeb/DOM/Document.cpp | 2 +- Libraries/LibWeb/DOM/Document.h | 2 +- Libraries/LibWeb/DOM/DocumentLoading.h | 4 ++-- Libraries/LibWeb/DOM/XMLDocument.h | 2 +- Libraries/LibWeb/HTML/BrowsingContext.cpp | 12 ++++++------ Libraries/LibWeb/HTML/HTMLDocument.h | 2 +- Libraries/LibWeb/HTML/HTMLIFrameElement.cpp | 4 ++-- Libraries/LibWeb/HTML/Location.cpp | 2 +- Libraries/LibWeb/HTML/Navigable.cpp | 6 +++--- Libraries/LibWeb/HTML/NavigableContainer.cpp | 2 +- Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp | 2 +- Libraries/LibWeb/HTML/Window.cpp | 2 +- Libraries/LibWeb/Page/Page.cpp | 2 +- .../LibWeb/SecureContexts/AbstractOperations.cpp | 2 +- Services/WebContent/PageHost.cpp | 2 +- UI/AppKit/Application/ApplicationDelegate.mm | 2 +- UI/Headless/Test.cpp | 4 ++-- UI/Headless/main.cpp | 2 +- 18 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index c269838b6a8..89033e44daa 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -422,7 +422,7 @@ GC::Ref Document::create(JS::Realm& realm, URL::URL const& url) GC::Ref Document::create_for_fragment_parsing(JS::Realm& realm) { - return realm.create(realm, "about:blank"sv, TemporaryDocumentForFragmentParsing::Yes); + return realm.create(realm, URL::about_blank(), TemporaryDocumentForFragmentParsing::Yes); } Document::Document(JS::Realm& realm, const URL::URL& url, TemporaryDocumentForFragmentParsing temporary_document_for_fragment_parsing) diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 5abb6567dd2..582f288d23e 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -103,7 +103,7 @@ public: static WebIDL::ExceptionOr> create_and_initialize(Type, String content_type, HTML::NavigationParams const&); - [[nodiscard]] static GC::Ref create(JS::Realm&, URL::URL const& url = "about:blank"sv); + [[nodiscard]] static GC::Ref create(JS::Realm&, URL::URL const& url = URL::about_blank()); [[nodiscard]] static GC::Ref create_for_fragment_parsing(JS::Realm&); static WebIDL::ExceptionOr> construct_impl(JS::Realm&); virtual ~Document() override; diff --git a/Libraries/LibWeb/DOM/DocumentLoading.h b/Libraries/LibWeb/DOM/DocumentLoading.h index 987da8403be..acf8f74f479 100644 --- a/Libraries/LibWeb/DOM/DocumentLoading.h +++ b/Libraries/LibWeb/DOM/DocumentLoading.h @@ -33,7 +33,7 @@ GC::Ref create_document_for_inline_content(GC::Ptr create_document_for_inline_content(GC::Ptrurl_list().append(URL::URL("about:error")); // AD-HOC: https://github.com/whatwg/html/issues/9122 + response->url_list().append(URL::about_error()); // AD-HOC: https://github.com/whatwg/html/issues/9122 auto navigation_params = vm.heap().allocate(); navigation_params->id = navigation_id; navigation_params->navigable = navigable; diff --git a/Libraries/LibWeb/DOM/XMLDocument.h b/Libraries/LibWeb/DOM/XMLDocument.h index b305de265b7..9d63b5d831a 100644 --- a/Libraries/LibWeb/DOM/XMLDocument.h +++ b/Libraries/LibWeb/DOM/XMLDocument.h @@ -15,7 +15,7 @@ class XMLDocument final : public Document { GC_DECLARE_ALLOCATOR(XMLDocument); public: - static GC::Ref create(JS::Realm&, URL::URL const& url = "about:blank"sv); + static GC::Ref create(JS::Realm&, URL::URL const& url = URL::about_blank()); virtual ~XMLDocument() override = default; private: diff --git a/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Libraries/LibWeb/HTML/BrowsingContext.cpp index 7a6ff4cd6a5..9592f795d1f 100644 --- a/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -73,7 +73,7 @@ URL::Origin determine_the_origin(Optional url, SandboxingFlagSe } // 3. If url is about:srcdoc, then: - if (url == "about:srcdoc"sv) { + if (url == URL::about_srcdoc()) { // 1. Assert: sourceOrigin is non-null. VERIFY(source_origin.has_value()); @@ -167,7 +167,7 @@ WebIDL::ExceptionOr BrowsingContext SandboxingFlagSet sandbox_flags = {}; // 7. Let origin be the result of determining the origin given about:blank, sandboxFlags, and creatorOrigin. - auto origin = determine_the_origin(URL::URL("about:blank"sv), sandbox_flags, creator_origin); + auto origin = determine_the_origin(URL::about_blank(), sandbox_flags, creator_origin); // FIXME: 8. Let permissionsPolicy be the result of creating a permissions policy given embedder and origin. [PERMISSIONSPOLICY] @@ -192,7 +192,7 @@ WebIDL::ExceptionOr BrowsingContext }); // 11. Let topLevelCreationURL be about:blank if embedder is null; otherwise embedder's relevant settings object's top-level creation URL. - auto top_level_creation_url = !embedder ? URL::URL("about:blank") : relevant_settings_object(*embedder).top_level_creation_url; + auto top_level_creation_url = !embedder ? URL::about_blank() : relevant_settings_object(*embedder).top_level_creation_url; // 12. Let topLevelOrigin be origin if embedder is null; otherwise embedder's relevant settings object's top-level origin. auto top_level_origin = !embedder ? origin : relevant_settings_object(*embedder).origin(); @@ -200,7 +200,7 @@ WebIDL::ExceptionOr BrowsingContext // 13. Set up a window environment settings object with about:blank, realm execution context, null, topLevelCreationURL, and topLevelOrigin. WindowEnvironmentSettingsObject::setup( page, - URL::URL("about:blank"), + URL::about_blank(), move(realm_execution_context), {}, top_level_creation_url, @@ -271,8 +271,8 @@ WebIDL::ExceptionOr BrowsingContext } // 17. Assert: document's URL and document's relevant settings object's creation URL are about:blank. - VERIFY(document->url() == "about:blank"sv); - VERIFY(document->relevant_settings_object().creation_url == "about:blank"sv); + VERIFY(document->url() == URL::about_blank()); + VERIFY(document->relevant_settings_object().creation_url == URL::about_blank()); // 18. Mark document as ready for post-load tasks. document->set_ready_for_post_load_tasks(true); diff --git a/Libraries/LibWeb/HTML/HTMLDocument.h b/Libraries/LibWeb/HTML/HTMLDocument.h index 2c1e52325f3..24002cbae57 100644 --- a/Libraries/LibWeb/HTML/HTMLDocument.h +++ b/Libraries/LibWeb/HTML/HTMLDocument.h @@ -21,7 +21,7 @@ class HTMLDocument final : public DOM::Document { public: virtual ~HTMLDocument() override; - [[nodiscard]] static GC::Ref create(JS::Realm&, URL::URL const& url = "about:blank"sv); + [[nodiscard]] static GC::Ref create(JS::Realm&, URL::URL const& url = URL::about_blank()); WebIDL::ExceptionOr> construct_impl(JS::Realm&); private: diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 7ebb0f6804c..2bcb0c3cd58 100644 --- a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -104,7 +104,7 @@ void HTMLIFrameElement::process_the_iframe_attributes(bool initial_insertion) // 1. Set element's lazy load resumption steps to the rest of this algorithm starting with the step labeled navigate to the srcdoc resource. set_lazy_load_resumption_steps([this]() { // 3. Navigate to the srcdoc resource: navigate an iframe or frame given element, about:srcdoc, the empty string, and the value of element's srcdoc attribute. - navigate_an_iframe_or_frame(URL::URL("about:srcdoc"sv), ReferrerPolicy::ReferrerPolicy::EmptyString, get_attribute(HTML::AttributeNames::srcdoc)); + navigate_an_iframe_or_frame(URL::about_srcdoc(), ReferrerPolicy::ReferrerPolicy::EmptyString, get_attribute(HTML::AttributeNames::srcdoc)); // FIXME: The resulting Document must be considered an iframe srcdoc document. }); @@ -120,7 +120,7 @@ void HTMLIFrameElement::process_the_iframe_attributes(bool initial_insertion) } // 3. Navigate to the srcdoc resource: navigate an iframe or frame given element, about:srcdoc, the empty string, and the value of element's srcdoc attribute. - navigate_an_iframe_or_frame(URL::URL("about:srcdoc"sv), ReferrerPolicy::ReferrerPolicy::EmptyString, get_attribute(HTML::AttributeNames::srcdoc)); + navigate_an_iframe_or_frame(URL::about_srcdoc(), ReferrerPolicy::ReferrerPolicy::EmptyString, get_attribute(HTML::AttributeNames::srcdoc)); // FIXME: The resulting Document must be considered an iframe srcdoc document. diff --git a/Libraries/LibWeb/HTML/Location.cpp b/Libraries/LibWeb/HTML/Location.cpp index 4913c2d5c71..ab623084d37 100644 --- a/Libraries/LibWeb/HTML/Location.cpp +++ b/Libraries/LibWeb/HTML/Location.cpp @@ -112,7 +112,7 @@ URL::URL Location::url() const // A Location object has an associated url, which is this Location object's relevant Document's URL, // if this Location object's relevant Document is non-null, and about:blank otherwise. auto const relevant_document = this->relevant_document(); - return relevant_document ? relevant_document->url() : "about:blank"sv; + return relevant_document ? relevant_document->url() : URL::about_blank(); } // https://html.spec.whatwg.org/multipage/history.html#dom-location-href diff --git a/Libraries/LibWeb/HTML/Navigable.cpp b/Libraries/LibWeb/HTML/Navigable.cpp index dd8d3a94b9c..c9a14691ecc 100644 --- a/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Libraries/LibWeb/HTML/Navigable.cpp @@ -625,7 +625,7 @@ static PolicyContainer determine_navigation_params_policy_container(URL::URL con } // 2. If responseURL is about:srcdoc, then: - if (response_url == "about:srcdoc"sv) { + if (response_url == URL::about_srcdoc()) { // 1. Assert: parentPolicyContainer is not null. VERIFY(parent_policy_container.has_value()); @@ -699,7 +699,7 @@ static GC::Ref create_navigation_params_from_a_srcdoc_resource // header list: (`Content-Type`, `text/html`) // body: the UTF-8 encoding of documentResource, as a body auto response = Fetch::Infrastructure::Response::create(vm); - response->url_list().append(URL::URL("about:srcdoc")); + response->url_list().append(URL::about_srcdoc()); auto header = Fetch::Infrastructure::Header::from_string_pair("Content-Type"sv, "text/html"sv); response->header_list()->append(move(header)); @@ -1254,7 +1254,7 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( auto error_html = load_error_page(entry->url(), error_message).release_value_but_fixme_should_propagate_errors(); entry->document_state()->set_document(create_document_for_inline_content(this, navigation_id, user_involvement, [this, error_html](auto& document) { auto parser = HTML::HTMLParser::create(document, error_html, "utf-8"sv); - document.set_url(URL::URL("about:error")); + document.set_url(URL::about_error()); parser->run(); // NOTE: Once the page has been set up, the user agent must act as if it had stopped parsing. diff --git a/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Libraries/LibWeb/HTML/NavigableContainer.cpp index 63b309ff3c8..720252e1f1e 100644 --- a/Libraries/LibWeb/HTML/NavigableContainer.cpp +++ b/Libraries/LibWeb/HTML/NavigableContainer.cpp @@ -203,7 +203,7 @@ Optional NavigableContainer::shared_attribute_processing_steps_for_ifr return {}; // 1. Let url be the URL record about:blank. - auto url = URL::URL("about:blank"); + auto url = URL::about_blank(); // 2. If element has a src attribute specified, and its value is not the empty string, // then parse the value of that attribute relative to element's node document. diff --git a/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp b/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp index a9fa9a45e63..82197ff86ca 100644 --- a/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp +++ b/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp @@ -26,7 +26,7 @@ GC::Ref ClassicScript::create(ByteString filename, StringView sou // 1. If muted errors is true, then set baseURL to about:blank. if (muted_errors == MutedErrors::Yes) - base_url = "about:blank"sv; + base_url = URL::about_blank(); // 2. If scripting is disabled for realm, then set source to the empty string. if (is_scripting_disabled(realm)) diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp index c49b53d6d4d..7e49b592e73 100644 --- a/Libraries/LibWeb/HTML/Window.cpp +++ b/Libraries/LibWeb/HTML/Window.cpp @@ -255,7 +255,7 @@ WebIDL::ExceptionOr Window::window_open_steps_internal(Str // 3. If urlRecord is null, then set urlRecord to a URL record representing about:blank. if (!url_record.has_value()) - url_record = URL::URL("about:blank"sv); + url_record = URL::about_blank(); // 4. If urlRecord matches about:blank, then perform the URL and history update steps given targetNavigable's active document and urlRecord. if (url_matches_about_blank(url_record.value())) { diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp index e882d8fc3ef..61fec2ad7e5 100644 --- a/Libraries/LibWeb/Page/Page.cpp +++ b/Libraries/LibWeb/Page/Page.cpp @@ -73,7 +73,7 @@ void Page::load_html(StringView html) // FIXME: #23909 Figure out why GC threshold does not stay low when repeatedly loading html from the WebView heap().collect_garbage(); - (void)top_level_traversable()->navigate({ .url = "about:srcdoc"sv, + (void)top_level_traversable()->navigate({ .url = URL::about_srcdoc(), .source_document = *top_level_traversable()->active_document(), .document_resource = String::from_utf8(html).release_value_but_fixme_should_propagate_errors(), .user_involvement = HTML::UserNavigationInvolvement::BrowserUI }); diff --git a/Libraries/LibWeb/SecureContexts/AbstractOperations.cpp b/Libraries/LibWeb/SecureContexts/AbstractOperations.cpp index 9855e5f964c..a249d91e4d8 100644 --- a/Libraries/LibWeb/SecureContexts/AbstractOperations.cpp +++ b/Libraries/LibWeb/SecureContexts/AbstractOperations.cpp @@ -72,7 +72,7 @@ Trustworthiness is_origin_potentially_trustworthy(URL::Origin const& origin) Trustworthiness is_url_potentially_trustworthy(URL::URL const& url) { // 1. If url is "about:blank" or "about:srcdoc", return "Potentially Trustworthy". - if (url == "about:blank"sv || url == "about:srcdoc"sv) + if (url == URL::about_blank() || url == URL::about_srcdoc()) return Trustworthiness::PotentiallyTrustworthy; // 2. If url’s scheme is "data", return "Potentially Trustworthy". diff --git a/Services/WebContent/PageHost.cpp b/Services/WebContent/PageHost.cpp index a85ac31e29b..53dc96d5e7b 100644 --- a/Services/WebContent/PageHost.cpp +++ b/Services/WebContent/PageHost.cpp @@ -19,7 +19,7 @@ PageHost::PageHost(ConnectionFromClient& client) : m_client(client) { auto& first_page = create_page(); - Web::HTML::TraversableNavigable::create_a_fresh_top_level_traversable(first_page.page(), URL::URL("about:blank")).release_value_but_fixme_should_propagate_errors(); + Web::HTML::TraversableNavigable::create_a_fresh_top_level_traversable(first_page.page(), URL::about_blank()).release_value_but_fixme_should_propagate_errors(); } PageClient& PageHost::create_page() diff --git a/UI/AppKit/Application/ApplicationDelegate.mm b/UI/AppKit/Application/ApplicationDelegate.mm index d3bbd71425d..2b2332889ec 100644 --- a/UI/AppKit/Application/ApplicationDelegate.mm +++ b/UI/AppKit/Application/ApplicationDelegate.mm @@ -180,7 +180,7 @@ return; } - [self createNewTab:URL::URL("about:version"sv) + [self createNewTab:URL::URL(URL::about_version()) fromTab:(Tab*)current_tab activateTab:Web::HTML::ActivateTab::Yes]; } diff --git a/UI/Headless/Test.cpp b/UI/Headless/Test.cpp index 50ce346d5d0..fff379f8d2b 100644 --- a/UI/Headless/Test.cpp +++ b/UI/Headless/Test.cpp @@ -382,7 +382,7 @@ static void run_test(HeadlessWebView& view, Test& test, Application& app) auto promise = Core::Promise::construct(); view.on_load_finish = [promise](auto const& url) { - if (!url.equals("about:blank"sv)) + if (!url.equals(URL::about_blank())) return; Core::deferred_invoke([promise]() { @@ -411,7 +411,7 @@ static void run_test(HeadlessWebView& view, Test& test, Application& app) VERIFY_NOT_REACHED(); }); - view.load("about:blank"sv); + view.load(URL::about_blank()); } static void set_ui_callbacks_for_tests(HeadlessWebView& view) diff --git a/UI/Headless/main.cpp b/UI/Headless/main.cpp index 158d659e8af..f651651182f 100644 --- a/UI/Headless/main.cpp +++ b/UI/Headless/main.cpp @@ -63,7 +63,7 @@ ErrorOr serenity_main(Main::Arguments arguments) { WebView::platform_init(); - auto app = Ladybird::Application::create(arguments, "about:newtab"sv); + auto app = Ladybird::Application::create(arguments, URL::about_newtab()); TRY(app->launch_services()); Core::ResourceImplementation::install(make(MUST(String::from_byte_string(app->resources_folder))));