mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 789527 - Change the way we install packaged apps [r=gwagner]
This commit is contained in:
parent
94eb40e12d
commit
4a8a8d8d27
@ -188,8 +188,10 @@ WebappsRegistry.prototype = {
|
|||||||
|
|
||||||
// mozIDOMApplicationRegistry2 implementation
|
// mozIDOMApplicationRegistry2 implementation
|
||||||
|
|
||||||
installPackage: function(aPackageURL, aParams) {
|
installPackage: function(aURL, aParams) {
|
||||||
this._validateScheme(aPackageURL);
|
let installURL = this._window.location.href;
|
||||||
|
let installOrigin = this._getOrigin(installURL);
|
||||||
|
this._validateScheme(aURL);
|
||||||
|
|
||||||
let request = this.createRequest();
|
let request = this.createRequest();
|
||||||
let requestID = this.getRequestId(request);
|
let requestID = this.getRequestId(request);
|
||||||
@ -198,13 +200,54 @@ WebappsRegistry.prototype = {
|
|||||||
Array.isArray(aParams.receipts)) ? aParams.receipts : [];
|
Array.isArray(aParams.receipts)) ? aParams.receipts : [];
|
||||||
let categories = (aParams && aParams.categories &&
|
let categories = (aParams && aParams.categories &&
|
||||||
Array.isArray(aParams.categories)) ? aParams.categories : [];
|
Array.isArray(aParams.categories)) ? aParams.categories : [];
|
||||||
cpmm.sendAsyncMessage("Webapps:InstallPackage", { url: aPackageURL,
|
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
||||||
receipts: receipts,
|
xhr.open("GET", aURL, true);
|
||||||
categories: categories,
|
xhr.channel.loadFlags |= Ci.nsIRequest.VALIDATE_ALWAYS;
|
||||||
requestID: requestID,
|
|
||||||
oid: this._id,
|
xhr.addEventListener("load", (function() {
|
||||||
from: this._window.location.href,
|
if (xhr.status == 200) {
|
||||||
installOrigin: this._getOrigin(this._window.location.href) });
|
let manifest;
|
||||||
|
try {
|
||||||
|
manifest = JSON.parse(xhr.responseText, installOrigin);
|
||||||
|
} catch(e) {
|
||||||
|
Services.DOMRequest.fireError(request, "MANIFEST_PARSE_ERROR");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(AppsUtils.checkManifest(manifest, installOrigin) &&
|
||||||
|
manifest.package_path)) {
|
||||||
|
Services.DOMRequest.fireError(request, "INVALID_MANIFEST");
|
||||||
|
} else {
|
||||||
|
if (!this.checkAppStatus(manifest)) {
|
||||||
|
Services.DOMRequest.fireError(request, "INVALID_SECURITY_LEVEL");
|
||||||
|
} else {
|
||||||
|
let receipts = (aParams && aParams.receipts && Array.isArray(aParams.receipts)) ? aParams.receipts : [];
|
||||||
|
let categories = (aParams && aParams.categories && Array.isArray(aParams.categories)) ? aParams.categories : [];
|
||||||
|
let etag = xhr.getResponseHeader("Etag");
|
||||||
|
cpmm.sendAsyncMessage("Webapps:InstallPackage", { app: {
|
||||||
|
installOrigin: installOrigin,
|
||||||
|
origin: this._getOrigin(aURL),
|
||||||
|
manifestURL: aURL,
|
||||||
|
updateManifest: manifest,
|
||||||
|
etag: etag,
|
||||||
|
receipts: receipts,
|
||||||
|
categories: categories },
|
||||||
|
from: installURL,
|
||||||
|
oid: this._id,
|
||||||
|
requestID: requestID,
|
||||||
|
isPackage: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Services.DOMRequest.fireError(request, "MANIFEST_URL_ERROR");
|
||||||
|
}
|
||||||
|
}).bind(this), false);
|
||||||
|
|
||||||
|
xhr.addEventListener("error", (function() {
|
||||||
|
Services.DOMRequest.fireError(request, "NETWORK_ERROR");
|
||||||
|
}).bind(this), false);
|
||||||
|
|
||||||
|
xhr.send(null);
|
||||||
return request;
|
return request;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -338,9 +381,11 @@ WebappsApplication.prototype = {
|
|||||||
"Webapps:Uninstall:Return:KO",
|
"Webapps:Uninstall:Return:KO",
|
||||||
"Webapps:OfflineCache",
|
"Webapps:OfflineCache",
|
||||||
"Webapps:CheckForUpdate:Return:OK",
|
"Webapps:CheckForUpdate:Return:OK",
|
||||||
"Webapps:CheckForUpdate:Return:KO"]);
|
"Webapps:CheckForUpdate:Return:KO",
|
||||||
|
"Webapps:PackageEvent"]);
|
||||||
cpmm.sendAsyncMessage("Webapps:RegisterForMessages",
|
cpmm.sendAsyncMessage("Webapps:RegisterForMessages",
|
||||||
["Webapps:Uninstall:Return:OK", "Webapps:OfflineCache"]);
|
["Webapps:Uninstall:Return:OK", "Webapps:OfflineCache",
|
||||||
|
"Webapps:PackageEvent"]);
|
||||||
},
|
},
|
||||||
|
|
||||||
set onprogress(aCallback) {
|
set onprogress(aCallback) {
|
||||||
@ -434,7 +479,8 @@ WebappsApplication.prototype = {
|
|||||||
uninit: function() {
|
uninit: function() {
|
||||||
this._onprogress = null;
|
this._onprogress = null;
|
||||||
cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
|
cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
|
||||||
["Webapps:Uninstall:Return:OK", "Webapps:OfflineCache"]);
|
["Webapps:Uninstall:Return:OK", "Webapps:OfflineCache",
|
||||||
|
"Webapps:PackageEvent"]);
|
||||||
},
|
},
|
||||||
|
|
||||||
_fireEvent: function(aName, aHandler) {
|
_fireEvent: function(aName, aHandler) {
|
||||||
@ -445,9 +491,11 @@ WebappsApplication.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
receiveMessage: function(aMessage) {
|
receiveMessage: function(aMessage) {
|
||||||
var msg = aMessage.json;
|
let msg = aMessage.json;
|
||||||
let req = this.takeRequest(msg.requestID);
|
let req = this.takeRequest(msg.requestID);
|
||||||
if ((msg.oid != this._id || !req) && aMessage.name !== "Webapps:OfflineCache")
|
if ((msg.oid != this._id || !req) &&
|
||||||
|
aMessage.name !== "Webapps:OfflineCache" &&
|
||||||
|
aMessage.name !== "Webapps:PackageEvent")
|
||||||
return;
|
return;
|
||||||
switch (aMessage.name) {
|
switch (aMessage.name) {
|
||||||
case "Webapps:Uninstall:Return:OK":
|
case "Webapps:Uninstall:Return:OK":
|
||||||
@ -491,6 +539,43 @@ WebappsApplication.prototype = {
|
|||||||
case "Webapps:CheckForUpdate:Return:KO":
|
case "Webapps:CheckForUpdate:Return:KO":
|
||||||
Services.DOMRequest.fireError(req, msg.error);
|
Services.DOMRequest.fireError(req, msg.error);
|
||||||
break;
|
break;
|
||||||
|
case "Webapps:PackageEvent":
|
||||||
|
if (msg.manifestURL != this.manifestURL)
|
||||||
|
return;
|
||||||
|
switch(msg.type) {
|
||||||
|
case "error":
|
||||||
|
this._downloadError = msg.error;
|
||||||
|
this._fireEvent("downloaderror", this._ondownloaderror);
|
||||||
|
break;
|
||||||
|
case "progress":
|
||||||
|
this.progress = msg.progress;
|
||||||
|
this._fireEvent("downloadprogress", this._onprogress);
|
||||||
|
break;
|
||||||
|
case "installed":
|
||||||
|
let app = msg.app;
|
||||||
|
this.progress = app.progress || 0;
|
||||||
|
this.downloadAvailable = app.downloadAvailable;
|
||||||
|
this.downloading = app.downloading;
|
||||||
|
this.readyToApplyDownload = app.readyToApplyDownload;
|
||||||
|
this.downloadSize = app.downloadSize || 0;
|
||||||
|
this.installState = app.installState;
|
||||||
|
this.manifest = app.manifest;
|
||||||
|
this._fireEvent("downloaded", this._ondownloaded);
|
||||||
|
this._fireEvent("downloadapplied", this._ondownloadapplied);
|
||||||
|
break;
|
||||||
|
case "canceled":
|
||||||
|
app = msg.app;
|
||||||
|
this.progress = app.progress || 0;
|
||||||
|
this.downloadAvailable = app.downloadAvailable;
|
||||||
|
this.downloading = app.downloading;
|
||||||
|
this.readyToApplyDownload = app.readyToApplyDownload;
|
||||||
|
this.downloadSize = app.downloadSize || 0;
|
||||||
|
this.installState = app.installState;
|
||||||
|
this._downloadError = msg.error;
|
||||||
|
this._fireEvent("downloaderror", this._ondownloaderror);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ let DOMApplicationRegistry = {
|
|||||||
webapps: { },
|
webapps: { },
|
||||||
children: [ ],
|
children: [ ],
|
||||||
allAppsLaunchable: false,
|
allAppsLaunchable: false,
|
||||||
|
downloads: { },
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
this.messages = ["Webapps:Install", "Webapps:Uninstall",
|
this.messages = ["Webapps:Install", "Webapps:Uninstall",
|
||||||
@ -470,7 +471,8 @@ let DOMApplicationRegistry = {
|
|||||||
mm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg);
|
mm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg);
|
||||||
break;
|
break;
|
||||||
case "Webapps:InstallPackage":
|
case "Webapps:InstallPackage":
|
||||||
this.installPackage(msg, mm);
|
// always ask for UI to install
|
||||||
|
Services.obs.notifyObservers(mm, "webapps-ask-install", JSON.stringify(msg));
|
||||||
break;
|
break;
|
||||||
case "Webapps:GetBasePath":
|
case "Webapps:GetBasePath":
|
||||||
return this.webapps[msg.id].basePath;
|
return this.webapps[msg.id].basePath;
|
||||||
@ -566,6 +568,26 @@ let DOMApplicationRegistry = {
|
|||||||
|
|
||||||
cancelDownload: function cancelDowload(aManifestURL) {
|
cancelDownload: function cancelDowload(aManifestURL) {
|
||||||
// We can't cancel appcache dowloads for now.
|
// We can't cancel appcache dowloads for now.
|
||||||
|
if (!this.downloads[aManifestURL]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// This is a HTTP channel.
|
||||||
|
let download = this.downloads[aManifestURL]
|
||||||
|
download.channel.cancel(Cr.NS_BINDING_ABORTED);
|
||||||
|
let app = this.webapps[dowload.appId];
|
||||||
|
|
||||||
|
app.progress = 0;
|
||||||
|
app.installState = app.previousState;
|
||||||
|
app.dowloading = false;
|
||||||
|
app.dowloadavailable = false;
|
||||||
|
app.downloadSize = 0;
|
||||||
|
this._saveApps((function() {
|
||||||
|
this.broadcastMessage("Webapps:PackageEvent",
|
||||||
|
{ type: "canceled",
|
||||||
|
manifestURL: aApp.manifestURL,
|
||||||
|
app: app,
|
||||||
|
error: "DOWNLOAD_CANCELED" });
|
||||||
|
}).bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
startOfflineCacheDownload: function startOfflineCacheDownload(aManifest, aApp, aProfileDir) {
|
startOfflineCacheDownload: function startOfflineCacheDownload(aManifest, aApp, aProfileDir) {
|
||||||
@ -714,8 +736,12 @@ let DOMApplicationRegistry = {
|
|||||||
confirmInstall: function(aData, aFromSync, aProfileDir, aOfflineCacheObserver) {
|
confirmInstall: function(aData, aFromSync, aProfileDir, aOfflineCacheObserver) {
|
||||||
let app = aData.app;
|
let app = aData.app;
|
||||||
app.removable = true;
|
app.removable = true;
|
||||||
|
|
||||||
|
let origin = Services.io.newURI(app.origin, null, null);
|
||||||
|
let manifestURL = origin.resolve(app.manifestURL);
|
||||||
|
|
||||||
let id = app.syncId || this._appId(app.origin);
|
let id = app.syncId || this._appId(app.origin);
|
||||||
let localId = this.getAppLocalIdByManifestURL(app.manifestURL);
|
let localId = this.getAppLocalIdByManifestURL(manifestURL);
|
||||||
|
|
||||||
// Installing an application again is considered as an update.
|
// Installing an application again is considered as an update.
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -729,9 +755,14 @@ let DOMApplicationRegistry = {
|
|||||||
localId = this._nextLocalId();
|
localId = this._nextLocalId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app.packageId) {
|
let manifestName = "manifest.webapp";
|
||||||
|
if (aData.isPackage) {
|
||||||
// Override the origin with the correct id.
|
// Override the origin with the correct id.
|
||||||
app.origin = "app://" + id;
|
app.origin = "app://" + id;
|
||||||
|
|
||||||
|
// For packaged apps, keep the update manifest distinct from the app
|
||||||
|
// manifest.
|
||||||
|
manifestName = "update.webapp";
|
||||||
}
|
}
|
||||||
|
|
||||||
let appObject = AppsUtils.cloneAppObject(app);
|
let appObject = AppsUtils.cloneAppObject(app);
|
||||||
@ -746,30 +777,23 @@ let DOMApplicationRegistry = {
|
|||||||
|
|
||||||
let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
|
let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
|
||||||
let manFile = dir.clone();
|
let manFile = dir.clone();
|
||||||
manFile.append("manifest.webapp");
|
manFile.append(manifestName);
|
||||||
this._writeFile(manFile, JSON.stringify(app.manifest), function() {
|
let jsonManifest = aData.isPackage ? app.updateManifest : app.manifest;
|
||||||
// If this a packaged app, move the zip file from the temp directory,
|
this._writeFile(manFile, JSON.stringify(jsonManifest), function() { });
|
||||||
// and delete the temp directory.
|
|
||||||
if (app.packageId) {
|
|
||||||
let appFile = FileUtils.getFile("TmpD", ["webapps", app.packageId, "application.zip"],
|
|
||||||
true, true);
|
|
||||||
appFile.moveTo(dir, "application.zip");
|
|
||||||
let tmpDir = FileUtils.getDir("TmpD", ["webapps", app.packageId],
|
|
||||||
true, true);
|
|
||||||
try {
|
|
||||||
tmpDir.remove(true);
|
|
||||||
} catch(e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let manifest = new DOMApplicationManifest(app.manifest, app.origin);
|
let manifest = new DOMApplicationManifest(jsonManifest, app.origin);
|
||||||
|
|
||||||
if (manifest.appcache_path) {
|
if (manifest.appcache_path) {
|
||||||
appObject.installState = "pending";
|
appObject.installState = "pending";
|
||||||
appObject.downloadAvailable = true;
|
appObject.downloadAvailable = true;
|
||||||
appObject.downloading = true;
|
appObject.downloading = true;
|
||||||
appObject.downloadsize = 0;
|
appObject.downloadSize = 0;
|
||||||
|
appObject.readyToApplyDownload = false;
|
||||||
|
} else if (manifest.package_path) {
|
||||||
|
appObject.installState = "pending";
|
||||||
|
appObject.downloadAvailable = true;
|
||||||
|
appObject.downloading = true;
|
||||||
|
appObject.downloadSize = manifest.size;
|
||||||
appObject.readyToApplyDownload = false;
|
appObject.readyToApplyDownload = false;
|
||||||
} else {
|
} else {
|
||||||
appObject.installState = "installed";
|
appObject.installState = "installed";
|
||||||
@ -778,9 +802,13 @@ let DOMApplicationRegistry = {
|
|||||||
appObject.readyToApplyDownload = false;
|
appObject.readyToApplyDownload = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
appObject.name = app.manifest.name;
|
appObject.name = manifest.name;
|
||||||
|
|
||||||
this.webapps[id] = appObject;
|
this.webapps[id] = appObject;
|
||||||
|
["installState", "downloadAvailable",
|
||||||
|
"downloading", "downloadSize", "readyToApplyDownload"].forEach(function(aProp) {
|
||||||
|
aData.app[aProp] = appObject[aProp];
|
||||||
|
});
|
||||||
|
|
||||||
if (!aFromSync)
|
if (!aFromSync)
|
||||||
this._saveApps((function() {
|
this._saveApps((function() {
|
||||||
@ -790,11 +818,16 @@ let DOMApplicationRegistry = {
|
|||||||
}).bind(this));
|
}).bind(this));
|
||||||
|
|
||||||
#ifdef MOZ_SYS_MSG
|
#ifdef MOZ_SYS_MSG
|
||||||
this._registerSystemMessages(app.manifest, app);
|
if (!aData.isPackage) {
|
||||||
this._registerActivities(app.manifest, app);
|
this._registerSystemMessages(app.manifest, app);
|
||||||
|
this._registerActivities(app.manifest, app);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
this.startOfflineCacheDownload(manifest, appObject, aProfileDir);
|
this.startOfflineCacheDownload(manifest, appObject, aProfileDir);
|
||||||
|
if (manifest.package_path) {
|
||||||
|
this.downloadPackage(manifest, appObject);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_nextLocalId: function() {
|
_nextLocalId: function() {
|
||||||
@ -811,6 +844,14 @@ let DOMApplicationRegistry = {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_appIdForManifestURL: function(aURI) {
|
||||||
|
for (let id in this.webapps) {
|
||||||
|
if (this.webapps[id].manifestURL == aURI)
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
makeAppId: function() {
|
makeAppId: function() {
|
||||||
let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
||||||
return uuidGenerator.generateUUID().toString();
|
return uuidGenerator.generateUUID().toString();
|
||||||
@ -838,6 +879,9 @@ let DOMApplicationRegistry = {
|
|||||||
// the manifest file used to be named manifest.json, so fallback on this.
|
// the manifest file used to be named manifest.json, so fallback on this.
|
||||||
let baseDir = (this.webapps[id].removable ? DIRECTORY_NAME : "coreAppsDir");
|
let baseDir = (this.webapps[id].removable ? DIRECTORY_NAME : "coreAppsDir");
|
||||||
let file = FileUtils.getFile(baseDir, ["webapps", id, "manifest.webapp"], true);
|
let file = FileUtils.getFile(baseDir, ["webapps", id, "manifest.webapp"], true);
|
||||||
|
if (!file.exists()) {
|
||||||
|
file = FileUtils.getFile(baseDir, ["webapps", id, "update.webapp"], true);
|
||||||
|
}
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file = FileUtils.getFile(baseDir, ["webapps", id, "manifest.json"], true);
|
file = FileUtils.getFile(baseDir, ["webapps", id, "manifest.json"], true);
|
||||||
}
|
}
|
||||||
@ -851,7 +895,7 @@ let DOMApplicationRegistry = {
|
|||||||
}).bind(this));
|
}).bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
installPackage: function(aData, aMm) {
|
downloadPackage: function(aManifest, aApp) {
|
||||||
// Here are the steps when installing a package:
|
// Here are the steps when installing a package:
|
||||||
// - create a temp directory where to store the app.
|
// - create a temp directory where to store the app.
|
||||||
// - download the zip in this directory.
|
// - download the zip in this directory.
|
||||||
@ -860,31 +904,22 @@ let DOMApplicationRegistry = {
|
|||||||
// - add the new app to the registry.
|
// - add the new app to the registry.
|
||||||
// If we fail at any step, we backout the previous ones and return an error.
|
// If we fail at any step, we backout the previous ones and return an error.
|
||||||
|
|
||||||
let id;
|
debug(JSON.stringify(aApp));
|
||||||
let manifestURL = "jar:" + aData.url + "!manifest.webapp";
|
|
||||||
// Check if we reinstall a known application.
|
|
||||||
for (let appId in this.webapps) {
|
|
||||||
if (this.webapps[appId].manifestURL == manifestURL) {
|
|
||||||
id = appId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// New application.
|
let id = this._appIdForManifestURL(aApp.manifestURL);
|
||||||
if (!id) {
|
let app = this.webapps[id];
|
||||||
id = this.makeAppId();
|
|
||||||
}
|
|
||||||
|
|
||||||
let dir = FileUtils.getDir("TmpD", ["webapps", id], true, true);
|
|
||||||
|
|
||||||
// Removes the directory we created, and sends an error to the DOM side.
|
// Removes the directory we created, and sends an error to the DOM side.
|
||||||
function cleanup(aError) {
|
function cleanup(aError) {
|
||||||
|
debug("Cleanup: " + aError);
|
||||||
|
let dir = FileUtils.getDir("TmpD", ["webapps", id], true, true);
|
||||||
try {
|
try {
|
||||||
dir.remove(true);
|
dir.remove(true);
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
aMm.sendAsyncMessage("Webapps:Install:Return:KO",
|
this.broadcastMessage("Webapps:PackageEvent",
|
||||||
{ oid: aData.oid,
|
{ type: "error",
|
||||||
requestID: aData.requestID,
|
manifestURL: aApp.manifestURL,
|
||||||
error: aError });
|
error: aError});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInferedStatus() {
|
function getInferedStatus() {
|
||||||
@ -928,7 +963,40 @@ let DOMApplicationRegistry = {
|
|||||||
return (getAppManifestStatus(aManifest) <= getInferedStatus());
|
return (getAppManifestStatus(aManifest) <= getInferedStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
NetUtil.asyncFetch(aData.url, function(aInput, aResult, aRequest) {
|
debug("About to download " + aManifest.fullPackagePath());
|
||||||
|
|
||||||
|
let requestChannel = NetUtil.newChannel(aManifest.fullPackagePath())
|
||||||
|
.QueryInterface(Ci.nsIHttpChannel);
|
||||||
|
this.downloads[aApp.manifestURL] =
|
||||||
|
{ channel:requestChannel,
|
||||||
|
appId: id,
|
||||||
|
previousState: "pending"
|
||||||
|
};
|
||||||
|
requestChannel.notificationCallbacks = {
|
||||||
|
QueryInterface: function notifQI(aIID) {
|
||||||
|
if (aIID.equals(Ci.nsISupports) ||
|
||||||
|
aIID.equals(Ci.nsIProgressEventSink))
|
||||||
|
return this;
|
||||||
|
|
||||||
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||||
|
},
|
||||||
|
getInterface: function notifGI(aIID) {
|
||||||
|
return this.QueryInterface(aIID);
|
||||||
|
},
|
||||||
|
onProgress: function notifProgress(aRequest, aContext,
|
||||||
|
aProgress, aProgressMax) {
|
||||||
|
debug("onProgress: " + aProgress + "/" + aProgressMax);
|
||||||
|
app.progress = aProgress;
|
||||||
|
DOMApplicationRegistry.broadcastMessage("Webapps:PackageEvent",
|
||||||
|
{ type: "progress",
|
||||||
|
manifestURL: aApp.manifestURL,
|
||||||
|
progress: aProgress });
|
||||||
|
},
|
||||||
|
onStatus: function notifStatus(aRequest, aContext, aStatus, aStatusArg) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
NetUtil.asyncFetch(requestChannel,
|
||||||
|
function(aInput, aResult, aRequest) {
|
||||||
if (!Components.isSuccessCode(aResult)) {
|
if (!Components.isSuccessCode(aResult)) {
|
||||||
// We failed to fetch the zip.
|
// We failed to fetch the zip.
|
||||||
cleanup("NETWORK_ERROR");
|
cleanup("NETWORK_ERROR");
|
||||||
@ -944,23 +1012,7 @@ let DOMApplicationRegistry = {
|
|||||||
cleanup("DOWNLOAD_ERROR");
|
cleanup("DOWNLOAD_ERROR");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Build a data structure to call the webapps confirmation dialog :
|
|
||||||
// - load the manifest from the zip
|
|
||||||
// - set data.app.(origin, install_origin, manifestURL, manifest, receipts, categories)
|
|
||||||
// - call notifyObservers(this, "webapps-ask-install", JSON.stringify(msg));
|
|
||||||
let msg = {
|
|
||||||
from: aData.from,
|
|
||||||
oid: aData.oid,
|
|
||||||
requestID: aData.requestID,
|
|
||||||
app: {
|
|
||||||
packageId: id,
|
|
||||||
installOrigin: aData.installOrigin,
|
|
||||||
origin: "app://" + id,
|
|
||||||
manifestURL: manifestURL,
|
|
||||||
receipts: aData.receipts,
|
|
||||||
categories: aData.categories
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
|
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
|
||||||
.createInstance(Ci.nsIZipReader);
|
.createInstance(Ci.nsIZipReader);
|
||||||
try {
|
try {
|
||||||
@ -970,19 +1022,50 @@ let DOMApplicationRegistry = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let istream = zipReader.getInputStream("manifest.webapp");
|
let istream = zipReader.getInputStream("manifest.webapp");
|
||||||
msg.app.manifest = JSON.parse(NetUtil.readInputStreamToString(istream,
|
|
||||||
istream.available()) || "");
|
// Obtain a converter to read from a UTF-8 encoded input stream.
|
||||||
if (!AppsUtils.checkManifest(msg.app.manifest, aData.installOrigin)) {
|
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
||||||
|
.createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||||
|
converter.charset = "UTF-8";
|
||||||
|
|
||||||
|
let manifest = JSON.parse(converter.ConvertToUnicode(NetUtil.readInputStreamToString(istream,
|
||||||
|
istream.available()) || ""));
|
||||||
|
|
||||||
|
if (!AppsUtils.checkManifest(manifest, aApp.installOrigin)) {
|
||||||
throw "INVALID_MANIFEST";
|
throw "INVALID_MANIFEST";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkAppStatus(msg.app.manifest)) {
|
if (!checkAppStatus(manifest)) {
|
||||||
throw "INVALID_SECURITY_LEVEL";
|
throw "INVALID_SECURITY_LEVEL";
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.app.appStatus = getAppStatus(msg.app.manifest);
|
// Success! Move the zip out of TmpD.
|
||||||
Services.obs.notifyObservers(this, "webapps-ask-install",
|
let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
|
||||||
JSON.stringify(msg));
|
zipFile.moveTo(dir, "application.zip");
|
||||||
|
let tmpDir = FileUtils.getDir("TmpD", ["webapps", id], true, true);
|
||||||
|
try {
|
||||||
|
tmpDir.remove(true);
|
||||||
|
} catch(e) { }
|
||||||
|
|
||||||
|
// Save the manifest
|
||||||
|
let manFile = dir.clone();
|
||||||
|
manFile.append("manifest.webapp");
|
||||||
|
DOMApplicationRegistry._writeFile(manFile,
|
||||||
|
JSON.stringify(manifest),
|
||||||
|
function() { });
|
||||||
|
// Set state and fire events.
|
||||||
|
app.installState = "installed";
|
||||||
|
app.dowloading = false;
|
||||||
|
app.dowloadavailable = false;
|
||||||
|
DOMApplicationRegistry._saveApps(function() {
|
||||||
|
debug("About to fire Webapps:PackageEvent");
|
||||||
|
DOMApplicationRegistry.broadcastMessage("Webapps:PackageEvent",
|
||||||
|
{ type: "installed",
|
||||||
|
manifestURL: aApp.manifestURL,
|
||||||
|
app: app,
|
||||||
|
manifest: manifest });
|
||||||
|
delete DOMApplicationRegistry.downloads[aApp.manifestURL]
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// XXX we may need new error messages.
|
// XXX we may need new error messages.
|
||||||
cleanup(e);
|
cleanup(e);
|
||||||
@ -1142,7 +1225,7 @@ let DOMApplicationRegistry = {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
let id = this._appId(aOrigin);
|
let id = this._appId(aOrigin);
|
||||||
if (!id) {
|
if (!id || this.webapps[id].installState == "pending") {
|
||||||
aCallback(null);
|
aCallback(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1495,6 +1578,14 @@ DOMApplicationManifest.prototype = {
|
|||||||
return this._localeProp("orientation");
|
return this._localeProp("orientation");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get package_path() {
|
||||||
|
return this._localeProp("package_path");
|
||||||
|
},
|
||||||
|
|
||||||
|
get size() {
|
||||||
|
return this._manifest["size"] || 0;
|
||||||
|
},
|
||||||
|
|
||||||
iconURLForSize: function(aSize) {
|
iconURLForSize: function(aSize) {
|
||||||
let icons = this._localeProp("icons");
|
let icons = this._localeProp("icons");
|
||||||
if (!icons)
|
if (!icons)
|
||||||
@ -1538,6 +1629,11 @@ DOMApplicationManifest.prototype = {
|
|||||||
fullAppcachePath: function() {
|
fullAppcachePath: function() {
|
||||||
let appcachePath = this._localeProp("appcache_path");
|
let appcachePath = this._localeProp("appcache_path");
|
||||||
return this._origin.resolve(appcachePath ? appcachePath : "");
|
return this._origin.resolve(appcachePath ? appcachePath : "");
|
||||||
|
},
|
||||||
|
|
||||||
|
fullPackagePath: function() {
|
||||||
|
let packagePath = this._localeProp("package_path");
|
||||||
|
return this._origin.resolve(packagePath ? packagePath : "");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user