Bug 1191468 - always load app dir add-ons irrespective of enabledScopes, r?Mossop draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 17 Nov 2015 13:55:31 +0000
changeset 309415 f218722dd70f74a45e4dbb461a7faaa3ef1d1d81
parent 309414 701fb57ec4c7afea9dae110aee653f6d457e9bb1
child 511285 4007c4d8c28718510e5c98638fe967683a294238
push id7600
push usergijskruitbosch@gmail.com
push dateTue, 17 Nov 2015 19:29:29 +0000
reviewersMossop
bugs1191468
milestone45.0a1
Bug 1191468 - always load app dir add-ons irrespective of enabledScopes, r?Mossop
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js
toolkit/mozapps/extensions/test/xpcshell/test_upgrade_strictcompat.js
toolkit/xre/nsXREDirProvider.cpp
xpcom/build/nsXULAppAPI.h
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -129,17 +129,17 @@ const DIR_TRASH                       = 
 
 const FILE_DATABASE                   = "extensions.json";
 const FILE_OLD_CACHE                  = "extensions.cache";
 const FILE_RDF_MANIFEST               = "install.rdf";
 const FILE_WEB_MANIFEST               = "manifest.json";
 const FILE_XPI_ADDONS_LIST            = "extensions.ini";
 
 const KEY_PROFILEDIR                  = "ProfD";
-const KEY_APPDIR                      = "XCurProcD";
+const KEY_ADDON_APP_DIR               = "XREAddonAppDir";
 const KEY_TEMPDIR                     = "TmpD";
 const KEY_APP_DISTRIBUTION            = "XREAppDist";
 const KEY_APP_FEATURES                = "XREAppFeat";
 
 const KEY_APP_PROFILE                 = "app-profile";
 const KEY_APP_SYSTEM_ADDONS           = "app-system-addons";
 const KEY_APP_SYSTEM_DEFAULTS         = "app-system-defaults";
 const KEY_APP_GLOBAL                  = "app-global";
@@ -2551,21 +2551,19 @@ this.XPIProvider = {
                                     AddonManager.SCOPE_USER, true);
         if (hasRegistry) {
           addRegistryInstallLocation("winreg-app-user",
                                      Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
                                      AddonManager.SCOPE_USER);
         }
       }
 
