From 4ae2a0b2a5ff58bbbdf4e72870fdac4569b6d7c8 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 14 Oct 2011 17:58:23 -0400 Subject: [PATCH] extensionSystem: Only load importers for enabled extensions Rather than loading and enabling all extensions at Shell init time, save some time and gain some basic security by not loading extensions if they're not enabled. https://bugzilla.gnome.org/show_bug.cgi?id=661815 --- js/ui/extensionSystem.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index f31f2b48c..c30da01cc 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -62,6 +62,9 @@ const extensionMeta = {}; const extensions = {}; // Maps uuid -> extension state object (returned from init()) const extensionStateObjs = {}; +// Maps uuid -> [GFile to the extension directory, Extension type] +const extensionDirs = {}; + // Arrays of uuids var enabledExtensions; // GFile for user extensions @@ -225,8 +228,13 @@ function disableExtension(uuid) { function enableExtension(uuid) { let meta = extensionMeta[uuid]; - if (!meta) + if (!meta) { + if (extensionDirs[uuid]) { + let [dir, type] = extensionDirs[uuid]; + loadExtension(dir, type); + } return; + } if (meta.state != ExtensionState.DISABLED) return; @@ -254,7 +262,7 @@ function logExtensionError(uuid, message, state) { state: state }); } -function loadExtension(dir, enabled, type) { +function loadExtension(dir, type) { let info; let uuid = dir.get_basename(); @@ -383,8 +391,7 @@ function loadExtension(dir, enabled, type) { meta.state = ExtensionState.DISABLED; - if (enabled) - enableExtension(uuid); + enableExtension(uuid); _signals.emit('extension-loaded', meta.uuid); _signals.emit('extension-state-changed', meta); @@ -444,7 +451,9 @@ function _loadExtensionsIn(dir, type) { let name = info.get_name(); let child = dir.get_child(name); let enabled = enabledExtensions.indexOf(name) != -1; - loadExtension(child, enabled, type); + extensionDirs[name] = [dir, type]; + if (enabled) + loadExtension(child, type); } fileEnum.close(null); }