diff --git a/web/webview/interfaces/native/BUILD.gn b/web/webview/interfaces/native/BUILD.gn index 326e619fcc57a025f87a4936b7f4c62eef57dcf6..7147abf3f8beec63332ee7324492a0aafbe4090d 100644 --- a/web/webview/interfaces/native/BUILD.gn +++ b/web/webview/interfaces/native/BUILD.gn @@ -21,8 +21,10 @@ ohos_ndk_library("libohweb") { system_capability = "SystemCapability.Web.Webview.Core" system_capability_headers = [ "web/arkweb_error_code.h", + "web/arkweb_interface.h", "web/arkweb_net_error_list.h", "web/arkweb_scheme_handler.h", + "web/arkweb_type.h", "web/native_interface_arkweb.h", ] min_compact_version = "11" @@ -32,8 +34,10 @@ ohos_ndk_headers("web_header") { dest_dir = "$ndk_headers_out_dir/web/" sources = [ "arkweb_error_code.h", + "arkweb_interface.h", "arkweb_net_error_list.h", "arkweb_scheme_handler.h", + "arkweb_type.h", "native_interface_arkweb.h", ] } diff --git a/web/webview/interfaces/native/arkweb_interface.h b/web/webview/interfaces/native/arkweb_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..90f3b80e5a4f1989d23f02a6599b2895d98f17cc --- /dev/null +++ b/web/webview/interfaces/native/arkweb_interface.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 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. + */ + +/** + * @addtogroup Web + * @{ + * + * @brief Provide the definition of the C interface for the native ArkWeb. + * @since 12 + */ +/** + * @file arkweb_interface.h + * + * @brief Provides a unified entry for the native ArkWeb. + * @library libohweb.so + * @syscap SystemCapability.Web.Webview.Core + * @since 12 + */ + +#ifndef ARKWEB_INTERFACE_H +#define ARKWEB_INTERFACE_H + +#include "arkweb_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the native API type of any size. + * + * @since 12 + */ +typedef struct { + /** Defines the size information of the native API set. */ + size_t size; +} ArkWeb_AnyNativeAPI; + +/** + * @brief Defines the native API set type. + * + * @since 12 + */ +typedef enum { + /** API type related to ArkWeb component. */ + ARKWEB_NATIVE_COMPONENT, + /** API type related to ArkWeb controller. */ + ARKWEB_NATIVE_CONTROLLER, +} ArkWeb_NativeAPIVariantKind; + +/* + * @brief Obtains the native API set of a specified type. + * @param type Indicates the type of the native API set provided by ArkWeb. + * @return Returns the pointer to the native API abstract object that carries the size. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 12 + */ +ArkWeb_AnyNativeAPI* OH_ArkWeb_GetNativeAPI(ArkWeb_NativeAPIVariantKind type); + +#ifdef __cplusplus +}; +#endif +#endif // ARKWEB_INTERFACE_H \ No newline at end of file diff --git a/web/webview/interfaces/native/arkweb_type.h b/web/webview/interfaces/native/arkweb_type.h new file mode 100644 index 0000000000000000000000000000000000000000..6b775a8e3816186336ee9e7d78b9d17057b52f26 --- /dev/null +++ b/web/webview/interfaces/native/arkweb_type.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2024 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. + */ + +/** + * @addtogroup Web + * @{ + * + * @brief Provide the definition of the C interface for the native ArkWeb. + * @since 12 + */ +/** + * @file arkweb_type.h + * + * @brief Defines the common types for the native ArkWeb. + * @library libohweb.so + * @syscap SystemCapability.Web.Webview.Core + * @since 12 + */ + +#ifndef ARKWEB_TYPE_H +#define ARKWEB_TYPE_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the javascript bridge data type. + * + * @since 12 + */ +typedef struct { + /** A buffer that contains data. */ + const uint8_t* buffer; + /** The size of the buffer. */ + size_t size; +} ArkWeb_JavaScriptBridgeData; + +/** + * @brief Defines the javascript callback of the native ArkWeb. + * + * @since 12 + */ +typedef void (*ArkWeb_OnJavaScriptCallback)( + const char* webTag, const ArkWeb_JavaScriptBridgeData* data, void* userData); + +/** + * @brief Defines the javascript proxy callback of the native ArkWeb. + * + * @since 12 + */ +typedef void (*ArkWeb_OnJavaScriptProxyCallback)( + const char* webTag, const ArkWeb_JavaScriptBridgeData* dataArray, size_t arraySize, void* userData); + +/** + * @brief Defines the component callback of the native ArkWeb. + * + * @since 12 + */ +typedef void (*ArkWeb_OnComponentCallback)(const char* webTag, void* userData); + +/** + * @brief Defines the javascript object. + * + * @since 12 + */ +typedef struct { + /** A piece of javascript code. */ + const uint8_t* buffer; + /** The size of the javascript code. */ + size_t size; + /** Callbacks execute JavaScript script results. */ + ArkWeb_OnJavaScriptCallback callback; + /** The user data to set. */ + void* userData; +} ArkWeb_JavaScriptObject; + +/** + * @brief Defines the javascript proxy registered method object. + * + * @since 12 + */ +typedef struct { + /** The method of the application side JavaScript object participating in the registration. */ + const char* methodName; + /** The callback function registered by developer is called back when HTML side uses. */ + ArkWeb_OnJavaScriptProxyCallback callback; + /** The user data to set. */ + void* userData; +} ArkWeb_ProxyMethod; + +/** + * @brief Defines the javascript proxy registered object. + * + * @since 12 + */ +typedef struct { + /** The name of the registered object. */ + const char* objName; + /** The javascript proxy registered method object list */ + const ArkWeb_ProxyMethod* methodList; + /** The size of the methodList. */ + size_t size; +} ArkWeb_ProxyObject; + +/** + * @brief Defines the controller API for native ArkWeb. + * + * @since 12 + */ +typedef struct { + /** The ArkWeb_ControllerAPI struct size. */ + size_t size; + /** Load a piece of code and execute JS code in the context of the currently displayed page. */ + void (*runJavaScript)(const char* webTag, const ArkWeb_JavaScriptObject* javascriptObject); + /** Register the JavaScript object and method list. */ + void (*registerJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject); + /** Deletes the registered object which th given name. */ + void (*deleteJavaScriptRegister)(const char* webTag, const char* objName); + /** Refresh the current web page. */ + void (*refresh)(const char* webTag); +} ArkWeb_ControllerAPI; + +/** + * @brief Defines the component API for native ArkWeb. + * + * @since 12 + */ +typedef struct { + /** The ArkWeb_ComponentAPI struct size. */ + size_t size; + /** Register the OnControllerAttached callback. */ + void (*onControllerAttached)(const char* webTag, ArkWeb_OnComponentCallback callback, void* userData); + /** Register the OnPageBegin callback. */ + void (*onPageBegin)(const char* webTag, ArkWeb_OnComponentCallback callback, void* userData); + /** Register the OnPageEnd callback. */ + void (*onPageEnd)(const char* webTag, ArkWeb_OnComponentCallback callback, void* userData); + /** Register the OnDestroy callback. */ + void (*onDestroy)(const char* webTag, ArkWeb_OnComponentCallback callback, void* userData); +} ArkWeb_ComponentAPI; + +/** + * @brief Check whether the member variables of the current struct exist. + * + * @since 12 + */ +#define ARKWEB_MEMBER_EXISTS(s, f) \ + ((intptr_t) & ((s)->f) - (intptr_t)(s) + sizeof((s)->f) <= *reinterpret_cast(s)) + +/** + * @brief Return false if the struct member does not exist, otherwise true. + * + * @since 12 + */ +#define ARKWEB_MEMBER_MISSING(s, f) (!ARKWEB_MEMBER_EXISTS(s, f) || !((s)->f)) + +#ifdef __cplusplus +}; +#endif +#endif // ARKWEB_TYPE_H \ No newline at end of file diff --git a/web/webview/interfaces/native/libohweb.ndk.json b/web/webview/interfaces/native/libohweb.ndk.json index 74e8d42a09d0d0d996ae209048785de8c94e60d8..520b8c85d10d6d0f335b9e6877e03adca565ba1b 100644 --- a/web/webview/interfaces/native/libohweb.ndk.json +++ b/web/webview/interfaces/native/libohweb.ndk.json @@ -326,5 +326,9 @@ { "first_introduced": "12", "name": "OH_ArkWeb_ReleaseByteArray" + }, + { + "first_introduced": "12", + "name": "OH_ArkWeb_GetNativeAPI" } ]