[epiphany/pgriffis/web-extension/windows: 6/9] WebExtensions: Implement windows.remove()
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/pgriffis/web-extension/windows: 6/9] WebExtensions: Implement windows.remove()
- Date: Wed, 8 Jun 2022 20:17:16 +0000 (UTC)
commit b06d2a7cc841cfc97d653d8cf8bcab3ceb746e38
Author: Patrick Griffis <pgriffis igalia com>
Date: Wed Jun 8 10:50:47 2022 -0500
WebExtensions: Implement windows.remove()
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1137>
src/webextension/api/windows.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
---
diff --git a/src/webextension/api/windows.c b/src/webextension/api/windows.c
index 39721b39d..2aee91dc7 100644
--- a/src/webextension/api/windows.c
+++ b/src/webextension/api/windows.c
@@ -234,11 +234,41 @@ windows_handler_get_all (EphyWebExtension *self,
return json_to_string (root, FALSE);
}
+static char *
+windows_handler_remove (EphyWebExtension *self,
+ char *name,
+ JSCValue *args,
+ WebKitWebView *web_view,
+ GError **error)
+{
+ g_autoptr (JSCValue) window_id_value = jsc_value_object_get_property_at_index (args, 0);
+ EphyWindow *window;
+ int window_id;
+
+ 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;
+ }
+
+ window_id = jsc_value_to_int32 (window_id_value);
+ window = get_window_for_id (window_id);
+
+ 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;
+ }
+
+ /* 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;
+}
+
static EphyWebExtensionSyncApiHandler windows_handlers[] = {
{"get", windows_handler_get},
{"getCurrent", windows_handler_get_current},
{"getLastFocused", windows_handler_get_last_focused},
{"getAll", windows_handler_get_all},
+ {"remove", windows_handler_remove},
};
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]