diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp index d6df6d2c28..3aea7be8bc 100644 --- a/Applications/Browser/Tab.cpp +++ b/Applications/Browser/Tab.cpp @@ -59,6 +59,7 @@ namespace Browser { +extern bool g_use_new_html_parser; extern String g_home_url; Tab::Tab() @@ -70,6 +71,8 @@ Tab::Tab() auto& toolbar = m_toolbar_container->add(); m_html_widget = widget.add(); + m_html_widget->set_use_new_parser(g_use_new_html_parser); + m_go_back_action = GUI::CommonActions::make_go_back_action([this](auto&) { m_history.go_back(); update_actions(); diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp index fc2eebfa4e..50257828d3 100644 --- a/Applications/Browser/main.cpp +++ b/Applications/Browser/main.cpp @@ -28,6 +28,7 @@ #include "InspectorWidget.h" #include "Tab.h" #include "WindowActions.h" +#include #include #include #include @@ -44,6 +45,7 @@ namespace Browser { static const char* bookmarks_filename = "/home/anon/bookmarks.json"; String g_home_url; +bool g_use_new_html_parser = false; } @@ -59,6 +61,13 @@ int main(int argc, char** argv) return 1; } + const char* specified_url = nullptr; + + Core::ArgsParser args_parser; + args_parser.add_option(Browser::g_use_new_html_parser, "Use new HTML parser", "new-parser", 'n'); + args_parser.add_positional_argument(specified_url, "URL to open", "url", Core::ArgsParser::Required::No); + args_parser.parse(argc, argv); + GUI::Application app(argc, argv); // Connect to the ProtocolServer immediately so we can drop the "unix" pledge. @@ -174,8 +183,8 @@ int main(int argc, char** argv) }; URL first_url = Browser::g_home_url; - if (app.args().size() >= 1) - first_url = URL::create_with_url_or_path(app.args()[0]); + if (specified_url) + first_url = URL::create_with_url_or_path(specified_url); window_actions.on_create_new_tab = [&] { create_new_tab(Browser::g_home_url, true); diff --git a/Libraries/LibWeb/HtmlView.cpp b/Libraries/LibWeb/HtmlView.cpp index e1e768ba24..e4e5317897 100644 --- a/Libraries/LibWeb/HtmlView.cpp +++ b/Libraries/LibWeb/HtmlView.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -431,7 +432,7 @@ static String guess_mime_type_based_on_filename(const URL& url) return "text/plain"; } -static RefPtr create_document_from_mime_type(const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding) +RefPtr HtmlView::create_document_from_mime_type(const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding) { if (mime_type.starts_with("image/")) return create_image_document(data, url); @@ -441,8 +442,14 @@ static RefPtr create_document_from_mime_type(const ByteBuffer& data, c return create_markdown_document(data, url); if (mime_type == "text/gemini") return create_gemini_document(data, url); - if (mime_type == "text/html") + if (mime_type == "text/html") { + if (m_use_new_parser) { + HTMLDocumentParser parser(data); + parser.run(url); + return parser.document(); + } return parse_html_document(data, url, encoding); + } return nullptr; } diff --git a/Libraries/LibWeb/HtmlView.h b/Libraries/LibWeb/HtmlView.h index 649535227e..008279abec 100644 --- a/Libraries/LibWeb/HtmlView.h +++ b/Libraries/LibWeb/HtmlView.h @@ -38,6 +38,9 @@ class HtmlView : public GUI::ScrollableWidget { public: virtual ~HtmlView() override; + // FIXME: Remove this once the new parser is ready. + void set_use_new_parser(bool use_new_parser) { m_use_new_parser = use_new_parser; } + Document* document(); const Document* document() const; void set_document(Document*); @@ -83,6 +86,8 @@ protected: private: virtual void did_scroll() override; + RefPtr create_document_from_mime_type(const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding); + void run_javascript_url(const String& url); void layout_and_sync_size(); void dump_selection(const char* event_name); @@ -92,6 +97,8 @@ private: bool m_should_show_line_box_borders { false }; bool m_in_mouse_selection { false }; + + bool m_use_new_parser { false }; }; }