[epiphany/pgriffis/web-extension/api-cleanups: 2/3] WebExtensions: Remove all sync API handlers
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/pgriffis/web-extension/api-cleanups: 2/3] WebExtensions: Remove all sync API handlers
- Date: Wed, 6 Jul 2022 20:47:29 +0000 (UTC)
commit 53d84d03639cfda7dae742ae37981412d023d12c
Author: Patrick Griffis <pgriffis igalia com>
Date: Thu Jun 30 21:12:06 2022 -0500
WebExtensions: Remove all sync API handlers
The APIs are async and it just added noise pretending otherwise.
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1161>
src/webextension/api/alarms.c | 94 +++++++-------
src/webextension/api/cookies.c | 10 +-
src/webextension/api/downloads.c | 117 +++++++----------
src/webextension/api/notifications.c | 74 +++++------
src/webextension/api/pageaction.c | 106 +++++++--------
src/webextension/api/runtime.c | 70 ++++------
src/webextension/api/storage.c | 83 ++++++------
src/webextension/api/tabs.c | 235 ++++++++++++++++------------------
src/webextension/api/windows.c | 110 +++++++---------
src/webextension/ephy-web-extension.h | 5 -
10 files changed, 387 insertions(+), 517 deletions(-)
---
diff --git a/src/webextension/api/alarms.c b/src/webextension/api/alarms.c
index eda9252bf..003026625 100644
--- a/src/webextension/api/alarms.c
+++ b/src/webextension/api/alarms.c
@@ -162,11 +162,11 @@ on_alarm_start (gpointer user_data)
return G_SOURCE_REMOVE;
}
-static char *
+static void
alarms_handler_create (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) alarm_name = NULL;
g_autoptr (JSCValue) alarm_info = NULL;
@@ -194,8 +194,8 @@ alarms_handler_create (EphyWebExtensionSender *sender,
}
if (delay_in_minutes && when) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "alarms.create(): Both
'when' and 'delayInMinutes' cannot be set");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"alarms.create(): Both 'when' and 'delayInMinutes' cannot be set");
+ return;
}
alarm = g_new0 (Alarm, 1);
@@ -216,14 +216,14 @@ alarms_handler_create (EphyWebExtensionSender *sender,
g_hash_table_replace (alarms, alarm->name, alarm);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
+static void
alarms_handler_clear (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
GHashTable *alarms = get_alarms (sender->extension);
g_autoptr (JSCValue) name_value = jsc_value_object_get_property_at_index (args, 0);
@@ -234,32 +234,36 @@ alarms_handler_clear (EphyWebExtensionSender *sender,
else
name_str = jsc_value_to_string (name_value);
- if (g_hash_table_remove (alarms, name_str))
- return g_strdup ("true");
+ if (g_hash_table_remove (alarms, name_str)) {
+ g_task_return_pointer (task, g_strdup ("true"), g_free);
+ return;
+ }
- return g_strdup ("false");
+ g_task_return_pointer (task, g_strdup ("false"), g_free);
}
-static char *
-alarms_handler_clear_all (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+alarms_handler_clear_all (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
GHashTable *alarms = get_alarms (sender->extension);
- if (g_hash_table_size (alarms) == 0)
- return g_strdup ("false");
+ if (g_hash_table_size (alarms) == 0) {
+ g_task_return_pointer (task, g_strdup ("false"), g_free);
+ return;
+ }
g_hash_table_remove_all (alarms);
- return g_strdup ("true");
+ g_task_return_pointer (task, g_strdup ("true"), g_free);
}
-static char *
-alarms_handler_get (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+alarms_handler_get (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
GHashTable *alarms = get_alarms (sender->extension);
g_autoptr (JSCValue) name_value = jsc_value_object_get_property_at_index (args, 0);
@@ -272,14 +276,14 @@ alarms_handler_get (EphyWebExtensionSender *sender,
name_str = jsc_value_to_string (name_value);
alarm = g_hash_table_lookup (alarms, name_str);
- return alarm_to_json (alarm);
+ g_task_return_pointer (task, alarm_to_json (alarm), g_free);
}
-static char *
-alarms_handler_get_all (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+alarms_handler_get_all (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
GHashTable *alarms = get_alarms (sender->extension);
g_autoptr (JsonNode) node = json_node_init_array (json_node_alloc (), json_array_new ());
@@ -291,10 +295,10 @@ alarms_handler_get_all (EphyWebExtensionSender *sender,
while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&alarm))
json_array_add_element (array, alarm_to_node (alarm));
- return json_to_string (node, FALSE);
+ g_task_return_pointer (task, json_to_string (node, FALSE), g_free);
}
-static EphyWebExtensionSyncApiHandler alarms_handlers[] = {
+static EphyWebExtensionAsyncApiHandler alarms_handlers[] = {
{"clear", alarms_handler_clear},
{"clearAll", alarms_handler_clear_all},
{"create", alarms_handler_create},
@@ -308,31 +312,19 @@ ephy_web_extension_api_alarms_handler (EphyWebExtensionSender *sender,
JSCValue *args,
GTask *task)
{
- g_autoptr (GError) error = NULL;
-
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));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "alarms:
Permission Denied");
return;
}
for (guint idx = 0; idx < G_N_ELEMENTS (alarms_handlers); idx++) {
- EphyWebExtensionSyncApiHandler handler = alarms_handlers[idx];
- char *ret;
+ EphyWebExtensionAsyncApiHandler handler = alarms_handlers[idx];
if (g_strcmp0 (handler.name, name) == 0) {
- ret = handler.execute (sender, name, args, &error);
-
- if (error)
- g_task_return_error (task, g_steal_pointer (&error));
- else
- g_task_return_pointer (task, ret, g_free);
-
+ handler.execute (sender, name, args, task);
return;
}
}
- error = g_error_new (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "alarms.%s(): Not
Implemented", name);
- g_task_return_error (task, g_steal_pointer (&error));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "alarms.%s(): Not
Implemented", name);
}
diff --git a/src/webextension/api/cookies.c b/src/webextension/api/cookies.c
index 1987788b2..e0f95d8d9 100644
--- a/src/webextension/api/cookies.c
+++ b/src/webextension/api/cookies.c
@@ -560,12 +560,8 @@ ephy_web_extension_api_cookies_handler (EphyWebExtensionSender *sender,
JSCValue *args,
GTask *task)
{
- g_autoptr (GError) error = NULL;
-
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));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission
Denied");
return;
}
@@ -578,7 +574,5 @@ ephy_web_extension_api_cookies_handler (EphyWebExtensionSender *sender,
}
}
- g_warning ("%s(): '%s' not implemented by Epiphany!", __FUNCTION__, name);
- error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not Implemented");
- g_task_return_error (task, g_steal_pointer (&error));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not
Implemented");
}
diff --git a/src/webextension/api/downloads.c b/src/webextension/api/downloads.c
index 6038d2e75..e3da3ac6e 100644
--- a/src/webextension/api/downloads.c
+++ b/src/webextension/api/downloads.c
@@ -90,35 +90,37 @@ downloads_handler_download (EphyWebExtensionSender *sender,
g_task_return_pointer (task, g_strdup_printf ("%" G_GUINT64_FORMAT, ephy_download_get_uid (download)),
g_free);
}
-static char *
-downloads_handler_cancel (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+downloads_handler_cancel (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 ();
EphyDownload *download;
if (!jsc_value_is_number (download_id)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"downloads.cancel(): Missing downloadId");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"downloads.cancel(): Missing downloadId");
+ return;
}
download = ephy_downloads_manager_find_download_by_id (downloads_manager, jsc_value_to_int32
(download_id));
/* If we fail to find one its possible it was removed already. So instead of erroring just consider it a
success. */
- if (!download)
- return NULL;
+ if (!download) {
+ g_task_return_pointer (task, NULL, NULL);
+ return;
+ }
ephy_download_cancel (download);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
-downloads_handler_open_or_show (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+downloads_handler_open_or_show (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 ();
@@ -128,14 +130,14 @@ downloads_handler_open_or_show (EphyWebExtensionSender *sender,
/* We reuse this method for both downloads.open() and downloads.show() as they are identical other than
the action. */
if (!jsc_value_is_number (download_id)) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "downloads.%s(): Missing
downloadId", name);
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"downloads.%s(): Missing downloadId", name);
+ return;
}
download = ephy_downloads_manager_find_download_by_id (downloads_manager, jsc_value_to_int32
(download_id));
if (!download) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "downloads.%s(): Failed
to find downloadId", name);
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"downloads.%s(): Failed to find downloadId", name);
+ return;
}
if (strcmp (name, "open") == 0)
@@ -144,11 +146,11 @@ downloads_handler_open_or_show (EphyWebExtensionSender *sender,
action = EPHY_DOWNLOAD_ACTION_BROWSE_TO;
if (!ephy_download_do_download_action (download, action)) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "downloads.%s(): Failed
to %s download", name, name);
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"downloads.%s(): Failed to %s download", name, name);
+ return;
}
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
static GDateTime *
@@ -613,11 +615,11 @@ download_to_json (EphyDownload *download)
return json_to_string (root, FALSE);
}
-static char *
-downloads_handler_search (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+downloads_handler_search (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) query_object = jsc_value_object_get_property_at_index (args, 0);
EphyDownloadsManager *downloads_manager = get_downloads_manager ();
@@ -627,8 +629,8 @@ downloads_handler_search (EphyWebExtensionSender *sender,
GList *downloads;
if (!jsc_value_is_object (query_object)) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "downloads.query():
Missing query");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"downloads.query(): Missing query");
+ return;
}
query = download_query_new (query_object);
@@ -641,14 +643,14 @@ downloads_handler_search (EphyWebExtensionSender *sender,
json_builder_end_array (builder);
root = json_builder_get_root (builder);
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
-static char *
-downloads_handler_erase (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+downloads_handler_erase (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) query_object = jsc_value_object_get_property_at_index (args, 0);
EphyDownloadsManager *downloads_manager = get_downloads_manager ();
@@ -658,8 +660,8 @@ downloads_handler_erase (EphyWebExtensionSender *sender,
GList *downloads;
if (!jsc_value_is_object (query_object)) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "downloads.erase():
Missing query");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"downloads.erase(): Missing query");
+ return;
}
query = download_query_new (query_object);
@@ -676,18 +678,18 @@ downloads_handler_erase (EphyWebExtensionSender *sender,
json_builder_end_array (builder);
root = json_builder_get_root (builder);
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
-static char *
-downloads_handler_showdefaultfolder (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+downloads_handler_showdefaultfolder (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (GFile) default_folder = g_file_new_for_path (ephy_file_get_downloads_dir ());
ephy_file_browse_to (default_folder);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
static void
@@ -745,7 +747,9 @@ downloads_handler_removefile (EphyWebExtensionSender *sender,
g_file_delete_async (destination_file, G_PRIORITY_DEFAULT, NULL,
(GAsyncReadyCallback)delete_file_ready_cb, task);
}
-static EphyWebExtensionSyncApiHandler downloads_sync_handlers[] = {
+static EphyWebExtensionAsyncApiHandler downloads_async_handlers[] = {
+ {"download", downloads_handler_download},
+ {"removeFile", downloads_handler_removefile},
{"cancel", downloads_handler_cancel},
{"open", downloads_handler_open_or_show},
{"show", downloads_handler_open_or_show},
@@ -754,19 +758,12 @@ static EphyWebExtensionSyncApiHandler downloads_sync_handlers[] = {
{"erase", downloads_handler_erase},
};
-static EphyWebExtensionAsyncApiHandler downloads_async_handlers[] = {
- {"download", downloads_handler_download},
- {"removeFile", downloads_handler_removefile},
-};
-
void
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 (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");
@@ -782,22 +779,6 @@ ephy_web_extension_api_downloads_handler (EphyWebExtensionSender *sender,
}
}
- for (guint idx = 0; idx < G_N_ELEMENTS (downloads_sync_handlers); idx++) {
- EphyWebExtensionSyncApiHandler handler = downloads_sync_handlers[idx];
- char *ret;
-
- if (g_strcmp0 (handler.name, name) == 0) {
- ret = handler.execute (sender, name, args, &error);
-
- if (error)
- g_task_return_error (task, g_steal_pointer (&error));
- else
- g_task_return_pointer (task, ret, g_free);
-
- return;
- }
- }
-
g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "downloads.%s():
Not Implemented", name);
}
diff --git a/src/webextension/api/notifications.c b/src/webextension/api/notifications.c
index 79135dc10..a132a5283 100644
--- a/src/webextension/api/notifications.c
+++ b/src/webextension/api/notifications.c
@@ -34,11 +34,11 @@ create_extension_notification_id (EphyWebExtension *web_extension,
return g_strconcat (ephy_web_extension_get_guid (web_extension), ".", id, NULL);
}
-static char *
-notifications_handler_create (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+notifications_handler_create (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
g_autoptr (JSCValue) button_array = NULL;
@@ -58,23 +58,23 @@ notifications_handler_create (EphyWebExtensionSender *sender,
value = jsc_value_object_get_property_at_index (args, 1);
} else {
if (strcmp (name, "update") == 0) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"notifications.update(): id not given");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"notifications.update(): id not given");
+ return;
}
id = g_dbus_generate_guid ();
}
if (!jsc_value_is_object (value)) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "notifications.%s():
notificationOptions not given", name);
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"notifications.%s(): notificationOptions not given", name);
+ return;
}
title = api_utils_get_string_property (value, "title", NULL);
message = api_utils_get_string_property (value, "message", NULL);
if (!title || !message) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "notifications.%s():
title and message are required", name);
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"notifications.%s(): title and message are required", name);
+ return;
}
notification = g_notification_new (title);
@@ -94,22 +94,22 @@ notifications_handler_create (EphyWebExtensionSender *sender,
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);
+ g_task_return_pointer (task, g_strdup_printf ("\"%s\"", id), g_free);
}
-static char *
-notifications_handler_clear (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+notifications_handler_clear (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
g_autofree char *id = NULL;
g_autofree char *namespaced_id = NULL;
if (!jsc_value_is_string (value)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"notifications.clear(): id not given");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"notifications.clear(): id not given");
+ return;
}
id = jsc_value_to_string (value);
@@ -118,20 +118,20 @@ notifications_handler_clear (EphyWebExtensionSender *sender,
g_application_withdraw_notification (G_APPLICATION (ephy_shell_get_default ()), namespaced_id);
/* We don't actually know if a notification was withdrawn but lets assume it was. */
- return g_strdup ("true");
+ g_task_return_pointer (task, g_strdup ("true"), g_free);
}
-static char *
-notifications_handler_get_all (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+notifications_handler_get_all (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
/* GNotification does not provide information on the state of notifications. */
- return g_strdup ("[]");
+ g_task_return_pointer (task, g_strdup ("[]"), g_free);
}
-static EphyWebExtensionSyncApiHandler notifications_handlers[] = {
+static EphyWebExtensionAsyncApiHandler notifications_handlers[] = {
{"create", notifications_handler_create},
{"clear", notifications_handler_clear},
{"getAll", notifications_handler_get_all},
@@ -144,32 +144,20 @@ ephy_web_extension_api_notifications_handler (EphyWebExtensionSender *sender,
JSCValue *args,
GTask *task)
{
- g_autoptr (GError) error = NULL;
-
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));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission
Denied");
return;
}
for (guint idx = 0; idx < G_N_ELEMENTS (notifications_handlers); idx++) {
- EphyWebExtensionSyncApiHandler handler = notifications_handlers[idx];
- char *ret;
+ EphyWebExtensionAsyncApiHandler handler = notifications_handlers[idx];
if (g_strcmp0 (handler.name, name) == 0) {
- ret = handler.execute (sender, name, args, &error);
-
- if (error)
- g_task_return_error (task, g_steal_pointer (&error));
- else
- g_task_return_pointer (task, ret, g_free);
-
+ handler.execute (sender, name, args, task);
return;
}
}
- g_warning ("%s(): '%s' not implemented by Epiphany!", __FUNCTION__, name);
- error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not Implemented");
- g_task_return_error (task, g_steal_pointer (&error));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not
Implemented");
}
diff --git a/src/webextension/api/pageaction.c b/src/webextension/api/pageaction.c
index 1cf8ed1f9..e48ba26d1 100644
--- a/src/webextension/api/pageaction.c
+++ b/src/webextension/api/pageaction.c
@@ -53,11 +53,11 @@ pageaction_get_action (EphyWebExtension *extension,
return ephy_web_extension_manager_get_page_action (manager, extension, web_view);
}
-static char *
-pageaction_handler_seticon (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+pageaction_handler_seticon (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
GtkWidget *action;
g_autofree char *path_str = NULL;
@@ -67,8 +67,8 @@ pageaction_handler_seticon (EphyWebExtensionSender *sender,
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
path_value = jsc_value_object_get_property (value, "path");
@@ -76,19 +76,19 @@ pageaction_handler_seticon (EphyWebExtensionSender *sender,
path_str = jsc_value_to_string (path_value);
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"pageAction.setIcon(): Currently only single path strings are supported.");
+ return;
}
gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_bin_get_child (GTK_BIN (action))), pixbuf);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
-pageaction_handler_settitle (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+pageaction_handler_settitle (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
GtkWidget *action;
g_autoptr (JSCValue) title = NULL;
@@ -96,21 +96,21 @@ pageaction_handler_settitle (EphyWebExtensionSender *sender,
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
title = jsc_value_object_get_property (value, "title");
gtk_widget_set_tooltip_text (action, jsc_value_to_string (title));
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
-pageaction_handler_gettitle (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+pageaction_handler_gettitle (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
GtkWidget *action;
@@ -118,56 +118,56 @@ pageaction_handler_gettitle (EphyWebExtensionSender *sender,
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
title = gtk_widget_get_tooltip_text (action);
- return g_strdup_printf ("\"%s\"", title ? title : "");
+ g_task_return_pointer (task, g_strdup_printf ("\"%s\"", title ? title : ""), g_free);
}
-static char *
-pageaction_handler_show (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+pageaction_handler_show (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
GtkWidget *action;
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
gtk_widget_set_visible (action, TRUE);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
-pageaction_handler_hide (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+pageaction_handler_hide (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
GtkWidget *action;
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
gtk_widget_set_visible (action, FALSE);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static EphyWebExtensionSyncApiHandler pageaction_handlers[] = {
+static EphyWebExtensionAsyncApiHandler pageaction_handlers[] = {
{"setIcon", pageaction_handler_seticon},
{"setTitle", pageaction_handler_settitle},
{"getTitle", pageaction_handler_gettitle},
@@ -181,26 +181,14 @@ ephy_web_extension_api_pageaction_handler (EphyWebExtensionSender *sender,
JSCValue *args,
GTask *task)
{
- g_autoptr (GError) error = NULL;
- guint idx;
-
- for (idx = 0; idx < G_N_ELEMENTS (pageaction_handlers); idx++) {
- EphyWebExtensionSyncApiHandler handler = pageaction_handlers[idx];
- char *ret;
+ for (guint idx = 0; idx < G_N_ELEMENTS (pageaction_handlers); idx++) {
+ EphyWebExtensionAsyncApiHandler handler = pageaction_handlers[idx];
if (g_strcmp0 (handler.name, name) == 0) {
- ret = handler.execute (sender, name, args, &error);
-
- if (error)
- g_task_return_error (task, g_steal_pointer (&error));
- else
- g_task_return_pointer (task, ret, g_free);
-
+ handler.execute (sender, name, args, task);
return;
}
}
- g_warning ("%s(): '%s' not implemented by Epiphany!", __FUNCTION__, name);
- error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not Implemented");
- g_task_return_error (task, g_steal_pointer (&error));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not
Implemented");
}
diff --git a/src/webextension/api/runtime.c b/src/webextension/api/runtime.c
index 350abccc2..2b9e093bd 100644
--- a/src/webextension/api/runtime.c
+++ b/src/webextension/api/runtime.c
@@ -27,11 +27,11 @@
#include "ephy-embed-utils.h"
#include "ephy-shell.h"
-static char *
-runtime_handler_get_browser_info (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+runtime_handler_get_browser_info (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JsonBuilder) builder = json_builder_new ();
g_autoptr (JsonNode) root = NULL;
@@ -47,7 +47,7 @@ runtime_handler_get_browser_info (EphyWebExtensionSender *sender,
root = json_builder_get_root (builder);
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
static const char *
@@ -66,11 +66,11 @@ get_arch (void)
#endif
}
-static char *
-runtime_handler_get_platform_info (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+runtime_handler_get_platform_info (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JsonBuilder) builder = json_builder_new ();
g_autoptr (JsonNode) root = NULL;
@@ -88,7 +88,7 @@ runtime_handler_get_platform_info (EphyWebExtensionSender *sender,
root = json_builder_get_root (builder);
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
static gboolean
@@ -143,11 +143,11 @@ runtime_handler_send_message (EphyWebExtensionSender *sender,
return;
}
-static char *
-runtime_handler_open_options_page (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+runtime_handler_open_options_page (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
const char *options_ui = ephy_web_extension_get_option_ui_page (sender->extension);
EphyShell *shell = ephy_shell_get_default ();
@@ -157,8 +157,8 @@ runtime_handler_open_options_page (EphyWebExtensionSender *sender,
GtkWindow *new_window;
if (!options_ui) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Extension does
not have an options page");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Extension
does not have an options page");
+ return;
}
title = g_strdup_printf (_("Options for %s"), ephy_web_extension_get_name (sender->extension));
@@ -178,16 +178,13 @@ runtime_handler_open_options_page (EphyWebExtensionSender *sender,
gtk_widget_show (new_web_view);
gtk_window_present (new_window);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static EphyWebExtensionSyncApiHandler runtime_sync_handlers[] = {
+static EphyWebExtensionAsyncApiHandler runtime_async_handlers[] = {
{"getBrowserInfo", runtime_handler_get_browser_info},
{"getPlatformInfo", runtime_handler_get_platform_info},
{"openOptionsPage", runtime_handler_open_options_page},
-};
-
-static EphyWebExtensionAsyncApiHandler runtime_async_handlers[] = {
{"sendMessage", runtime_handler_send_message},
};
@@ -197,26 +194,7 @@ ephy_web_extension_api_runtime_handler (EphyWebExtensionSender *sender,
JSCValue *args,
GTask *task)
{
- g_autoptr (GError) error = NULL;
- guint idx;
-
- for (idx = 0; idx < G_N_ELEMENTS (runtime_sync_handlers); idx++) {
- EphyWebExtensionSyncApiHandler handler = runtime_sync_handlers[idx];
- char *ret;
-
- if (g_strcmp0 (handler.name, name) == 0) {
- ret = handler.execute (sender, name, args, &error);
-
- if (error)
- g_task_return_error (task, g_steal_pointer (&error));
- else
- g_task_return_pointer (task, ret, g_free);
-
- return;
- }
- }
-
- for (idx = 0; idx < G_N_ELEMENTS (runtime_async_handlers); idx++) {
+ for (guint idx = 0; idx < G_N_ELEMENTS (runtime_async_handlers); idx++) {
EphyWebExtensionAsyncApiHandler handler = runtime_async_handlers[idx];
if (g_strcmp0 (handler.name, name) == 0) {
@@ -225,7 +203,5 @@ ephy_web_extension_api_runtime_handler (EphyWebExtensionSender *sender,
}
}
- g_warning ("%s(): '%s' not implemented by Epiphany!", __FUNCTION__, name);
- error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not Implemented");
- g_task_return_error (task, g_steal_pointer (&error));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not
Implemented");
}
diff --git a/src/webextension/api/storage.c b/src/webextension/api/storage.c
index 323a24973..d84f09e67 100644
--- a/src/webextension/api/storage.c
+++ b/src/webextension/api/storage.c
@@ -57,11 +57,11 @@ strv_from_value (JSCValue *array)
return g_strv_builder_end (builder);
}
-static char *
-storage_handler_local_set (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+storage_handler_local_set (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
JsonNode *local_storage = ephy_web_extension_get_local_storage (sender->extension);
JsonObject *local_storage_obj = json_node_get_object (local_storage);
@@ -69,8 +69,8 @@ storage_handler_local_set (EphyWebExtensionSender *sender,
g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
if (!jsc_value_is_object (value)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
keys = jsc_value_object_enumerate_properties (value);
@@ -82,14 +82,14 @@ storage_handler_local_set (EphyWebExtensionSender *sender,
/* FIXME: Async IO */
ephy_web_extension_save_local_storage (sender->extension);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
-storage_handler_local_get (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+storage_handler_local_get (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
JsonNode *local_storage = ephy_web_extension_get_local_storage (sender->extension);
JsonObject *local_storage_obj = json_node_get_object (local_storage);
@@ -97,8 +97,10 @@ storage_handler_local_get (EphyWebExtensionSender *sender,
g_auto (GStrv) keys = NULL;
g_autoptr (JSCValue) value = jsc_value_object_get_property_at_index (args, 0);
- if (jsc_value_is_null (value))
- return json_to_string (local_storage, FALSE);
+ if (jsc_value_is_null (value)) {
+ g_task_return_pointer (task, json_to_string (local_storage, FALSE), g_free);
+ return;
+ }
builder = json_builder_new ();
json_builder_begin_object (builder);
@@ -141,14 +143,14 @@ storage_handler_local_get (EphyWebExtensionSender *sender,
end_get:
json_builder_end_object (builder);
- return json_to_string (json_builder_get_root (builder), FALSE);
+ g_task_return_pointer (task, json_to_string (json_builder_get_root (builder), FALSE), g_free);
}
-static char *
-storage_handler_local_remove (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+storage_handler_local_remove (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
JsonNode *local_storage = ephy_web_extension_get_local_storage (sender->extension);
JsonObject *local_storage_obj = json_node_get_object (local_storage);
@@ -170,21 +172,21 @@ storage_handler_local_remove (EphyWebExtensionSender *sender,
end_remove:
ephy_web_extension_save_local_storage (sender->extension);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
-storage_handler_local_clear (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+storage_handler_local_clear (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
ephy_web_extension_clear_local_storage (sender->extension);
ephy_web_extension_save_local_storage (sender->extension);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static EphyWebExtensionSyncApiHandler storage_handlers[] = {
+static EphyWebExtensionAsyncApiHandler storage_handlers[] = {
{"local.set", storage_handler_local_set},
{"local.get", storage_handler_local_get},
{"local.remove", storage_handler_local_remove},
@@ -197,33 +199,20 @@ ephy_web_extension_api_storage_handler (EphyWebExtensionSender *sender,
JSCValue *args,
GTask *task)
{
- g_autoptr (GError) error = NULL;
- guint idx;
-
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));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "storage:
Permission Denied");
return;
}
- for (idx = 0; idx < G_N_ELEMENTS (storage_handlers); idx++) {
- EphyWebExtensionSyncApiHandler handler = storage_handlers[idx];
- char *ret;
+ for (guint idx = 0; idx < G_N_ELEMENTS (storage_handlers); idx++) {
+ EphyWebExtensionAsyncApiHandler handler = storage_handlers[idx];
if (g_strcmp0 (handler.name, name) == 0) {
- ret = handler.execute (sender, name, args, &error);
-
- if (error)
- g_task_return_error (task, g_steal_pointer (&error));
- else
- g_task_return_pointer (task, ret, g_free);
-
+ handler.execute (sender, name, args, task);
return;
}
}
- g_warning ("%s(): '%s' not implemented by Epiphany!", __FUNCTION__, name);
- error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not Implemented");
- g_task_return_error (task, g_steal_pointer (&error));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "storage.%s():
Not Implemented", name);
}
diff --git a/src/webextension/api/tabs.c b/src/webextension/api/tabs.c
index 78a04be22..eaf5d66b3 100644
--- a/src/webextension/api/tabs.c
+++ b/src/webextension/api/tabs.c
@@ -157,11 +157,11 @@ get_window_by_id (EphyShell *shell,
return EPHY_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (shell)));
}
-static char *
-tabs_handler_query (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_query (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JsonBuilder) builder = json_builder_new ();
g_autoptr (JsonNode) root = NULL;
@@ -174,8 +174,10 @@ tabs_handler_query (EphyWebExtensionSender *sender,
gint32 window_id;
gint32 tab_index;
- if (!jsc_value_is_object (value))
- return NULL;
+ if (!jsc_value_is_object (value)) {
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.query():
Missing query object.");
+ return;
+ }
active = api_utils_get_tri_state_value_property (value, "active");
current_window = api_utils_get_tri_state_value_property (value, "currentWindow");
@@ -229,15 +231,14 @@ tabs_handler_query (EphyWebExtensionSender *sender,
json_builder_end_array (builder);
root = json_builder_get_root (builder);
-
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
-static char *
-tabs_handler_insert_css (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_insert_css (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyShell *shell = ephy_shell_get_default ();
WebKitUserContentManager *ucm;
@@ -257,8 +258,8 @@ tabs_handler_insert_css (EphyWebExtensionSender *sender,
}
if (!jsc_value_is_object (obj)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
if (!tab_id_value)
@@ -267,13 +268,13 @@ tabs_handler_insert_css (EphyWebExtensionSender *sender,
target_web_view = get_web_view_for_tab_id (shell, jsc_value_to_int32 (tab_id_value), NULL);
if (!target_web_view) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission
Denied");
+ return;
}
ucm = webkit_web_view_get_user_content_manager (target_web_view);
@@ -284,14 +285,14 @@ tabs_handler_insert_css (EphyWebExtensionSender *sender,
if (css)
webkit_user_content_manager_add_style_sheet (ucm, css);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
-tabs_handler_remove_css (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_remove_css (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyShell *shell = ephy_shell_get_default ();
JSCValue *code;
@@ -311,8 +312,8 @@ tabs_handler_remove_css (EphyWebExtensionSender *sender,
}
if (!jsc_value_is_object (obj)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
if (!tab_id_value)
@@ -321,13 +322,13 @@ tabs_handler_remove_css (EphyWebExtensionSender *sender,
target_web_view = get_web_view_for_tab_id (shell, jsc_value_to_int32 (tab_id_value), NULL);
if (!target_web_view) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_PERMISSION_DENIED, "Permission
Denied");
+ return;
}
ucm = webkit_web_view_get_user_content_manager (target_web_view);
@@ -337,14 +338,14 @@ tabs_handler_remove_css (EphyWebExtensionSender *sender,
if (css)
webkit_user_content_manager_remove_style_sheet (ucm, css);
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
-tabs_handler_get (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_get (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyShell *shell = ephy_shell_get_default ();
g_autoptr (JsonBuilder) builder = json_builder_new ();
@@ -355,20 +356,20 @@ tabs_handler_get (EphyWebExtensionSender *sender,
tab_id_value = jsc_value_object_get_property_at_index (args, 0);
if (!jsc_value_is_number (tab_id_value)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
target_web_view = EPHY_WEB_VIEW (get_web_view_for_tab_id (shell, jsc_value_to_int32 (args),
&parent_window));
if (!target_web_view) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "Invalid
Arguments");
+ return;
}
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);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
static void
@@ -544,11 +545,11 @@ ephy_web_extension_api_tabs_url_is_unprivileged (const char *url)
return TRUE;
}
-static char *
-tabs_handler_create (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_create (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyShell *shell = ephy_shell_get_default ();
EphyEmbed *embed;
@@ -562,14 +563,14 @@ tabs_handler_create (EphyWebExtensionSender *sender,
create_properties = jsc_value_object_get_property_at_index (args, 0);
if (!jsc_value_is_object (create_properties)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.create():
First argument is not an object");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.create(): First argument is not an object");
+ return;
}
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.create(): URL '%s' is not allowed", url);
+ return;
}
if (api_utils_get_boolean_property (create_properties, "active", FALSE))
@@ -593,14 +594,14 @@ tabs_handler_create (EphyWebExtensionSender *sender,
builder = json_builder_new ();
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);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
-static char *
-tabs_handler_update (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_update (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyShell *shell = ephy_shell_get_default ();
g_autoptr (JSCValue) update_properties = NULL;
@@ -624,8 +625,8 @@ tabs_handler_update (EphyWebExtensionSender *sender,
}
if (!jsc_value_is_object (update_properties)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.update():
Missing updateProperties.");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.update(): Missing updateProperties.");
+ return;
}
if (tab_id >= 0)
@@ -636,14 +637,14 @@ tabs_handler_update (EphyWebExtensionSender *sender,
}
if (!target_web_view) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.update(): Failed to
find tabId %d.", tab_id);
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.update(): Failed to find tabId %d.", tab_id);
+ return;
}
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;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.update(): URL '%s' is not allowed", new_url);
+ return;
}
muted = api_utils_get_tri_state_value_property (update_properties, "muted");
@@ -656,7 +657,7 @@ tabs_handler_update (EphyWebExtensionSender *sender,
builder = json_builder_new ();
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);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
static void
@@ -675,11 +676,11 @@ close_tab_id (EphyShell *shell,
ephy_tab_view_close (tab_view, gtk_widget_get_parent (gtk_widget_get_parent (web_view)));
}
-static char *
-tabs_handler_remove (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_remove (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyShell *shell = ephy_shell_get_default ();
g_autoptr (JSCValue) tab_ids = NULL;
@@ -690,7 +691,8 @@ tabs_handler_remove (EphyWebExtensionSender *sender,
if (jsc_value_is_number (tab_ids)) {
close_tab_id (shell, jsc_value_to_int32 (tab_ids));
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
+ return;
}
if (jsc_value_is_array (tab_ids)) {
@@ -703,18 +705,17 @@ tabs_handler_remove (EphyWebExtensionSender *sender,
value = jsc_value_object_get_property_at_index (tab_ids, i);
}
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.remove():
First argument is not a number or array.");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.remove():
First argument is not a number or array.");
}
-static char *
-tabs_handler_set_zoom (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_set_zoom (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyShell *shell = ephy_shell_get_default ();
g_autoptr (JSCValue) zoom_level_value = NULL;
@@ -734,14 +735,14 @@ tabs_handler_set_zoom (EphyWebExtensionSender *sender,
}
if (!jsc_value_is_number (zoom_level_value)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.setZoom():
Missing zoomFactor.");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.setZoom(): Missing zoomFactor.");
+ return;
}
zoom_level = jsc_value_to_double (zoom_level_value);
if (zoom_level < 0.3 || zoom_level > 5) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.setZoom():
zoomFactor must be between 0.3 and 5.0.");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.setZoom(): zoomFactor must be between 0.3 and 5.0.");
+ return;
}
if (tab_id >= 0)
@@ -750,19 +751,19 @@ tabs_handler_set_zoom (EphyWebExtensionSender *sender,
target_web_view = WEBKIT_WEB_VIEW (ephy_shell_get_active_web_view (shell));
if (!target_web_view) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.setZoom(): Failed
to find tabId %d.", tab_id);
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.setZoom(): Failed to find tabId %d.", tab_id);
+ return;
}
webkit_web_view_set_zoom_level (target_web_view, jsc_value_to_double (zoom_level_value));
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static char *
-tabs_handler_get_zoom (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_get_zoom (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyShell *shell = ephy_shell_get_default ();
g_autoptr (JSCValue) tab_id_value = NULL;
@@ -779,18 +780,18 @@ tabs_handler_get_zoom (EphyWebExtensionSender *sender,
target_web_view = WEBKIT_WEB_VIEW (ephy_shell_get_active_web_view (shell));
if (!target_web_view) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.getZoom(): Failed
to find tabId %d.", tab_id);
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.getZoom(): Failed to find tabId %d.", tab_id);
+ return;
}
- return g_strdup_printf ("%f", webkit_web_view_get_zoom_level (target_web_view));
+ g_task_return_pointer (task, g_strdup_printf ("%f", webkit_web_view_get_zoom_level (target_web_view)),
g_free);
}
-static char *
-tabs_handler_reload (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+tabs_handler_reload (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyShell *shell = ephy_shell_get_default ();
g_autoptr (JSCValue) tab_id_value = NULL;
@@ -807,16 +808,18 @@ tabs_handler_reload (EphyWebExtensionSender *sender,
target_web_view = WEBKIT_WEB_VIEW (ephy_shell_get_active_web_view (shell));
if (!target_web_view) {
- g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.reload(): Failed to
find tabId %d.", tab_id);
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"tabs.reload(): Failed to find tabId %d.", tab_id);
+ return;
}
webkit_web_view_reload (WEBKIT_WEB_VIEW (target_web_view));
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static EphyWebExtensionSyncApiHandler tabs_sync_handlers[] = {
+static EphyWebExtensionAsyncApiHandler tab_async_handlers[] = {
+ {"executeScript", tabs_handler_execute_script},
+ {"sendMessage", tabs_handler_send_message},
{"create", tabs_handler_create},
{"query", tabs_handler_query},
{"insertCSS", tabs_handler_insert_css},
@@ -829,35 +832,12 @@ static EphyWebExtensionSyncApiHandler tabs_sync_handlers[] = {
{"reload", tabs_handler_reload},
};
-static EphyWebExtensionAsyncApiHandler tab_async_handlers[] = {
- {"executeScript", tabs_handler_execute_script},
- {"sendMessage", tabs_handler_send_message},
-};
-
void
ephy_web_extension_api_tabs_handler (EphyWebExtensionSender *sender,
char *name,
JSCValue *args,
GTask *task)
{
- g_autoptr (GError) error = NULL;
-
- for (guint idx = 0; idx < G_N_ELEMENTS (tabs_sync_handlers); idx++) {
- EphyWebExtensionSyncApiHandler handler = tabs_sync_handlers[idx];
- char *ret;
-
- if (g_strcmp0 (handler.name, name) == 0) {
- ret = handler.execute (sender, name, args, &error);
-
- if (error)
- g_task_return_error (task, g_steal_pointer (&error));
- else
- g_task_return_pointer (task, ret, g_free);
-
- return;
- }
- }
-
for (guint idx = 0; idx < G_N_ELEMENTS (tab_async_handlers); idx++) {
EphyWebExtensionAsyncApiHandler handler = tab_async_handlers[idx];
@@ -868,6 +848,5 @@ ephy_web_extension_api_tabs_handler (EphyWebExtensionSender *sender,
}
g_warning ("%s(): '%s' not implemented by Epiphany!", __FUNCTION__, name);
- error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not Implemented");
- g_task_return_error (task, g_steal_pointer (&error));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not
Implemented");
}
diff --git a/src/webextension/api/windows.c b/src/webextension/api/windows.c
index 4d131a6ca..850a1d2e4 100644
--- a/src/webextension/api/windows.c
+++ b/src/webextension/api/windows.c
@@ -126,11 +126,11 @@ ephy_web_extension_api_windows_create_window_json (EphyWebExtension *extension,
}
-static char *
-windows_handler_get (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+windows_handler_get (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
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);
@@ -140,15 +140,15 @@ windows_handler_get (EphyWebExtensionSender *sender,
gboolean populate_tabs = FALSE;
if (!jsc_value_is_number (window_id_value)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "window.get():
First argument is not a windowId");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "window.get():
First argument is not a windowId");
+ return;
}
window = ephy_web_extension_api_windows_get_window_for_id (jsc_value_to_int32 (window_id_value));
if (!window) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "window.get():
Failed to find window by id");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "window.get():
Failed to find window by id");
+ return;
}
if (jsc_value_is_object (get_info_value)) {
@@ -158,14 +158,14 @@ windows_handler_get (EphyWebExtensionSender *sender,
add_window_to_json (sender->extension, builder, window, populate_tabs);
root = json_builder_get_root (builder);
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
-static char *
-windows_handler_get_current (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+windows_handler_get_current (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
EphyWebExtensionManager *manager = ephy_web_extension_manager_get_default ();
g_autoptr (JSCValue) get_info_value = jsc_value_object_get_property_at_index (args, 0);
@@ -186,14 +186,14 @@ windows_handler_get_current (EphyWebExtensionSender *sender,
add_window_to_json (sender->extension, builder, window, populate_tabs);
root = json_builder_get_root (builder);
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
-static char *
-windows_handler_get_last_focused (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+windows_handler_get_last_focused (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) get_info_value = jsc_value_object_get_property_at_index (args, 0);
g_autoptr (JsonBuilder) builder = json_builder_new ();
@@ -210,14 +210,14 @@ windows_handler_get_last_focused (EphyWebExtensionSender *sender,
add_window_to_json (sender->extension, builder, window, populate_tabs);
root = json_builder_get_root (builder);
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
-static char *
-windows_handler_get_all (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+windows_handler_get_all (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) get_info_value = jsc_value_object_get_property_at_index (args, 0);
g_autoptr (JsonBuilder) builder = json_builder_new ();
@@ -241,7 +241,7 @@ windows_handler_get_all (EphyWebExtensionSender *sender,
json_builder_end_array (builder);
root = json_builder_get_root (builder);
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
static GPtrArray *
@@ -278,11 +278,11 @@ get_url_property (JSCValue *object)
return urls;
}
-static char *
-windows_handler_create (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+windows_handler_create (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) create_data_value = jsc_value_object_get_property_at_index (args, 0);
g_autoptr (GPtrArray) urls = NULL;
@@ -307,36 +307,36 @@ windows_handler_create (EphyWebExtensionSender *sender,
add_window_to_json (sender->extension, builder, window, TRUE);
root = json_builder_get_root (builder);
- return json_to_string (root, FALSE);
+ g_task_return_pointer (task, json_to_string (root, FALSE), g_free);
}
-static char *
-windows_handler_remove (EphyWebExtensionSender *sender,
- char *name,
- JSCValue *args,
- GError **error)
+static void
+windows_handler_remove (EphyWebExtensionSender *sender,
+ char *name,
+ JSCValue *args,
+ GTask *task)
{
g_autoptr (JSCValue) window_id_value = jsc_value_object_get_property_at_index (args, 0);
EphyWindow *window;
if (!jsc_value_is_number (window_id_value)) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "window.remove():
First argument is not a windowId");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"window.remove(): First argument is not a windowId");
+ return;
}
window = ephy_web_extension_api_windows_get_window_for_id (jsc_value_to_int32 (window_id_value));
if (!window) {
- g_set_error_literal (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "window.remove():
Failed to find window by id");
- return NULL;
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT,
"window.remove(): Failed to find window by id");
+ return;
}
/* We could use `ephy_window_close()` here but it will do a blocking prompt to the user which I don't
believe is expected. */
gtk_widget_destroy (GTK_WIDGET (window));
- return NULL;
+ g_task_return_pointer (task, NULL, NULL);
}
-static EphyWebExtensionSyncApiHandler windows_handlers[] = {
+static EphyWebExtensionAsyncApiHandler windows_handlers[] = {
{"get", windows_handler_get},
{"getCurrent", windows_handler_get_current},
{"getLastFocused", windows_handler_get_last_focused},
@@ -351,26 +351,14 @@ ephy_web_extension_api_windows_handler (EphyWebExtensionSender *sender,
JSCValue *args,
GTask *task)
{
- g_autoptr (GError) error = NULL;
- guint idx;
-
- for (idx = 0; idx < G_N_ELEMENTS (windows_handlers); idx++) {
- EphyWebExtensionSyncApiHandler handler = windows_handlers[idx];
- char *ret;
+ for (guint idx = 0; idx < G_N_ELEMENTS (windows_handlers); idx++) {
+ EphyWebExtensionAsyncApiHandler handler = windows_handlers[idx];
if (g_strcmp0 (handler.name, name) == 0) {
- ret = handler.execute (sender, name, args, &error);
-
- if (error)
- g_task_return_error (task, g_steal_pointer (&error));
- else
- g_task_return_pointer (task, ret, g_free);
-
+ handler.execute (sender, name, args, task);
return;
}
}
- g_warning ("%s(): '%s' not implemented by Epiphany!", __FUNCTION__, name);
- error = g_error_new_literal (WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "Not Implemented");
- g_task_return_error (task, g_steal_pointer (&error));
+ g_task_return_new_error (task, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_NOT_IMPLEMENTED, "windows.%s():
Not Implemented", name);
}
diff --git a/src/webextension/ephy-web-extension.h b/src/webextension/ephy-web-extension.h
index 7692de4eb..c9f470a91 100644
--- a/src/webextension/ephy-web-extension.h
+++ b/src/webextension/ephy-web-extension.h
@@ -85,11 +85,6 @@ typedef struct {
executeTaskHandler execute;
} EphyWebExtensionAsyncApiHandler;
-typedef struct {
- char *name;
- executeHandler execute;
-} EphyWebExtensionSyncApiHandler;
-
GdkPixbuf *ephy_web_extension_get_icon (EphyWebExtension *self,
gint64 size);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]