Title: [275936] trunk
Revision
275936
Author
[email protected]
Date
2021-04-14 00:44:16 -0700 (Wed, 14 Apr 2021)

Log Message

[GTK][WPE] Add a property to the WebKitWebView indicating whether the web process is responsive
https://bugs.webkit.org/show_bug.cgi?id=224359

Reviewed by Adrian Perez de Castro.

Source/WebKit:

Add a property to WebKitWebView indicating whether the web processes used are responsive.

* UIProcess/API/glib/WebKitNavigationClient.cpp:
* UIProcess/API/glib/WebKitWebView.cpp:
(webkitWebViewConstructed):
(webkitWebViewGetProperty):
(webkit_web_view_class_init):
(webkitWebViewSetIsWebProcessResponsive):
(webkit_web_view_get_is_web_process_responsive):
* UIProcess/API/glib/WebKitWebViewPrivate.h:
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
* UIProcess/API/wpe/WebKitWebView.h:
* UIProcess/API/wpe/docs/wpe-1.0-sections.txt:

Tools:

Added unit test for web process responsiveness API.

* TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
(testWebViewIsWebProcessResponsive):
(beforeAll):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (275935 => 275936)


--- trunk/Source/WebKit/ChangeLog	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Source/WebKit/ChangeLog	2021-04-14 07:44:16 UTC (rev 275936)
@@ -1,3 +1,25 @@
+2021-04-14  Miguel Gomez  <[email protected]>
+
+        [GTK][WPE] Add a property to the WebKitWebView indicating whether the web process is responsive
+        https://bugs.webkit.org/show_bug.cgi?id=224359
+
+        Reviewed by Adrian Perez de Castro.
+
+        Add a property to WebKitWebView indicating whether the web processes used are responsive.
+
+        * UIProcess/API/glib/WebKitNavigationClient.cpp:
+        * UIProcess/API/glib/WebKitWebView.cpp:
+        (webkitWebViewConstructed):
+        (webkitWebViewGetProperty):
+        (webkit_web_view_class_init):
+        (webkitWebViewSetIsWebProcessResponsive):
+        (webkit_web_view_get_is_web_process_responsive):
+        * UIProcess/API/glib/WebKitWebViewPrivate.h:
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+        * UIProcess/API/wpe/WebKitWebView.h:
+        * UIProcess/API/wpe/docs/wpe-1.0-sections.txt:
+
 2021-04-13  Jer Noble  <[email protected]>
 
         [GPUP] MediaSource.addSourceBuffer() will throw if given the same parameter as a previous call to HTMLMediaElement.canPlayType()

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitNavigationClient.cpp (275935 => 275936)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitNavigationClient.cpp	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitNavigationClient.cpp	2021-04-14 07:44:16 UTC (rev 275936)
@@ -125,6 +125,16 @@
         return false;
     }
 
+    void processDidBecomeResponsive(WebKit::WebPageProxy&) override
+    {
+        webkitWebViewSetIsWebProcessResponsive(m_webView, true);
+    }
+
+    void processDidBecomeUnresponsive(WebKit::WebPageProxy&) override
+    {
+        webkitWebViewSetIsWebProcessResponsive(m_webView, false);
+    }
+
     void decidePolicyForNavigationAction(WebPageProxy&, Ref<API::NavigationAction>&& navigationAction, Ref<WebFramePolicyListenerProxy>&& listener, API::Object* /* userData */) override
     {
         WebKitPolicyDecisionType decisionType = navigationAction->targetFrame() ? WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION : WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION;

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp (275935 => 275936)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2021-04-14 07:44:16 UTC (rev 275936)
@@ -204,6 +204,7 @@
     PROP_PAGE_ID,
     PROP_IS_MUTED,
     PROP_WEBSITE_POLICIES,
+    PROP_IS_WEB_PROCESS_RESPONSIVE,
 
     N_PROPERTIES,
 };
@@ -312,6 +313,8 @@
     GRefPtr<WebKitWebsitePolicies> websitePolicies;
 
     double textScaleFactor;
+
+    bool isWebProcessResponsive;
 };
 
 static guint signals[LAST_SIGNAL] = { 0, };
@@ -811,6 +814,8 @@
         webView->priv->textScaleFactor = WebCore::screenDPI() / 96.;
         page.setTextZoomFactor(zoomFactor * webView->priv->textScaleFactor);
     }, webView);
