[epiphany/pgriffis/web-extension/api-cleanups: 7/20] WebExtensions: Pass frameId to all API handlers




commit 0e5357f4088720255ec8845de7155f8651485d8f
Author: Patrick Griffis <pgriffis igalia com>
Date:   Thu Jun 30 21:00:29 2022 -0500

    WebExtensions: Pass frameId to all API handlers
    
    This is information used in some places.
    
    This bundles up everything into an EphyWebExtensionSender object
    which represesnts all the data of the sender.

 .../ephy-web-process-extension.c                   |   1 +
 .../web-process-extension/ephy-webextension-api.c  |   6 +
 .../ephy-webextension-common.c                     |   5 +-
 .../ephy-webextension-common.h                     |   1 +
 src/webextension/api/alarms.c                      |  72 +++++----
 src/webextension/api/alarms.h                      |   9 +-
 src/webextension/api/cookies.c                     |  68 ++++-----
 src/webextension/api/cookies.h                     |   9 +-
 src/webextension/api/downloads.c                   |  82 +++++-----
 src/webextension/api/downloads.h                   |   9 +-
 src/webextension/api/menus.c                       |  46 +++---
 src/webextension/api/menus.h                       |   9 +-
 src/webextension/api/notifications.c               |  48 +++---
 src/webextension/api/notifications.h               |   9 +-
 src/webextension/api/pageaction.c                  |  72 +++++----
 src/webextension/api/pageaction.h                  |   9 +-
 src/webextension/api/runtime.c                     |  62 ++++----
 src/webextension/api/runtime.h                     |   9 +-
 src/webextension/api/storage.c                     |  65 ++++----
 src/webextension/api/storage.h                     |   9 +-
 src/webextension/api/tabs.c                        | 165 ++++++++++-----------
 src/webextension/api/tabs.h                        |   9 +-
 src/webextension/api/windows.c                     |  93 ++++++------
 src/webextension/api/windows.h                     |   9 +-
 src/webextension/ephy-web-extension-manager.c      |  59 ++++----
 src/webextension/ephy-web-extension-manager.h      |   9 +-
 src/webextension/ephy-web-extension.c              |  14 +-
 src/webextension/ephy-web-extension.h              |  43 +++---
 28 files changed, 473 insertions(+), 528 deletions(-)
