Bug 1365568: Enable chrome registration for non-bootstrapped proxy file add-ons. r?rhelmer draft
authorKris Maglione <maglione.k@gmail.com>
Sat, 20 May 2017 15:35:58 -0700
changeset 582070 942f924190b264384421535425c2320bd97ae4ac
parent 582002 093eab57d50408eab14dcfa17f8e916e34ecd4b6
child 629658 c0d5f20d554f8ff545a814cea8eeca66b7a3471e
push id59959
push usermaglione.k@gmail.com
push dateSat, 20 May 2017 22:38:27 +0000
reviewersrhelmer
bugs1365568
milestone55.0a1
Bug 1365568: Enable chrome registration for non-bootstrapped proxy file add-ons. r?rhelmer Paths for proxy file add-ons are not relative to their install location, so they require special treatment when resolving the full paths to their manifests. Additionally, on Windows, absolute paths are also technically valid as relative paths, so we need to try parsing them as absolute paths before falling back to relative paths, rather than the reverse. MozReview-Commit-ID: GDDJddLxRbA
toolkit/mozapps/extensions/AddonManagerStartup.cpp
toolkit/mozapps/extensions/internal/XPIProvider.jsm
--- a/toolkit/mozapps/extensions/AddonManagerStartup.cpp
+++ b/toolkit/mozapps/extensions/AddonManagerStartup.cpp
@@ -380,25 +380,29 @@ public:
 private:
   nsString mId;
   InstallLocation& mLocation;
 };
 
 already_AddRefed<nsIFile>
 Addon::FullPath()
 {
-  nsString path = mLocation.Path();
+  nsString path = Path();
 
+  // First check for an absolute path, in case we have a proxy file.
   nsCOMPtr<nsIFile> file;
-  NS_NewLocalFile(path, false, getter_AddRefs(file));
+  if (NS_SUCCEEDED(NS_NewLocalFile(path, false, getter_AddRefs(file)))) {
+    return file.forget();
+  }
+
+  // If not an absolute path, fall back to a relative path from the location.
+  NS_NewLocalFile(mLocation.Path(), false, getter_AddRefs(file));
   MOZ_RELEASE_ASSERT(file);
 
-  path = Path();
   file->AppendRelativePath(path);
-
   return file.forget();
 }
 
 NSLocationType
 Addon::LocationType()
 {
   nsString type = GetString("type", "extension");
   if (type.LowerCaseEqualsLiteral("theme")) {
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -119,24 +119,30 @@ const nsIFile = Components.Constructor("
  *
  * @param {string} path
  *        The (possibly relative) path of the file.
  * @param {nsIFile} [base]
  *        An optional file to use as a base path if `path` is relative.
  * @returns {nsIFile}
  */
 function getFile(path, base = null) {
-  if (base) {
-    let file = base.clone();
-    try {
-      file.appendRelativePath(path);
-      return file;
-    } catch (e) {}
-  }
-  return new nsIFile(path);
+  // First try for an absolute path, as we get in the case of proxy
+  // files. Ideally we would try a relative path first, but on Windows,
+  // paths which begin with a drive letter are valid as relative paths,
+  // and treated as such.
+  try {
+    return new nsIFile(path);
+  } catch (e) {
+    // Ignore invalid relative paths.
+  }
+
+  // If the path isn't absolute, we must have a base path.
+  let file = base.clone();
+  file.appendRelativePath(path);
+  return file;
 }
 
 /**
  * Returns the modification time of the given file, or 0 if the file
  * does not exist, or cannot be accessed.
  *
  * @param {nsIFile} file
  *        The file to retrieve the modification time for.