+
+    priv->isWebProcessResponsive = true;
 }
 
 static void webkitWebViewSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
@@ -934,6 +939,9 @@
     case PROP_WEBSITE_POLICIES:
         g_value_set_object(value, webkit_web_view_get_website_policies(webView));
         break;
+    case PROP_IS_WEB_PROCESS_RESPONSIVE:
+        g_value_set_boolean(value, webkit_web_view_get_is_web_process_responsive(webView));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     }
@@ -1313,6 +1321,21 @@
             WEBKIT_TYPE_WEBSITE_POLICIES,
             static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
+    /**
+     * WebKitWebView:is-web-process-responsive:
+     *
+     * Whether the web process currently associated to the #WebKitWebView is responsive.
+     *
+     * Since: 2.34
+     */
+    sObjProperties[PROP_IS_WEB_PROCESS_RESPONSIVE] =
+        g_param_spec_boolean(
+            "is-web-process-responsive",
+            "Is Web Process Responsive",
+            _("Whether the web process currently associated to the web view is responsive"),
+            TRUE,
+            WEBKIT_PARAM_READABLE);
+
     g_object_class_install_properties(gObjectClass, N_PROPERTIES, sObjProperties);
 
     /**
@@ -4703,3 +4726,29 @@
 
     return webView->priv->websitePolicies.get();
 }
+
+void webkitWebViewSetIsWebProcessResponsive(WebKitWebView* webView, bool isResponsive)
+{
+    if (webView->priv->isWebProcessResponsive == isResponsive)
+        return;
+
+    webView->priv->isWebProcessResponsive = isResponsive;
+    g_object_notify_by_pspec(G_OBJECT(webView), sObjProperties[PROP_IS_WEB_PROCESS_RESPONSIVE]);
+}
+
+/**
+ * webkit_web_view_is_web_process_responsive:
+ * @web_view: a #WebKitWebView
+ *
+ * Get whether the current web process of a #WebKitWebView is responsive.
+ *
+ * Returns: %TRUE if the web process attached to @web_view is responsive, or %FALSE otherwise.
+ *
+ * Since: 2.34
+ */
+gboolean webkit_web_view_get_is_web_process_responsive(WebKitWebView* webView)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
+
+    return webView->priv->isWebProcessResponsive;
+}

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewPrivate.h (275935 => 275936)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewPrivate.h	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewPrivate.h	2021-04-14 07:44:16 UTC (rev 275936)
@@ -120,3 +120,4 @@
 void webkitWebViewConfirmComposition(WebKitWebView*, const String&);
 void webkitWebViewCancelComposition(WebKitWebView*, const String&);
 void webkitWebViewDeleteSurrounding(WebKitWebView*, int offset, unsigned characterCount);
+void webkitWebViewSetIsWebProcessResponsive(WebKitWebView*, bool);

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h (275935 => 275936)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h	2021-04-14 07:44:16 UTC (rev 275936)
@@ -589,6 +589,8 @@
 WEBKIT_API WebKitWebsitePolicies *
 webkit_web_view_get_website_policies                 (WebKitWebView             *web_view);
 
+WEBKIT_API gboolean
+webkit_web_view_get_is_web_process_responsive        (WebKitWebView             *web_view);
 
 G_END_DECLS
 

Modified: trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt (275935 => 275936)


--- trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2021-04-14 07:44:16 UTC (rev 275936)
@@ -290,6 +290,7 @@
 webkit_web_view_set_input_method_context
 webkit_web_view_get_input_method_context
 webkit_web_view_get_website_policies
+webkit_web_view_get_is_web_process_responsive
 
 <SUBSECTION WebKitJavascriptResult>
 WebKitJavascriptResult

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h (275935 => 275936)


--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h	2021-04-14 07:44:16 UTC (rev 275936)
@@ -565,6 +565,9 @@
 WEBKIT_API WebKitWebsitePolicies *
 webkit_web_view_get_website_policies                 (WebKitWebView             *web_view);
 
+WEBKIT_API gboolean
+webkit_web_view_get_is_web_process_responsive        (WebKitWebView             *web_view);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt (275935 => 275936)


--- trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt	2021-04-14 07:44:16 UTC (rev 275936)
@@ -262,6 +262,7 @@
 webkit_web_view_set_input_method_context
 webkit_web_view_get_input_method_context
 webkit_web_view_get_website_policies