---
diff --git a/embed/web-process-extension/ephy-web-process-extension.c 
b/embed/web-process-extension/ephy-web-process-extension.c
index 01afd379a..ad57ad331 100644
--- a/embed/web-process-extension/ephy-web-process-extension.c
+++ b/embed/web-process-extension/ephy-web-process-extension.c
@@ -259,6 +259,7 @@ content_script_window_object_cleared_cb (WebKitScriptWorld *world,
   g_clear_object (&result);
 
   ephy_webextension_install_common_apis (page,
+                                         frame,
                                          js_context,
                                          guid,
                                          translations);
diff --git a/embed/web-process-extension/ephy-webextension-api.c 
b/embed/web-process-extension/ephy-webextension-api.c
index 6f097048b..2df4df038 100644
--- a/embed/web-process-extension/ephy-webextension-api.c
+++ b/embed/web-process-extension/ephy-webextension-api.c
@@ -178,8 +178,13 @@ window_object_cleared_cb (WebKitScriptWorld         *world,
   g_autoptr (GBytes) bytes = NULL;
   g_autoptr (JSCValue) result = NULL;
   const char *data;
+  const char *uri;
   gsize data_size;
 
+  uri = webkit_web_page_get_uri (page);
+  if (!uri || !g_str_has_prefix (uri, "ephy-webextension:"))
+    return;
+
   js_context = webkit_frame_get_js_context_for_script_world (frame, world);
 
   /* FIXME: This is a herustic that the first view is the background view.
@@ -202,6 +207,7 @@ window_object_cleared_cb (WebKitScriptWorld         *world,
   g_clear_object (&result);
 
   ephy_webextension_install_common_apis (page,
+                                         frame,
                                          js_context,
                                          extension->guid,
                                          extension->translations);
diff --git a/embed/web-process-extension/ephy-webextension-common.c 
b/embed/web-process-extension/ephy-webextension-common.c
index 6726d1dbe..41d36df39 100644
--- a/embed/web-process-extension/ephy-webextension-common.c
+++ b/embed/web-process-extension/ephy-webextension-common.c
@@ -24,6 +24,7 @@
 
 typedef struct {
   WebKitWebPage *page;
+  WebKitFrame *frame;
   const char *guid;
 } EphySendMessageData;
 
@@ -105,7 +106,7 @@ ephy_send_message (const char *function_name,
 
   args_json = jsc_value_to_json (function_args, 0);
   message = webkit_user_message_new (function_name,
-                                     g_variant_new ("(ss)", send_message_data->guid, args_json));
+                                     g_variant_new ("(sts)", send_message_data->guid, webkit_frame_get_id 
(send_message_data->frame), args_json));
 
   webkit_web_page_send_message_to_view (send_message_data->page, message, NULL,
                                         (GAsyncReadyCallback)on_send_message_finish,
@@ -174,6 +175,7 @@ js_exception_handler (JSCContext   *context,
 
 void
 ephy_webextension_install_common_apis (WebKitWebPage *page,
+                                       WebKitFrame   *frame,
                                        JSCContext    *js_context,
                                        const char    *guid,
                                        JsonObject    *translations)
@@ -231,6 +233,7 @@ ephy_webextension_install_common_apis (WebKitWebPage *page,
   /* global functions */
   send_message_data = g_new (EphySendMessageData, 1);
   send_message_data->page = page;
+  send_message_data->frame = frame;
   send_message_data->guid = guid;
   js_function = jsc_value_new_function (js_context,
                                         NULL,
diff --git a/embed/web-process-extension/ephy-webextension-common.h 
b/embed/web-process-extension/ephy-webextension-common.h
index 220838356..cda5e308e 100644
--- a/embed/web-process-extension/ephy-webextension-common.h
+++ b/embed/web-process-extension/ephy-webextension-common.h
@@ -28,6 +28,7 @@
 G_BEGIN_DECLS
 
 void ephy_webextension_install_common_apis (WebKitWebPage *page,
+                                            WebKitFrame   *frame,
                                             JSCContext    *js_context,
                                             const char    *guid,
                                             JsonObject    *translations);
diff --git a/src/webextension/api/alarms.c b/src/webextension/api/alarms.c
index b1722a334..eda9252bf 100644
--- a/src/webextension/api/alarms.c
+++ b/src/webextension/api/alarms.c
@@ -163,15 +163,14 @@ on_alarm_start (gpointer user_data)
 }
 
 static char *
-alarms_handler_create (EphyWebExtension  *self,
-                       char              *name,
-                       JSCValue          *args,
-                       WebKitWebView     *web_view,
-                       GError           **error)
+alarms_handler_create (EphyWebExtensionSender *sender,
+                       char                   *name,
+                       JSCValue               *args,
+                       GError                **error)
 {
   g_autoptr (JSCValue) alarm_name = NULL;
   g_autoptr (JSCValue) alarm_info = NULL;
-  GHashTable *alarms = get_alarms (self);
+  GHashTable *alarms = get_alarms (sender->extension);
   Alarm *alarm;
   double delay_in_minutes = 0.0;
   double period_in_minutes = 0.0;
@@ -201,7 +200,7 @@ alarms_handler_create (EphyWebExtension  *self,
 
   alarm = g_new0 (Alarm, 1);
   alarm->repeat_interval_ms = minutes_to_ms (period_in_minutes);
-  alarm->web_extension = self;
+  alarm->web_extension = sender->extension;
   alarm->name = g_steal_pointer (&name_str);
 
   if (delay_in_minutes) {
@@ -221,13 +220,12 @@ alarms_handler_create (EphyWebExtension  *self,
 }
 
 static char *
-alarms_handler_clear (EphyWebExtension  *self,
-                      char              *name,
-                      JSCValue          *args,
-                      WebKitWebView     *web_view,
-                      GError           **error)
+alarms_handler_clear (EphyWebExtensionSender *sender,
+                      char                   *name,
+                      JSCValue               *args,
+                      GError                **error)
 {
-  GHashTable *alarms = get_alarms (self);
+  GHashTable *alarms = get_alarms (sender->extension);
   g_autoptr (JSCValue) name_value = jsc_value_object_get_property_at_index (args, 0);
   g_autofree char *name_str = NULL;
 
@@ -243,13 +241,12 @@ alarms_handler_clear (EphyWebExtension  *self,
 }
 
 static char *
-alarms_handler_clear_all (EphyWebExtension  *self,
-                          char              *name,
-                          JSCValue          *args,
-                          WebKitWebView     *web_view,
-                          GError           **error)
+alarms_handler_clear_all (EphyWebExtensionSender  *sender,
+                          char                    *name,
+                          JSCValue                *args,
+                          GError                 **error)
 {
-  GHashTable *alarms = get_alarms (self);
+  GHashTable *alarms = get_alarms (sender->extension);
 
   if (g_hash_table_size (alarms) == 0)
     return g_strdup ("false");
@@ -259,13 +256,12 @@ alarms_handler_clear_all (EphyWebExtension  *self,
 }
 
 static char *
-alarms_handler_get (EphyWebExtension  *self,
-                    char              *name,
-                    JSCValue          *args,
-                    WebKitWebView     *web_view,
-                    GError           **error)
+alarms_handler_get (EphyWebExtensionSender  *sender,
+                    char                    *name,
+                    JSCValue                *args,
+                    GError                 **error)
 {
-  GHashTable *alarms = get_alarms (self);
+  GHashTable *alarms = get_alarms (sender->extension);
   g_autoptr (JSCValue) name_value = jsc_value_object_get_property_at_index (args, 0);
   g_autofree char *name_str = NULL;
   Alarm *alarm;
@@ -280,13 +276,12 @@ alarms_handler_get (EphyWebExtension  *self,
 }
 
 static char *
-alarms_handler_get_all (EphyWebExtension  *self,
-                        char              *name,
-                        JSCValue          *args,
-                        WebKitWebView     *web_view,
-                        GError           **error)
+alarms_handler_get_all (EphyWebExtensionSender  *sender,
+                        char                    *name,
+                        JSCValue                *args,
+                        GError                 **error)
 {
-  GHashTable *alarms = get_alarms (self);
+  GHashTable *alarms = get_alarms (sender->extension);
   g_autoptr (JsonNode) node = json_node_init_array (json_node_alloc (), json_array_new ());
   JsonArray *array = json_node_get_array (node);
   GHashTableIter iter;
@@ -308,16 +303,15 @@ static EphyWebExtensionSyncApiHandler alarms_handlers[] = {
 };
 
 void
-ephy_web_extension_api_alarms_handler (EphyWebExtension *self,
-                                       char             *name,
-                                       JSCValue         *args,
-                                       WebKitWebView    *web_view,
-                                       GTask            *task)
+ephy_web_extension_api_alarms_handler (EphyWebExtensionSender *sender,
+                                       char                   *name,
+                                       JSCValue               *args,
+                                       GTask                  *task)
 {
   g_autoptr (GError) error = NULL;
 
-  if (!ephy_web_extension_has_permission (self, "alarms")) {
-    g_warning ("Extension %s tried to use alarms without permission.", ephy_web_extension_get_name (self));
+  if (!ephy_web_extension_has_permission (sender->extension, "alarms")) {
+    g_warning ("Extension %s tried to use alarms without permission.", ephy_web_extension_get_name 
(sender->extension));
     error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "alarms: 
Permission Denied");
     g_task_return_error (task, g_steal_pointer (&error));
     return;
@@ -328,7 +322,7 @@ ephy_web_extension_api_alarms_handler (EphyWebExtension *self,
     char *ret;
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      ret = handler.execute (self, name, args, web_view, &error);
+      ret = handler.execute (sender, name, args, &error);
 
       if (error)
         g_task_return_error (task, g_steal_pointer (&error));
diff --git a/src/webextension/api/alarms.h b/src/webextension/api/alarms.h
index 2114c95a3..6e64bee05 100644
--- a/src/webextension/api/alarms.h
+++ b/src/webextension/api/alarms.h
@@ -27,10 +27,9 @@
 
 G_BEGIN_DECLS
 
-void ephy_web_extension_api_alarms_handler (EphyWebExtension *self,
-                                            char            *name,
-                                            JSCValue        *value,
-                                            WebKitWebView   *web_view,
-                                            GTask           *task);
+void ephy_web_extension_api_alarms_handler (EphyWebExtensionSender *sender,
+                                            char                   *name,
+                                            JSCValue               *value,
+                                            GTask                  *task);
 
 G_END_DECLS
diff --git a/src/webextension/api/cookies.c b/src/webextension/api/cookies.c
index faff077c1..1987788b2 100644
--- a/src/webextension/api/cookies.c
+++ b/src/webextension/api/cookies.c
@@ -206,11 +206,10 @@ get_cookies_ready_cb (WebKitCookieManager *cookie_manager,
 }
 
 static void
-cookies_handler_get (EphyWebExtension *self,
-                     char             *name,
-                     JSCValue         *args,
-                     WebKitWebView    *web_view,
-                     GTask            *task)
+cookies_handler_get (EphyWebExtensionSender *sender,
+                     char                   *name,
+                     JSCValue               *args,
+                     GTask                  *task)
 {
   g_autoptr (JSCValue) details = jsc_value_object_get_property_at_index (args, 0);
   WebKitCookieManager *cookie_manager = get_cookie_manager ();
@@ -231,7 +230,7 @@ cookies_handler_get (EphyWebExtension *self,
     return;
   }
 
-  if (!ephy_web_extension_has_host_permission (self, url)) {
+  if (!ephy_web_extension_has_host_permission (sender->extension, url)) {
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, 
"cookies.get(): Permission denied for host '%s'", url);
     return;
   }
@@ -264,11 +263,10 @@ add_cookie_ready_cb (WebKitCookieManager *cookie_manager,
 }
 
 static void
-cookies_handler_set (EphyWebExtension *self,
-                     char             *name,
-                     JSCValue         *args,
-                     WebKitWebView    *web_view,
-                     GTask            *task)
+cookies_handler_set (EphyWebExtensionSender *sender,
+                     char                   *name,
+                     JSCValue               *args,
+                     GTask                  *task)
 {
   g_autoptr (JSCValue) details = jsc_value_object_get_property_at_index (args, 0);
   g_autofree char *url = NULL;
@@ -306,7 +304,7 @@ cookies_handler_set (EphyWebExtension *self,
     return;
   }
 
-  if (!ephy_web_extension_has_host_permission (self, url) || (domain && 
!ephy_web_extension_has_host_permission (self, domain))) {
+  if (!ephy_web_extension_has_host_permission (sender->extension, url) || (domain && 
!ephy_web_extension_has_host_permission (sender->extension, domain))) {
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, 
"cookies.set(): Permission denied for host '%s'", url);
     return;
   }
@@ -334,11 +332,10 @@ cookies_handler_set (EphyWebExtension *self,
 }
 
 static void
-cookies_handler_remove (EphyWebExtension *self,
-                        char             *name,
-                        JSCValue         *args,
-                        WebKitWebView    *web_view,
-                        GTask            *task)
+cookies_handler_remove (EphyWebExtensionSender *sender,
+                        char                   *name,
+                        JSCValue               *args,
+                        GTask                  *task)
 {
   g_autoptr (JSCValue) details = jsc_value_object_get_property_at_index (args, 0);
   g_autofree char *url = NULL;
@@ -359,7 +356,7 @@ cookies_handler_remove (EphyWebExtension *self,
     return;
   }
 
-  if (!ephy_web_extension_has_host_permission (self, url)) {
+  if (!ephy_web_extension_has_host_permission (sender->extension, url)) {
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, 
"cookies.remove(): Permission denied for host '%s'", url);
     return;
   }
@@ -459,11 +456,10 @@ get_all_cookies_ready_cb (WebKitCookieManager       *cookie_manager,
 }
 
 static void
-cookies_handler_get_all (EphyWebExtension *self,
-                         char             *name,
-                         JSCValue         *args,
-                         WebKitWebView    *web_view,
-                         GTask            *task)
+cookies_handler_get_all (EphyWebExtensionSender *sender,
+                         char                   *name,
+                         JSCValue               *args,
+                         GTask                  *task)
 {
   g_autoptr (JSCValue) details = jsc_value_object_get_property_at_index (args, 0);
   WebKitCookieManager *cookie_manager = get_cookie_manager ();
@@ -484,7 +480,7 @@ cookies_handler_get_all (EphyWebExtension *self,
     return;
   }
 
-  if (!ephy_web_extension_has_host_permission (self, url)) {
+  if (!ephy_web_extension_has_host_permission (sender->extension, url)) {
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, 
"cookies.getAll(): Permission denied for host '%s'", url);
     return;
   }
@@ -525,11 +521,10 @@ create_array_of_all_tab_ids (void)
 }
 
 static void
-cookies_handler_get_all_cookie_stores (EphyWebExtension *self,
-                                       char             *name,
-                                       JSCValue         *args,
-                                       WebKitWebView    *web_view,
-                                       GTask            *task)
+cookies_handler_get_all_cookie_stores (EphyWebExtensionSender *sender,
+                                       char                   *name,
+                                       JSCValue               *args,
+                                       GTask                  *task)
 {
   g_autoptr (JsonBuilder) builder = json_builder_new ();
   g_autoptr (JsonNode) root = NULL;
@@ -560,16 +555,15 @@ static EphyWebExtensionAsyncApiHandler cookies_async_handlers[] = {
 };
 
 void
-ephy_web_extension_api_cookies_handler (EphyWebExtension *self,
-                                        char             *name,
-                                        JSCValue         *args,
-                                        WebKitWebView    *web_view,
-                                        GTask            *task)
+ephy_web_extension_api_cookies_handler (EphyWebExtensionSender *sender,
+                                        char                   *name,
+                                        JSCValue               *args,
+                                        GTask                  *task)
 {
   g_autoptr (GError) error = NULL;
 
-  if (!ephy_web_extension_has_permission (self, "cookies")) {
-    g_warning ("Extension %s tried to use cookies without permission.", ephy_web_extension_get_name (self));
+  if (!ephy_web_extension_has_permission (sender->extension, "cookies")) {
+    g_warning ("Extension %s tried to use cookies without permission.", ephy_web_extension_get_name 
(sender->extension));
     error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission 
Denied");
     g_task_return_error (task, g_steal_pointer (&error));
     return;
@@ -579,7 +573,7 @@ ephy_web_extension_api_cookies_handler (EphyWebExtension *self,
     EphyWebExtensionAsyncApiHandler handler = cookies_async_handlers[idx];
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      handler.execute (self, name, args, web_view, task);
+      handler.execute (sender, name, args, task);
       return;
     }
   }
diff --git a/src/webextension/api/cookies.h b/src/webextension/api/cookies.h
index 8c8d1dfdd..079fd11ac 100644
--- a/src/webextension/api/cookies.h
+++ b/src/webextension/api/cookies.h
@@ -26,10 +26,9 @@
 
 G_BEGIN_DECLS
 
-void         ephy_web_extension_api_cookies_handler                    (EphyWebExtension *self,
-                                                                        char             *name,
-                                                                        JSCValue         *value,
-                                                                        WebKitWebView    *web_view,
-                                                                        GTask            *task);
+void         ephy_web_extension_api_cookies_handler                    (EphyWebExtensionSender *sender,
+                                                                        char                   *name,
+                                                                        JSCValue               *value,
+                                                                        GTask                  *task);
 
 G_END_DECLS
diff --git a/src/webextension/api/downloads.c b/src/webextension/api/downloads.c
index d0cc791c0..6038d2e75 100644
--- a/src/webextension/api/downloads.c
+++ b/src/webextension/api/downloads.c
@@ -33,11 +33,10 @@ get_downloads_manager (void)
 }
 
 static void
-downloads_handler_download (EphyWebExtension *self,
-                            char             *name,
-                            JSCValue         *args,
-                            WebKitWebView    *web_view,
-                            GTask            *task)
+downloads_handler_download (EphyWebExtensionSender *sender,
+                            char                   *name,
+                            JSCValue               *args,
+                            GTask                  *task)
 {
   g_autoptr (JSCValue) options = jsc_value_object_get_property_at_index (args, 0);
   EphyDownloadsManager *downloads_manager = get_downloads_manager ();
@@ -82,7 +81,7 @@ downloads_handler_download (EphyWebExtension *self,
   ephy_download_set_choose_filename (download, TRUE);
   ephy_download_set_suggested_destination (download, suggested_directory, suggested_filename);
   ephy_download_set_always_ask_destination (download, api_utils_get_boolean_property (options, "saveAs", 
FALSE));
-  ephy_download_set_initiating_web_extension_info (download, ephy_web_extension_get_guid (self), 
ephy_web_extension_get_name (self));
+  ephy_download_set_initiating_web_extension_info (download, ephy_web_extension_get_guid 
(sender->extension), ephy_web_extension_get_name (sender->extension));
   ephy_downloads_manager_add_download (downloads_manager, download);
 
   /* FIXME: We should wait to return until after the user has been prompted to error if they cancelled it. */
@@ -92,11 +91,10 @@ downloads_handler_download (EphyWebExtension *self,
 }
 
 static char *
-downloads_handler_cancel (EphyWebExtension  *self,
-                          char              *name,
-                          JSCValue          *args,
-                          WebKitWebView     *web_view,
-                          GError           **error)
+downloads_handler_cancel (EphyWebExtensionSender  *sender,
+                          char                    *name,
+                          JSCValue                *args,
+                          GError                 **error)
 {
   g_autoptr (JSCValue) download_id = jsc_value_object_get_property_at_index (args, 0);
   EphyDownloadsManager *downloads_manager = get_downloads_manager ();
@@ -117,11 +115,10 @@ downloads_handler_cancel (EphyWebExtension  *self,
 }
 
 static char *
-downloads_handler_open_or_show (EphyWebExtension  *self,
-                                char              *name,
-                                JSCValue          *args,
-                                WebKitWebView     *web_view,
-                                GError           **error)
+downloads_handler_open_or_show (EphyWebExtensionSender  *sender,
+                                char                    *name,
+                                JSCValue                *args,
+                                GError                 **error)
 {
   g_autoptr (JSCValue) download_id = jsc_value_object_get_property_at_index (args, 0);
   EphyDownloadsManager *downloads_manager = get_downloads_manager ();
@@ -617,11 +614,10 @@ download_to_json (EphyDownload *download)
 }
 
 static char *
-downloads_handler_search (EphyWebExtension  *self,
-                          char              *name,
-                          JSCValue          *args,
-                          WebKitWebView     *web_view,
-                          GError           **error)
+downloads_handler_search (EphyWebExtensionSender  *sender,
+                          char                    *name,
+                          JSCValue                *args,
+                          GError                 **error)
 {
   g_autoptr (JSCValue) query_object = jsc_value_object_get_property_at_index (args, 0);
   EphyDownloadsManager *downloads_manager = get_downloads_manager ();
@@ -649,11 +645,10 @@ downloads_handler_search (EphyWebExtension  *self,
 }
 
 static char *
-downloads_handler_erase (EphyWebExtension  *self,
-                         char              *name,
-                         JSCValue          *args,
-                         WebKitWebView     *web_view,
-                         GError           **error)
+downloads_handler_erase (EphyWebExtensionSender  *sender,
+                         char                    *name,
+                         JSCValue                *args,
+                         GError                 **error)
 {
   g_autoptr (JSCValue) query_object = jsc_value_object_get_property_at_index (args, 0);
   EphyDownloadsManager *downloads_manager = get_downloads_manager ();
@@ -685,11 +680,10 @@ downloads_handler_erase (EphyWebExtension  *self,
 }
 
 static char *
-downloads_handler_showdefaultfolder (EphyWebExtension  *self,
-                                     char              *name,
-                                     JSCValue          *args,
-                                     WebKitWebView     *web_view,
-                                     GError           **error)
+downloads_handler_showdefaultfolder (EphyWebExtensionSender  *sender,
+                                     char                    *name,
+                                     JSCValue                *args,
+                                     GError                 **error)
 {
   g_autoptr (GFile) default_folder = g_file_new_for_path (ephy_file_get_downloads_dir ());
   ephy_file_browse_to (default_folder);
@@ -715,11 +709,10 @@ delete_file_ready_cb (GFile        *file,
 }
 
 static void
-downloads_handler_removefile (EphyWebExtension *self,
-                              char             *name,
-                              JSCValue         *args,
-                              WebKitWebView    *web_view,
-                              GTask            *task)
+downloads_handler_removefile (EphyWebExtensionSender *sender,
+                              char                   *name,
+                              JSCValue               *args,
+                              GTask                  *task)
 {
   g_autoptr (JSCValue) download_id = jsc_value_object_get_property_at_index (args, 0);
   EphyDownloadsManager *downloads_manager = get_downloads_manager ();
@@ -767,16 +760,15 @@ static EphyWebExtensionAsyncApiHandler downloads_async_handlers[] = {
 };
 
 void
-ephy_web_extension_api_downloads_handler (EphyWebExtension *self,
-                                          char             *name,
-                                          JSCValue         *args,
-                                          WebKitWebView    *web_view,
-                                          GTask            *task)
+ephy_web_extension_api_downloads_handler (EphyWebExtensionSender *sender,
+                                          char                   *name,
+                                          JSCValue               *args,
+                                          GTask                  *task)
 {
   g_autoptr (GError) error = NULL;
 
-  if (!ephy_web_extension_has_permission (self, "downloads")) {
-    g_warning ("Extension %s tried to use downloads without permission.", ephy_web_extension_get_name 
(self));
+  if (!ephy_web_extension_has_permission (sender->extension, "downloads")) {
+    g_warning ("Extension %s tried to use downloads without permission.", ephy_web_extension_get_name 
(sender->extension));
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "downloads: 
Permission Denied");
     return;
   }
@@ -785,7 +777,7 @@ ephy_web_extension_api_downloads_handler (EphyWebExtension *self,
     EphyWebExtensionAsyncApiHandler handler = downloads_async_handlers[idx];
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      handler.execute (self, name, args, web_view, task);
+      handler.execute (sender, name, args, task);
       return;
     }
   }
@@ -795,7 +787,7 @@ ephy_web_extension_api_downloads_handler (EphyWebExtension *self,
     char *ret;
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      ret = handler.execute (self, name, args, web_view, &error);
+      ret = handler.execute (sender, name, args, &error);
 
       if (error)
         g_task_return_error (task, g_steal_pointer (&error));
diff --git a/src/webextension/api/downloads.h b/src/webextension/api/downloads.h
index f91ad6e2e..9bb9726cf 100644
--- a/src/webextension/api/downloads.h
+++ b/src/webextension/api/downloads.h
@@ -32,10 +32,9 @@ void ephy_web_extension_api_downloads_init (EphyWebExtensionManager *manager);
 
 void ephy_web_extension_api_downloads_dispose (EphyWebExtensionManager *manager);
 
-void ephy_web_extension_api_downloads_handler (EphyWebExtension *self,
-                                               char             *name,
-                                               JSCValue         *value,
-                                               WebKitWebView    *web_view,
-                                               GTask            *task);
+void ephy_web_extension_api_downloads_handler (EphyWebExtensionSender *sender,
+                                               char                   *name,
+                                               JSCValue               *value,
+                                               GTask                  *task);
 
 G_END_DECLS
diff --git a/src/webextension/api/menus.c b/src/webextension/api/menus.c
index eb0ef209c..752fbb0f5 100644
--- a/src/webextension/api/menus.c
+++ b/src/webextension/api/menus.c
@@ -318,15 +318,14 @@ get_menus (EphyWebExtension *extension)
 }
 
 static void
-menus_handler_create (EphyWebExtension *self,
-                      char             *name,
-                      JsonArray        *args,
-                      WebKitWebView    *web_view,
-                      GTask            *task)
+menus_handler_create (EphyWebExtensionSender *sender,
+                      char                   *name,
+                      JsonArray              *args,
+                      GTask                  *task)
 {
   JsonObject *create_properties = ephy_json_array_get_object (args, 0);
   MenuItem *item;
-  GHashTable *menus = get_menus (self);
+  GHashTable *menus = get_menus (sender->extension);
 
   if (!create_properties) {
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, 
"menus.create(): Missing createProperties");
@@ -373,11 +372,10 @@ menus_remove_by_id (GHashTable *menus,
 }
 
 static void
-menus_handler_remove (EphyWebExtension *self,
-                      char             *name,
-                      JsonArray        *args,
-                      WebKitWebView    *web_view,
-                      GTask            *task)
+menus_handler_remove (EphyWebExtensionSender *sender,
+                      char                   *name,
+                      JsonArray              *args,
+                      GTask                  *task)
 {
   const char *menu_id = ephy_json_array_get_string (args, 0);
 
@@ -386,7 +384,7 @@ menus_handler_remove (EphyWebExtension *self,
     return;
   }
 
-  if (!menus_remove_by_id (get_menus (self), menu_id)) {
+  if (!menus_remove_by_id (get_menus (sender->extension), menu_id)) {
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, 
"menus.remove(): Failed to find menuId '%s'", menu_id);
     return;
   }
@@ -395,13 +393,12 @@ menus_handler_remove (EphyWebExtension *self,
 }
 
 static void
-menus_handler_remove_all (EphyWebExtension *self,
-                          char             *name,
-                          JsonArray        *args,
-                          WebKitWebView    *web_view,
-                          GTask            *task)
+menus_handler_remove_all (EphyWebExtensionSender *sender,
+                          char                   *name,
+                          JsonArray              *args,
+                          GTask                  *task)
 {
-  g_object_set_data (G_OBJECT (self), "menus", NULL);
+  g_object_set_data (G_OBJECT (sender->extension), "menus", NULL);
   g_task_return_pointer (task, NULL, NULL);
 }
 
@@ -676,11 +673,10 @@ static EphyWebExtensionApiHandler menus_handlers[] = {
 };
 
 void
-ephy_web_extension_api_menus_handler (EphyWebExtension *self,
-                                      char             *name,
-                                      JSCValue         *args,
-                                      WebKitWebView    *web_view,
-                                      GTask            *task)
+ephy_web_extension_api_menus_handler (EphyWebExtensionSender *sender,
+                                      char                   *name,
+                                      JSCValue               *args,
+                                      GTask                  *task)
 {
   /* Temporary conversion as we migrate to json-glib here. */
   g_autofree char *json = jsc_value_to_json (args, 0);
@@ -689,7 +685,7 @@ ephy_web_extension_api_menus_handler (EphyWebExtension *self,
   json_array_seal (json_args);
 
   /* We slightly differ from Firefox here that either permission works for either API but they are 
identical. */
-  if (!ephy_web_extension_has_permission (self, "menus") && !ephy_web_extension_has_permission (self, 
"contextMenus")) {
+  if (!ephy_web_extension_has_permission (sender->extension, "menus") && !ephy_web_extension_has_permission 
(sender->extension, "contextMenus")) {
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission 
Denied");
     return;
   }
@@ -698,7 +694,7 @@ ephy_web_extension_api_menus_handler (EphyWebExtension *self,
     EphyWebExtensionApiHandler handler = menus_handlers[idx];
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      handler.execute (self, name, json_args, web_view, task);
+      handler.execute (sender, name, json_args, task);
       return;
     }
   }
diff --git a/src/webextension/api/menus.h b/src/webextension/api/menus.h
index 419570f76..22193a0d9 100644
--- a/src/webextension/api/menus.h
+++ b/src/webextension/api/menus.h
@@ -26,11 +26,10 @@
 
 G_BEGIN_DECLS
 
-void         ephy_web_extension_api_menus_handler                    (EphyWebExtension *self,
-                                                                      char             *name,
-                                                                      JSCValue         *value,
-                                                                      WebKitWebView    *web_view,
-                                                                      GTask            *task);
+void         ephy_web_extension_api_menus_handler                    (EphyWebExtensionSender *sender,
+                                                                      char                   *name,
+                                                                      JSCValue               *value,
+                                                                      GTask                  *task);
 
 WebKitContextMenuItem  *ephy_web_extension_api_menus_create_context_menu        (EphyWebExtension    *self,
                                                                                  WebKitWebView       
*web_view,
diff --git a/src/webextension/api/notifications.c b/src/webextension/api/notifications.c
index 9cae6e8d3..79135dc10 100644
--- a/src/webextension/api/notifications.c
+++ b/src/webextension/api/notifications.c
@@ -35,11 +35,10 @@ create_extension_notification_id (EphyWebExtension *web_extension,
 }
 
 static char *
-notifications_handler_create (EphyWebExtension  *self,
-                              char              *name,
-                              JSCValue          *args,
-                              WebKitWebView     *web_view,
-                              GError           **error)
+notifications_handler_create (EphyWebExtensionSender  *sender,
+                              char                    *name,
+                              JSCValue                *args,
+                              GError                 **error)
 {
   g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
   g_autoptr (JSCValue) button_array = NULL;
@@ -48,7 +47,7 @@ notifications_handler_create (EphyWebExtension  *self,
   g_autofree char *title = NULL;
   g_autofree char *message = NULL;
   g_autoptr (GNotification) notification = NULL;
-  const char *extension_guid = ephy_web_extension_get_guid (self);
+  const char *extension_guid = ephy_web_extension_get_guid (sender->extension);
 
   /* We share the same "create" and "update" function here because our
    * implementation would be the same. The only difference is we require
@@ -92,18 +91,17 @@ notifications_handler_create (EphyWebExtension  *self,
     }
   }
 
-  namespaced_id = create_extension_notification_id (self, id);
+  namespaced_id = create_extension_notification_id (sender->extension, id);
   g_application_send_notification (G_APPLICATION (ephy_shell_get_default ()), namespaced_id, notification);
 
   return g_strdup_printf ("\"%s\"", id);
 }
 
 static char *
-notifications_handler_clear (EphyWebExtension  *self,
-                             char              *name,
-                             JSCValue          *args,
-                             WebKitWebView     *web_view,
-                             GError           **error)
+notifications_handler_clear (EphyWebExtensionSender  *sender,
+                             char                    *name,
+                             JSCValue                *args,
+                             GError                 **error)
 {
   g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
   g_autofree char *id = NULL;
@@ -115,7 +113,7 @@ notifications_handler_clear (EphyWebExtension  *self,
   }
 
   id = jsc_value_to_string (value);
-  namespaced_id = create_extension_notification_id (self, id);
+  namespaced_id = create_extension_notification_id (sender->extension, id);
 
   g_application_withdraw_notification (G_APPLICATION (ephy_shell_get_default ()), namespaced_id);
 
@@ -124,11 +122,10 @@ notifications_handler_clear (EphyWebExtension  *self,
 }
 
 static char *
-notifications_handler_get_all (EphyWebExtension  *self,
-                               char              *name,
-                               JSCValue          *args,
-                               WebKitWebView     *web_view,
-                               GError           **error)
+notifications_handler_get_all (EphyWebExtensionSender  *sender,
+                               char                    *name,
+                               JSCValue                *args,
+                               GError                 **error)
 {
   /* GNotification does not provide information on the state of notifications. */
   return g_strdup ("[]");
@@ -142,16 +139,15 @@ static EphyWebExtensionSyncApiHandler notifications_handlers[] = {
 };
 
 void
-ephy_web_extension_api_notifications_handler (EphyWebExtension *self,
-                                              char             *name,
-                                              JSCValue         *args,
-                                              WebKitWebView    *web_view,
-                                              GTask            *task)
+ephy_web_extension_api_notifications_handler (EphyWebExtensionSender *sender,
+                                              char                   *name,
+                                              JSCValue               *args,
+                                              GTask                  *task)
 {
   g_autoptr (GError) error = NULL;
 
-  if (!ephy_web_extension_has_permission (self, "notifications")) {
-    g_warning ("Extension %s tried to use notifications without permission.", ephy_web_extension_get_name 
(self));
+  if (!ephy_web_extension_has_permission (sender->extension, "notifications")) {
+    g_warning ("Extension %s tried to use notifications without permission.", ephy_web_extension_get_name 
(sender->extension));
     error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission 
Denied");
     g_task_return_error (task, g_steal_pointer (&error));
     return;
@@ -162,7 +158,7 @@ ephy_web_extension_api_notifications_handler (EphyWebExtension *self,
     char *ret;
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      ret = handler.execute (self, name, args, web_view, &error);
+      ret = handler.execute (sender, name, args, &error);
 
       if (error)
         g_task_return_error (task, g_steal_pointer (&error));
diff --git a/src/webextension/api/notifications.h b/src/webextension/api/notifications.h
index c05e9a856..b368e0699 100644
--- a/src/webextension/api/notifications.h
+++ b/src/webextension/api/notifications.h
@@ -25,10 +25,9 @@
 
 G_BEGIN_DECLS
 
-void ephy_web_extension_api_notifications_handler (EphyWebExtension *self,
-                                                    char            *name,
-                                                    JSCValue        *args,
-                                                    WebKitWebView   *web_view,
-                                                    GTask           *task);
+void ephy_web_extension_api_notifications_handler (EphyWebExtensionSender *sender,
+                                                   char                   *name,
+                                                   JSCValue               *args,
+                                                   GTask                  *task);
 
 G_END_DECLS
diff --git a/src/webextension/api/pageaction.c b/src/webextension/api/pageaction.c
index 76ee0bb3a..1cf8ed1f9 100644
--- a/src/webextension/api/pageaction.c
+++ b/src/webextension/api/pageaction.c
@@ -27,7 +27,7 @@
 #include "pageaction.h"
 
 static GtkWidget *
-pageaction_get_action (EphyWebExtension *self,
+pageaction_get_action (EphyWebExtension *extension,
                        JSCValue         *value)
 {
   EphyWebView *web_view = NULL;
@@ -50,15 +50,14 @@ pageaction_get_action (EphyWebExtension *self,
     return NULL;
   }
 
-  return ephy_web_extension_manager_get_page_action (manager, self, web_view);
+  return ephy_web_extension_manager_get_page_action (manager, extension, web_view);
 }
 
 static char *
-pageaction_handler_seticon (EphyWebExtension  *self,
-                            char              *name,
-                            JSCValue          *args,
-                            WebKitWebView     *web_view,
-                            GError           **error)
+pageaction_handler_seticon (EphyWebExtensionSender  *sender,
+                            char                    *name,
+                            JSCValue                *args,
+                            GError                 **error)
 {
   GtkWidget *action;
   g_autofree char *path_str = NULL;
@@ -66,7 +65,7 @@ pageaction_handler_seticon (EphyWebExtension  *self,
   g_autoptr (GdkPixbuf) pixbuf = NULL;
   g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
 
-  action = pageaction_get_action (self, value);
+  action = pageaction_get_action (sender->extension, value);
   if (!action) {
     g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid 
Arguments");
     return NULL;
@@ -75,7 +74,7 @@ pageaction_handler_seticon (EphyWebExtension  *self,
   path_value = jsc_value_object_get_property (value, "path");
   if (jsc_value_is_string (path_value)) {
     path_str = jsc_value_to_string (path_value);
-    pixbuf = ephy_web_extension_load_pixbuf (self, path_str, -1);
+    pixbuf = ephy_web_extension_load_pixbuf (sender->extension, path_str, -1);
   } else {
     g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, 
"pageAction.setIcon(): Currently only single path strings are supported.");
     return NULL;
@@ -86,17 +85,16 @@ pageaction_handler_seticon (EphyWebExtension  *self,
 }
 
 static char *
-pageaction_handler_settitle (EphyWebExtension  *self,
-                             char              *name,
-                             JSCValue          *args,
-                             WebKitWebView     *web_view,
-                             GError           **error)
+pageaction_handler_settitle (EphyWebExtensionSender  *sender,
+                             char                    *name,
+                             JSCValue                *args,
+                             GError                 **error)
 {
   GtkWidget *action;
   g_autoptr (JSCValue) title = NULL;
   g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
 
-  action = pageaction_get_action (self, value);
+  action = pageaction_get_action (sender->extension, value);
   if (!action) {
     g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid 
Arguments");
     return NULL;
@@ -109,17 +107,16 @@ pageaction_handler_settitle (EphyWebExtension  *self,
 }
 
 static char *
-pageaction_handler_gettitle (EphyWebExtension  *self,
-                             char              *name,
-                             JSCValue          *args,
-                             WebKitWebView     *web_view,
-                             GError           **error)
+pageaction_handler_gettitle (EphyWebExtensionSender  *sender,
+                             char                    *name,
+                             JSCValue                *args,
+                             GError                 **error)
 {
   g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
   GtkWidget *action;
   g_autofree char *title = NULL;
 
-  action = pageaction_get_action (self, value);
+  action = pageaction_get_action (sender->extension, value);
   if (!action) {
     g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid 
Arguments");
     return NULL;
@@ -131,16 +128,15 @@ pageaction_handler_gettitle (EphyWebExtension  *self,
 }
 
 static char *
-pageaction_handler_show (EphyWebExtension  *self,
-                         char              *name,
-                         JSCValue          *args,
-                         WebKitWebView     *web_view,
-                         GError           **error)
+pageaction_handler_show (EphyWebExtensionSender  *sender,
+                         char                    *name,
+                         JSCValue                *args,
+                         GError                 **error)
 {
   g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
   GtkWidget *action;
 
-  action = pageaction_get_action (self, value);
+  action = pageaction_get_action (sender->extension, value);
   if (!action) {
     g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid 
Arguments");
     return NULL;
@@ -152,16 +148,15 @@ pageaction_handler_show (EphyWebExtension  *self,
 }
 
 static char *
-pageaction_handler_hide (EphyWebExtension  *self,
-                         char              *name,
-                         JSCValue          *args,
-                         WebKitWebView     *web_view,
-                         GError           **error)
+pageaction_handler_hide (EphyWebExtensionSender  *sender,
+                         char                    *name,
+                         JSCValue                *args,
+                         GError                 **error)
 {
   g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
   GtkWidget *action;
 
-  action = pageaction_get_action (self, value);
+  action = pageaction_get_action (sender->extension, value);
   if (!action) {
     g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid 
Arguments");
     return NULL;
@@ -181,11 +176,10 @@ static EphyWebExtensionSyncApiHandler pageaction_handlers[] = {
 };
 
 void
-ephy_web_extension_api_pageaction_handler (EphyWebExtension *self,
-                                           char             *name,
-                                           JSCValue         *args,
-                                           WebKitWebView    *web_view,
-                                           GTask            *task)
+ephy_web_extension_api_pageaction_handler (EphyWebExtensionSender *sender,
+                                           char                   *name,
+                                           JSCValue               *args,
+                                           GTask                  *task)
 {
   g_autoptr (GError) error = NULL;
   guint idx;
@@ -195,7 +189,7 @@ ephy_web_extension_api_pageaction_handler (EphyWebExtension *self,
     char *ret;
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      ret = handler.execute (self, name, args, web_view, &error);
+      ret = handler.execute (sender, name, args, &error);
 
       if (error)
         g_task_return_error (task, g_steal_pointer (&error));
diff --git a/src/webextension/api/pageaction.h b/src/webextension/api/pageaction.h
index 9dffb1d1c..95ec408a0 100644
--- a/src/webextension/api/pageaction.h
+++ b/src/webextension/api/pageaction.h
@@ -25,10 +25,9 @@
 
 G_BEGIN_DECLS
 
-void ephy_web_extension_api_pageaction_handler (EphyWebExtension *self,
-                                                 char            *name,
-                                                 JSCValue        *args,
-                                                 WebKitWebView   *web_view,
-                                                 GTask           *task);
+void ephy_web_extension_api_pageaction_handler (EphyWebExtensionSender *sender,
+                                                char                   *name,
+                                                JSCValue               *args,
+                                                GTask                  *task);
 
 G_END_DECLS
diff --git a/src/webextension/api/runtime.c b/src/webextension/api/runtime.c
index d2b64f561..350abccc2 100644
--- a/src/webextension/api/runtime.c
+++ b/src/webextension/api/runtime.c
@@ -28,11 +28,10 @@
 #include "ephy-shell.h"
 
 static char *
-runtime_handler_get_browser_info (EphyWebExtension  *self,
-                                  char              *name,
-                                  JSCValue          *args,
-                                  WebKitWebView     *web_view,
-                                  GError           **error)
+runtime_handler_get_browser_info (EphyWebExtensionSender  *sender,
+                                  char                    *name,
+                                  JSCValue                *args,
+                                  GError                 **error)
 {
   g_autoptr (JsonBuilder) builder = json_builder_new ();
   g_autoptr (JsonNode) root = NULL;
@@ -68,11 +67,10 @@ get_arch (void)
 }
 
 static char *
-runtime_handler_get_platform_info (EphyWebExtension  *self,
-                                   char              *name,
-                                   JSCValue          *args,
-                                   WebKitWebView     *web_view,
-                                   GError           **error)
+runtime_handler_get_platform_info (EphyWebExtensionSender  *sender,
+                                   char                    *name,
+                                   JSCValue                *args,
+                                   GError                 **error)
 {
   g_autoptr (JsonBuilder) builder = json_builder_new ();
   g_autoptr (JsonNode) root = NULL;
@@ -105,11 +103,10 @@ is_empty_object (JSCValue *value)
 }
 
 static void
-runtime_handler_send_message (EphyWebExtension *self,
-                              char             *name,
-                              JSCValue         *args,
-                              WebKitWebView    *web_view,
-                              GTask            *task)
+runtime_handler_send_message (EphyWebExtensionSender *sender,
+                              char                   *name,
+                              JSCValue               *args,
+                              GTask                  *task)
 {
   EphyWebExtensionManager *manager = ephy_web_extension_manager_get_default ();
   g_autoptr (GError) error = NULL;
@@ -137,22 +134,22 @@ runtime_handler_send_message (EphyWebExtension *self,
   }
 
   json = jsc_value_to_json (message, 0);
-  ephy_web_extension_manager_emit_in_extension_views_with_reply (manager, self, "runtime.onMessage",
+  ephy_web_extension_manager_emit_in_extension_views_with_reply (manager, sender->extension,
+                                                                 sender,
+                                                                 "runtime.onMessage",
                                                                  json,
-                                                                 web_view,
                                                                  task);
 
   return;
 }
 
 static char *
-runtime_handler_open_options_page (EphyWebExtension  *self,
-                                   char              *name,
-                                   JSCValue          *args,
-                                   WebKitWebView     *web_view,
-                                   GError           **error)
+runtime_handler_open_options_page (EphyWebExtensionSender  *sender,
+                                   char                    *name,
+                                   JSCValue                *args,
+                                   GError                 **error)
 {
-  const char *options_ui = ephy_web_extension_get_option_ui_page (self);
+  const char *options_ui = ephy_web_extension_get_option_ui_page (sender->extension);
   EphyShell *shell = ephy_shell_get_default ();
   g_autofree char *title = NULL;
   g_autofree char *options_uri = NULL;
@@ -164,8 +161,8 @@ runtime_handler_open_options_page (EphyWebExtension  *self,
     return NULL;
   }
 
-  title = g_strdup_printf (_("Options for %s"), ephy_web_extension_get_name (self));
-  options_uri = g_strdup_printf ("ephy-webextension://%s/%s", ephy_web_extension_get_guid (self), 
options_ui);
+  title = g_strdup_printf (_("Options for %s"), ephy_web_extension_get_name (sender->extension));
+  options_uri = g_strdup_printf ("ephy-webextension://%s/%s", ephy_web_extension_get_guid 
(sender->extension), options_ui);
 
   new_window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
   gtk_window_set_transient_for (new_window, gtk_application_get_active_window (GTK_APPLICATION (shell)));
@@ -173,7 +170,7 @@ runtime_handler_open_options_page (EphyWebExtension  *self,
   gtk_window_set_title (new_window, title);
   gtk_window_set_position (new_window, GTK_WIN_POS_CENTER_ON_PARENT);
 
-  new_web_view = ephy_web_extensions_manager_create_web_extensions_webview (self);
+  new_web_view = ephy_web_extensions_manager_create_web_extensions_webview (sender->extension);
   gtk_container_add (GTK_CONTAINER (new_window), new_web_view);
 
   webkit_web_view_load_uri (WEBKIT_WEB_VIEW (new_web_view), options_uri);
@@ -195,11 +192,10 @@ static EphyWebExtensionAsyncApiHandler runtime_async_handlers[] = {
 };
 
 void
-ephy_web_extension_api_runtime_handler (EphyWebExtension *self,
-                                        char             *name,
-                                        JSCValue         *args,
-                                        WebKitWebView    *web_view,
-                                        GTask            *task)
+ephy_web_extension_api_runtime_handler (EphyWebExtensionSender *sender,
+                                        char                   *name,
+                                        JSCValue               *args,
+                                        GTask                  *task)
 {
   g_autoptr (GError) error = NULL;
   guint idx;
@@ -209,7 +205,7 @@ ephy_web_extension_api_runtime_handler (EphyWebExtension *self,
     char *ret;
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      ret = handler.execute (self, name, args, web_view, &error);
+      ret = handler.execute (sender, name, args, &error);
 
       if (error)
         g_task_return_error (task, g_steal_pointer (&error));
@@ -224,7 +220,7 @@ ephy_web_extension_api_runtime_handler (EphyWebExtension *self,
     EphyWebExtensionAsyncApiHandler handler = runtime_async_handlers[idx];
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      handler.execute (self, name, args, web_view, task);
+      handler.execute (sender, name, args, task);
       return;
     }
   }
diff --git a/src/webextension/api/runtime.h b/src/webextension/api/runtime.h
index ffce31286..469587732 100644
--- a/src/webextension/api/runtime.h
+++ b/src/webextension/api/runtime.h
@@ -25,10 +25,9 @@
 
 G_BEGIN_DECLS
 
-void ephy_web_extension_api_runtime_handler (EphyWebExtension *self,
-                                              char            *name,
-                                              JSCValue        *args,
-                                              WebKitWebView   *web_view,
-                                              GTask           *task);
+void ephy_web_extension_api_runtime_handler (EphyWebExtensionSender *sender,
+                                             char                   *name,
+                                             JSCValue               *args,
+                                             GTask                  *task);
 
 G_END_DECLS
diff --git a/src/webextension/api/storage.c b/src/webextension/api/storage.c
index 04ead21fd..323a24973 100644
--- a/src/webextension/api/storage.c
+++ b/src/webextension/api/storage.c
@@ -58,13 +58,12 @@ strv_from_value (JSCValue *array)
 }
 
 static char *
-storage_handler_local_set (EphyWebExtension  *self,
-                           char              *name,
-                           JSCValue          *args,
-                           WebKitWebView     *web_view,
-                           GError           **error)
+storage_handler_local_set (EphyWebExtensionSender  *sender,
+                           char                    *name,
+                           JSCValue                *args,
+                           GError                 **error)
 {
-  JsonNode *local_storage = ephy_web_extension_get_local_storage (self);
+  JsonNode *local_storage = ephy_web_extension_get_local_storage (sender->extension);
   JsonObject *local_storage_obj = json_node_get_object (local_storage);
   g_auto (GStrv) keys = NULL;
   g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
@@ -81,19 +80,18 @@ storage_handler_local_set (EphyWebExtension  *self,
 
   /* FIXME: Implement storage.onChanged */
   /* FIXME: Async IO */
-  ephy_web_extension_save_local_storage (self);
+  ephy_web_extension_save_local_storage (sender->extension);
 
   return NULL;
 }
 
 static char *
-storage_handler_local_get (EphyWebExtension  *self,
-                           char              *name,
-                           JSCValue          *args,
-                           WebKitWebView     *web_view,
-                           GError           **error)
+storage_handler_local_get (EphyWebExtensionSender  *sender,
+                           char                    *name,
+                           JSCValue                *args,
+                           GError                 **error)
 {
-  JsonNode *local_storage = ephy_web_extension_get_local_storage (self);
+  JsonNode *local_storage = ephy_web_extension_get_local_storage (sender->extension);
   JsonObject *local_storage_obj = json_node_get_object (local_storage);
   g_autoptr (JsonBuilder) builder = NULL;
   g_auto (GStrv) keys = NULL;
@@ -147,13 +145,12 @@ end_get:
 }
 
 static char *
-storage_handler_local_remove (EphyWebExtension  *self,
-                              char              *name,
-                              JSCValue          *args,
-                              WebKitWebView     *web_view,
-                              GError           **error)
+storage_handler_local_remove (EphyWebExtensionSender  *sender,
+                              char                    *name,
+                              JSCValue                *args,
+                              GError                 **error)
 {
-  JsonNode *local_storage = ephy_web_extension_get_local_storage (self);
+  JsonNode *local_storage = ephy_web_extension_get_local_storage (sender->extension);
   JsonObject *local_storage_obj = json_node_get_object (local_storage);
   g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
 
@@ -172,19 +169,18 @@ storage_handler_local_remove (EphyWebExtension  *self,
   }
 
 end_remove:
-  ephy_web_extension_save_local_storage (self);
+  ephy_web_extension_save_local_storage (sender->extension);
   return NULL;
 }
 
 static char *
-storage_handler_local_clear (EphyWebExtension  *self,
-                             char              *name,
-                             JSCValue          *args,
-                             WebKitWebView     *web_view,
-                             GError           **error)
+storage_handler_local_clear (EphyWebExtensionSender  *sender,
+                             char                    *name,
+                             JSCValue                *args,
+                             GError                 **error)
 {
-  ephy_web_extension_clear_local_storage (self);
-  ephy_web_extension_save_local_storage (self);
+  ephy_web_extension_clear_local_storage (sender->extension);
+  ephy_web_extension_save_local_storage (sender->extension);
   return NULL;
 }
 
@@ -196,17 +192,16 @@ static EphyWebExtensionSyncApiHandler storage_handlers[] = {
 };
 
 void
-ephy_web_extension_api_storage_handler (EphyWebExtension *self,
-                                        char             *name,
-                                        JSCValue         *args,
-                                        WebKitWebView    *web_view,
-                                        GTask            *task)
+ephy_web_extension_api_storage_handler (EphyWebExtensionSender *sender,
+                                        char                   *name,
+                                        JSCValue               *args,
+                                        GTask                  *task)
 {
   g_autoptr (GError) error = NULL;
   guint idx;
 
-  if (!ephy_web_extension_has_permission (self, "storage")) {
-    g_warning ("Extension %s tried to use storage without permission.", ephy_web_extension_get_name (self));
+  if (!ephy_web_extension_has_permission (sender->extension, "storage")) {
+    g_warning ("Extension %s tried to use storage without permission.", ephy_web_extension_get_name 
(sender->extension));
     error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission 
Denied");
     g_task_return_error (task, g_steal_pointer (&error));
     return;
@@ -217,7 +212,7 @@ ephy_web_extension_api_storage_handler (EphyWebExtension *self,
     char *ret;
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      ret = handler.execute (self, name, args, web_view, &error);
+      ret = handler.execute (sender, name, args, &error);
 
       if (error)
         g_task_return_error (task, g_steal_pointer (&error));
diff --git a/src/webextension/api/storage.h b/src/webextension/api/storage.h
index f905613c3..ff2b98d0a 100644
--- a/src/webextension/api/storage.h
+++ b/src/webextension/api/storage.h
@@ -28,10 +28,9 @@
 
 G_BEGIN_DECLS
 
-void ephy_web_extension_api_storage_handler (EphyWebExtension *self,
-                                              char            *name,
-                                              JSCValue        *value,
-                                              WebKitWebView   *web_view,
-                                              GTask           *task);
+void ephy_web_extension_api_storage_handler (EphyWebExtensionSender *sender,
+                                             char                   *name,
+                                             JSCValue               *value,
+                                             GTask                  *task);
 
 G_END_DECLS
diff --git a/src/webextension/api/tabs.c b/src/webextension/api/tabs.c
index 4427f9d73..78a04be22 100644
--- a/src/webextension/api/tabs.c
+++ b/src/webextension/api/tabs.c
@@ -66,7 +66,7 @@ get_web_view_for_tab_id (EphyShell   *shell,
 }
 
 static void
-add_web_view_to_json (EphyWebExtension *self,
+add_web_view_to_json (EphyWebExtension *extension,
                       JsonBuilder      *builder,
                       EphyWindow       *window,
                       EphyWebView      *web_view)
@@ -76,7 +76,7 @@ add_web_view_to_json (EphyWebExtension *self,
   gboolean is_active = ephy_tab_view_get_current_page (tab_view) == page;
   WebKitFaviconDatabase *favicon_db = webkit_web_context_get_favicon_database (webkit_web_view_get_context 
(WEBKIT_WEB_VIEW (web_view)));
   const char *favicon_uri = webkit_favicon_database_get_favicon_uri (favicon_db, ephy_web_view_get_address 
(web_view));
-  gboolean has_tab_permission = ephy_web_extension_has_tab_or_host_permission (self, web_view, TRUE);
+  gboolean has_tab_permission = ephy_web_extension_has_tab_or_host_permission (extension, web_view, TRUE);
 
   json_builder_begin_object (builder);
   if (has_tab_permission) {
@@ -120,20 +120,20 @@ add_web_view_to_json (EphyWebExtension *self,
 }
 
 void
-ephy_web_extension_api_tabs_add_tab_to_json (EphyWebExtension *self,
+ephy_web_extension_api_tabs_add_tab_to_json (EphyWebExtension *extension,
                                              JsonBuilder      *builder,
                                              EphyWindow       *window,
                                              EphyWebView      *web_view)
 {
-  add_web_view_to_json (self, builder, window, web_view);
+  add_web_view_to_json (extension, builder, window, web_view);
 }
 
 JsonNode *
-ephy_web_extension_api_tabs_create_tab_object (EphyWebExtension *self,
+ephy_web_extension_api_tabs_create_tab_object (EphyWebExtension *extension,
                                                EphyWebView      *web_view)
 {
   g_autoptr (JsonBuilder) builder = json_builder_new ();
-  add_web_view_to_json (self,
+  add_web_view_to_json (extension,
                         builder,
                         EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (web_view))),
                         web_view);
@@ -158,11 +158,10 @@ get_window_by_id (EphyShell *shell,
 }
 
 static char *
-tabs_handler_query (EphyWebExtension  *self,
-                    char              *name,
-                    JSCValue          *args,
-                    WebKitWebView     *web_view,
-                    GError           **error)
+tabs_handler_query (EphyWebExtensionSender  *sender,
+                    char                    *name,
+                    JSCValue                *args,
+                    GError                 **error)
 {
   g_autoptr (JsonBuilder) builder = json_builder_new ();
   g_autoptr (JsonNode) root = NULL;
@@ -224,7 +223,7 @@ tabs_handler_query (EphyWebExtension  *self,
       else if (active == API_VALUE_FALSE && web_view == active_web_view)
         continue;
 
-      add_web_view_to_json (self, builder, window, web_view);
+      add_web_view_to_json (sender->extension, builder, window, web_view);
     }
   }
 
@@ -235,11 +234,10 @@ tabs_handler_query (EphyWebExtension  *self,
 }
 
 static char *
-tabs_handler_insert_css (EphyWebExtension  *self,
-                         char              *name,
-                         JSCValue          *args,
-                         WebKitWebView     *web_view,
-                         GError           **error)
+tabs_handler_insert_css (EphyWebExtensionSender  *sender,
+                         char                    *name,
+                         JSCValue                *args,
+                         GError                 **error)
 {
   EphyShell *shell = ephy_shell_get_default ();
   WebKitUserContentManager *ucm;
@@ -273,7 +271,7 @@ tabs_handler_insert_css (EphyWebExtension  *self,
     return NULL;
   }
 
-  if (!ephy_web_extension_has_host_or_active_permission (self, EPHY_WEB_VIEW (target_web_view), TRUE)) {
+  if (!ephy_web_extension_has_host_or_active_permission (sender->extension, EPHY_WEB_VIEW (target_web_view), 
TRUE)) {
     g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission 
Denied");
     return NULL;
   }
@@ -281,7 +279,7 @@ tabs_handler_insert_css (EphyWebExtension  *self,
   ucm = webkit_web_view_get_user_content_manager (target_web_view);
 
   code = jsc_value_object_get_property (obj, "code");
-  css = ephy_web_extension_add_custom_css (self, jsc_value_to_string (code));
+  css = ephy_web_extension_add_custom_css (sender->extension, jsc_value_to_string (code));
 
   if (css)
     webkit_user_content_manager_add_style_sheet (ucm, css);
@@ -290,11 +288,10 @@ tabs_handler_insert_css (EphyWebExtension  *self,
 }
 
 static char *
-tabs_handler_remove_css (EphyWebExtension  *self,
-                         char              *name,
-                         JSCValue          *args,
-                         WebKitWebView     *web_view,
-                         GError           **error)
+tabs_handler_remove_css (EphyWebExtensionSender  *sender,
+                         char                    *name,
+                         JSCValue                *args,
+                         GError                 **error)
 {
   EphyShell *shell = ephy_shell_get_default ();
   JSCValue *code;
@@ -328,7 +325,7 @@ tabs_handler_remove_css (EphyWebExtension  *self,
     return NULL;
   }
 
-  if (!ephy_web_extension_has_host_or_active_permission (self, EPHY_WEB_VIEW (target_web_view), TRUE)) {
+  if (!ephy_web_extension_has_host_or_active_permission (sender->extension, EPHY_WEB_VIEW (target_web_view), 
TRUE)) {
     g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission 
Denied");
     return NULL;
   }
@@ -336,7 +333,7 @@ tabs_handler_remove_css (EphyWebExtension  *self,
   ucm = webkit_web_view_get_user_content_manager (target_web_view);
 
   code = jsc_value_object_get_property (obj, "code");
-  css = ephy_web_extension_get_custom_css (self, jsc_value_to_string (code));
+  css = ephy_web_extension_get_custom_css (sender->extension, jsc_value_to_string (code));
   if (css)
     webkit_user_content_manager_remove_style_sheet (ucm, css);
 
@@ -344,11 +341,10 @@ tabs_handler_remove_css (EphyWebExtension  *self,
 }
 
 static char *
-tabs_handler_get (EphyWebExtension  *self,
-                  char              *name,
-                  JSCValue          *args,
-                  WebKitWebView     *web_view,
-                  GError           **error)
+tabs_handler_get (EphyWebExtensionSender  *sender,
+                  char                    *name,
+                  JSCValue                *args,
+                  GError                 **error)
 {
   EphyShell *shell = ephy_shell_get_default ();
   g_autoptr (JsonBuilder) builder = json_builder_new ();
@@ -369,7 +365,7 @@ tabs_handler_get (EphyWebExtension  *self,
     return NULL;
   }
 
-  add_web_view_to_json (self, builder, parent_window, target_web_view);
+  add_web_view_to_json (sender->extension, builder, parent_window, target_web_view);
   root = json_builder_get_root (builder);
 
   return json_to_string (root, FALSE);
@@ -397,11 +393,10 @@ on_execute_script_ready (GObject      *source,
 }
 
 static void
-tabs_handler_execute_script (EphyWebExtension *self,
-                             char             *name,
-                             JSCValue         *args,
-                             WebKitWebView    *web_view,
-                             GTask            *task)
+tabs_handler_execute_script (EphyWebExtensionSender *sender,
+                             char                   *name,
+                             JSCValue               *args,
+                             GTask                  *task)
 {
   g_autoptr (JSCValue) code_value = NULL;
   g_autoptr (JSCValue) file_value = NULL;
@@ -433,7 +428,7 @@ tabs_handler_execute_script (EphyWebExtension *self,
     code = jsc_value_to_string (code_value);
   else if (jsc_value_is_string (file_value)) {
     g_autofree char *resource_path = jsc_value_to_string (file_value);
-    code = ephy_web_extension_get_resource_as_string (self, resource_path[0] == '/' ? resource_path + 1 : 
resource_path);
+    code = ephy_web_extension_get_resource_as_string (sender->extension, resource_path[0] == '/' ? 
resource_path + 1 : resource_path);
   } else {
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid 
Arguments");
     return;
@@ -445,14 +440,14 @@ tabs_handler_execute_script (EphyWebExtension *self,
     target_web_view = get_web_view_for_tab_id (shell, jsc_value_to_int32 (tab_id_value), NULL);
 
   if (code && target_web_view) {
-    if (!ephy_web_extension_has_host_or_active_permission (self, EPHY_WEB_VIEW (target_web_view), TRUE)) {
+    if (!ephy_web_extension_has_host_or_active_permission (sender->extension, EPHY_WEB_VIEW 
(target_web_view), TRUE)) {
       g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission 
Denied");
       return;
     }
 
     webkit_web_view_run_javascript_in_world (target_web_view,
                                              code,
-                                             ephy_web_extension_get_guid (self),
+                                             ephy_web_extension_get_guid (sender->extension),
                                              NULL,
                                              on_execute_script_ready,
                                              task);
@@ -460,11 +455,10 @@ tabs_handler_execute_script (EphyWebExtension *self,
 }
 
 static void
-tabs_handler_send_message (EphyWebExtension *self,
-                           char             *name,
-                           JSCValue         *args,
-                           WebKitWebView    *web_view,
-                           GTask            *task)
+tabs_handler_send_message (EphyWebExtensionSender *sender,
+                           char                   *name,
+                           JSCValue               *args,
+                           GTask                  *task)
 {
   EphyWebExtensionManager *manager = ephy_web_extension_manager_get_default ();
   g_autoptr (JSCValue) tab_id_value = NULL;
@@ -492,18 +486,18 @@ tabs_handler_send_message (EphyWebExtension *self,
   }
 
 
-  if (!ephy_web_extension_has_host_or_active_permission (self, EPHY_WEB_VIEW (target_web_view), TRUE)) {
+  if (!ephy_web_extension_has_host_or_active_permission (sender->extension, EPHY_WEB_VIEW (target_web_view), 
TRUE)) {
     g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, 
"tabs.sendMessage(): Permission Denied");
     return;
   }
 
   serialized_message = jsc_value_to_json (message_value, 0);
   ephy_web_extension_manager_emit_in_tab_with_reply (manager,
-                                                     self,
+                                                     sender->extension,
                                                      "runtime.onMessage",
                                                      serialized_message,
                                                      target_web_view,
-                                                     ephy_web_extension_create_sender_object (self, 
web_view),
+                                                     ephy_web_extension_create_sender_object (sender),
                                                      task);
 }
 
@@ -551,11 +545,10 @@ ephy_web_extension_api_tabs_url_is_unprivileged (const char *url)
 }
 
 static char *
-tabs_handler_create (EphyWebExtension  *self,
-                     char              *name,
-                     JSCValue          *args,
-                     WebKitWebView     *web_view,
-                     GError           **error)
+tabs_handler_create (EphyWebExtensionSender  *sender,
+                     char                    *name,
+                     JSCValue                *args,
+                     GError                 **error)
 {
   EphyShell *shell = ephy_shell_get_default ();
   EphyEmbed *embed;
@@ -573,7 +566,7 @@ tabs_handler_create (EphyWebExtension  *self,
     return NULL;
   }
 
-  url = resolve_to_absolute_url (self, api_utils_get_string_property (create_properties, "url", NULL));
+  url = resolve_to_absolute_url (sender->extension, api_utils_get_string_property (create_properties, "url", 
NULL));
   if (!ephy_web_extension_api_tabs_url_is_unprivileged (url)) {
     g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.create(): URL '%s' 
is not allowed", url);
     return NULL;
@@ -598,17 +591,16 @@ tabs_handler_create (EphyWebExtension  *self,
     ephy_web_view_load_new_tab_page (new_web_view);
 
   builder = json_builder_new ();
-  add_web_view_to_json (self, builder, parent_window, new_web_view);
+  add_web_view_to_json (sender->extension, builder, parent_window, new_web_view);
   root = json_builder_get_root (builder);
   return json_to_string (root, FALSE);
 }
 
 static char *
-tabs_handler_update (EphyWebExtension  *self,
-                     char              *name,
-                     JSCValue          *args,
-                     WebKitWebView     *web_view,
-                     GError           **error)
+tabs_handler_update (EphyWebExtensionSender  *sender,
+                     char                    *name,
+                     JSCValue                *args,
+                     GError                 **error)
 {
   EphyShell *shell = ephy_shell_get_default ();
   g_autoptr (JSCValue) update_properties = NULL;
@@ -648,7 +640,7 @@ tabs_handler_update (EphyWebExtension  *self,
     return NULL;
   }
 
-  new_url = resolve_to_absolute_url (self, api_utils_get_string_property (update_properties, "url", NULL));
+  new_url = resolve_to_absolute_url (sender->extension, api_utils_get_string_property (update_properties, 
"url", NULL));
   if (!ephy_web_extension_api_tabs_url_is_unprivileged (new_url)) {
     g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.update(): URL '%s' 
is not allowed", new_url);
     return NULL;
@@ -662,7 +654,7 @@ tabs_handler_update (EphyWebExtension  *self,
     webkit_web_view_load_uri (target_web_view, new_url);
 
   builder = json_builder_new ();
-  add_web_view_to_json (self, builder, parent_window, EPHY_WEB_VIEW (target_web_view));
+  add_web_view_to_json (sender->extension, builder, parent_window, EPHY_WEB_VIEW (target_web_view));
   root = json_builder_get_root (builder);
   return json_to_string (root, FALSE);
 }
@@ -684,11 +676,10 @@ close_tab_id (EphyShell *shell,
 }
 
 static char *
-tabs_handler_remove (EphyWebExtension  *self,
-                     char              *name,
-                     JSCValue          *args,
-                     WebKitWebView     *web_view,
-                     GError           **error)
+tabs_handler_remove (EphyWebExtensionSender  *sender,
+                     char                    *name,
+                     JSCValue                *args,
+                     GError                 **error)
 {
   EphyShell *shell = ephy_shell_get_default ();
   g_autoptr (JSCValue) tab_ids = NULL;
@@ -720,11 +711,10 @@ tabs_handler_remove (EphyWebExtension  *self,
 }
 
 static char *
-tabs_handler_set_zoom (EphyWebExtension  *self,
-                       char              *name,
-                       JSCValue          *args,
-                       WebKitWebView     *web_view,
-                       GError           **error)
+tabs_handler_set_zoom (EphyWebExtensionSender  *sender,
+                       char                    *name,
+                       JSCValue                *args,
+                       GError                 **error)
 {
   EphyShell *shell = ephy_shell_get_default ();
   g_autoptr (JSCValue) zoom_level_value = NULL;
@@ -769,11 +759,10 @@ tabs_handler_set_zoom (EphyWebExtension  *self,
 }
 
 static char *
-tabs_handler_get_zoom (EphyWebExtension  *self,
-                       char              *name,
-                       JSCValue          *args,
-                       WebKitWebView     *web_view,
-                       GError           **error)
+tabs_handler_get_zoom (EphyWebExtensionSender  *sender,
+                       char                    *name,
+                       JSCValue                *args,
+                       GError                 **error)
 {
   EphyShell *shell = ephy_shell_get_default ();
   g_autoptr (JSCValue) tab_id_value = NULL;
@@ -798,11 +787,10 @@ tabs_handler_get_zoom (EphyWebExtension  *self,
 }
 
 static char *
-tabs_handler_reload (EphyWebExtension  *self,
-                     char              *name,
-                     JSCValue          *args,
-                     WebKitWebView     *web_view,
-                     GError           **error)
+tabs_handler_reload (EphyWebExtensionSender  *sender,
+                     char                    *name,
+                     JSCValue                *args,
+                     GError                 **error)
 {
   EphyShell *shell = ephy_shell_get_default ();
   g_autoptr (JSCValue) tab_id_value = NULL;
@@ -847,11 +835,10 @@ static EphyWebExtensionAsyncApiHandler tab_async_handlers[] = {
 };
 
 void
-ephy_web_extension_api_tabs_handler (EphyWebExtension *self,
-                                     char             *name,
-                                     JSCValue         *args,
-                                     WebKitWebView    *web_view,
-                                     GTask            *task)
+ephy_web_extension_api_tabs_handler (EphyWebExtensionSender *sender,
+                                     char                   *name,
+                                     JSCValue               *args,
+                                     GTask                  *task)
 {
   g_autoptr (GError) error = NULL;
 
@@ -860,7 +847,7 @@ ephy_web_extension_api_tabs_handler (EphyWebExtension *self,
     char *ret;
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      ret = handler.execute (self, name, args, web_view, &error);
+      ret = handler.execute (sender, name, args, &error);
 
       if (error)
         g_task_return_error (task, g_steal_pointer (&error));
@@ -875,7 +862,7 @@ ephy_web_extension_api_tabs_handler (EphyWebExtension *self,
     EphyWebExtensionAsyncApiHandler handler = tab_async_handlers[idx];
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      handler.execute (self, name, args, web_view, task);
+      handler.execute (sender, name, args, task);
       return;
     }
   }
diff --git a/src/webextension/api/tabs.h b/src/webextension/api/tabs.h
index 814716bdd..1ce8ca40c 100644
--- a/src/webextension/api/tabs.h
+++ b/src/webextension/api/tabs.h
@@ -27,11 +27,10 @@
 
 G_BEGIN_DECLS
 
-void ephy_web_extension_api_tabs_handler (EphyWebExtension *self,
-                                          char             *name,
-                                          JSCValue         *value,
-                                          WebKitWebView    *web_view,
-                                          GTask            *task);
+void ephy_web_extension_api_tabs_handler (EphyWebExtensionSender *sender,
+                                          char                   *name,
+                                          JSCValue               *value,
+                                          GTask                  *task);
 
 JsonNode *ephy_web_extension_api_tabs_create_tab_object (EphyWebExtension *self,
                                                          EphyWebView      *web_view);
diff --git a/src/webextension/api/windows.c b/src/webextension/api/windows.c
index 9b41a6114..4d131a6ca 100644
--- a/src/webextension/api/windows.c
+++ b/src/webextension/api/windows.c
@@ -57,7 +57,7 @@ get_window_state (EphyWindow *window)
 }
 
 static void
-add_tabs_to_json (EphyWebExtension *self,
+add_tabs_to_json (EphyWebExtension *extension,
                   JsonBuilder      *builder,
                   EphyWindow       *window)
 {
@@ -68,14 +68,14 @@ add_tabs_to_json (EphyWebExtension *self,
   for (int i = 0; i < ephy_tab_view_get_n_pages (tab_view); i++) {
     EphyWebView *web_view = ephy_embed_get_web_view (EPHY_EMBED (ephy_tab_view_get_nth_page (tab_view, i)));
 
-    ephy_web_extension_api_tabs_add_tab_to_json (self, builder, window, web_view);
+    ephy_web_extension_api_tabs_add_tab_to_json (extension, builder, window, web_view);
   }
 
   json_builder_end_array (builder);
 }
 
 static void
-add_window_to_json (EphyWebExtension *self,
+add_window_to_json (EphyWebExtension *extension,
                     JsonBuilder      *builder,
                     EphyWindow       *window,
                     gboolean          populate_tabs)
@@ -84,7 +84,7 @@ add_window_to_json (EphyWebExtension *self,
   EphyTabView *tab_view = ephy_window_get_tab_view (window);
   EphyEmbed *embed = EPHY_EMBED (ephy_tab_view_get_selected_page (tab_view));
   EphyWebView *active_web_view = ephy_embed_get_web_view (embed);
-  gboolean has_tab_permission = ephy_web_extension_has_tab_or_host_permission (self, active_web_view, TRUE);
+  gboolean has_tab_permission = ephy_web_extension_has_tab_or_host_permission (extension, active_web_view, 
TRUE);
 
   json_builder_begin_object (builder);
   json_builder_set_member_name (builder, "id");
@@ -106,18 +106,18 @@ add_window_to_json (EphyWebExtension *self,
   }
   if (populate_tabs) {
     json_builder_set_member_name (builder, "tabs");
-    add_tabs_to_json (self, builder, window);
+    add_tabs_to_json (extension, builder, window);
   }
   json_builder_end_object (builder);
 }
 
 char *
-ephy_web_extension_api_windows_create_window_json (EphyWebExtension *self,
+ephy_web_extension_api_windows_create_window_json (EphyWebExtension *extension,
                                                    EphyWindow       *window)
 {
   g_autoptr (JsonBuilder) builder = json_builder_new ();
   g_autoptr (JsonNode) root = NULL;
-  add_window_to_json (self,
+  add_window_to_json (extension,
                       builder,
                       window,
                       TRUE);
@@ -127,11 +127,10 @@ ephy_web_extension_api_windows_create_window_json (EphyWebExtension *self,
 
 
 static char *
-windows_handler_get (EphyWebExtension  *self,
-                     char              *name,
-                     JSCValue          *args,
-                     WebKitWebView     *web_view,
-                     GError           **error)
+windows_handler_get (EphyWebExtensionSender  *sender,
+                     char                    *name,
+                     JSCValue                *args,
+                     GError                 **error)
 {
   g_autoptr (JSCValue) window_id_value = jsc_value_object_get_property_at_index (args, 0);
   g_autoptr (JSCValue) get_info_value = jsc_value_object_get_property_at_index (args, 1);
@@ -157,17 +156,16 @@ windows_handler_get (EphyWebExtension  *self,
     populate_tabs = jsc_value_to_boolean (populate);
   }
 
-  add_window_to_json (self, builder, window, populate_tabs);
+  add_window_to_json (sender->extension, builder, window, populate_tabs);
   root = json_builder_get_root (builder);
   return json_to_string (root, FALSE);
 }
 
 static char *
-windows_handler_get_current (EphyWebExtension  *self,
-                             char              *name,
-                             JSCValue          *args,
-                             WebKitWebView     *web_view,
-                             GError           **error)
+windows_handler_get_current (EphyWebExtensionSender  *sender,
+                             char                    *name,
+                             JSCValue                *args,
+                             GError                 **error)
 {
   EphyWebExtensionManager *manager = ephy_web_extension_manager_get_default ();
   g_autoptr (JSCValue) get_info_value = jsc_value_object_get_property_at_index (args, 0);
@@ -176,27 +174,26 @@ windows_handler_get_current (EphyWebExtension  *self,
   gboolean populate_tabs = FALSE;
   EphyWindow *window;
 
-  if (web_view == ephy_web_extension_manager_get_background_web_view (manager, self))
+  if (sender->view == ephy_web_extension_manager_get_background_web_view (manager, sender->extension))
     window = EPHY_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (ephy_shell_get_default ())));
   else
-    window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (web_view)));
+    window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sender->view)));
 
   if (jsc_value_is_object (get_info_value)) {
     g_autoptr (JSCValue) populate = jsc_value_object_get_property (get_info_value, "populate");
     populate_tabs = jsc_value_to_boolean (populate);
   }
 
-  add_window_to_json (self, builder, window, populate_tabs);
+  add_window_to_json (sender->extension, builder, window, populate_tabs);
   root = json_builder_get_root (builder);
   return json_to_string (root, FALSE);
 }
 
 static char *
-windows_handler_get_last_focused (EphyWebExtension  *self,
-                                  char              *name,
-                                  JSCValue          *args,
-                                  WebKitWebView     *web_view,
-                                  GError           **error)
+windows_handler_get_last_focused (EphyWebExtensionSender  *sender,
+                                  char                    *name,
+                                  JSCValue                *args,
+                                  GError                 **error)
 {
   g_autoptr (JSCValue) get_info_value = jsc_value_object_get_property_at_index (args, 0);
   g_autoptr (JsonBuilder) builder = json_builder_new ();
@@ -211,17 +208,16 @@ windows_handler_get_last_focused (EphyWebExtension  *self,
     populate_tabs = jsc_value_to_boolean (populate);
   }
 
-  add_window_to_json (self, builder, window, populate_tabs);
+  add_window_to_json (sender->extension, builder, window, populate_tabs);
   root = json_builder_get_root (builder);
   return json_to_string (root, FALSE);
 }
 
 static char *
-windows_handler_get_all (EphyWebExtension  *self,
-                         char              *name,
-                         JSCValue          *args,
-                         WebKitWebView     *web_view,
-                         GError           **error)
+windows_handler_get_all (EphyWebExtensionSender  *sender,
+                         char                    *name,
+                         JSCValue                *args,
+                         GError                 **error)
 {
   g_autoptr (JSCValue) get_info_value = jsc_value_object_get_property_at_index (args, 0);
   g_autoptr (JsonBuilder) builder = json_builder_new ();
@@ -239,7 +235,7 @@ windows_handler_get_all (EphyWebExtension  *self,
 
   for (GList *win_list = windows; win_list; win_list = g_list_next (win_list)) {
     EphyWindow *window = EPHY_WINDOW (win_list->data);
-    add_window_to_json (self, builder, window, populate_tabs);
+    add_window_to_json (sender->extension, builder, window, populate_tabs);
   }
 
   json_builder_end_array (builder);
@@ -283,11 +279,10 @@ get_url_property (JSCValue *object)
 }
 
 static char *
-windows_handler_create (EphyWebExtension  *self,
-                        char              *name,
-                        JSCValue          *args,
-                        WebKitWebView     *web_view,
-                        GError           **error)
+windows_handler_create (EphyWebExtensionSender  *sender,
+                        char                    *name,
+                        JSCValue                *args,
+                        GError                 **error)
 {
   g_autoptr (JSCValue) create_data_value = jsc_value_object_get_property_at_index (args, 0);
   g_autoptr (GPtrArray) urls = NULL;
@@ -310,17 +305,16 @@ windows_handler_create (EphyWebExtension  *self,
 
   gtk_window_present (GTK_WINDOW (window));
 
-  add_window_to_json (self, builder, window, TRUE);
+  add_window_to_json (sender->extension, builder, window, TRUE);
   root = json_builder_get_root (builder);
   return json_to_string (root, FALSE);
 }
 
 static char *
-windows_handler_remove (EphyWebExtension  *self,
-                        char              *name,
-                        JSCValue          *args,
-                        WebKitWebView     *web_view,
-                        GError           **error)
+windows_handler_remove (EphyWebExtensionSender  *sender,
+                        char                    *name,
+                        JSCValue                *args,
+                        GError                 **error)
 {
   g_autoptr (JSCValue) window_id_value = jsc_value_object_get_property_at_index (args, 0);
   EphyWindow *window;
@@ -352,11 +346,10 @@ static EphyWebExtensionSyncApiHandler windows_handlers[] = {
 };
 
 void
-ephy_web_extension_api_windows_handler (EphyWebExtension *self,
-                                        char             *name,
-                                        JSCValue         *args,
-                                        WebKitWebView    *web_view,
-                                        GTask            *task)
+ephy_web_extension_api_windows_handler (EphyWebExtensionSender *sender,
+                                        char                   *name,
+                                        JSCValue               *args,
+                                        GTask                  *task)
 {
   g_autoptr (GError) error = NULL;
   guint idx;
@@ -366,7 +359,7 @@ ephy_web_extension_api_windows_handler (EphyWebExtension *self,
     char *ret;
 
     if (g_strcmp0 (handler.name, name) == 0) {
-      ret = handler.execute (self, name, args, web_view, &error);
+      ret = handler.execute (sender, name, args, &error);
 
       if (error)
         g_task_return_error (task, g_steal_pointer (&error));
diff --git a/src/webextension/api/windows.h b/src/webextension/api/windows.h
index a89ba50ab..c5f09a42a 100644
--- a/src/webextension/api/windows.h
+++ b/src/webextension/api/windows.h
@@ -26,11 +26,10 @@
 
 G_BEGIN_DECLS
 
-void         ephy_web_extension_api_windows_handler                    (EphyWebExtension *self,
-                                                                        char             *name,
-                                                                        JSCValue         *value,
-                                                                        WebKitWebView    *web_view,
-                                                                        GTask            *task);
+void         ephy_web_extension_api_windows_handler                    (EphyWebExtensionSender *sender,
+                                                                        char                   *name,
+                                                                        JSCValue               *value,
+                                                                        GTask                  *task);
 
 char        *ephy_web_extension_api_windows_create_window_json          (EphyWebExtension *self,
                                                                          EphyWindow       *window);
diff --git a/src/webextension/ephy-web-extension-manager.c b/src/webextension/ephy-web-extension-manager.c
index a7955347c..9de0e55b0 100644
--- a/src/webextension/ephy-web-extension-manager.c
+++ b/src/webextension/ephy-web-extension-manager.c
@@ -571,6 +571,7 @@ respond_with_error (WebKitUserMessage *message,
 }
 
 typedef struct {
+  EphyWebExtensionSender *sender;
   WebKitUserMessage *message;
   JSCValue *args;
 } ApiHandlerData;
@@ -580,16 +581,24 @@ api_handler_data_free (ApiHandlerData *data)
 {
   g_object_unref (data->message);
   g_object_unref (data->args);
+  g_free (data->sender);
   g_free (data);
 }
 
 static ApiHandlerData *
-api_handler_data_new (WebKitUserMessage *message,
+api_handler_data_new (EphyWebExtension  *extension,
+                      WebKitWebView     *view,
+                      guint64            frame_id,
+                      WebKitUserMessage *message,
                       JSCValue          *args)
 {
   ApiHandlerData *data = g_new (ApiHandlerData, 1);
   data->message = g_object_ref (message);
   data->args = g_object_ref (args);
+  data->sender = g_new (EphyWebExtensionSender, 1);
+  data->sender->extension = extension;
+  data->sender->view = view;
+  data->sender->frame_id = frame_id;
   return data;
 }
 
@@ -626,8 +635,9 @@ extension_view_handle_user_message (WebKitWebView     *web_view,
   g_auto (GStrv) split = NULL;
   const char *guid;
   const char *json_args;
+  guint64 frame_id;
 
-  g_variant_get (webkit_user_message_get_parameters (message), "(&s&s)", &guid, &json_args);
+  g_variant_get (webkit_user_message_get_parameters (message), "(&st&s)", &guid, &frame_id, &json_args);
 
   js_context = jsc_context_new ();
   args = jsc_value_new_from_json (js_context, json_args);
@@ -654,9 +664,10 @@ extension_view_handle_user_message (WebKitWebView     *web_view,
     if (g_strcmp0 (handler.name, split[0]) == 0) {
       /* TODO: Cancellable */
       GTask *task = g_task_new (web_extension, NULL, 
(GAsyncReadyCallback)on_web_extension_api_handler_finish, NULL);
-      g_task_set_task_data (task, api_handler_data_new (message, args), 
(GDestroyNotify)api_handler_data_free);
+      ApiHandlerData *data = api_handler_data_new (web_extension, web_view, frame_id, message, args);
+      g_task_set_task_data (task, data, (GDestroyNotify)api_handler_data_free);
 
-      handler.execute (web_extension, split[1], args, web_view, task);
+      handler.execute (data->sender, split[1], args, task);
       return TRUE;
     }
   }
@@ -679,8 +690,9 @@ content_scripts_handle_user_message (WebKitWebView     *web_view,
   const char *json_args;
   const char *extension_guid;
   GTask *task;
+  guint64 frame_id;
 
-  g_variant_get (webkit_user_message_get_parameters (message), "(&s&s)", &extension_guid, &json_args);
+  g_variant_get (webkit_user_message_get_parameters (message), "(&st&s)", &extension_guid, &frame_id, 
&json_args);
 
   /* Multiple extensions can send user-messages from the same web-view, so only the target one handles this. 
*/
   if (strcmp (extension_guid, ephy_web_extension_get_guid (web_extension)) != 0)
@@ -707,18 +719,21 @@ content_scripts_handle_user_message (WebKitWebView     *web_view,
 
   /* Content Scripts are very limited in their API access compared to extension views so we handle them 
individually. */
   if (strcmp (split[0], "storage") == 0) {
+    ApiHandlerData *data = api_handler_data_new (web_extension, web_view, frame_id, message, args);
     task = g_task_new (web_extension, NULL, (GAsyncReadyCallback)on_web_extension_api_handler_finish, NULL);
-    g_task_set_task_data (task, api_handler_data_new (message, args), (GDestroyNotify)api_handler_data_free);
+    g_task_set_task_data (task, data, (GDestroyNotify)api_handler_data_free);
 
-    ephy_web_extension_api_storage_handler (web_extension, split[1], args, web_view, task);
+    ephy_web_extension_api_storage_handler (data->sender, split[1], args, task);
     return TRUE;
   }
 
   if (strcmp (name, "runtime.sendMessage") == 0) {
+    ApiHandlerData *data = api_handler_data_new (web_extension, web_view, frame_id, message, args);
     task = g_task_new (web_extension, NULL, (GAsyncReadyCallback)on_web_extension_api_handler_finish, NULL);
-    g_task_set_task_data (task, api_handler_data_new (message, args), (GDestroyNotify)api_handler_data_free);
 
-    ephy_web_extension_api_runtime_handler (web_extension, split[1], args, web_view, task);
+    g_task_set_task_data (task, data, (GDestroyNotify)api_handler_data_free);
+
+    ephy_web_extension_api_runtime_handler (data->sender, split[1], args, task);
     return TRUE;
   }
 
@@ -1576,9 +1591,9 @@ on_extension_emit_ready (GObject      *source,
 static void
 ephy_web_extension_manager_emit_in_extension_views_internal (EphyWebExtensionManager *self,
                                                              EphyWebExtension        *web_extension,
+                                                             EphyWebExtensionSender  *sender,
                                                              const char              *name,
                                                              const char              *message_json,
-                                                             WebKitWebView           *own_web_view,
                                                              GTask                   *reply_task)
 {
   WebKitWebView *background_view = ephy_web_extension_manager_get_background_web_view (self, web_extension);
@@ -1599,7 +1614,7 @@ ephy_web_extension_manager_emit_in_extension_views_internal (EphyWebExtensionMan
    *  - The first `runtime._sendMessageReply` call wins and completes the GTask with its data.
    */
   if (reply_task) {
-    g_autofree char *sender_json = ephy_web_extension_create_sender_object (web_extension, own_web_view);
+    g_autofree char *sender_json = ephy_web_extension_create_sender_object (sender);
     message_guid = g_dbus_generate_guid ();
     tracker = g_new0 (PendingMessageReplyTracker, 1);
     script = g_strdup_printf ("window.browser.%s._emit_with_reply(%s, %s, '%s');", name, message_json, 
sender_json, message_guid);
@@ -1607,7 +1622,7 @@ ephy_web_extension_manager_emit_in_extension_views_internal (EphyWebExtensionMan
     script = g_strdup_printf ("window.browser.%s._emit(%s);", name, message_json);
 
   if (background_view) {
-    if (own_web_view != background_view) {
+    if (!sender || (sender->view != background_view)) {
       webkit_web_view_run_javascript (background_view,
                                       script,
                                       NULL,
@@ -1620,7 +1635,7 @@ ephy_web_extension_manager_emit_in_extension_views_internal (EphyWebExtensionMan
   if (popup_views) {
     for (guint i = 0; i < popup_views->len; i++) {
       WebKitWebView *popup_view = g_ptr_array_index (popup_views, i);
-      if (own_web_view == popup_view)
+      if (!sender || (sender->view == popup_view))
         continue;
 
       webkit_web_view_run_javascript (popup_view,
@@ -1661,28 +1676,18 @@ ephy_web_extension_manager_emit_in_extension_views (EphyWebExtensionManager *sel
                                                     const char              *name,
                                                     const char              *json)
 {
-  ephy_web_extension_manager_emit_in_extension_views_internal (self, web_extension, name, json, NULL, NULL);
-}
-
-void
-ephy_web_extension_manager_emit_in_extension_views_except_self (EphyWebExtensionManager *self,
-                                                                EphyWebExtension        *web_extension,
-                                                                const char              *name,
-                                                                const char              *json,
-                                                                WebKitWebView           *own_webview)
-{
-  ephy_web_extension_manager_emit_in_extension_views_internal (self, web_extension, name, json, own_webview, 
NULL);
+  ephy_web_extension_manager_emit_in_extension_views_internal (self, web_extension, NULL, name, json, NULL);
 }
 
 void
 ephy_web_extension_manager_emit_in_extension_views_with_reply (EphyWebExtensionManager *self,
                                                                EphyWebExtension        *web_extension,
+                                                               EphyWebExtensionSender  *sender,
                                                                const char              *name,
                                                                const char              *json,
-                                                               WebKitWebView           *own_web_view,
                                                                GTask                   *reply_task)
 {
   g_assert (reply_task);
-  g_assert (own_web_view);
-  ephy_web_extension_manager_emit_in_extension_views_internal (self, web_extension, name, json, 
own_web_view, reply_task);
+  g_assert (sender);
+  ephy_web_extension_manager_emit_in_extension_views_internal (self, web_extension, sender, name, json, 
reply_task);
 }
diff --git a/src/webextension/ephy-web-extension-manager.h b/src/webextension/ephy-web-extension-manager.h
index dc66a6991..b7bc91627 100644
--- a/src/webextension/ephy-web-extension-manager.h
+++ b/src/webextension/ephy-web-extension-manager.h
@@ -82,19 +82,12 @@ void                     ephy_web_extension_manager_emit_in_extension_views
                                                                                      const char              
*name,
                                                                                      const char              
*json);
 
-void                     ephy_web_extension_manager_emit_in_extension_views_except_self
-                                                                                    (EphyWebExtensionManager 
*self,
-                                                                                     EphyWebExtension        
*web_extension,
-                                                                                     const char              
*name,
-                                                                                     const char              
*json,
-                                                                                     WebKitWebView           
*own_web_view);
-
 void                     ephy_web_extension_manager_emit_in_extension_views_with_reply
                                                                                     (EphyWebExtensionManager 
*self,
                                                                                      EphyWebExtension        
*web_extension,
+                                                                                     EphyWebExtensionSender  
*sender,
                                                                                      const char              
*name,
                                                                                      const char              
*json,
-                                                                                     WebKitWebView           
*own_web_view,
                                                                                      GTask                   
*reply_task);
 
 void                     ephy_web_extension_manager_emit_in_tab_with_reply          (EphyWebExtensionManager 
*self,
diff --git a/src/webextension/ephy-web-extension.c b/src/webextension/ephy-web-extension.c
index c88da11d8..9ddb28081 100644
--- a/src/webextension/ephy-web-extension.c
+++ b/src/webextension/ephy-web-extension.c
@@ -1571,19 +1571,19 @@ ephy_web_extension_clear_local_storage (EphyWebExtension *self)
 }
 
 char *
-ephy_web_extension_create_sender_object (EphyWebExtension *self,
-                                         WebKitWebView    *web_view)
+ephy_web_extension_create_sender_object (EphyWebExtensionSender *sender)
 {
   g_autoptr (JsonNode) node = json_node_init_object (json_node_alloc (), json_object_new ());
   JsonObject *obj = json_node_get_object (node);
 
-  json_object_set_string_member (obj, "id", ephy_web_extension_get_guid (self));
-  if (web_view) {
-    json_object_set_string_member (obj, "url", webkit_web_view_get_uri (web_view));
+  json_object_set_string_member (obj, "id", ephy_web_extension_get_guid (sender->extension));
+  if (sender->view) {
+    json_object_set_string_member (obj, "url", webkit_web_view_get_uri (sender->view));
+    json_object_set_int_member (obj, "frameId", sender->frame_id);
 
     /* For now these are always regular views and not extension views. */
-    if (EPHY_IS_WEB_VIEW (web_view)) {
-      json_object_set_member (obj, "tab", ephy_web_extension_api_tabs_create_tab_object (self, EPHY_WEB_VIEW 
(web_view)));
+    if (EPHY_IS_WEB_VIEW (sender->view)) {
+      json_object_set_member (obj, "tab", ephy_web_extension_api_tabs_create_tab_object (sender->extension, 
EPHY_WEB_VIEW (sender->view)));
     }
   }
 
diff --git a/src/webextension/ephy-web-extension.h b/src/webextension/ephy-web-extension.h
index 6339b1b29..7692de4eb 100644
--- a/src/webextension/ephy-web-extension.h
+++ b/src/webextension/ephy-web-extension.h
@@ -35,23 +35,32 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphyWebExtension, ephy_web_extension, EPHY, WEB_EXTENSION, GObject)
 
-typedef void (*executeTaskHandler)(EphyWebExtension *web_extension,
-                                   char             *name,
-                                   JSCValue         *args,
-                                   WebKitWebView    *web_view,
-                                   GTask            *task);
+/**
+ * EphyWebExtensionSender:
+ *
+ * Represents the sender of a message or API call.
+ * Which extension from which view in which frame.
+ */
+typedef struct {
+  EphyWebExtension *extension;
+  WebKitWebView *view;
+  guint64 frame_id;
+} EphyWebExtensionSender;
 
-typedef char *(*executeHandler)(EphyWebExtension  *web_extension,
-                                char              *name,
-                                JSCValue          *args,
-                                WebKitWebView     *web_view,
-                                GError           **error);
+typedef void (*executeTaskHandler)(EphyWebExtensionSender *sender,
+                                   char                   *name,
+                                   JSCValue               *args,
+                                   GTask                  *task);
 
-typedef void (*EphyApiExecuteFunc)(EphyWebExtension *web_extension,
-                                   char             *name,
-                                   JsonArray        *args,
-                                   WebKitWebView    *web_view,
-                                   GTask            *task);
+typedef char *(*executeHandler)(EphyWebExtensionSender  *sender,
+                                char                    *name,
+                                JSCValue                *args,
+                                GError                 **error);
+
+typedef void (*EphyApiExecuteFunc)(EphyWebExtensionSender *sender,
+                                   char                   *name,
+                                   JsonArray              *args,
+                                   GTask                  *task);
 
 
 extern GQuark web_extension_error_quark (void);
@@ -180,8 +189,8 @@ void                   ephy_web_extension_save_local_storage              (EphyW
 
 void                   ephy_web_extension_clear_local_storage             (EphyWebExtension *self);
 
-char                  *ephy_web_extension_create_sender_object            (EphyWebExtension *self,
-                                                                           WebKitWebView     *web_view);
+char                  *ephy_web_extension_create_sender_object            (EphyWebExtensionSender *sender);
+
 gboolean               ephy_web_extension_rule_matches_uri                (const char       *rule,
                                                                            GUri             *uri);
 


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