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
--- 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.