diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp index 36d93a3bb33..684a7b6e3a3 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp +++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp @@ -91,9 +91,9 @@ static WebIDL::ExceptionOr> load_html_document(H // causes a load event to be fired. else { // FIXME: Parse as we receive the document data, instead of waiting for the whole document to be fetched first. - auto process_body = JS::create_heap_function(document->heap(), [document, url = navigation_params.response->url().value()](ByteBuffer data) { - Platform::EventLoopPlugin::the().deferred_invoke([document = document, data = move(data), url = url] { - auto parser = HTML::HTMLParser::create_with_uncertain_encoding(document, data); + auto process_body = JS::create_heap_function(document->heap(), [document, url = navigation_params.response->url().value(), mime_type = navigation_params.response->header_list()->extract_mime_type()](ByteBuffer data) { + Platform::EventLoopPlugin::the().deferred_invoke([document = document, data = move(data), url = url, mime_type] { + auto parser = HTML::HTMLParser::create_with_uncertain_encoding(document, data, mime_type); parser->run(url); }); }); diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 52d6d7d1f74..3f7e36e0f53 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -4373,11 +4373,11 @@ JS::NonnullGCPtr HTMLParser::create_for_scripting(DOM::Document& doc return document.heap().allocate_without_realm(document); } -JS::NonnullGCPtr HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input) +JS::NonnullGCPtr HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input, Optional maybe_mime_type) { if (document.has_encoding()) return document.heap().allocate_without_realm(document, input, document.encoding().value().to_byte_string()); - auto encoding = run_encoding_sniffing_algorithm(document, input); + auto encoding = run_encoding_sniffing_algorithm(document, input, maybe_mime_type); dbgln_if(HTML_PARSER_DEBUG, "The encoding sniffing algorithm returned encoding '{}'", encoding); return document.heap().allocate_without_realm(document, input, encoding); } diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.h b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.h index 190d8c23f6e..e240153ca76 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.h +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace Web::HTML { @@ -50,7 +51,7 @@ public: ~HTMLParser(); static JS::NonnullGCPtr create_for_scripting(DOM::Document&); - static JS::NonnullGCPtr create_with_uncertain_encoding(DOM::Document&, ByteBuffer const& input); + static JS::NonnullGCPtr create_with_uncertain_encoding(DOM::Document&, ByteBuffer const& input, Optional maybe_mime_type = {}); static JS::NonnullGCPtr create(DOM::Document&, StringView input, StringView encoding); void run(HTMLTokenizer::StopAtInsertionPoint = HTMLTokenizer::StopAtInsertionPoint::No);