WebContent: Exit peacefully when client dies during synchronous IPC

If we're waiting for the client (typically Browser) to respond to a
synchronous IPC message from our side (e.g window.alert()) and the
client disconnects instead, just exit peacefully.

Ultimately a WebContent process lives to serve its client. When the
client dies, there is no need for WebContent anymore.
This commit is contained in:
Andreas Kling 2022-02-16 11:53:21 +01:00
parent 5caeb8b747
commit 9c78c1bf81
Notes: sideshowbarker 2024-07-17 18:43:45 +09:00

View file

@ -203,17 +203,31 @@ void PageHost::page_did_request_link_context_menu(const Gfx::IntPoint& content_p
void PageHost::page_did_request_alert(const String& message)
{
m_client.did_request_alert(message);
auto response = m_client.send_sync_but_allow_failure<Messages::WebContentClient::DidRequestAlert>(message);
if (!response) {
dbgln("WebContent client disconnected during DidRequestAlert. Exiting peacefully.");
exit(0);
}
}
bool PageHost::page_did_request_confirm(const String& message)
{
return m_client.did_request_confirm(message);
auto response = m_client.send_sync_but_allow_failure<Messages::WebContentClient::DidRequestConfirm>(message);
if (!response) {
dbgln("WebContent client disconnected during DidRequestConfirm. Exiting peacefully.");
exit(0);
}
return response->take_result();
}
String PageHost::page_did_request_prompt(const String& message, const String& default_)
{
return m_client.did_request_prompt(message, default_);
auto response = m_client.send_sync_but_allow_failure<Messages::WebContentClient::DidRequestPrompt>(message, default_);
if (!response) {
dbgln("WebContent client disconnected during DidRequestPrompt. Exiting peacefully.");
exit(0);
}
return response->take_response();
}
void PageHost::page_did_change_favicon(const Gfx::Bitmap& favicon)
@ -229,7 +243,12 @@ void PageHost::page_did_request_image_context_menu(const Gfx::IntPoint& content_
String PageHost::page_did_request_cookie(const URL& url, Web::Cookie::Source source)
{
return m_client.did_request_cookie(url, static_cast<u8>(source));
auto response = m_client.send_sync_but_allow_failure<Messages::WebContentClient::DidRequestCookie>(move(url), static_cast<u8>(source));
if (!response) {
dbgln("WebContent client disconnected during DidRequestCookie. Exiting peacefully.");
exit(0);
}
return response->take_cookie();
}
void PageHost::page_did_set_cookie(const URL& url, const Web::Cookie::ParsedCookie& cookie, Web::Cookie::Source source)