[tbb-commits] [tor-browser/tor-browser-31.5.0esr-4.5-1] Bug 10280: Don't load any plugins into the address space.

mikeperry at torproject.org mikeperry at torproject.org
Wed Mar 25 17:07:26 UTC 2015


commit eb596b885a5b8083a2789b837a59a0907f7bda0a
Author: Mike Perry <mikeperry-git at torproject.org>
Date:   Tue Mar 24 11:02:32 2015 +0000

    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 ++
 toolkit/mozapps/extensions/content/extensions.js   |   68 ++++++++++++++++++++
 toolkit/mozapps/extensions/content/extensions.xul  |   21 ++++++
 .../mozapps/extensions/internal/PluginProvider.jsm |    8 +++
 5 files changed, 113 insertions(+)

diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp
index 1efe59f..72e3942 100644
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -3105,6 +3105,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);
     mPluginsClickToPlay = Preferences::GetBool("plugins.click_to_play", false);
     // Unload or load plugins as needed
@@ -3113,6 +3114,16 @@ NS_IMETHODIMP nsPluginHost::Observe(nsISupports *aSubject,
     } else {
       LoadPlugins();
     }
+    if (prefName.Equals("plugin.disable")) {
+      nsCOMPtr<nsIObserverService> 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 81f2670..03e5588 100644
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -2364,6 +2364,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 35d2392..775064e 100644
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -820,6 +820,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 cmd_toggleAutoUpdateDefault_isEnabled() true,
       doCommand: function cmd_toggleAutoUpdateDefault_doCommand() {
@@ -2553,12 +2567,16 @@ var gListView = {
   node: null,
   _listBox: null,
   _emptyNotice: null,
+  _pluginEnableButton: null,
+  _pluginHeader: null,
   _type: null,
 
   initialize: function gListView_initialize() {
     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];
 
     var self = this;
     this._listBox.addEventListener("keydown", function listbox_onKeydown(aEvent) {
@@ -2570,6 +2588,11 @@ var gListView = {
     }, false);
   },
 
+  shutdown: function gListView_shutdown() {
+    AddonManager.removeAddonListener(this);
+    AddonManager.removeManagerListener(this);
+  },
+
   show: function gListView_show(aType, aRequest) {
     if (!(aType in AddonManager.addonTypes))
       throw Components.Exception("Attempting to show unknown type " + aType, Cr.NS_ERROR_INVALID_ARG);
@@ -2577,6 +2600,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);
@@ -2600,14 +2625,19 @@ var gListView = {
         for (let element of elements)
           self._listBox.appendChild(element);
       }
+      self.showPluginButton();
 
       gEventManager.registerInstallListener(self);
       gViewController.updateCommands();
       gViewController.notifyViewChanged();
+      AddonManager.addAddonListener(self); /* for onUninstalled */
+      AddonManager.addManagerListener(self); /* for onPluginPolicyChanged */
     });
   },
 
   hide: function gListView_hide() {
+    AddonManager.removeAddonListener(this);
+    AddonManager.removeManagerListener(this);
     gEventManager.unregisterInstallListener(this);
     doPendingUninstalls(this._listBox);
   },
@@ -2658,6 +2688,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 gListView_addItem(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 d247bdf..b64937b 100644
--- a/toolkit/mozapps/extensions/content/extensions.xul
+++ b/toolkit/mozapps/extensions/content/extensions.xul
@@ -86,6 +86,8 @@
     <command id="cmd_forward"/>
     <command id="cmd_enableCheckCompatibility"/>
     <command id="cmd_pluginCheck"/>
+    <command id="cmd_pluginEnable"/>
+    <command id="cmd_pluginDisable"/>
     <command id="cmd_enableUpdateSecurity"/>
     <command id="cmd_toggleAutoUpdateDefault"/>
     <command id="cmd_resetAddonAutoUpdate"/>
@@ -357,6 +359,14 @@
                       command="cmd_pluginCheck"/>
               <spacer flex="5000"/> <!-- Necessary to allow the message to wrap -->
             </hbox>
+            <vbox id="plugin-disable-button" class="global-info" flex="1"
+                  align="end">
+              <button class="button-plugin-disable"
+                      label="&plugins.installed.disable;"
+                      tooltiptext="&plugins.installed.disable.tip;"
+                      command="cmd_pluginDisable"/>
+              <spacer flex="5000"/>
+            </vbox>
           </hbox>
           <hbox class="view-header global-info-container experiment-info-container">
             <hbox class="global-info" flex="1" align="center">
@@ -386,6 +396,17 @@
             </vbox>
             <spacer class="alert-spacer-after"/>
           </vbox>
+          <vbox id="plugin-enable-button" class="alert-container" flex="1"
+                hidden="true">
+            <spacer class="alert-spacer-before"/>
+            <vbox class="alert">
+              <label value="&plugins.installed.find;"/>
+              <button class="button-plugin-enable"
+                      label="&plugins.installed.enable;"
+                      command="cmd_pluginEnable"/>
+            </vbox>
+            <spacer class="alert-spacer-after"/>
+          </vbox>
           <richlistbox id="addon-list" class="list" flex="1"/>
         </vbox>
 
diff --git a/toolkit/mozapps/extensions/internal/PluginProvider.jsm b/toolkit/mozapps/extensions/internal/PluginProvider.jsm
index 7b6e335..65d41a7 100644
--- a/toolkit/mozapps/extensions/internal/PluginProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/PluginProvider.jsm
@@ -52,6 +52,7 @@ var PluginProvider = {
   plugins: null,
 
   startup: function PL_startup() {
+    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);
   },
@@ -64,6 +65,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) {
@@ -89,6 +91,12 @@ var PluginProvider = {
       if (this.plugins)
         this.updatePluginList();
       break;
+    case "plugin-policy-changed":
+      if (!this.plugins)
+        this.plugins ={};
+      this.updatePluginList();
+      AddonManagerPrivate.callManagerListeners("onPluginPolicyChanged");
+      break;
     }
   },
 





More information about the tbb-commits mailing list