From 2a8fdc0a608eadc21e9df607734b500ac7f17f4b Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Tue, 24 Mar 2015 11:02:32 +0000 Subject: [PATCH] Bug 10280: Don't load any plugins into the address space. If the pref plugin.disable is set, the user has to click an extra button to cause Firefox to actually scan the filesystem for plugins. Note: The strings for this patch are actually present in Torbutton. Patch by 'disgleirio'. --- dom/plugins/base/nsPluginHost.cpp | 11 +++ toolkit/mozapps/extensions/AddonManager.jsm | 5 ++ .../mozapps/extensions/content/extensions.js | 68 +++++++++++++++++++ .../mozapps/extensions/content/extensions.xul | 4 ++ .../extensions/internal/PluginProvider.jsm | 8 +++ 5 files changed, 96 insertions(+) diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp index 83363764b642a..cd1707beaf5f6 100644 --- a/dom/plugins/base/nsPluginHost.cpp +++ b/dom/plugins/base/nsPluginHost.cpp @@ -3588,6 +3588,7 @@ NS_IMETHODIMP nsPluginHost::Observe(nsISupports *aSubject, sInst->Release(); } if (!strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic)) { + NS_ConvertUTF16toUTF8 prefName(someData); mPluginsDisabled = Preferences::GetBool("plugin.disable", false); // Unload or load plugins as needed if (mPluginsDisabled) { @@ -3595,6 +3596,16 @@ NS_IMETHODIMP nsPluginHost::Observe(nsISupports *aSubject, } else { LoadPlugins(); } + if (prefName.Equals("plugin.disable")) { + nsCOMPtr obsService = + mozilla::services::GetObserverService(); + if (obsService) { + nsAutoString pluginPolicy; + pluginPolicy = mPluginsDisabled ? NS_LITERAL_STRING("disabled") + : NS_LITERAL_STRING("enabled"); + obsService->NotifyObservers(nullptr, "plugin-policy-changed", pluginPolicy.get()); + } + } } if (!strcmp("blocklist-updated", aTopic)) { nsPluginTag* plugin = mPlugins; diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index c5cb80091ece3..11fbb87073a6e 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -3092,6 +3092,11 @@ this.AddonManagerPrivate = { AddonManagerInternal.callAddonListeners.apply(AddonManagerInternal, aArgs); }, + callManagerListeners: function AMP_callManagerListeners(...aArgs) { + AddonManagerInternal.callManagerListeners.apply(AddonManagerInternal, + aArgs); + }, + AddonAuthor: AddonAuthor, AddonScreenshot: AddonScreenshot, diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 56158d9c634f1..adb658bb8deda 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -951,6 +951,20 @@ var gViewController = { } }, + cmd_pluginEnable: { + isEnabled: function cmd_pluginEnable_isEnabled() true, + doCommand: function cmd_pluginEnable_doCommand() { + Services.prefs.setBoolPref("plugin.disable", false); + } + }, + + cmd_pluginDisable: { + isEnabled: function cmd_pluginDisable_isEnabled() true, + doCommand: function cmd_pluginDisable_doCommand() { + Services.prefs.setBoolPref("plugin.disable", true); + } + }, + cmd_toggleAutoUpdateDefault: { isEnabled: function() { return true; @@ -2711,12 +2725,16 @@ var gListView = { node: null, _listBox: null, _emptyNotice: null, + _pluginEnableButton: null, + _pluginHeader: null, _type: null, initialize: function() { this.node = document.getElementById("list-view"); this._listBox = document.getElementById("addon-list"); this._emptyNotice = document.getElementById("addon-list-empty"); + this._pluginEnableButton = document.getElementById("plugin-enable-button"); + this._pluginHeader = document.getElementsByClassName("plugin-info-container")[0]; this._listBox.addEventListener("keydown", (aEvent) => { if (aEvent.keyCode == aEvent.DOM_VK_RETURN) { @@ -2752,6 +2770,11 @@ var gListView = { } }, + shutdown: function gListView_shutdown() { + AddonManager.removeAddonListener(this); + AddonManager.removeManagerListener(this); + }, + show: function(aType, aRequest) { let showOnlyDisabledUnsigned = false; if (aType.endsWith("?unsigned=true")) { @@ -2765,6 +2788,8 @@ var gListView = { this._type = aType; this.node.setAttribute("type", aType); this.showEmptyNotice(false); + this.showPluginHeader(false); + this.showPluginEnableButton(false); while (this._listBox.itemCount > 0) this._listBox.removeItemAt(0); @@ -2791,16 +2816,21 @@ var gListView = { for (let element of elements) this._listBox.appendChild(element); } + this.showPluginButton(); this.filterDisabledUnsigned(showOnlyDisabledUnsigned); gEventManager.registerInstallListener(this); gViewController.updateCommands(); gViewController.notifyViewChanged(); + AddonManager.addAddonListener(this); /* for onUninstalled */ + AddonManager.addManagerListener(this); /* for onPluginPolicyChanged */ }); }, hide: function() { + AddonManager.removeAddonListener(this); + AddonManager.removeManagerListener(this); gEventManager.unregisterInstallListener(this); doPendingUninstalls(this._listBox); }, @@ -2874,6 +2904,44 @@ var gListView = { } }, + onUninstalled: function gListView_onUninstalled() { + this.showEmptyNotice(this._listBox.itemCount == 0); + }, + + showPluginEnableButton: function gListView_showPluginEnableButton(aShow) { + if (this._pluginEnableButton) + this._pluginEnableButton.hidden = !aShow; + }, + + showPluginHeader: function gListView_showPluginHeader(aShow) { + if (this._pluginHeader) + this._pluginHeader.hidden = !aShow; + }, + + showPluginButton: function gListView_showPluginButton() { + if (this._type == "plugin") { + var plugin_disable = false; + + try { + plugin_disable = Services.prefs.getBoolPref("plugin.disable") + } catch (e) {} + + if (plugin_disable == true) { + this.showPluginHeader(false); + this.showEmptyNotice(false); + this.showPluginEnableButton(true); + } else { + this.showPluginHeader(true); + this.showEmptyNotice(this._listBox.itemCount == 0); + this.showPluginEnableButton(false); + } + } + }, + + onPluginPolicyChanged: function gListView_onPluginPolicyChanged() { + this.showPluginButton(); + }, + addItem: function(aObj, aIsInstall) { if (aObj.type != this._type) return; diff --git a/toolkit/mozapps/extensions/content/extensions.xul b/toolkit/mozapps/extensions/content/extensions.xul index 70939d0248ac1..69ad7f042988c 100644 --- a/toolkit/mozapps/extensions/content/extensions.xul +++ b/toolkit/mozapps/extensions/content/extensions.xul @@ -88,6 +88,8 @@ + + @@ -391,6 +393,7 @@ command="cmd_enableUpdateSecurity"/> + @@ -420,6 +423,7 @@ + diff --git a/toolkit/mozapps/extensions/internal/PluginProvider.jsm b/toolkit/mozapps/extensions/internal/PluginProvider.jsm index 075159a9ac373..bf07b0342b969 100644 --- a/toolkit/mozapps/extensions/internal/PluginProvider.jsm +++ b/toolkit/mozapps/extensions/internal/PluginProvider.jsm @@ -58,6 +58,7 @@ var PluginProvider = { plugins: null, startup: function() { + Services.obs.addObserver(this, "plugin-policy-changed", false); Services.obs.addObserver(this, LIST_UPDATED_TOPIC, false); Services.obs.addObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED, false); }, @@ -70,6 +71,7 @@ var PluginProvider = { this.plugins = null; Services.obs.removeObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED); Services.obs.removeObserver(this, LIST_UPDATED_TOPIC); + Services.obs.removeObserver(this, "plugin-policy-changed"); }, observe: function(aSubject, aTopic, aData) { @@ -98,6 +100,12 @@ var PluginProvider = { if (this.plugins) this.updatePluginList(); break; + case "plugin-policy-changed": + if (!this.plugins) + this.plugins ={}; + this.updatePluginList(); + AddonManagerPrivate.callManagerListeners("onPluginPolicyChanged"); + break; } }, -- GitLab