[epiphany/pgriffis/web-extension-fixes-2: 4/11] Move webextension to its own bundle




commit 9a1aa09752a17727fb801aadaa2b61a1d86d23b8
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Tue Jun 1 12:14:21 2021 +0200

    Move webextension to its own bundle
    
    Keep webextension api in its own bundle and therefore rework ephy-webextension cb handling.
    
    Fixes #1449
    Fixes #1448
    Fixes #1442

 .../ephy-web-process-extension.c                   |  34 ---
 .../web-process-extension/ephy-webextension-api.c  | 278 +++++++++++++++++----
 .../web-process-extension/ephy-webextension-api.h  |   9 +-
 embed/web-process-extension/meson.build            |  45 +++-
 .../resources/epiphany-web-extension.gresource.xml |   6 +
 src/webextension/ephy-web-extension-manager.c      | 122 ++++-----
 6 files changed, 327 insertions(+), 167 deletions(-)
---
diff --git a/embed/web-process-extension/ephy-web-process-extension.c 
b/embed/web-process-extension/ephy-web-process-extension.c
index 967559a86..54ecdfa0a 100644
--- a/embed/web-process-extension/ephy-web-process-extension.c
+++ b/embed/web-process-extension/ephy-web-process-extension.c
@@ -330,18 +330,6 @@ ephy_web_process_extension_user_message_received_cb (EphyWebProcessExtension *ex
       return;
 
     g_variant_get (parameters, "b", &extension->should_remember_passwords);
-  } else if (g_strcmp0 (name, "WebExtension.Add") == 0) {
-    GVariant *parameters;
-    const char *name;
-    const char *data;
-    guint64 length;
-
-    parameters = webkit_user_message_get_parameters (message);
-    if (!parameters)
-      return;
-
-    g_variant_get (parameters, "(&s&st)", &name, &data, &length);
-    webextensions_add_translation (extension, name, data, length);
   }
 }
 
