Files
tubestation/toolkit/components/extensions/webidl-api/ExtensionWebIDL.conf
Rob Wu 136d141805 Bug 1911833 - Skip userScripts in GenerateWebIDLBindings.py r=rpl
Although the bindings generator skips MV2-only APIs at some point
(https://searchfox.org/mozilla-central/rev/1bc0601cc5b3d4c3919d220acbe248221ebce035/toolkit/components/extensions/webidl-api/GenerateWebIDLBindings.py#337-338),
that only happens after loading all schemas. Because user_scripts.json
contains multiple userScripts.register definitions (one for MV2 and one
for MV3), GenerateWebIDLBindings.py raised the following error before
this patch:

> TypeError: Unxpected multiple schema data for API property "userScripts.register" in schema group toolkit

This patch fixes the issue by ignoring the schemas that define the
userScripts API, and now the following test passes again:

```
./mach test toolkit/components/extensions/webidl-api/test/test_all_schemas_smoketest.py
```

Differential Revision: https://phabricator.services.mozilla.com/D227969
2024-11-20 16:50:12 +00:00

112 lines
4.6 KiB
Plaintext

# -*- Mode:Python; tab-width:8; indent-tabs-mode:nil -*- */
# vim: set ts=8 sts=4 et sw=4 tw=80: */
# 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/.
# WebExtension WebIDL API Bindings Configuration, used by the script
# `dom/extensions-webidl/GenerateWebIDLBindingsFromJSONSchema.py`
# to customize the WebIDL generated based on the WebExtensions API JSON Schemas.
#
# Generating the WebIDL definitions for some of the WebExtensions API does require
# some special handling, there are corresponding entries in the configuration tables
# below.
#
# Mapping table between the JSON Schema types (represented as keys of the map)
# and the related WebIDL type (represented by the value in the map).
# Any mapping missing from this table will fallback to use the "any" webidl type
# (See GenerateWebIDLBindings.py WebIDLHelpers.webidl_type_from_mapping method).
#
# NOTE: Please keep this table in alphabetic order (upper and lower case in two
# separate alphabetic orders, group of the upcase ones first).
WEBEXT_TYPES_MAPPING = {
"ExpectedError": "any", # Only used in test.assertThrows/assertRejects
"Port": "ExtensionPort",
"Promise": "Promise<any>",
"StreamFilter": "ExtensionStreamFilter",
"any": "any",
"boolean": "boolean",
"number": "float",
"function": "Function",
"integer": "long",
"object": "any", # TODO: as a follow up we may look into generating webidl dictionaries to achieve a more precise mapping
"runtime.Port": "ExtensionPort",
"string": "DOMString",
"types.Setting": "ExtensionSetting",
}
# Set of the types from the WEBEXT_TYPES_MAPPING that will be threated as primitive
# types (e.g. used to omit optional attribute in the WebIDL methods type signatures).
#
# NOTE: Please keep this table in alphabetic order (upper and lower case in two
# separate alphabetic orders, group of the update ones first).
WEBIDL_PRIMITIVE_TYPES = set([
"DOMString",
"boolean",
"float"
"long",
])
# Mapping table for some APIs that do require special handling and a
# specific stub method should be set in the generated webidl extended
# attribute `WebExtensionStub`.
#
# The key in this map represent the API method name (including the
# API namespace that is part of), the value is the value to set on the
# `WebExtensionStub` webidl extended attribute:
#
# "namespace.methodName": "WebExtensionStubName",
#
# NOTE: Please keep this table in alphabetic order.
WEBEXT_STUBS_MAPPING = {
"dns.resolve": "AsyncAmbiguous",
"runtime.connect": "ReturnsPort",
"runtime.connectNative": "ReturnsPort",
"runtime.getURL": "ReturnsString",
# TODO: Bug 1782690 - This method accepts functions/args so we'll need to
# serialize them.
"scripting.executeScript": "NotImplementedAsync",
"scripting.getRegisteredContentScripts": "AsyncAmbiguous",
"scripting.unregisterContentScripts": "AsyncAmbiguous",
"test.assertEq": "AssertEq",
"test.assertRejects": False, # No WebExtensionStub attribute.
"test.assertThrows": False, # No WebExtensionStub attribute.
"test.withHandlingUserInput": "NotImplementedNoReturn",
}
WEBEXT_WORKER_HIDDEN_SET = set([
"runtime.getFrameId",
"runtime.getBackgroundPage",
])
# Mapping table for the directories where the JSON API schema will be loaded
# from.
WEBEXT_SCHEMADIRS_MAPPING = {
"toolkit": ["toolkit", "components", "extensions", "schemas"],
"browser": ["browser", "components", "extensions", "schemas"],
"mobile": ["mobile", "shared", "components", "extensions", "schemas"],
}
# List of toolkit-level WebExtensions API namespaces that are not included
# in android builds.
#
# NOTE: keep this list in sync with the API namespaces excluded in
# - toolkit/components/extensions/jar.mn
# - toolkit/components/extensions/schemas/jar.mn
WEBEXT_ANDROID_EXCLUDED = [
"captivePortal",
"geckoProfiler",
"identity"
]
WEBEXT_IGNORED_SCHEMA_FILES = [
# The userScripts.register API method is declared twice, for MV2 and MV3.
# This is currently not supported and will raise an error at
# https://searchfox.org/mozilla-central/rev/1bc0601cc5b3d4c3919d220acbe248221ebce035/toolkit/components/extensions/webidl-api/GenerateWebIDLBindings.py#840
# e.g. when running the test_all_jsonschema_load_and_parse_smoketest test
# in test_all_schemas_smoketest.py. Ignore these namespaces for now.
"toolkit/components/extensions/schemas/user_scripts.json",
"toolkit/components/extensions/schemas/user_scripts_content.json",
]