browser-plugin: Set the 'enabled-extensions' GSettings key directly
This way, we won't have to shuttle over DBus if we want to set an extension's status outside of a GNOME Shell session. https://bugzilla.gnome.org/show_bug.cgi?id=676837
This commit is contained in:
parent
ba4b9f229e
commit
9d3750b9b8
@ -267,6 +267,7 @@ typedef struct {
|
|||||||
NPObject parent;
|
NPObject parent;
|
||||||
NPP instance;
|
NPP instance;
|
||||||
GDBusProxy *proxy;
|
GDBusProxy *proxy;
|
||||||
|
GSettings *settings;
|
||||||
NPObject *listener;
|
NPObject *listener;
|
||||||
NPObject *restart_listener;
|
NPObject *restart_listener;
|
||||||
gint signal_id;
|
gint signal_id;
|
||||||
@ -323,6 +324,9 @@ on_shell_appeared (GDBusConnection *connection,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SHELL_SCHEMA "org.gnome.shell"
|
||||||
|
#define ENABLED_EXTENSIONS_KEY "enabled-extensions"
|
||||||
|
|
||||||
static NPObject *
|
static NPObject *
|
||||||
plugin_object_allocate (NPP instance,
|
plugin_object_allocate (NPP instance,
|
||||||
NPClass *klass)
|
NPClass *klass)
|
||||||
@ -332,6 +336,7 @@ plugin_object_allocate (NPP instance,
|
|||||||
|
|
||||||
obj->instance = instance;
|
obj->instance = instance;
|
||||||
obj->proxy = g_object_ref (data->proxy);
|
obj->proxy = g_object_ref (data->proxy);
|
||||||
|
obj->settings = g_settings_new (SHELL_SCHEMA);
|
||||||
obj->signal_id = g_signal_connect (obj->proxy, "g-signal",
|
obj->signal_id = g_signal_connect (obj->proxy, "g-signal",
|
||||||
G_CALLBACK (on_shell_signal), obj);
|
G_CALLBACK (on_shell_signal), obj);
|
||||||
|
|
||||||
@ -492,25 +497,53 @@ plugin_enable_extension (PluginObject *obj,
|
|||||||
NPString uuid,
|
NPString uuid,
|
||||||
gboolean enabled)
|
gboolean enabled)
|
||||||
{
|
{
|
||||||
|
gboolean ret;
|
||||||
gchar *uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
|
gchar *uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
|
||||||
|
gsize length;
|
||||||
|
gchar **uuids;
|
||||||
|
const gchar **new_uuids;
|
||||||
|
|
||||||
if (!uuid_is_valid (uuid_str))
|
if (!uuid_is_valid (uuid_str))
|
||||||
{
|
{
|
||||||
g_free (uuid_str);
|
g_free (uuid_str);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_dbus_proxy_call (obj->proxy,
|
uuids = g_settings_get_strv (obj->settings, ENABLED_EXTENSIONS_KEY);
|
||||||
(enabled ? "EnableExtension" : "DisableExtension"),
|
length = g_strv_length (uuids);
|
||||||
g_variant_new ("(s)", uuid_str),
|
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
|
||||||
-1, /* timeout */
|
|
||||||
NULL, /* cancellable */
|
|
||||||
NULL, /* callback */
|
|
||||||
NULL /* user_data */);
|
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
new_uuids = g_new (const gchar *, length + 2); /* New key, NULL */
|
||||||
|
memcpy (new_uuids, uuids, length);
|
||||||
|
new_uuids[length - 2] = uuid_str;
|
||||||
|
new_uuids[length - 1] = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gsize i = 0, j = 0;
|
||||||
|
new_uuids = g_new (const gchar *, length);
|
||||||
|
for (i = 0; i < length; i ++)
|
||||||
|
{
|
||||||
|
if (g_str_equal (uuids[i], uuid_str))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
new_uuids[j] = uuids[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_uuids[j] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = g_settings_set_strv (obj->settings,
|
||||||
|
ENABLED_EXTENSIONS_KEY,
|
||||||
|
new_uuids);
|
||||||
|
|
||||||
|
g_strfreev (uuids);
|
||||||
|
g_free (new_uuids);
|
||||||
g_free (uuid_str);
|
g_free (uuid_str);
|
||||||
|
|
||||||
return TRUE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
Loading…
x
Reference in New Issue
Block a user