Back out 557609749a57 (bug 1150160) for Windows bustage

This commit is contained in:
Phil Ringnalda 2015-04-03 21:37:14 -07:00
parent 4f562ebb78
commit ec54508366
2 changed files with 19 additions and 81 deletions

View File

@ -26,9 +26,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "PermissionsInstaller",
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm");
this.EXPORTED_SYMBOLS = ["ImportExport"];
const kAppArchiveMimeType = "application/openwebapp+zip";
@ -228,12 +225,7 @@ this.ImportExport = {
// |file| now points to application.zip, open it.
let appZipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
.createInstance(Ci.nsIZipReader);
try {
appZipReader.open(file);
} catch(e) {
throw "InvalidZip";
}
appZipReader.open(file);
if (!appZipReader.hasEntry("manifest.webapp")) {
throw "NoManifestFound";
}
@ -241,32 +233,10 @@ this.ImportExport = {
return [readObjectFromZip(appZipReader, "manifest.webapp"), file];
},
// Returns a promise that resolves to the temp file path.
_writeBlobToTempFile: function(aBlob) {
// Save the blob to a temp file.
let path;
return new Promise((aResolve, aReject) => {
let reader = Cc['@mozilla.org/files/filereader;1']
.createInstance(Ci.nsIDOMFileReader);
reader.onloadend = () => {
path = OS.Path.join(OS.Constants.Path.tmpDir, "app-blob.zip");
OS.File.openUnique(path).then(file => {
path = file.path;
return OS.File.writeAtomic(path,
new Uint8Array(reader.result),
{ tmpPath: path + ".tmp" })
})
.then(() => aResolve(path))
.catch(aReject);
}
reader.readAsArrayBuffer(aBlob);
});
},
// Imports a blob, returning a Promise that resolves to
// [manifestURL, manifest]
// Possible errors are:
// NoBlobFound, InvalidZip, MissingMetadataFile, IncorrectVersion,
// NoBlobFound, UnsupportedBlobArchive, MissingMetadataFile, IncorrectVersion,
// AppAlreadyInstalled, DontImportCertifiedApps, InvalidManifest,
// InvalidPrivilegeLevel, InvalidOrigin, DuplicateOrigin
import: Task.async(function*(aBlob) {
@ -276,15 +246,15 @@ this.ImportExport = {
throw "NoBlobFound";
}
let isFileBlob = aBlob instanceof Ci.nsIDOMFile;
let isFile = aBlob instanceof Ci.nsIDOMFile;
if (!isFile) {
// XXX: TODO Store the blob on disk.
throw "UnsupportedBlobArchive";
}
// We can't QI the DOMFile to nsIFile, so we need to create one.
let zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
if (!isFileBlob) {
let path = yield this._writeBlobToTempFile(aBlob);
zipFile.initWithPath(path);
} else {
zipFile.initWithPath(aBlob.mozFullPath);
}
zipFile.initWithPath(aBlob.mozFullPath);
debug("Importing from " + zipFile.path);
@ -293,13 +263,8 @@ this.ImportExport = {
let manifest;
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
.createInstance(Ci.nsIZipReader);
zipReader.open(zipFile);
try {
try {
zipReader.open(zipFile);
} catch(e) {
throw "InvalidZip";
}
// Do some sanity checks on the metadata.json and manifest.webapp files.
if (!zipReader.hasEntry("metadata.json")) {
throw "MissingMetadataFile";
@ -466,9 +431,6 @@ this.ImportExport = {
throw e;
} finally {
zipReader.close();
if (!isFileBlob) {
zipFile.remove(false);
}
}
return [meta.manifestURL, manifest];
@ -477,37 +439,31 @@ this.ImportExport = {
// Extracts the manifest from a blob, returning a Promise that resolves to
// the manifest
// Possible errors are:
// NoBlobFound, InvalidZip, MissingMetadataFile.
// NoBlobFound, UnsupportedBlobArchive, MissingMetadataFile.
extractManifest: Task.async(function*(aBlob) {
// First, do we even have a blob?
if (!aBlob || !aBlob instanceof Ci.nsIDOMBlob) {
throw "NoBlobFound";
}
let isFileBlob = aBlob instanceof Ci.nsIDOMFile;
// We can't QI the DOMFile to nsIFile, so we need to create one.
let zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
if (!isFileBlob) {
let path = yield this._writeBlobToTempFile(aBlob);
zipFile.initWithPath(path);
} else {
zipFile.initWithPath(aBlob.mozFullPath);
let isFile = aBlob instanceof Ci.nsIDOMFile;
if (!isFile) {
// XXX: TODO Store the blob on disk.
throw "UnsupportedBlobArchive";
}
// We can't QI the DOMFile to nsIFile, so we need to create one.
let zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
zipFile.initWithPath(aBlob.mozFullPath);
debug("extractManifest from " + zipFile.path);
// Do some sanity checks on the metadata.json and manifest.webapp files.
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
.createInstance(Ci.nsIZipReader);
zipReader.open(zipFile);
let manifest;
try {
try {
zipReader.open(zipFile);
} catch(e) {
throw "InvalidZip";
}
if (zipReader.hasEntry("manifest.webapp")) {
manifest = readObjectFromZip(zipReader, "manifest.webapp");
if (!manifest) {
@ -528,9 +484,6 @@ this.ImportExport = {
}
} finally {
zipReader.close();
if (!isFileBlob) {
zipFile.remove(false);
}
}
return manifest;

View File

@ -299,21 +299,6 @@ function runTest() {
is(request.result, miniManifestURL, "Packaged App uninstalled.");
navigator.mozApps.mgmt.onuninstall = null;
// Check that we support memory backed blobs.
// The blob here is not a valid app, but that's fine for this test.
let blob = new Blob(["This is a test blob."]);
navigator.mozApps.mgmt.import(blob)
.then(() => {
ok(false, "This is not an app!");
continueTest();
})
.catch(aError => {
is(aError.name, "InvalidZip", "Memory blob processed.");
continueTest();
});
yield undefined;
// Check that we restored the app registry.
request = navigator.mozApps.mgmt.getAll();
request.onerror = cbError;