Bug 1208257 - [webext] extension.json (r=kmag)

This commit is contained in:
Bill McCloskey 2015-11-25 15:16:57 -08:00
Родитель 9e01a18c0b
Коммит 1b98762630
6 изменённых файлов: 198 добавлений и 16 удалений

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

@ -65,6 +65,7 @@ ExtensionManagement.registerScript("chrome://extensions/content/ext-storage.js")
ExtensionManagement.registerScript("chrome://extensions/content/ext-test.js");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/cookies.json");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/extension.json");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/extension_types.json");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/i18n.json");
ExtensionManagement.registerSchema("chrome://extensions/content/schemas/idle.json");

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

@ -466,11 +466,12 @@ class TypeProperty extends Entry {
// care of validating parameter lists (i.e., handling of optional
// parameters and parameter type checking).
class CallEntry extends Entry {
constructor(namespaceName, name, parameters) {
constructor(namespaceName, name, parameters, allowAmbiguousOptionalArguments) {
super();
this.namespaceName = namespaceName;
this.name = name;
this.parameters = parameters;
this.allowAmbiguousOptionalArguments = allowAmbiguousOptionalArguments;
}
throwError(global, msg) {
@ -519,9 +520,15 @@ class CallEntry extends Entry {
return check(parameterIndex + 1, argIndex + 1);
};
let success = check(0, 0);
if (!success) {
this.throwError(global, "Incorrect argument types");
if (this.allowAmbiguousOptionalArguments) {
// When this option is set, it's up to the implementation to
// parse arguments.
return args;
} else {
let success = check(0, 0);
if (!success) {
this.throwError(global, "Incorrect argument types");
}
}
// Now we normalize (and fully type check) all non-omitted arguments.
@ -544,8 +551,8 @@ class CallEntry extends Entry {
// Represents a "function" defined in a schema namespace.
class FunctionEntry extends CallEntry {
constructor(namespaceName, name, type, unsupported) {
super(namespaceName, name, type.parameters);
constructor(namespaceName, name, type, unsupported, allowAmbiguousOptionalArguments) {
super(namespaceName, name, type.parameters, allowAmbiguousOptionalArguments);
this.unsupported = unsupported;
}
@ -738,7 +745,9 @@ this.Schemas = {
if ("value" in prop) {
this.register(namespaceName, name, new ValueProperty(name, prop.value));
} else {
let type = this.parseType(namespaceName, prop);
// We ignore the "optional" attribute on properties since we
// don't inject anything here anyway.
let type = this.parseType(namespaceName, prop, ["optional"]);
this.register(namespaceName, name, new TypeProperty(name, type));
}
},
@ -749,8 +758,10 @@ this.Schemas = {
let f = new FunctionEntry(namespaceName, fun.name,
this.parseType(namespaceName, fun,
["name", "unsupported", "deprecated", "returns"]),
fun.unsupported || false);
["name", "unsupported", "deprecated", "returns",
"allowAmbiguousOptionalArguments"]),
fun.unsupported || false,
fun.allowAmbiguousOptionalArguments || false);
this.register(namespaceName, fun.name, f);
},

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

@ -106,7 +106,7 @@ extensions.on("shutdown", (type, extension) => {
});
/* eslint-enable mozilla/balanced-listeners */
extensions.registerAPI((extension, context) => {
extensions.registerSchemaAPI("extension", null, (extension, context) => {
return {
extension: {
getBackgroundPage: function() {

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

@ -1,6 +1,6 @@
"use strict";
extensions.registerAPI((extension, context) => {
extensions.registerSchemaAPI("extension", null, (extension, context) => {
return {
extension: {
getURL: function(url) {
@ -11,14 +11,12 @@ extensions.registerAPI((extension, context) => {
let result = Cu.cloneInto([], context.cloneScope);
for (let view of extension.views) {
if (fetchProperties && "type" in fetchProperties) {
if (view.type != fetchProperties.type) {
if (fetchProperties !== null) {
if (fetchProperties.type !== null && view.type != fetchProperties.type) {
continue;
}
}
if (fetchProperties && "windowId" in fetchProperties) {
if (view.windowId != fetchProperties.windowId) {
if (fetchProperties.windowId !== null && view.windowId != fetchProperties.windowId) {
continue;
}
}

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

@ -0,0 +1,171 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
{
"namespace": "extension",
"description": "The <code>browser.extension</code> API has utilities that can be used by any extension page. It includes support for exchanging messages between an extension and its content scripts or between extensions, as described in detail in $(topic:messaging)[Message Passing].",
"properties": {
"lastError": {
"type": "object",
"optional": true,
"description": "Set for the lifetime of a callback if an ansychronous extension api has resulted in an error. If no error has occured lastError will be <var>undefined</var>.",
"properties": {
"message": { "type": "string", "description": "Description of the error that has taken place." }
}
},
"inIncognitoContext": {
"type": "boolean",
"optional": true,
"description": "True for content scripts running inside incognito tabs, and for extension pages running inside an incognito process. The latter only applies to extensions with 'split' incognito_behavior."
}
},
"types": [
{
"id": "ViewType",
"type": "string",
"enum": ["tab", "notification", "popup"],
"description": "The type of extension view."
}
],
"functions": [
{
"name": "getURL",
"type": "function",
"description": "Converts a relative path within an extension install directory to a fully-qualified URL.",
"parameters": [
{
"type": "string",
"name": "path",
"description": "A path to a resource within an extension expressed relative to its install directory."
}
],
"returns": {
"type": "string",
"description": "The fully-qualified URL to the resource."
}
},
{
"name": "getViews",
"type": "function",
"description": "Returns an array of the JavaScript 'window' objects for each of the pages running inside the current extension.",
"parameters": [
{
"type": "object",
"name": "fetchProperties",
"optional": true,
"properties": {
"type": {
"$ref": "ViewType",
"optional": true,
"description": "The type of view to get. If omitted, returns all views (including background pages and tabs). Valid values: 'tab', 'notification', 'popup'."
},
"windowId": {
"type": "integer",
"optional": true,
"description": "The window to restrict the search to. If omitted, returns all views."
}
}
}
],
"returns": {
"type": "array",
"description": "Array of global objects",
"items": {
"name": "viewGlobals",
"type": "object",
"isInstanceOf": "Window",
"additionalProperties": { "type": "any" }
}
}
},
{
"name": "getBackgroundPage",
"type": "function",
"description": "Returns the JavaScript 'window' object for the background page running inside the current extension. Returns null if the extension has no background page.",
"parameters": [],
"returns": {
"type": "object",
"optional": true,
"name": "backgroundPageGlobal",
"isInstanceOf": "Window",
"additionalProperties": { "type": "any" }
}
},
{
"name": "isAllowedIncognitoAccess",
"unsupported": true,
"type": "function",
"description": "Retrieves the state of the extension's access to Incognito-mode (as determined by the user-controlled 'Allowed in Incognito' checkbox.",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "isAllowedAccess",
"type": "boolean",
"description": "True if the extension has access to Incognito mode, false otherwise."
}
]
}
]
},
{
"name": "isAllowedFileSchemeAccess",
"unsupported": true,
"type": "function",
"description": "Retrieves the state of the extension's access to the 'file://' scheme (as determined by the user-controlled 'Allow access to File URLs' checkbox.",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "isAllowedAccess",
"type": "boolean",
"description": "True if the extension can access the 'file://' scheme, false otherwise."
}
]
}
]
},
{
"name": "setUpdateUrlData",
"unsupported": true,
"type": "function",
"description": "Sets the value of the ap CGI parameter used in the extension's update URL. This value is ignored for extensions that are hosted in the browser vendor's store.",
"parameters": [
{"type": "string", "name": "data", "maxLength": 1024}
]
}
],
"events": [
{
"name": "onRequest",
"unsupported": true,
"deprecated": "Please use $(ref:runtime.onMessage).",
"type": "function",
"description": "Fired when a request is sent from either an extension process or a content script.",
"parameters": [
{"name": "request", "type": "any", "optional": true, "description": "The request sent by the calling script."},
{"name": "sender", "$ref": "runtime.MessageSender" },
{"name": "sendResponse", "type": "function", "description": "Function to call (at most once) when you have a response. The argument should be any JSON-ifiable object, or undefined if there is no response. If you have more than one <code>onRequest</code> listener in the same document, then only one may send a response." }
]
},
{
"name": "onRequestExternal",
"unsupported": true,
"deprecated": "Please use $(ref:runtime.onMessageExternal).",
"type": "function",
"description": "Fired when a request is sent from another extension.",
"parameters": [
{"name": "request", "type": "any", "optional": true, "description": "The request sent by the calling script."},
{"name": "sender", "$ref": "runtime.MessageSender" },
{"name": "sendResponse", "type": "function", "description": "Function to call when you have a response. The argument should be any JSON-ifiable object, or undefined if there is no response." }
]
}
]
}
]

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

@ -5,6 +5,7 @@
toolkit.jar:
% content extensions %content/extensions/
content/extensions/schemas/cookies.json
content/extensions/schemas/extension.json
content/extensions/schemas/extension_types.json
content/extensions/schemas/i18n.json
content/extensions/schemas/idle.json