Skip to content

Truly independent web browser

LibWebView: Only complete a WebDriver command from the page running it

Andreas Klingc857fe03dcc4
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 4bfd32397c6..3f03ed51510 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -3281,9 +3281,16 @@ void ViewImplementation::switch_webdriver_to_parent_frame(Function<void(Web::Web
});
}
-void ViewImplementation::did_complete_webdriver_content_command(Badge<WebContentPage>, u64 command_id, Web::WebDriver::Response response)
+void ViewImplementation::did_complete_webdriver_content_command(WebContentPage& page, u64 command_id, Web::WebDriver::Response response)
{
- if (m_pending_webdriver_crash_commands.contains(command_id)) {
+ // NB: Only the page that runs a command completes it. Another page of this view, such as one hosting a cross-site
+ // frame, cannot.
+ auto is_running_command = [&](auto const& commands) {
+ auto command = commands.find(command_id);
+ return command != commands.end() && command->value.page.ptr() == &page;
+ };
+
+ if (is_running_command(m_pending_webdriver_crash_commands)) {
// WebContent acknowledges the command before its deferred process exit. Keep the command pending until the
// crash handler has obtained the page standing in for the crashed document and started session-history recovery.
if (response.is_error()) {
@@ -3293,8 +3300,10 @@ void ViewImplementation::did_complete_webdriver_content_command(Badge<WebContent
return;
}
- if (m_pending_webdriver_commands.remove(command_id))
+ if (is_running_command(m_pending_webdriver_commands)) {
+ m_pending_webdriver_commands.remove(command_id);
Application::the().complete_webdriver_content_command(command_id, move(response));
+ }
}
void ViewImplementation::did_close_browsing_context(Badge<WebContentPage>)
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 21ef78f482a..97ddf4063b8 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -433,7 +433,7 @@ public:
void wait_for_webdriver_navigation_completion(Optional<u64> page_load_timeout, Function<void(Web::WebDriver::Response)>);
void run_webdriver_content_command(u64 command_id, Web::WebDriver::SessionBrowsingContext, String const& name, JsonValue payload, Vector<String> arguments);
void run_webdriver_commands_waiting_for_a_document(Badge<CanonicalTraversable>);
- void did_complete_webdriver_content_command(Badge<WebContentPage>, u64 command_id, Web::WebDriver::Response);
+ void did_complete_webdriver_content_command(WebContentPage&, u64 command_id, Web::WebDriver::Response);
void did_set_webdriver_current_browsing_context(Badge<WebContentPage>, u64 command_id, Web::HTML::CrossProcessId navigable_id);
void enqueue_webdriver_mouse_event(Badge<WebContentPage>, Web::MouseEvent, Function<void()> on_handled);
void did_lose_page(Badge<CanonicalTraversable>, WebContentPage&, WebContentProcessLost);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 7f5260f6b4d..b6dd1d267fe 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1343,7 +1343,7 @@ void WebContentPage::webdriver_did_set_current_browsing_context(u64 command_id,
void WebContentPage::webdriver_command_complete(u64 command_id, Web::WebDriver::Response response)
{
- view().did_complete_webdriver_content_command({}, command_id, move(response));
+ view().did_complete_webdriver_content_command(*this, command_id, move(response));
}
void WebContentPage::did_update_resource_count(i32 count_waiting)