summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-02-22 11:07:40 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-22 11:28:34 +0100
commite405a8f730c9717ac60172acfd62be24b0ca62aa (patch)
treee62b014ff92946c72d5ac84d49aa07467be5dc6e /Userland
parent38781cb1318beb2054758d5d996d54abd8606d39 (diff)
downloadserenity-e405a8f730c9717ac60172acfd62be24b0ca62aa.zip
LibWeb: Defer the handling of WebContent process crashes
Handling crashes synchronously is finicky since we're modifying the m_client_state struct while in a callback lambda owned by it. Let's avoid all the footguns here by simply using deferred_invoke() and handling the crash on next event loop iteration instead.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/OutOfProcessWebView.cpp45
-rw-r--r--Userland/Libraries/LibWeb/OutOfProcessWebView.h2
2 files changed, 28 insertions, 19 deletions
diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
index 36a4cf19bf..3ca0fbdf5a 100644
--- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
+++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
@@ -52,31 +52,38 @@ OutOfProcessWebView::~OutOfProcessWebView()
{
}
+void OutOfProcessWebView::handle_web_content_process_crash()
+{
+ create_client();
+ ASSERT(m_client_state.client);
+
+ // Don't keep a stale backup bitmap around.
+ m_backup_bitmap = nullptr;
+
+ handle_resize();
+ StringBuilder builder;
+ builder.append("<html><head><title>Crashed: ");
+ builder.append(escape_html_entities(m_url.to_string()));
+ builder.append("</title></head><body>");
+ builder.append("<h1>Web page crashed");
+ if (!m_url.host().is_empty()) {
+ builder.appendff(" on {}", escape_html_entities(m_url.host()));
+ }
+ builder.append("</h1>");
+ builder.appendff("The web page <a href=\"{}\">{}</a> has crashed.<br><br>You can reload the page to try again.", escape_html_entities(m_url.to_string_encoded()), escape_html_entities(m_url.to_string()));
+ builder.append("</body></html>");
+ load_html(builder.to_string(), m_url);
+}
+
void OutOfProcessWebView::create_client()
{
m_client_state = {};
m_client_state.client = WebContentClient::construct(*this);
m_client_state.client->on_web_content_process_crash = [this] {
- create_client();
- ASSERT(m_client_state.client);
-
- // Don't keep a stale backup bitmap around.
- m_backup_bitmap = nullptr;
-
- handle_resize();
- StringBuilder builder;
- builder.append("<html><head><title>Crashed: ");
- builder.append(escape_html_entities(m_url.to_string()));
- builder.append("</title></head><body>");
- builder.append("<h1>Web page crashed");
- if (!m_url.host().is_empty()) {
- builder.appendff(" on {}", escape_html_entities(m_url.host()));
- }
- builder.append("</h1>");
- builder.appendff("The web page <a href=\"{}\">{}</a> has crashed.<br><br>You can reload the page to try again.", escape_html_entities(m_url.to_string_encoded()), escape_html_entities(m_url.to_string()));
- builder.append("</body></html>");
- load_html(builder.to_string(), m_url);
+ deferred_invoke([this] {
+ handle_web_content_process_crash();
+ });
};
client().post_message(Messages::WebContentServer::UpdateSystemTheme(Gfx::current_system_theme_buffer()));
diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h
index 5ca5bdd720..890860babe 100644
--- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h
+++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h
@@ -90,6 +90,8 @@ private:
void create_client();
WebContentClient& client();
+ void handle_web_content_process_crash();
+
URL m_url;
struct ClientState {