Bug 1386427 - Part 1: Add XRE*NativeManifests locations to dirsvc draft
authorTomislav Jovanovic <tomica@gmail.com>
Tue, 12 Sep 2017 18:58:23 +0200
changeset 667982 4b66f595b9f6dbf6e92ae325407acc2f76ed07e8
parent 662594 15128312c02a238ac158589c59fd3ee3e384ce80
child 667983 d6ebf123ea4c42094f255caf32f9c40942f5ba52
push id80910
push userbmo:tomica@gmail.com
push dateThu, 21 Sep 2017 00:19:34 +0000
bugs1386427
milestone57.0a1
Bug 1386427 - Part 1: Add XRE*NativeManifests locations to dirsvc MozReview-Commit-ID: DoJIP6QZ5AX
toolkit/components/extensions/NativeMessaging.jsm
toolkit/components/extensions/test/mochitest/test_chrome_native_messaging_paths.html
toolkit/components/extensions/test/xpcshell/head_native_messaging.js
toolkit/components/extensions/test/xpcshell/test_native_messaging.js
toolkit/xre/nsXREDirProvider.cpp
xpcom/build/nsXULAppAPI.h
--- a/toolkit/components/extensions/NativeMessaging.jsm
+++ b/toolkit/components/extensions/NativeMessaging.jsm
@@ -59,18 +59,18 @@ this.HostManifestManager = {
 
   init() {
     if (!this._initializePromise) {
       let platform = AppConstants.platform;
       if (platform == "win") {
         this._lookup = this._winLookup;
       } else if (platform == "macosx" || platform == "linux") {
         let dirs = [
-          Services.dirsvc.get("XREUserNativeMessaging", Ci.nsIFile).path,
-          Services.dirsvc.get("XRESysNativeMessaging", Ci.nsIFile).path,
+          Services.dirsvc.get("XREUserNativeManifests", Ci.nsIFile).path,
+          Services.dirsvc.get("XRESysNativeManifests", Ci.nsIFile).path,
         ];
         this._lookup = (application, context) => this._tryPaths(application, dirs, context);
       } else {
         throw new Error(`Native messaging is not supported on ${AppConstants.platform}`);
       }
       this._initializePromise = Schemas.load(HOST_MANIFEST_SCHEMA);
     }
     return this._initializePromise;
--- a/toolkit/components/extensions/test/mochitest/test_chrome_native_messaging_paths.html
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_native_messaging_paths.html
@@ -21,41 +21,41 @@ Cu.import("resource://gre/modules/AppCon
 
 // Test that the default paths searched for native host manifests
 // are the ones we expect.
 add_task(async function test_default_paths() {
   let expectUser, expectGlobal;
   switch (AppConstants.platform) {
     case "macosx": {
       expectUser = OS.Path.join(OS.Constants.Path.homeDir,
-                                "Library/Application Support/Mozilla/NativeMessagingHosts");
-      expectGlobal = "/Library/Application Support/Mozilla/NativeMessagingHosts";
+                                "Library/Application Support/Mozilla");
+      expectGlobal = "/Library/Application Support/Mozilla";
 
       break;
     }
 
     case "linux": {
-      expectUser = OS.Path.join(OS.Constants.Path.homeDir, ".mozilla/native-messaging-hosts");
+      expectUser = OS.Path.join(OS.Constants.Path.homeDir, ".mozilla");
 
       const libdir = AppConstants.HAVE_USR_LIB64_DIR ? "lib64" : "lib";
-      expectGlobal = OS.Path.join("/usr", libdir, "mozilla/native-messaging-hosts");
+      expectGlobal = OS.Path.join("/usr", libdir, "mozilla");
       break;
     }
 
     default:
       // Fixed filesystem paths are only defined for MacOS and Linux,
       // there's nothing to test on other platforms.
       ok(false, `This test does not apply on ${AppConstants.platform}`);
       break;
   }
 
-  let userDir = Services.dirsvc.get("XREUserNativeMessaging", Ci.nsIFile).path;
+  let userDir = Services.dirsvc.get("XREUserNativeManifests", Ci.nsIFile).path;
   is(userDir, expectUser, "user-specific native messaging directory is correct");
 
-  let globalDir = Services.dirsvc.get("XRESysNativeMessaging", Ci.nsIFile).path;
+  let globalDir = Services.dirsvc.get("XRESysNativeManifests", Ci.nsIFile).path;
   is(globalDir, expectGlobal, "system-wide native messaing directory is correct");
 });
 
 </script>
 
 </body>
 </html>
 
--- a/toolkit/components/extensions/test/xpcshell/head_native_messaging.js
+++ b/toolkit/components/extensions/test/xpcshell/head_native_messaging.js
@@ -57,19 +57,19 @@ async function setupHosts(scripts) {
     return manifestPath;
   }
 
   switch (AppConstants.platform) {
     case "macosx":
     case "linux":
       let dirProvider = {
         getFile(property) {
-          if (property == "XREUserNativeMessaging") {
+          if (property == "XREUserNativeManifests") {
             return tmpDir.clone();
-          } else if (property == "XRESysNativeMessaging") {
+          } else if (property == "XRESysNativeManifests") {
             return tmpDir.clone();
           }
           return null;
         },
       };
 
       Services.dirsvc.registerProvider(dirProvider);
       do_register_cleanup(() => {
--- a/toolkit/components/extensions/test/xpcshell/test_native_messaging.js
+++ b/toolkit/components/extensions/test/xpcshell/test_native_messaging.js
@@ -32,19 +32,19 @@ userDir.append("user");
 userDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
 
 let globalDir = dir.clone();
 globalDir.append("global");
 globalDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
 
 let dirProvider = {
   getFile(property) {
-    if (property == "XREUserNativeMessaging") {
+    if (property == "XREUserNativeManifests") {
       return userDir.clone();
-    } else if (property == "XRESysNativeMessaging") {
+    } else if (property == "XRESysNativeManifests") {
       return globalDir.clone();
     }
     return null;
   },
 };
 
 Services.dirsvc.registerProvider(dirProvider);
 
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -271,17 +271,17 @@ nsXREDirProvider::GetUserProfilesLocalDi
   }
   file.swap(*aResult);
   return NS_OK;
 }
 
 #if defined(XP_UNIX) || defined(XP_MACOSX)
 /**
  * Get the directory that is the parent of the system-wide directories
- * for extensions and native-messaing manifests.
+ * for extensions and native manifests.
  *
  * On OSX this is /Library/Application Support/Mozilla
  * On Linux this is /usr/{lib,lib64}/mozilla
  *   (for 32- and 64-bit systems respsectively)
  */
 static nsresult
 GetSystemParentDirectory(nsIFile** aFile)
 {
@@ -383,48 +383,32 @@ nsXREDirProvider::GetFile(const char* aP
         rv = file->AppendNative(NS_LITERAL_CSTRING("pref"));
     }
   }
   else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_DIR) ||
            !strcmp(aProperty, XRE_USER_APP_DATA_DIR)) {
     rv = GetUserAppDataDirectory(getter_AddRefs(file));
   }
 #if defined(XP_UNIX) || defined(XP_MACOSX)
-  else if (!strcmp(aProperty, XRE_SYS_NATIVE_MESSAGING_MANIFESTS)) {
+  else if (!strcmp(aProperty, XRE_SYS_NATIVE_MANIFESTS)) {
     nsCOMPtr<nsIFile> localDir;
 
     rv = ::GetSystemParentDirectory(getter_AddRefs(localDir));
     if (NS_SUCCEEDED(rv)) {
-      NS_NAMED_LITERAL_CSTRING(dirname,
-#if defined(XP_MACOSX)
-                               "NativeMessagingHosts"
-#else
-                               "native-messaging-hosts"
-#endif
-                               );
-      rv = localDir->AppendNative(dirname);
-      if (NS_SUCCEEDED(rv)) {
-        localDir.swap(file);
-      }
+      localDir.swap(file);
     }
   }
-  else if (!strcmp(aProperty, XRE_USER_NATIVE_MESSAGING_MANIFESTS)) {
+  else if (!strcmp(aProperty, XRE_USER_NATIVE_MANIFESTS)) {
     nsCOMPtr<nsIFile> localDir;
     rv = GetUserDataDirectoryHome(getter_AddRefs(localDir), false);
     if (NS_SUCCEEDED(rv)) {
 #if defined(XP_MACOSX)
       rv = localDir->AppendNative(NS_LITERAL_CSTRING("Mozilla"));
-      if (NS_SUCCEEDED(rv)) {
-        rv = localDir->AppendNative(NS_LITERAL_CSTRING("NativeMessagingHosts"));
-      }
 #else
       rv = localDir->AppendNative(NS_LITERAL_CSTRING(".mozilla"));
-      if (NS_SUCCEEDED(rv)) {
-        rv = localDir->AppendNative(NS_LITERAL_CSTRING("native-messaging-hosts"));
-      }
 #endif
     }
     if (NS_SUCCEEDED(rv)) {
       localDir.swap(file);
     }
   }
 #endif
   else if (!strcmp(aProperty, XRE_UPDATE_ROOT_DIR)) {
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -110,21 +110,21 @@
  * Additionally, the directory may be equal to that returned by
  * XRE_SYS_LOCAL_EXTENSION_PARENT_DIR on some platforms.
  */
 #define XRE_SYS_SHARE_EXTENSION_PARENT_DIR "XRESysSExtPD"
 
 #if defined(XP_UNIX) || defined(XP_MACOSX)
 /**
  * Directory service keys for the system-wide and user-specific
- * directories where host manifests used by the WebExtensions
- * native messaging feature are found.
+ * directories where native manifests used by the WebExtensions
+ * native messaging and managed storage features are found.
  */
-#define XRE_SYS_NATIVE_MESSAGING_MANIFESTS "XRESysNativeMessaging"
-#define XRE_USER_NATIVE_MESSAGING_MANIFESTS "XREUserNativeMessaging"
+#define XRE_SYS_NATIVE_MANIFESTS "XRESysNativeManifests"
+#define XRE_USER_NATIVE_MANIFESTS "XREUserNativeManifests"
 #endif
 
 /**
  * A directory service key which specifies the user system extension
  * parent directory.
  */
 #define XRE_USER_SYS_EXTENSION_DIR "XREUSysExt"