[epiphany] Use webkit_web_view_run_javascript_in_world() to execute Ephy js code from the UI process



commit 318a8ad17b7bcb66668a63ce3eef772f41c1df3f
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Mon Jun 11 14:40:35 2018 +0200

    Use webkit_web_view_run_javascript_in_world() to execute Ephy js code from the UI process

 embed/ephy-embed-shell.c                      | 19 +++++++++----
 embed/ephy-embed-shell.h                      |  1 +
 embed/ephy-web-view.c                         | 39 ++++++++++++++-------------
 embed/web-extension/ephy-web-extension-main.c |  4 ++-
 embed/web-extension/ephy-web-extension.c      |  3 ++-
 embed/web-extension/ephy-web-extension.h      |  1 +
 meson.build                                   |  2 +-
 7 files changed, 43 insertions(+), 26 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 818178b27..e5909daea 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -63,6 +63,7 @@ typedef struct {
   EphyPermissionsManager *permissions_manager;
   EphyAboutHandler *about_handler;
   EphyViewSourceHandler *source_handler;
+  char *guid;
   GDBusServer *dbus_server;
   GList *web_extensions;
   EphyFiltersManager *filters_manager;
@@ -167,6 +168,7 @@ ephy_embed_shell_dispose (GObject *object)
   g_clear_object (&priv->downloads_manager);
   g_clear_object (&priv->permissions_manager);
   g_clear_object (&priv->web_context);
+  g_clear_pointer (&priv->guid, g_free);
   g_clear_object (&priv->dbus_server);
   g_clear_object (&priv->filters_manager);
   g_clear_object (&priv->search_engine_manager);
@@ -715,7 +717,8 @@ initialize_web_extensions (WebKitWebContext *web_context,
 
   private_profile = priv->mode == EPHY_EMBED_SHELL_MODE_PRIVATE || priv->mode == 
EPHY_EMBED_SHELL_MODE_INCOGNITO;
   browser_mode = priv->mode == EPHY_EMBED_SHELL_MODE_BROWSER;
-  user_data = g_variant_new ("(msssbb)",
+  user_data = g_variant_new ("(smsssbb)",
+                             priv->guid,
                              address,
                              ephy_dot_dir (),
                              ephy_filters_manager_get_adblock_filters_dir (priv->filters_manager),
@@ -779,12 +782,10 @@ ephy_embed_shell_setup_web_extensions_server (EphyEmbedShell *shell)
   EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
   GDBusAuthObserver *observer;
   char *address;
-  char *guid;
   GError *error = NULL;
 
   address = g_strdup_printf ("unix:tmpdir=%s", g_get_tmp_dir ());
 
-  guid = g_dbus_generate_guid ();
   observer = g_dbus_auth_observer_new ();
 
   g_signal_connect (observer, "authorize-authenticated-peer",
@@ -797,7 +798,7 @@ ephy_embed_shell_setup_web_extensions_server (EphyEmbedShell *shell)
    */
   priv->dbus_server = g_dbus_server_new_sync (address,
                                               G_DBUS_SERVER_FLAGS_NONE,
-                                              guid,
+                                              priv->guid,
                                               observer,
                                               NULL,
                                               &error);
@@ -814,7 +815,6 @@ ephy_embed_shell_setup_web_extensions_server (EphyEmbedShell *shell)
 
  out:
   g_free (address);
-  g_free (guid);
   g_object_unref (observer);
 }
 
@@ -1083,6 +1083,7 @@ ephy_embed_shell_constructed (GObject *object)
 
   shell = EPHY_EMBED_SHELL (object);
   priv = ephy_embed_shell_get_instance_private (shell);
+  priv->guid = g_dbus_generate_guid ();
   mode = ephy_embed_shell_get_mode (shell);
 
   /* These do not run the EmbedShell application instance, so make sure that
@@ -1465,6 +1466,14 @@ ephy_embed_shell_get_user_content_manager (EphyEmbedShell *shell)
   return priv->user_content;
 }
 
+const char *
+ephy_embed_shell_get_guid (EphyEmbedShell *shell)
+{
+  EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
+
+  return priv->guid;
+}
+
 WebKitWebContext *
 ephy_embed_shell_get_web_context (EphyEmbedShell *shell)
 {
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index 44c973632..23f2792ca 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -56,6 +56,7 @@ struct _EphyEmbedShellClass
 };
 
 EphyEmbedShell    *ephy_embed_shell_get_default                (void);
+const char        *ephy_embed_shell_get_guid                   (EphyEmbedShell   *shell);
 WebKitWebContext  *ephy_embed_shell_get_web_context            (EphyEmbedShell   *shell);
 EphyHistoryService
                   *ephy_embed_shell_get_global_history_service (EphyEmbedShell   *shell);
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 8a3b0655f..d6bad79e6 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -3207,7 +3207,7 @@ has_modified_forms_cb (WebKitWebView *view,
   WebKitJavascriptResult *js_result;
   gboolean retval = FALSE;
 
-  js_result = webkit_web_view_run_javascript_finish (view, result, NULL);
+  js_result = webkit_web_view_run_javascript_in_world_finish (view, result, NULL);
   if (js_result) {
     retval = jsc_value_to_boolean (webkit_javascript_result_get_js_value (js_result));
     webkit_javascript_result_unref (js_result);
@@ -3242,11 +3242,12 @@ ephy_web_view_has_modified_forms (EphyWebView        *view,
   g_assert (EPHY_IS_WEB_VIEW (view));
 
   task = g_task_new (view, cancellable, callback, user_data);
-  webkit_web_view_run_javascript (WEBKIT_WEB_VIEW (view),
-                                  "Ephy.hasModifiedForms();",
-                                  cancellable,
-                                  (GAsyncReadyCallback)has_modified_forms_cb,
-                                  task);
+  webkit_web_view_run_javascript_in_world (WEBKIT_WEB_VIEW (view),
+                                           "Ephy.hasModifiedForms();",
+                                           ephy_embed_shell_get_guid (ephy_embed_shell_get_default ()),
+                                           cancellable,
+                                           (GAsyncReadyCallback)has_modified_forms_cb,
+                                           task);
 }
 
 gboolean
@@ -3281,7 +3282,7 @@ get_best_web_app_icon_cb (WebKitWebView *view,
   WebKitJavascriptResult *js_result;
   GError *error = NULL;
 
-  js_result = webkit_web_view_run_javascript_finish (view, result, &error);
+  js_result = webkit_web_view_run_javascript_in_world_finish (view, result, &error);
   if (js_result) {
     JSCValue *js_value, *js_uri, *js_color;
     GetBestWebAppIconAsyncData *data;
@@ -3321,11 +3322,12 @@ ephy_web_view_get_best_web_app_icon (EphyWebView        *view,
 
   task = g_task_new (view, cancellable, callback, user_data);
   script = g_strdup_printf ("Ephy.getWebAppIcon(\"%s\");", webkit_web_view_get_uri (wk_view));
-  webkit_web_view_run_javascript (wk_view,
-                                  script,
-                                  cancellable,
-                                  (GAsyncReadyCallback)get_best_web_app_icon_cb,
-                                  task);
+  webkit_web_view_run_javascript_in_world (wk_view,
+                                           script,
+                                           ephy_embed_shell_get_guid (ephy_embed_shell_get_default ()),
+                                           cancellable,
+                                           (GAsyncReadyCallback)get_best_web_app_icon_cb,
+                                           task);
   g_free (script);
 }
 
@@ -3366,7 +3368,7 @@ get_web_app_title_cb (WebKitWebView *view,
   WebKitJavascriptResult *js_result;
   GError *error = NULL;
 
-  js_result = webkit_web_view_run_javascript_finish (view, result, &error);
+  js_result = webkit_web_view_run_javascript_in_world_finish (view, result, &error);
   if (js_result) {
     JSCValue *js_value;
     char *retval = NULL;
@@ -3393,11 +3395,12 @@ ephy_web_view_get_web_app_title (EphyWebView        *view,
   g_assert (EPHY_IS_WEB_VIEW (view));
 
   task = g_task_new (view, cancellable, callback, user_data);
-  webkit_web_view_run_javascript (WEBKIT_WEB_VIEW (view),
-                                  "Ephy.getWebAppTitle();",
-                                  cancellable,
-                                  (GAsyncReadyCallback)get_web_app_title_cb,
-                                  task);
+  webkit_web_view_run_javascript_in_world (WEBKIT_WEB_VIEW (view),
+                                           "Ephy.getWebAppTitle();",
+                                           ephy_embed_shell_get_guid (ephy_embed_shell_get_default ()),
+                                           cancellable,
+                                           (GAsyncReadyCallback)get_web_app_title_cb,
+                                           task);
 }
 
 char *
diff --git a/embed/web-extension/ephy-web-extension-main.c b/embed/web-extension/ephy-web-extension-main.c
index 1ca5ee6e2..3123b6ff7 100644
--- a/embed/web-extension/ephy-web-extension-main.c
+++ b/embed/web-extension/ephy-web-extension-main.c
@@ -34,6 +34,7 @@ G_MODULE_EXPORT void
 webkit_web_extension_initialize_with_user_data (WebKitWebExtension *webkit_extension,
                                                 GVariant           *user_data)
 {
+  const char *guid;
   const char *server_address;
   const char *dot_dir;
   const char *adblock_data_dir;
@@ -41,7 +42,7 @@ webkit_web_extension_initialize_with_user_data (WebKitWebExtension *webkit_exten
   gboolean browser_mode;
   GError *error = NULL;
 
-  g_variant_get (user_data, "(m&s&s&sbb)", &server_address, &dot_dir, &adblock_data_dir, &private_profile, 
&browser_mode);
+  g_variant_get (user_data, "(&sm&s&s&sbb)", &guid, &server_address, &dot_dir, &adblock_data_dir, 
&private_profile, &browser_mode);
 
   if (!server_address) {
     g_warning ("UI process did not start D-Bus server, giving up.");
@@ -59,6 +60,7 @@ webkit_web_extension_initialize_with_user_data (WebKitWebExtension *webkit_exten
 
   ephy_web_extension_initialize (extension,
                                  webkit_extension,
+                                 guid,
                                  server_address,
                                  adblock_data_dir,
                                  private_profile,
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index e9c904a18..e17901253 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -960,6 +960,7 @@ window_object_cleared_cb (WebKitScriptWorld *world,
 void
 ephy_web_extension_initialize (EphyWebExtension   *extension,
                                WebKitWebExtension *wk_extension,
+                               const char         *guid,
                                const char         *server_address,
                                const char         *adblock_data_dir,
                                gboolean            is_private_profile,
@@ -974,7 +975,7 @@ ephy_web_extension_initialize (EphyWebExtension   *extension,
 
   extension->initialized = TRUE;
 
-  extension->script_world = webkit_script_world_new ();
+  extension->script_world = webkit_script_world_new_with_name (guid);
   g_signal_connect (extension->script_world,
                     "window-object-cleared",
                     G_CALLBACK (window_object_cleared_cb),
diff --git a/embed/web-extension/ephy-web-extension.h b/embed/web-extension/ephy-web-extension.h
index 3475426ae..a3784beb7 100644
--- a/embed/web-extension/ephy-web-extension.h
+++ b/embed/web-extension/ephy-web-extension.h
@@ -32,6 +32,7 @@ G_DECLARE_FINAL_TYPE (EphyWebExtension, ephy_web_extension, EPHY, WEB_EXTENSION,
 EphyWebExtension *ephy_web_extension_get            (void);
 void              ephy_web_extension_initialize     (EphyWebExtension   *extension,
                                                      WebKitWebExtension *wk_extension,
+                                                     const char         *guid,
                                                      const char         *server_address,
                                                      const char         *adblock_data_dir,
                                                      gboolean            is_private_profile,
diff --git a/meson.build b/meson.build
index 65121058e..74c54e030 100644
--- a/meson.build
+++ b/meson.build
@@ -67,7 +67,7 @@ endif
 glib_requirement = '>= 2.52.0'
 gtk_requirement = '>= 3.22.13'
 nettle_requirement = '>= 3.2'
-webkitgtk_requirement = '>= 2.21.1'
+webkitgtk_requirement = '>= 2.21.4'
 
 cairo_dep = dependency('cairo', version: '>= 1.2')
 dazzle_dep = dependency('libdazzle-1.0', version: '>= 3.28.0')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]