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

mikeperry at torproject.org mikeperry at torproject.org
Fri Feb 13 05:16:13 UTC 2015


commit bc305e697edb6860fe035e4b67fc5f027de237a5
Author: Mike Perry <mikeperry-git at torproject.org>
Date:   Thu Feb 12 16:04:13 2015 -0800

    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 bobnomnom.
---
 dom/plugins/base/nsPluginHost.cpp                  |   11 +++
 toolkit/mozapps/extensions/content/extensions.js   |   75 +++++++++++++++++++-
 toolkit/mozapps/extensions/content/extensions.xul  |   23 ++++++
 .../mozapps/extensions/internal/PluginProvider.jsm |   11 +++
 4 files changed, 117 insertions(+), 3 deletions(-)

diff --git a/dom/plugins/base/nsPluginHost.cpp b/dom/plugins/base/nsPluginHost.cpp
index 1efe59f..68ac197 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, "plugins-policy-changed", pluginPolicy.get());
+      }
+    }
   }
   if (!strcmp("blocklist-updated", aTopic)) {
     nsPluginTag* plugin = mPlugins;
diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js
index 35d2392..6790841 100644
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -858,6 +858,20 @@ var gViewController = {
       }
     },
 
+    cmd_goToEnablePlugins: {
+      isEnabled: function cmd_goToEnablePlugins_isEnabled() true,
+      doCommand: function cmd_goToEnablePlugins_doCommand() {
+        Services.prefs.setBoolPref("plugin.disable", false);
+      }
+    },
+
+    cmd_goToDisablePlugins: {
+      isEnabled: function cmd_goToDisablePlugins_isEnabled() true,
+      doCommand: function cmd_goToDisablePlugins_doCommand() {
+        Services.prefs.setBoolPref("plugin.disable", true);
+      }
+    },
+
     cmd_goToRecentUpdates: {
       isEnabled: function cmd_goToRecentUpdates_isEnabled() true,
       doCommand: function cmd_goToRecentUpdates_doCommand() {
@@ -2553,12 +2567,17 @@ var gListView = {
   node: null,
   _listBox: null,
   _emptyNotice: null,
+  _pluginDisabledNotice: null,
+  _pluginEnabledNotice: null,
   _type: null,
+  _pluginListEmpty: false,
 
   initialize: function gListView_initialize() {
     this.node = document.getElementById("list-view");
     this._listBox = document.getElementById("addon-list");
     this._emptyNotice = document.getElementById("addon-list-empty");
+    this._pluginDisabledNotice = document.getElementById("plugin-disabled");
+    this._pluginEnabledNotice = document.getElementById("plugin-enabled");
 
     var self = this;
     this._listBox.addEventListener("keydown", function listbox_onKeydown(aEvent) {
@@ -2570,6 +2589,10 @@ var gListView = {
     }, false);
   },
 
+  shutdown: function gListView_shutdown() {
+    AddonManager.removeAddonListener(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,9 +2600,12 @@ var gListView = {
     this._type = aType;
     this.node.setAttribute("type", aType);
     this.showEmptyNotice(false);
+    this.showPluginEnabledNotice(false);
+    this.showPluginDisabledNotice(false);
 
     while (this._listBox.itemCount > 0)
       this._listBox.removeItemAt(0);
+    this._pluginListEmpty = true;
 
     var self = this;
     getAddonsAndInstalls(aType, function show_getAddonsAndInstalls(aAddonsList, aInstallsList) {
@@ -2594,20 +2620,22 @@ var gListView = {
       for (let installItem of aInstallsList)
         elements.push(createItem(installItem, true));
 
-      self.showEmptyNotice(elements.length == 0);
       if (elements.length > 0) {
         sortElements(elements, ["uiState", "name"], true);
         for (let element of elements)
           self._listBox.appendChild(element);
       }
+      self.showAllNeedNotices(true);
 
       gEventManager.registerInstallListener(self);
       gViewController.updateCommands();
       gViewController.notifyViewChanged();
+      AddonManager.addAddonListener(self);
     });
   },
 
   hide: function gListView_hide() {
+    AddonManager.removeAddonListener(this);
     gEventManager.unregisterInstallListener(this);
     doPendingUninstalls(this._listBox);
   },
@@ -2616,6 +2644,43 @@ var gListView = {
     this._emptyNotice.hidden = !aShow;
   },
 
+  showPluginDisabledNotice: function gListView_showPluginDisabledNotice(aShow) {
+    this._pluginDisabledNotice.hidden = !aShow;
+  },
+
+  showPluginEnabledNotice: function gListView_showPluginEnabledNotice(aShow) {
+    this._pluginEnabledNotice.hidden = !aShow;
+  },
+
+  showAllNeedNotices: function gListView_showAllNeedNotices(aShow) {
+      var empty_list = (this._listBox.itemCount == 0);
+      var show_empty_notice = true;
+
+      if (this._type == "plugin") {
+        var update_notices = (this._pluginListEmpty != empty_list);
+        this._pluginListEmpty = empty_list;
+
+        if (update_notices || aShow) {
+          var plugin_disable = false;
+
+          try {
+            plugin_disable = Services.prefs.getBoolPref("plugin.disable")
+          } catch (e) {}
+
+          if (plugin_disable == true) {
+            this.showPluginEnabledNotice(false);
+            this.showPluginDisabledNotice(true);
+            show_empty_notice = false;
+          } else {
+            this.showPluginDisabledNotice(false);
+            this.showPluginEnabledNotice(true);
+          }
+        }
+      }
+      if (show_empty_notice == true)
+        this.showEmptyNotice(empty_list);
+  },
+
   onSortChanged: function gListView_onSortChanged(aSortBy, aAscending) {
     sortList(this._listBox, aSortBy, aAscending);
   },
@@ -2658,6 +2723,10 @@ var gListView = {
     }
   },
 
+  onUninstalled: function gListView_onUninstalled()  {
+    this.showAllNeedNotices(false);
+  },
+
   addItem: function gListView_addItem(aObj, aIsInstall) {
     if (aObj.type != this._type)
       return;
@@ -2673,7 +2742,7 @@ var gListView = {
 
     let item = createItem(aObj, aIsInstall);
     this._listBox.insertBefore(item, this._listBox.firstChild);
-    this.showEmptyNotice(false);
+    this.showAllNeedNotices(false);
   },
 
   removeItem: function gListView_removeItem(aObj, aIsInstall) {
@@ -2682,7 +2751,7 @@ var gListView = {
     for (let item of this._listBox.childNodes) {
       if (item[prop] == aObj) {
         this._listBox.removeChild(item);
-        this.showEmptyNotice(this._listBox.itemCount == 0);
+        this.showAllNeedNotices(false);
         return;
       }
     }
diff --git a/toolkit/mozapps/extensions/content/extensions.xul b/toolkit/mozapps/extensions/content/extensions.xul
index d247bdf..1c2bb07 100644
--- a/toolkit/mozapps/extensions/content/extensions.xul
+++ b/toolkit/mozapps/extensions/content/extensions.xul
@@ -79,6 +79,8 @@
     <command id="cmd_findAllUpdates"/>
     <command id="cmd_restartApp"/>
     <command id="cmd_goToDiscoverPane"/>
+    <command id="cmd_goToEnablePlugins"/>
+    <command id="cmd_goToDisablePlugins"/>
     <command id="cmd_goToRecentUpdates"/>
     <command id="cmd_goToAvailableUpdates"/>
     <command id="cmd_installFromFile"/>
@@ -386,7 +388,28 @@
             </vbox>
             <spacer class="alert-spacer-after"/>
           </vbox>
+          <vbox id="plugin-disabled" class="alert-container"
+                flex="1" hidden="true">
+            <spacer class="alert-spacer-before"/>
+            <vbox class="alert">
+              <label value="&plugins.installed.find;"/>
+              <button class="button-enableplugin"
+                      label="&plugins.installed.enable;"
+                      command="cmd_goToEnablePlugins"/>
+            </vbox>
+            <spacer class="alert-spacer-after"/>
+          </vbox>
           <richlistbox id="addon-list" class="list" flex="1"/>
+          <vbox id="plugin-enabled" class="view-header global-info-container"
+                hidden="true">
+            <vbox class="global-info" flex="1"  align="center">
+              <button class="button-disableplugin"
+                      label="&plugins.installed.disable;"
+                      tooltiptext="&plugins.installed.disable.tip;"
+                      command="cmd_goToDisablePlugins"/>
+              <spacer flex="5000"/> <!-- Necessary to allow the message to wrap -->
+            </vbox>
+          </vbox>
         </vbox>
 
         <!-- updates view -->
diff --git a/toolkit/mozapps/extensions/internal/PluginProvider.jsm b/toolkit/mozapps/extensions/internal/PluginProvider.jsm
index 7b6e335..2cf2583 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, "plugins-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, "plugins-policy-changed");
   },
 
   observe: function(aSubject, aTopic, aData) {
@@ -89,6 +91,15 @@ var PluginProvider = {
       if (this.plugins)
         this.updatePluginList();
       break;
+    case "plugins-policy-changed":
+      var plugin_policy = aData
+      if (!this.plugins)
+        this.plugins =[];
+      this.updatePluginList();
+      Services.obs.notifyObservers(null,
+                                   "plugin-provider-after-changed-policy",
+                                   plugin_policy);
+      break;
     }
   },
 





More information about the tbb-commits mailing list