summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Griffis <pgriffis@igalia.com>2022-06-07 14:51:29 -0500
committerPatrick Griffis <pgriffis@igalia.com>2022-06-08 15:13:59 -0500
commit75d992f46841ded066bb23ebce948334ccae171a (patch)
treeb924ead1fcf2f33cc23f5fd7a22c203087546522
parentb80306e89a5c8556ddb9396e9f001e1f9c2d382d (diff)
downloadepiphany-75d992f46841ded066bb23ebce948334ccae171a.tar.gz
WebExtensions: Implement windows.getLastFocused()
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1137>
-rw-r--r--src/webextension/api/windows.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/webextension/api/windows.c b/src/webextension/api/windows.c
index 68436fb60..60c9e2804 100644
--- a/src/webextension/api/windows.c
+++ b/src/webextension/api/windows.c
@@ -177,9 +177,35 @@ windows_handler_get_current (EphyWebExtension *self,
return json_to_string (root, FALSE);
}
+static char *
+windows_handler_get_last_focused (EphyWebExtension *self,
+ char *name,
+ JSCValue *args,
+ WebKitWebView *web_view,
+ GError **error)
+{
+ g_autoptr (JSCValue) get_info_value = jsc_value_object_get_property_at_index (args, 0);
+ g_autoptr (JsonBuilder) builder = json_builder_new ();
+ g_autoptr (JsonNode) root = NULL;
+ gboolean populate_tabs = FALSE;
+ EphyWindow *window;
+
+ window = EPHY_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (ephy_shell_get_default ())));
+
+ 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);
+ root = json_builder_get_root (builder);
+ return json_to_string (root, FALSE);
+}
+
static EphyWebExtensionSyncApiHandler windows_handlers[] = {
{"get", windows_handler_get},
{"getCurrent", windows_handler_get_current},
+ {"getLastFocused", windows_handler_get_last_focused},
};
void