From 9af8c70a686e4e3e1d03887e450eab5250d34d47 Mon Sep 17 00:00:00 2001 From: some-one-mmx Date: Sat, 21 Jun 2025 10:59:46 +0800 Subject: [PATCH] add blankless ndk api Signed-off-by: some-one-mmx --- .../interfaces/native/arkweb_error_code.h | 58 ++++++++++++++ .../interfaces/native/libohweb.ndk.json | 16 ++++ .../native/native_interface_arkweb.h | 79 +++++++++++++++++++ 3 files changed, 153 insertions(+) diff --git a/web/webview/interfaces/native/arkweb_error_code.h b/web/webview/interfaces/native/arkweb_error_code.h index 4caab8f5d..6865c29be 100644 --- a/web/webview/interfaces/native/arkweb_error_code.h +++ b/web/webview/interfaces/native/arkweb_error_code.h @@ -71,5 +71,63 @@ ARKWEB_LIBRARY_OPEN_FAILURE = 17100105, ARKWEB_LIBRARY_SYMBOL_NOT_FOUND = 17100106, } ArkWeb_ErrorCode; +typedef enum ArkWeb_BlanklessErrorCode { +/* + * @brief Success. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 20 + */ +ARKWEB_BLANKLESS_SUCCESS = 0, + +/* + * @brief Unknown error. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 20 + */ +ARKWEB_BLANKLESS_ERR_UNKNOWN = -1, + +/* + * @brief Invalid args. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 20 + */ +ARKWEB_BLANKLESS_ERR_INVALID_ARGS = -2, + +/* + * @brief Init error. The web controller is not binded with the component. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 20 + */ +ARKWEB_BLANKLESS_ERR_CONTROLLER_NOT_INITED = -3, + +/* + * @brief The key of blankless was not matched. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 20 + */ +ARKWEB_BLANKLESS_KEY_NOT_MATCH = -4, + +/* + * @brief There are significant changes for the loading page. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 20 + */ +ARKWEB_BLANKLESS_SIGNIFICANT_CHANGE = -5, + +/* + * @brief Device not support. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 20 + */ +ARKWEB_BLANKLESS_ERR_DEVICE_NOT_SUPPORT = 801, +} ArkWeb_BlanklessErrorCode; + #endif // ARKWEB_ERROR_CODE_H /** @} */ diff --git a/web/webview/interfaces/native/libohweb.ndk.json b/web/webview/interfaces/native/libohweb.ndk.json index aa5489f4a..5438e63f5 100644 --- a/web/webview/interfaces/native/libohweb.ndk.json +++ b/web/webview/interfaces/native/libohweb.ndk.json @@ -326,5 +326,21 @@ { "first_introduced": "20", "name": "OH_NativeArkWeb_RegisterAsyncThreadJavaScriptProxy" + }, + { + "first_introduced": "20", + "name": "OH_NativeArkWeb_GetBlanklessInfoWithKey" + }, + { + "first_introduced": "20", + "name": "OH_NativeArkWeb_SetBlanklessLoadingWithKey" + }, + { + "first_introduced": "20", + "name": "OH_NativeArkWeb_ClearBlanklessLoadingCache" + }, + { + "first_introduced": "20", + "name": "OH_NativeArkWeb_SetBlanklessLoadingCacheCapacity" } ] diff --git a/web/webview/interfaces/native/native_interface_arkweb.h b/web/webview/interfaces/native/native_interface_arkweb.h index 9df320d8c..e05a11eb8 100644 --- a/web/webview/interfaces/native/native_interface_arkweb.h +++ b/web/webview/interfaces/native/native_interface_arkweb.h @@ -70,6 +70,20 @@ typedef void (*NativeArkWeb_OnValidCallback)(const char*); */ typedef void (*NativeArkWeb_OnDestroyCallback)(const char*); +/** + * @brief Defines the blankless information. + * + * @since 20 + */ +typedef struct { + /** The errCode of the blankless. */ + ArkWeb_BlanklessErrorCode errCode; + /** The estimated similarity of the history snapshots. */ + double similarity; + /** The loadingTime of the history loading. */ + int32_t loadingTime; +} ArkWeb_BlanklessInfo; + /** * @brief Loads a piece of code and execute JS code in the context of the currently displayed page. * @@ -203,6 +217,71 @@ ArkWeb_ErrorCode OH_NativeArkWeb_LoadData(const char* webTag, void OH_NativeArkWeb_RegisterAsyncThreadJavaScriptProxy(const char* webTag, const ArkWeb_ProxyObjectWithResult* proxyObject, const char* permission); +/** + * @brief Sets whether to enable blankless page loading. This API must be used in pair with the + * OH_NativeArkWeb_GetBlanklessInfoWithKey API. + * + * @param webTag webTag used when the webviewController is created. + * @param key Key value that uniquely identifies the current page. It must be the same as the key value of the + * OH_NativeArkWeb_GetBlanklessInfoWithKey API. + * @param isStarted Whether to enable frame interpolation. The value true indicates to enable frame + * interpolation, and the value false indicates the opposite. + * The default value is false. + * The value can be true or false. + * Action for setting an invalid value: N/A. + * @return Whether the API is successfully called. For details, see ArkWeb_BlanklessErrorCode. + * @since 20 + */ +ArkWeb_BlanklessErrorCode OH_NativeArkWeb_SetBlanklessLoadingWithKey(const char* webTag, + const char* key, + bool isStarted); + +/** + * @brief Clears the blankless loading cache of the page with a specified key value. + * + * @param key The list of key values of pages cached in the blankless loading solution. These key values are + * specified in OH_NativeArkWeb_GetBlanklessInfoWithKey. + * The default value is the list of key values of all pages cached in the blankless loading solution. + * The key length cannot exceed 2048 characters, and the number of keys must be less than or equal to 100. The + * URL is the same as that input to the Web component during page loading. + * When the key length exceeds 2048 characters, the key does not take effect. When the number of keys exceeds + * 100, the first 100 keys are used. If this parameter is set to NULL, the default value is used. + * @param size Size of the key list. + * @since 20 + */ +void OH_NativeArkWeb_ClearBlanklessLoadingCache(const char* key[], uint32_t size); + +/** + * @brief Obtains the prediction information about the blankless loading solution and enables the generation + * of the transition frame for the current loading. The application determines whether to enable the blankless + * loading solution based on the information. + * This API applies to pages in an applet or web application whose URLs are not fixed or cannot be uniquely + * identified. + * + * @param webTag webTag used when the webviewController is created. + * Default value: N/A. + * The value cannot be empty. + * When an invalid value is set, the error code is returned, and the API does not take effect. + * @param key Key value that uniquely identifies the current page. + * @return Return value of the ArkWeb_BlanklessInfo type. + * @since 20 + */ +ArkWeb_BlanklessInfo OH_NativeArkWeb_GetBlanklessInfoWithKey(const char* webTag, const char* key); + +/** + * @brief Sets the cache capacity of the blankless loading solution and returns the value that takes effect. + * + * @param capacity Cache capacity, in MB. The maximum value is 100 MB. + * The default value is 30 MB. + * The value ranges from 0 to 100. If this parameter is set to 0, no cache capacity is available and the + * functionality is disabled globally. + * When the value is set to a number smaller than 0, the value 0 takes effect. When the value is set to a + * number greater than 100, the value 100 takes effect. + * @return The effective value that ranges from 0 MB to 100 MB. + * @since 20 + */ +uint32_t OH_NativeArkWeb_SetBlanklessLoadingCacheCapacity(uint32_t capacity); + #ifdef __cplusplus }; #endif -- Gitee