Bug 1244474: [webext] Part 2 - Make extra manifest properties/permissions warnings instead of errors. r?billm
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -353,16 +353,20 @@ GlobalManager = {
let inject = (extension, context) => {
let chromeObj = Cu.createObjectIn(contentWindow, {defineAs: "browser"});
contentWindow.wrappedJSObject.chrome = contentWindow.wrappedJSObject.browser;
let api = Management.generateAPIs(extension, context, Management.apis);
injectAPI(api, chromeObj);
let schemaApi = Management.generateAPIs(extension, context, Management.schemaApis);
let schemaWrapper = {
+ get cloneScope() {
+ return context.cloneScope;
+ },
+
callFunction(ns, name, args) {
return schemaApi[ns][name].apply(null, args);
},
getProperty(ns, name) {
return schemaApi[ns][name];
},
@@ -561,16 +565,20 @@ ExtensionData.prototype = {
return Promise.all([
this.readJSON("manifest.json"),
Management.lazyInit(),
]).then(([manifest]) => {
let context = {
url: this.baseURI && this.baseURI.spec,
principal: this.principal,
+
+ logError: error => {
+ this.logger.warn(`Loading extension '${this.id}': Reading manifest: ${error}`);
+ },
};
let normalized = Schemas.normalize(manifest, "manifest.WebExtensionManifest", context);
if (normalized.error) {
this.manifestError(normalized.error);
this.manifest = manifest;
} else {
this.manifest = normalized.value;
--- a/toolkit/components/extensions/schemas/manifest.json
+++ b/toolkit/components/extensions/schemas/manifest.json
@@ -94,25 +94,38 @@
"content_scripts": {
"type": "array",
"optional": true,
"items": { "$ref": "ContentScript" }
},
"permissions": {
"type": "array",
- "items": { "$ref": "Permission" },
+ "items": {
+ "choices": [
+ { "$ref": "Permission" },
+ {
+ "type": "string",
+ "deprecated": "Unknown permission ${value}"
+ }
+ ]
+ },
"optional": true
},
"web_accessible_resources": {
"type": "array",
"items": { "type": "string" },
"optional": true
}
+ },
+
+ "additionalProperties": {
+ "type": "any",
+ "deprecated": "An unexpected property was found in the WebExtension manifest"
}
},
{
"id": "Permission",
"choices": [
{
"type": "string",
"enum": [
--- a/toolkit/components/extensions/test/mochitest/mochitest.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest.ini
@@ -20,16 +20,17 @@ support-files =
file_sample.html
redirection.sjs
file_privilege_escalation.html
file_ext_test_api_injection.js
file_permission_xhr.html
[test_ext_simple.html]
[test_ext_schema.html]
+skip-if = e10s # Uses a console montitor. Actual code does not depend on e10s.
[test_ext_geturl.html]
[test_ext_contentscript.html]
skip-if = buildapp == 'b2g' # runat != document_idle is not supported.
[test_ext_contentscript_create_iframe.html]
[test_ext_contentscript_api_injection.html]
[test_ext_i18n_css.html]
[test_ext_generate.html]
[test_ext_localStorage.html]
--- a/toolkit/components/extensions/test/mochitest/test_ext_schema.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_schema.html
@@ -8,29 +8,63 @@
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="text/javascript">
"use strict";
-add_task(function* testSchema() {
+add_task(function* testEmptySchema() {
function background() {
browser.test.assertTrue(!("manifest" in browser), "browser.manifest is not defined");
browser.test.notifyPass("schema");
}
let extension = ExtensionTestUtils.loadExtension({
background: `(${background})()`,
});
yield extension.startup();
yield extension.awaitFinish("schema");
yield extension.unload();
});
+
+add_task(function* testUnknownProperties() {
+ function background() {
+ browser.test.notifyPass("loaded");
+ }
+
+ let extension = ExtensionTestUtils.loadExtension({
+ manifest: {
+ permissions: ["unknownPermission"],
+
+ unknown_property: {},
+ },
+
+ background: `(${background})()`,
+ });
+
+ let messages = [
+ {message: /processing permissions\.0: Unknown permission "unknownPermission"/},
+ {message: /processing unknown_property: An unexpected property was found in the WebExtension manifest/},
+ ];
+
+ let waitForConsole = new Promise(resolve => {
+ SimpleTest.monitorConsole(resolve, messages);
+ });
+
+ yield extension.startup();
+
+ yield extension.awaitFinish("loaded");
+
+ yield extension.unload();
+
+ SimpleTest.endMonitorConsole();
+ yield waitForConsole;
+});
</script>
</body>
</html>