Use returns_async in extension API schemas when callback is specified

Chromium change:
https://source.chromium.org/chromium/chromium/src/+/6a8c35314cd95efb0d218f03d38af6c5fadb03c9

commit 6a8c35314cd95efb0d218f03d38af6c5fadb03c9
Author: Tim Judkins <tjudkins@chromium.org>
Date:   Thu Nov 5 18:02:56 2020 +0000

    [Extensions Bindings] Support returns_async in extension schemas

    (Based on previous work from https://crrev.com/c/2144684 )
    This CL is a starting point for supporting a returns_async parameter in
    Extension schemas, which is a step in supporting promise-based APIs. It
    adds a new property to the Model in json_schema_compiler, returns_async,
    which contains information about what the API function is expected to
    return.

    returns_async is used instead of Model.callback, and can be created
    either from a callback specification or a specific "returns_async"
    entry in the schema.

    It also modifies the doc generation code to handle this new property,
    displaying it as a callback at the end of the schema. This should
    result in there being no visible difference to the docs when an API is
    rolled over to using returns_async, other than previously required
    callbacks being displayed as optional.

    In order to do end-to-end tests, this CL also moves over tabs.create,
    tabs.duplicate and tabs.query to use the new schema format, thereby
    enabling promise support on them.

    Bug: 978538
This commit is contained in:
Emerick Rogul
2024-03-08 14:55:59 -05:00
parent 6db8edeea8
commit 5ed5af75c2
6 changed files with 994 additions and 1059 deletions
File diff suppressed because it is too large Load Diff
+11 -12
View File
@@ -16,18 +16,17 @@
"name": "isSupported",
"type": "function",
"description": "Fetches whether or not Brave Talk is supported",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "supported",
"type": "boolean"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "supported",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}
],
"types": [
+24 -28
View File
@@ -28,39 +28,35 @@
"name": "getBraveThemeList",
"type": "function",
"description": "Get available brave theme list",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called when brave theme list is fetched",
"parameters": [
{
"name": "types",
"type": "string",
"description": "json stringified avalable theme list"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "types",
"type": "string",
"description": "json stringified available theme list"
}
]
},
"does_not_support_promises": "Requires refactoring"
},
{
"name": "getBraveThemeType",
"type": "function",
"description": "Get current brave theme",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called when current brave theme is fetched",
"parameters": [
{
"name": "type",
"type": "string",
"description": "current theme type (Dark or Light)"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "types",
"type": "string",
"description": "current theme type (Dark or Light)"
}
]
},
"does_not_support_promises": "Requires refactoring"
},
{
"name": "setBraveThemeType",
+83 -97
View File
@@ -21,18 +21,16 @@
"name": "shouldPromptForSetup",
"type": "function",
"description": "Called to determine if a brave wallet prompt should be shown to opt into install",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "enabled",
"type": "boolean"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "enabled",
"type": "boolean"
}
]
}
}, {
"name": "notifyWalletUnlock",
"type": "function",
@@ -46,52 +44,45 @@
{
"name": "key",
"type": "binary"
}, {
"name": "seedCallback",
"type": "function",
"name": "callback",
"parameters": [
{
"name": "seed",
"type": "binary"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "seed",
"type": "binary"
}
]
}
}, {
"name": "getProjectID",
"type": "function",
"description": "Called to get the configured infura project ID",
"parameters": [
{
"name": "cb",
"type": "function",
"name": "callback",
"parameters": [
{
"name": "projectID",
"type": "string"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "projectID",
"type": "string"
}
]
}
}, {
"name": "getBraveKey",
"type": "function",
"description": "Called to get the Brave service key",
"parameters": [
{
"name": "cb",
"type": "function",
"name": "callback",
"parameters": [
{
"name": "key",
"type": "string"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "key",
"type": "string"
}
]
}
}, {
"name": "resetWallet",
"type": "function",
@@ -101,66 +92,61 @@
"name": "getWeb3Provider",
"type": "function",
"description": "Called to get the configured web3 provider extension ID",
"parameters": [
{
"name": "cb",
"type": "function",
"name": "callback",
"parameters": [
{
"name": "extensionID",
"type": "string"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "extensionID",
"type": "string"
}
]
}
}, {
"name": "getWeb3ProviderList",
"type": "function",
"description": "Get available web3 providers",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called when brave web3 provider list is fetched",
"parameters": [
{
"name": "types",
"type": "string",
"description": "json stringified avalable web3 provider list"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "types",
"type": "string",
"description": "json stringified avalable web3 provider list"
}
]
}
}, {
"name": "isNativeWalletEnabled",
"type": "function",
"description": "Determine if the native wallet is enabled",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called with a boolean indicating if the native wallet is enabled",
"parameters": [
{
"name": "val",
"type": "boolean"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "val",
"type": "boolean"
}
]
}
}, {
"name": "loadUI",
"type": "function",
"description": "Called when brave://wallet WebUI wants to load the real UI",
"parameters": [
{
"name": "cb",
"type": "function",
"name": "callback",
"parameters": []
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "cb",
"type": "function",
"name": "callback",
"parameters": []
}
]
}
}
],
"types": [
+11 -11
View File
@@ -19,18 +19,18 @@
"name": "id",
"type": "string",
"description": "The extension id to validate"
},
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "valid",
"type": "boolean"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "valid",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}
]
}
+259 -284
View File
@@ -16,39 +16,35 @@
"name": "getIpnsKeysList",
"type": "function",
"description": "Get list of available p2p keys",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called when keys list are fetched",
"parameters": [
{
"name": "keys",
"type": "string",
"description": "json stringified avalable keys list"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "keys",
"type": "string",
"description": "json stringified avalable keys list"
}
],
"does_not_support_promises": "Requires refactoring"
}
},
{
"name": "getIpfsPeersList",
"type": "function",
"description": "Get list of peers",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called when the peers list is fetched",
"parameters": [
{
"name": "peers",
"type": "string",
"description": "json stringified avalable peers list"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "peers",
"type": "string",
"description": "json stringified avalable peers list"
}
],
"does_not_support_promises": "Requires refactoring"
}
},
{
"name": "removeIpfsPeer",
@@ -64,20 +60,19 @@
"name": "address",
"type": "string",
"description": "The address of a peer"
},
{
"name": "callback",
"type": "function",
"description": "Function called when the peer is removed",
"parameters": [
{
"name": "success",
"type": "boolean",
"description": "result of operation"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "success",
"type": "boolean",
"description": "result of operation"
}
],
"does_not_support_promises": "Requires refactoring"
}
},
{
"name": "addIpfsPeer",
@@ -88,20 +83,19 @@
"name": "value",
"type": "string",
"description": "The name of new peer"
},
{
"name": "callback",
"type": "function",
"description": "Function called when peer is created",
"parameters": [
{
"name": "success",
"type": "boolean",
"description": "result of config update operation"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "success",
"type": "boolean",
"description": "result of config update operation"
}
],
"does_not_support_promises": "Requires refactoring"
}
},
{
"name": "addIpnsKey",
@@ -112,20 +106,19 @@
"name": "name",
"type": "string",
"description": "The name of new key"
},
{
"name": "callback",
"type": "function",
"description": "Function called when key is created",
"parameters": [
{
"name": "result",
"type": "string",
"description": "json stringified created key information"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "result",
"type": "string",
"description": "json stringified created key information"
}
],
"does_not_support_promises": "Requires refactoring"
}
},
{
"name": "rotateKey",
@@ -136,20 +129,19 @@
"name": "name",
"type": "string",
"description": "The name of oldkey key"
},
{
"name": "callback",
"type": "function",
"description": "Function called when key is rotated",
"parameters": [
{
"name": "result",
"type": "boolean",
"description": "json stringified created key information"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "result",
"type": "boolean",
"description": "json stringified created key information"
}
],
"does_not_support_promises": "Requires refactoring"
}
},
{
"name": "removeIpnsKey",
@@ -160,140 +152,130 @@
"name": "name",
"type": "string",
"description": "The name of removed key"
},
{
"name": "callback",
"type": "function",
"description": "Function called when key is removed",
"parameters": [
{
"name": "result",
"type": "string",
"description": "removed key name"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "result",
"type": "string",
"description": "removed key name"
}
],
"does_not_support_promises": "Requires refactoring"
}
},
{
"name": "getResolveMethodList",
"type": "function",
"description": "Get methods for resolving IPFS URIs",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called when IPFS resolve methods list are fetched",
"parameters": [
{
"name": "types",
"type": "string",
"description": "json stringified avalable IPFS resolve methods list"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "types",
"type": "string",
"description": "json stringified avalable IPFS resolve methods list"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "getIPFSEnabled",
"type": "function",
"description": "Get to see if the IPFS feature flag is enabled",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called with enabled status",
"parameters": [
{
"name": "enabled",
"type": "boolean"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "enabled",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "getResolveMethodType",
"type": "function",
"description": "Obtains the gateway setting for IPFS",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called with enabled status",
"parameters": [
{
"name": "type",
"type": "string"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "type",
"type": "string"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "launch",
"type": "function",
"description": "Called to launch the IPFS daemon",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "success",
"type": "boolean"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "success",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "shutdown",
"type": "function",
"description": "Called to shutdown the IPFS daemon",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "success",
"type": "boolean"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "success",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "getConfig",
"type": "function",
"description": "Called to get the IPFS config path",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "success",
"type": "boolean"
}, {
"name": "path",
"type": "string"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "success",
"type": "boolean"
},
{
"name": "path",
"type": "string"
}
],
"does_not_support_promises": "Multi-parameter callback"
}
}, {
"name": "getExecutableAvailable",
"type": "function",
"description": "Called to determine if a local node is installed",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "available",
"type": "boolean"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "available",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "resolveIPFSURI",
"type": "function",
@@ -302,17 +284,18 @@
{
"type": "string",
"name": "uri"
}, {
"type": "function",
"name": "callback",
"parameters": [
{
"name": "gateway",
"type": "string"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "gateway",
"type": "string"
}
],
"does_not_support_promises": "Requires refactoring"
}
},
{
"name": "validateGatewayUrl",
@@ -323,37 +306,34 @@
"name": "url",
"type": "string",
"description": "The url to validate"
},
{
"name": "callback",
"type": "function",
"description": "Function called when url is validated",
"parameters": [
{
"name": "result",
"type": "boolean",
"description": "True if gateway is valid otherwise false"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "result",
"type": "boolean",
"description": "True if gateway is valid otherwise false"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "getSettings",
"type": "function",
"description": "Returns list of ipfs settings",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called with settings list",
"parameters": [
{
"name": "settings",
"type": "string"
}
]
}
]
"parameters": [],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "settings",
"type": "string"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "setResolveMethod",
"type": "function",
@@ -363,19 +343,18 @@
"name": "resolve_method",
"type": "string",
"description": "ask/disabled/gateway/local"
},
{
"name": "callback",
"type": "function",
"description": "Function called with status",
"parameters": [
{
"name": "status",
"type": "boolean"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "status",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "setPublicGateway",
"type": "function",
@@ -385,42 +364,40 @@
"name": "url",
"type": "string",
"description": "Public gateway url"
},
{
"name": "callback",
"type": "function",
"description": "Function called with status",
"parameters": [
{
"name": "status",
"type": "boolean"
}
]
}
]
}, {
"name": "setPublicNFTGateway",
"type": "function",
"description": "Sets public NFT gateway value",
"parameters": [
{
"name": "url",
"type": "string",
"description": "Public NFT gateway url"
},
{
],
"returns_async": {
"name": "callback",
"type": "function",
"description": "Function called with status",
"parameters": [
{
"name": "status",
"type": "boolean"
}
]
],
"does_not_support_promises": "Requires refactoring"
}
]
}, {
}, {
"name": "setPublicNFTGateway",
"type": "function",
"description": "Sets public NFT gateway value",
"parameters": [
{
"name": "url",
"type": "string",
"description": "Public NFT gateway url"
}
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "status",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "setAutoRedirectToConfiguredGatewayEnabled",
"type": "function",
"description": "Sets whether IPFS resouceces should be forwarded to the configured gateway",
@@ -429,19 +406,18 @@
"name": "value",
"type": "boolean",
"description": "value"
},
{
"name": "callback",
"type": "function",
"description": "Function called with status",
"parameters": [
{
"name": "status",
"type": "boolean"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "status",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}, {
"name": "setGatewayFallbackEnabled",
"type": "function",
@@ -451,19 +427,18 @@
"name": "value",
"type": "boolean",
"description": "value"
},
{
"name": "callback",
"type": "function",
"description": "Function called with status",
"parameters": [
{
"name": "status",
"type": "boolean"
}
]
}
]
],
"returns_async": {
"name": "callback",
"parameters": [
{
"name": "status",
"type": "boolean"
}
],
"does_not_support_promises": "Requires refactoring"
}
}
],
"types": [