Bug 1262003 - Back out changeset 983702f6874c. r=kmag

MozReview-Commit-ID: 10GVdKTFjiR

--HG--
extra : transplant_source : %15%C7%90%93%95%00%8BST%09e%F0%A6%94M%3C%E2%AF%F2%9A
This commit is contained in:
Andrew Swan 2016-04-04 16:09:32 -07:00
Родитель b194792316
Коммит a1d4cd1add
3 изменённых файлов: 27 добавлений и 108 удалений

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

@ -671,34 +671,16 @@ ExtensionData.prototype = {
});
},
// Reads the extension's |manifest.json| file and optional |mozilla.json|,
// and stores the parsed and merged contents in |this.manifest|.
// Reads the extension's |manifest.json| file, and stores its
// parsed contents in |this.manifest|.
readManifest() {
return Promise.all([
this.readJSON("manifest.json"),
this.readJSON("mozilla.json").catch(err => null),
Management.lazyInit(),
]).then(([manifest, mozManifest]) => {
]).then(([manifest]) => {
this.manifest = manifest;
this.rawManifest = manifest;
if (mozManifest) {
if (typeof mozManifest != "object") {
this.logger.warn(`Loading extension '${this.id}': mozilla.json has unexpected type ${typeof mozManifest}`);
} else {
Object.keys(mozManifest).forEach(key => {
if (key != "applications") {
throw new Error(`Illegal property "${key}" in mozilla.json`);
}
if (key in manifest) {
this.logger.warn(`Ignoring property "${key}" from mozilla.json`);
} else {
manifest[key] = mozManifest[key];
}
});
}
}
if (manifest && manifest.default_locale) {
return this.initLocale();
}

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

@ -273,17 +273,16 @@ function createAppInfo(ID, name, version, platformVersion="1.0") {
gAppInfo = tmp.getAppInfo();
}
function getManifestURIForBundle(file, manifest="manifest.json") {
function getManifestURIForBundle(file) {
if (file.isDirectory()) {
let path = file.clone();
path.append("install.rdf");
if (path.exists()) {
return NetUtil.newURI(path);
file.append("install.rdf");
if (file.exists()) {
return NetUtil.newURI(file);
}
path.leafName = manifest;
if (path.exists()) {
return NetUtil.newURI(path);
file.leafName = "manifest.json";
if (file.exists()) {
return NetUtil.newURI(file);
}
throw new Error("No manifest file present");
@ -299,8 +298,8 @@ function getManifestURIForBundle(file, manifest="manifest.json") {
return NetUtil.newURI("jar:" + uri.spec + "!/" + "install.rdf");
}
if (zip.hasEntry(manifest)) {
return NetUtil.newURI("jar:" + uri.spec + "!/" + manifest);
if (zip.hasEntry("manifest.json")) {
return NetUtil.newURI("jar:" + uri.spec + "!/" + "manifest.json");
}
throw new Error("No manifest file present");
@ -342,12 +341,8 @@ let getIDForManifest = Task.async(function*(manifestURI) {
return rdfID.QueryInterface(AM_Ci.nsIRDFLiteral).Value;
}
else {
try {
let manifest = JSON.parse(data);
return manifest.applications.gecko.id;
} catch (err) {
return null;
}
let manifest = JSON.parse(data);
return manifest.applications.gecko.id;
}
});
@ -385,15 +380,6 @@ function overrideCertDB(handler) {
let id = yield getIDForManifest(manifestURI);
if (!id) {
manifestURI = getManifestURIForBundle(file, "mozilla.json");
id = yield getIDForManifest(manifestURI);
}
if (!id) {
throw new Error("Cannot find addon ID");
}
// Make sure to close the open zip file or it will be locked.
if (file.isFile()) {
Services.obs.notifyObservers(file, "flush-cache-entry", "cert-override");
@ -1126,7 +1112,7 @@ function writeInstallRDFForExtension(aData, aDir, aId, aExtraFile) {
* An optional string to override the default installation aId
* @return A file pointing to where the extension was installed
*/
function writeWebManifestForExtension(aData, aDir, aId = undefined, aMozData = undefined) {
function writeWebManifestForExtension(aData, aDir, aId = undefined) {
if (!aId)
aId = aData.applications.gecko.id;
@ -1136,26 +1122,19 @@ function writeWebManifestForExtension(aData, aDir, aId = undefined, aMozData = u
if (!dir.exists())
dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
function writeOne(filename, raw) {
let file = dir.clone();
file.append(filename);
if (file.exists())
file.remove(true);
let file = dir.clone();
file.append("manifest.json");
if (file.exists())
file.remove(true);
let data = JSON.stringify(raw);
let fos = AM_Cc["@mozilla.org/network/file-output-stream;1"].
createInstance(AM_Ci.nsIFileOutputStream);
fos.init(file,
FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
FileUtils.PERMS_FILE, 0);
fos.write(data, data.length);
fos.close();
}
writeOne("manifest.json", aData);
if (aMozData) {
writeOne("mozilla.json", aMozData);
}
let data = JSON.stringify(aData);
let fos = AM_Cc["@mozilla.org/network/file-output-stream;1"].
createInstance(AM_Ci.nsIFileOutputStream);
fos.init(file,
FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
FileUtils.PERMS_FILE, 0);
fos.write(data, data.length);
fos.close();
return dir;
}
@ -1171,13 +1150,6 @@ function writeWebManifestForExtension(aData, aDir, aId = undefined, aMozData = u
zipW.open(file, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE);
zipW.addEntryStream("manifest.json", 0, AM_Ci.nsIZipWriter.COMPRESSION_NONE,
stream, false);
if (aMozData) {
let mozStream = AM_Cc["@mozilla.org/io/string-input-stream;1"].
createInstance(AM_Ci.nsIStringInputStream);
mozStream.setData(JSON.stringify(aMozData), -1);
zipW.addEntryStream("mozilla.json", 0, AM_Ci.nsIZipWriter.COMPRESSION_NONE,
mozStream, false);
}
zipW.close();
return file;

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

@ -159,41 +159,6 @@ add_task(function*() {
yield promiseRestartManager();
});
// applications.gecko.id may be in mozilla.json
add_task(function* test_mozilla_json() {
writeWebManifestForExtension({
name: "Web Extension Name",
version: "1.0",
manifest_version: 2,
}, profileDir, ID, {
applications: {
gecko: {
id: ID
}
}
});
yield promiseRestartManager();
let addon = yield promiseAddonByID(ID);
do_check_neq(addon, null);
do_check_eq(addon.version, "1.0");
do_check_eq(addon.name, "Web Extension Name");
do_check_true(addon.isCompatible);
do_check_false(addon.appDisabled);
do_check_true(addon.isActive);
do_check_false(addon.isSystem);
do_check_eq(addon.type, "extension");
do_check_eq(addon.signedState, mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_SIGNED : AddonManager.SIGNEDSTATE_NOT_REQUIRED);
let file = getFileForAddon(profileDir, ID);
do_check_true(file.exists());
addon.uninstall();
yield promiseRestartManager();
});
add_task(function* test_manifest_localization() {
const ID = "webextension3@tests.mozilla.org";