[geary/mjog/user-plugins: 11/26] Application.PluginManager: Add notion of trusted plugins
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/user-plugins: 11/26] Application.PluginManager: Add notion of trusted plugins
- Date: Tue, 17 Mar 2020 08:25:09 +0000 (UTC)
commit 25b527fc2b7632bfdcd21e7282bab0ccc86e0e12
Author: Michael Gratton <mike vee net>
Date: Fri Mar 6 08:51:10 2020 +1100
Application.PluginManager: Add notion of trusted plugins
Keep a list of trusted plugins and load those by default, rather than
trusting the peas built-in flag.
.../application/application-plugin-manager.vala | 39 +++++++++++++++-------
.../desktop-notifications.plugin.in | 1 -
.../plugin/messaging-menu/messaging-menu.plugin.in | 1 -
.../notification-badge.plugin.in | 1 -
4 files changed, 27 insertions(+), 15 deletions(-)
---
diff --git a/src/client/application/application-plugin-manager.vala
b/src/client/application/application-plugin-manager.vala
index fd2c7caf..30ab8666 100644
--- a/src/client/application/application-plugin-manager.vala
+++ b/src/client/application/application-plugin-manager.vala
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 Michael Gratton <mike vee net>
+ * Copyright © 2019-2020 Michael Gratton <mike vee net>
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
@@ -11,9 +11,18 @@
public class Application.PluginManager : GLib.Object {
+ // Plugins that will be loaded automatically and trusted with
+ // access to the application if they have been installed
+ private const string[] TRUSTED_MODULES = {
+ "desktop-notifications",
+ "messaging-menu",
+ "notification-badge"
+ };
+
private Client application;
private Peas.Engine engine;
private bool is_shutdown = false;
+ private string trusted_path;
private Peas.ExtensionSet notification_extensions;
private NotificationContext notifications;
@@ -24,8 +33,8 @@ public class Application.PluginManager : GLib.Object {
this.application = application;
this.engine = Peas.Engine.get_default();
- string builtin_path = application.get_app_plugins_dir().get_path();
- this.engine.add_search_path(builtin_path, null);
+ this.trusted_path = application.get_app_plugins_dir().get_path();
+ this.plugins.add_search_path(trusted_path, null);
this.notifications = notifications;
this.notification_extensions = new Peas.ExtensionSet(
@@ -52,9 +61,8 @@ public class Application.PluginManager : GLib.Object {
string name = info.get_module_name();
try {
if (info.is_available()) {
- if (info.is_builtin() &&
- info.get_module_dir().has_prefix(builtin_path)) {
- debug("Loading built-in plugin: %s", name);
+ if (is_trusted(info)) {
+ debug("Loading trusted plugin: %s", name);
this.engine.load_plugin(info);
} else if (name in optional_names) {
debug("Loading optional plugin: %s", name);
@@ -67,12 +75,19 @@ public class Application.PluginManager : GLib.Object {
}
}
- public Gee.List<Peas.PluginInfo> get_optional_plugins() {
+ public inline bool is_trusted(Peas.PluginInfo plugin) {
+ return (
+ plugin.get_module_name() in TRUSTED_MODULES &&
+ plugin.get_module_dir().has_prefix(trusted_path)
+ );
+ }
+
+ public Gee.Collection<Peas.PluginInfo> get_optional_plugins() {
var plugins = new Gee.LinkedList<Peas.PluginInfo>();
foreach (Peas.PluginInfo plugin in this.engine.get_plugin_list()) {
try {
plugin.is_available();
- if (!plugin.is_builtin()) {
+ if (!is_trusted(plugin)) {
plugins.add(plugin);
}
} catch (GLib.Error err) {
@@ -89,8 +104,8 @@ public class Application.PluginManager : GLib.Object {
bool loaded = false;
if (plugin.is_available() &&
!plugin.is_loaded() &&
- !plugin.is_builtin()) {
- this.engine.load_plugin(plugin);
+ !is_trusted(plugin)) {
+ this.plugins.load_plugin(plugin);
loaded = true;
string name = plugin.get_module_name();
string[] optional_names =
@@ -107,8 +122,8 @@ public class Application.PluginManager : GLib.Object {
bool unloaded = false;
if (plugin.is_available() &&
plugin.is_loaded() &&
- !plugin.is_builtin()) {
- this.engine.unload_plugin(plugin);
+ !is_trusted(plugin)) {
+ this.plugins.unload_plugin(plugin);
unloaded = true;
string name = plugin.get_module_name();
string[] old_names =
diff --git a/src/client/plugin/desktop-notifications/desktop-notifications.plugin.in
b/src/client/plugin/desktop-notifications/desktop-notifications.plugin.in
index 6c8c9f39..2019963a 100644
--- a/src/client/plugin/desktop-notifications/desktop-notifications.plugin.in
+++ b/src/client/plugin/desktop-notifications/desktop-notifications.plugin.in
@@ -2,4 +2,3 @@
Module=desktop-notifications
Name=Desktop Notifications
Description=Displays desktop notifications when new email is delivered
-Builtin=true
diff --git a/src/client/plugin/messaging-menu/messaging-menu.plugin.in
b/src/client/plugin/messaging-menu/messaging-menu.plugin.in
index f02a2e78..4668e58d 100644
--- a/src/client/plugin/messaging-menu/messaging-menu.plugin.in
+++ b/src/client/plugin/messaging-menu/messaging-menu.plugin.in
@@ -2,4 +2,3 @@
Module=messaging-menu-geary
Name=Messaging Menu
Description=Displays Unity Messaging Menu notifications for new email
-Builtin=true
diff --git a/src/client/plugin/notification-badge/notification-badge.plugin.in
b/src/client/plugin/notification-badge/notification-badge.plugin.in
index 611ec691..7a729a6a 100644
--- a/src/client/plugin/notification-badge/notification-badge.plugin.in
+++ b/src/client/plugin/notification-badge/notification-badge.plugin.in
@@ -2,4 +2,3 @@
Module=notification-badge
Name=Notification Badge
Description=Displays an application badge showing the number of unread messages
-Builtin=true
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]