Backed out changeset 8a2d8c34d905 (bug 796198) because of mochitest-chrome failures

This commit is contained in:
Ehsan Akhgari 2012-12-10 20:56:28 -05:00
Родитель 83d08fa86c
Коммит a2e323dd48
2 изменённых файлов: 130 добавлений и 155 удалений

Просмотреть файл

@ -34,6 +34,14 @@ function WebappsRegistry() {
WebappsRegistry.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) {
let msg = aMessage.json;
if (msg.oid != this._id)
@ -88,27 +96,66 @@ WebappsRegistry.prototype = {
this._validateScheme(aURL);
let installURL = this._window.location.href;
let installOrigin = this._getOrigin(installURL);
let request = this.createRequest();
let requestID = this.getRequestId(request);
let receipts = (aParams && aParams.receipts &&
Array.isArray(aParams.receipts)) ? aParams.receipts
: [];
let categories = (aParams && 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;
cpmm.sendAsyncMessage("Webapps:Install",
{ app: {
installOrigin: this._getOrigin(installURL),
origin: this._getOrigin(aURL),
manifestURL: aURL,
receipts: receipts,
categories: categories
},
from: installURL,
oid: this._id,
requestID: requestID
});
xhr.addEventListener("load", (function() {
if (xhr.status == 200) {
if (!AppsUtils.checkManifestContentType(installOrigin, this._getOrigin(aURL),
xhr.getResponseHeader("content-type"))) {
Services.DOMRequest.fireError(request, "INVALID_MANIFEST");
return;
}
let manifest;
try {
manifest = JSON.parse(xhr.responseText, installOrigin);
} 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;
},
@ -156,31 +203,73 @@ WebappsRegistry.prototype = {
// mozIDOMApplicationRegistry2 implementation
installPackage: function(aURL, aParams) {
let installURL = this._window.location.href;
let installOrigin = this._getOrigin(installURL);
this._validateScheme(aURL);
let installURL = this._window.location.href;
let request = this.createRequest();
let requestID = this.getRequestId(request);
let receipts = (aParams && aParams.receipts &&
Array.isArray(aParams.receipts)) ? aParams.receipts
: [];
let categories = (aParams && aParams.categories &&
Array.isArray(aParams.categories)) ? aParams.categories
: [];
cpmm.sendAsyncMessage("Webapps:InstallPackage",
{ app: {
installOrigin: this._getOrigin(installURL),
origin: this._getOrigin(aURL),
manifestURL: aURL,
receipts: receipts,
categories: categories
},
from: installURL,
oid: this._id,
requestID: requestID,
isPackage: true
});
let receipts = (aParams && aParams.receipts &&
Array.isArray(aParams.receipts)) ? aParams.receipts : [];
let categories = (aParams && 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() {
if (xhr.status == 200) {
if (!AppsUtils.checkManifestContentType(installOrigin, this._getOrigin(aURL),
xhr.getResponseHeader("content-type"))) {
Services.DOMRequest.fireError(request, "INVALID_MANIFEST");
return;
}
let manifest;
try {
manifest = JSON.parse(xhr.responseText, installOrigin);
} catch(e) {
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;
},

Просмотреть файл

@ -734,8 +734,7 @@ this.DOMApplicationRegistry = {
switch (aMessage.name) {
case "Webapps:Install":
// always ask for UI to install
this.doInstall(msg, mm);
//Services.obs.notifyObservers(mm, "webapps-ask-install", JSON.stringify(msg));
Services.obs.notifyObservers(mm, "webapps-ask-install", JSON.stringify(msg));
break;
case "Webapps:GetSelf":
this.getSelf(msg, mm);
@ -762,7 +761,8 @@ this.DOMApplicationRegistry = {
mm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg);
break;
case "Webapps:InstallPackage":
this.doInstallPackage(msg, mm);
// always ask for UI to install
Services.obs.notifyObservers(mm, "webapps-ask-install", JSON.stringify(msg));
break;
case "Webapps:GetBasePath":
return this.webapps[msg.id].basePath;
@ -1205,120 +1205,6 @@ this.DOMApplicationRegistry = {
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) {
let packageId = aData.app.packageId;
if (packageId) {