зеркало из https://github.com/mozilla/gecko-dev.git
Bug 959420 - Refactor saveApps, getManifestFor, readManifests, writeFile functions to use promises. r=fabrice
This commit is contained in:
Родитель
ec5250f4c8
Коммит
384728f025
|
@ -816,7 +816,7 @@ var AlertsHelper = {
|
|||
this._listeners[uid] = listener;
|
||||
|
||||
let app = DOMApplicationRegistry.getAppByManifestURL(listener.manifestURL);
|
||||
DOMApplicationRegistry.getManifestFor(app.manifestURL, function(manifest) {
|
||||
DOMApplicationRegistry.getManifestFor(app.manifestURL).then((manifest) => {
|
||||
let helper = new ManifestHelper(manifest, app.origin);
|
||||
let getNotificationURLFor = function(messages) {
|
||||
if (!messages)
|
||||
|
@ -873,7 +873,7 @@ var AlertsHelper = {
|
|||
// If we have a manifest URL, get the icon and title from the manifest
|
||||
// to prevent spoofing.
|
||||
let app = DOMApplicationRegistry.getAppByManifestURL(manifestUrl);
|
||||
DOMApplicationRegistry.getManifestFor(manifestUrl, function(aManifest) {
|
||||
DOMApplicationRegistry.getManifestFor(manifestUrl).then((aManifest) => {
|
||||
let helper = new ManifestHelper(aManifest, app.origin);
|
||||
send(helper.name, helper.iconURLForSize(128));
|
||||
});
|
||||
|
@ -972,7 +972,7 @@ var WebappsHelper = {
|
|||
|
||||
switch(topic) {
|
||||
case "webapps-launch":
|
||||
DOMApplicationRegistry.getManifestFor(json.manifestURL, function(aManifest) {
|
||||
DOMApplicationRegistry.getManifestFor(json.manifestURL).then((aManifest) => {
|
||||
if (!aManifest)
|
||||
return;
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -165,12 +165,12 @@ WebappsActor.prototype = {
|
|||
reg.webapps[aId] = aApp;
|
||||
reg.updatePermissionsForApp(aId);
|
||||
|
||||
reg._readManifests([{ id: aId }], function(aResult) {
|
||||
reg._readManifests([{ id: aId }]).then((aResult) => {
|
||||
let manifest = aResult[0].manifest;
|
||||
aApp.name = manifest.name;
|
||||
reg.updateAppHandlers(null, manifest, aApp);
|
||||
|
||||
reg._saveApps(function() {
|
||||
reg._saveApps().then(() => {
|
||||
aApp.manifest = manifest;
|
||||
|
||||
// Needed to evict manifest cache on content side
|
||||
|
@ -264,17 +264,8 @@ WebappsActor.prototype = {
|
|||
if (aManifest) {
|
||||
return promise.resolve(aManifest);
|
||||
} else {
|
||||
let deferred = promise.defer();
|
||||
let manFile = aDir.clone();
|
||||
manFile.append("manifest.webapp");
|
||||
DOMApplicationRegistry._loadJSONAsync(manFile, function(aManifest) {
|
||||
if (!aManifest) {
|
||||
deferred.reject("Error parsing manifest.webapp.");
|
||||
} else {
|
||||
deferred.resolve(aManifest);
|
||||
}
|
||||
});
|
||||
return deferred.promise;
|
||||
let manFile = OS.Path.join(aDir.path, "manifest.webapp");
|
||||
return AppsUtils.loadJSONAsync(manFile);
|
||||
}
|
||||
}
|
||||
function checkSideloading(aManifest) {
|
||||
|
@ -285,13 +276,10 @@ WebappsActor.prototype = {
|
|||
// The destination directory for this app.
|
||||
let installDir = DOMApplicationRegistry._getAppDir(aId);
|
||||
if (aManifest) {
|
||||
let deferred = promise.defer();
|
||||
let manFile = installDir.clone();
|
||||
manFile.append("manifest.webapp");
|
||||
DOMApplicationRegistry._writeFile(manFile, JSON.stringify(aManifest), function () {
|
||||
deferred.resolve(aAppType);
|
||||
let manFile = OS.Path.join(installDir.path, "manifest.webapp");
|
||||
return DOMApplicationRegistry._writeFile(manFile, JSON.stringify(aManifest)).then(() => {
|
||||
return aAppType;
|
||||
});
|
||||
return deferred.promise;
|
||||
} else {
|
||||
let manFile = aDir.clone();
|
||||
manFile.append("manifest.webapp");
|
||||
|
@ -304,21 +292,16 @@ WebappsActor.prototype = {
|
|||
return { metadata: aMetadata, appType: aAppType };
|
||||
}
|
||||
// Read the origin and manifest url from metadata.json
|
||||
let deferred = promise.defer();
|
||||
let metaFile = aDir.clone();
|
||||
metaFile.append("metadata.json");
|
||||
DOMApplicationRegistry._loadJSONAsync(metaFile, function(aMetadata) {
|
||||
let metaFile = OS.Path.join(aDir.path, "metadata.json");
|
||||
return AppsUtils.loadJSONAsync(metaFile).then((aMetadata) => {
|
||||
if (!aMetadata) {
|
||||
deferred.reject("Error parsing metadata.json.");
|
||||
return;
|
||||
throw("Error parsing metadata.json.");
|
||||
}
|
||||
if (!aMetadata.origin) {
|
||||
deferred.reject("Missing 'origin' property in metadata.json");
|
||||
return;
|
||||
throw("Missing 'origin' property in metadata.json");
|
||||
}
|
||||
deferred.resolve({ metadata: aMetadata, appType: aAppType });
|
||||
return { metadata: aMetadata, appType: aAppType };
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
let runnable = {
|
||||
run: function run() {
|
||||
|
@ -645,7 +628,7 @@ WebappsActor.prototype = {
|
|||
let reg = DOMApplicationRegistry;
|
||||
let id = reg._appIdForManifestURL(aManifestURL);
|
||||
|
||||
reg._readManifests([{ id: id }], function (aResults) {
|
||||
reg._readManifests([{ id: id }]).then((aResults) => {
|
||||
deferred.resolve(aResults[0].manifest);
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче