зеркало из https://github.com/mozilla/gecko-dev.git
Bug 915067 - Part 2: Filter certified apps from webapps actor. r=ochameau
This commit is contained in:
Родитель
799217b306
Коммит
6638204722
|
@ -500,13 +500,36 @@ WebappsActor.prototype = {
|
|||
|
||||
let defer = promise.defer();
|
||||
let reg = DOMApplicationRegistry;
|
||||
reg.getAll(function onsuccess(apps) {
|
||||
defer.resolve({ apps: apps });
|
||||
reg.getAll(apps => {
|
||||
defer.resolve({ apps: this._filterAllowedApps(apps) });
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
},
|
||||
|
||||
_areCertifiedAppsAllowed: function wa__areCertifiedAppsAllowed() {
|
||||
let pref = "devtools.debugger.forbid-certified-apps";
|
||||
return !Services.prefs.getBoolPref(pref);
|
||||
},
|
||||
|
||||
_isAppAllowedForManifest: function wa__isAppAllowedForManifest(aManifest) {
|
||||
if (this._areCertifiedAppsAllowed()) {
|
||||
return true;
|
||||
}
|
||||
let type = this._getAppType(aManifest.type);
|
||||
return type !== Ci.nsIPrincipal.APP_STATUS_CERTIFIED;
|
||||
},
|
||||
|
||||
_filterAllowedApps: function wa__filterAllowedApps(aApps) {
|
||||
return aApps.filter(app => this._isAppAllowedForManifest(app.manifest));
|
||||
},
|
||||
|
||||
_isAppAllowedForURL: function wa__isAppAllowedForURL(aManifestURL) {
|
||||
return this._findManifestByURL(aManifestURL).then(manifest => {
|
||||
return this._isAppAllowedForManifest(manifest);
|
||||
});
|
||||
},
|
||||
|
||||
uninstall: function wa_actorUninstall(aRequest) {
|
||||
debug("uninstall");
|
||||
|
||||
|
@ -531,6 +554,19 @@ WebappsActor.prototype = {
|
|||
return defer.promise;
|
||||
},
|
||||
|
||||
_findManifestByURL: function wa__findManifestByURL(aManifestURL) {
|
||||
let deferred = promise.defer();
|
||||
|
||||
let reg = DOMApplicationRegistry;
|
||||
let id = reg._appIdForManifestURL(aManifestURL);
|
||||
|
||||
reg._readManifests([{ id: id }], function (aResults) {
|
||||
deferred.resolve(aResults[0].manifest);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
getIconAsDataURL: function (aRequest) {
|
||||
debug("getIconAsDataURL");
|
||||
|
||||
|
@ -549,9 +585,7 @@ WebappsActor.prototype = {
|
|||
|
||||
let deferred = promise.defer();
|
||||
|
||||
let id = reg._appIdForManifestURL(manifestURL);
|
||||
reg._readManifests([{ id: id }], function (aResults) {
|
||||
let jsonManifest = aResults[0].manifest;
|
||||
this._findManifestByURL(manifestURL).then(jsonManifest => {
|
||||
let manifest = new ManifestHelper(jsonManifest, app.origin);
|
||||
let iconURL = manifest.iconURLForSize(aRequest.size || 128);
|
||||
if (!iconURL) {
|
||||
|
@ -665,14 +699,22 @@ WebappsActor.prototype = {
|
|||
listRunningApps: function (aRequest) {
|
||||
debug("listRunningApps\n");
|
||||
|
||||
let appPromises = [];
|
||||
let apps = [];
|
||||
|
||||
for each (let frame in this._appFrames()) {
|
||||
let manifestURL = frame.getAttribute("mozapp");
|
||||
|
||||
appPromises.push(this._isAppAllowedForURL(manifestURL).then(allowed => {
|
||||
if (allowed) {
|
||||
apps.push(manifestURL);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
return promise.all(appPromises).then(() => {
|
||||
return { apps: apps };
|
||||
});
|
||||
},
|
||||
|
||||
_connectToApp: function (aFrame) {
|
||||
|
@ -745,10 +787,19 @@ WebappsActor.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
if (!appFrame) {
|
||||
return { error: "appNotFound",
|
||||
let notFoundError = {
|
||||
error: "appNotFound",
|
||||
message: "Unable to find any opened app whose manifest " +
|
||||
"is '" + manifestURL + "'" };
|
||||
"is '" + manifestURL + "'"
|
||||
};
|
||||
|
||||
if (!appFrame) {
|
||||
return notFoundError;
|
||||
}
|
||||
|
||||
return this._isAppAllowedForURL(manifestURL).then(allowed => {
|
||||
if (!allowed) {
|
||||
return notFoundError;
|
||||
}
|
||||
|
||||
// Only create a new actor, if we haven't already
|
||||
|
@ -763,6 +814,7 @@ WebappsActor.prototype = {
|
|||
}
|
||||
|
||||
return { actor: actor };
|
||||
});
|
||||
},
|
||||
|
||||
watchApps: function () {
|
||||
|
@ -800,19 +852,30 @@ WebappsActor.prototype = {
|
|||
}
|
||||
this._openedApps.add(manifestURL);
|
||||
|
||||
this._isAppAllowedForURL(manifestURL).then(allowed => {
|
||||
if (allowed) {
|
||||
this.conn.send({ from: this.actorID,
|
||||
type: "appOpen",
|
||||
manifestURL: manifestURL
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case "appterminated":
|
||||
manifestURL = event.detail.manifestURL;
|
||||
this._openedApps.delete(manifestURL);
|
||||
|
||||
this._isAppAllowedForURL(manifestURL).then(allowed => {
|
||||
if (allowed) {
|
||||
this.conn.send({ from: this.actorID,
|
||||
type: "appClose",
|
||||
manifestURL: manifestURL
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче