From 75d992f46841ded066bb23ebce948334ccae171a Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Tue, 7 Jun 2022 14:51:29 -0500 Subject: WebExtensions: Implement windows.getLastFocused() Part-of: --- src/webextension/api/windows.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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 -- cgit v1.2.1