From ec2330a796c963c8777b3421a662d589e872d070 Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Sat, 24 Sep 2022 17:03:22 +0100 Subject: [PATCH] wpe: Add a basic WebProcess crash handler For now an error is emitted. Additional notification could be sent to the application as well, if needed. Part-of: --- .../ext/wpe/WPEThreadedView.cpp | 20 +++++++++++++++++++ .../gst-plugins-bad/ext/wpe/WPEThreadedView.h | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-bad/ext/wpe/WPEThreadedView.cpp b/subprojects/gst-plugins-bad/ext/wpe/WPEThreadedView.cpp index abc505d8dd..c195ede08a 100644 --- a/subprojects/gst-plugins-bad/ext/wpe/WPEThreadedView.cpp +++ b/subprojects/gst-plugins-bad/ext/wpe/WPEThreadedView.cpp @@ -399,7 +399,26 @@ static void s_loadProgressChanged(GObject* object, GParamSpec*, gpointer data) gst_object_unref (bus); } +static void s_webProcessCrashed(WebKitWebView*, WebKitWebProcessTerminationReason reason, gpointer data) +{ + auto &view = *static_cast(data); + auto *src = view.src(); + gchar *reason_str = + g_enum_to_string (WEBKIT_TYPE_WEB_PROCESS_TERMINATION_REASON, reason); + + // In case the crash happened while doing the initial URL loading, unlock + // the load completion waiting. + view.notifyLoadFinished(); + + // TODO: Emit a signal here and fallback to error system if signal wasn't handled by application? + + GST_ELEMENT_ERROR(GST_ELEMENT_CAST(src), RESOURCE, FAILED, (NULL), ("%s", reason_str)); + + g_free (reason_str); +} + WPEView::WPEView(WebKitWebContext* web_context, GstWpeVideoSrc* src, GstGLContext* context, GstGLDisplay* display, int width, int height) + : m_src(src) { #ifdef G_OS_UNIX { @@ -474,6 +493,7 @@ WPEView::WPEView(WebKitWebContext* web_context, GstWpeVideoSrc* src, GstGLContex g_signal_connect(webkit.view, "load-failed", G_CALLBACK(s_loadFailed), src); g_signal_connect(webkit.view, "load-failed-with-tls-errors", G_CALLBACK(s_loadFailedWithTLSErrors), src); g_signal_connect(webkit.view, "notify::estimated-load-progress", G_CALLBACK(s_loadProgressChanged), src); + g_signal_connect(webkit.view, "web-process-terminated", G_CALLBACK(s_webProcessCrashed), this); auto* settings = webkit_web_view_get_settings(webkit.view); webkit_settings_set_enable_webaudio(settings, TRUE); diff --git a/subprojects/gst-plugins-bad/ext/wpe/WPEThreadedView.h b/subprojects/gst-plugins-bad/ext/wpe/WPEThreadedView.h index 315cfbf47c..6e005827d7 100644 --- a/subprojects/gst-plugins-bad/ext/wpe/WPEThreadedView.h +++ b/subprojects/gst-plugins-bad/ext/wpe/WPEThreadedView.h @@ -59,6 +59,10 @@ public: void disconnectLoadFailedSignal(); void waitLoadCompletion(); + GstWpeVideoSrc *src() const { return m_src; } + + void notifyLoadFinished(); + protected: void handleExportedImage(gpointer); void handleExportedBuffer(struct wpe_fdo_shm_exported_buffer*); @@ -67,7 +71,6 @@ private: struct wpe_view_backend* backend() const; void frameComplete(); void loadUriUnlocked(const gchar*); - void notifyLoadFinished(); void releaseImage(gpointer); void releaseSHMBuffer(gpointer); @@ -121,6 +124,7 @@ private: gulong extension_msg_sigid; } audio {0, 0}; + GstWpeVideoSrc *m_src { nullptr }; }; class WPEContextThread {