From 831099cca5468f5fe6cca8e1949d8b00d598ad8d Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 18 Jan 2012 21:30:06 -0500 Subject: [PATCH] browser-plugin: Provide new APIs for launching extension preferences Add two new APIs, "launchExtensionPrefs" to let SweetTooth let the user launch the extension preferences tool directly from the browser. To allow SweetTooth to check if an extension can be configured, add a new key to the 'metadata', 'hasPrefs', which is returned by the GetExtensionInfo/ ListExtensions DBus methods. https://bugzilla.gnome.org/show_bug.cgi?id=668429 --- browser-plugin/browser-plugin.c | 42 +++++++++++++++++++++++++++++++-- js/misc/extensionUtils.js | 1 + js/ui/shellDBus.js | 14 +++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/browser-plugin/browser-plugin.c b/browser-plugin/browser-plugin.c index d2685887e..8f7e87696 100644 --- a/browser-plugin/browser-plugin.c +++ b/browser-plugin/browser-plugin.c @@ -41,7 +41,7 @@ "It can be used only by extensions.gnome.org" #define PLUGIN_MIME_STRING "application/x-gnome-shell-integration::Gnome Shell Integration Dummy Content-Type"; -#define PLUGIN_API_VERSION 2 +#define PLUGIN_API_VERSION 3 typedef struct { GDBusProxy *proxy; @@ -375,6 +375,7 @@ static NPIdentifier uninstall_extension_id; static NPIdentifier onextension_changed_id; static NPIdentifier onrestart_id; static NPIdentifier get_errors_id; +static NPIdentifier launch_extension_prefs_id; static bool plugin_object_has_method (NPObject *npobj, @@ -385,7 +386,8 @@ plugin_object_has_method (NPObject *npobj, name == enable_extension_id || name == install_extension_id || name == uninstall_extension_id || - name == get_errors_id); + name == get_errors_id || + name == launch_extension_prefs_id); } static inline gboolean @@ -652,6 +654,33 @@ plugin_get_errors (PluginObject *obj, return jsonify_variant (res, result); } +static gboolean +plugin_launch_extension_prefs (PluginObject *obj, + NPString uuid, + NPVariant *result) +{ + gchar *uuid_str; + + uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length); + if (!uuid_is_valid (uuid_str)) + { + g_free (uuid_str); + return FALSE; + } + + g_dbus_proxy_call (obj->proxy, + "LaunchExtensionPrefs", + g_variant_new ("(s)", uuid_str), + G_DBUS_CALL_FLAGS_NONE, + -1, /* timeout */ + NULL, /* cancellable */ + NULL, /* callback */ + NULL /* user_data */); + + g_free (uuid_str); + return TRUE; +} + static int plugin_get_api_version (PluginObject *obj, NPVariant *result) @@ -762,6 +791,14 @@ plugin_object_invoke (NPObject *npobj, NPVARIANT_TO_STRING(args[0]), result); } + else if (name == launch_extension_prefs_id) + { + if (!NPVARIANT_IS_STRING(args[0])) return FALSE; + + return plugin_launch_extension_prefs (obj, + NPVARIANT_TO_STRING(args[0]), + result); + } return TRUE; } @@ -876,6 +913,7 @@ init_methods_and_properties (void) install_extension_id = funcs.getstringidentifier ("installExtension"); uninstall_extension_id = funcs.getstringidentifier ("uninstallExtension"); get_errors_id = funcs.getstringidentifier ("getExtensionErrors"); + launch_extension_prefs_id = funcs.getstringidentifier ("launchExtensionPrefs"); onrestart_id = funcs.getstringidentifier ("onshellrestart"); onextension_changed_id = funcs.getstringidentifier ("onchange"); diff --git a/js/misc/extensionUtils.js b/js/misc/extensionUtils.js index 3ff0b22d6..7c2120bb5 100644 --- a/js/misc/extensionUtils.js +++ b/js/misc/extensionUtils.js @@ -99,6 +99,7 @@ function loadMetadata(uuid, dir, type) { meta.dir = dir; meta.path = dir.get_path(); meta.error = ''; + meta.hasPrefs = dir.get_child('prefs.js').query_exists(null); return meta; } diff --git a/js/ui/shellDBus.js b/js/ui/shellDBus.js index 779a173b1..d3daf4b96 100644 --- a/js/ui/shellDBus.js +++ b/js/ui/shellDBus.js @@ -3,6 +3,7 @@ const Lang = imports.lang; const Gio = imports.gi.Gio; const GLib = imports.gi.GLib; +const Shell = imports.gi.Shell; const Config = imports.misc.config; const ExtensionSystem = imports.ui.extensionSystem; @@ -60,6 +61,9 @@ const GnomeShellIface = + + + @@ -198,6 +202,9 @@ const GnomeShell = new Lang.Class({ case 'number': type = 'd'; break; + case 'boolean': + type = 'b'; + break; default: continue; } @@ -232,6 +239,13 @@ const GnomeShell = new Lang.Class({ return ExtensionSystem.uninstallExtensionFromUUID(uuid); }, + LaunchExtensionPrefs: function(uuid) { + let appSys = Shell.AppSystem.get_default(); + let app = appSys.lookup_app('gnome-shell-extension-prefs.desktop'); + app.launch(global.display.get_current_time_roundtrip(), + ['extension:///' + uuid], -1, null); + }, + get OverviewActive() { return Main.overview.visible; },