зеркало из https://github.com/mozilla/gecko-dev.git
Bug 796198 - Use the right cookie jar when downloading package and minimanifest for packaged apps - Part 1: move the xhr to Webapps.jsm [r=sicking]
This commit is contained in:
Родитель
bfc2a71ade
Коммит
c3dabcbd2b
|
@ -34,14 +34,6 @@ function WebappsRegistry() {
|
||||||
WebappsRegistry.prototype = {
|
WebappsRegistry.prototype = {
|
||||||
__proto__: DOMRequestIpcHelper.prototype,
|
__proto__: DOMRequestIpcHelper.prototype,
|
||||||
|
|
||||||
// Hosted apps can't be trusted or certified, so just check that the
|
|
||||||
// manifest doesn't ask for those.
|
|
||||||
checkAppStatus: function(aManifest) {
|
|
||||||
let manifestStatus = aManifest.type || "web";
|
|
||||||
return (Services.prefs.getBoolPref("dom.mozApps.dev_mode") ||
|
|
||||||
manifestStatus === "web");
|
|
||||||
},
|
|
||||||
|
|
||||||
receiveMessage: function(aMessage) {
|
receiveMessage: function(aMessage) {
|
||||||
let msg = aMessage.json;
|
let msg = aMessage.json;
|
||||||
if (msg.oid != this._id)
|
if (msg.oid != this._id)
|
||||||
|
@ -96,66 +88,27 @@ WebappsRegistry.prototype = {
|
||||||
this._validateScheme(aURL);
|
this._validateScheme(aURL);
|
||||||
|
|
||||||
let installURL = this._window.location.href;
|
let installURL = this._window.location.href;
|
||||||
let installOrigin = this._getOrigin(installURL);
|
|
||||||
let request = this.createRequest();
|
let request = this.createRequest();
|
||||||
let requestID = this.getRequestId(request);
|
let requestID = this.getRequestId(request);
|
||||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
let receipts = (aParams && aParams.receipts &&
|
||||||
xhr.open("GET", aURL, true);
|
Array.isArray(aParams.receipts)) ? aParams.receipts
|
||||||
xhr.channel.loadFlags |= Ci.nsIRequest.VALIDATE_ALWAYS;
|
: [];
|
||||||
|
let categories = (aParams && aParams.categories &&
|
||||||
|
Array.isArray(aParams.categories)) ? aParams.categories
|
||||||
|
: [];
|
||||||
|
|
||||||
xhr.addEventListener("load", (function() {
|
cpmm.sendAsyncMessage("Webapps:Install",
|
||||||
if (xhr.status == 200) {
|
{ app: {
|
||||||
if (!AppsUtils.checkManifestContentType(installOrigin, this._getOrigin(aURL),
|
installOrigin: this._getOrigin(installURL),
|
||||||
xhr.getResponseHeader("content-type"))) {
|
origin: this._getOrigin(aURL),
|
||||||
Services.DOMRequest.fireError(request, "INVALID_MANIFEST");
|
manifestURL: aURL,
|
||||||
return;
|
receipts: receipts,
|
||||||
}
|
categories: categories
|
||||||
|
},
|
||||||
let manifest;
|
from: installURL,
|
||||||
try {
|
oid: this._id,
|
||||||
manifest = JSON.parse(xhr.responseText, installOrigin);
|
requestID: requestID
|
||||||
} catch (e) {
|
});
|
||||||
Services.DOMRequest.fireError(request, "MANIFEST_PARSE_ERROR");
|
|
||||||
Cu.reportError("Error installing app from: " + installOrigin + ": " + "MANIFEST_PARSE_ERROR");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!AppsUtils.checkManifest(manifest)) {
|
|
||||||
Services.DOMRequest.fireError(request, "INVALID_MANIFEST");
|
|
||||||
Cu.reportError("Error installing app from: " + installOrigin + ": " + "INVALID_MANIFEST");
|
|
||||||
} else if (!AppsUtils.checkInstallAllowed(manifest, installOrigin)) {
|
|
||||||
Services.DOMRequest.fireError(request, "INSTALL_FROM_DENIED");
|
|
||||||
Cu.reportError("Error installing app from: " + installOrigin + ": " + "INSTALL_FROM_DENIED");
|
|
||||||
} else if (!this.checkAppStatus(manifest)) {
|
|
||||||
Services.DOMRequest.fireError(request, "INVALID_SECURITY_LEVEL");
|
|
||||||
Cu.reportError("Error installing app, '" + manifest.name + "': " + "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:Install", { app: { installOrigin: installOrigin,
|
|
||||||
origin: this._getOrigin(aURL),
|
|
||||||
manifestURL: aURL,
|
|
||||||
manifest: manifest,
|
|
||||||
etag: etag,
|
|
||||||
receipts: receipts,
|
|
||||||
categories: categories },
|
|
||||||
from: installURL,
|
|
||||||
oid: this._id,
|
|
||||||
requestID: requestID });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Services.DOMRequest.fireError(request, "MANIFEST_URL_ERROR");
|
|
||||||
Cu.reportError("Error installing app from: " + installOrigin + ": " + "MANIFEST_URL_ERROR");
|
|
||||||
}
|
|
||||||
}).bind(this), false);
|
|
||||||
|
|
||||||
xhr.addEventListener("error", (function() {
|
|
||||||
Services.DOMRequest.fireError(request, "NETWORK_ERROR");
|
|
||||||
Cu.reportError("Error installing app from: " + installOrigin + ": " + "NETWORK_ERROR");
|
|
||||||
}).bind(this), false);
|
|
||||||
|
|
||||||
xhr.send(null);
|
|
||||||
return request;
|
return request;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -203,73 +156,31 @@ WebappsRegistry.prototype = {
|
||||||
// mozIDOMApplicationRegistry2 implementation
|
// mozIDOMApplicationRegistry2 implementation
|
||||||
|
|
||||||
installPackage: function(aURL, aParams) {
|
installPackage: function(aURL, aParams) {
|
||||||
let installURL = this._window.location.href;
|
|
||||||
let installOrigin = this._getOrigin(installURL);
|
|
||||||
this._validateScheme(aURL);
|
this._validateScheme(aURL);
|
||||||
|
|
||||||
|
let installURL = this._window.location.href;
|
||||||
let request = this.createRequest();
|
let request = this.createRequest();
|
||||||
let requestID = this.getRequestId(request);
|
let requestID = this.getRequestId(request);
|
||||||
|
|
||||||
let receipts = (aParams && aParams.receipts &&
|
let receipts = (aParams && aParams.receipts &&
|
||||||
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
|
||||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
: [];
|
||||||
xhr.open("GET", aURL, true);
|
|
||||||
xhr.channel.loadFlags |= Ci.nsIRequest.VALIDATE_ALWAYS;
|
|
||||||
|
|
||||||
xhr.addEventListener("load", (function() {
|
cpmm.sendAsyncMessage("Webapps:InstallPackage",
|
||||||
if (xhr.status == 200) {
|
{ app: {
|
||||||
if (!AppsUtils.checkManifestContentType(installOrigin, this._getOrigin(aURL),
|
installOrigin: this._getOrigin(installURL),
|
||||||
xhr.getResponseHeader("content-type"))) {
|
origin: this._getOrigin(aURL),
|
||||||
Services.DOMRequest.fireError(request, "INVALID_MANIFEST");
|
manifestURL: aURL,
|
||||||
return;
|
receipts: receipts,
|
||||||
}
|
categories: categories
|
||||||
|
},
|
||||||
let manifest;
|
from: installURL,
|
||||||
try {
|
oid: this._id,
|
||||||
manifest = JSON.parse(xhr.responseText, installOrigin);
|
requestID: requestID,
|
||||||
} catch(e) {
|
isPackage: true
|
||||||
Services.DOMRequest.fireError(request, "MANIFEST_PARSE_ERROR");
|
});
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!(AppsUtils.checkManifest(manifest) &&
|
|
||||||
manifest.package_path)) {
|
|
||||||
Services.DOMRequest.fireError(request, "INVALID_MANIFEST");
|
|
||||||
} else if (!AppsUtils.checkInstallAllowed(manifest, installOrigin)) {
|
|
||||||
Services.DOMRequest.fireError(request, "INSTALL_FROM_DENIED");
|
|
||||||
} 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;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -734,7 +734,8 @@ this.DOMApplicationRegistry = {
|
||||||
switch (aMessage.name) {
|
switch (aMessage.name) {
|
||||||
case "Webapps:Install":
|
case "Webapps:Install":
|
||||||
// always ask for UI to install
|
// always ask for UI to install
|
||||||
Services.obs.notifyObservers(mm, "webapps-ask-install", JSON.stringify(msg));
|
this.doInstall(msg, mm);
|
||||||
|
//Services.obs.notifyObservers(mm, "webapps-ask-install", JSON.stringify(msg));
|
||||||
break;
|
break;
|
||||||
case "Webapps:GetSelf":
|
case "Webapps:GetSelf":
|
||||||
this.getSelf(msg, mm);
|
this.getSelf(msg, mm);
|
||||||
|
@ -761,8 +762,7 @@ this.DOMApplicationRegistry = {
|
||||||
mm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg);
|
mm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg);
|
||||||
break;
|
break;
|
||||||
case "Webapps:InstallPackage":
|
case "Webapps:InstallPackage":
|
||||||
// always ask for UI to install
|
this.doInstallPackage(msg, mm);
|
||||||
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;
|
||||||
|
@ -1205,6 +1205,120 @@ this.DOMApplicationRegistry = {
|
||||||
xhr.send(null);
|
xhr.send(null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Downloads the manifest and run checks, then eventually triggers the
|
||||||
|
// installation UI.
|
||||||
|
doInstall: function doInstall(aData, aMm) {
|
||||||
|
let sendError = function sendError(aError) {
|
||||||
|
aData.error = aError;
|
||||||
|
aMm.sendAsyncMessage("Webapps:Install:Return:KO", aData);
|
||||||
|
Cu.reportError("Error installing app from: " + app.installOrigin +
|
||||||
|
": " + aError);
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
|
// Hosted apps can't be trusted or certified, so just check that the
|
||||||
|
// manifest doesn't ask for those.
|
||||||
|
function checkAppStatus(aManifest) {
|
||||||
|
let manifestStatus = aManifest.type || "web";
|
||||||
|
return (Services.prefs.getBoolPref("dom.mozApps.dev_mode") ||
|
||||||
|
manifestStatus === "web");
|
||||||
|
}
|
||||||
|
|
||||||
|
let app = aData.app;
|
||||||
|
|
||||||
|
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||||
|
.createInstance(Ci.nsIXMLHttpRequest);
|
||||||
|
xhr.open("GET", app.manifestURL, true);
|
||||||
|
xhr.channel.loadFlags |= Ci.nsIRequest.VALIDATE_ALWAYS;
|
||||||
|
xhr.responseType = "json";
|
||||||
|
xhr.addEventListener("load", (function() {
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
if (!AppsUtils.checkManifestContentType(app.installOrigin, app.origin,
|
||||||
|
xhr.getResponseHeader("content-type"))) {
|
||||||
|
sendError("INVALID_MANIFEST");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.manifest = xhr.response;
|
||||||
|
if (!app.manifest) {
|
||||||
|
sendError("MANIFEST_PARSE_ERROR");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!AppsUtils.checkManifest(app.manifest)) {
|
||||||
|
sendError("INVALID_MANIFEST");
|
||||||
|
} else if (!AppsUtils.checkInstallAllowed(app.manifest, app.installOrigin)) {
|
||||||
|
sendError("INSTALL_FROM_DENIED");
|
||||||
|
} else if (!checkAppStatus(app.manifest)) {
|
||||||
|
sendError("INVALID_SECURITY_LEVEL");
|
||||||
|
} else {
|
||||||
|
app.etag = xhr.getResponseHeader("Etag");
|
||||||
|
Services.obs.notifyObservers(aMm, "webapps-ask-install",
|
||||||
|
JSON.stringify(aData));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sendError("MANIFEST_URL_ERROR");
|
||||||
|
}
|
||||||
|
}).bind(this), false);
|
||||||
|
|
||||||
|
xhr.addEventListener("error", (function() {
|
||||||
|
sendError("NETWORK_ERROR");
|
||||||
|
}).bind(this), false);
|
||||||
|
|
||||||
|
xhr.send(null);
|
||||||
|
},
|
||||||
|
|
||||||
|
doInstallPackage: function doInstallPackage(aData, aMm) {
|
||||||
|
let sendError = function sendError(aError) {
|
||||||
|
aData.error = aError;
|
||||||
|
aMm.sendAsyncMessage("Webapps:Install:Return:KO", aData);
|
||||||
|
Cu.reportError("Error installing packaged app from: " +
|
||||||
|
app.installOrigin + ": " + aError);
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
|
let app = aData.app;
|
||||||
|
|
||||||
|
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||||
|
.createInstance(Ci.nsIXMLHttpRequest);
|
||||||
|
xhr.open("GET", app.manifestURL, true);
|
||||||
|
xhr.channel.loadFlags |= Ci.nsIRequest.VALIDATE_ALWAYS;
|
||||||
|
xhr.responseType = "json";
|
||||||
|
|
||||||
|
xhr.addEventListener("load", (function() {
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
if (!AppsUtils.checkManifestContentType(app.installOrigin, app.origin,
|
||||||
|
xhr.getResponseHeader("content-type"))) {
|
||||||
|
sendError("INVALID_MANIFEST");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let manifest = app.updateManifest = xhr.response;
|
||||||
|
if (!manifest) {
|
||||||
|
sendError("MANIFEST_PARSE_ERROR");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(AppsUtils.checkManifest(manifest) &&
|
||||||
|
manifest.package_path)) {
|
||||||
|
sendError("INVALID_MANIFEST");
|
||||||
|
} else if (!AppsUtils.checkInstallAllowed(manifest, app.installOrigin)) {
|
||||||
|
sendError("INSTALL_FROM_DENIED");
|
||||||
|
} else {
|
||||||
|
app.etag = xhr.getResponseHeader("Etag");
|
||||||
|
Services.obs.notifyObservers(aMm, "webapps-ask-install",
|
||||||
|
JSON.stringify(aData));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sendError("MANIFEST_URL_ERROR");
|
||||||
|
}
|
||||||
|
}).bind(this), false);
|
||||||
|
|
||||||
|
xhr.addEventListener("error", (function() {
|
||||||
|
sendError("NETWORK_ERROR");
|
||||||
|
}).bind(this), false);
|
||||||
|
|
||||||
|
xhr.send(null);
|
||||||
|
},
|
||||||
|
|
||||||
denyInstall: function(aData) {
|
denyInstall: function(aData) {
|
||||||
let packageId = aData.app.packageId;
|
let packageId = aData.app.packageId;
|
||||||
if (packageId) {
|
if (packageId) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче