mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1263935 - Use AddonPathService.mapURIToAddonId instead of AddonManager.mapURIToAddonID. r=ejpbruel
This commit is contained in:
parent
912faf0bc9
commit
c0ae627a40
@ -200,11 +200,7 @@ BrowserAddonActor.prototype = {
|
||||
} catch (e) {}
|
||||
|
||||
if (global instanceof Ci.nsIDOMWindow) {
|
||||
let id = {};
|
||||
if (mapURIToAddonID(global.document.documentURIObject, id)) {
|
||||
return id.value === this.id;
|
||||
}
|
||||
return false;
|
||||
return mapURIToAddonID(global.document.documentURIObject) == this.id;
|
||||
}
|
||||
|
||||
// Check the global for a __URI__ property and then try to map that to an
|
||||
@ -223,9 +219,8 @@ BrowserAddonActor.prototype = {
|
||||
return false;
|
||||
}
|
||||
|
||||
let id = {};
|
||||
if (mapURIToAddonID(uri, id)) {
|
||||
return id.value === this.id;
|
||||
if (mapURIToAddonID(uri) == this.id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,6 @@ loader.lazyGetter(this, "Debugger", () => {
|
||||
});
|
||||
loader.lazyRequireGetter(this, "CssLogic", "devtools/shared/inspector/css-logic", true);
|
||||
loader.lazyRequireGetter(this, "events", "sdk/event/core");
|
||||
loader.lazyRequireGetter(this, "mapURIToAddonID", "devtools/server/actors/utils/map-uri-to-addon-id");
|
||||
loader.lazyRequireGetter(this, "setTimeout", "sdk/timers", true);
|
||||
|
||||
/**
|
||||
|
@ -238,39 +238,43 @@ let SourceActor = ActorClass({
|
||||
}
|
||||
|
||||
let localURI = resolveURIToLocalPath(nsuri);
|
||||
if (!localURI) {
|
||||
return;
|
||||
}
|
||||
|
||||
let id = {};
|
||||
if (localURI && mapURIToAddonID(localURI, id)) {
|
||||
this._addonID = id.value;
|
||||
let id = mapURIToAddonID(localURI);
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
this._addonID = id;
|
||||
|
||||
if (localURI instanceof Ci.nsIJARURI) {
|
||||
// The path in the add-on is easy for jar: uris
|
||||
this._addonPath = localURI.JAREntry;
|
||||
if (localURI instanceof Ci.nsIJARURI) {
|
||||
// The path in the add-on is easy for jar: uris
|
||||
this._addonPath = localURI.JAREntry;
|
||||
}
|
||||
else if (localURI instanceof Ci.nsIFileURL) {
|
||||
// For file: uris walk up to find the last directory that is part of the
|
||||
// add-on
|
||||
let target = localURI.file;
|
||||
let path = target.leafName;
|
||||
|
||||
// We can assume that the directory containing the source file is part
|
||||
// of the add-on
|
||||
let root = target.parent;
|
||||
let file = root.parent;
|
||||
while (file && mapURIToAddonID(Services.io.newFileURI(file))) {
|
||||
path = root.leafName + "/" + path;
|
||||
root = file;
|
||||
file = file.parent;
|
||||
}
|
||||
else if (localURI instanceof Ci.nsIFileURL) {
|
||||
// For file: uris walk up to find the last directory that is part of the
|
||||
// add-on
|
||||
let target = localURI.file;
|
||||
let path = target.leafName;
|
||||
|
||||
// We can assume that the directory containing the source file is part
|
||||
// of the add-on
|
||||
let root = target.parent;
|
||||
let file = root.parent;
|
||||
while (file && mapURIToAddonID(Services.io.newFileURI(file), {})) {
|
||||
path = root.leafName + "/" + path;
|
||||
root = file;
|
||||
file = file.parent;
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
const error = new Error("Could not find the root of the add-on for " + this.url);
|
||||
DevToolsUtils.reportException("SourceActor.prototype._mapSourceToAddon", error)
|
||||
return;
|
||||
}
|
||||
|
||||
this._addonPath = path;
|
||||
if (!file) {
|
||||
const error = new Error("Could not find the root of the add-on for " + this.url);
|
||||
DevToolsUtils.reportException("SourceActor.prototype._mapSourceToAddon", error)
|
||||
return;
|
||||
}
|
||||
|
||||
this._addonPath = path;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -8,52 +8,37 @@
|
||||
|
||||
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
||||
const Services = require("Services");
|
||||
const { Cc, Ci } = require("chrome");
|
||||
|
||||
Object.defineProperty(this, "addonManager", {
|
||||
get: (function () {
|
||||
let cached;
|
||||
return () => {
|
||||
if (cached === undefined) {
|
||||
// catch errors as the addonManager might not exist in this environment
|
||||
// (eg, xpcshell)
|
||||
try {
|
||||
cached = Cc["@mozilla.org/addons/integration;1"]
|
||||
.getService(Ci.amIAddonManager);
|
||||
} catch (ex) {
|
||||
cached = null;
|
||||
}
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
}())
|
||||
});
|
||||
loader.lazyServiceGetter(this, "AddonPathService",
|
||||
"@mozilla.org/addon-path-service;1",
|
||||
"amIAddonPathService");
|
||||
|
||||
const B2G_ID = "{3c2e2abc-06d4-11e1-ac3b-374f68613e61}";
|
||||
const GRAPHENE_ID = "{d1bfe7d9-c01e-4237-998b-7b5f960a4314}";
|
||||
|
||||
/**
|
||||
* This is a wrapper around amIAddonManager.mapURIToAddonID which always returns
|
||||
* This is a wrapper around amIAddonPathService.mapURIToAddonID which always returns
|
||||
* false on B2G and graphene to avoid loading the add-on manager there and
|
||||
* reports any exceptions rather than throwing so that the caller doesn't have
|
||||
* to worry about them.
|
||||
*/
|
||||
module.exports = function mapURIToAddonID(uri, id) {
|
||||
if (!Services.appinfo
|
||||
|| Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT
|
||||
|| Services.appinfo.ID === undefined /* XPCShell */
|
||||
|| Services.appinfo.ID == B2G_ID
|
||||
|| Services.appinfo.ID == GRAPHENE_ID
|
||||
|| !uri
|
||||
|| !addonManager) {
|
||||
if (!Services.appinfo
|
||||
|| Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT
|
||||
|| Services.appinfo.ID === undefined /* XPCShell */
|
||||
|| Services.appinfo.ID == B2G_ID
|
||||
|| Services.appinfo.ID == GRAPHENE_ID
|
||||
|| !AddonPathService) {
|
||||
module.exports = function mapURIToAddonId(uri) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return addonManager.mapURIToAddonID(uri, id);
|
||||
}
|
||||
catch (e) {
|
||||
DevToolsUtils.reportException("mapURIToAddonID", e);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
} else {
|
||||
module.exports = function mapURIToAddonId(uri) {
|
||||
try {
|
||||
return AddonPathService.mapURIToAddonId(uri);
|
||||
}
|
||||
catch (e) {
|
||||
DevToolsUtils.reportException("mapURIToAddonId", e);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user