@@ -663,28 +651,6 @@ window_object_cleared_cb (WebKitScriptWorld       *world,
   js_context = webkit_frame_get_js_context_for_script_world (frame, world);
   jsc_context_push_exception_handler (js_context, (JSCExceptionHandler)js_exception_handler, NULL, NULL);
 
-  /* If we are using the default script world, then we are a WebExtension. We
-   * must not register any internal Epiphany APIs, since they must never be
-   * accessible in the default script world. We don't want them exposed to the
-   * web or to WebExtensions. If we were to improperly allow access to our
-   * internal APIs, then malicious web content could do nasty things like
-   * iterate through passwords stored in EphyPasswordsManager, for example.
-   *
-   * And if we are not using the default script world, then we are not a
-   * WebExtension. There is no point in registering WebExtension APIs, because
-   * WebExtensions only have access to what is in the default script world
-   * anyway.
-   *
-   * FIXME: let's try to make this less confusing:
-   *
-   * https://gitlab.gnome.org/GNOME/epiphany/-/issues/1448
-   * https://gitlab.gnome.org/GNOME/epiphany/-/issues/1449
-   */
-  if (extension->script_world == webkit_script_world_get_default ()) {
-    set_up_webextensions (extension, page, js_context);
-    return;
-  }
-
   result = jsc_context_get_value (js_context, "Ephy");
   g_assert (jsc_value_is_undefined (result));
   g_clear_object (&result);
diff --git a/embed/web-process-extension/ephy-webextension-api.c 
b/embed/web-process-extension/ephy-webextension-api.c
index 35f5d85fd..05f81be8e 100644
--- a/embed/web-process-extension/ephy-webextension-api.c
+++ b/embed/web-process-extension/ephy-webextension-api.c
@@ -19,40 +19,56 @@
  */
 
 #include "config.h"
-#include "ephy-web-process-extension.h"
+#include "ephy-webextension-api.h"
 
 #include <locale.h>
 #include <json-glib/json-glib.h>
 #include <webkit2/webkit-web-extension.h>
 #include <JavaScriptCore/JavaScript.h>
 
-static char *
-js_getmessage (const char *message,
-               gpointer    user_data)
-{
-  EphyWebProcessExtension *extension = EPHY_WEB_PROCESS_EXTENSION (user_data);
-  GHashTable *translations = ephy_web_process_extension_get_translations (extension);
-  JsonObject *translation = NULL;
-  g_autoptr (JsonObject) name = NULL;
-  GList *list = NULL;
+struct _EphyWebExtensionExtension {
+  GObject parent_instance;
 
-  if (!extension)
-    return g_strdup (message);
+  WebKitWebExtension *extension;
+  gboolean initialized;
 
-  list = g_hash_table_get_values (translations);
-  if (list && list->data)
-    translation = list->data;
+  WebKitScriptWorld *script_world;
 
-  if (!translation) {
-    return g_strdup (message);
-  }
+  GHashTable *translation_table;
+  int counter;
+};
 
-  name = json_object_get_object_member (translation, message);
-  if (name) {
-    const char *trans = json_object_get_string_member (name, "message");
-    return g_strdup (trans);
-  }
+G_DEFINE_TYPE (EphyWebExtensionExtension, ephy_web_extension_extension, G_TYPE_OBJECT)
+
+static EphyWebExtensionExtension *extension = NULL;
 
+static GHashTable *
+ephy_web_extension_extension_get_translations (EphyWebExtensionExtension *extension)
+{
+  return extension->translation_table;
+}
+
+static void
+js_exception_handler (JSCContext   *context,
+                      JSCException *exception)
+{
+  g_autoptr (JSCValue) js_console = NULL;
+  g_autoptr (JSCValue) js_result = NULL;
+  g_autofree char *report = NULL;
+
+  js_console = jsc_context_get_value (context, "console");
+  js_result = jsc_value_object_invoke_method (js_console, "error", JSC_TYPE_EXCEPTION, exception, 
G_TYPE_NONE);
+  (void)js_result;
+  report = jsc_exception_report (exception);
+  g_warning ("%s", report);
+
+  jsc_context_throw_exception (context, exception);
+}
+
+static char *
+js_getmessage (const char *message,
+               gpointer    user_data)
+{
   return g_strdup (message);
 }
 
@@ -74,14 +90,147 @@ static char *
 js_geturl (const char *path,
            gpointer    user_data)
 {
-  return g_strdup_printf ("ephy-webextension:///%s", path);
+  JSCContext *context = jsc_context_get_current ();
+  JSCValue *value;
+  char *ret;
+
+  value = jsc_context_evaluate (context, "window.location.host", -1);
+  ret = g_strdup_printf ("ephy-webextension://%s/%s", jsc_value_to_string (value), path);
+
+  return ret;
+}
+
+static void
+ephy_web_extension_page_user_message_received_cb (WebKitWebPage     *page,
+                                                  WebKitUserMessage *message)
+{
+  const char *name = webkit_user_message_get_name (message);
+  WebKitFrame *frame = webkit_web_page_get_main_frame (page);
+  g_autoptr (JSCValue) value = NULL;
+
+  if (strcmp (name, "executeScript") == 0) {
+    GVariant *parameters;
+    const char *guid;
+    const char *path;
+    const char *code;
+    g_autofree char *uri = NULL;
+    JSCContext *context = webkit_frame_get_js_context (frame);
+
+    parameters = webkit_user_message_get_parameters (message);
+    if (!parameters)
+      return;
+
+    g_variant_get (parameters, "(&s&s&s)", &guid, &path, &code);
+    uri = g_strdup_printf ("ephy-webextension://%s/%s", guid, path);
+    value = jsc_context_evaluate_with_source_uri (context, code, -1, uri, 1);
+    g_clear_object (&value);
+  } else if (strcmp (name, "sendMessage") == 0) {
+    GVariant *parameters;
+    const char *script;
+    g_autofree char *uri = NULL;
+    JSCContext *context = webkit_frame_get_js_context (frame);
+
+    parameters = webkit_user_message_get_parameters (message);
+    if (!parameters)
+      return;
+
+    g_variant_get (parameters, "(&s)", &script);
+    value = jsc_context_evaluate (context, script, -1);
+    g_clear_object (&value);
+  }
 }
 
 void
-set_up_webextensions (EphyWebProcessExtension *extension,
-                      WebKitWebPage           *page,
-                      JSCContext              *js_context)
+webextensions_add_translation (EphyWebExtensionExtension *extension,
+                               const char                *name,
+                               const char                *data,
+                               guint64                    length)
+{
+  GHashTable *translations = ephy_web_extension_extension_get_translations (extension);
+  JsonParser *parser = NULL;
+  JsonNode *root;
+  JsonObject *root_object;
+  g_autoptr (GError) error = NULL;
+
+  g_hash_table_remove (translations, name);
+
+  if (!data || strlen (data) == 0)
+    return;
+
+  parser = json_parser_new ();
+  if (json_parser_load_from_data (parser, data, length, &error)) {
+    root = json_parser_get_root (parser);
+    g_assert (root);
+    root_object = json_node_get_object (root);
+    g_assert (root_object);
+
+    g_hash_table_insert (translations, (char *)name, json_object_ref (root_object));
+  } else {
+    g_warning ("Could not read translation json data: %s. '%s'", error->message, data);
+  }
+}
+
+static void
+ephy_web_extension_extension_page_created_cb (EphyWebExtensionExtension *extension,
+                                              WebKitWebPage             *web_page)
 {
+  g_autoptr (JSCContext) js_context = NULL;
+
+  /* Enforce the creation of the script world global context in the main frame */
+  js_context = webkit_frame_get_js_context_for_script_world (webkit_web_page_get_main_frame (web_page), 
extension->script_world);
+  (void)js_context;
+
+  g_signal_connect_swapped (web_page, "user-message-received",
+                            G_CALLBACK (ephy_web_extension_page_user_message_received_cb),
+                            web_page);
+}
+
+static void
+ephy_web_extension_dispose (GObject *object)
+{
+  EphyWebExtensionExtension *extension = EPHY_WEB_EXTENSION_EXTENSION (object);
+
+  g_clear_object (&extension->script_world);
+  g_clear_object (&extension->extension);
+
+  g_clear_pointer (&extension->translation_table, g_hash_table_destroy);
+
+  G_OBJECT_CLASS (ephy_web_extension_extension_parent_class)->dispose (object);
+}
+
+static void
+ephy_web_extension_extension_class_init (EphyWebExtensionExtensionClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = ephy_web_extension_dispose;
+}
+
+static void
+ephy_web_extension_extension_init (EphyWebExtensionExtension *extension)
+{
+}
+
+static gpointer
+ephy_web_extension_extension_create_instance (gpointer data)
+{
+  return g_object_new (EPHY_TYPE_WEB_EXTENSION_EXTENSION, NULL);
+}
+
+EphyWebExtensionExtension *
+ephy_web_extension_extension_get (void)
+{
+  static GOnce once_init = G_ONCE_INIT;
+  return EPHY_WEB_EXTENSION_EXTENSION (g_once (&once_init, ephy_web_extension_extension_create_instance, 
NULL));
+}
+
+static void
+window_object_cleared_cb (WebKitScriptWorld         *world,
+                          WebKitWebPage             *page,
+                          WebKitFrame               *frame,
+                          EphyWebExtensionExtension *extension)
+{
+  g_autoptr (JSCContext) js_context = NULL;
   g_autoptr (JSCValue) js_browser = NULL;
   g_autoptr (JSCValue) js_i18n = NULL;
   g_autoptr (JSCValue) js_extension = NULL;
@@ -91,6 +240,9 @@ set_up_webextensions (EphyWebProcessExtension *extension,
   const char *data;
   gsize data_size;
 
+  js_context = webkit_frame_get_js_context_for_script_world (frame, world);
+  jsc_context_push_exception_handler (js_context, (JSCExceptionHandler)js_exception_handler, NULL, NULL);
+
   result = jsc_context_get_value (js_context, "browser");
   g_assert (jsc_value_is_undefined (result));
 
@@ -130,38 +282,62 @@ set_up_webextensions (EphyWebProcessExtension *extension,
   jsc_value_object_set_property (js_extension, "getURL", js_function);
   g_clear_object (&js_function);
 
-  bytes = g_resources_lookup_data ("/org/gnome/epiphany-web-process-extension/js/webextensions.js", 
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+  bytes = g_resources_lookup_data ("/org/gnome/epiphany-web-extension/js/webextensions.js", 
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
   data = g_bytes_get_data (bytes, &data_size);
-  result = jsc_context_evaluate_with_source_uri (js_context, data, data_size, 
"resource:///org/gnome/epiphany-web-process-extension/js/webextensions.js", 1);
+  result = jsc_context_evaluate_with_source_uri (js_context, data, data_size, 
"resource:///org/gnome/epiphany-web-extension/js/webextensions.js", 1);
   g_clear_object (&result);
 }
 
 void
-webextensions_add_translation (EphyWebProcessExtension *extension,
-                               const char              *name,
-                               const char              *data,
-                               guint64                  length)
+ephy_web_extension_extension_initialize (EphyWebExtensionExtension *extension,
+                                         WebKitWebExtension        *wk_extension,
+                                         const char                *guid)
 {
-  GHashTable *translations = ephy_web_process_extension_get_translations (extension);
-  JsonParser *parser = NULL;
-  JsonNode *root;
-  JsonObject *root_object;
-  g_autoptr (GError) error = NULL;
-
-  g_hash_table_remove (translations, name);
+  g_assert (EPHY_IS_WEB_EXTENSION_EXTENSION (extension));
 
-  if (!data || strlen (data) == 0)
+  if (extension->initialized)
     return;
 
-  parser = json_parser_new ();
-  if (json_parser_load_from_data (parser, data, length, &error)) {
-    root = json_parser_get_root (parser);
-    g_assert (root);
-    root_object = json_node_get_object (root);
-    g_assert (root_object);
+  extension->initialized = TRUE;
 
-    g_hash_table_insert (translations, (char *)name, json_object_ref (root_object));
-  } else {
-    g_warning ("Could not read translation json data: %s. '%s'", error->message, data);
-  }
+  if (!guid || strlen (guid) == 0)
+    extension->script_world = webkit_script_world_get_default ();
+  else
+    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),
+                    extension);
+
+  extension->extension = g_object_ref (wk_extension);
+
+  g_signal_connect_swapped (extension->extension, "page-created",
+                            G_CALLBACK (ephy_web_extension_extension_page_created_cb),
+                            extension);
+
+  extension->translation_table = g_hash_table_new (g_str_hash, NULL);
+}
+
+G_MODULE_EXPORT void
+webkit_web_extension_initialize_with_user_data (WebKitWebExtension *webkit_extension,
+                                                GVariant           *user_data)
+{
+  const char *guid;
+  const char *profile_dir;
+  gboolean private_profile;
+  gboolean should_remember_passwords;
+
+  g_variant_get (user_data, "(&sm&sbb)", &guid, &profile_dir, &should_remember_passwords, &private_profile);
+  extension = ephy_web_extension_extension_get ();
+
+  ephy_web_extension_extension_initialize (extension,
+                                           webkit_extension,
+                                           guid);
+}
+
+static void __attribute__((destructor))
+ephy_web_extension_shutdown (void)
+{
+  g_clear_object (&extension);
 }
diff --git a/embed/web-process-extension/ephy-webextension-api.h 
b/embed/web-process-extension/ephy-webextension-api.h
index 64e21e30f..2a0d5aeda 100644
--- a/embed/web-process-extension/ephy-webextension-api.h
+++ b/embed/web-process-extension/ephy-webextension-api.h
@@ -25,13 +25,8 @@
 
 G_BEGIN_DECLS
 
-void set_up_webextensions          (EphyWebProcessExtension *extension,
-                                    WebKitWebPage           *page,
-                                    JSCContext              *js_context);
+#define EPHY_TYPE_WEB_EXTENSION_EXTENSION (ephy_web_extension_extension_get_type())
 
-void webextensions_add_translation (EphyWebProcessExtension *extension,
-                                    const char              *name,
-                                    const char              *data,
-                                    guint64                  length);
+G_DECLARE_FINAL_TYPE (EphyWebExtensionExtension, ephy_web_extension_extension, EPHY, 
WEB_EXTENSION_EXTENSION, GObject)
 
 G_END_DECLS
diff --git a/embed/web-process-extension/meson.build b/embed/web-process-extension/meson.build
index b50cb4079..d77fa2af0 100644
--- a/embed/web-process-extension/meson.build
+++ b/embed/web-process-extension/meson.build
@@ -1,6 +1,10 @@
-resource_files = files('resources/epiphany-web-process-extension.gresource.xml')
-resources = gnome.compile_resources('epiphany-web-process-extension-resources',
-    resource_files,
+#
+# Web Process Extensions
+#
+
+web_process_extension_resource_files = files('resources/epiphany-web-process-extension.gresource.xml')
+web_process_extension_resources = gnome.compile_resources('epiphany-web-process-extension-resources',
+    web_process_extension_resource_files,
     c_name: 'epiphany_web_process_extension',
     source_dir: 'resources'
 )
@@ -9,8 +13,7 @@ web_process_extension_sources = [
   'ephy-web-process-extension.c',
   'ephy-web-process-extension-main.c',
   'ephy-web-overview-model.c',
-  'ephy-webextension-api.c',
-  resources
+  web_process_extension_resources
 ]
 
 web_process_extension_deps = [
@@ -27,3 +30,35 @@ shared_module('ephywebprocessextension',
   install_dir: webprocessextensionsdir,
   install_rpath: pkglibdir
 )
+
+#
+# WebExtensions
+#
+
+web_extension_resource_files = files('resources/epiphany-web-extension.gresource.xml')
+web_extension_resources = gnome.compile_resources('epiphany-web-extension-resources',
+    web_extension_resource_files,
+    c_name: 'epiphany_web_extension',
+    source_dir: 'resources'
+)
+
+web_extension_sources = [
+  'ephy-webextension-api.c',
+  web_extension_resources
+]
+
+web_extension_deps = [
+  config_h,
+  ephymisc_dep,
+  ephysync_dep,
+  webkit2gtk_web_extension_dep
+]
+
+shared_module('ephywebextension',
+  web_extension_sources,
+  dependencies: web_extension_deps,
+  install: true,
+  install_dir: webprocessextensionsdir, # Same directory as above, single source
+  install_rpath: pkglibdir
+)
+
diff --git a/embed/web-process-extension/resources/epiphany-web-extension.gresource.xml 
b/embed/web-process-extension/resources/epiphany-web-extension.gresource.xml
new file mode 100644
index 000000000..9d5221ba9
--- /dev/null
+++ b/embed/web-process-extension/resources/epiphany-web-extension.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/epiphany-web-extension">
+    <file compressed="true">js/webextensions.js</file>
+  </gresource>
+</gresources>
diff --git a/src/webextension/ephy-web-extension-manager.c b/src/webextension/ephy-web-extension-manager.c
index 4aaa9f9fe..f93700cb2 100644
--- a/src/webextension/ephy-web-extension-manager.c
+++ b/src/webextension/ephy-web-extension-manager.c
@@ -189,9 +189,51 @@ ephy_web_extension_manager_class_init (EphyWebExtensionManagerClass *klass)
                   G_TYPE_NONE, 0);
 }
 
+static void
+web_extension_cb (WebKitURISchemeRequest *request,
+                  gpointer                user_data)
+{
+  EphyWebExtensionManager *self = EPHY_WEB_EXTENSION_MANAGER (user_data);
+  EphyWebExtension *web_extension = NULL;
+  const char *path;
+  const unsigned char *data;
+  gsize length;
+  g_autoptr (GInputStream) stream = NULL;
+  g_auto (GStrv) split = NULL;
+
+  path = webkit_uri_scheme_request_get_uri (request) + strlen ("ephy-webextension://");
+
+  split = g_strsplit (path, "/", -1);
+  /* FIND WEB EXTENSION */
+  for (GList *list = self->web_extensions; list && list->data; list = list->next) {
+    EphyWebExtension *ext = EPHY_WEB_EXTENSION (list->data);
+
+    if (strcmp (ephy_web_extension_get_guid (ext), split[0]) == 0) {
+      web_extension = EPHY_WEB_EXTENSION (list->data);
+      break;
+    }
+  }
+
+  if (!web_extension)
+    return;
+
+  data = ephy_web_extension_get_resource (web_extension, path + strlen (split[0]) + 1, &length);
+  if (!data)
+    return;
+
+  stream = g_memory_input_stream_new_from_data (data, length, NULL);
+  webkit_uri_scheme_request_finish (request, stream, length, NULL);
+}
+
 static void
 ephy_web_extension_manager_init (EphyWebExtensionManager *self)
 {
+  WebKitWebContext *web_context;
+
+  web_context = ephy_embed_shell_get_web_context (ephy_embed_shell_get_default ());
+  webkit_web_context_register_uri_scheme (web_context, "ephy-webextension", web_extension_cb, self, NULL);
+  webkit_security_manager_register_uri_scheme_as_secure (webkit_web_context_get_security_manager 
(web_context),
+                                                         "ephy-webextension");
 }
 
 EphyWebExtensionManager *
@@ -576,82 +618,22 @@ page_attached_cb (HdyTabView *tab_view,
   ephy_web_extension_manager_update_location_entry (self, window);
 }
 
-static void
-web_extension_cb (WebKitURISchemeRequest *request,
-                  gpointer                user_data)
-{
-  EphyWebExtension *web_extension = EPHY_WEB_EXTENSION (user_data);
-  const char *path;
-  const unsigned char *data;
-  gsize length;
-  g_autoptr (GInputStream) stream = NULL;
-
-  path = webkit_uri_scheme_request_get_path (request);
-
-  data = ephy_web_extension_get_resource (web_extension, path + 1, &length);
-  if (!data)
-    return;
-
-  stream = g_memory_input_stream_new_from_data (data, length, NULL);
-  webkit_uri_scheme_request_finish (request, stream, length, NULL);
-}
-
-static void
-init_web_extension_api (WebKitWebContext *web_context,
-                        EphyWebExtension *web_extension)
-{
-  g_autoptr (GVariant) user_data = NULL;
-
-#if DEVELOPER_MODE
-  webkit_web_context_set_web_extensions_directory (web_context, BUILD_ROOT "/embed/web-process-extension");
-#else
-  webkit_web_context_set_web_extensions_directory (web_context, EPHY_WEB_PROCESS_EXTENSIONS_DIR);
-#endif
-
-  user_data = g_variant_new ("(smsbb)",
-                             "",
-                             ephy_profile_dir_is_default () ? NULL : ephy_profile_dir (),
-                             FALSE,
-                             FALSE);
-  webkit_web_context_set_web_extensions_initialization_user_data (web_context, g_steal_pointer (&user_data));
-}
-
 static GtkWidget *
-create_web_extensions_webview (EphyWebExtension *web_extension,
-                               gboolean          custom_web_context)
+create_web_extensions_webview (EphyWebExtension *web_extension)
 {
   g_autoptr (WebKitUserContentManager) ucm = NULL;
-  WebKitWebContext *web_context;
   WebKitSettings *settings;
   GtkWidget *web_view;
 
   /* Create an own ucm so new scripts/css are only applied to this web_view */
   ucm = webkit_user_content_manager_new ();
-  g_signal_connect_object (ucm, "script-message-received", G_CALLBACK 
(ephy_web_extension_handle_background_script_message), web_extension, 0);
+  web_view = ephy_web_view_new_with_user_content_manager (ucm);
+  g_signal_connect_object (ucm, "script-message-received::epiphany", G_CALLBACK 
(ephy_web_extension_handle_background_script_message), web_extension, 0);
 
-  if (!custom_web_context) {
-    /* Get webcontext and register web_extension scheme */
-    webkit_user_content_manager_register_script_message_handler_in_world (ucm,
-                                                                          "epiphany",
-                                                                          ephy_embed_shell_get_guid 
(ephy_embed_shell_get_default ()));
-    web_context = ephy_embed_shell_get_web_context (ephy_embed_shell_get_default ());
-    webkit_web_context_register_uri_scheme (web_context, "ephy-webextension", web_extension_cb, 
web_extension, NULL);
-    webkit_security_manager_register_uri_scheme_as_secure (webkit_web_context_get_security_manager 
(web_context),
-                                                           "ephy-webextension");
-    web_view = ephy_web_view_new_with_user_content_manager (ucm);
-  } else {
-    webkit_user_content_manager_register_script_message_handler (ucm, "epiphany");
-    web_context = webkit_web_context_new ();
-    webkit_web_context_register_uri_scheme (web_context, "ephy-webextension", web_extension_cb, 
web_extension, NULL);
-    g_signal_connect_object (web_context, "initialize-web_extensions", G_CALLBACK (init_web_extension_api), 
web_extension, 0);
-    webkit_security_manager_register_uri_scheme_as_secure (webkit_web_context_get_security_manager 
(web_context),
-                                                           "ephy-webextension");
-    web_view = g_object_new (EPHY_TYPE_WEB_VIEW,
-                             "web-context", web_context,
-                             "user-content-manager", ucm,
-                             "settings", ephy_embed_prefs_get_settings (),
-                             NULL);
-  }
+  /* Get webcontext and register web_extension scheme */
+  webkit_user_content_manager_register_script_message_handler_in_world (ucm,
+                                                                        "epiphany",
+                                                                        ephy_embed_shell_get_guid 
(ephy_embed_shell_get_default ()));
 
   settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (web_view));
   webkit_settings_set_enable_write_console_messages_to_stdout (settings, TRUE);
@@ -673,11 +655,11 @@ create_browser_popup (EphyWebExtension *web_extension)
 
   popover = gtk_popover_new (NULL);
 
-  web_view = create_web_extensions_webview (web_extension, TRUE);
+  web_view = create_web_extensions_webview (web_extension);
 
   popup = ephy_web_extension_get_browser_popup (web_extension);
   dir_name = g_path_get_dirname (popup);
-  base_uri = g_strdup_printf ("ephy-webextension:///%s/", dir_name);
+  base_uri = g_strdup_printf ("ephy-webextension://%s/%s/", ephy_web_extension_get_guid (web_extension), 
dir_name);
   data = ephy_web_extension_get_resource_as_string (web_extension, popup);
   webkit_web_view_load_html (WEBKIT_WEB_VIEW (web_view), (char *)data, base_uri);
   gtk_container_add (GTK_CONTAINER (popover), web_view);
@@ -868,7 +850,7 @@ run_background_script (EphyWebExtensionManager *self,
   page = ephy_web_extension_background_web_view_get_page (web_extension);
 
   /* Create new background web_view */
-  background = create_web_extensions_webview (web_extension, page != NULL);
+  background = create_web_extensions_webview (web_extension);
   ephy_web_extension_manager_set_background_web_view (self, web_extension, EPHY_WEB_VIEW (background));
 
   if (page) {


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