Skip to content

Truly independent web browser

LibWeb+LibWebView+WebContent: Identify a finished load by its document

Shannon Booth70f8130200f1
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 2789ead05bc..79886e3ec36 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -5050,8 +5050,8 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)
if (navigable && navigable->is_traversable()) {
if (!is_decoded_svg()) {
HTML::HTMLLinkElement::load_fallback_favicon_if_needed(*this);
+ navigable->page().client().page_did_finish_loading(navigable->id(), id());
}
- navigable->page().client().page_did_finish_loading(navigable->id(), m_navigation_id);
} else {
m_needs_to_call_page_did_load = true;
}
@@ -6982,7 +6982,7 @@ void Document::make_active()
HTML::relevant_settings_object(window).execution_ready = true;
if (m_needs_to_call_page_did_load) {
- navigable()->page().client().page_did_finish_loading(navigable()->id(), m_navigation_id);
+ navigable()->page().client().page_did_finish_loading(navigable()->id(), id());
m_needs_to_call_page_did_load = false;
}
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index f44f9db86c2..fbb5525290b 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -724,7 +724,7 @@ public:
virtual void page_did_change_picture_in_picture_video_size(Gfx::IntSize) { }
virtual void page_did_change_picture_in_picture_player_controls_visibility(bool) { }
virtual void page_did_change_active_document_in_top_level_browsing_context(Web::DOM::Document&) { }
- virtual void page_did_finish_loading(HTML::CrossProcessId, Optional<Utf16String> const&) { }
+ virtual void page_did_finish_loading(HTML::CrossProcessId, HTML::CrossProcessId) { }
virtual Optional<u64> page_did_start_download(HTML::CrossProcessId navigable_id, Optional<Utf16String> const& navigation_id, URL::URL const&, ByteString const& suggested_filename, Optional<u64> total_size, int request_server_client_id, u64 request_server_request_id, ByteBuffer initial_data)
{
(void)navigable_id;
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index b7385e1b63e..d5cc90f9d5f 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -2254,7 +2254,7 @@ void WebContentPage::did_fail_download(u64 download_id, String error)
Application::the().file_downloader().fail_download(download_id, move(error));
}
-void WebContentPage::did_finish_loading(Web::HTML::CrossProcessId navigable_id, Optional<Utf16String> navigation_id)
+void WebContentPage::did_finish_loading(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id)
{
// NB: Only the page hosting the active document finishes loading it. A page standing in for a document the
// navigable lost, as the page displaying the tab after its process crashed does, finishes loading the stand-in;
@@ -2263,7 +2263,10 @@ void WebContentPage::did_finish_loading(Web::HTML::CrossProcessId navigable_id,
if (!navigable.has_value() || navigable->active_document().host() != this)
return;
- if (navigation_id != navigable->tracked_load_navigation_id())
+ if (navigable->active_document().id() != document_id)
+ return;
+
+ if (navigable->tracked_load_navigation_id() != navigable->active_document_load().navigation_id)
return;
navigable->clear_active_document_load();
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 8c95772d0df..3cb8f09d5bf 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -313,7 +313,7 @@ private:
virtual void did_receive_download_data(u64 download_id, ByteBuffer data) override;
virtual void did_finish_download(u64 download_id) override;
virtual void did_fail_download(u64 download_id, String error) override;
- virtual void did_finish_loading(Web::HTML::CrossProcessId navigable_id, Optional<Utf16String> navigation_id) override;
+ virtual void did_finish_loading(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id) override;
virtual void did_change_title(Utf16String title) override;
virtual void did_request_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::ContextMenuForInputEventsTarget for_input_events_target, Optional<Utf16String> misspelled_word, Optional<u64> text_fragment_generation_id) override;
virtual void did_request_link_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString, unsigned, Optional<u64> text_fragment_generation_id) override;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 1767c3a83c9..13426f1632d 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -993,9 +993,9 @@ void PageClient::page_did_change_active_document_in_top_level_browsing_context(W
}
}
-void PageClient::page_did_finish_loading(Web::HTML::CrossProcessId navigable_id, Optional<Utf16String> const& navigation_id)
+void PageClient::page_did_finish_loading(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id)
{
- client().async_did_finish_loading(m_id, navigable_id, navigation_id);
+ client().async_did_finish_loading(m_id, navigable_id, document_id);
}
Optional<u64> PageClient::page_did_start_download(Web::HTML::CrossProcessId navigable_id, Optional<Utf16String> const& navigation_id, URL::URL const& url, ByteString const& suggested_filename, Optional<u64> total_size, int request_server_client_id, u64 request_server_request_id, ByteBuffer initial_data)
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index b664cc1779a..cd9778f25d1 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -261,7 +261,7 @@ private:
virtual void page_did_request_image_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint, Web::HTML::PreparedNavigationDescriptor, ByteString const& target, unsigned modifiers, Optional<Gfx::Bitmap const*>) override;
virtual void page_did_request_media_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint, ByteString const& target, unsigned modifiers, Web::Page::MediaContextMenu const&, Optional<Web::HTML::PreparedNavigationDescriptor>) override;
virtual void page_did_change_active_document_in_top_level_browsing_context(Web::DOM::Document&) override;
- virtual void page_did_finish_loading(Web::HTML::CrossProcessId, Optional<Utf16String> const&) override;
+ virtual void page_did_finish_loading(Web::HTML::CrossProcessId, Web::HTML::CrossProcessId) override;
virtual Optional<u64> page_did_start_download(Web::HTML::CrossProcessId navigable_id, Optional<Utf16String> const& navigation_id, URL::URL const&, ByteString const& suggested_filename, Optional<u64> total_size, int request_server_client_id, u64 request_server_request_id, ByteBuffer initial_data) override;
virtual Optional<u64> page_did_start_download(URL::URL const&, ByteString const& suggested_filename, Optional<u64> total_size) override;
virtual void page_did_receive_download_data(u64 download_id, ByteBuffer data) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index e115731e909..fa3fc102fe9 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -105,7 +105,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_update_child_frame_viewport(Web::PageId page_id, Web::HTML::CrossProcessId frame_id, Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio) =|
did_forward_mouse_event_to_child_frame(Web::PageId page_id, Web::HTML::CrossProcessId frame_id, Web::MouseEvent event) =|
did_destroy_child_frame(Web::PageId page_id, Web::HTML::CrossProcessId frame_id) =|
- did_finish_loading(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Optional<Utf16String> navigation_id) =|
+ did_finish_loading(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id) =|
[NotRouted] did_start_download_without_request(Web::PageId page_id, URL::URL url, ByteString suggested_filename, Optional<u64> total_size) => (Optional<u64> download_id)
[NotRouted] did_start_download(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Optional<Utf16String> navigation_id, URL::URL url, ByteString suggested_filename, Optional<u64> total_size, int request_server_client_id, u64 request_server_request_id, ByteBuffer initial_data) => (Optional<u64> download_id)
did_receive_download_data(Web::PageId page_id, u64 download_id, ByteBuffer data) =|
diff --git a/Tests/LibWeb/Text/expected/wpt-import/xml/onreadystatechange-crash-on-stop.txt b/Tests/LibWeb/Text/expected/wpt-import/xml/onreadystatechange-crash-on-stop.txt
new file mode 100644
index 00000000000..8b0fe5da62b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/xml/onreadystatechange-crash-on-stop.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Test for crash with stop() in onreadystatechange handler
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/xml/onreadystatechange-crash-on-stop.xhtml b/Tests/LibWeb/Text/input/wpt-import/xml/onreadystatechange-crash-on-stop.xhtml
new file mode 100644
index 00000000000..14b6ce70197
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/xml/onreadystatechange-crash-on-stop.xhtml
@@ -0,0 +1,25 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <!--
+ This needs to be a testharness.js test rather than a crashtest so that we
+ can explicitly call done().
+ -->
+ <head>
+ <title>Test for crash with stop() in onreadystatechange handler</title>
+ <script src="../resources/testharness.js" />
+ <script src="../resources/testharnessreport.js" />
+ </head>
+ <body>
+ <script>
+ setup({ single_test: true });
+ document.addEventListener("readystatechange", function () {
+ window.stop();
+
+ // Call done() explicitly because stop() would otherwise lead to a
+ // timeout (at least in a crashtest), and also explicitly dispatch the
+ // "load" event to keep WPT happy.
+ done();
+ window.dispatchEvent(new Event("load"));
+ }, { once: true });
+ </script>
+ </body>
+</html>