diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-21 22:29:05 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-21 22:29:05 +0200 |
commit | 07d976716fdb323de1087ac0378060a7e20eb18c (patch) | |
tree | 0a108855ba74e8154afa020d59e71a4b6df21773 | |
parent | c9d55e3b80ebd97ce62d7c637f27e353e6a175fa (diff) | |
download | serenity-07d976716fdb323de1087ac0378060a7e20eb18c.zip |
LibWeb: Remove most uses of the old HTML parser
The only remaining client of the old parser is the fragment parser used
by the Element.innerHTML setter. We'll need to implement a bit more
stuff in the new parser before we can switch that over.
-rw-r--r-- | Libraries/LibWeb/Loader/FrameLoader.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibWeb/Parser/HTMLDocumentParser.cpp | 7 | ||||
-rw-r--r-- | Libraries/LibWeb/Parser/HTMLDocumentParser.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Parser/HTMLParser.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibWeb/Parser/HTMLParser.h | 1 |
5 files changed, 16 insertions, 8 deletions
diff --git a/Libraries/LibWeb/Loader/FrameLoader.cpp b/Libraries/LibWeb/Loader/FrameLoader.cpp index f625a03e57..927d229f55 100644 --- a/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -54,7 +54,7 @@ static RefPtr<Document> create_markdown_document(const ByteBuffer& data, const U if (!markdown_document) return nullptr; - return parse_html_document(markdown_document->render_to_html(), url); + return parse_html_document(markdown_document->render_to_html(), url, "utf-8"); } static RefPtr<Document> create_text_document(const ByteBuffer& data, const URL& url) @@ -116,7 +116,7 @@ static RefPtr<Document> create_gemini_document(const ByteBuffer& data, const URL { auto markdown_document = Gemini::Document::parse({ (const char*)data.data(), data.size() }, url); - return parse_html_document(markdown_document->render_to_html(), url); + return parse_html_document(markdown_document->render_to_html(), url, "utf-8"); } RefPtr<Document> FrameLoader::create_document_from_mime_type(const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding) @@ -190,7 +190,7 @@ void FrameLoader::load_error_page(const URL& failed_url, const String& error) String::copy(data).characters(), escape_html_entities(failed_url.to_string()).characters(), escape_html_entities(error).characters()); - auto document = parse_html_document(html, failed_url); + auto document = parse_html_document(html, failed_url, "utf-8"); ASSERT(document); frame().set_document(document); frame().page().client().page_did_change_title(document->title()); diff --git a/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp b/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp index 5d930b9a94..f8fed2ca5c 100644 --- a/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp +++ b/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp @@ -46,6 +46,13 @@ namespace Web { +RefPtr<Document> parse_html_document(const StringView& data, const URL& url, const String& encoding) +{ + HTMLDocumentParser parser(data, encoding); + parser.run(url); + return parser.document(); +} + HTMLDocumentParser::HTMLDocumentParser(const StringView& input, const String& encoding) : m_tokenizer(input, encoding) { diff --git a/Libraries/LibWeb/Parser/HTMLDocumentParser.h b/Libraries/LibWeb/Parser/HTMLDocumentParser.h index 02f8b3c900..fa1bb2c33f 100644 --- a/Libraries/LibWeb/Parser/HTMLDocumentParser.h +++ b/Libraries/LibWeb/Parser/HTMLDocumentParser.h @@ -59,6 +59,8 @@ namespace Web { +RefPtr<Document> parse_html_document(const StringView&, const URL&, const String& encoding); + class HTMLDocumentParser { public: HTMLDocumentParser(const StringView& input, const String& encoding); diff --git a/Libraries/LibWeb/Parser/HTMLParser.cpp b/Libraries/LibWeb/Parser/HTMLParser.cpp index 1cc7fdf826..c963c4d49b 100644 --- a/Libraries/LibWeb/Parser/HTMLParser.cpp +++ b/Libraries/LibWeb/Parser/HTMLParser.cpp @@ -82,7 +82,7 @@ static Vector<char> codepoint_to_bytes(const u32 codepoint) return bytes; } -static bool parse_html_document(const StringView& html, Document& document, ParentNode& root) +static bool deprecated_parse_html_document(const StringView& html, Document& document, ParentNode& root) { NonnullRefPtrVector<ParentNode> node_stack; node_stack.append(root); @@ -466,19 +466,19 @@ String to_utf8(const StringView& input, const String& encoding) RefPtr<DocumentFragment> parse_html_fragment(Document& document, const StringView& raw_html, const String& encoding) { auto fragment = adopt(*new DocumentFragment(document)); - if (!parse_html_document(to_utf8(raw_html, encoding), document, *fragment)) + if (!deprecated_parse_html_document(to_utf8(raw_html, encoding), document, *fragment)) return nullptr; return fragment; } -RefPtr<Document> parse_html_document(const StringView& raw_html, const URL& url, const String& encoding) +RefPtr<Document> deprecated_parse_html_document(const StringView& raw_html, const URL& url, const String& encoding) { String html = to_utf8(raw_html, encoding); auto document = adopt(*new Document(url)); document->set_source(html); - if (!parse_html_document(html, *document, *document)) + if (!deprecated_parse_html_document(html, *document, *document)) return nullptr; document->fixup(); diff --git a/Libraries/LibWeb/Parser/HTMLParser.h b/Libraries/LibWeb/Parser/HTMLParser.h index da60ddcca1..37e706fc1a 100644 --- a/Libraries/LibWeb/Parser/HTMLParser.h +++ b/Libraries/LibWeb/Parser/HTMLParser.h @@ -33,7 +33,6 @@ namespace Web { class DocumentFragment; -RefPtr<Document> parse_html_document(const StringView&, const URL& = URL(), const String& encoding = "utf-8"); RefPtr<DocumentFragment> parse_html_fragment(Document&, const StringView&, const String& encoding = "utf-8"); } |