Bug 1270356 Part 1: Add native messaging paths to XRE directory provider r?kmag
MozReview-Commit-ID: 2tjR3r9YySy
--- a/toolkit/components/extensions/test/mochitest/chrome.ini
+++ b/toolkit/components/extensions/test/mochitest/chrome.ini
@@ -12,15 +12,18 @@ skip-if = true # bug 1267328; was (toolk
[test_chrome_ext_downloads_download.html]
[test_chrome_ext_downloads_misc.html]
[test_chrome_ext_downloads_search.html]
[test_chrome_ext_eventpage_warning.html]
[test_chrome_ext_contentscript_unrecognizedprop_warning.html]
skip-if = (os == 'android') # browser.tabs is undefined. Bug 1258975 on android.
[test_chrome_ext_webnavigation_resolved_urls.html]
skip-if = (os == 'android') # browser.tabs is undefined. Bug 1258975 on android.
+[test_chrome_native_messaging_paths.html]
+# Re-enable for Windows with bug 1270359.
+skip-if = os != "mac" && os != "linux"
[test_ext_cookies_expiry.html]
skip-if = buildapp == 'b2g'
[test_ext_cookies_permissions.html]
skip-if = buildapp == 'b2g'
[test_ext_jsversion.html]
skip-if = buildapp == 'b2g'
[test_ext_schema.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_native_messaging_paths.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>WebExtension test</title>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+ <script src="chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js"></script>
+ <script type="text/javascript" src="head.js"></script>
+ <link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="text/javascript">
+"use strict";
+
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+
+/* global OS */
+
+Cu.import("resource://gre/modules/osfile.jsm");
+Cu.import("resource://gre/modules/AppConstants.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+// Test that the default paths searched for native host manifests
+// are the ones we expect.
+add_task(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";
+
+ break;
+ }
+
+ case "linux": {
+ expectUser = OS.Path.join(OS.Constants.Path.homeDir, ".mozilla/native-messaging-hosts");
+
+ const libdir = AppConstants.HAVE_USR_LIB64_DIR ? "lib64" : "lib";
+ expectGlobal = OS.Path.join("/usr", libdir, "mozilla/native-messaging-hosts");
+ break;
+ }
+
+ default:
+ ok(false, `This test should be skipped on ${AppConstants.platform}`);
+ break;
+ }
+
+ let userDir = Services.dirsvc.get("XREUserNativeMessaging", Ci.nsIFile).path;
+ is(userDir, expectUser, "user-specific native messaging directory is correct");
+
+ let globalDir = Services.dirsvc.get("XRESysNativeMessaging", Ci.nsIFile).path;
+ is(globalDir, expectGlobal, "system-wide native messaing directory is correct");
+});
+
+</script>
+
+</body>
+</html>
+
--- a/toolkit/modules/AppConstants.jsm
+++ b/toolkit/modules/AppConstants.jsm
@@ -311,13 +311,20 @@ this.AppConstants = Object.freeze({
// On unofficial builds, this is an empty string.
#ifndef MOZ_SOURCE_URL
#define MOZ_SOURCE_URL
#endif
SOURCE_REVISION_URL: "@MOZ_SOURCE_URL@",
MOZ_NUWA_PROCESS:
#ifdef MOZ_NUWA_PROCESS
- true
+ true,
#else
- false
+ false,
+#endif
+
+ HAVE_USR_LIB64_DIR:
+#ifdef HAVE_USR_LIB64_DIR
+ true,
+#else
+ false,
#endif
});
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -234,16 +234,55 @@ nsXREDirProvider::GetUserProfilesLocalDi
if (NS_FAILED(tmp)) {
rv = tmp;
}
}
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.
+ *
+ * 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)
+{
+ nsresult rv;
+ nsCOMPtr<nsIFile> localDir;
+#if defined(XP_MACOSX)
+ rv = GetOSXFolderType(kOnSystemDisk, kApplicationSupportFolderType, getter_AddRefs(localDir));
+ if (NS_SUCCEEDED(rv)) {
+ rv = localDir->AppendNative(NS_LITERAL_CSTRING("Mozilla"));
+ }
+#else
+ NS_NAMED_LITERAL_CSTRING(dirname,
+#ifdef HAVE_USR_LIB64_DIR
+ "/usr/lib64/mozilla"
+#elif defined(__OpenBSD__) || defined(__FreeBSD__)
+ "/usr/local/lib/mozilla"
+#else
+ "/usr/lib/mozilla"
+#endif
+ );
+ rv = NS_NewNativeLocalFile(dirname, false, getter_AddRefs(localDir));
+#endif
+
+ if (NS_SUCCEEDED(rv)) {
+ localDir.forget(aFile);
+ }
+ return rv;
+}
+#endif
+
NS_IMETHODIMP
nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
nsIFile** aFile)
{
nsresult rv;
bool gettingProfile = false;
@@ -309,16 +348,56 @@ nsXREDirProvider::GetFile(const char* aP
if (NS_SUCCEEDED(rv))
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)) {
+ 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);
+ }
+ }
+ }
+ else if (!strcmp(aProperty, XRE_USER_NATIVE_MESSAGING_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)) {
rv = GetUpdateRootDir(getter_AddRefs(file));
}
else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE)) {
rv = GetUserAppDataDirectory(getter_AddRefs(file));
if (NS_SUCCEEDED(rv))
rv = file->AppendNative(NS_LITERAL_CSTRING(APP_REGISTRY_NAME));
}
@@ -1414,56 +1493,33 @@ nsXREDirProvider::GetSysUserExtensionsDi
}
#if defined(XP_UNIX) || defined(XP_MACOSX)
nsresult
nsXREDirProvider::GetSystemExtensionsDirectory(nsIFile** aFile)
{
nsresult rv;
nsCOMPtr<nsIFile> localDir;
-#if defined(XP_MACOSX)
- FSRef fsRef;
- OSErr err = ::FSFindFolder(kOnSystemDisk, kApplicationSupportFolderType, kCreateFolder, &fsRef);
- NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
-
- rv = NS_NewNativeLocalFile(EmptyCString(), true, getter_AddRefs(localDir));
- NS_ENSURE_SUCCESS(rv, rv);
-
- nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir);
- NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED);
-
- rv = dirFileMac->InitWithFSRef(&fsRef);
- NS_ENSURE_SUCCESS(rv, rv);
-
- localDir = do_QueryInterface(dirFileMac, &rv);
-
- static const char* const sXR = "Mozilla";
- rv = localDir->AppendNative(nsDependentCString(sXR));
- NS_ENSURE_SUCCESS(rv, rv);
- static const char* const sExtensions = "Extensions";
- rv = localDir->AppendNative(nsDependentCString(sExtensions));
- NS_ENSURE_SUCCESS(rv, rv);
-#elif defined(XP_UNIX)
- static const char *const sysSExtDir =
-#ifdef HAVE_USR_LIB64_DIR
- "/usr/lib64/mozilla/extensions";
-#elif defined(__OpenBSD__) || defined(__FreeBSD__)
- "/usr/local/lib/mozilla/extensions";
+ rv = GetSystemParentDirectory(getter_AddRefs(localDir));
+ if (NS_SUCCEEDED(rv)) {
+ NS_NAMED_LITERAL_CSTRING(sExtensions,
+#if defined(XP_MACOSX)
+ "Extensions"
#else
- "/usr/lib/mozilla/extensions";
+ "extensions"
#endif
+ );
- rv = NS_NewNativeLocalFile(nsDependentCString(sysSExtDir), false,
- getter_AddRefs(localDir));
- NS_ENSURE_SUCCESS(rv, rv);
-#endif
-
- localDir.forget(aFile);
- return NS_OK;
+ rv = localDir->AppendNative(sExtensions);
+ if (NS_SUCCEEDED(rv)) {
+ localDir.forget(aFile);
+ }
+ }
+ return rv;
}
#endif
nsresult
nsXREDirProvider::GetUserDataDirectory(nsIFile** aFile, bool aLocal,
const nsACString* aProfileName,
const nsACString* aAppName,
const nsACString* aVendorName)
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -101,16 +101,26 @@
* A directory service key which specifies the system extension
* parent directory containing platform-independent extensions.
* This key may not be available on all platforms.
* 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.
+ */
+#define XRE_SYS_NATIVE_MESSAGING_MANIFESTS "XRESysNativeMessaging"
+#define XRE_USER_NATIVE_MESSAGING_MANIFESTS "XREUserNativeMessaging"
+#endif
+
/**
* A directory service key which specifies the user system extension
* parent directory.
*/
#define XRE_USER_SYS_EXTENSION_DIR "XREUSysExt"
/**
* A directory service key which specifies the distribution specific files for