Bug 1242561 - [webext] Import missing events API schema file. r?kmag draft
authorLuca Greco <lgreco@mozilla.com>
Wed, 20 Apr 2016 05:17:13 +0200
changeset 354294 4cfcd71c6397140f76ee30140b88f84847062dab
parent 354242 19b8851d8d4c19997ecc73960f4de8d90c981c28
child 354295 790fbc1da4f2a76817b7f123835aca2104387560
child 354305 b16fd9398caad427f82af4e4d606debdb5d99985
push id16023
push userluca.greco@alcacoop.it
push dateWed, 20 Apr 2016 14:55:50 +0000
reviewerskmag
bugs1242561
milestone48.0a1
Bug 1242561 - [webext] Import missing events API schema file. r?kmag MozReview-Commit-ID: HgQJTfwb5w0
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/Schemas.jsm
toolkit/components/extensions/schemas/events.json
toolkit/components/extensions/schemas/jar.mn
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -83,16 +83,17 @@ ExtensionManagement.registerSchema("chro
 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");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/notifications.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/runtime.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/storage.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/test.json");
+ExtensionManagement.registerSchema("chrome://extensions/content/schemas/events.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/web_navigation.json");
 ExtensionManagement.registerSchema("chrome://extensions/content/schemas/web_request.json");
 
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 var {
   BaseContext,
   LocaleData,
   Messenger,
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -1141,17 +1141,19 @@ this.Schemas = {
         format = FORMATS[type.format];
       }
       return new StringType(type, enumeration,
                             type.minLength || 0,
                             type.maxLength || Infinity,
                             pattern,
                             format);
     } else if (type.type == "object" && "functions" in type) {
-      checkTypeProperties("functions");
+      // TODO: additionalProperties is currently unused, added to the allowed to be able
+      // to load the event.json file.
+      checkTypeProperties("functions", "additionalProperties");
 
       // The path we pass in here is only used for error messages.
       let functions = type.functions.map(fun => this.parseFunction(path.concat(type.id), fun));
 
       return new SubModuleType(functions);
     } else if (type.type == "object") {
       let parseProperty = (type, extraProps = []) => {
         return {
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/schemas/events.json
@@ -0,0 +1,323 @@
+// 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": "events",
+    "description": "The <code>chrome.events</code> namespace contains common types used by APIs dispatching events to notify you when something interesting happens.",
+    "types": [
+      {
+        "id": "Rule",
+        "type": "object",
+        "description": "Description of a declarative rule for handling events.",
+        "properties": {
+          "id": {
+            "type": "string",
+            "optional": true,
+            "description": "Optional identifier that allows referencing this rule."
+          },
+          "tags": {
+            "type": "array",
+            "items": {"type": "string"},
+            "optional": true,
+            "description":  "Tags can be used to annotate rules and perform operations on sets of rules."
+          },
+          "conditions": {
+            "type": "array",
+            "items": {"type": "any"},
+            "description": "List of conditions that can trigger the actions."
+          },
+          "actions": {
+            "type": "array",
+            "items": {"type": "any"},
+            "description": "List of actions that are triggered if one of the condtions is fulfilled."
+          },
+          "priority": {
+            "type": "integer",
+            "optional": true,
+            "description": "Optional priority of this rule. Defaults to 100."
+          }
+        }
+      },
+      {
+        "id": "Event",
+        "type": "object",
+        "description": "An object which allows the addition and removal of listeners for a Chrome event.",
+        "additionalProperties": {"type": "any"},
+        "functions": [
+          {
+            "name": "addListener",
+            "type": "function",
+            "description": "Registers an event listener <em>callback</em> to an event.",
+            "parameters": [
+              {
+                "name": "callback",
+                "type": "function",
+                "description": "Called when an event occurs. The parameters of this function depend on the type of event."
+              }
+            ]
+          },
+          {
+            "name": "removeListener",
+            "type": "function",
+            "description": "Deregisters an event listener <em>callback</em> from an event.",
+            "parameters": [
+              {
+                "name": "callback",
+                "type": "function",
+                "description": "Listener that shall be unregistered."
+              }
+            ]
+          },
+          {
+            "name": "hasListener",
+            "type": "function",
+            "parameters": [
+              {
+                "name": "callback",
+                "type": "function",
+                "description": "Listener whose registration status shall be tested."
+              }
+            ],
+            "returns": {
+              "type": "boolean",
+              "description": "True if <em>callback</em> is registered to the event."
+            }
+          },
+          {
+            "name": "hasListeners",
+            "type": "function",
+            "parameters": [],
+            "returns": {
+              "type": "boolean",
+              "description": "True if any event listeners are registered to the event."
+            }
+          },
+          {
+            "name": "addRules",
+            "unsupported": true,
+            "type": "function",
+            "description": "Registers rules to handle events.",
+            "parameters": [
+              {
+                "name": "eventName",
+                "type": "string",
+                "description": "Name of the event this function affects."
+              },
+              {
+                "name": "webViewInstanceId",
+                "type": "integer",
+                "description": "If provided, this is an integer that uniquely identfies the <webview> associated with this function call."
+              },
+              {
+                "name": "rules",
+                "type": "array",
+                "items": {"$ref": "Rule"},
+                "description": "Rules to be registered. These do not replace previously registered rules."
+              },
+              {
+                "name": "callback",
+                "optional": true,
+                "type": "function",
+                "parameters": [
+                  {
+                    "name": "rules",
+                    "type": "array",
+                    "items": {"$ref": "Rule"},
+                    "description": "Rules that were registered, the optional parameters are filled with values."
+                  }
+                ],
+                "description": "Called with registered rules."
+              }
+            ]
+          },
+          {
+            "name": "getRules",
+            "unsupported": true,
+            "type": "function",
+            "description": "Returns currently registered rules.",
+            "parameters": [
+              {
+                "name": "eventName",
+                "type": "string",
+                "description": "Name of the event this function affects."
+              },
+              {
+                "name": "webViewInstanceId",
+                "type": "integer",
+                "description": "If provided, this is an integer that uniquely identfies the <webview> associated with this function call."
+              },
+              {
+                "name": "ruleIdentifiers",
+                "optional": true,
+                "type": "array",
+                "items": {"type": "string"},
+                "description": "If an array is passed, only rules with identifiers contained in this array are returned."
+              },
+              {
+                "name": "callback",
+                "type": "function",
+                "parameters": [
+                  {
+                    "name": "rules",
+                    "type": "array",
+                    "items": {"$ref": "Rule"},
+                    "description": "Rules that were registered, the optional parameters are filled with values."
+                  }
+                ],
+                "description": "Called with registered rules."
+              }
+            ]
+          },
+          {
+            "name": "removeRules",
+            "unsupported": true,
+            "type": "function",
+            "description": "Unregisters currently registered rules.",
+            "parameters": [
+              {
+                "name": "eventName",
+                "type": "string",
+                "description": "Name of the event this function affects."
+              },
+              {
+                "name": "webViewInstanceId",
+                "type": "integer",
+                "description": "If provided, this is an integer that uniquely identfies the <webview> associated with this function call."
+              },
+              {
+                "name": "ruleIdentifiers",
+                "optional": true,
+                "type": "array",
+                "items": {"type": "string"},
+                "description": "If an array is passed, only rules with identifiers contained in this array are unregistered."
+              },
+              {
+                "name": "callback",
+                "optional": true,
+                "type": "function",
+                "parameters": [],
+                "description": "Called when rules were unregistered."
+              }
+            ]
+          }
+        ]
+      },
+      {
+        "id": "UrlFilter",
+        "type": "object",
+        "description": "Filters URLs for various criteria. See <a href='events#filtered'>event filtering</a>. All criteria are case sensitive.",
+        "properties": {
+          "hostContains": {
+            "type": "string",
+            "description": "Matches if the host name of the URL contains a specified string. To test whether a host name component has a prefix 'foo', use hostContains: '.foo'. This matches 'www.foobar.com' and 'foo.com', because an implicit dot is added at the beginning of the host name. Similarly, hostContains can be used to match against component suffix ('foo.') and to exactly match against components ('.foo.'). Suffix- and exact-matching for the last components need to be done separately using hostSuffix, because no implicit dot is added at the end of the host name.",
+            "optional": true
+          },
+          "hostEquals": {
+            "type": "string",
+            "description": "Matches if the host name of the URL is equal to a specified string.",
+            "optional": true
+          },
+          "hostPrefix": {
+            "type": "string",
+            "description": "Matches if the host name of the URL starts with a specified string.",
+            "optional": true
+          },
+          "hostSuffix": {
+            "type": "string",
+            "description": "Matches if the host name of the URL ends with a specified string.",
+            "optional": true
+          },
+          "pathContains": {
+            "type": "string",
+            "description": "Matches if the path segment of the URL contains a specified string.",
+            "optional": true
+          },
+          "pathEquals": {
+            "type": "string",
+            "description": "Matches if the path segment of the URL is equal to a specified string.",
+            "optional": true
+          },
+          "pathPrefix": {
+            "type": "string",
+            "description": "Matches if the path segment of the URL starts with a specified string.",
+            "optional": true
+          },
+          "pathSuffix": {
+            "type": "string",
+            "description": "Matches if the path segment of the URL ends with a specified string.",
+            "optional": true
+          },
+          "queryContains": {
+            "type": "string",
+            "description": "Matches if the query segment of the URL contains a specified string.",
+            "optional": true
+          },
+          "queryEquals": {
+            "type": "string",
+            "description": "Matches if the query segment of the URL is equal to a specified string.",
+            "optional": true
+          },
+          "queryPrefix": {
+            "type": "string",
+            "description": "Matches if the query segment of the URL starts with a specified string.",
+            "optional": true
+          },
+          "querySuffix": {
+            "type": "string",
+            "description": "Matches if the query segment of the URL ends with a specified string.",
+            "optional": true
+          },
+          "urlContains": {
+            "type": "string",
+            "description": "Matches if the URL (without fragment identifier) contains a specified string. Port numbers are stripped from the URL if they match the default port number.",
+            "optional": true
+          },
+          "urlEquals": {
+            "type": "string",
+            "description": "Matches if the URL (without fragment identifier) is equal to a specified string. Port numbers are stripped from the URL if they match the default port number.",
+            "optional": true
+          },
+          "urlMatches": {
+            "type": "string",
+            "description": "Matches if the URL (without fragment identifier) matches a specified regular expression. Port numbers are stripped from the URL if they match the default port number. The regular expressions use the <a href=\"https://github.com/google/re2/blob/master/doc/syntax.txt\">RE2 syntax</a>.",
+            "optional": true
+          },
+          "originAndPathMatches": {
+            "type": "string",
+            "description": "Matches if the URL without query segment and fragment identifier matches a specified regular expression. Port numbers are stripped from the URL if they match the default port number. The regular expressions use the <a href=\"https://github.com/google/re2/blob/master/doc/syntax.txt\">RE2 syntax</a>.",
+            "optional": true
+          },
+          "urlPrefix": {
+            "type": "string",
+            "description": "Matches if the URL (without fragment identifier) starts with a specified string. Port numbers are stripped from the URL if they match the default port number.",
+            "optional": true
+          },
+          "urlSuffix": {
+            "type": "string",
+            "description": "Matches if the URL (without fragment identifier) ends with a specified string. Port numbers are stripped from the URL if they match the default port number.",
+            "optional": true
+          },
+          "schemes": {
+            "type": "array",
+            "description": "Matches if the scheme of the URL is equal to any of the schemes specified in the array.",
+            "optional": true,
+            "items": { "type": "string" }
+          },
+          "ports": {
+            "type": "array",
+            "description": "Matches if the port of the URL is contained in any of the specified port lists. For example <code>[80, 443, [1000, 1200]]</code> matches all requests on port 80, 443 and in the range 1000-1200.",
+            "optional": true,
+            "items": {
+              "choices": [
+                {"type": "integer", "description": "A specific port."},
+                {"type": "array", "minItems": 2, "maxItems": 2, "items": {"type": "integer"}, "description": "A pair of integers identiying the start and end (both inclusive) of a port range."}
+              ]
+            }
+          }
+        }
+      }
+    ]
+  }
+]
--- a/toolkit/components/extensions/schemas/jar.mn
+++ b/toolkit/components/extensions/schemas/jar.mn
@@ -2,16 +2,17 @@
 # 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/.
 
 toolkit.jar:
 % content extensions %content/extensions/
     content/extensions/schemas/alarms.json
     content/extensions/schemas/cookies.json
     content/extensions/schemas/downloads.json
+    content/extensions/schemas/events.json
     content/extensions/schemas/extension.json
     content/extensions/schemas/extension_types.json
     content/extensions/schemas/i18n.json
     content/extensions/schemas/idle.json
     content/extensions/schemas/manifest.json
     content/extensions/schemas/notifications.json
     content/extensions/schemas/runtime.json
     content/extensions/schemas/storage.json