-      if (enabledScopes & AddonManager.SCOPE_APPLICATION) {
-        addDirectoryInstallLocation(KEY_APP_GLOBAL, KEY_APPDIR,
-                                    [DIR_EXTENSIONS],
-                                    AddonManager.SCOPE_APPLICATION, true);
-      }
+      addDirectoryInstallLocation(KEY_APP_GLOBAL, KEY_ADDON_APP_DIR,
+                                  [DIR_EXTENSIONS],
+                                  AddonManager.SCOPE_APPLICATION, true);
 
       if (enabledScopes & AddonManager.SCOPE_SYSTEM) {
         addDirectoryInstallLocation(KEY_APP_SYSTEM_SHARE, "XRESysSExtPD",
                                     [Services.appinfo.ID],
                                     AddonManager.SCOPE_SYSTEM, true);
         addDirectoryInstallLocation(KEY_APP_SYSTEM_LOCAL, "XRESysLExtPD",
                                     [Services.appinfo.ID],
                                     AddonManager.SCOPE_SYSTEM, true);
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -1636,16 +1636,22 @@ Services.prefs.setCharPref(PREF_EM_MIN_C
 Services.prefs.setBoolPref(PREF_XPI_SIGNATURES_REQUIRED, false);
 
 // Register a temporary directory for the tests.
 const gTmpD = gProfD.clone();
 gTmpD.append("temp");
 gTmpD.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
 registerDirectory("TmpD", gTmpD);
 
+// Create a replacement app directory for the tests.
+const gAppDirForAddons = gProfD.clone();
+gAppDirForAddons.append("appdir-addons");
+gAppDirForAddons.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
+registerDirectory("XREAddonAppDir", gAppDirForAddons);
+
 // Write out an empty blocklist.xml file to the profile to ensure nothing
 // is blocklisted by default
 var blockFile = gProfD.clone();
 blockFile.append("blocklist.xml");
 var stream = AM_Cc["@mozilla.org/network/file-output-stream;1"].
              createInstance(AM_Ci.nsIFileOutputStream);
 stream.init(blockFile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
             FileUtils.PERMS_FILE, 0);
@@ -1699,16 +1705,20 @@ do_register_cleanup(function addon_clean
   var dirEntries = gTmpD.directoryEntries
                         .QueryInterface(AM_Ci.nsIDirectoryEnumerator);
   var entry;
   while ((entry = dirEntries.nextFile)) {
     do_throw("Found unexpected file in temporary directory: " + entry.leafName);
   }
   dirEntries.close();
 
+  try {
+    gAppDirForAddons.remove(true);
+  } catch (ex) { do_print("Got exception removing addon app dir, " + ex); }
+
   var testDir = gProfD.clone();
   testDir.append("extensions");
   testDir.append("trash");
   pathShouldntExist(testDir);
 
   testDir.leafName = "staged";
   pathShouldntExist(testDir);
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js
@@ -10,17 +10,17 @@ Services.prefs.setBoolPref(PREF_EM_STRIC
 // Enable loading extensions from the application scope
 Services.prefs.setIntPref("extensions.enabledScopes",
                           AddonManager.SCOPE_PROFILE +
                           AddonManager.SCOPE_APPLICATION);
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
-const globalDir = Services.dirsvc.get("XCurProcD", AM_Ci.nsIFile);
+const globalDir = Services.dirsvc.get("XREAddonAppDir", AM_Ci.nsIFile);
 globalDir.append("extensions");
 
 var gGlobalExisted = globalDir.exists();
 var gInstallTime = Date.now();
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_upgrade_strictcompat.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_upgrade_strictcompat.js
@@ -8,17 +8,17 @@
 // Enable loading extensions from the application scope
 Services.prefs.setIntPref("extensions.enabledScopes",
                           AddonManager.SCOPE_PROFILE +
                           AddonManager.SCOPE_APPLICATION);
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
-const globalDir = Services.dirsvc.get("XCurProcD", AM_Ci.nsIFile);
+const globalDir = Services.dirsvc.get("XREAddonAppDir", AM_Ci.nsIFile);
 globalDir.append("extensions");
 
 var gGlobalExisted = globalDir.exists();
 var gInstallTime = Date.now();
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -389,16 +389,23 @@ nsXREDirProvider::GetFile(const char* aP
     if (NS_SUCCEEDED(rv))
       rv = file->AppendNative(NS_LITERAL_CSTRING("distribution"));
   }
   else if (!strcmp(aProperty, XRE_APP_FEATURES_DIR)) {
     rv = GetAppDir()->Clone(getter_AddRefs(file));
     if (NS_SUCCEEDED(rv))
       rv = file->AppendNative(NS_LITERAL_CSTRING("features"));
   }
+  else if (!strcmp(aProperty, XRE_ADDON_APP_DIR)) {
+    nsCOMPtr<nsIDirectoryServiceProvider> dirsvc(do_GetService("@mozilla.org/file/directory_service;1", &rv));
+    if (NS_FAILED(rv))
+      return rv;
+    bool unused;
+    rv = dirsvc->GetFile("XCurProcD", &unused, getter_AddRefs(file));
+  }
   else if (NS_SUCCEEDED(GetProfileStartupDir(getter_AddRefs(file)))) {
     // We need to allow component, xpt, and chrome registration to
     // occur prior to the profile-after-change notification.
     if (!strcmp(aProperty, NS_APP_USER_CHROME_DIR)) {
       rv = file->AppendNative(NS_LITERAL_CSTRING("chrome"));
     }
   }
 
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -119,16 +119,21 @@
 #define XRE_APP_DISTRIBUTION_DIR "XREAppDist"
 
 /**
  * A directory service key which specifies the location for system add-ons.
  */
 #define XRE_APP_FEATURES_DIR "XREAppFeat"
 
 /**
+ * A directory service key which specifies the location for app dir add-ons.
+ */
+#define XRE_ADDON_APP_DIR "XREAddonAppDir"
+
+/**
  * A directory service key which provides the update directory.
  * At present this is supported only on Windows.
  * Windows: Documents and Settings\<User>\Local Settings\Application Data\
  *          <Vendor>\<Application>\<relative path to app dir from Program Files>
  * If appDir is not under the Program Files, directory service will fail.
  * Callers should fallback to appDir.
  */
 #define XRE_UPDATE_ROOT_DIR "UpdRootD"