Bug 1491274 - Split content script-only userScripts API from ext-userScripts.js and user_scripts.json. r=robwu,mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D6156

--HG--
rename : toolkit/components/extensions/child/ext-userScripts.js => toolkit/components/extensions/child/ext-userScripts-content.js
rename : toolkit/components/extensions/schemas/user_scripts.json => toolkit/components/extensions/schemas/user_scripts_content.json
extra : moz-landing-system : lando
This commit is contained in:
Luca Greco 2018-09-20 17:25:03 +00:00
parent 28fc8336c0
commit 5f865f59f4
8 changed files with 81 additions and 30 deletions

View File

@ -67,11 +67,18 @@ extensions.registerModules({
},
userScripts: {
url: "chrome://extensions/content/child/ext-userScripts.js",
scopes: ["addon_child", "content_child"],
scopes: ["addon_child"],
paths: [
["userScripts"],
],
},
userScriptsContent: {
url: "chrome://extensions/content/child/ext-userScripts-content.js",
scopes: ["content_child"],
paths: [
["userScripts", "setScriptAPIs"],
],
},
webRequest: {
url: "chrome://extensions/content/child/ext-webRequest.js",
scopes: ["addon_child"],

View File

@ -0,0 +1,28 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
var USERSCRIPT_PREFNAME = "extensions.webextensions.userScripts.enabled";
var USERSCRIPT_DISABLED_ERRORMSG = `userScripts APIs are currently experimental and must be enabled with the ${USERSCRIPT_PREFNAME} preference.`;
XPCOMUtils.defineLazyPreferenceGetter(this, "userScriptsEnabled", USERSCRIPT_PREFNAME, false);
var {
ExtensionError,
} = ExtensionUtils;
this.userScriptsContent = class extends ExtensionAPI {
getAPI(context) {
return {
userScripts: {
setScriptAPIs(exportedAPIMethods) {
if (!userScriptsEnabled) {
throw new ExtensionError(USERSCRIPT_DISABLED_ERRORMSG);
}
context.setUserScriptAPIs(exportedAPIMethods);
},
},
};
}
};

View File

@ -2,8 +2,8 @@
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const USERSCRIPT_PREFNAME = "extensions.webextensions.userScripts.enabled";
const USERSCRIPT_DISABLED_ERRORMSG = `userScripts APIs are currently experimental and must be enabled with the ${USERSCRIPT_PREFNAME} preference.`;
var USERSCRIPT_PREFNAME = "extensions.webextensions.userScripts.enabled";
var USERSCRIPT_DISABLED_ERRORMSG = `userScripts APIs are currently experimental and must be enabled with the ${USERSCRIPT_PREFNAME} preference.`;
XPCOMUtils.defineLazyPreferenceGetter(this, "userScriptsEnabled", USERSCRIPT_PREFNAME, false);
@ -164,13 +164,6 @@ this.userScripts = class extends ExtensionAPI {
return convertToAPIObject(scriptId, options);
});
},
setScriptAPIs(exportedAPIMethods) {
if (!userScriptsEnabled) {
throw new ExtensionError(USERSCRIPT_DISABLED_ERRORMSG);
}
context.setUserScriptAPIs(exportedAPIMethods);
},
},
};
}

View File

@ -192,11 +192,18 @@
"userScripts": {
"url": "chrome://extensions/content/parent/ext-userScripts.js",
"schema": "chrome://extensions/content/schemas/user_scripts.json",
"scopes": ["addon_parent", "content_parent"],
"scopes": ["addon_parent"],
"paths": [
["userScripts"]
]
},
"userScriptsContent": {
"schema": "chrome://extensions/content/schemas/user_scripts_content.json",
"scopes": ["content_child"],
"paths": [
["userScripts", "setScriptAPIs"]
]
},
"webNavigation": {
"url": "chrome://extensions/content/parent/ext-webNavigation.js",
"schema": "chrome://extensions/content/schemas/web_navigation.json",

View File

@ -49,4 +49,5 @@ toolkit.jar:
content/extensions/child/ext-test.js (child/ext-test.js)
content/extensions/child/ext-toolkit.js (child/ext-toolkit.js)
content/extensions/child/ext-userScripts.js (child/ext-userScripts.js)
content/extensions/child/ext-userScripts-content.js (child/ext-userScripts-content.js)
content/extensions/child/ext-webRequest.js (child/ext-webRequest.js)

View File

@ -37,5 +37,6 @@ toolkit.jar:
content/extensions/schemas/top_sites.json
content/extensions/schemas/types.json
content/extensions/schemas/user_scripts.json
content/extensions/schemas/user_scripts_content.json
content/extensions/schemas/web_navigation.json
content/extensions/schemas/web_request.json

View File

@ -27,14 +27,7 @@
{
"namespace": "userScripts",
"permissions": ["manifest:user_scripts"],
"allowedContexts": ["content"],
"types": [
{
"id": "ExportedAPIMethods",
"type": "object",
"description": "A set of API methods provided by the extensions to its userScripts",
"additionalProperties": { "type": "function" }
},
{
"id": "UserScriptOptions",
"type": "object",
@ -121,18 +114,6 @@
"$ref": "UserScriptOptions"
}
]
},
{
"name": "setScriptAPIs",
"allowedContexts": ["content", "content_only"],
"type": "function",
"description": "Provides a set of custom API methods available to the registered userScripts",
"parameters": [
{
"name": "exportedAPIMethods",
"$ref": "ExportedAPIMethods"
}
]
}
]
}

View File

@ -0,0 +1,33 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
[
{
"namespace": "userScripts",
"permissions": ["manifest:user_scripts"],
"allowedContexts": ["content"],
"types": [
{
"id": "ExportedAPIMethods",
"type": "object",
"description": "A set of API methods provided by the extensions to its userScripts",
"additionalProperties": { "type": "function" }
}
],
"functions": [
{
"name": "setScriptAPIs",
"allowedContexts": ["content", "content_only"],
"type": "function",
"description": "Provides a set of custom API methods available to the registered userScripts",
"parameters": [
{
"name": "exportedAPIMethods",
"$ref": "ExportedAPIMethods"
}
]
}
]
}
]