Bug 582833 - Add-on manager updates add-ons whose location is not managed by Firefox. r=Mossap. a=blocker.
authorAsaf Romano <aromano@mozilla.com>
Wed, 15 Dec 2010 20:56:35 +0200
changeset 59207 6fe13b97627f9da51ab0f77ce44e3c1af749e9e4
parent 59204 baee733bafd8fd953366a5043f5c6d9a4d3c1686 (current diff)
parent 59206 afd3b6431ccf62e9251104890b0d1da2d0cfd860 (diff)
child 59208 efc2bc1058dff5cdfd9f664aaf0ee59e71f17e81
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersMossap, blocker
bugs582833
milestone2.0b9pre
Bug 582833 - Add-on manager updates add-ons whose location is not managed by Firefox. r=Mossap. a=blocker.
storage/src/SQLiteMutex.h
--- a/toolkit/mozapps/extensions/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/XPIProvider.jsm
@@ -6471,17 +6471,19 @@ function AddonWrapper(aAddon) {
     if (!aAddon.appDisabled) {
       if (aAddon.userDisabled)
         permissions |= AddonManager.PERM_CAN_ENABLE;
       else if (aAddon.type != "theme")
         permissions |= AddonManager.PERM_CAN_DISABLE;
     }
     if (aAddon._installLocation) {
       if (!aAddon._installLocation.locked) {
-        permissions |= AddonManager.PERM_CAN_UPGRADE;
+        if (!aAddon._installLocation.isLinkedAddon(aAddon.id))
+          permissions |= AddonManager.PERM_CAN_UPGRADE;
+
         if (!aAddon.pendingUninstall)
           permissions |= AddonManager.PERM_CAN_UNINSTALL;
       }
     }
     return permissions;
   });
 
   this.__defineGetter__("isActive", function() {
@@ -6615,16 +6617,17 @@ function AddonWrapper(aAddon) {
  */
 function DirectoryInstallLocation(aName, aDirectory, aScope, aLocked) {
   this._name = aName;
   this.locked = aLocked;
   this._directory = aDirectory;
   this._scope = aScope
   this._IDToFileMap = {};
   this._FileToIDMap = {};
+  this._linkedAddons = [];
 
   if (!aDirectory.exists())
     return;
   if (!aDirectory.isDirectory())
     throw new Error("Location must be a directory.");
 
   this._readAddons();
 }
@@ -6709,17 +6712,19 @@ DirectoryInstallLocation.prototype = {
              entry.path);
         continue;
       }
 
       if (entry.isFile() && !directLoad) {
         newEntry = this._readDirectoryFromFile(entry);
         if (!newEntry)
           continue;
+
         entry = newEntry;
+        this._linkedAddons.push(id);
       }
 
       this._IDToFileMap[id] = entry;
       this._FileToIDMap[entry.path] = id;
     }
     entries.close();
   },
 
@@ -6935,16 +6940,27 @@ DirectoryInstallLocation.prototype = {
    *         The ID of the add-on
    * @return the nsILocalFile
    * @throws if the ID does not match any of the add-ons installed
    */
   getLocationForID: function DirInstallLocation_getLocationForID(aId) {
     if (aId in this._IDToFileMap)
       return this._IDToFileMap[aId].clone().QueryInterface(Ci.nsILocalFile);
     throw new Error("Unknown add-on ID " + aId);
+  },
+
+  /**
+   * Returns true if the given addon was installed in this location by a text
+   * file pointing to its real path.
+   *
+   * @param aId
+   *        The ID of the addon
+   */
+  isLinkedAddon: function(aId) {
+    return this._linkedAddons.indexOf(aId) != -1;
   }
 };
 
 #ifdef XP_WIN
 /**
  * An object that identifies a registry install location for add-ons. The location
  * consists of a registry key which contains string values mapping ID to the
  * path where an add-on is installed
@@ -7080,13 +7096,20 @@ WinRegInstallLocation.prototype = {
    * @param  aId
    *         The ID of the add-on
    * @return the nsIFile
    */
   getLocationForID: function RegInstallLocation_getLocationForID(aId) {
     if (aId in this._IDToFileMap)
       return this._IDToFileMap[aId].clone().QueryInterface(Ci.nsILocalFile);
     throw new Error("Unknown add-on ID");
+  },
+
+  /**
+   * @see DirectoryInstallLocation
+   */
+  isLinkedAddon: function(aId) {
+    return true;
   }
 };
 #endif
 
 AddonManagerPrivate.registerProvider(XPIProvider);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_filepointer.js
@@ -99,22 +99,25 @@ function run_test_1() {
     let file = a1.getResourceURI().QueryInterface(AM_Ci.nsIFileURL).file;
     do_check_eq(file.parent.path, sourceDir.path);
 
     let rootUri = do_get_addon_root_uri(sourceDir, addon1.id);
     let uri = a1.getResourceURI("/");
     do_check_eq(uri.spec, rootUri);
     uri = a1.getResourceURI("install.rdf");
     do_check_eq(uri.spec, rootUri + "install.rdf");
-
+    
+    // Check that upgrade is disabled for addons installed by file-pointers.
+    do_check_eq(a1.permissions & AddonManager.PERM_CAN_UPGRADE, 0);
     run_test_2();
   });
 }
 
-// Tests that installing an upgrade doesn't clobber the original sources
+// Tests that installing the addon from some other source doesn't clobber
+// the original sources
 function run_test_2() {
   prepare_test({}, [
     "onNewInstall",
   ]);
 
   let url = "http://localhost:4444/addons/test_filepointer.xpi";
   AddonManager.getInstallForURL(url, function(install) {
     ensure_test_completed();