+webkit_web_view_get_is_web_process_responsive
 
 <SUBSECTION WebKitJavascriptResult>
 WebKitJavascriptResult

Modified: trunk/Tools/ChangeLog (275935 => 275936)


--- trunk/Tools/ChangeLog	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Tools/ChangeLog	2021-04-14 07:44:16 UTC (rev 275936)
@@ -1,3 +1,16 @@
+2021-04-14  Miguel Gomez  <[email protected]>
+
+        [GTK][WPE] Add a property to the WebKitWebView indicating whether the web process is responsive
+        https://bugs.webkit.org/show_bug.cgi?id=224359
+
+        Reviewed by Adrian Perez de Castro.
+
+        Added unit test for web process responsiveness API.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
+        (testWebViewIsWebProcessResponsive):
+        (beforeAll):
+
 2021-04-13  Myles C. Maxfield  <[email protected]>
 
         [GPU Process] Simplify DisplayList::Iterator part 4: Move DisplayList::Iterator to its own .h/.cpp files

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp (275935 => 275936)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp	2021-04-14 06:59:58 UTC (rev 275935)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp	2021-04-14 07:44:16 UTC (rev 275936)
@@ -1177,6 +1177,56 @@
     g_assert_cmpint(webkit_website_policies_get_autoplay_policy(policies), ==, WEBKIT_AUTOPLAY_ALLOW_WITHOUT_SOUND);
 }
 
+class WebViewIsWebProcessResponsiveTest: public WebViewTest {
+public:
+    MAKE_GLIB_TEST_FIXTURE(WebViewIsWebProcessResponsiveTest);
+
+    static void isWebProcessResponsiveChanged(WebKitWebView* view, GParamSpec*, WebViewIsWebProcessResponsiveTest* test)
+    {
+        g_signal_handlers_disconnect_by_func(test->m_webView, reinterpret_cast<void*>(isWebProcessResponsiveChanged), test);
+        g_main_loop_quit(test->m_mainLoop);
+    }
+
+    void waitUntilIsWebProcessResponsiveChanged()
+    {
+        g_signal_connect(m_webView, "notify::is-web-process-responsive", G_CALLBACK(isWebProcessResponsiveChanged), this);
+        g_main_loop_run(m_mainLoop);
+    }
+};
+
+static void testWebViewIsWebProcessResponsive(WebViewIsWebProcessResponsiveTest* test, gconstpointer)
+{
+    static const char* hangHTML =
+        "<html>"
+        " <body>"
+        "  <script>"
+        "   setTimeout(function() {"
+        "    var start = new Date().getTime();"
+        "    var end = start;"
+        "     while(end < start + 4000) {"
+        "      end = new Date().getTime();"
+        "     }"
+        "    }, 500);"
+        "  </script>"
+        " </body>"
+        "</html>";
+
+    g_assert_true(webkit_web_view_get_is_web_process_responsive(test->m_webView));
+    test->loadHtml(hangHTML, nullptr);
+    test->waitUntilLoadFinished();
+    // Wait 1 second, so the js while loop kicks in and blocks the web process. Then try to load a new
+    // page. As the web process is busy this won't work, and after 3 seconds the web process will be marked
+    // as unresponsive.
+    test->wait(1);
+    test->loadHtml("<html></html>", nullptr);
+    test->waitUntilIsWebProcessResponsiveChanged();
+    g_assert_false(webkit_web_view_get_is_web_process_responsive(test->m_webView));
+    // 500ms after the web process is marked as unresponsive, the js while loop will finish and the process
+    // will be responsive again, finishing the pending load.
+    test->waitUntilLoadFinished();
+    g_assert_true(webkit_web_view_get_is_web_process_responsive(test->m_webView));
+}
+
 static void testWebViewBackgroundColor(WebViewTest* test, gconstpointer)
 {
 #if PLATFORM(GTK)
@@ -1578,6 +1628,7 @@
 #if PLATFORM(WPE) && USE(WPEBACKEND_FDO_AUDIO_EXTENSION)
     AudioRenderingWebViewTest::add("WebKitWebView", "external-audio-rendering", testWebViewExternalAudioRendering);
 #endif
+    WebViewIsWebProcessResponsiveTest::add("WebKitWebView", "is-web-process-responsive", testWebViewIsWebProcessResponsive);
 }
 
 void afterAll()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to