Bug 1263935 - Forward AddonManager.mapURIToAddonId to AddonPathService.mapURIToAddonId. r=mossop

This commit is contained in:
Alexandre Poirot 2016-04-26 07:11:15 -07:00
parent 30d3ba40c6
commit 912faf0bc9
2 changed files with 10 additions and 17 deletions

View File

@ -71,6 +71,10 @@ XPCOMUtils.defineLazyServiceGetter(this,
"AddonPolicyService",
"@mozilla.org/addons/policy-service;1",
"nsIAddonPolicyService");
XPCOMUtils.defineLazyServiceGetter(this,
"AddonPathService",
"@mozilla.org/addon-path-service;1",
"amIAddonPathService");
XPCOMUtils.defineLazyGetter(this, "CertUtils", function() {
let certUtils = {};
@ -2435,8 +2439,7 @@ this.XPIProvider = {
logger.info("Mapping " + aID + " to " + aFile.path);
this._addonFileMap.set(aID, aFile.path);
let service = Cc["@mozilla.org/addon-path-service;1"].getService(Ci.amIAddonPathService);
service.insertPath(aFile.path, aID);
AddonPathService.insertPath(aFile.path, aID);
},
/**
@ -4106,20 +4109,8 @@ this.XPIProvider = {
* @see amIAddonManager.mapURIToAddonID
*/
mapURIToAddonID: function(aURI) {
if (aURI.scheme == "moz-extension") {
return AddonPolicyService.extensionURIToAddonId(aURI);
}
let resolved = this._resolveURIToFile(aURI);
if (!resolved || !(resolved instanceof Ci.nsIFileURL))
return null;
for (let [id, path] of this._addonFileMap) {
if (resolved.file.path.startsWith(path))
return id;
}
return null;
// Returns `null` instead of empty string if the URI can't be mapped.
return AddonPathService.mapURIToAddonId(aURI) || null;
},
/**

View File

@ -83,8 +83,10 @@ function run_test_early() {
"resource://gre/modules/addons/XPIProvider.jsm", {});
// Make the early API call.
do_check_null(s.XPIProvider.mapURIToAddonID(uri));
// AddonManager still misses its provider and so doesn't work yet.
do_check_null(AddonManager.mapURIToAddonID(uri));
// But calling XPIProvider directly works immediately
do_check_eq(s.XPIProvider.mapURIToAddonID(uri), id);
// Actually start up the manager.
startupManager(false);