diff --git a/api/@ohos.web.webNativeMessagingExtensionAbility.d.ts b/api/@ohos.web.webNativeMessagingExtensionAbility.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..119ea7568c8c7e8c67585fb099aa371161fb3bf0 --- /dev/null +++ b/api/@ohos.web.webNativeMessagingExtensionAbility.d.ts @@ -0,0 +1,126 @@ + +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @kit ArkWeb + */ + +import ExtensionAbility from './@ohos.app.ability.ExtensionAbility'; +import type WebNativeMessagingExtensionContext from './@ohos.web.webNativeMessagingExtensionContext'; + +/** + * Indicates connection information about web native messaging connection + * + * @typedef ConnectionInfo + * @syscap SystemCapability.Web.Webview.Core + * @since 21 + */ +export interface ConnectionInfo { + /** + * Indicates connection id + * + * @type { int } + * @syscap SystemCapability.Web.Webview.Core + * @since 21 + */ + connectionId: int; + + /** + * Indicates the caller bundle name + * + * @type { string } + * @syscap SystemCapability.Web.Webview.Core + * @since 21 + */ + bundleName: string; + + /** + * Indicates the caller extension origin url + * + * @type { string } + * @syscap SystemCapability.Web.Webview.Core + * @since 21 + */ + extensionOrigin: string; + + /** + * Indicates the pipe read for connection + * + * @type { int } + * @syscap SystemCapability.Web.Webview.Core + * @since 21 + */ + fdRead: int; + + /** + * Indicates the pipe write for connection + * + * @type { int } + * @syscap SystemCapability.Web.Webview.Core + * @since 21 + */ + fdWrite: int; +} + +/** + * class of web native messaging extension ability. + * + * @extends ExtensionAbility + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ +export default class WebNativeMessagingExtensionAbility extends ExtensionAbility { + /** + * Indicates web native messaging extension ability context. + * + * @type { WebNativeMessagingExtensionContext } + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + context: WebNativeMessagingExtensionContext; + + /** + * Called back when an web native messaging extension is first connected to an ability. + * + * @param { ConnectionInfo } info - Indicates connection information about new native connection. + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + onConnectNative(info: ConnectionInfo): void; + + /** + * Called back when all abilities connected to an web native messaging extension are disconnected. + * + * @param { ConnectionInfo } info - Indicates connection information about new native connection. + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + onDisconnectNative(info: ConnectionInfo): void; + + /** + * Called back before an web native messaging extension is destroyed. + * + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + onDestroy(): void; +} diff --git a/api/@ohos.web.webNativeMessagingExtensionContext.d.ts b/api/@ohos.web.webNativeMessagingExtensionContext.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..19f1fd4fe93039d1ce889576ec211ebd71e166dd --- /dev/null +++ b/api/@ohos.web.webNativeMessagingExtensionContext.d.ts @@ -0,0 +1,95 @@ + +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @kit ArkWeb + */ + +import ExtensionContext from './application/ExtensionContext'; +import Want from './@ohos.app.ability.Want'; +import StartOptions from './@ohos.app.ability.StartOptions'; + +/** + * The context of web native messaging extension. It allows access to WebNativeMessagingExtension-specific resources. + * + * @extends ExtensionContext + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ +export default class WebNativeMessagingExtensionContext extends ExtensionContext { + /** + * Starts a new ability. + * + * @param { Want } want - Indicates the ability to start. + * @param { StartOptions } [options] - Indicates the start options. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - The application does not have permission to call the interface. + * @throws { BusinessError } 16000001 - The specified ability does not exist. + * @throws { BusinessError } 16000002 - Incorrect ability type. + * @throws { BusinessError } 16000004 - Cannot start an invisible component. + * @throws { BusinessError } 16000005 - The specified process does not have the permission. + * @throws { BusinessError } 16000008 - The crowdtesting application expires. + * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. + * @throws { BusinessError } 16000010 - The call with the continuation and prepare continuation flag is forbidden. + * @throws { BusinessError } 16000011 - The context does not exist. + * @throws { BusinessError } 16000012 - The application is controlled. + * @throws { BusinessError } 16000013 - The application is controlled by EDM. + * @throws { BusinessError } 16000019 - No matching ability is found. + * @throws { BusinessError } 16000050 - Internal error. + * @throws { BusinessError } 16000055 - Installation-free timed out. + * @throws { BusinessError } 16000071 - App clone is not supported. + * @throws { BusinessError } 16000072 - App clone or multi-instance is not supported. + * @throws { BusinessError } 16000073 - The app clone index is invalid. + * @throws { BusinessError } 16000076 - The app instance key is invalid. + * @throws { BusinessError } 16000077 - The number of app instances reaches the limit. + * @throws { BusinessError } 16000078 - The multi-instance is not supported. + * @throws { BusinessError } 16000079 - The APP_INSTANCE_KEY cannot be specified. + * @throws { BusinessError } 16000080 - Creating a new instance is not supported. + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + startAbility(want: Want, options?: StartOptions): Promise; + + /** + * Destroys this web native messaging extension. + * + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 16000009 - An ability cannot be started or stopped in Wukong mode. + * @throws { BusinessError } 16000011 - The context does not exist. + * @throws { BusinessError } 16000050 - Internal error. + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + terminateSelf(): Promise; + + /** + * Stop the specified native connection. + * + * @param { int } connectionId - Indicates the id of the specified connection. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - The application does not have permission to call the interface. + * @throws { BusinessError } 16000011 - The context does not exist. + * @throws { BusinessError } 16000050 - Internal error. + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + stopNativeConnection(connectionId: int): Promise; +} diff --git a/api/@ohos.web.webNativeMessagingExtensionManager.d.ts b/api/@ohos.web.webNativeMessagingExtensionManager.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..edd92583691cee2ef5213ca64b8b5aeee07705d8 --- /dev/null +++ b/api/@ohos.web.webNativeMessagingExtensionManager.d.ts @@ -0,0 +1,156 @@ + +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @kit ArkWeb + */ + +import type UIAbilityContext from './application/UIAbilityContext'; +import type Want from './@ohos.app.ability.Want'; + +/** + * This module of web native messaging extension manager. + * + * @namespace webNativeMessagingExtensionManager + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ +declare namespace webNativeMessagingExtensionManager { + + /** + * Indicates connection information about web native messaging connection + * @typedef ConnectionNativeInfo + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + interface ConnectionNativeInfo { + /** + * Indicates connection id + * + * @type { int } + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + connectionId: int; + + /** + * Indicates the bundle name of the web native messaging extension + * + * @type { string } + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + bundleName: string; + + /** + * Indicates the browser extension origin url + * + * @type { string } + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + extensionOrigin: string; + + /** + * Indicates the pid of the web native messaging extension + * + * @type { int } + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + extensionPid: int; + } + + /** + * As an input parameter when connecting a web native messaging extension, it is used to receive + * state changes during the connection. + * @typedef WebExtensionConnectionCallback + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + interface WebExtensionConnectionCallback { + /** + * The callback interface was connect successfully. + * + * @param { ConnectionNativeInfo } connection - The remote connection info + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + onConnect(connection: ConnectionNativeInfo): void; + + /** + * The callback interface was disconnect successfully. + * + * @param { ConnectionNativeInfo } connection - The remote connection info + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + onDisconnect(connection: ConnectionNativeInfo): void; + + /** + * The callback interface was connect failed. + * + * @param { int } code - The error code of the failed. + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + onFailed(code: int): void; + } + + /** + * Connects current ability to an web native message extension ability. + * + * @permission ohos.permission.WEB_NATIVE_MESSAGING + * @param { UIAbilityContext } context - The context of the caller of the ui ability + * @param { Want } want - The element name of the web native messaging ability + * @param { WebExtensionConnectionCallback } callback - The remote object instance + * @returns { int } Returns the number code of the ability connected + * @throws { BusinessError } 801 - Capability not supported. + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + function connectNative(context: UIAbilityContext, want: Want, callback: WebExtensionConnectionCallback): int; + + /** + * Disconnect current ability from an web native messaging extension, in contrast to {@link connectNative}. + * + * @permission ohos.permission.WEB_NATIVE_MESSAGING + * @param { int } connectionId - The number code of the ability connected + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - Permission verification failed. + * @throws { BusinessError } 801 - Capability not supported. + * @throws { BusinessError } 16000011 - The context does not exist. + * @throws { BusinessError } 16000050 - Internal error. + * @syscap SystemCapability.Web.Webview.Core + * @stagemodelonly + * @since 21 + */ + function disconnectNative(connectionId: int): Promise; +} + +export default webNativeMessagingExtensionManager; diff --git a/kits/@kit.ArkWeb.d.ts b/kits/@kit.ArkWeb.d.ts index 219e3b278d29c378065683fa34c7e1abca58d115..f389f4095062a19b70b6c256fe34fdd1afd5f570 100644 --- a/kits/@kit.ArkWeb.d.ts +++ b/kits/@kit.ArkWeb.d.ts @@ -21,6 +21,11 @@ import { WebNetErrorList } from '@ohos.web.netErrorList'; export { WebNetErrorList }; +import WebNativeMessagingExtensionAbility, { ConnectionInfo } from '@ohos.web.webNativeMessagingExtensionAbility'; +import webNativeMessagingExtensionManager from '@ohos.web.webNativeMessagingExtensionManager'; + +export { WebNativeMessagingExtensionAbility, webNativeMessagingExtensionManager, ConnectionInfo}; + /*** if arkts 1.1&1.2 */ import webview from '@ohos.web.webview';