diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp index 7929915f55..ffe3f64c11 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp @@ -437,7 +437,7 @@ int main(int argc, char** argv) return 1; } - if (namespace_.is_one_of("CSS", "DOM", "HTML", "UIEvents", "HighResolutionTime", "NavigationTiming", "SVG", "XHR")) { + if (namespace_.is_one_of("CSS", "DOM", "HTML", "UIEvents", "HighResolutionTime", "NavigationTiming", "SVG", "XHR", "URL")) { StringBuilder builder; builder.append(namespace_); builder.append("::"); @@ -968,6 +968,8 @@ static void generate_header(IDL::Interface const& interface) # include #elif __has_include() # include +#elif __has_include() +# include #endif )~~~"); @@ -1235,6 +1237,8 @@ void generate_constructor_implementation(IDL::Interface const& interface) # include #elif __has_include() # include +#elif __has_include() +# include #endif // FIXME: This is a total hack until we can figure out the namespace for a given type somehow. @@ -1504,6 +1508,8 @@ void generate_prototype_implementation(IDL::Interface const& interface) # include #elif __has_include() # include +#elif __has_include() +# include #endif // FIXME: This is a total hack until we can figure out the namespace for a given type somehow. @@ -1512,6 +1518,7 @@ using namespace Web::DOM; using namespace Web::HTML; using namespace Web::NavigationTiming; using namespace Web::XHR; +using namespace Web::URL; namespace Web::Bindings { diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 3bd037fe22..117f81f447 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -230,7 +230,7 @@ set(SOURCES StylePropertiesModel.cpp UIEvents/EventNames.cpp UIEvents/MouseEvent.cpp - URLEncoder.cpp + URL/URL.cpp WebAssembly/WebAssemblyInstanceConstructor.cpp WebAssembly/WebAssemblyInstanceObject.cpp WebAssembly/WebAssemblyInstanceObjectPrototype.cpp diff --git a/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp index 0c75ed71ca..bb7a009425 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp @@ -10,7 +10,7 @@ namespace Web::CSS { -CSSImportRule::CSSImportRule(URL url) +CSSImportRule::CSSImportRule(AK::URL url) : m_url(move(url)) { } diff --git a/Userland/Libraries/LibWeb/CSS/CSSImportRule.h b/Userland/Libraries/LibWeb/CSS/CSSImportRule.h index cd3cc32b81..839555a5da 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSImportRule.h +++ b/Userland/Libraries/LibWeb/CSS/CSSImportRule.h @@ -16,14 +16,14 @@ class CSSImportRule : public CSSRule { AK_MAKE_NONMOVABLE(CSSImportRule); public: - static NonnullRefPtr create(URL url) + static NonnullRefPtr create(AK::URL url) { return adopt_ref(*new CSSImportRule(move(url))); } ~CSSImportRule(); - const URL& url() const { return m_url; } + const AK::URL& url() const { return m_url; } bool has_import_result() const { return !m_style_sheet.is_null(); } RefPtr loaded_style_sheet() { return m_style_sheet; } @@ -34,9 +34,9 @@ public: virtual Type type() const { return Type::Import; }; private: - explicit CSSImportRule(URL); + explicit CSSImportRule(AK::URL); - URL m_url; + AK::URL m_url; RefPtr m_style_sheet; }; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index a8bd5a767c..cd1372985f 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -50,9 +50,9 @@ bool ParsingContext::in_quirks_mode() const return m_document ? m_document->in_quirks_mode() : false; } -URL ParsingContext::complete_url(String const& addr) const +AK::URL ParsingContext::complete_url(String const& addr) const { - return m_document ? m_document->url().complete_url(addr) : URL::create_with_url_or_path(addr); + return m_document ? m_document->url().complete_url(addr) : AK::URL::create_with_url_or_path(addr); } template @@ -1159,7 +1159,7 @@ Vector> Parser::parse_a_comma_separated_list_of_ return lists; } -Optional Parser::parse_url_function(ParsingContext const& context, StyleComponentValueRule const& component_value) +Optional Parser::parse_url_function(ParsingContext const& context, StyleComponentValueRule const& component_value) { // FIXME: Handle list of media queries. https://www.w3.org/TR/css-cascade-3/#conditional-import // FIXME: Handle data: urls (RFC2397) @@ -1201,7 +1201,7 @@ RefPtr Parser::convert_to_rule(NonnullRefPtr rule) return {}; } else if (rule->m_name.equals_ignoring_case("import"sv) && !rule->prelude().is_empty()) { - Optional url; + Optional url; for (auto& token : rule->prelude()) { if (token.is(Token::Type::Whitespace)) continue; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index a343f5c711..3777251f48 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -38,7 +38,7 @@ public: bool in_quirks_mode() const; DOM::Document* document() const { return m_document; } - URL complete_url(String const&) const; + AK::URL complete_url(String const&) const; PropertyID current_property_id() const { return m_current_property_id; } void set_current_property_id(PropertyID property_id) { m_current_property_id = property_id; } @@ -172,7 +172,7 @@ private: static Optional try_parse_float(StringView string); static Optional parse_color(ParsingContext const&, StyleComponentValueRule const&); static Optional parse_length(ParsingContext const&, StyleComponentValueRule const&); - static Optional parse_url_function(ParsingContext const&, StyleComponentValueRule const&); + static Optional parse_url_function(ParsingContext const&, StyleComponentValueRule const&); Result, ParsingResult> parse_css_value(PropertyID, TokenStream&); static RefPtr parse_css_value(ParsingContext const&, StyleComponentValueRule const&); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 8f462166ce..481de75603 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -152,7 +152,7 @@ Color IdentifierStyleValue::to_color(const DOM::Document& document) const } } -ImageStyleValue::ImageStyleValue(const URL& url, DOM::Document& document) +ImageStyleValue::ImageStyleValue(const AK::URL& url, DOM::Document& document) : StyleValue(Type::Image) , m_url(url) , m_document(document) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index b8a7219108..bba3b18f3d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -651,7 +651,7 @@ class ImageStyleValue final : public StyleValue , public ImageResourceClient { public: - static NonnullRefPtr create(const URL& url, DOM::Document& document) { return adopt_ref(*new ImageStyleValue(url, document)); } + static NonnullRefPtr create(const AK::URL& url, DOM::Document& document) { return adopt_ref(*new ImageStyleValue(url, document)); } virtual ~ImageStyleValue() override { } String to_string() const override { return String::formatted("Image({})", m_url.to_string()); } @@ -659,12 +659,12 @@ public: const Gfx::Bitmap* bitmap() const { return m_bitmap; } private: - ImageStyleValue(const URL&, DOM::Document&); + ImageStyleValue(const AK::URL&, DOM::Document&); // ^ResourceClient virtual void resource_did_load() override; - URL m_url; + AK::URL m_url; WeakPtr m_document; RefPtr m_bitmap; }; diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index a6b1c4c856..0a26a2f214 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -57,7 +57,7 @@ namespace Web::DOM { -Document::Document(const URL& url) +Document::Document(const AK::URL& url) : ParentNode(*this, NodeType::DOCUMENT_NODE) , m_style_resolver(make(*this)) , m_style_sheets(CSS::StyleSheetList::create(*this)) @@ -383,7 +383,7 @@ CSS::Repeat Document::background_repeat_y() const } // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#parse-a-url -URL Document::parse_url(String const& url) const +AK::URL Document::parse_url(String const& url) const { // FIXME: Make sure we do this according to spec. return m_url.complete_url(url); diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 91970e4e4c..099f199795 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -45,7 +45,7 @@ class Document public: using WrapperType = Bindings::DocumentWrapper; - static NonnullRefPtr create(const URL& url = "about:blank") + static NonnullRefPtr create(const AK::URL& url = "about:blank") { return adopt_ref(*new Document(url)); } @@ -64,15 +64,15 @@ public: bool should_invalidate_styles_on_attribute_changes() const { return m_should_invalidate_styles_on_attribute_changes; } void set_should_invalidate_styles_on_attribute_changes(bool b) { m_should_invalidate_styles_on_attribute_changes = b; } - void set_url(const URL& url) { m_url = url; } - URL url() const { return m_url; } + void set_url(const AK::URL& url) { m_url = url; } + AK::URL url() const { return m_url; } Origin origin() const; void set_origin(const Origin& origin); bool is_scripting_enabled() const { return true; } - URL parse_url(String const&) const; + AK::URL parse_url(String const&) const; CSS::StyleResolver& style_resolver() { return *m_style_resolver; } const CSS::StyleResolver& style_resolver() const { return *m_style_resolver; } @@ -282,7 +282,7 @@ public: Bindings::LocationObject* location(); private: - explicit Document(const URL&); + explicit Document(const AK::URL&); // ^DOM::Node virtual RefPtr create_layout_node() override; @@ -316,7 +316,7 @@ private: RefPtr m_hovered_node; RefPtr m_inspected_node; WeakPtr m_browsing_context; - URL m_url; + AK::URL m_url; RefPtr m_window; diff --git a/Userland/Libraries/LibWeb/DOM/Window.cpp b/Userland/Libraries/LibWeb/DOM/Window.cpp index 8af72c6418..8202ed9825 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.cpp +++ b/Userland/Libraries/LibWeb/DOM/Window.cpp @@ -138,7 +138,7 @@ void Window::cancel_animation_frame(i32 id) GUI::DisplayLink::unregister_callback(id); } -void Window::did_set_location_href(Badge, URL const& new_href) +void Window::did_set_location_href(Badge, AK::URL const& new_href) { auto* frame = associated_document().browsing_context(); if (!frame) diff --git a/Userland/Libraries/LibWeb/DOM/Window.h b/Userland/Libraries/LibWeb/DOM/Window.h index fb646f541c..36f5fecb5c 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.h +++ b/Userland/Libraries/LibWeb/DOM/Window.h @@ -54,7 +54,7 @@ public: int inner_width() const; int inner_height() const; - void did_set_location_href(Badge, URL const& new_href); + void did_set_location_href(Badge, AK::URL const& new_href); void did_call_location_reload(Badge); Bindings::WindowObject* wrapper() { return m_wrapper; } diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index f99f71c7ed..1cdd5734b9 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -205,6 +205,9 @@ class XMLHttpRequest; class XMLHttpRequestEventTarget; } +namespace Web::URL { +} + namespace Web::Bindings { class AbortControllerWrapper; class AbortSignalWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 857887da64..cabbf54f75 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -92,7 +92,7 @@ String HTMLCanvasElement::to_data_url(const String& type, [[maybe_unused]] Optio if (type != "image/png") return {}; auto encoded_bitmap = Gfx::PNGWriter::encode(*m_bitmap); - return URL::create_with_data(type, encode_base64(encoded_bitmap), true).to_string(); + return AK::URL::create_with_data(type, encode_base64(encoded_bitmap), true).to_string(); } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index dbca33611c..5d9e3ef437 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include namespace Web::HTML { @@ -75,7 +75,7 @@ void HTMLFormElement::submit_form(RefPtr submitter, bool from_submi return; } - URL url(document().parse_url(action())); + AK::URL url(document().parse_url(action())); if (!url.is_valid()) { dbgln("Failed to submit form: Invalid URL: {}", action()); @@ -96,7 +96,7 @@ void HTMLFormElement::submit_form(RefPtr submitter, bool from_submi return; } - Vector parameters; + Vector parameters; for_each_in_inclusive_subtree_of_type([&](auto& input) { if (!input.name().is_null() && (input.type() != "submit" || &input == submitter)) @@ -105,14 +105,14 @@ void HTMLFormElement::submit_form(RefPtr submitter, bool from_submi }); if (effective_method == "get") { - url.set_query(urlencode(parameters, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded)); + url.set_query(url_encode(parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded)); } LoadRequest request; request.set_url(url); if (effective_method == "post") { - auto body = urlencode(parameters, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded).to_byte_buffer(); + auto body = url_encode(parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded).to_byte_buffer(); request.set_method("POST"); request.set_header("Content-Type", "application/x-www-form-urlencoded"); request.set_header("Content-Length", String::number(body.size())); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index 4aa8f5d205..57be9a6745 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -304,7 +304,7 @@ void HTMLScriptElement::prepare_script() document().interpreter(); // FIXME: This is all ad-hoc and needs work. - auto script = ClassicScript::create(url.to_string(), data, document().interpreter().realm(), URL()); + auto script = ClassicScript::create(url.to_string(), data, document().interpreter().realm(), AK::URL()); // When the chosen algorithm asynchronously completes, set the script's script to the result. At that time, the script is ready. m_script = script; @@ -331,7 +331,7 @@ void HTMLScriptElement::prepare_script() document().interpreter(); // FIXME: Pass settings, base URL and options. - auto script = ClassicScript::create(m_document->url().to_string(), source_text, document().interpreter().realm(), URL()); + auto script = ClassicScript::create(m_document->url().to_string(), source_text, document().interpreter().realm(), AK::URL()); // 2. Set the script's script to script. m_script = script; diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 1d690dc92e..17324abc95 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -93,7 +93,7 @@ static Vector s_quirks_public_ids = { "-//WebTechs//DTD Mozilla HTML//" }; -RefPtr parse_html_document(const StringView& data, const URL& url, const String& encoding) +RefPtr parse_html_document(const StringView& data, const AK::URL& url, const String& encoding) { auto document = DOM::Document::create(url); HTMLDocumentParser parser(document, data, encoding); @@ -116,7 +116,7 @@ HTMLDocumentParser::~HTMLDocumentParser() m_document->set_should_invalidate_styles_on_attribute_changes(true); } -void HTMLDocumentParser::run(const URL& url) +void HTMLDocumentParser::run(const AK::URL& url) { m_document->set_url(url); m_document->set_source(m_tokenizer.source()); diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.h b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.h index 3f56db98c1..5cefb17a43 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.h +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.h @@ -39,7 +39,7 @@ namespace Web::HTML { __ENUMERATE_INSERTION_MODE(AfterAfterBody) \ __ENUMERATE_INSERTION_MODE(AfterAfterFrameset) -RefPtr parse_html_document(const StringView&, const URL&, const String& encoding); +RefPtr parse_html_document(const StringView&, const AK::URL&, const String& encoding); class HTMLDocumentParser { public: @@ -48,7 +48,7 @@ public: static NonnullOwnPtr create_with_uncertain_encoding(DOM::Document&, const ByteBuffer& input); - void run(const URL&); + void run(const AK::URL&); DOM::Document& document(); diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp index 4cb96d3532..da2022b2b8 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp @@ -11,7 +11,7 @@ namespace Web::HTML { // https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-classic-script -NonnullRefPtr ClassicScript::create(String filename, StringView source, JS::Realm& realm, URL base_url, MutedErrors muted_errors) +NonnullRefPtr ClassicScript::create(String filename, StringView source, JS::Realm& realm, AK::URL base_url, MutedErrors muted_errors) { // 1. If muted errors was not provided, let it be false. (NOTE: This is taken care of by the default argument.) @@ -65,7 +65,7 @@ JS::Value ClassicScript::run(RethrowErrors rethrow_errors) return vm.last_value(); } -ClassicScript::ClassicScript(URL base_url, String filename) +ClassicScript::ClassicScript(AK::URL base_url, String filename) : Script(move(base_url), move(filename)) { } diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h index 296b7caba5..34af98d50c 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h @@ -20,7 +20,7 @@ public: No, Yes, }; - static NonnullRefPtr create(String filename, StringView source, JS::Realm&, URL base_url, MutedErrors = MutedErrors::No); + static NonnullRefPtr create(String filename, StringView source, JS::Realm&, AK::URL base_url, MutedErrors = MutedErrors::No); JS::Script* script_record() { return m_script_record; } JS::Script const* script_record() const { return m_script_record; } @@ -32,7 +32,7 @@ public: JS::Value run(RethrowErrors = RethrowErrors::No); private: - ClassicScript(URL base_url, String filename); + ClassicScript(AK::URL base_url, String filename); RefPtr m_script_record; MutedErrors m_muted_errors { MutedErrors::No }; diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp index d915e0b85a..8fcc9ddea7 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp @@ -8,7 +8,7 @@ namespace Web::HTML { -Script::Script(URL base_url, String filename) +Script::Script(AK::URL base_url, String filename) : m_base_url(move(base_url)) , m_filename(move(filename)) { diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Script.h b/Userland/Libraries/LibWeb/HTML/Scripting/Script.h index 10a189ccba..36f5885717 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Script.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Script.h @@ -16,14 +16,14 @@ class Script : public RefCounted