[epiphany/pgriffis/web-extension/windows: 3/8] WebExtensions: Implement windows.getLastFocused()




commit 0590d9b9835fbac764d6ab0bc6816eac540d02b6
Author: Patrick Griffis <pgriffis igalia com>
Date:   Tue Jun 7 14:51:29 2022 -0500

    WebExtensions: Implement windows.getLastFocused()

 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 8abbfbbdf..88828e0ea 100644
--- a/src/webextension/api/windows.c
+++ b/src/webextension/api/windows.c
@@ -178,9 +178,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


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