Преглед на файлове

Add the ability to whitelist/blacklist plugins.

JC Brand преди 8 години
родител
ревизия
ebbde138db
променени са 6 файла, в които са добавени 156 реда и са изтрити 34 реда
  1. 42 9
      dist/converse-mobile.js
  2. 42 9
      dist/converse-no-dependencies.js
  3. 42 9
      dist/converse.js
  4. 1 1
      package.json
  5. 28 5
      src/converse-core.js
  6. 1 1
      src/converse-rosterview.js

+ 42 - 9
dist/converse-mobile.js

@@ -41977,7 +41977,7 @@ define("polyfill", function(){});
     // then the name by which the pluggable object may be referenced on the
     // __super__ object (inside overrides).
     function PluginSocket (plugged, name) {
-        this.name = name; 
+        this.name = name;
         this.plugged = plugged;
         if (typeof this.plugged.__super__ === 'undefined') {
             this.plugged.__super__ = {};
@@ -42125,6 +42125,10 @@ define("polyfill", function(){});
         // `initializePlugin` applies the overrides (if any) defined on all
         // the registered plugins and then calls the initialize method for each plugin.
         initializePlugin: function (plugin) {
+            if (!_.includes(_.keys(this.allowed_plugins), plugin.__name__)) {
+                /* Don't initialize disallowed plugins. */
+                return;
+            }
             if (_.includes(this.initialized_plugins, plugin.__name__)) {
                 /* Don't initialize plugins twice, otherwise we get
                  * infinite recursion in overridden methods.
@@ -42154,12 +42158,18 @@ define("polyfill", function(){});
         // `initializePlugin` for each.
         // The passed in  properties variable is an object with attributes and methods
         // which will be attached to the plugins.
-        initializePlugins: function (properties) {
+        initializePlugins: function (properties, whitelist, blacklist) {
             if (!_.size(this.plugins)) {
                 return;
             }
             this.properties = properties;
-            _.each(_.values(this.plugins), this.initializePlugin.bind(this));
+            this.allowed_plugins  = _.pickBy(this.plugins,
+                function (plugin, key) {
+                    return (whitelist.length && _.includes(whitelist, key)) &&
+                                !_.includes(blacklist, key);
+                }
+            );
+            _.each(_.values(this.allowed_plugins), this.initializePlugin.bind(this));
         }
     });
     return {
@@ -44787,6 +44797,25 @@ return Backbone.BrowserStorage;
     _.extend(_converse, Backbone.Events);
     _converse.emit = _converse.trigger;
 
+    _converse.core_plugins = [
+        'converse-bookmarks',
+        'converse-chatview',
+        'converse-controlbox',
+        'converse-core',
+        'converse-dragresize',
+        'converse-headline',
+        'converse-mam',
+        'converse-minimize',
+        'converse-muc',
+        'converse-muc-embedded',
+        'converse-notification',
+        'converse-otr',
+        'converse-ping',
+        'converse-register',
+        'converse-rosterview',
+        'converse-vcard'
+    ];
+
     // Make converse pluggable
     pluggable.enable(_converse, '_converse', 'pluggable');
 
@@ -44926,7 +44955,8 @@ return Backbone.BrowserStorage;
             auto_reconnect: false,
             auto_subscribe: false,
             auto_xa: 0, // Seconds after which user status is set to 'xa'
-            bosh_service_url: undefined, // The BOSH connection manager URL.
+            blacklisted_plugins: [],
+            bosh_service_url: undefined,
             connection_options: {},
             credentials_url: null, // URL from where login credentials can be fetched
             csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
@@ -44940,10 +44970,9 @@ return Backbone.BrowserStorage;
             jid: undefined,
             keepalive: false,
             locked_domain: undefined,
-            message_carbons: false, // Support for XEP-280
+            message_carbons: false,
             message_storage: 'session',
             password: undefined,
-            prebind: false, // XXX: Deprecated, use "authentication" instead.
             prebind_url: null,
             rid: undefined,
             roster_groups: false,
@@ -44951,8 +44980,9 @@ return Backbone.BrowserStorage;
             sid: undefined,
             storage: 'session',
             strict_plugin_dependencies: false,
-            synchronize_availability: true, // Set to false to not sync with other clients or with resource name of the particular client that it should synchronize with
+            synchronize_availability: true,
             websocket_url: undefined,
+            whitelisted_plugins: [],
             xhr_custom_status: false,
             xhr_custom_status_url: '',
         };
@@ -46712,10 +46742,13 @@ return Backbone.BrowserStorage;
         // in any case.
         _converse.pluggable.initialized_plugins = [];
 
+        var whitelist = _converse.core_plugins.concat(_converse.whitelisted_plugins);
+
         _converse.pluggable.initializePlugins({
             'updateSettings': updateSettings,
             '_converse': _converse
-        });
+        }, whitelist, _converse.blacklisted_plugins);
+
         _converse.emit('pluginsInitialized');
         _converse._initialize();
         _converse.registerGlobalEventHandlers();
@@ -49918,7 +49951,7 @@ return __p
         b64_sha1 = converse.env.b64_sha1,
         _ = converse.env._;
 
-    converse.plugins.add('rosterview', {
+    converse.plugins.add('converse-rosterview', {
 
         overrides: {
             // Overrides mentioned here will be picked up by converse.js's

+ 42 - 9
dist/converse-no-dependencies.js

@@ -3450,7 +3450,7 @@ define("polyfill", function(){});
     // then the name by which the pluggable object may be referenced on the
     // __super__ object (inside overrides).
     function PluginSocket (plugged, name) {
-        this.name = name; 
+        this.name = name;
         this.plugged = plugged;
         if (typeof this.plugged.__super__ === 'undefined') {
             this.plugged.__super__ = {};
@@ -3598,6 +3598,10 @@ define("polyfill", function(){});
         // `initializePlugin` applies the overrides (if any) defined on all
         // the registered plugins and then calls the initialize method for each plugin.
         initializePlugin: function (plugin) {
+            if (!_.includes(_.keys(this.allowed_plugins), plugin.__name__)) {
+                /* Don't initialize disallowed plugins. */
+                return;
+            }
             if (_.includes(this.initialized_plugins, plugin.__name__)) {
                 /* Don't initialize plugins twice, otherwise we get
                  * infinite recursion in overridden methods.
@@ -3627,12 +3631,18 @@ define("polyfill", function(){});
         // `initializePlugin` for each.
         // The passed in  properties variable is an object with attributes and methods
         // which will be attached to the plugins.
-        initializePlugins: function (properties) {
+        initializePlugins: function (properties, whitelist, blacklist) {
             if (!_.size(this.plugins)) {
                 return;
             }
             this.properties = properties;
-            _.each(_.values(this.plugins), this.initializePlugin.bind(this));
+            this.allowed_plugins  = _.pickBy(this.plugins,
+                function (plugin, key) {
+                    return (whitelist.length && _.includes(whitelist, key)) &&
+                                !_.includes(blacklist, key);
+                }
+            );
+            _.each(_.values(this.allowed_plugins), this.initializePlugin.bind(this));
         }
     });
     return {
@@ -3710,6 +3720,25 @@ define("polyfill", function(){});
     _.extend(_converse, Backbone.Events);
     _converse.emit = _converse.trigger;
 
+    _converse.core_plugins = [
+        'converse-bookmarks',
+        'converse-chatview',
+        'converse-controlbox',
+        'converse-core',
+        'converse-dragresize',
+        'converse-headline',
+        'converse-mam',
+        'converse-minimize',
+        'converse-muc',
+        'converse-muc-embedded',
+        'converse-notification',
+        'converse-otr',
+        'converse-ping',
+        'converse-register',
+        'converse-rosterview',
+        'converse-vcard'
+    ];
+
     // Make converse pluggable
     pluggable.enable(_converse, '_converse', 'pluggable');
 
@@ -3849,7 +3878,8 @@ define("polyfill", function(){});
             auto_reconnect: false,
             auto_subscribe: false,
             auto_xa: 0, // Seconds after which user status is set to 'xa'
-            bosh_service_url: undefined, // The BOSH connection manager URL.
+            blacklisted_plugins: [],
+            bosh_service_url: undefined,
             connection_options: {},
             credentials_url: null, // URL from where login credentials can be fetched
             csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
@@ -3863,10 +3893,9 @@ define("polyfill", function(){});
             jid: undefined,
             keepalive: false,
             locked_domain: undefined,
-            message_carbons: false, // Support for XEP-280
+            message_carbons: false,
             message_storage: 'session',
             password: undefined,
-            prebind: false, // XXX: Deprecated, use "authentication" instead.
             prebind_url: null,
             rid: undefined,
             roster_groups: false,
@@ -3874,8 +3903,9 @@ define("polyfill", function(){});
             sid: undefined,
             storage: 'session',
             strict_plugin_dependencies: false,
-            synchronize_availability: true, // Set to false to not sync with other clients or with resource name of the particular client that it should synchronize with
+            synchronize_availability: true,
             websocket_url: undefined,
+            whitelisted_plugins: [],
             xhr_custom_status: false,
             xhr_custom_status_url: '',
         };
@@ -5635,10 +5665,13 @@ define("polyfill", function(){});
         // in any case.
         _converse.pluggable.initialized_plugins = [];
 
+        var whitelist = _converse.core_plugins.concat(_converse.whitelisted_plugins);
+
         _converse.pluggable.initializePlugins({
             'updateSettings': updateSettings,
             '_converse': _converse
-        });
+        }, whitelist, _converse.blacklisted_plugins);
+
         _converse.emit('pluginsInitialized');
         _converse._initialize();
         _converse.registerGlobalEventHandlers();
@@ -8736,7 +8769,7 @@ return __p
         b64_sha1 = converse.env.b64_sha1,
         _ = converse.env._;
 
-    converse.plugins.add('rosterview', {
+    converse.plugins.add('converse-rosterview', {
 
         overrides: {
             // Overrides mentioned here will be picked up by converse.js's

+ 42 - 9
dist/converse.js

@@ -41977,7 +41977,7 @@ define("polyfill", function(){});
     // then the name by which the pluggable object may be referenced on the
     // __super__ object (inside overrides).
     function PluginSocket (plugged, name) {
-        this.name = name; 
+        this.name = name;
         this.plugged = plugged;
         if (typeof this.plugged.__super__ === 'undefined') {
             this.plugged.__super__ = {};
@@ -42125,6 +42125,10 @@ define("polyfill", function(){});
         // `initializePlugin` applies the overrides (if any) defined on all
         // the registered plugins and then calls the initialize method for each plugin.
         initializePlugin: function (plugin) {
+            if (!_.includes(_.keys(this.allowed_plugins), plugin.__name__)) {
+                /* Don't initialize disallowed plugins. */
+                return;
+            }
             if (_.includes(this.initialized_plugins, plugin.__name__)) {
                 /* Don't initialize plugins twice, otherwise we get
                  * infinite recursion in overridden methods.
@@ -42154,12 +42158,18 @@ define("polyfill", function(){});
         // `initializePlugin` for each.
         // The passed in  properties variable is an object with attributes and methods
         // which will be attached to the plugins.
-        initializePlugins: function (properties) {
+        initializePlugins: function (properties, whitelist, blacklist) {
             if (!_.size(this.plugins)) {
                 return;
             }
             this.properties = properties;
-            _.each(_.values(this.plugins), this.initializePlugin.bind(this));
+            this.allowed_plugins  = _.pickBy(this.plugins,
+                function (plugin, key) {
+                    return (whitelist.length && _.includes(whitelist, key)) &&
+                                !_.includes(blacklist, key);
+                }
+            );
+            _.each(_.values(this.allowed_plugins), this.initializePlugin.bind(this));
         }
     });
     return {
@@ -44787,6 +44797,25 @@ return Backbone.BrowserStorage;
     _.extend(_converse, Backbone.Events);
     _converse.emit = _converse.trigger;
 
+    _converse.core_plugins = [
+        'converse-bookmarks',
+        'converse-chatview',
+        'converse-controlbox',
+        'converse-core',
+        'converse-dragresize',
+        'converse-headline',
+        'converse-mam',
+        'converse-minimize',
+        'converse-muc',
+        'converse-muc-embedded',
+        'converse-notification',
+        'converse-otr',
+        'converse-ping',
+        'converse-register',
+        'converse-rosterview',
+        'converse-vcard'
+    ];
+
     // Make converse pluggable
     pluggable.enable(_converse, '_converse', 'pluggable');
 
@@ -44926,7 +44955,8 @@ return Backbone.BrowserStorage;
             auto_reconnect: false,
             auto_subscribe: false,
             auto_xa: 0, // Seconds after which user status is set to 'xa'
-            bosh_service_url: undefined, // The BOSH connection manager URL.
+            blacklisted_plugins: [],
+            bosh_service_url: undefined,
             connection_options: {},
             credentials_url: null, // URL from where login credentials can be fetched
             csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
@@ -44940,10 +44970,9 @@ return Backbone.BrowserStorage;
             jid: undefined,
             keepalive: false,
             locked_domain: undefined,
-            message_carbons: false, // Support for XEP-280
+            message_carbons: false,
             message_storage: 'session',
             password: undefined,
-            prebind: false, // XXX: Deprecated, use "authentication" instead.
             prebind_url: null,
             rid: undefined,
             roster_groups: false,
@@ -44951,8 +44980,9 @@ return Backbone.BrowserStorage;
             sid: undefined,
             storage: 'session',
             strict_plugin_dependencies: false,
-            synchronize_availability: true, // Set to false to not sync with other clients or with resource name of the particular client that it should synchronize with
+            synchronize_availability: true,
             websocket_url: undefined,
+            whitelisted_plugins: [],
             xhr_custom_status: false,
             xhr_custom_status_url: '',
         };
@@ -46712,10 +46742,13 @@ return Backbone.BrowserStorage;
         // in any case.
         _converse.pluggable.initialized_plugins = [];
 
+        var whitelist = _converse.core_plugins.concat(_converse.whitelisted_plugins);
+
         _converse.pluggable.initializePlugins({
             'updateSettings': updateSettings,
             '_converse': _converse
-        });
+        }, whitelist, _converse.blacklisted_plugins);
+
         _converse.emit('pluginsInitialized');
         _converse._initialize();
         _converse.registerGlobalEventHandlers();
@@ -49918,7 +49951,7 @@ return __p
         b64_sha1 = converse.env.b64_sha1,
         _ = converse.env._;
 
-    converse.plugins.add('rosterview', {
+    converse.plugins.add('converse-rosterview', {
 
         overrides: {
             // Overrides mentioned here will be picked up by converse.js's

+ 1 - 1
package.json

@@ -59,7 +59,7 @@
     "otr": "0.2.16",
     "phantom-jasmine": "0.1.8",
     "phantomjs": "~1.9.7-1",
-    "pluggable.js": "https://github.com/jcbrand/pluggable.js.git#d5679e907bfbc8e673f7fa23e75f21cb4a26ae57",
+    "pluggable.js": "https://github.com/jcbrand/pluggable.js.git#078e8898b26954d0744f3e41b894b870675f17e7",
     "po2json": "^0.4.4",
     "requirejs": "2.3.2",
     "snyk": "^1.21.2",

+ 28 - 5
src/converse-core.js

@@ -48,6 +48,25 @@
     _.extend(_converse, Backbone.Events);
     _converse.emit = _converse.trigger;
 
+    _converse.core_plugins = [
+        'converse-bookmarks',
+        'converse-chatview',
+        'converse-controlbox',
+        'converse-core',
+        'converse-dragresize',
+        'converse-headline',
+        'converse-mam',
+        'converse-minimize',
+        'converse-muc',
+        'converse-muc-embedded',
+        'converse-notification',
+        'converse-otr',
+        'converse-ping',
+        'converse-register',
+        'converse-rosterview',
+        'converse-vcard'
+    ];
+
     // Make converse pluggable
     pluggable.enable(_converse, '_converse', 'pluggable');
 
@@ -187,7 +206,8 @@
             auto_reconnect: false,
             auto_subscribe: false,
             auto_xa: 0, // Seconds after which user status is set to 'xa'
-            bosh_service_url: undefined, // The BOSH connection manager URL.
+            blacklisted_plugins: [],
+            bosh_service_url: undefined,
             connection_options: {},
             credentials_url: null, // URL from where login credentials can be fetched
             csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
@@ -201,10 +221,9 @@
             jid: undefined,
             keepalive: false,
             locked_domain: undefined,
-            message_carbons: false, // Support for XEP-280
+            message_carbons: false,
             message_storage: 'session',
             password: undefined,
-            prebind: false, // XXX: Deprecated, use "authentication" instead.
             prebind_url: null,
             rid: undefined,
             roster_groups: false,
@@ -212,8 +231,9 @@
             sid: undefined,
             storage: 'session',
             strict_plugin_dependencies: false,
-            synchronize_availability: true, // Set to false to not sync with other clients or with resource name of the particular client that it should synchronize with
+            synchronize_availability: true,
             websocket_url: undefined,
+            whitelisted_plugins: [],
             xhr_custom_status: false,
             xhr_custom_status_url: '',
         };
@@ -1973,10 +1993,13 @@
         // in any case.
         _converse.pluggable.initialized_plugins = [];
 
+        var whitelist = _converse.core_plugins.concat(_converse.whitelisted_plugins);
+
         _converse.pluggable.initializePlugins({
             'updateSettings': updateSettings,
             '_converse': _converse
-        });
+        }, whitelist, _converse.blacklisted_plugins);
+
         _converse.emit('pluginsInitialized');
         _converse._initialize();
         _converse.registerGlobalEventHandlers();

+ 1 - 1
src/converse-rosterview.js

@@ -30,7 +30,7 @@
         b64_sha1 = converse.env.b64_sha1,
         _ = converse.env._;
 
-    converse.plugins.add('rosterview', {
+    converse.plugins.add('converse-rosterview', {
 
         overrides: {
             // Overrides mentioned here will be picked up by converse.js's