Bug 918695 - Only instanciate one singleton target per app r=paul

This commit is contained in:
Alexandre Poirot 2013-10-21 10:35:00 +01:00
parent 6ef67e921c
commit 812398850f

View File

@ -15,6 +15,8 @@ const PR_TRUNCATE = 0x20;
const CHUNK_SIZE = 10000;
const appTargets = new Map();
function addDirToZip(writer, dir, basePath) {
let files = dir.directoryEntries;
@ -212,6 +214,13 @@ function installHosted(client, webappsActor, appId, metadata, manifest) {
exports.installHosted = installHosted;
function getTargetForApp(client, webappsActor, manifestURL) {
// Ensure always returning the exact same JS object for a target
// of the same app in order to show only one toolbox per app and
// avoid re-creating lot of objects twice.
let existingTarget = appTargets.get(manifestURL);
if (existingTarget)
return promise.resolve(existingTarget);
let deferred = promise.defer();
let request = {
to: webappsActor,
@ -230,6 +239,10 @@ function getTargetForApp(client, webappsActor, manifestURL) {
devtools.TargetFactory.forRemoteTab(options).then((target) => {
target.isApp = true;
appTargets.set(manifestURL, target);
target.on("close", () => {
appTargets.delete(manifestURL);
});
deferred.resolve(target)
}, (error) => {
deferred.reject(error);