Title: [270186] trunk/Tools
Revision
270186
Author
[email protected]
Date
2020-11-27 02:02:08 -0800 (Fri, 27 Nov 2020)

Log Message

[GTK] MiniBroeser add an option to quit the browser after loading finishes
https://bugs.webkit.org/show_bug.cgi?id=219081

Reviewed by Carlos Alberto Lopez Perez.

It's useful to run benchmarks or test case reduction tools.

* MiniBrowser/gtk/BrowserTab.c:
(webProcessTerminatedCallback): Show a warning when the web process crashes.
(browserTabConstructed): Connect to web-process-terminated signal.
* MiniBrowser/gtk/main.c:
(quitApplication): Quit the MiniBrowser.
(exitAfterWebViewLoadFinishesCallback): Schedule a browser quit to the next run loop iteration.
(exitAfterWebProcessCrashed): Call exitAfterWebViewLoadFinishesCallback with WEBKIT_LOAD_FINISHED.
(exitAfterWebViewLoadFinishes): Connect to load-changed and web-process-terminated signals
(activate): Ensure the browser is exited after the load finishes or web process crashes when --exit-after-load is passed.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (270185 => 270186)


--- trunk/Tools/ChangeLog	2020-11-27 09:51:39 UTC (rev 270185)
+++ trunk/Tools/ChangeLog	2020-11-27 10:02:08 UTC (rev 270186)
@@ -1,3 +1,22 @@
+2020-11-27  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] MiniBroeser add an option to quit the browser after loading finishes
+        https://bugs.webkit.org/show_bug.cgi?id=219081
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        It's useful to run benchmarks or test case reduction tools.
+
+        * MiniBrowser/gtk/BrowserTab.c:
+        (webProcessTerminatedCallback): Show a warning when the web process crashes.
+        (browserTabConstructed): Connect to web-process-terminated signal.
+        * MiniBrowser/gtk/main.c:
+        (quitApplication): Quit the MiniBrowser.
+        (exitAfterWebViewLoadFinishesCallback): Schedule a browser quit to the next run loop iteration.
+        (exitAfterWebProcessCrashed): Call exitAfterWebViewLoadFinishesCallback with WEBKIT_LOAD_FINISHED.
+        (exitAfterWebViewLoadFinishes): Connect to load-changed and web-process-terminated signals
+        (activate): Ensure the browser is exited after the load finishes or web process crashes when --exit-after-load is passed.
+
 2020-11-26  Lauro Moura  <[email protected]>
 
         [GTK] Unreviewed. Remove leftover test case after Internet Explorer quirks changes

Modified: trunk/Tools/MiniBrowser/gtk/BrowserTab.c (270185 => 270186)


--- trunk/Tools/MiniBrowser/gtk/BrowserTab.c	2020-11-27 09:51:39 UTC (rev 270185)
+++ trunk/Tools/MiniBrowser/gtk/BrowserTab.c	2020-11-27 10:02:08 UTC (rev 270186)
@@ -417,6 +417,12 @@
     return TRUE;
 }
 
