Title: [262940] trunk/Source/WebKit
Revision
262940
Author
ctur...@igalia.com
Date
2020-06-12 01:49:27 -0700 (Fri, 12 Jun 2020)

Log Message

[GTK] Add an internal API to run _javascript_ without forced user gestures
https://bugs.webkit.org/show_bug.cgi?id=212969

Reviewed by Carlos Garcia Campos.

To be used by tests in a follow-up commit.

* UIProcess/API/glib/WebKitWebView.cpp:
(webkitWebViewRunJavaScriptWithParams): Factor out the glue to run
_javascript_ in the page.
(webkitWebViewRunJavascriptWithoutForcedUserGestures): Add a new
internal API for use by tests.
(webkit_web_view_run_javascript): Modified to use factored out
glue.
* UIProcess/API/glib/WebKitWebViewInternal.h: Added. Place to keep
API test-specific internal APIs.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (262939 => 262940)


--- trunk/Source/WebKit/ChangeLog	2020-06-12 08:42:50 UTC (rev 262939)
+++ trunk/Source/WebKit/ChangeLog	2020-06-12 08:49:27 UTC (rev 262940)
@@ -1,3 +1,22 @@
+2020-06-12  Charlie Turner  <ctur...@igalia.com>
+
+        [GTK] Add an internal API to run _javascript_ without forced user gestures
+        https://bugs.webkit.org/show_bug.cgi?id=212969
+
+        Reviewed by Carlos Garcia Campos.
+
+        To be used by tests in a follow-up commit.
+
+        * UIProcess/API/glib/WebKitWebView.cpp:
+        (webkitWebViewRunJavaScriptWithParams): Factor out the glue to run
+        _javascript_ in the page.
+        (webkitWebViewRunJavascriptWithoutForcedUserGestures): Add a new
+        internal API for use by tests.
+        (webkit_web_view_run_javascript): Modified to use factored out
+        glue.
+        * UIProcess/API/glib/WebKitWebViewInternal.h: Added. Place to keep
+        API test-specific internal APIs.
+
 2020-06-12  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK4] Make WebDriver work

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


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2020-06-12 08:42:50 UTC (rev 262939)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2020-06-12 08:49:27 UTC (rev 262940)
@@ -60,6 +60,7 @@
 #include "WebKitUserMessagePrivate.h"
 #include "WebKitWebContextPrivate.h"
 #include "WebKitWebResourcePrivate.h"
+#include "WebKitWebViewInternal.h"
 #include "WebKitWebViewPrivate.h"
 #include "WebKitWebViewSessionStatePrivate.h"
 #include "WebKitWebsiteDataManagerPrivate.h"
@@ -3733,6 +3734,27 @@
         reinterpret_cast<GDestroyNotify>(webkit_javascript_result_unref));
 }
 
+static void webkitWebViewRunJavaScriptWithParams(WebKitWebView* webView, const gchar* script, RunJavaScriptParameters&& params, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData)
+{
+    GRefPtr<GTask> task = adoptGRef(g_task_new(webView, cancellable, callback, userData));
+
+    getPage(webView).runJavaScriptInMainFrame(WTFMove(params), [task = WTFMove(task)](API::SerializedScriptValue* serializedScriptValue, Optional<ExceptionDetails> details, WebKit::CallbackBase::Error) {
+        ExceptionDetails exceptionDetails;
+        if (details)
+            exceptionDetails = *details;
+        webkitWebViewRunJavaScriptCallback(serializedScriptValue, exceptionDetails, task.get());
+    });
+}
+
+void webkitWebViewRunJavascriptWithoutForcedUserGestures(WebKitWebView* webView, const gchar* script, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+    g_return_if_fail(script);
+
+    RunJavaScriptParameters params = { String::fromUTF8(script), URL { }, false, WTF::nullopt, false };
+    webkitWebViewRunJavaScriptWithParams(webView, script, WTFMove(params), cancellable, callback, userData);
+}
+
 /**
  * webkit_web_view_run_javascript:
  * @web_view: a #WebKitWebView
@@ -3752,13 +3774,8 @@
     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
     g_return_if_fail(script);
 
-    GRefPtr<GTask> task = adoptGRef(g_task_new(webView, cancellable, callback, userData));
-    getPage(webView).runJavaScriptInMainFrame({ String::fromUTF8(script), URL { }, false, WTF::nullopt, true }, [task = WTFMove(task)](API::SerializedScriptValue* serializedScriptValue, Optional<ExceptionDetails> details, WebKit::CallbackBase::Error) {
-        ExceptionDetails exceptionDetails;
-        if (details)
-            exceptionDetails = *details;
-        webkitWebViewRunJavaScriptCallback(serializedScriptValue, exceptionDetails, task.get());
-    });
+    RunJavaScriptParameters params = { String::fromUTF8(script), URL { }, false, WTF::nullopt, true };
+    webkitWebViewRunJavaScriptWithParams(webView, script, WTFMove(params), cancellable, callback, userData);
 }
 
 /**

Added: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewInternal.h (0 => 262940)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewInternal.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewInternal.h	2020-06-12 08:49:27 UTC (rev 262940)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2020 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include <gio/gio.h>
+
+// Private API required by the unit tests.
+
+typedef struct _WebKitWebView WebKitWebView;
+
+void webkitWebViewRunJavascriptWithoutForcedUserGestures(WebKitWebView*, const gchar*, GCancellable*, GAsyncReadyCallback, gpointer);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to