diff --git a/web/webview/interfaces/native/BUILD.gn b/web/webview/interfaces/native/BUILD.gn index ad0a8e96a58a3431439591a86602d6d9fd4f78f3..326e619fcc57a025f87a4936b7f4c62eef57dcf6 100644 --- a/web/webview/interfaces/native/BUILD.gn +++ b/web/webview/interfaces/native/BUILD.gn @@ -20,6 +20,7 @@ ohos_ndk_library("libohweb") { ndk_description_file = "./libohweb.ndk.json" system_capability = "SystemCapability.Web.Webview.Core" system_capability_headers = [ + "web/arkweb_error_code.h", "web/arkweb_net_error_list.h", "web/arkweb_scheme_handler.h", "web/native_interface_arkweb.h", @@ -30,6 +31,7 @@ ohos_ndk_library("libohweb") { ohos_ndk_headers("web_header") { dest_dir = "$ndk_headers_out_dir/web/" sources = [ + "arkweb_error_code.h", "arkweb_net_error_list.h", "arkweb_scheme_handler.h", "native_interface_arkweb.h", diff --git a/web/webview/interfaces/native/arkweb_error_code.h b/web/webview/interfaces/native/arkweb_error_code.h new file mode 100644 index 0000000000000000000000000000000000000000..07f27402591ac122463d4f340482d6191aefc58f --- /dev/null +++ b/web/webview/interfaces/native/arkweb_error_code.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 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 Provides APIs for the ArkWeb errors. + * @since 12 + */ +/** + * @file arkweb_error_code.h + * + * @brief Declares the APIs for the ArkWeb errors. + * @library libohweb.so + * @syscap SystemCapability.Web.Webview.Core + * @since 12 + */ +#ifndef ARKWEB_ERROR_CODE_H +#define ARKWEB_ERROR_CODE_H + +typedef enum ArkWeb_ErrorCode { +/* + * @brief Unknown error. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 12 + */ +ARKWEB_ERROR_UNKNOWN = 17100100, + +/* + * @brief Invalid param. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 12 + */ +ARKWEB_INVALID_PARAM = 17100101, + +/* + * @brief Register custom schemes should be called before create any ArkWeb. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 12 + */ +ARKWEB_SCHEME_REGISTER_FAILED = 17100102, +} ArkWeb_ErrorCode; + +#endif // ARKWEB_ERROR_CODE_H diff --git a/web/webview/interfaces/native/arkweb_net_error_list.h b/web/webview/interfaces/native/arkweb_net_error_list.h index e436876613998143f1f5232ea323391c0ed7856c..d7e2aef40e0a203ed5cbfca98e6e77ef0e33e7e0 100644 --- a/web/webview/interfaces/native/arkweb_net_error_list.h +++ b/web/webview/interfaces/native/arkweb_net_error_list.h @@ -31,23 +31,7 @@ #ifndef ARKWEB_NET_ERROR_LIST_H #define ARKWEB_NET_ERROR_LIST_H -enum ArkWeb_NetError { - /* - * @brief Invalid param. - * - * @syscap SystemCapability.Web.Webview.Core - * @since 12 - */ - ARKWEB_NET_INVALID_PARAM = 2, - - /* - * @brief Unknown error. - * - * @syscap SystemCapability.Web.Webview.Core - * @since 12 - */ - ARKWEB_NET_UNKNOWN = 1, - +typedef enum ArkWeb_NetError { /* * @brief Normal. * @@ -2134,6 +2118,6 @@ enum ArkWeb_NetError { * @since 12 */ ARKWEB_ERR_DNS_NO_MATCHING_SUPPORTED_ALPN = -811, -}; +} ArkWeb_NetError; #endif // ARKWEB_NET_ERROR_LIST_H diff --git a/web/webview/interfaces/native/arkweb_scheme_handler.h b/web/webview/interfaces/native/arkweb_scheme_handler.h index 348909b5ac3125bab9c4eb136f5bd39abc67b948..f212525e5d9a254d62f4dc57130ef43f7eb46374 100644 --- a/web/webview/interfaces/native/arkweb_scheme_handler.h +++ b/web/webview/interfaces/native/arkweb_scheme_handler.h @@ -33,6 +33,7 @@ #include "stdint.h" +#include "arkweb_error_code.h" #include "arkweb_net_error_list.h" #ifdef __cplusplus @@ -181,6 +182,8 @@ typedef void (*ArkWeb_OnRequestStart)(const ArkWeb_SchemeHandler* schemeHandler, /* * @brief Callback when the request is completed. This will called on the IO thread. + * Should destory the resourceRequest by ArkWeb_ResourceRequest_Destroy and use ArkWeb_ResourceHandler_Destroy + * destroy the ArkWeb_ResourceHandler received in ArkWeb_OnRequestStart. * @param schemeHandler The ArkWeb_SchemeHandler. * @param resourceRequest The ArkWeb_ResourceRequest. * @@ -263,7 +266,7 @@ void OH_ArkWebRequestHeaderList_GetHeader(const ArkWeb_RequestHeaderList* reques * @brief Set a user data to ArkWeb_ResourceRequest. * @param resourceRequest The ArkWeb_ResourceRequest. * @param userData The user data to set. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -327,7 +330,7 @@ void OH_ArkWebResourceRequest_DestroyPostData(ArkWeb_PostDataStream* postDataStr * @brief Set a user data to ArkWeb_PostDataStream. * @param postDataStream The ArkWeb_PostDataStream. * @param userData The user data to set. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -350,7 +353,7 @@ void* OH_ArkWebPostDataStream_GetUserData(const ArkWeb_PostDataStream* postDataS * OH_ArkWebPostDataStream_Read. * @param postDataStream The ArkWeb_PostDataStream. * @param readCallback The callback of read function. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -362,7 +365,7 @@ int32_t OH_ArkWebPostDataStream_SetReadCallback(ArkWeb_PostDataStream* postDataS * @brief Init the post data stream. This function must be called before calling any other functions. * @param postDataStream The ArkWeb_PostDataStream. * @param initCallback The callback of init. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -436,6 +439,16 @@ bool OH_ArkWebPostDataStream_IsEof(const ArkWeb_PostDataStream* postDataStream); */ bool OH_ArkWebPostDataStream_IsInMemory(const ArkWeb_PostDataStream* postDataStream); +/* + * @brief Destroy the ArkWeb_ResourceRequest. + * @param resourceRequest The ArkWeb_ResourceRequest. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 12 + */ +int32_t OH_ArkWebResourceRequest_Destroy(const ArkWeb_ResourceRequest* resourceRequest); + /* * @brief Get the referrer of request. * @param resourceRequest The ArkWeb_ResourceRequest. @@ -493,7 +506,7 @@ bool OH_ArkWebResourceRequest_HasGesture(const ArkWeb_ResourceRequest* resourceR * DATA schemes. This function should be called on main thread. * @param scheme The scheme to regist. * @param option The configuration of the scheme. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -502,6 +515,9 @@ int32_t OH_ArkWeb_RegisterCustomSchemes(const char* scheme, int32_t option); /* * @brief Set a ArkWeb_SchemeHandler for a specific scheme to intercept requests of that scheme type. + * SchemeHandler should be set after the BrowserContext created. + * Use WebviewController.initializeWebEngine to initialize the BrowserContext without create a ArkWeb. + * * @param scheme Scheme that need to be intercepted. * @param schemeHandler The SchemeHandler for the scheme. Only requests triggered by ServiceWorker will be notified * through this handler. @@ -514,6 +530,9 @@ bool OH_ArkWebServiceWorker_SetSchemeHandler(const char* scheme, ArkWeb_SchemeHa /* * @brief Set a ArkWeb_SchemeHandler for a specific scheme to intercept requests of that scheme type. + * SchemeHandler should be set after the BrowserContext created. + * Use WebviewController.initializeWebEngine to initialize the BrowserContext without create a ArkWeb. + * * @param scheme Scheme that need to be intercepted. * @param webTag The name of the web component. * @param schemeHandler The SchemeHandler for the scheme. Only requests triggered from the specified web will be @@ -527,7 +546,7 @@ bool OH_ArkWeb_SetSchemeHandler(const char* scheme, const char* webTag, ArkWeb_S /* * @brief Clear the handler registered on the specified web for service worker. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -537,7 +556,7 @@ int32_t OH_ArkWebServiceWorker_ClearSchemeHandlers(); /* * @brief Clear the handler registered on the specified web. * @param webTag The name of the web component. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -567,7 +586,7 @@ void OH_ArkWeb_DestroySchemeHandler(ArkWeb_SchemeHandler* schemeHandler); * @brief Set a user data to ArkWeb_SchemeHandler. * @param schemeHandler The ArkWeb_SchemeHandler. * @param userData The user data to set. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -588,7 +607,7 @@ void* OH_ArkWebSchemeHandler_GetUserData(const ArkWeb_SchemeHandler* schemeHandl * @brief Set the OnRequestStart callback for SchemeHandler. * @param schemeHandler The SchemeHandler for the scheme. * @param onRequestStart The OnRequestStart callback. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -600,7 +619,7 @@ int32_t OH_ArkWebSchemeHandler_SetOnRequestStart(ArkWeb_SchemeHandler* schemeHan * @brief Set the OnRequestStop callback for SchemeHandler. * @param schemeHandler The SchemeHandler for the scheme. * @param onRequestStop The OnRequestStop callback. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -630,7 +649,7 @@ void OH_ArkWeb_DestroyResponse(ArkWeb_Response* response); * @brief Set the resolved URL after redirects or changed as a result of HSTS. * @param response The ArkWeb_Response. * @param url The resolved URL. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -651,7 +670,7 @@ void OH_ArkWebResponse_GetUrl(const ArkWeb_Response* response, char** url); * @brief Set a error code to ArkWeb_Response. * @param response The ArkWeb_Response. * @param errorCode The error code for the failed request. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -672,7 +691,7 @@ ArkWeb_NetError OH_ArkWebResponse_GetError(const ArkWeb_Response* response); * @brief Set a status code to ArkWebResponse. * @param response The ArkWeb_Response. * @param status The http status code for the request. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -693,7 +712,7 @@ int OH_ArkWebResponse_GetStatus(const ArkWeb_Response* response); * @brief Set a status text to ArkWebResponse. * @param response The ArkWeb_Response. * @param statusText The status text for the request. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -715,7 +734,7 @@ void OH_ArkWebResponse_GetStatusText(const ArkWeb_Response* response, char** sta * @brief Set mime type to ArkWebResponse. * @param response The ArkWeb_Response. * @param mimeType The mime type for the request. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -737,7 +756,7 @@ void OH_ArkWebResponse_GetMimeType(const ArkWeb_Response* response, char** mimeT * @brief Set charset to ArkWeb_Response. * @param response The ArkWeb_Response. * @param charset The charset for the request. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -761,7 +780,7 @@ void OH_ArkWebResponse_GetCharset(const ArkWeb_Response* response, char** charse * @param name The name of the header. * @param value The value of the header. * @bool overwirte If true will overwrite the exsits header, if false otherwise. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -783,11 +802,21 @@ int32_t OH_ArkWebResponse_SetHeaderByName(ArkWeb_Response* response, */ void OH_ArkWebResponse_GetHeaderByName(const ArkWeb_Response* response, const char* name, char** value); +/* + * @brief Destroy the ArkWeb_ResourceHandler. + * @param resourceHandler The ArkWeb_ResourceHandler. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. + * + * @syscap SystemCapability.Web.Webview.Core + * @since 12 + */ +int32_t OH_ArkWebResourceHandler_Destroy(const ArkWeb_ResourceHandler* resourceHandler); + /* * @brief Pass response headers to intercepted requests. * @param resourceHandler The ArkWeb_ResourceHandler for the request. * @param response The ArkWeb_Response for the intercepting requests. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -800,7 +829,7 @@ int32_t OH_ArkWebResourceHandler_DidReceiveResponse(const ArkWeb_ResourceHandler * @param resourceHandler The ArkWeb_ResourceHandler for the request. * @param buffer Buffer data to send. * @param bufLen The size of buffer. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -812,7 +841,7 @@ int32_t OH_ArkWebResourceHandler_DidReceiveData(const ArkWeb_ResourceHandler* re /* * @brief Notify the ArkWeb that this request should be finished and there is no more data available. * @param resourceHandler The ArkWeb_ResourceHandler for the request. - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 @@ -823,7 +852,7 @@ int32_t OH_ArkWebResourceHandler_DidFinish(const ArkWeb_ResourceHandler* resourc * @brief Notify the ArkWeb that this request should be failed. * @param resourceHandler The ArkWeb_ResourceHandler for the request. * @param errorCode The error code for this request. refer to arkweb_net_error_list.h - * @return 0 if success; otherwise if fail. refer to arkweb_net_error_list.h. + * @return 0 if success; otherwise if fail. refer to arkweb_error_code.h. * * @syscap SystemCapability.Web.Webview.Core * @since 12 diff --git a/web/webview/interfaces/native/libohweb.ndk.json b/web/webview/interfaces/native/libohweb.ndk.json index 7d99bc707125eea0d758d890d96b2c26358aa812..74e8d42a09d0d0d996ae209048785de8c94e60d8 100644 --- a/web/webview/interfaces/native/libohweb.ndk.json +++ b/web/webview/interfaces/native/libohweb.ndk.json @@ -95,6 +95,10 @@ "first_introduced": "12", "name": "OH_ArkWebRequestHeader_GetValue" }, + { + "first_introduced": "12", + "name": "OH_ArkWebResourceRequest_Destroy" + }, { "first_introduced": "12", "name": "OH_ArkWebResourceRequest_GetMethod" @@ -107,6 +111,10 @@ "first_introduced": "12", "name": "OH_ArkWebResourceRequest_GetPostData" }, + { + "first_introduced": "12", + "name": "OH_ArkWebResourceRequest_DestroyPostData" + }, { "first_introduced": "12", "name": "OH_ArkWebPostDataStream_SetReadCallback" @@ -291,6 +299,10 @@ "first_introduced": "12", "name": "OH_ArkWebResponse_GetHeaderByName" }, + { + "first_introduced": "12", + "name": "OH_ArkWebResourceHandler_Destroy" + }, { "first_introduced": "12", "name": "OH_ArkWebResourceHandler_DidReceiveResponse"