+static void webProcessTerminatedCallback(WebKitWebView *webView, WebKitWebProcessTerminationReason reason)
+{
+    if (reason == WEBKIT_WEB_PROCESS_CRASHED)
+        g_warning("WebProcess CRASHED");
+}
+
 static gboolean inspectorOpenedInWindow(WebKitWebInspector *inspector, BrowserTab *tab)
 {
     tab->inspectorIsVisible = TRUE;
@@ -626,6 +632,7 @@
     g_signal_connect(tab->webView, "load-failed-with-tls-errors", G_CALLBACK(loadFailedWithTLSerrors), tab);
     g_signal_connect(tab->webView, "permission-request", G_CALLBACK(decidePermissionRequest), tab);
     g_signal_connect(tab->webView, "run-color-chooser", G_CALLBACK(runColorChooserCallback), tab);
+    g_signal_connect(tab->webView, "web-process-terminated", G_CALLBACK(webProcessTerminatedCallback), NULL);
 
     g_object_bind_property(tab->webView, "is-playing-audio", tab->titleAudioButton, "visible", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
     g_signal_connect(tab->webView, "notify::is-muted", G_CALLBACK(audioMutedChanged), tab);

Modified: trunk/Tools/MiniBrowser/gtk/main.c (270185 => 270186)


--- trunk/Tools/MiniBrowser/gtk/main.c	2020-11-27 09:51:39 UTC (rev 270185)
+++ trunk/Tools/MiniBrowser/gtk/main.c	2020-11-27 10:02:08 UTC (rev 270186)
@@ -52,6 +52,8 @@
 static const char *proxy;
 static gboolean darkMode;
 static gboolean enableITP;
+static gboolean exitAfterLoad;
+static gboolean webProcessCrashed;
 static gboolean printVersion;
 
 typedef enum {
@@ -143,6 +145,7 @@
     { "ignore-tls-errors", 0, 0, G_OPTION_ARG_NONE, &ignoreTLSErrors, "Ignore TLS errors", NULL },
     { "content-filter", 0, 0, G_OPTION_ARG_FILENAME, &contentFilter, "JSON with content filtering rules", "FILE" },
     { "enable-itp", 0, 0, G_OPTION_ARG_NONE, &enableITP, "Enable Intelligent Tracking Prevention (ITP)", NULL },
+    { "exit-after-load", 0, 0, G_OPTION_ARG_NONE, &exitAfterLoad, "Quit the browser after the load finishes", NULL },
     { "version", 'v', 0, G_OPTION_ARG_NONE, &printVersion, "Print the WebKitGTK version", NULL },
     { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &uriArguments, 0, "[URL…]" },
     { 0, 0, 0, 0, 0, 0, 0 }
@@ -572,6 +575,34 @@
     g_signal_connect(session, "create-web-view::tab", G_CALLBACK(createWebViewForAutomationInTabCallback), application);
 }
 
+static gboolean quitApplication(GApplication *application)
+{
+    g_application_quit(application);
+    return FALSE;
+}
+
+static void exitAfterWebViewLoadFinishesCallback(WebKitWebView *webView, WebKitLoadEvent loadEvent, GApplication *application)
+{
+    if (loadEvent != WEBKIT_LOAD_FINISHED)
+        return;
+
+    g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, (GSourceFunc)quitApplication, g_object_ref(application), g_object_unref);
+}
+
+static void exitAfterWebProcessCrashed(WebKitWebView *webView, WebKitWebProcessTerminationReason reason, GApplication *application)
+{
+    if (reason == WEBKIT_WEB_PROCESS_CRASHED) {
+        webProcessCrashed = TRUE;
+        exitAfterWebViewLoadFinishesCallback(webView, WEBKIT_LOAD_FINISHED, application);
+    }
+}
+
+static void exitAfterWebViewLoadFinishes(WebKitWebView *webView, GApplication *application)
+{
+    g_signal_connect_object(webView, "load-changed", G_CALLBACK(exitAfterWebViewLoadFinishesCallback), application, G_CONNECT_AFTER);
+    g_signal_connect_object(webView, "web-process-terminated", G_CALLBACK(exitAfterWebProcessCrashed), application, G_CONNECT_AFTER);
+}
+
 typedef struct {
     GMainLoop *mainLoop;
     WebKitUserContentFilter *filter;
@@ -714,8 +745,11 @@
 
         for (i = 0; uriArguments[i]; i++) {
             WebKitWebView *webView = createBrowserTab(mainWindow, webkitSettings, userContentManager, defaultWebsitePolicies);
-            if (!i)
+            if (!i) {
                 firstTab = GTK_WIDGET(webView);
+                if (exitAfterLoad)
+                    exitAfterWebViewLoadFinishes(webView, application);
+            }
             gchar *url = ""
             webkit_web_view_load_uri(webView, url);
             g_free(url);
@@ -727,8 +761,10 @@
         if (!editorMode) {
             if (sessionFile)
                 browser_window_load_session(mainWindow, sessionFile);
-            else if (!automationMode)
+            else if (!automationMode) {
                 webkit_web_view_load_uri(webView, BROWSER_DEFAULT_URL);
+                exitAfterWebViewLoadFinishes(webView, application);
+            }
         }
     }
 
@@ -796,5 +832,5 @@
     g_application_run(G_APPLICATION(application), 0, NULL);
     g_object_unref(application);
 
-    return 0;
+    return exitAfterLoad && webProcessCrashed ? 1 : 0;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to