diff --git a/bundle.json b/bundle.json index 068d0402b2a09b04371314a2a7b7362189057e92..4e86bbfcbf264f7612ec5b184d41f8bfae34b768 100644 --- a/bundle.json +++ b/bundle.json @@ -71,13 +71,14 @@ "relational_store", "resource_schedule_service", "samgr", + "sensor", "soc_perf", "time_service", "window_manager", "netstack", "protobuf", - "libxml2" - + "libxml2", + "openssl" ], "third_party": [ "chromium", @@ -261,6 +262,7 @@ "//base/web/webview/test/unittest/ohos_adapter/res_sched_adapter_impl_test:unittest", "//base/web/webview/test/unittest/ohos_adapter/web_data_base_adapter_impl_test:unittest", "//base/web/webview/test/unittest/ohos_adapter/ohos_resource_adapter_test:unittest", + "//base/web/webview/test/unittest/ohos_adapter/ohos_image_adapter:unittest", "//base/web/webview/test/unittest/ohos_adapter/graphic_adapter_test:unittest", "//base/web/webview/test/unittest/ohos_adapter/datashare_adapter_impl_test:unittest", "//base/web/webview/test/unittest/ohos_adapter/ohos_init_web_adapter:unittest", diff --git a/c b/c new file mode 100644 index 0000000000000000000000000000000000000000..c788a21f997eb4118ac3f60787e07f79ceff0a0e --- /dev/null +++ b/c @@ -0,0 +1,25 @@ +filter.lfs.clean=git-lfs clean -- %f +filter.lfs.smudge=git-lfs smudge -- %f +filter.lfs.process=git-lfs filter-process +filter.lfs.required=true +filter.lfs.clean=git-lfs clean -- %f +filter.lfs.smudge=git-lfs smudge -- %f +filter.lfs.process=git-lfs filter-process +filter.lfs.required=true +user.name=xs +user.email=xs@xs.com +credential.helper=store +color.ui=auto +core.repositoryformatversion=0 +core.filemode=false +core.bare=false +core.logallrefupdates=true +filter.lfs.smudge=git-lfs smudge --skip -- %f +filter.lfs.process=git-lfs filter-process --skip +remote.origin.url=git@gitee.com:openharmony/web_webview +remote.origin.review=https://openharmony.gitee.com/openharmony/ +remote.origin.projectname=web_webview +remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* +lfs.repositoryformatversion=0 +remote.xs.url=git@gitee.com:x50041882/web_webview.git +remote.xs.fetch=+refs/heads/*:refs/remotes/xs/* diff --git a/config.gni b/config.gni index cd08c73099ef4895e139c54cafea6c0faac24c82..84868daeec2dbfa6826a752a597aeb334e0545f8 100644 --- a/config.gni +++ b/config.gni @@ -24,6 +24,7 @@ declare_args() { webview_print_enable = true webview_enterprise_device_manager_enable = true webview_media_avsession_enable = true + webview_sensors_sensor_enable = true if (defined(global_parts_info) && !defined(global_parts_info.resourceschedule_soc_perf)) { @@ -75,4 +76,8 @@ declare_args() { !defined(global_parts_info.multimedia_av_session)) { webview_media_avsession_enable = false } + if (defined(global_parts_info) && + !defined(global_parts_info.sensors_sensor)) { + webview_sensors_sensor_enable = false + } } diff --git a/interfaces/kits/cj/include/webview_controller_impl.h b/interfaces/kits/cj/include/webview_controller_impl.h index ddcb4a51df7351b1d0735bc73e07a9154a0e508d..0a17826f347cd7a6617c8a718b1b103dd060ed69 100644 --- a/interfaces/kits/cj/include/webview_controller_impl.h +++ b/interfaces/kits/cj/include/webview_controller_impl.h @@ -23,6 +23,8 @@ #include "webview_javascript_result_callback.h" #include "nweb.h" #include "nweb_helper.h" +#include "arkweb_scheme_handler.h" +#include "nweb_log.h" namespace OHOS::Webview { enum class WebHitTestType : int { @@ -50,6 +52,29 @@ namespace OHOS::Webview { DANGEROUS = 5 }; + enum class WebResourceType : int { + MAIN_FRAME = 0, + SUB_FRAME = 1, + STYLE_SHEET = 2, + SCRIPT = 3, + IMAGE = 4, + FONT_RESOURCE = 5, + SUB_RESOURCE = 6, + OBJECT = 7, + MEDIA = 8, + WORKED = 9, + SHARED_WORKED = 10, + PREFETCH = 11, + FAVICON = 12, + XHR = 13, + PING = 14, + SERVICE_WORKED = 15, + CSP_REPORT = 16, + PLUNGIN_RESOURCE = 17, + NAVIGATION_PRELOAD_MAIN_FRAME = 19, + NAVIGATION_PRELOAD_USB_FRAME = 20 + }; + class __attribute__((visibility("default"))) WebviewControllerImpl : public OHOS::FFI::FFIData { DECL_TYPE(WebviewControllerImpl, OHOS::FFI::FFIData) public: @@ -153,6 +178,8 @@ namespace OHOS::Webview { void Stop(); + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive); + public: static std::string customeSchemeCmdLine_; static bool existNweb_; @@ -183,5 +210,72 @@ namespace OHOS::Webview { private: std::shared_ptr sptrHistoryList_ = nullptr; }; + + //WebSHRequestImpl + using WebHeaderList = std::vector>; + class __attribute__((visibility("default"))) WebSHRequestImpl : public OHOS::FFI::FFIData { + DECL_TYPE(WebSHRequestImpl, OHOS::FFI::FFIData) + public: + explicit WebSHRequestImpl() = default; + WebSHRequestImpl(const ArkWeb_ResourceRequest* request) + { + OH_ArkWebResourceRequest_GetUrl(request, &url_); + OH_ArkWebResourceRequest_GetMethod(request, &method_); + OH_ArkWebResourceRequest_GetReferrer(request, &referrer_); + isRedirect_ = OH_ArkWebResourceRequest_IsRedirect(request); + isMainFrame_ = OH_ArkWebResourceRequest_IsMainFrame(request); + hasGesture_ = OH_ArkWebResourceRequest_HasGesture(request); + OH_ArkWebResourceRequest_GetFrameUrl(request, &frameUrl_); + OH_ArkWebResourceRequest_GetHttpBodyStream(request, &stream_); + requestResourceType_ = OH_ArkWebResourceRequest_GetResourceType(request); + + ArkWeb_RequestHeaderList* arkWebHeaderlist = nullptr; + OH_ArkWebResourceRequest_GetRequestHeaders(request, &arkWebHeaderlist); + if (!arkWebHeaderlist) { + WVLOG_E("OH_ArkWebRequestHeaderList_Create failed"); + return; + } + int32_t size = OH_ArkWebRequestHeaderList_GetSize(arkWebHeaderlist); + if (size <= 0) { + WVLOG_E("OH_ArkWebRequestHeaderList_GetSize:%{public}d", size); + return; + } + for (int32_t index = 0; index < size; index++) { + char* key; + char* value; + OH_ArkWebRequestHeaderList_GetHeader(arkWebHeaderlist, index, &key, &value); + if (!key || !value) { + continue; + } + std::string strKey(key); + std::string strValue(value); + headerList_.emplace_back(std::make_pair(strKey, strValue)); + OH_ArkWeb_ReleaseString(key); + OH_ArkWeb_ReleaseString(value); + } + OH_ArkWebRequestHeaderList_Destroy(arkWebHeaderlist); + }; + std::string GetRequestUrl(); + std::string GetMethod(); + std::string GetReferrer(); + std::string GetFrameUrl(); + int32_t GetRequestResourceType(); + ArkWeb_HttpBodyStream* GetHttpBodyStream(); + const WebHeaderList& GetHeader(); + bool HasGesture(); + bool IsMainFrame(); + bool IsRedirect(); + private: + char* url_ = nullptr; + char* method_ = nullptr; + char* referrer_ = nullptr; + char* frameUrl_ = nullptr; + int32_t requestResourceType_ = -1; + bool isRedirect_ = false; + bool isMainFrame_ = false; + bool hasGesture_ = false; + WebHeaderList headerList_; + ArkWeb_HttpBodyStream* stream_ = nullptr; + }; } #endif // WEBVIEW_CONTROLLER_IMPL_FFI_H \ No newline at end of file diff --git a/interfaces/kits/cj/include/webview_ffi.h b/interfaces/kits/cj/include/webview_ffi.h index af456fc2ca2331176ba9f5709797e7c9e75273f4..2b6391c686fd17cee490036a3c3b700d2454dd8c 100644 --- a/interfaces/kits/cj/include/webview_ffi.h +++ b/interfaces/kits/cj/include/webview_ffi.h @@ -20,6 +20,7 @@ #include "ffi_remote_data.h" #include "webview_utils.h" #include "cj_common_ffi.h" +#include "arkweb_scheme_handler.h" extern "C" { FFI_EXPORT int64_t FfiOHOSWebviewCtlConstructor(); @@ -85,6 +86,20 @@ extern "C" { FFI_EXPORT bool FfiOHOSCookieMgrExistCookie(bool incognitoMode); FFI_EXPORT void FfiOHOSCookieMgrClearAllCookiesSync(bool incognitoMode); FFI_EXPORT void FfiOHOSCookieMgrClearSessionCookieSync(); + + //SchemeHandlerRequest + FFI_EXPORT int64_t FfiOHOSWebSHRequestConstructor(); + FFI_EXPORT int64_t FfiOHOSWebSHRequestConstructorwithrequest(const ArkWeb_ResourceRequest* request); + FFI_EXPORT int32_t FfiOHOSWebSHRequestGetRequestResourceType(int64_t id, int32_t *errCode); + FFI_EXPORT bool FfiOHOSWebSHRequestHasGesture(int64_t id, int32_t *errCode); + FFI_EXPORT bool FfiOHOSWebSHRequestIsMainFrame(int64_t id, int32_t *errCode); + FFI_EXPORT bool FfiOHOSWebSHRequestIsRedirect(int64_t id, int32_t *errCode); + FFI_EXPORT char* FfiOHOSWebSHRequestGetRequestUrl(int64_t id, int32_t *errCode); + FFI_EXPORT char* FfiOHOSWebSHRequestGetMethod(int64_t id, int32_t *errCode); + FFI_EXPORT char* FfiOHOSWebSHRequestGetReferrer(int64_t id, int32_t *errCode); + FFI_EXPORT char* FfiOHOSWebSHRequestGetFrameUrl(int64_t id, int32_t *errCode); + FFI_EXPORT const OHOS::Webview::WebHeaderList* FfiOHOSWebSHRequestGetHeader(int64_t id, int32_t *errCode); + FFI_EXPORT ArkWeb_ResourceRequest* FfiOHOSWebSHRequestGetHttpBodyStream(int64_t id, int32_t *errCode); } #endif // WEBVIEW_FFI_H \ No newline at end of file diff --git a/interfaces/kits/cj/include/webview_javascript_result_callback.h b/interfaces/kits/cj/include/webview_javascript_result_callback.h index bc4c56379197880be3be41314166166972c12983..1a313945d75aa7a8e6b393f66ac75a96d518d6c1 100644 --- a/interfaces/kits/cj/include/webview_javascript_result_callback.h +++ b/interfaces/kits/cj/include/webview_javascript_result_callback.h @@ -170,7 +170,7 @@ private: bool ConstructArgv(void* ashmem, std::vector> args, std::vector& argv, std::shared_ptr jsObj, int32_t routingId); - char* FlowbufStrAtIndex(void* mem, int flowbuf_index, int* arg_index, int* str_len); + char* FlowbufStrAtIndex(void* mem, int flowbufIndex, int* argIndex, int* strLen); std::shared_ptr GetJavaScriptResultSelfHelper(std::shared_ptr jsObj, const std::string& method, int32_t routingId, std::vector argv); diff --git a/interfaces/kits/cj/include/webview_utils.h b/interfaces/kits/cj/include/webview_utils.h index f7c8ee7da6c8f5c67357985a9576c113f7c56717..68053115f9b7bd1bf790352708e612211f9f04e5 100644 --- a/interfaces/kits/cj/include/webview_utils.h +++ b/interfaces/kits/cj/include/webview_utils.h @@ -48,6 +48,8 @@ namespace Webview { }; char* MallocCString(const std::string& origin); + + using WebHeaderList = std::vector>; } } diff --git a/interfaces/kits/cj/src/web_cookie_manager.cpp b/interfaces/kits/cj/src/web_cookie_manager.cpp index 5810abfcca5cb74a9dd4ede32dd2b9fe70243c78..8956d29de979467398ff29d03c58265ba23e8dff 100644 --- a/interfaces/kits/cj/src/web_cookie_manager.cpp +++ b/interfaces/kits/cj/src/web_cookie_manager.cpp @@ -31,7 +31,7 @@ std::string WebCookieManager::CjGetCookie(const std::string &url, bool incognito } if (cookieContent == "" && !isValid) { errCode = NWebError::INVALID_URL; - return nullptr; + return ""; } errCode = NWebError::NO_ERROR; return cookieContent; diff --git a/interfaces/kits/cj/src/webview_controller_impl.cpp b/interfaces/kits/cj/src/webview_controller_impl.cpp index 10b83226cc52c29ad44119ce56fad0f3d468e351..0698c70867459d1ac2ca36752132f5d44e6cfb8f 100644 --- a/interfaces/kits/cj/src/webview_controller_impl.cpp +++ b/interfaces/kits/cj/src/webview_controller_impl.cpp @@ -607,4 +607,64 @@ namespace OHOS::Webview { } return; } + + void WebviewControllerImpl::SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + WEBVIEWLOGE("WebviewControllerImpl::void SetBackForwardCacheOptions nweb_ptr is null"); + return; + } + nweb_ptr->SetBackForwardCacheOptions(size, timeToLive); + } + + int WebSHRequestImpl::GetRequestResourceType() + { + return requestResourceType_; + } + + bool WebSHRequestImpl::HasGesture() + { + return hasGesture_; + } + + bool WebSHRequestImpl::IsMainFrame() + { + return isMainFrame_; + } + + bool WebSHRequestImpl::IsRedirect() + { + return isRedirect_; + } + + std::string WebSHRequestImpl::GetRequestUrl() + { + return url_; + } + + std::string WebSHRequestImpl::GetMethod() + { + return method_; + } + + std::string WebSHRequestImpl::GetReferrer() + { + return referrer_; + } + + std::string WebSHRequestImpl::GetFrameUrl() + { + return frameUrl_; + } + + const WebHeaderList& WebSHRequestImpl::GetHeader() + { + return headerList_; + } + + ArkWeb_HttpBodyStream* WebSHRequestImpl::GetHttpBodyStream() + { + return stream_; + } } diff --git a/interfaces/kits/cj/src/webview_ffi.cpp b/interfaces/kits/cj/src/webview_ffi.cpp index 62028c2aade09bdae76724873a3a861a364e1a4f..a42b913a1a69e776e85dac828cc1d37ceb735b9c 100644 --- a/interfaces/kits/cj/src/webview_ffi.cpp +++ b/interfaces/kits/cj/src/webview_ffi.cpp @@ -762,6 +762,166 @@ extern "C" { *errCode = NWebError::NO_ERROR; return ret; } + + //WebSchemeHandlerRequest + int64_t FfiOHOSWebSHRequestConstructor() + { + auto nativeWebSHRequest = FFIData::Create(); + if (nativeWebSHRequest == nullptr) { + WEBVIEWLOGE("new Web Scheme Handler Request failed"); + return -1; + } + //WebSHRequestImpl::webDebuggingAccess_ = OHOS::system::GetBoolParameter("web.debug.devtools", false); + return nativeWebSHRequest->GetID(); + } + + + int64_t FfiOHOSWebSHRequestConstructorwithrequest(const ArkWeb_ResourceRequest* request) + { + auto nativeWebSHRequest = FFIData::Create(request); + if (nativeWebSHRequest == nullptr) { + WEBVIEWLOGE("new Web Scheme Handler Request failed"); + return -1; + } + //WebSHRequestImpl::webDebuggingAccess_ = OHOS::system::GetBoolParameter("web.debug.devtools", false); + return nativeWebSHRequest->GetID(); + } + + int32_t FfiOHOSWebSHRequestGetRequestResourceType(int64_t id, int32_t *errCode) + { + auto nativeWebSHRequest = FFIData::GetData(id); + if (nativeWebSHRequest == nullptr) { + *errCode = NWebError::INIT_ERROR; + return -1; + } + int32_t RequestResourceType = nativeWebSHRequest->GetRequestResourceType(); + *errCode = NWebError::NO_ERROR; + return RequestResourceType; + } + + bool FfiOHOSWebSHRequestHasGesture(int64_t id, int32_t *errCode) + { + auto nativeWebSHRequest = FFIData::GetData(id); + if (nativeWebSHRequest == nullptr) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool HasGesture = nativeWebSHRequest->HasGesture(); + *errCode = NWebError::NO_ERROR; + return HasGesture; + } + + bool FfiOHOSWebSHRequestIsMainFrame(int64_t id, int32_t *errCode) + { + auto nativeWebSHRequest = FFIData::GetData(id); + if (nativeWebSHRequest == nullptr) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool IsMainFrame = nativeWebSHRequest->IsMainFrame(); + *errCode = NWebError::NO_ERROR; + return IsMainFrame; + } + + bool FfiOHOSWebSHRequestIsRedirect(int64_t id, int32_t *errCode) + { + auto nativeWebSHRequest = FFIData::GetData(id); + if (nativeWebSHRequest == nullptr) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool IsRedirect = nativeWebSHRequest->IsRedirect(); + *errCode = NWebError::NO_ERROR; + return IsRedirect; + } + + char *FfiOHOSWebSHRequestGetRequestUrl(int64_t id, int32_t *errCode) + { + auto nativeWebSHRequest = FFIData::GetData(id); + if (nativeWebSHRequest == nullptr) { + *errCode = NWebError::INIT_ERROR; + return nullptr; + } + std::string RequestUrl = ""; + RequestUrl = nativeWebSHRequest->GetRequestUrl(); + *errCode = NWebError::NO_ERROR; + return MallocCString(RequestUrl); + } + + char *FfiOHOSWebSHRequestGetMethod(int64_t id, int32_t *errCode) + { + auto nativeWebSHRequest = FFIData::GetData(id); + if (nativeWebSHRequest == nullptr) { + *errCode = NWebError::INIT_ERROR; + return nullptr; + } + std::string Method = ""; + Method = nativeWebSHRequest->GetMethod(); + *errCode = NWebError::NO_ERROR; + return MallocCString(Method); + } + + char *FfiOHOSWebSHRequestGetReferrer(int64_t id, int32_t *errCode) + { + auto nativeWebSHRequest = FFIData::GetData(id); + if (nativeWebSHRequest == nullptr) { + *errCode = NWebError::INIT_ERROR; + return nullptr; + } + std::string Referrer = ""; + Referrer = nativeWebSHRequest->GetReferrer(); + *errCode = NWebError::NO_ERROR; + return MallocCString(Referrer); + } + + char *FfiOHOSWebSHRequestGetFrameUrl(int64_t id, int32_t *errCode) + { + auto nativeWebSHRequest = FFIData::GetData(id); + if (nativeWebSHRequest == nullptr) { + *errCode = NWebError::INIT_ERROR; + return nullptr; + } + std::string FrameUrl = ""; + FrameUrl = nativeWebSHRequest->GetFrameUrl(); + *errCode = NWebError::NO_ERROR; + return MallocCString(FrameUrl); + } + + const WebHeaderList* FfiOHOSWebSHRequestGetHeader(int64_t id, int32_t *errCode) + { + auto nativeWebSHRequest = FFIData::GetData(id); + if (nativeWebSHRequest == nullptr) { + *errCode = NWebError::INIT_ERROR; + return nullptr; + } + WebHeaderList Header; + WebHeaderList* ret = new WebHeaderList; + Header = nativeWebSHRequest->GetHeader(); + *errCode = NWebError::NO_ERROR; + size_t headerSize = Header.size(); + for (size_t index = 0; index < headerSize; index++) { + std::string first = MallocCString(Header[index].first.c_str()); + std::string second = MallocCString(Header[index].second.c_str()); + ret->push_back(std::pair(first,second)); + } + if (ret == nullptr) { + return nullptr; + } + return ret; + } + + // ArkWeb_ResourceRequest* FfiOHOSWebSHRequestGetHttpBodyStream(int64_t id, int32_t *errCode) + // { + // auto nativeWebSHRequest = FFIData::GetData(id); + // if (nativeWebSHRequest == nullptr) { + // *errCode = NWebError::INIT_ERROR; + // return nullptr; + // } + // ArkWeb_ResourceRequest* HttpBodyStream = new HttpBodyStream; + // HttpBodyStream = nativeWebSHRequest->GetHttpBodyStream(); + // *errCode = NWebError::NO_ERROR; + // return ; + // } } } } diff --git a/interfaces/kits/cj/src/webview_javascript_result_callback.cpp b/interfaces/kits/cj/src/webview_javascript_result_callback.cpp index f3ca8d1d055b55b44ee248022fcb09794f2cdef3..358cbc75939a6461a4c16343319e8b3fb5734345 100644 --- a/interfaces/kits/cj/src/webview_javascript_result_callback.cpp +++ b/interfaces/kits/cj/src/webview_javascript_result_callback.cpp @@ -205,37 +205,37 @@ std::shared_ptr WebviewJavaScriptResultCallBackImpl::GetJavaScriptRes } char* WebviewJavaScriptResultCallBackImpl::FlowbufStrAtIndex( - void* mem, int flowbuf_index, int* arg_index, int* str_len) + void* mem, int flowbufIndex, int* argIndex, int* strLen) { int* header = static_cast(mem); // Cast the memory block to int* for easier access int offset = 0; - if (arg_index == nullptr) { + if (argIndex == nullptr) { return nullptr; } - if (flowbuf_index >= MAX_ENTRIES) { - *arg_index = -1; + if (flowbufIndex >= MAX_ENTRIES) { + *argIndex = -1; return nullptr; } - int* entry = header + (flowbuf_index * INDEX_SIZE); + int* entry = header + (flowbufIndex * INDEX_SIZE); if (entry == nullptr) { return nullptr; } if (*(entry + 1) == 0) { // Check if length is 0, indicating unused entry - *arg_index = -1; + *argIndex = -1; return nullptr; } int i = 0; - for (i = 0; i < flowbuf_index; i++) { + for (i = 0; i < flowbufIndex; i++) { offset += *(header + (i * INDEX_SIZE) + 1); } - if (str_len == nullptr) { + if (strLen == nullptr) { return nullptr; } - *str_len = *(header + (i * INDEX_SIZE) + 1) - 1; + *strLen = *(header + (i * INDEX_SIZE) + 1) - 1; - *arg_index = *entry; + *argIndex = *entry; char* dataSegment = static_cast(mem) + HEADER_SIZE; char* currentString = dataSegment + offset; @@ -248,35 +248,35 @@ bool WebviewJavaScriptResultCallBackImpl::ConstructArgv(void* ashmem, std::shared_ptr jsObj, int32_t routingId) { - int arg_index = -1; - int curr_index = 0; - int flowbuf_index = 0; - int str_len = 0; - char* flowbuf_str = FlowbufStrAtIndex(ashmem, flowbuf_index, &arg_index, &str_len); - flowbuf_index++; - while (arg_index == curr_index) { - argv.push_back(std::string(flowbuf_str)); - curr_index ++; - flowbuf_str = FlowbufStrAtIndex(ashmem, flowbuf_index, &arg_index, &str_len); - flowbuf_index++; + int argIndex = -1; + int currIndex = 0; + int flowbufIndex = 0; + int strLen = 0; + char* flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen); + flowbufIndex++; + while (argIndex == currIndex) { + argv.push_back(std::string(flowbufStr)); + currIndex ++; + flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen); + flowbufIndex++; } for (std::shared_ptr input : args) { - while (arg_index == curr_index) { - argv.push_back(std::string(flowbuf_str)); - curr_index ++; - flowbuf_str = FlowbufStrAtIndex(ashmem, flowbuf_index, &arg_index, &str_len); - flowbuf_index++; + while (argIndex == currIndex) { + argv.push_back(std::string(flowbufStr)); + currIndex ++; + flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen); + flowbufIndex++; } argv.push_back(input->GetString()); - curr_index++; + currIndex++; } - while (arg_index == curr_index) { - argv.push_back(std::string(flowbuf_str)); - curr_index ++; - flowbuf_str = FlowbufStrAtIndex(ashmem, flowbuf_index, &arg_index, &str_len); - flowbuf_index++; + while (argIndex == currIndex) { + argv.push_back(std::string(flowbufStr)); + currIndex ++; + flowbufStr = FlowbufStrAtIndex(ashmem, flowbufIndex, &argIndex, &strLen); + flowbufIndex++; } return true; } diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index ad331007d034c05db81f5a807b31e95a8f07fac9..964b8e492e5ce0e5e67deb54449c54ba1573f997 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -51,6 +51,10 @@ ohos_shared_library("webview_napi") { "webfunction/napi_webview_function.cpp", "webfunction/webview_web_inited_callback.cpp", "webstorage/napi_web_storage.cpp", + "webviewcontroller/back_forward_cache_options.cpp", + "webviewcontroller/back_forward_cache_options.h", + "webviewcontroller/napi_back_forward_cache_options.cpp", + "webviewcontroller/napi_back_forward_cache_options.h", "webviewcontroller/napi_native_media_player.cpp", "webviewcontroller/napi_native_media_player.h", "webviewcontroller/napi_web_download_delegate.cpp", diff --git a/interfaces/kits/napi/common/napi_webview_native_module.cpp b/interfaces/kits/napi/common/napi_webview_native_module.cpp index d09ed21fa2c7753a81bd5e56c80386f9c1e7ef7e..4047842051ce1c7e463f50def5a65af0283f9ae2 100644 --- a/interfaces/kits/napi/common/napi_webview_native_module.cpp +++ b/interfaces/kits/napi/common/napi_webview_native_module.cpp @@ -30,6 +30,7 @@ #include "napi_web_download_item.h" #include "napi_web_download_delegate.h" #include "napi_web_scheme_handler_request.h" +#include "napi_back_forward_cache_options.h" namespace OHOS { namespace NWeb { @@ -51,6 +52,8 @@ static napi_value WebViewExport(napi_env env, napi_value exports) NapiWebAdsBlockManager::Init(env, exports); WebFunctionInit(env, exports); NapiNativeMediaPlayerHandler::Init(env, exports); + NapiBackForwardCacheOptions::Init(env, exports); + NapiBackForwardCacheSupportedFeatures::Init(env, exports); return exports; } EXTERN_C_END diff --git a/interfaces/kits/napi/js/webview_export.js b/interfaces/kits/napi/js/webview_export.js index 872b6e5c812e231ece1ebe3696911a9849fc47ef..d71c3d6ec7fc88e8fe0ab2bd8c1aef45f2b935cf 100644 --- a/interfaces/kits/napi/js/webview_export.js +++ b/interfaces/kits/napi/js/webview_export.js @@ -28,11 +28,11 @@ let errMsgMap = new Map(); errMsgMap.set(PARAM_CHECK_ERROR, ERROR_MSG_INVALID_PARAM); class BusinessError extends Error { - constructor(code, errorMsg = "undefined") { - if(errorMsg === "undefined") { + constructor(code, errorMsg = 'undefined') { + if (errorMsg === 'undefined') { let msg = errMsgMap.get(code); super(msg); - }else{ + } else { super(errorMsg); } this.code = code; @@ -230,7 +230,7 @@ Object.defineProperty(webview.WebviewController.prototype, 'getCertificate', { value: function (callback) { if (arguments.length !== 0 && arguments.length !== 1) { throw new BusinessError(PARAM_CHECK_ERROR, - "BusinessError 401: Parameter error. The number of params must be zero or one."); + 'BusinessError 401: Parameter error. The number of params must be zero or one.'); } let certChainData = this.innerGetCertificate(); @@ -241,9 +241,9 @@ Object.defineProperty(webview.WebviewController.prototype, 'getCertificate', { console.log('get certificate async callback'); if (typeof callback !== 'function') { throw new BusinessError(PARAM_CHECK_ERROR, - "BusinessError 401: Parameter error. The type of 'callback' must be function." ); + 'BusinessError 401: Parameter error. The type of "callback" must be function.' ); } - getCertificatePromise(certChainData).then(x509CertArray => { + return getCertificatePromise(certChainData).then(x509CertArray => { callback(undefined, x509CertArray); }).catch(error => { callback(error, undefined); diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f6fcbb15d833af46b983cd79cf56902821618a95 --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#include "back_forward_cache_options.h" + +#include + +#include "napi_parse_utils.h" +#include "nweb_log.h" +#include "business_error.h" +#include "web_errors.h" + +namespace OHOS::NWeb { +BackForwardCacheOptions::BackForwardCacheOptions() +{ + WVLOG_D("Created a BackForwardCacheOptions class."); +} + +int32_t BackForwardCacheOptions::GetSize() +{ + return size_; +} + +int32_t BackForwardCacheOptions::GetTimeToLive() +{ + return timeToLive_; +} + +BackForwardCacheSupportedFeatures::BackForwardCacheSupportedFeatures() +{ + WVLOG_D("Created a BackForwardCacheSupportedFeatures class."); +} + +bool BackForwardCacheSupportedFeatures::IsEnableNativeEmbed() +{ + return nativeEmbed_; +} + +bool BackForwardCacheSupportedFeatures::IsEnableMediaTakeOver() +{ + return mediaTakeOver_; +} + +} \ No newline at end of file diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h new file mode 100644 index 0000000000000000000000000000000000000000..e11da84d483da4edae3d1ad43adf674f4cdc5e24 --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#ifndef NWEB_BACK_FORWARD_CACHE_OPTIONS_H +#define NWEB_BACK_FORWARD_CACHE_OPTIONS_H + +#include +#include + +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" + +#define BFCACHE_DEFAULT_SIZE 1 +#define BFCACHE_DEFAULT_TIMETOLIVE 600 + +namespace OHOS { +namespace NWeb { +class BackForwardCacheOptions { +public: + BackForwardCacheOptions(); + int32_t GetSize(); + int32_t GetTimeToLive(); + +private: + int32_t size_ = 1; + int32_t timeToLive_ = 600; +}; + +class BackForwardCacheSupportedFeatures { +public: + BackForwardCacheSupportedFeatures(); + bool IsEnableNativeEmbed(); + bool IsEnableMediaTakeOver(); + +private: + bool nativeEmbed_ = false; + bool mediaTakeOver_ = false; +}; + +} +} + +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f149c6007c5c5cb47891aded0113f6e1d74b7e6d --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp @@ -0,0 +1,106 @@ +/* + * 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. + */ + +#include "napi_back_forward_cache_options.h" + +#include +#include +#include +#include +#include + +#include "back_forward_cache_options.h" +#include "business_error.h" +#include "nweb_log.h" +#include "napi_parse_utils.h" +#include "napi/native_node_api.h" +#include "web_errors.h" + +using namespace OHOS::NWebError; + +namespace OHOS { +namespace NWeb { +napi_value NapiBackForwardCacheOptions::JS_Constructor(napi_env env, napi_callback_info info) +{ + WVLOG_I("NapiBackForwardCacheOptions::JS_Constructor is called"); + napi_value thisVar = nullptr; + void *data = nullptr; + size_t argc = 2; + napi_value argv[2] = {0}; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + + BackForwardCacheOptions *options = new BackForwardCacheOptions(); + + napi_wrap( + env, thisVar, options, + [](napi_env /* env */, void *data, void * /* hint */) { + BackForwardCacheOptions *options = (BackForwardCacheOptions *)data; + delete options; + options = nullptr; + }, + nullptr, nullptr); + + return thisVar; +} + +napi_value NapiBackForwardCacheSupportedFeatures::JS_Constructor(napi_env env, napi_callback_info info) +{ + WVLOG_I("NapiBackForwardCacheSupportedFeatures::JS_Constructor is called"); + napi_value thisVar = nullptr; + void *data = nullptr; + size_t argc = 2; + napi_value argv[2] = {0}; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + + BackForwardCacheSupportedFeatures *features = new BackForwardCacheSupportedFeatures(); + + napi_wrap( + env, thisVar, features, + [](napi_env /* env */, void *data, void * /* hint */) { + BackForwardCacheSupportedFeatures *features = (BackForwardCacheSupportedFeatures *)data; + delete features; + features = nullptr; + }, + nullptr, nullptr); + + return thisVar; +} + +napi_value NapiBackForwardCacheOptions::Init(napi_env env, napi_value exports) +{ + WVLOG_D("NapiBackForwardCacheOptions::Init"); + napi_value backForwardCacheOptions = nullptr; + napi_define_class(env, BACK_FORWARD_CACHE_OPTIONS.c_str(), + BACK_FORWARD_CACHE_OPTIONS.length(), + JS_Constructor, nullptr, 0, nullptr, &backForwardCacheOptions); + napi_set_named_property(env, exports, BACK_FORWARD_CACHE_OPTIONS.c_str(), + backForwardCacheOptions); + return exports; +} + +napi_value NapiBackForwardCacheSupportedFeatures::Init(napi_env env, napi_value exports) +{ + WVLOG_D("NapiBackForwardCacheSupportedFeatures::Init"); + napi_value backForwardCacheSupportedFeatures = nullptr; + napi_define_class(env, BACK_FORWARD_CACHE_SUPPORTED_FEATURES.c_str(), + BACK_FORWARD_CACHE_SUPPORTED_FEATURES.length(), + JS_Constructor, nullptr, 0, nullptr, &backForwardCacheSupportedFeatures); + napi_set_named_property(env, exports, BACK_FORWARD_CACHE_SUPPORTED_FEATURES.c_str(), + backForwardCacheSupportedFeatures); + return exports; +} + +} +} \ No newline at end of file diff --git a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h new file mode 100644 index 0000000000000000000000000000000000000000..2d04145c96a5648acb7ecedc032d274ee732c373 --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef NWEB_NAPI_BACK_FORWARD_CACHE_OPTIONS_H +#define NWEB_NAPI_BACK_FORWARD_CACHE_OPTIONS_H + +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" + +namespace OHOS { +namespace NWeb { + +const std::string BACK_FORWARD_CACHE_OPTIONS = "BackForwardCacheOptions"; +const std::string BACK_FORWARD_CACHE_SUPPORTED_FEATURES = "BackForwardCacheSupportedFeatures"; + +class NapiBackForwardCacheOptions { +public: + NapiBackForwardCacheOptions() = default; + ~NapiBackForwardCacheOptions() = default; + + static napi_value Init(napi_env env, napi_value exports); + static napi_value JS_Constructor(napi_env env, napi_callback_info info); +}; + +class NapiBackForwardCacheSupportedFeatures { +public: + NapiBackForwardCacheSupportedFeatures() = default; + ~NapiBackForwardCacheSupportedFeatures() = default; + + static napi_value Init(napi_env env, napi_value exports); + static napi_value JS_Constructor(napi_env env, napi_callback_info info); +}; + +} +} + +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp b/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp index a49293da2a107161eb50a22021f61024775b0cb5..17ca2f7c416ee5b0af3359f4c5b9b8252caf4f86 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp @@ -40,6 +40,8 @@ void NapiNativeMediaPlayerHandler::Init(napi_env env, napi_value value) NAPI_CALL_RETURN_VOID(env, ExportEnumReadyState(env, &value)); + NAPI_CALL_RETURN_VOID(env, ExportEnumSuspendType(env, &value)); + NAPI_CALL_RETURN_VOID(env, ExportEnumNetworkState(env, &value)); NAPI_CALL_RETURN_VOID(env, ExportEnumPlaybackStatus(env, &value)); @@ -172,16 +174,16 @@ napi_status NapiNativeMediaPlayerHandler::ExportEnumReadyState(napi_env env, nap napi_status NapiNativeMediaPlayerHandler::ExportEnumSuspendType(napi_env env, napi_value* value) { - WVLOG_D("begin to export enum suspend type state"); + WVLOG_D("begin to export enum suspend type"); const std::string NPI_SUSPEND_TYPE_ENUM_NAME = "SuspendType"; napi_property_descriptor properties[] = { + DECLARE_NAPI_STATIC_PROPERTY("ENTER_BACK_FORWARD_CACHE", + NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::ENTER_BACK_FORWARD_CACHE))), DECLARE_NAPI_STATIC_PROPERTY( - "EnterBFCache", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::EnterBFCache))), - DECLARE_NAPI_STATIC_PROPERTY( - "EnterBackground", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::EnterBackground))), + "ENTER_BACKGROUND", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::ENTER_BACKGROUND))), DECLARE_NAPI_STATIC_PROPERTY( - "PausedOverTime", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::PausedOverTime))), + "AUTO_CLEANUP", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::AUTO_CLEANUP))), }; napi_value enumValue = nullptr; diff --git a/interfaces/kits/napi/webviewcontroller/napi_web_download_item.cpp b/interfaces/kits/napi/webviewcontroller/napi_web_download_item.cpp index 0c9742d589f939b03e9dcfe046f8af0f7412df75..a912fbdf9727218999ef2025ed5f1134aa0a64be 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_web_download_item.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_web_download_item.cpp @@ -513,8 +513,8 @@ napi_value NapiWebDownloadItem::JS_Pause(napi_env env, napi_callback_info cbinfo WVLOG_E("[DOWNLOAD] unwrap webDownloadItem failed"); return nullptr; } - NWebDownloadItemState state = WebDownload_GetItemState( - webDownloadItem->nwebId, webDownloadItem->webDownloadId); + NWebDownloadItemState state = WebDownload_GetItemStateByGuid(webDownloadItem->guid); + WVLOG_D("[DOWNLOAD] pause state %{public}d", static_cast(state)); if (state != NWebDownloadItemState::IN_PROGRESS && state != NWebDownloadItemState::PENDING) { BusinessError::ThrowErrorByErrcode(env, DOWNLOAD_NOT_START); @@ -545,8 +545,8 @@ napi_value NapiWebDownloadItem::JS_Resume(napi_env env, napi_callback_info cbinf return nullptr; } - NWebDownloadItemState state = WebDownload_GetItemState( - webDownloadItem->nwebId, webDownloadItem->webDownloadId); + NWebDownloadItemState state = WebDownload_GetItemStateByGuid(webDownloadItem->guid); + WVLOG_D("[DOWNLOAD] resume state %{public}d", static_cast(state)); if (state != NWebDownloadItemState::PAUSED) { BusinessError::ThrowErrorByErrcode(env, DOWNLOAD_NOT_PAUSED); return nullptr; @@ -614,6 +614,7 @@ napi_value NapiWebDownloadItem::JS_Start(napi_env env, napi_callback_info cbinfo return nullptr; } webDownloadItem->downloadPath = std::string(stringValue); + WVLOG_D("NapiWebDownloadItem::JS_Start, download_path: %s", webDownloadItem->downloadPath.c_str()); WebDownload_Continue(webDownloadItem->before_download_callback, webDownloadItem->downloadPath.c_str()); return nullptr; } diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 84119e8c0e97345d1e4d7f5dd0b8bd6b4512421a..5f7d0f80d6565c797fc627ddeafeccf72ee1a127 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -44,6 +44,8 @@ #include "arkweb_scheme_handler.h" #include "web_scheme_handler_request.h" +#include "back_forward_cache_options.h" + namespace OHOS { namespace NWeb { using namespace NWebError; @@ -525,6 +527,10 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("webPageSnapshot", NapiWebviewController::WebPageSnapshot), DECLARE_NAPI_FUNCTION("setPathAllowingUniversalAccess", NapiWebviewController::SetPathAllowingUniversalAccess), + DECLARE_NAPI_STATIC_FUNCTION("enableBackForwardCache", NapiWebviewController::EnableBackForwardCache), + DECLARE_NAPI_FUNCTION("setBackForwardCacheOptions", NapiWebviewController::SetBackForwardCacheOptions), + DECLARE_NAPI_STATIC_FUNCTION("trimMemoryByPressureLevel", + NapiWebviewController::TrimMemoryByPressureLevel), }; napi_value constructor = nullptr; napi_define_class(env, WEBVIEW_CONTROLLER_CLASS_NAME.c_str(), WEBVIEW_CONTROLLER_CLASS_NAME.length(), @@ -708,6 +714,18 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) sizeof(offlineResourceTypeProperties[0]), offlineResourceTypeProperties, &offlineResourceTypeEnum); napi_set_named_property(env, exports, OFFLINE_RESOURCE_TYPE_ENUM_NAME.c_str(), offlineResourceTypeEnum); + napi_value pressureLevelEnum = nullptr; + napi_property_descriptor pressureLevelProperties[] = { + DECLARE_NAPI_STATIC_PROPERTY("MEMORY_PRESSURE_LEVEL_MODERATE", NapiParseUtils::ToInt32Value(env, + static_cast(PressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE))), + DECLARE_NAPI_STATIC_PROPERTY("MEMORY_PRESSURE_LEVEL_CRITICAL", NapiParseUtils::ToInt32Value(env, + static_cast(PressureLevel::MEMORY_PRESSURE_LEVEL_CRITICAL))), + }; + napi_define_class(env, WEB_PRESSURE_LEVEL_ENUM_NAME.c_str(), WEB_PRESSURE_LEVEL_ENUM_NAME.length(), + NapiParseUtils::CreateEnumConstructor, nullptr, sizeof(pressureLevelProperties) / + sizeof(pressureLevelProperties[0]), pressureLevelProperties, &pressureLevelEnum); + napi_set_named_property(env, exports, WEB_PRESSURE_LEVEL_ENUM_NAME.c_str(), pressureLevelEnum); + WebviewJavaScriptExecuteCallback::InitJSExcute(env, exports); return exports; } @@ -1148,11 +1166,12 @@ napi_value NapiWebviewController::OnActive(napi_env env, napi_callback_info info napi_value result = nullptr; WebviewController *webviewController = GetWebviewController(env, info); if (!webviewController) { + WVLOG_E("NapiWebviewController::OnActive get controller failed"); return nullptr; } webviewController->OnActive(); - WVLOG_D("The web component has been successfully activated"); + WVLOG_I("The web component has been successfully activated"); NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } @@ -1162,11 +1181,12 @@ napi_value NapiWebviewController::OnInactive(napi_env env, napi_callback_info in napi_value result = nullptr; WebviewController *webviewController = GetWebviewController(env, info); if (!webviewController) { + WVLOG_E("NapiWebviewController::OnInactive get controller failed"); return nullptr; } webviewController->OnInactive(); - WVLOG_D("The web component has been successfully inactivated"); + WVLOG_I("The web component has been successfully inactivated"); NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } @@ -5481,6 +5501,86 @@ napi_value NapiWebviewController::PrecompileJavaScript(napi_env env, napi_callba return promise; } +napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_callback_info info) +{ + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + napi_get_undefined(env, &result); + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + if (argc != INTEGER_ONE) { + WVLOG_E("SetBackForwardCacheOptions: wrong number of params."); + NWebHelper::Instance().EnableBackForwardCache(false, false); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; + } + + bool nativeEmbed = false; + bool mediaTakeOver = false; + napi_value embedObj = nullptr; + napi_value mediaObj = nullptr; + if (napi_get_named_property(env, argv[INTEGER_ZERO], "nativeEmbed", &embedObj) == napi_ok) { + if (!NapiParseUtils::ParseBoolean(env, embedObj, nativeEmbed)) { + nativeEmbed = false; + } + } + + if (napi_get_named_property(env, argv[INTEGER_ZERO], "mediaTakeOver", &mediaObj) != napi_ok) { + if (!NapiParseUtils::ParseBoolean(env, mediaObj, mediaTakeOver)) { + mediaTakeOver = false; + } + } + + NWebHelper::Instance().EnableBackForwardCache(nativeEmbed, mediaTakeOver); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; +} + +napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_callback_info info) +{ + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + napi_get_undefined(env, &result); + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + WebviewController* webviewController = GetWebviewController(env, info); + if (!webviewController) { + WVLOG_E("SetBackForwardCacheOptions: Init webview controller error."); + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); + return result; + } + + if (argc != INTEGER_ONE) { + WVLOG_E("SetBackForwardCacheOptions: wrong number of params."); + webviewController->SetBackForwardCacheOptions( + BFCACHE_DEFAULT_SIZE, BFCACHE_DEFAULT_TIMETOLIVE); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; + } + + int32_t size = 1; + int32_t timeToLive = 600; + napi_value sizeObj = nullptr; + napi_value timeToLiveObj = nullptr; + if (napi_get_named_property(env, argv[INTEGER_ZERO], "size", &sizeObj) == napi_ok) { + if (!NapiParseUtils::ParseInt32(env, sizeObj, size)) { + size = BFCACHE_DEFAULT_SIZE; + } + } + + if (napi_get_named_property(env, argv[INTEGER_ZERO], "timeToLive", &timeToLiveObj) == napi_ok) { + if (!NapiParseUtils::ParseInt32(env, timeToLiveObj, timeToLive)) { + timeToLive = BFCACHE_DEFAULT_TIMETOLIVE; + } + } + + webviewController->SetBackForwardCacheOptions(size, timeToLive); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; +} + napi_value NapiWebviewController::WarmupServiceWorker(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -6088,5 +6188,34 @@ napi_value NapiWebviewController::SetPathAllowingUniversalAccess( } return result; } + +napi_value NapiWebviewController::TrimMemoryByPressureLevel(napi_env env, + napi_callback_info info) +{ + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + int32_t memoryLevel; + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + if (argc != INTEGER_ONE) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString( + ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "one")); + return result; + } + + if (!NapiParseUtils::ParseInt32(env, argv[INTEGER_ZERO], memoryLevel)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, + "PressureLevel", "number")); + return result; + } + + memoryLevel = memoryLevel == 1 ? 0 : memoryLevel; + NWebHelper::Instance().TrimMemoryByPressureLevel(memoryLevel); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; +} } // namespace NWeb } // namespace OHOS diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h index bab044a4ee8c6b4908f8ac22175005bf46e0b01e..5a0c1ae913ee3e77c0f823ea20f49c75ead857ee 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -40,6 +40,7 @@ const std::string WEB_PRINT_DOCUMENT_CLASS_NAME = "WebPrintDocument"; const std::string WEB_SECURITY_LEVEL_ENUM_NAME = "SecurityLevel"; const std::string WEB_RENDER_PROCESS_MODE_ENUM_NAME = "RenderProcessMode"; const std::string OFFLINE_RESOURCE_TYPE_ENUM_NAME = "OfflineResourceType"; +const std::string WEB_PRESSURE_LEVEL_ENUM_NAME = "PressureLevel"; struct Scheme { std::string name; @@ -348,6 +349,12 @@ private: static napi_value SetPathAllowingUniversalAccess(napi_env env, napi_callback_info info); + static napi_value EnableBackForwardCache(napi_env env, napi_callback_info info); + + static napi_value SetBackForwardCacheOptions(napi_env env, napi_callback_info info); + + static napi_value TrimMemoryByPressureLevel(napi_env env, napi_callback_info info); + static int32_t maxFdNum_; static std::atomic usedFd_; }; diff --git a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp index ae5aa70a4e26eddaa944723e2dd6a3829b27fad0..a0bbf6d437e1e7340d83b99a383a0928bee8789f 100644 --- a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp +++ b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp @@ -163,7 +163,7 @@ void NWebNativeMediaPlayerBridgeImpl::SuspendMediaPlayer(SuspendType type) napi_value argv[INTEGER_ONE] = { nullptr }; NAPI_CALL_RETURN_VOID(env_, napi_create_int32(env_, static_cast(type), &argv[INTEGER_ZERO])); - NAPI_CALL_RETURN_VOID(env_, napi_call_function(env_, value_, callback, INTEGER_ZERO, nullptr, nullptr)); + NAPI_CALL_RETURN_VOID(env_, napi_call_function(env_, value_, callback, INTEGER_ONE, argv, nullptr)); } NapiNativeMediaPlayerHandlerImpl::NapiNativeMediaPlayerHandlerImpl( diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp index 8541e8e1f735da55f50e365d5a052e76292110a5..6480d7fbb45adbf8d332455c14d20a07a715c6d9 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp @@ -1973,5 +1973,15 @@ void WebviewController::ScrollByWithAnime(float deltaX, float deltaY, int32_t du } return; } + +void WebviewController::SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) +{ + auto nweb_ptr = NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return; + } + + nweb_ptr->SetBackForwardCacheOptions(size, timeToLive); +} } // namespace NWeb } // namespace OHOS diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.h b/interfaces/kits/napi/webviewcontroller/webview_controller.h index d9f804eaead3774130d1d87f6a9ccc2a5a8b9bf6..5876499501c9b846d3106fac480cf4306fe42406 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.h @@ -21,6 +21,7 @@ #include #include +#include "back_forward_cache_options.h" #include "napi/native_api.h" #include "napi/native_common.h" #include "napi/native_node_api.h" @@ -116,6 +117,11 @@ enum class UrlListSetResult : int { SET_OK = 0, }; +enum class PressureLevel : int { + MEMORY_PRESSURE_LEVEL_MODERATE = 1, + MEMORY_PRESSURE_LEVEL_CRITICAL = 2, +}; + class WebPrintDocument; class WebviewController { public: @@ -373,6 +379,8 @@ public: void ScrollToWithAnime(float x, float y, int32_t duration) ; void ScrollByWithAnime(float deltaX, float deltaY, int32_t duration) ; + + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive); private: int ConverToWebHitTestType(int hitType); diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 2b0e2b7f4389c4837f459a179f2874591d07c626..802467745b10ab277195379250d09e36557a947e 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -102,6 +102,7 @@ ohos_shared_library("nweb_ohos_adapter") { "screen_capture_adapter/include", "soc_perf_adapter/include", "system_properties_adapter/include", + "sensor_adapter/include", ] public_configs = [ ":ohos_adapter_public_interface" ] @@ -143,6 +144,7 @@ ohos_shared_library("nweb_ohos_adapter") { "napi:ace_napi", "netmanager_base:net_conn_manager_if", "netstack:net_ssl", + "openssl:libssl_shared", "pasteboard:pasteboard_client", "relational_store:native_rdb", "resource_schedule_service:ressched_client", @@ -243,9 +245,11 @@ ohos_shared_library("nweb_ohos_adapter") { if (webview_telephony_enable) { sources += [ + "net_connect_adapter/src/net_capabilities_adapter_impl.cpp", "net_connect_adapter/src/net_connect_adapter_impl.cpp", "net_connect_adapter/src/net_connect_callback_impl.cpp", "net_connect_adapter/src/net_connect_utils.cpp", + "net_connect_adapter/src/net_connection_properties_adapter_impl.cpp", ] external_deps += [ "cellular_data:tel_cellular_data_api", @@ -286,6 +290,12 @@ ohos_shared_library("nweb_ohos_adapter") { defines += [ "NWEB_MEDIA_AVSESSION_ENABLE" ] } + if (webview_sensors_sensor_enable) { + sources += [ "sensor_adapter/src/sensor_adapter_impl.cpp" ] + external_deps += [ "sensor:sensor_interface_native" ] + defines += [ "NWEB_SENSORS_SENSOR_ENABLE" ] + } + innerapi_tags = [ "platformsdk" ] part_name = "webview" subsystem_name = "web" diff --git a/ohos_adapter/aafwk_adapter/src/aafwk_render_scheduler_impl.cpp b/ohos_adapter/aafwk_adapter/src/aafwk_render_scheduler_impl.cpp index c4785d8e57daf8c1eab5f0c94c01959e87c0838e..d95ea28d093c31d79d62fff70a06fca5cf2d0300 100644 --- a/ohos_adapter/aafwk_adapter/src/aafwk_render_scheduler_impl.cpp +++ b/ohos_adapter/aafwk_adapter/src/aafwk_render_scheduler_impl.cpp @@ -34,7 +34,7 @@ void AafwkRenderSchedulerImpl::NotifyBrowserFd( return; } if (browser == nullptr) { - WVLOG_E("browser is nullptr!"); + WVLOG_D("NotifyBrowserFd for render process."); renderSchedulerHostAdapter_->NotifyBrowser(ipcFd, sharedFd, crashFd, nullptr); } else { sptr browserHost = iface_cast(browser); diff --git a/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp b/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp index 4b79df9c1e3afcc7e02c456076162b7d19b7e4c0..0a7c3f8eddf6bf3651780c4c2fad1bf1dca709a6 100644 --- a/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp +++ b/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp @@ -170,12 +170,11 @@ void VSyncAdapterImpl::SetFrameRateLinkerEnable(bool enabled) return; } - Rosen::FrameRateRange range = {0, RANGE_MAX_REFRESHRATE, 120, WEBVIEW_FRAME_RATE_TYPE}; if (frameRateLinker_) { if (!enabled) { - range = {0, RANGE_MAX_REFRESHRATE, 0, WEBVIEW_FRAME_RATE_TYPE}; + Rosen::FrameRateRange range = {0, RANGE_MAX_REFRESHRATE, 0, WEBVIEW_FRAME_RATE_TYPE}; + frameRateLinker_->UpdateFrameRateRangeImme(range); } - frameRateLinker_->UpdateFrameRateRangeImme(range); frameRateLinker_->SetEnable(enabled); frameRateLinkerEnable_ = enabled; } diff --git a/ohos_adapter/hiviewdfx_adapter/include/hitrace_adapter_impl.h b/ohos_adapter/hiviewdfx_adapter/include/hitrace_adapter_impl.h index 227957c6d94a07d80ada3d8e8a7b77b0850dc3f3..97cde921f0a16addc05bbc0a39f8685bf4db4d07 100644 --- a/ohos_adapter/hiviewdfx_adapter/include/hitrace_adapter_impl.h +++ b/ohos_adapter/hiviewdfx_adapter/include/hitrace_adapter_impl.h @@ -43,14 +43,7 @@ public: void CountOHOSTrace(const std::string& name, int64_t count) override; - void UpdateOHOSTraceTag(const char* value); - bool IsACETraceEnable() override; - -private: - bool firstAceEnable_ = false; - bool isNWEBTraceEnable_ = false; - bool isOHOSTraceEnable_ = false; }; } // namespace OHOS::NWeb diff --git a/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp b/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp index 27ef05c3c7d75ca9f3818d84e4a196df99c7bd7f..62faf1a0145d0bec7fe6c3752598b42d4b89e1bc 100644 --- a/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp +++ b/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp @@ -62,47 +62,43 @@ bool HiTraceAdapterImpl::IsHiTraceEnable() static CachedHandle g_Handle = CachedParameterCreate("debug.hitrace.tags.enableflags", "0"); int changed = 0; const char *enable = CachedParameterGetChanged(g_Handle, &changed); - auto tags = ConvertToInt(enable, 0); - firstAceEnable_ = tags & HITRACE_TAG_ACE; + uint64_t tags = static_cast(ConvertToInt(enable, 0)); return (tags & HITRACE_TAG_NWEB); } void HiTraceAdapterImpl::StartOHOSTrace(const std::string& value, float limit) { - if (isOHOSTraceEnable_) { - ::StartTrace(HITRACE_TAG_ACE, value, limit); - } else if (isNWEBTraceEnable_) { + if (IsHiTraceEnable()) { ::StartTrace(HITRACE_TAG_NWEB, value, limit); + } else if (IsACETraceEnable()) { + ::StartTrace(HITRACE_TAG_ACE, value, limit); } } void HiTraceAdapterImpl::FinishOHOSTrace() { - if (isOHOSTraceEnable_) { - ::FinishTrace(HITRACE_TAG_ACE); - } else if (isNWEBTraceEnable_) { + if (IsHiTraceEnable()) { ::FinishTrace(HITRACE_TAG_NWEB); + } else if (IsACETraceEnable()) { + ::FinishTrace(HITRACE_TAG_ACE); } } void HiTraceAdapterImpl::CountOHOSTrace(const std::string& name, int64_t count) { - if (isOHOSTraceEnable_) { - ::CountTrace(HITRACE_TAG_ACE, name, count); - } else if (isNWEBTraceEnable_) { + if (IsHiTraceEnable()) { ::CountTrace(HITRACE_TAG_NWEB, name, count); + } else if (IsACETraceEnable()) { + ::CountTrace(HITRACE_TAG_ACE, name, count); } } -void HiTraceAdapterImpl::UpdateOHOSTraceTag(const char* value) -{ - auto status = std::stoul(value); - isNWEBTraceEnable_ = status & HITRACE_TAG_NWEB; - isOHOSTraceEnable_ = status & HITRACE_TAG_ACE; -} - bool HiTraceAdapterImpl::IsACETraceEnable() { - return firstAceEnable_; + static CachedHandle g_Handle = CachedParameterCreate("debug.hitrace.tags.enableflags", "0"); + int changed = 0; + const char *enable = CachedParameterGetChanged(g_Handle, &changed); + uint64_t tags = static_cast(ConvertToInt(enable, 0)); + return (tags & HITRACE_TAG_ACE); } } // namespace OHOS::NWeb diff --git a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp index e2b5bc8f3d128277b5baef346aa44c4e6e4a047e..4d832a1952d3804c9f75a33ab99d258daa2e29a9 100644 --- a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp +++ b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp @@ -300,9 +300,13 @@ bool IMFAdapterImpl::Attach(std::shared_ptr listener, bo .width = config->GetCursorInfo()->GetWidth(), .height = config->GetCursorInfo()->GetHeight() }; - MiscServices::TextConfig textConfig = { - .inputAttribute = inputAttribute, .cursorInfo = imfInfo, .windowId = config->GetWindowId() - }; + MiscServices::TextConfig textConfig = { .inputAttribute = inputAttribute, + .cursorInfo = imfInfo, + .windowId = config->GetWindowId(), + .positionY = config->GetPositionY(), + .height = config->GetHeight() }; + WVLOG_I("web inputmethod attach, isShowKeyboard=%{public}d, textConfig=%{public}s", isShowKeyboard, + textConfig.ToString().c_str()); int32_t ret = MiscServices::InputMethodController::GetInstance()->Attach(textListener_, isShowKeyboard, textConfig); if (ret != 0) { WVLOG_E("inputmethod attach failed, errcode=%{public}d", ret); diff --git a/ohos_adapter/net_connect_adapter/include/net_capabilities_adapter_impl.h b/ohos_adapter/net_connect_adapter/include/net_capabilities_adapter_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..c53b9526c5fb73ad7e71e7a90e9fdfa3922b86ca --- /dev/null +++ b/ohos_adapter/net_connect_adapter/include/net_capabilities_adapter_impl.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef NET_CAPABILITIES_ADAPTER_IMPL_H +#define NET_CAPABILITIES_ADAPTER_IMPL_H + +#include "net_connect_adapter.h" + +namespace OHOS::NWeb { + +class NetCapabilitiesAdapterImpl : public NetCapabilitiesAdapter { +public: + NetCapabilitiesAdapterImpl() = default; + + ~NetCapabilitiesAdapterImpl() override = default; + + int32_t GetNetId() override; + + NetConnectType GetConnectType() override; + + NetConnectSubtype GetConnectSubtype() override; + + void SetNetId(int32_t netId); + + void SetConnectType(NetConnectType type); + + void SetConnectSubtype(NetConnectSubtype subtype); + +private: + int32_t netId_ = -1; + NetConnectType type_ = NetConnectType::CONNECTION_UNKNOWN; + NetConnectSubtype subtype_ = NetConnectSubtype::SUBTYPE_UNKNOWN; +}; + +} // namespace OHOS::NWeb + +#endif // NET_CAPABILITIES_ADAPTER_IMPL_H diff --git a/ohos_adapter/net_connect_adapter/include/net_connection_properties_adapter_impl.h b/ohos_adapter/net_connect_adapter/include/net_connection_properties_adapter_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..c453e8e17aeaa5b063b7c002aa170f6abdb268e6 --- /dev/null +++ b/ohos_adapter/net_connect_adapter/include/net_connection_properties_adapter_impl.h @@ -0,0 +1,39 @@ +/* + * 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. + */ + +#ifndef NET_CONNECTION_PROPERTIES_ADAPTER_IMPL_H +#define NET_CONNECTION_PROPERTIES_ADAPTER_IMPL_H + +#include "net_connect_adapter.h" + +namespace OHOS::NWeb { + +class NetConnectionPropertiesAdapterImpl : public NetConnectionPropertiesAdapter { +public: + NetConnectionPropertiesAdapterImpl() = default; + + ~NetConnectionPropertiesAdapterImpl() override = default; + + int32_t GetNetId() override; + + void SetNetId(int32_t netId); + +private: + int32_t netId_ = -1; +}; + +} // namespace OHOS::NWeb + +#endif // NET_CONNECTION_PROPERTIES_ADAPTER_IMPL_H diff --git a/ohos_adapter/net_connect_adapter/src/net_capabilities_adapter_impl.cpp b/ohos_adapter/net_connect_adapter/src/net_capabilities_adapter_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d63e0ea51a6622a964e47e7b7b62c6939ec305e --- /dev/null +++ b/ohos_adapter/net_connect_adapter/src/net_capabilities_adapter_impl.cpp @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#include "net_capabilities_adapter_impl.h" + +namespace OHOS::NWeb { + +int32_t NetCapabilitiesAdapterImpl::GetNetId() +{ + return netId_; +} + +NetConnectType NetCapabilitiesAdapterImpl::GetConnectType() +{ + return type_; +} + +NetConnectSubtype NetCapabilitiesAdapterImpl::GetConnectSubtype() +{ + return subtype_; +} + +void NetCapabilitiesAdapterImpl::SetNetId(int32_t netId) +{ + netId_ = netId; +} + +void NetCapabilitiesAdapterImpl::SetConnectType(NetConnectType type) +{ + type_ = type; +} + +void NetCapabilitiesAdapterImpl::SetConnectSubtype(NetConnectSubtype subtype) +{ + subtype_ = subtype; +} + +} // namespace OHOS::NWeb \ No newline at end of file diff --git a/ohos_adapter/net_connect_adapter/src/net_connect_callback_impl.cpp b/ohos_adapter/net_connect_adapter/src/net_connect_callback_impl.cpp index ded4a4796617f393515502d7e64c3072d01df56f..a3dd17caca448d13914a5c0ef4e6ba29bd4e9346 100644 --- a/ohos_adapter/net_connect_adapter/src/net_connect_callback_impl.cpp +++ b/ohos_adapter/net_connect_adapter/src/net_connect_callback_impl.cpp @@ -78,7 +78,7 @@ int32_t NetConnectCallbackImpl::NetCapabilitiesChange(sptr &netHandle int32_t NetConnectCallbackImpl::NetConnectionPropertiesChange(sptr &netHandle, const sptr &info) { if (netHandle == nullptr || info == nullptr) { - WVLOG_E("NetConnCallback enter, NetCapabilitiesChange, netHandle or info is nullptr."); + WVLOG_E("NetConnCallback enter, NetConnectionPropertiesChange, netHandle or info is nullptr."); return 0; } diff --git a/ohos_adapter/net_connect_adapter/src/net_connection_properties_adapter_impl.cpp b/ohos_adapter/net_connect_adapter/src/net_connection_properties_adapter_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..340aa4aa6b14b89012f1508c83f981c1759c36c6 --- /dev/null +++ b/ohos_adapter/net_connect_adapter/src/net_connection_properties_adapter_impl.cpp @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#include "net_connection_properties_adapter_impl.h" + +namespace OHOS::NWeb { + +int32_t NetConnectionPropertiesAdapterImpl::GetNetId() +{ + return netId_; +} + +void NetConnectionPropertiesAdapterImpl::SetNetId(int32_t netId) +{ + netId_ = netId; +} + +} // namespace OHOS::NWeb \ No newline at end of file diff --git a/ohos_adapter/ohos_adapter_helper/include/ohos_adapter_helper_impl.h b/ohos_adapter/ohos_adapter_helper/include/ohos_adapter_helper_impl.h index 7ca517ce103ae7972e9aae6aff4da74e27313e27..7bd751b8c9e5e1a9ed350689f48898e49e4a97e9 100644 --- a/ohos_adapter/ohos_adapter_helper/include/ohos_adapter_helper_impl.h +++ b/ohos_adapter/ohos_adapter_helper/include/ohos_adapter_helper_impl.h @@ -110,6 +110,8 @@ public: std::unique_ptr CreateMediaAVSessionAdapter() override; std::unique_ptr CreateOhosImageDecoderAdapter() override; + + std::unique_ptr CreateSensorAdapter() override; }; } // namespace OHOS::NWeb diff --git a/ohos_adapter/ohos_adapter_helper/src/ohos_adapter_helper_impl.cpp b/ohos_adapter/ohos_adapter_helper/src/ohos_adapter_helper_impl.cpp index 66b6a8f388c6393945955350c2e100f80c184a7c..8c429eacb7ead265e39ff2def286627f256d538b 100644 --- a/ohos_adapter/ohos_adapter_helper/src/ohos_adapter_helper_impl.cpp +++ b/ohos_adapter/ohos_adapter_helper/src/ohos_adapter_helper_impl.cpp @@ -70,6 +70,9 @@ #include "system_properties_adapter_impl.h" #include "vsync_adapter_impl.h" #include "window_adapter_impl.h" +#if defined(NWEB_SENSORS_SENSOR_ENABLE) +#include "sensor_adapter_impl.h" +#endif namespace OHOS::NWeb { // static @@ -323,4 +326,13 @@ std::unique_ptr OhosAdapterHelperImpl::CreateOhosImageD { return std::make_unique(); } + +std::unique_ptr OhosAdapterHelperImpl::CreateSensorAdapter() +{ +#if defined(NWEB_SENSORS_SENSOR_ENABLE) + return std::make_unique(); +#else + return nullptr; +#endif +} } // namespace OHOS::NWeb diff --git a/ohos_adapter/ohos_image_adapter/include/ohos_image_decoder_adapter_impl.h b/ohos_adapter/ohos_image_adapter/include/ohos_image_decoder_adapter_impl.h index 4e8af4e680fc62d17aee032267101158acceca7d..02e5125c0936dac2a8100cef31d58d53a0721d31 100755 --- a/ohos_adapter/ohos_image_adapter/include/ohos_image_decoder_adapter_impl.h +++ b/ohos_adapter/ohos_image_adapter/include/ohos_image_decoder_adapter_impl.h @@ -50,6 +50,7 @@ public: void* GetNativeWindowBuffer() override; int32_t GetPlanesCount() override; void ReleasePixelMap() override; + Media::PixelMap* GetPixelMap() { return pixelMap_.get(); } private: Media::ImageInfo imageInfo_; diff --git a/ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h b/ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..319e3cb9df90a22ea0b3468c64c9f940341f232b --- /dev/null +++ b/ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h @@ -0,0 +1,75 @@ +/* + * 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. + */ + +#ifndef SENSOR_ADAPTER_IMPL_H +#define SENSOR_ADAPTER_IMPL_H + +#include "sensor_adapter.h" +#include "sensor_agent.h" + +namespace OHOS::NWeb { + +class SensorCallbackImpl { +public: + SensorCallbackImpl(std::shared_ptr callbackAdapter); + ~SensorCallbackImpl() = default; + + void UpdateOhosSensorData(double timestamp, + double value1, double value2, double value3, double value4); +private: + std::shared_ptr callbackAdapter_; +}; + +class SensorAdapterImpl : public SensorAdapter { +public: + SensorAdapterImpl() = default; + ~SensorAdapterImpl() = default; + + int32_t IsOhosSensorSupported(int32_t sensorTypeId) override; + int32_t GetOhosSensorReportingMode(int32_t sensorTypeId) override; + double GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) override; + double GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) override; + double GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) override; + int32_t SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) override; + int32_t RegistOhosSensorCallback(int32_t sensorTypeId, + std::shared_ptr callbackAdapter) override; + int32_t UnsubscribeOhosSensor(int32_t sensorTypeId) override; + +private: + static void OhosSensorCallback(SensorEvent* event); + static std::unordered_map> sensorCallbackMap; + + static void handleAccelerometerData(std::shared_ptr callback, + SensorEvent* event); + static void handleLinearAccelerometerData(std::shared_ptr callback, + SensorEvent* event); + static void handleGravityData(std::shared_ptr callback, + SensorEvent* event); + static void handleCyroscopeData(std::shared_ptr callback, + SensorEvent* event); + static void handleMagnetometerData(std::shared_ptr callback, + SensorEvent* event); + static void handleOrientationData(std::shared_ptr callback, + SensorEvent* event); + static void handleRotationVectorData(std::shared_ptr callback, + SensorEvent* event); + static void handleGameRotationVectorData(std::shared_ptr callback, + SensorEvent* event); + + SensorUser mSensorUser{}; +}; + +} +#endif // SENSOR_ADAPTER_IMPL_H \ No newline at end of file diff --git a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e244a577044b5a5e9cf490137a64045c95adb51f --- /dev/null +++ b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp @@ -0,0 +1,416 @@ +/* + * 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. + */ + +#include "sensor_adapter_impl.h" + +#include +#include + +#include "nweb_log.h" + +namespace OHOS::NWeb { + +std::unordered_map> SensorAdapterImpl::sensorCallbackMap; +constexpr double NANOSECONDS_IN_SECOND = 1000000000.0; +constexpr double DEFAULT_SAMPLE_PERIOD = 200000000.0; + +SensorTypeId SensorTypeToOhosSensorType(int sensorTypeId) +{ + SensorTypeId ohosSensorTypeId = SENSOR_TYPE_ID_NONE; + const static std::map TO_OHOS_SENSOR_TYPE_MAP = { + {2 /* ACCELEROMETER */, SENSOR_TYPE_ID_ACCELEROMETER }, + {3 /* LINEAR_ACCELERATION */, SENSOR_TYPE_ID_LINEAR_ACCELERATION }, + {4 /* GRAVITY */, SENSOR_TYPE_ID_GRAVITY }, + {5 /* GYROSCOPE */, SENSOR_TYPE_ID_GYROSCOPE }, + {6 /* MAGNETOMETER */, SENSOR_TYPE_ID_MAGNETIC_FIELD }, + {8 /* ABSOLUTE_ORIENTATION_EULER_ANGLES}*/, SENSOR_TYPE_ID_ORIENTATION }, + {9 /* ABSOLUTE_ORIENTATION_QUATERNION} */, SENSOR_TYPE_ID_ROTATION_VECTOR }, + {11 /* RELATIVE_ORIENTATION_QUATERNION} */, SENSOR_TYPE_ID_GAME_ROTATION_VECTOR } + }; + auto checkIter = TO_OHOS_SENSOR_TYPE_MAP.find(sensorTypeId); + if (checkIter != TO_OHOS_SENSOR_TYPE_MAP.end()) { + ohosSensorTypeId = checkIter->second; + } + return ohosSensorTypeId; +} + +std::string SensorTypeToSensorUserName(int sensorTypeId) +{ + const static std::map TO_OHOS_SENSOR_USER_NAME_MAP = { + {2 /* ACCELEROMETER */, "OhosAccelerometerService" }, + {3 /* LINEAR_ACCELERATION */, "OhosLinearAccelerometerService" }, + {4 /* GRAVITY */, "OhosGravityService" }, + {5 /* GYROSCOPE */, "OhosCyroscopeService" }, + {6 /* MAGNETOMETER */, "OhosMagnetometerService" }, + {8 /* ABSOLUTE_ORIENTATION_EULER_ANGLES}*/, "OhosOrientationService" }, + {9 /* ABSOLUTE_ORIENTATION_QUATERNION} */, "OhosRotationVectorService"}, + {11 /* RELATIVE_ORIENTATION_QUATERNION} */, "OhosGameRotationVectorService" } + }; + std::string userName = "OhosSensorService"; + auto checkIter = TO_OHOS_SENSOR_USER_NAME_MAP.find(sensorTypeId); + if (checkIter != TO_OHOS_SENSOR_USER_NAME_MAP.end()) { + userName = checkIter->second; + } + return userName; +} + +SensorCallbackImpl::SensorCallbackImpl( + std::shared_ptr callbackAdapter) + : callbackAdapter_(callbackAdapter) +{} + +void SensorCallbackImpl::UpdateOhosSensorData(double timestamp, + double value1, double value2, double value3, double value4) +{ + if (callbackAdapter_) { + callbackAdapter_->UpdateOhosSensorData(timestamp, value1, value2, value3, value4); + } +} + +int32_t SensorAdapterImpl::IsOhosSensorSupported(int32_t sensorTypeId) +{ + int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); + if (ohosSensorTypeId != SENSOR_TYPE_ID_NONE) { + SensorInfo* sensorInfo = nullptr; + int32_t count; + int ret = GetAllSensors(&sensorInfo, &count); + if (ret != SENSOR_SUCCESS || sensorInfo == nullptr || count < 0) { + WVLOG_E("IsOhosSensorSupported Error, ret = %{public}d, count = %{public}d.", ret, count); + return SENSOR_ERROR; + } + + for (int i = 0; i < count; i++) { + if (sensorInfo[i].sensorId == ohosSensorTypeId) { + WVLOG_I("IsOhosSensorSupported SUCCESS, sensorTypeId = %{public}d.", sensorTypeId); + return SENSOR_SUCCESS; + } + } + } + WVLOG_E("IsOhosSensorSupported Error, sensorTypeId = %{public}d is invalid.", sensorTypeId); + return SENSOR_ERROR; +} + +int32_t SensorAdapterImpl::GetOhosSensorReportingMode(int32_t sensorTypeId) +{ + int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); + int32_t reportingMode = -1; + switch (ohosSensorTypeId) { + case SENSOR_TYPE_ID_ACCELEROMETER: + case SENSOR_TYPE_ID_GRAVITY: + case SENSOR_TYPE_ID_LINEAR_ACCELERATION: + case SENSOR_TYPE_ID_GYROSCOPE: + case SENSOR_TYPE_ID_MAGNETIC_FIELD: + case SENSOR_TYPE_ID_ORIENTATION: + case SENSOR_TYPE_ID_ROTATION_VECTOR: + case SENSOR_TYPE_ID_GAME_ROTATION_VECTOR: + reportingMode = SENSOR_DATA_REPORT_CONTINUOUS; + break; + default: + break; + } + return reportingMode; +} + +double SensorAdapterImpl::GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) +{ + int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); + double defaultFrequency = 0.0; + if (ohosSensorTypeId != SENSOR_TYPE_ID_NONE) { + defaultFrequency = NANOSECONDS_IN_SECOND / DEFAULT_SAMPLE_PERIOD; + } + WVLOG_I("GetOhosSensorDefaultSupportedFrequency sensorTypeId: %{public}d, defaultFrequency: %{public}f", + sensorTypeId, defaultFrequency); + return defaultFrequency; +} + +double SensorAdapterImpl::GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) +{ + int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); + double minFrequency = 0.0; + if (ohosSensorTypeId == SENSOR_TYPE_ID_NONE) { + WVLOG_E("GetOhosSensorMinSupportedFrequency Error, sensorTypeId = %{public}d is invalid.", sensorTypeId); + return minFrequency; + } + SensorInfo* sensorInfo = nullptr; + int32_t count; + int ret = GetAllSensors(&sensorInfo, &count); + if (ret != SENSOR_SUCCESS || sensorInfo == nullptr || count < 0) { + WVLOG_E("GetOhosSensorMinSupportedFrequency Error, ret = %{public}d, count = %{public}d.", ret, count); + return minFrequency; + } + for (int i = 0; i < count; i++) { + if (sensorInfo[i].sensorId == ohosSensorTypeId) { + int64_t maxSamplePeriod = sensorInfo[i].maxSamplePeriod; + if (maxSamplePeriod > 0) { + minFrequency = NANOSECONDS_IN_SECOND / static_cast(maxSamplePeriod); + } + break; + } + } + WVLOG_I("GetOhosSensorMinSupportedFrequency sensorTypeId: %{public}d, minFrequency: %{public}f", + sensorTypeId, minFrequency); + return minFrequency; +} + +double SensorAdapterImpl::GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) +{ + int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); + double maxFrequency = 0.0; + if (ohosSensorTypeId == SENSOR_TYPE_ID_NONE) { + WVLOG_E("GetOhosSensorMaxSupportedFrequency Error, sensorTypeId = %{public}d is invalid.", sensorTypeId); + return maxFrequency; + } + SensorInfo* sensorInfo = nullptr; + int32_t count; + int ret = GetAllSensors(&sensorInfo, &count); + if (ret != SENSOR_SUCCESS || sensorInfo == nullptr || count < 0) { + WVLOG_E("GetOhosSensorMaxSupportedFrequency Error, ret = %{public}d, count = %{public}d.", ret, count); + return maxFrequency; + } + for (int i = 0; i < count; i++) { + if (sensorInfo[i].sensorId == ohosSensorTypeId) { + int64_t minSamplePeriod = sensorInfo[i].minSamplePeriod; + if (minSamplePeriod > 0) { + maxFrequency = NANOSECONDS_IN_SECOND / static_cast(minSamplePeriod); + } + break; + } + } + WVLOG_I("GetOhosSensorMaxSupportedFrequency sensorTypeId: %{public}d, maxFrequency: %{public}f", + sensorTypeId, maxFrequency); + return maxFrequency; +} + +void SensorAdapterImpl::handleAccelerometerData(std::shared_ptr callback, + SensorEvent* event) +{ + if ((event == nullptr) || (callback == nullptr)) { + WVLOG_E("handleAccelerometerData Error."); + return; + } + AccelData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); + } +} + +void SensorAdapterImpl::handleLinearAccelerometerData(std::shared_ptr callback, + SensorEvent* event) +{ + if ((event == nullptr) || (callback == nullptr)) { + WVLOG_E("handleLinearAccelerometerData Error."); + return; + } + LinearAccelData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); + } +} + +void SensorAdapterImpl::handleGravityData(std::shared_ptr callback, + SensorEvent* event) +{ + if ((event == nullptr) || (callback == nullptr)) { + WVLOG_E("handleGravityData Error."); + return; + } + GravityData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); + } +} + +void SensorAdapterImpl::handleCyroscopeData(std::shared_ptr callback, + SensorEvent* event) +{ + if ((event == nullptr) || (callback == nullptr)) { + WVLOG_E("handleCyroscopeData Error."); + return; + } + GyroscopeData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); + } +} + +void SensorAdapterImpl::handleMagnetometerData(std::shared_ptr callback, + SensorEvent* event) +{ + if ((event == nullptr) || (callback == nullptr)) { + WVLOG_E("handleMagnetometerData Error."); + return; + } + MagneticFieldData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); + } +} + +void SensorAdapterImpl::handleOrientationData(std::shared_ptr callback, + SensorEvent* event) +{ + if ((event == nullptr) || (callback == nullptr)) { + WVLOG_E("handleOrientationData Error."); + return; + } + OrientationData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->beta, data->gamma, data->alpha, 0.0f); + } +} + +void SensorAdapterImpl::handleRotationVectorData(std::shared_ptr callback, + SensorEvent* event) +{ + if ((event == nullptr) || (callback == nullptr)) { + WVLOG_E("handleRotationVectorData Error."); + return; + } + RotationVectorData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, data->w); + } +} + +void SensorAdapterImpl::handleGameRotationVectorData(std::shared_ptr callback, + SensorEvent* event) +{ + if ((event == nullptr) || (callback == nullptr)) { + WVLOG_E("handleGameRotationVectorData Error."); + return; + } + GameRotationVectorData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, data->w); + } +} + +void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) +{ + std::shared_ptr callback = nullptr; + auto findIter = sensorCallbackMap.find(event->sensorTypeId); + if (findIter != sensorCallbackMap.end()) { + callback = findIter->second; + } + if ((event == nullptr) || (callback == nullptr)) { + WVLOG_E("OhosSensorCallback Error."); + return; + } + switch (event->sensorTypeId) { + case SENSOR_TYPE_ID_ACCELEROMETER: + handleAccelerometerData(callback, event); + break; + case SENSOR_TYPE_ID_GRAVITY: + handleGravityData(callback, event); + break; + case SENSOR_TYPE_ID_LINEAR_ACCELERATION: + handleLinearAccelerometerData(callback, event); + break; + case SENSOR_TYPE_ID_GYROSCOPE: + handleCyroscopeData(callback, event); + break; + case SENSOR_TYPE_ID_MAGNETIC_FIELD: + handleMagnetometerData(callback, event); + break; + case SENSOR_TYPE_ID_ORIENTATION: + handleOrientationData(callback, event); + break; + case SENSOR_TYPE_ID_ROTATION_VECTOR: + handleRotationVectorData(callback, event); + break; + case SENSOR_TYPE_ID_GAME_ROTATION_VECTOR: + handleGameRotationVectorData(callback, event); + break; + default: + break; + } +} + +int32_t SensorAdapterImpl::SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) +{ + WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d", sensorTypeId); + if (samplingInterval <= 0) { + WVLOG_E("SubscribeOhosSensor error, samplingInterval is invalid."); + return SENSOR_PARAMETER_ERROR; + } + int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); + if (ohosSensorTypeId == SENSOR_TYPE_ID_NONE) { + WVLOG_E("SubscribeOhosSensor error, sensorTypeId is invalid."); + return SENSOR_PARAMETER_ERROR; + } + + std::string userName = SensorTypeToSensorUserName(sensorTypeId); + (void)strcpy_s(mSensorUser.name, sizeof(mSensorUser.name), userName.c_str()); + mSensorUser.userData = nullptr; + mSensorUser.callback = OhosSensorCallback; + int32_t ret = SENSOR_SUCCESS; + ret = SubscribeSensor(ohosSensorTypeId, &mSensorUser); + if (ret != SENSOR_SUCCESS) { + WVLOG_E("SubscribeOhosSensor error, call SubscribeSensor ret = %{public}d.", ret); + return ret; + } + ret = SetBatch(ohosSensorTypeId, &mSensorUser, samplingInterval, samplingInterval); + if (ret != SENSOR_SUCCESS) { + WVLOG_E("SubscribeOhosSensor error, call SetBatch ret = %{public}d.", ret); + return ret; + } + ret = ActivateSensor(ohosSensorTypeId, &mSensorUser); + if (ret != SENSOR_SUCCESS) { + WVLOG_E("SubscribeOhosSensor error, call ActivateSensor ret = %{public}d.", ret); + return ret; + } + ret = SetMode(ohosSensorTypeId, &mSensorUser, SENSOR_REALTIME_MODE); + if (ret != SENSOR_SUCCESS) { + WVLOG_E("SubscribeOhosSensor error, call SetMode ret = %{public}d.", ret); + return ret; + } + return SENSOR_SUCCESS; +} + +int32_t SensorAdapterImpl::RegistOhosSensorCallback(int32_t sensorTypeId, + std::shared_ptr callbackAdapter) +{ + int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); + if (ohosSensorTypeId != SENSOR_TYPE_ID_NONE) { + auto callback = std::make_shared(callbackAdapter); + sensorCallbackMap[ohosSensorTypeId] = callback; + return SENSOR_SUCCESS; + } + WVLOG_E("RegistOhosSensorCallback error, sensorTypeId is invalid."); + return SENSOR_PARAMETER_ERROR; +} + +int32_t SensorAdapterImpl::UnsubscribeOhosSensor(int32_t sensorTypeId) +{ + WVLOG_I("UnsubscribeOhosSensor sensorTypeId: %{public}d.", sensorTypeId); + int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); + if (ohosSensorTypeId != SENSOR_TYPE_ID_NONE) { + sensorCallbackMap.erase(ohosSensorTypeId); + int32_t ret = DeactivateSensor(ohosSensorTypeId, &mSensorUser); + if (ret != SENSOR_SUCCESS) { + WVLOG_E("UnsubscribeOhosSensor error, call DeactivateSensor ret = %{public}d.", ret); + return ret; + } + ret = UnsubscribeSensor(ohosSensorTypeId, &mSensorUser); + if (ret != SENSOR_SUCCESS) { + WVLOG_E("UnsubscribeOhosSensor error, call UnsubscribeSensor ret = %{public}d.", ret); + return ret; + } + return SENSOR_SUCCESS; + } + WVLOG_E("UnsubscribeOhosSensor error, sensorTypeId is invalid."); + return SENSOR_PARAMETER_ERROR; +} +} // namespace OHOS::NWeb \ No newline at end of file diff --git a/ohos_glue/BUILD.gn b/ohos_glue/BUILD.gn index e4386d88b8c475462ecf2b3ed7999f17f0529669..df67451d89a3ed10b2d6050585414c147cb9ff21 100644 --- a/ohos_glue/BUILD.gn +++ b/ohos_glue/BUILD.gn @@ -600,10 +600,14 @@ action("ohos_glue_adapter_prepare") { "${glue_build_gen_dir}/ohos_adapter/bridge/ark_mmi_listener_adapter_wrapper.h", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_native_image_adapter_impl.cpp", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_native_image_adapter_impl.h", + "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_capabilities_adapter_impl.cpp", + "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_capabilities_adapter_impl.h", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_conn_callback_wrapper.cpp", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_conn_callback_wrapper.h", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_connect_adapter_impl.cpp", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_connect_adapter_impl.h", + "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_connection_properties_adapter_impl.cpp", + "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_connection_properties_adapter_impl.h", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_proxy_adapter_impl.cpp", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_proxy_adapter_impl.h", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_net_proxy_event_callback_adapter_wrapper.cpp", @@ -655,6 +659,10 @@ action("ohos_glue_adapter_prepare") { "${glue_build_gen_dir}/ohos_adapter/bridge/ark_screen_capture_callback_adapter_wrapper.h", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_screen_capture_config_adapter_wrapper.cpp", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_screen_capture_config_adapter_wrapper.h", + "${glue_build_gen_dir}/ohos_adapter/bridge/ark_sensor_adapter_impl.cpp", + "${glue_build_gen_dir}/ohos_adapter/bridge/ark_sensor_adapter_impl.h", + "${glue_build_gen_dir}/ohos_adapter/bridge/ark_sensor_callback_adapter_wrapper.cpp", + "${glue_build_gen_dir}/ohos_adapter/bridge/ark_sensor_callback_adapter_wrapper.h", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_soc_perf_client_adapter_impl.cpp", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_soc_perf_client_adapter_impl.h", "${glue_build_gen_dir}/ohos_adapter/bridge/ark_surface_buffer_adapter_impl.cpp", @@ -773,8 +781,12 @@ action("ohos_glue_adapter_prepare") { "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_mmiadapter_cpptoc.h", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_native_image_adapter_cpptoc.cpp", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_native_image_adapter_cpptoc.h", + "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_net_capabilities_adapter_cpptoc.cpp", + "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_net_capabilities_adapter_cpptoc.h", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_net_connect_adapter_cpptoc.cpp", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_net_connect_adapter_cpptoc.h", + "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_net_connection_properties_adapter_cpptoc.cpp", + "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_net_connection_properties_adapter_cpptoc.h", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_net_proxy_adapter_cpptoc.cpp", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_net_proxy_adapter_cpptoc.h", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_ohos_adapter_helper_cpptoc.cpp", @@ -817,6 +829,8 @@ action("ohos_glue_adapter_prepare") { "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_running_lock_adapter_cpptoc.h", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_screen_capture_adapter_cpptoc.cpp", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_screen_capture_adapter_cpptoc.h", + "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_sensor_adapter_cpptoc.cpp", + "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_sensor_adapter_cpptoc.h", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_soc_perf_client_adapter_cpptoc.cpp", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_soc_perf_client_adapter_cpptoc.h", "${glue_build_gen_dir}/ohos_adapter/cpptoc/ark_surface_buffer_adapter_cpptoc.cpp", @@ -935,6 +949,8 @@ action("ohos_glue_adapter_prepare") { "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_screen_capture_callback_adapter_ctocpp.h", "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_screen_capture_config_adapter_ctocpp.cpp", "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_screen_capture_config_adapter_ctocpp.h", + "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_sensor_callback_adapter_ctocpp.cpp", + "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_sensor_callback_adapter_ctocpp.h", "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_timezone_event_callback_adapter_ctocpp.cpp", "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_timezone_event_callback_adapter_ctocpp.h", "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_video_capture_info_adapter_ctocpp.cpp", diff --git a/ohos_interface/include/ohos_adapter/imf_adapter.h b/ohos_interface/include/ohos_adapter/imf_adapter.h index 5aa58b694582a2bccc45959d76bfa75d03860320..fca87684834d89926f0638c96c36444ef0a87ec6 100644 --- a/ohos_interface/include/ohos_adapter/imf_adapter.h +++ b/ohos_interface/include/ohos_adapter/imf_adapter.h @@ -106,6 +106,16 @@ public: virtual std::shared_ptr GetSelectionRange() = 0; virtual uint32_t GetWindowId() = 0; + + virtual double GetPositionY() + { + return 0.0; + } + + virtual double GetHeight() + { + return 0.0; + } }; enum class IMFAdapterKeyboardStatus : int32_t { NONE = 0, HIDE, SHOW }; diff --git a/ohos_interface/include/ohos_adapter/net_connect_adapter.h b/ohos_interface/include/ohos_adapter/net_connect_adapter.h index 64c9f79830f8221ed0ffa89d3c35aa81fa9e5c56..6920cc34e946e7f909ba0b0424d37386d7973cdd 100644 --- a/ohos_interface/include/ohos_adapter/net_connect_adapter.h +++ b/ohos_interface/include/ohos_adapter/net_connect_adapter.h @@ -71,6 +71,24 @@ enum class NetConnectSubtype : uint32_t { SUBTYPE_LAST = SUBTYPE_WIFI_AD }; +class NetCapabilitiesAdapter { +public: + NetCapabilitiesAdapter() = default; + virtual ~NetCapabilitiesAdapter() = default; + + virtual int32_t GetNetId() = 0; + virtual NetConnectType GetConnectType() = 0; + virtual NetConnectSubtype GetConnectSubtype() = 0; +}; + +class NetConnectionPropertiesAdapter { +public: + NetConnectionPropertiesAdapter() = default; + virtual ~NetConnectionPropertiesAdapter() = default; + + virtual int32_t GetNetId() = 0; +}; + class NetConnCallback { public: NetConnCallback() = default; @@ -81,6 +99,10 @@ public: const NetConnectType& netConnectType, const NetConnectSubtype& netConnectSubtype) = 0; virtual int32_t NetConnectionPropertiesChange() = 0; virtual int32_t NetUnavailable() = 0; + virtual int32_t OnNetCapabilitiesChanged( + const std::shared_ptr capabilities) { return 0; } + virtual int32_t OnNetConnectionPropertiesChanged( + const std::shared_ptr properties) { return 0; } }; class NetConnectAdapter { diff --git a/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h b/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h index 6a82adfef8084c98a66a3efa1f3768565e60ed1a..0b89991c9166db969f833cd811e9cd4d82b7da88 100644 --- a/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h +++ b/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h @@ -54,6 +54,7 @@ #include "screen_capture_adapter.h" #include "soc_perf_client_adapter.h" #include "system_properties_adapter.h" +#include "sensor_adapter.h" namespace OHOS::NWeb { class OhosAdapterHelper { @@ -143,6 +144,8 @@ public: virtual std::unique_ptr CreateMediaAVSessionAdapter() = 0; virtual std::unique_ptr CreateOhosImageDecoderAdapter() = 0; + + virtual std::unique_ptr CreateSensorAdapter() = 0; }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_adapter/sensor_adapter.h b/ohos_interface/include/ohos_adapter/sensor_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..c3253b0e079079fa9e31b7483e55a96f21278d3e --- /dev/null +++ b/ohos_interface/include/ohos_adapter/sensor_adapter.h @@ -0,0 +1,65 @@ +/* + * 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. + */ + +#ifndef SENSOR_ADAPTER_H +#define SENSOR_ADAPTER_H + +#include + + +namespace OHOS::NWeb { + +enum { + SENSOR_ERROR = -1, + SENSOR_SUCCESS = 0, + SENSOR_PERMISSION_DENIED = 201, // Use this error code when permission is denied. + SENSOR_PARAMETER_ERROR = 401, // Use this error code when the input parameter type or range does not match. + SENSOR_SERVICE_EXCEPTION = 14500101, // Use this error code when the service is exception. + SENSOR_NO_SUPPORT = 14500102, // Use this error code when the sensor is not supported by the device. + SENSOR_NON_SYSTEM_API = 202 // Permission check failed. A non-system application uses the system API. +}; + +enum { + SENSOR_DATA_REPORT_ON_CHANGE = 0, + SENSOR_DATA_REPORT_CONTINUOUS = 1 +}; + +class SensorCallbackAdapter { +public: + virtual ~SensorCallbackAdapter() = default; + + virtual void UpdateOhosSensorData(double timestamp, + double value1, double value2, double value3, double value4) = 0; +}; + +class SensorAdapter { +public: + SensorAdapter() = default; + virtual ~SensorAdapter() = default; + + virtual int32_t IsOhosSensorSupported(int32_t sensorTypeId) = 0; + virtual int32_t GetOhosSensorReportingMode(int32_t sensorTypeId) = 0; + virtual double GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) = 0; + virtual double GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) = 0; + virtual double GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) = 0; + virtual int32_t SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) = 0; + virtual int32_t RegistOhosSensorCallback(int32_t sensorTypeId, + std::shared_ptr callbackAdapter) = 0; + virtual int32_t UnsubscribeOhosSensor(int32_t sensorTypeId) = 0; +}; + +} + +#endif // SENSOR_ADAPTER_H \ No newline at end of file diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 14a9fe83f573416cfd28155034322a8c1c8125f3..db5bc6e270129343a11e9bf480ebcded3df9417c 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -1430,6 +1430,35 @@ public: */ virtual void RegisterArkJSfunction(const std::string& object_name, const std::vector& method_list, const std::vector& async_method_list, const int32_t object_id, const std::string& permission) {} + + /** + * @brief resize visual viewport. + * + * @param width width. + * @param height height. + * @param iskeyboard from keybord. + */ + virtual void ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) {} + + /** + * @brief Set backforward cache options. + * + * @param size The size of the back forward cache could saved. + * @param timeToLive The time of the back forward cache page could stay. + */ + virtual void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) { return; } + + /** + * @brief set the callback of the autofill event. + * @param callback callback. + */ + virtual void SetAutofillCallback(std::shared_ptr callback) {} + + /** + * @brief fill autofill data. + * @param data data. + */ + virtual void FillAutofillData(std::shared_ptr data) {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_access_request.h b/ohos_interface/include/ohos_nweb/nweb_access_request.h index 703f989f3b94cc5e22e86a624d03efaaf3802244..a41853f4687f28b58d9b98e75537de0a8fb927aa 100644 --- a/ohos_interface/include/ohos_nweb/nweb_access_request.h +++ b/ohos_interface/include/ohos_nweb/nweb_access_request.h @@ -35,7 +35,8 @@ public: PROTECTED_MEDIA_ID = 1 << 3, MIDI_SYSEX = 1 << 4, CLIPBOARD_READ_WRITE = 1 << 5, - CLIPBOARD_SANITIZED_WRITE = 1 << 6, + CLIPBOARD_SANITIZED_WRITE = 1 << 6, + SENSORS = 1 << 7, }; /** diff --git a/ohos_interface/include/ohos_nweb/nweb_autofill.h b/ohos_interface/include/ohos_nweb/nweb_autofill.h new file mode 100644 index 0000000000000000000000000000000000000000..8dbff39d83d0886d3fe966f6e3c24b44ca805367 --- /dev/null +++ b/ohos_interface/include/ohos_nweb/nweb_autofill.h @@ -0,0 +1,62 @@ +/* + * 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. + */ + +#ifndef NWEB_AUTOFILL_H +#define NWEB_AUTOFILL_H + +#include + +namespace OHOS::NWeb { + +const std::string NWEB_VIEW_DATA_KEY_FOCUS = "focus"; +const std::string NWEB_VIEW_DATA_KEY_RECT_X = "x"; +const std::string NWEB_VIEW_DATA_KEY_RECT_Y = "y"; +const std::string NWEB_VIEW_DATA_KEY_RECT_W = "width"; +const std::string NWEB_VIEW_DATA_KEY_RECT_H = "height"; +const std::string NWEB_VIEW_DATA_KEY_VALUE = "value"; +const std::string NWEB_VIEW_DATA_KEY_PLACEHOLDER = "placeholder"; + +const std::string NWEB_AUTOFILL_EVENT_SAVE = "save"; +const std::string NWEB_AUTOFILL_EVENT_FILL = "fill"; +const std::string NWEB_AUTOFILL_EVENT_UPDATE = "update"; +const std::string NWEB_AUTOFILL_EVENT_CLOSE = "close"; + +const std::string NWEB_AUTOFILL_STREET_ADDRESS = "street-address"; +const std::string NWEB_AUTOFILL_ADDRESS_LEVEL_3 = "address-level3"; +const std::string NWEB_AUTOFILL_ADDRESS_LEVEL_2 = "address-level2"; +const std::string NWEB_AUTOFILL_ADDRESS_LEVEL_1 = "address-level1"; +const std::string NWEB_AUTOFILL_COUNTRY = "country"; +const std::string NWEB_AUTOFILL_NAME = "name"; +const std::string NWEB_AUTOFILL_FAMILY_NAME = "family-name"; +const std::string NWEB_AUTOFILL_GIVEN_NAME = "given-name"; +const std::string NWEB_AUTOFILL_TEL_NATIONAL = "tel-national"; +const std::string NWEB_AUTOFILL_TEL = "tel"; +const std::string NWEB_AUTOFILL_TEL_COUNTRY_CODE = "tel-country-code"; +const std::string NWEB_AUTOFILL_EMAIL = "email"; +const std::string NWEB_AUTOFILL_CC_NUMBER = "cc-number"; +const std::string NWEB_AUTOFILL_ID_CARD_NUMBER = "id-card-number"; +const std::string NWEB_AUTOFILL_NICKNAME = "nickname"; + +enum NWebAutofillEvent { + UNKNOWN = 0, + SAVE, + FILL, + UPDATE, + CLOSE, +}; + +} // namespace OHOS::NWeb + +#endif // NWEB_AUTOFILL_H \ No newline at end of file diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 41853edc059c36f6b63f9a38289eab73fa782bad..616b166fcafd9484fc827821e81d0d4b825feba8 100644 --- a/ohos_interface/include/ohos_nweb/nweb_engine.h +++ b/ohos_interface/include/ohos_nweb/nweb_engine.h @@ -82,6 +82,8 @@ public: virtual std::shared_ptr GetAdsBlockManager() { return nullptr; }; + + virtual void TrimMemoryByPressureLevel(int32_t memoryLevel) {}; }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index f27bea9b1f83eebc63b058749af15d98fe6ea29b..00fe234e6ccada4de8c1a672d8560eebaeef6fa4 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -213,6 +213,8 @@ enum class NativeEmbedStatus { CREATE, UPDATE, DESTROY, + ENTER_BFCACHE, + LEAVE_BFCACHE, }; enum class NWebFocusSource { @@ -964,6 +966,22 @@ public: * */ virtual void OnAdsBlocked(const std::string& url, const std::vector& adsBlocked) {} + + /** + * @brief called when the cursor info is updated. + * + * @param x, y relative coordinates within web components of the cursor + * @param width, height width and height of the cursor + */ + virtual void OnCursorUpdate(double x, double y, double width, double height) {} + + /** + * @brief Called when web occurs frame loss event. + * + * @param sceneId The id of event scene. + * @param isStart True if is start. + */ + virtual void ReportDynamicFrameLossEvent(const std::string& sceneId, bool isStart) {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_native_media_player.h b/ohos_interface/include/ohos_nweb/nweb_native_media_player.h index 4aa810c1bc93345df0b146a1b0547c15a5ed7205..609d9a6bb3cab05af35940ab1d0b03566f99018e 100644 --- a/ohos_interface/include/ohos_nweb/nweb_native_media_player.h +++ b/ohos_interface/include/ohos_nweb/nweb_native_media_player.h @@ -31,7 +31,7 @@ enum class MediaError { NETWORK_ERROR = 1, FORMAT_ERROR, DECODE_ERROR }; enum class ReadyState { HAVE_NOTHING = 0, HAVE_METADATA, HAVE_CURRENT_DATA, HAVE_FUTURE_DATA, HAVE_ENOUGH_DATA }; -enum class SuspendType { EnterBFCache = 0, EnterBackground, PausedOverTime }; +enum class SuspendType { ENTER_BACK_FORWARD_CACHE = 0, ENTER_BACKGROUND, AUTO_CLEANUP }; enum class NetworkState { EMPTY = 0, IDLE, LOADING, NETWORK_ERROR }; diff --git a/ohos_interface/ohos_glue/BUILD_webcore.gn b/ohos_interface/ohos_glue/BUILD_webcore.gn index 9e56406b808a0e50717a80d499cf26d724b8050f..87ff0a239d41b488638bb688f1d59f2959567baa 100644 --- a/ohos_interface/ohos_glue/BUILD_webcore.gn +++ b/ohos_interface/ohos_glue/BUILD_webcore.gn @@ -17,7 +17,10 @@ import("//build/config/ohos/config.gni") ################################################# config("ohos_glue_config") { - defines = [ "OHOS_NWEB" ] + defines = [ + "OHOS_NWEB", + "OHOS_WEBCORE_GLUE", + ] include_dirs = [ "//ohos_glue" ] @@ -592,10 +595,14 @@ component("ohos_adapter_glue_source") { "ohos_adapter/bridge/ark_mmi_listener_adapter_impl.h", "ohos_adapter/bridge/ark_native_image_adapter_wrapper.cpp", "ohos_adapter/bridge/ark_native_image_adapter_wrapper.h", + "ohos_adapter/bridge/ark_net_capabilities_adapter_wrapper.cpp", + "ohos_adapter/bridge/ark_net_capabilities_adapter_wrapper.h", "ohos_adapter/bridge/ark_net_conn_callback_impl.cpp", "ohos_adapter/bridge/ark_net_conn_callback_impl.h", "ohos_adapter/bridge/ark_net_connect_adapter_wrapper.cpp", "ohos_adapter/bridge/ark_net_connect_adapter_wrapper.h", + "ohos_adapter/bridge/ark_net_connection_properties_adapter_wrapper.cpp", + "ohos_adapter/bridge/ark_net_connection_properties_adapter_wrapper.h", "ohos_adapter/bridge/ark_net_proxy_adapter_wrapper.cpp", "ohos_adapter/bridge/ark_net_proxy_adapter_wrapper.h", "ohos_adapter/bridge/ark_net_proxy_event_callback_adapter_impl.cpp", @@ -647,6 +654,10 @@ component("ohos_adapter_glue_source") { "ohos_adapter/bridge/ark_screen_capture_callback_adapter_impl.h", "ohos_adapter/bridge/ark_screen_capture_config_adapter_impl.cpp", "ohos_adapter/bridge/ark_screen_capture_config_adapter_impl.h", + "ohos_adapter/bridge/ark_sensor_adapter_wrapper.cpp", + "ohos_adapter/bridge/ark_sensor_adapter_wrapper.h", + "ohos_adapter/bridge/ark_sensor_callback_adapter_impl.cpp", + "ohos_adapter/bridge/ark_sensor_callback_adapter_impl.h", "ohos_adapter/bridge/ark_soc_perf_client_adapter_wrapper.cpp", "ohos_adapter/bridge/ark_soc_perf_client_adapter_wrapper.h", "ohos_adapter/bridge/ark_surface_buffer_adapter_wrapper.cpp", @@ -775,6 +786,8 @@ component("ohos_adapter_glue_source") { "ohos_adapter/cpptoc/ark_screen_capture_callback_adapter_cpptoc.h", "ohos_adapter/cpptoc/ark_screen_capture_config_adapter_cpptoc.cpp", "ohos_adapter/cpptoc/ark_screen_capture_config_adapter_cpptoc.h", + "ohos_adapter/cpptoc/ark_sensor_callback_adapter_cpptoc.cpp", + "ohos_adapter/cpptoc/ark_sensor_callback_adapter_cpptoc.h", "ohos_adapter/cpptoc/ark_timezone_event_callback_adapter_cpptoc.cpp", "ohos_adapter/cpptoc/ark_timezone_event_callback_adapter_cpptoc.h", "ohos_adapter/cpptoc/ark_video_capture_info_adapter_cpptoc.cpp", @@ -875,8 +888,12 @@ component("ohos_adapter_glue_source") { "ohos_adapter/ctocpp/ark_mmiadapter_ctocpp.h", "ohos_adapter/ctocpp/ark_native_image_adapter_ctocpp.cpp", "ohos_adapter/ctocpp/ark_native_image_adapter_ctocpp.h", + "ohos_adapter/ctocpp/ark_net_capabilities_adapter_ctocpp.cpp", + "ohos_adapter/ctocpp/ark_net_capabilities_adapter_ctocpp.h", "ohos_adapter/ctocpp/ark_net_connect_adapter_ctocpp.cpp", "ohos_adapter/ctocpp/ark_net_connect_adapter_ctocpp.h", + "ohos_adapter/ctocpp/ark_net_connection_properties_adapter_ctocpp.cpp", + "ohos_adapter/ctocpp/ark_net_connection_properties_adapter_ctocpp.h", "ohos_adapter/ctocpp/ark_net_proxy_adapter_ctocpp.cpp", "ohos_adapter/ctocpp/ark_net_proxy_adapter_ctocpp.h", "ohos_adapter/ctocpp/ark_ohos_adapter_helper_ctocpp.cpp", @@ -919,6 +936,8 @@ component("ohos_adapter_glue_source") { "ohos_adapter/ctocpp/ark_running_lock_adapter_ctocpp.h", "ohos_adapter/ctocpp/ark_screen_capture_adapter_ctocpp.cpp", "ohos_adapter/ctocpp/ark_screen_capture_adapter_ctocpp.h", + "ohos_adapter/ctocpp/ark_sensor_adapter_ctocpp.cpp", + "ohos_adapter/ctocpp/ark_sensor_adapter_ctocpp.h", "ohos_adapter/ctocpp/ark_soc_perf_client_adapter_ctocpp.cpp", "ohos_adapter/ctocpp/ark_soc_perf_client_adapter_ctocpp.h", "ohos_adapter/ctocpp/ark_surface_buffer_adapter_ctocpp.cpp", diff --git a/ohos_interface/ohos_glue/base/bridge/ark_web_bridge_helper.cpp b/ohos_interface/ohos_glue/base/bridge/ark_web_bridge_helper.cpp index df9dbaaf79ce571fdf77bde9be909618cf758fae..9b835fbb2fbaaa6d7ddc079c80283ef53706d463 100644 --- a/ohos_interface/ohos_glue/base/bridge/ark_web_bridge_helper.cpp +++ b/ohos_interface/ohos_glue/base/bridge/ark_web_bridge_helper.cpp @@ -43,6 +43,7 @@ bool ArkWebBridgeHelper::LoadLibFile(int mode, const std::string& libFilePath, b return true; } +#if !defined(OHOS_WEBCORE_GLUE) bool ArkWebBridgeHelper::LoadLibFile(int mode, const std::string& libNsName, const std::string& libDirPath, const std::string& libFileName, bool isPrintLog) { @@ -69,6 +70,7 @@ bool ArkWebBridgeHelper::LoadLibFile(int mode, const std::string& libNsName, con libFileHandler_ = libFileHandler; return true; } +#endif void ArkWebBridgeHelper::UnloadLibFile() { diff --git a/ohos_interface/ohos_glue/base/bridge/ark_web_bridge_helper.h b/ohos_interface/ohos_glue/base/bridge/ark_web_bridge_helper.h index 71dbd3abec187085dc69acbe6f494dd78ef2bc66..75f0818a01f9b8035786f0c8c3d414a14a860ec4 100644 --- a/ohos_interface/ohos_glue/base/bridge/ark_web_bridge_helper.h +++ b/ohos_interface/ohos_glue/base/bridge/ark_web_bridge_helper.h @@ -33,8 +33,10 @@ protected: bool LoadLibFile(int mode, const std::string& libFilePath, bool isPrintLog = true); +#if !defined(OHOS_WEBCORE_GLUE) bool LoadLibFile(int mode, const std::string& libNsName, const std::string& libDirPath, const std::string& libFileName, bool isPrintLog = true); +#endif private: void UnloadLibFile(); diff --git a/ohos_interface/ohos_glue/base/include/ark_web_bridge_types.h b/ohos_interface/ohos_glue/base/include/ark_web_bridge_types.h index 7507c246d1c45eb2c142fd70c2757e0e252d2ddd..ee115fa479de068b0dfb58f862c9bf6660c619e6 100644 --- a/ohos_interface/ohos_glue/base/include/ark_web_bridge_types.h +++ b/ohos_interface/ohos_glue/base/include/ark_web_bridge_types.h @@ -243,6 +243,10 @@ enum ArkWebBridgeType { ARK_AAFWK_BROWSER_CLIENT_ADAPTER = 10127, ARK_AAFWK_BROWSER_HOST_ADAPTER = 10128, ARK_AUDIO_OUTPUT_CHANGE_CALLBACK_ADAPTER = 10129, + ARK_SENSOR_ADAPTER = 10130, + ARK_SENSOR_CALLBACK_ADAPTER = 10131, + ARK_NET_CAPABILITIES_ADAPTER = 10132, + ARK_NET_CONNECTION_PROPERTIES_ADAPTER = 10133, /*Note: Only add an enum value before ARK_WEB_BRIDGE_BUTT*/ ARK_WEB_BRIDGE_BUTT diff --git a/ohos_interface/ohos_glue/base/include/ark_web_log_utils.h b/ohos_interface/ohos_glue/base/include/ark_web_log_utils.h index 164ff908af995a2ad233b3b50265c6e5436339dd..f2bf1b2ea94b6d9ae6af6cb406e78a5510d834e1 100644 --- a/ohos_interface/ohos_glue/base/include/ark_web_log_utils.h +++ b/ohos_interface/ohos_glue/base/include/ark_web_log_utils.h @@ -38,13 +38,15 @@ #define ARK_WEB_BASE_DV_LOG(fmt, ...) WVLOG_D(LOG_FMT_PREFIX fmt, ##__VA_ARGS__) #define ARK_WEB_BASE_REF_LOG(fmt, ...) WVLOG_D(LOG_FMT_PREFIX fmt, ##__VA_ARGS__) + +#define ARK_WEB_BASE_DEBUG_LOG(fmt, ...) WVLOG_D(LOG_FMT_PREFIX fmt, ##__VA_ARGS__) #else #define ARK_WEB_BASE_DV_LOG(fmt, ...) #define ARK_WEB_BASE_REF_LOG(fmt, ...) -#endif -#define ARK_WEB_BASE_DEBUG_LOG(fmt, ...) WVLOG_D(LOG_FMT_PREFIX fmt, ##__VA_ARGS__) +#define ARK_WEB_BASE_DEBUG_LOG(fmt, ...) +#endif #define ARK_WEB_BASE_INFO_LOG(fmt, ...) WVLOG_I(LOG_FMT_PREFIX fmt, ##__VA_ARGS__) diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_config_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_config_adapter_impl.cpp index b1fbadd3b3c7b48c998ef326ca8e322b8cd0d8f7..54d23bc9b8a294501344d956bed612f55af201b0 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_config_adapter_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_config_adapter_impl.cpp @@ -59,4 +59,13 @@ uint32_t ArkIMFTextConfigAdapterImpl::GetWindowId() return real_->GetWindowId(); } +double ArkIMFTextConfigAdapterImpl::GetPositionY() +{ + return real_->GetPositionY(); +} + +double ArkIMFTextConfigAdapterImpl::GetHeight() +{ + return real_->GetHeight(); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_config_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_config_adapter_impl.h index 2fa2214252950b955a0df6113a75cd3567ab34c4..1d6762f00cad68277425bdb184259c3cbdc02a25 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_config_adapter_impl.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_config_adapter_impl.h @@ -34,6 +34,10 @@ public: uint32_t GetWindowId() override; + double GetPositionY() override; + + double GetHeight() override; + private: std::shared_ptr real_; diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_capabilities_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_capabilities_adapter_wrapper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..71ed0cf4bfe324a0bfd4849bb61392375b5865a9 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_capabilities_adapter_wrapper.cpp @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#include "ohos_adapter/bridge/ark_net_capabilities_adapter_wrapper.h" + +namespace OHOS::ArkWeb { + +ArkNetCapabilitiesAdapterWrapper::ArkNetCapabilitiesAdapterWrapper( + ArkWebRefPtr ref) : ctocpp_(ref) {} + +int32_t ArkNetCapabilitiesAdapterWrapper::GetNetId() +{ + return ctocpp_->GetNetId(); +} + +OHOS::NWeb::ConnectType ArkNetCapabilitiesAdapterWrapper::GetConnectType() +{ + return static_cast(ctocpp_->GetConnectType()); +} + +OHOS::NWeb::ConnectSubtype ArkNetCapabilitiesAdapterWrapper::GetConnectSubtype() +{ + return static_cast(ctocpp_->GetConnectSubtype()); +} + +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_capabilities_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_capabilities_adapter_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..a7fdd7f5fde9f72b750165d42744dc246acb3953 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_capabilities_adapter_wrapper.h @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#ifndef ARK_NET_CAPABILITIES_ADAPTER_WRAPPER_H +#define ARK_NET_CAPABILITIES_ADAPTER_WRAPPER_H +#pragma once + +#include "net_connect_adapter.h" +#include "ohos_adapter/include/ark_net_connect_adapter.h" + +namespace OHOS::ArkWeb { + +class ArkNetCapabilitiesAdapterWrapper : public NWeb::NetCapabilitiesAdapter { +public: + ArkNetCapabilitiesAdapterWrapper(ArkWebRefPtr); + + int32_t GetNetId() override; + + OHOS::NWeb::ConnectType GetConnectType() override; + + OHOS::NWeb::ConnectSubtype GetConnectSubtype() override; + +private: + ArkWebRefPtr ctocpp_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_NET_CAPABILITIES_ADAPTER_WRAPPER_H \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_conn_callback_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_conn_callback_impl.cpp index 17c2e6bc3d2fa053d28b5943f0810185d2ef58fb..fc76257af1edfc5b6ce2731c7466e4f32025e83d 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_conn_callback_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_conn_callback_impl.cpp @@ -13,7 +13,11 @@ * limitations under the License. */ +#include "ohos_adapter/bridge/ark_net_capabilities_adapter_wrapper.h" #include "ohos_adapter/bridge/ark_net_conn_callback_impl.h" +#include "ohos_adapter/bridge/ark_net_connection_properties_adapter_wrapper.h" + +#include "base/bridge/ark_web_bridge_macros.h" namespace OHOS::ArkWeb { @@ -40,4 +44,26 @@ int32_t ArkNetConnCallbackImpl::NetUnavailable() return real_->NetUnavailable(); } +int32_t ArkNetConnCallbackImpl::OnNetCapabilitiesChanged( + const ArkWebRefPtr capabilites) +{ + if (CHECK_REF_PTR_IS_NULL(capabilites)) { + return real_->OnNetCapabilitiesChanged(nullptr); + } + + return real_->OnNetCapabilitiesChanged( + std::make_shared(capabilites)); +} + +int32_t ArkNetConnCallbackImpl::OnNetConnectionPropertiesChanged( + const ArkWebRefPtr properties) +{ + if (CHECK_REF_PTR_IS_NULL(properties)) { + return real_->OnNetConnectionPropertiesChanged(nullptr); + } + + return real_->OnNetConnectionPropertiesChanged( + std::make_shared(properties)); +} + } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_conn_callback_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_conn_callback_impl.h index 4287d40fca390210e1b2ffba7facf8702180d75d..7c9bc9f1e0cfa575e652f05dfd056ee75aaa3192 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_conn_callback_impl.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_conn_callback_impl.h @@ -34,6 +34,12 @@ public: int32_t NetUnavailable() override; + int32_t OnNetCapabilitiesChanged( + const ArkWebRefPtr capabilites) override; + + int32_t OnNetConnectionPropertiesChanged( + const ArkWebRefPtr properties) override; + private: std::shared_ptr real_; diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_connection_properties_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_connection_properties_adapter_wrapper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9d9f88b201812a365096f3dc90171ebf05d20dab --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_connection_properties_adapter_wrapper.cpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +#include "ohos_adapter/bridge/ark_net_connection_properties_adapter_wrapper.h" + +namespace OHOS::ArkWeb { + +ArkNetConnectionPropertiesAdapterWrapper::ArkNetConnectionPropertiesAdapterWrapper( + ArkWebRefPtr ref) : ctocpp_(ref) {} + +int32_t ArkNetConnectionPropertiesAdapterWrapper::GetNetId() +{ + return ctocpp_->GetNetId(); +} + +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_connection_properties_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_connection_properties_adapter_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..80287efb415733d970b8a9e0f7a25d89ef295777 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_connection_properties_adapter_wrapper.h @@ -0,0 +1,37 @@ +/* + * 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. + */ + +#ifndef ARK_NET_CONNECTION_PROPERTIES_ADAPTER_WRAPPER_H +#define ARK_NET_CONNECTION_PROPERTIES_ADAPTER_WRAPPER_H +#pragma once + +#include "net_connect_adapter.h" +#include "ohos_adapter/include/ark_net_connect_adapter.h" + +namespace OHOS::ArkWeb { + +class ArkNetConnectionPropertiesAdapterWrapper : public NWeb::NetConnectionPropertiesAdapter { +public: + ArkNetConnectionPropertiesAdapterWrapper(ArkWebRefPtr); + + int32_t GetNetId() override; + +private: + ArkWebRefPtr ctocpp_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_NET_CONNECTION_PROPERTIES_ADAPTER_WRAPPER_H \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_adapter_helper_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_adapter_helper_wrapper.cpp index 45706409c77768ecb3a66e285e0e923160f3c388..6d4ae1703eae0f58622cabe9d3d338a3478279a7 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_adapter_helper_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_adapter_helper_wrapper.cpp @@ -57,6 +57,7 @@ #include "ohos_adapter/bridge/ark_print_manager_adapter_wrapper.h" #include "ohos_adapter/bridge/ark_running_lock_adapter_wrapper.h" #include "ohos_adapter/bridge/ark_screen_capture_adapter_wrapper.h" +#include "ohos_adapter/bridge/ark_sensor_adapter_wrapper.h" #include "ohos_adapter/bridge/ark_soc_perf_client_adapter_wrapper.h" #include "ohos_adapter/bridge/ark_surface_buffer_adapter_wrapper.h" #include "ohos_adapter/bridge/ark_system_properties_adapter_wrapper.h" @@ -448,4 +449,14 @@ std::unique_ptr ArkOhosAdapterHelperWrapper::Crea return std::make_unique(adapter); } +std::unique_ptr ArkOhosAdapterHelperWrapper::CreateSensorAdapter() +{ + ArkWebRefPtr adapter = ctocpp_->CreateSensorAdapter(); + + if (CHECK_REF_PTR_IS_NULL(adapter)) { + return nullptr; + } + + return std::make_unique(adapter); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_adapter_helper_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_adapter_helper_wrapper.h index 1d11905b6bbfec562c77c5dfa040c43d5be24c69..3290249d578f0a904fb43eb61de0dc761f179554 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_adapter_helper_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_adapter_helper_wrapper.h @@ -108,6 +108,8 @@ public: std::unique_ptr CreateOhosImageDecoderAdapter() override; + std::unique_ptr CreateSensorAdapter() override; + private: ArkWebRefPtr ctocpp_; }; diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_adapter_wrapper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0f1765b9b6a0019ed0468f9206c02246b2964391 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_adapter_wrapper.cpp @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#include "ohos_adapter/bridge/ark_sensor_adapter_wrapper.h" + +#include "ohos_adapter/bridge/ark_sensor_callback_adapter_impl.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkSensorAdapterWrapper::ArkSensorAdapterWrapper(ArkWebRefPtr ref) + : ctocpp_(ref) +{} + +int32_t ArkSensorAdapterWrapper::IsOhosSensorSupported(int32_t sensorTypeId) +{ + return ctocpp_->IsOhosSensorSupported(sensorTypeId); +} + +int32_t ArkSensorAdapterWrapper::GetOhosSensorReportingMode(int32_t sensorTypeId) +{ + return ctocpp_->GetOhosSensorReportingMode(sensorTypeId); +} + +double ArkSensorAdapterWrapper::GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) +{ + return ctocpp_->GetOhosSensorDefaultSupportedFrequency(sensorTypeId); +} + +double ArkSensorAdapterWrapper::GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) +{ + return ctocpp_->GetOhosSensorMinSupportedFrequency(sensorTypeId); +} + +double ArkSensorAdapterWrapper::GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) +{ + return ctocpp_->GetOhosSensorMaxSupportedFrequency(sensorTypeId); +} + +int32_t ArkSensorAdapterWrapper::SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) +{ + return ctocpp_->SubscribeOhosSensor(sensorTypeId, samplingInterval); +} + +int32_t ArkSensorAdapterWrapper::UnsubscribeOhosSensor(int32_t sensorTypeId) +{ + return ctocpp_->UnsubscribeOhosSensor(sensorTypeId); +} + +int32_t ArkSensorAdapterWrapper::RegistOhosSensorCallback(int32_t sensorTypeId, + std::shared_ptr callbackAdapter) +{ + if (CHECK_SHARED_PTR_IS_NULL(callbackAdapter)) { + return ctocpp_->RegistOhosSensorCallback(-1, nullptr); + } + + return ctocpp_->RegistOhosSensorCallback(sensorTypeId, + new ArkSensorCallbackAdapterImpl(callbackAdapter)); +} +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_adapter_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..8db4f15eb130614a7499632fd531d44c167eb38d --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_adapter_wrapper.h @@ -0,0 +1,45 @@ +/* + * 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. + */ + +#ifndef ARK_SENSOR_ADAPTER_WRAPPER_H +#define ARK_SENSOR_ADAPTER_WRAPPER_H +#pragma once + +#include "sensor_adapter.h" +#include "ohos_adapter/include/ark_sensor_adapter.h" + +namespace OHOS::ArkWeb { + +class ArkSensorAdapterWrapper : public OHOS::NWeb::SensorAdapter { +public: + ArkSensorAdapterWrapper(ArkWebRefPtr); + + int32_t IsOhosSensorSupported(int32_t sensorTypeId) override; + int32_t GetOhosSensorReportingMode(int32_t sensorTypeId) override; + double GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) override; + double GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) override; + double GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) override; + int32_t SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) override; + int32_t RegistOhosSensorCallback(int32_t sensorTypeId, + std::shared_ptr callbackAdapter) override; + int32_t UnsubscribeOhosSensor(int32_t sensorTypeId) override; + +private: + ArkWebRefPtr ctocpp_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_SENSOR_ADAPTER_WRAPPER_H diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_callback_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_callback_adapter_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1714e840e88e2b2572c2d86875f940837e697cf6 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_callback_adapter_impl.cpp @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#include "ohos_adapter/bridge/ark_sensor_callback_adapter_impl.h" + +namespace OHOS::ArkWeb { + +ArkSensorCallbackAdapterImpl::ArkSensorCallbackAdapterImpl( + std::shared_ptr ref) + : real_(ref) +{} + +void ArkSensorCallbackAdapterImpl::UpdateOhosSensorData(double timestamp, + double value1, double value2, double value3, double value4) +{ + real_->UpdateOhosSensorData(timestamp, value1, value2, value3, value4); +} +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_callback_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_callback_adapter_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..0bca27d8c719d45fc943d79e2eb7d7111f7b76ed --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_callback_adapter_impl.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef ARK_SENSOR_CALLBACK_ADAPTER_IMPL_H +#define ARK_SENSOR_CALLBACK_ADAPTER_IMPL_H +#pragma once + +#include "sensor_adapter.h" +#include "ohos_adapter/include/ark_sensor_adapter.h" + +namespace OHOS::ArkWeb { + +class ArkSensorCallbackAdapterImpl : public ArkSensorCallbackAdapter { +public: + ArkSensorCallbackAdapterImpl(std::shared_ptr); + + void UpdateOhosSensorData(double timestamp, + double value1, double value2, double value3, double value4) override; + +private: + std::shared_ptr real_; + + IMPLEMENT_REFCOUNTING(ArkSensorCallbackAdapterImpl); +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_SENSOR_CALLBACK_ADAPTER_IMPL_H diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_web_adapter_bridge_helper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_web_adapter_bridge_helper.cpp index bec20dfb8673dd90c7616401557d5155bdc699ab..1180d736db242553f8b6a9a3c79e0aa2c1882955 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_web_adapter_bridge_helper.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_web_adapter_bridge_helper.cpp @@ -22,12 +22,6 @@ namespace OHOS::ArkWeb { const std::string LIB_FILE_NAME = "libohos_adapter_glue_source.z.so"; -#if defined(__aarch64__) || defined(__x86_64__) -const std::string LIB_DIR_PATH = "/system/lib64"; -#else -const std::string LIB_DIR_PATH = "/system/lib"; -#endif - ArkWebAdapterBridgeHelper& ArkWebAdapterBridgeHelper::GetInstance(bool isPrintLog) { static ArkWebAdapterBridgeHelper helper; @@ -38,7 +32,7 @@ ArkWebAdapterBridgeHelper& ArkWebAdapterBridgeHelper::GetInstance(bool isPrintLo bool ArkWebAdapterBridgeHelper::Init(bool isPrintLog) { - return LoadLibFile(RTLD_LAZY, LIB_DIR_PATH + "/" + LIB_FILE_NAME, isPrintLog); + return LoadLibFile(RTLD_LAZY, LIB_FILE_NAME, isPrintLog); } } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_config_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_config_adapter_wrapper.cpp index 61ef624f8e40ec508d41fe0a48ea172d697fba76..af7aa2310423ebf79578d718ee92e1785b373d13 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_config_adapter_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_config_adapter_wrapper.cpp @@ -58,4 +58,13 @@ uint32_t ArkIMFTextConfigAdapterWrapper::GetWindowId() return ctocpp_->GetWindowId(); } +double ArkIMFTextConfigAdapterWrapper::GetPositionY() +{ + return ctocpp_->GetPositionY(); +} + +double ArkIMFTextConfigAdapterWrapper::GetHeight() +{ + return ctocpp_->GetHeight(); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_config_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_config_adapter_wrapper.h index 6f03508c362701680f0db63124134a527bacc25f..b7121b0df402a108916e1e6138df0621dda0dbe3 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_config_adapter_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_config_adapter_wrapper.h @@ -34,6 +34,10 @@ public: uint32_t GetWindowId() override; + double GetPositionY() override; + + double GetHeight() override; + private: ArkWebRefPtr ctocpp_; }; diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_capabilities_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_capabilities_adapter_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..999fc701c10e3337534ed44963377b35e6d4a110 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_capabilities_adapter_impl.cpp @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#include "ohos_adapter/bridge/ark_net_capabilities_adapter_impl.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { +ArkNetCapabilitiesAdapterImpl::ArkNetCapabilitiesAdapterImpl(std::shared_ptr ref) + : real_(ref) {} + +int32_t ArkNetCapabilitiesAdapterImpl::GetNetId() +{ + return real_->GetNetId(); +} + +uint32_t ArkNetCapabilitiesAdapterImpl::GetConnectType() +{ + return (uint32_t)real_->GetConnectType(); +} + +uint32_t ArkNetCapabilitiesAdapterImpl::GetConnectSubtype() +{ + return (uint32_t)real_->GetConnectSubtype(); +} +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_capabilities_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_capabilities_adapter_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..a9f60efff8fc799e43b1ea89cfd6b6b0e9793607 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_capabilities_adapter_impl.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef ARK_NET_CAPABILITIES_ADAPTER_IMPL_H +#define ARK_NET_CAPABILITIES_ADAPTER_IMPL_H +#pragma once + +#include "net_connect_adapter.h" +#include "ohos_adapter/include/ark_net_connect_adapter.h" + +namespace OHOS::ArkWeb { + +class ArkNetCapabilitiesAdapterImpl : public ArkNetCapabilitiesAdapter { +public: + ArkNetCapabilitiesAdapterImpl(std::shared_ptr); + + int32_t GetNetId() override; + + uint32_t GetConnectType() override; + + uint32_t GetConnectSubtype() override; + +private: + std::shared_ptr real_; + + IMPLEMENT_REFCOUNTING(ArkNetCapabilitiesAdapterImpl); +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_NET_CAPABILITIES_ADAPTER_IMPL_H \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_conn_callback_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_conn_callback_wrapper.cpp index f23a6c972ff18ccd96da8a3d19ede42202710e81..89ac8d56c3424fc9a8b8519a0e5e0b8786b0b4af 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_conn_callback_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_conn_callback_wrapper.cpp @@ -13,7 +13,9 @@ * limitations under the License. */ +#include "ohos_adapter/bridge/ark_net_capabilities_adapter_impl.h" #include "ohos_adapter/bridge/ark_net_conn_callback_wrapper.h" +#include "ohos_adapter/bridge/ark_net_connection_properties_adapter_impl.h" #include "base/bridge/ark_web_bridge_macros.h" @@ -42,4 +44,24 @@ int32_t ArkNetConnCallbackWrapper::NetUnavailable() return ctocpp_->NetUnavailable(); } +int32_t ArkNetConnCallbackWrapper::OnNetCapabilitiesChanged( + const std::shared_ptr capabilities) +{ + if (CHECK_SHARED_PTR_IS_NULL(capabilities)) { + return ctocpp_->OnNetCapabilitiesChanged(nullptr); + } + + return ctocpp_->OnNetCapabilitiesChanged(new ArkNetCapabilitiesAdapterImpl(capabilities)); +} + +int32_t ArkNetConnCallbackWrapper::OnNetConnectionPropertiesChanged( + const std::shared_ptr properties) +{ + if (CHECK_SHARED_PTR_IS_NULL(properties)) { + return ctocpp_->OnNetConnectionPropertiesChanged(nullptr); + } + + return ctocpp_->OnNetConnectionPropertiesChanged(new ArkNetConnectionPropertiesAdapterImpl(properties)); +} + } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_conn_callback_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_conn_callback_wrapper.h index 78975cec80d7977bacd275145b0bce4b4ead27a8..03539aa9054df553c9f6799d9a53481cf3aef0d8 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_conn_callback_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_conn_callback_wrapper.h @@ -30,6 +30,10 @@ public: const OHOS::NWeb::NetConnectSubtype& netConnectSubtype) override; int32_t NetConnectionPropertiesChange() override; int32_t NetUnavailable() override; + int32_t OnNetCapabilitiesChanged( + const std::shared_ptr capabilities) override; + int32_t OnNetConnectionPropertiesChanged( + const std::shared_ptr properties) override; private: ArkWebRefPtr ctocpp_; diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_connection_properties_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_connection_properties_adapter_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a80f77d9a19734cd0bd9d25d6b66c2c972360d24 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_connection_properties_adapter_impl.cpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +#include "ohos_adapter/bridge/ark_net_connection_properties_adapter_impl.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { +ArkNetConnectionPropertiesAdapterImpl::ArkNetConnectionPropertiesAdapterImpl( + std::shared_ptr ref) : real_(ref) {} + +int32_t ArkNetConnectionPropertiesAdapterImpl::GetNetId() +{ + return real_->GetNetId(); +} + +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_connection_properties_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_connection_properties_adapter_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..fd1d757004753e006443b9d82c03e6ce7f9a8900 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_connection_properties_adapter_impl.h @@ -0,0 +1,39 @@ +/* + * 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. + */ + +#ifndef ARK_NET_CONNECTION_PROPERTIES_ADAPTER_IMPL_H +#define ARK_NET_CONNECTION_PROPERTIES_ADAPTER_IMPL_H +#pragma once + +#include "net_connect_adapter.h" +#include "ohos_adapter/include/ark_net_connect_adapter.h" + +namespace OHOS::ArkWeb { + +class ArkNetConnectionPropertiesAdapterImpl : public ArkNetConnectionPropertiesAdapter { +public: + ArkNetConnectionPropertiesAdapterImpl(std::shared_ptr); + + int32_t GetNetId() override; + +private: + std::shared_ptr real_; + + IMPLEMENT_REFCOUNTING(ArkNetConnectionPropertiesAdapterImpl); +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_NET_CONNECTION_PROPERTIES_ADAPTER_IMPL_H \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_adapter_helper_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_adapter_helper_impl.cpp index fb8d79ff5a34f87eed671e8d68a1ae8daf04caa7..e52ff0a71b833c71e6e8e03d8fd81943151a1230 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_adapter_helper_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_adapter_helper_impl.cpp @@ -68,7 +68,7 @@ #include "ohos_adapter/bridge/ark_vsync_adapter_impl.h" #include "ohos_adapter/bridge/ark_web_date_timezone_info_impl.h" #include "ohos_adapter/bridge/ark_window_adapter_impl.h" - +#include "ohos_adapter/bridge/ark_sensor_adapter_impl.h" #include "base/bridge/ark_web_bridge_macros.h" namespace OHOS::ArkWeb { @@ -371,4 +371,10 @@ ArkWebRefPtr ArkOhosAdapterHelperImpl::CreateOhosIma return new ArkOhosImageDecoderAdapterImpl(shared); } +ArkWebRefPtr ArkOhosAdapterHelperImpl::CreateSensorAdapter() +{ + std::unique_ptr adapter = real_.CreateSensorAdapter(); + std::shared_ptr shared = std::move(adapter); + return new ArkSensorAdapterImpl(shared); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_adapter_helper_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_adapter_helper_impl.h index 5fbe44c4c7d83b95c4399f495e5263f820b4991f..1efa2b1a5c2139bdf95e64c3b705da8c7dd07183 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_adapter_helper_impl.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_adapter_helper_impl.h @@ -108,6 +108,8 @@ public: ArkWebRefPtr CreateOhosImageDecoderAdapter() override; + ArkWebRefPtr CreateSensorAdapter() override; + private: NWeb::OhosAdapterHelper& real_; diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_adapter_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..472ef827e6b1333dd78c115cf9f77aed3f2d915c --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_adapter_impl.cpp @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#include "ohos_adapter/bridge/ark_sensor_adapter_impl.h" + +#include "ohos_adapter/bridge/ark_sensor_callback_adapter_wrapper.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkSensorAdapterImpl::ArkSensorAdapterImpl(std::shared_ptr ref) + : real_(ref) +{} + +int32_t ArkSensorAdapterImpl::IsOhosSensorSupported(int32_t type) +{ + return real_->IsOhosSensorSupported(type); +} + +int32_t ArkSensorAdapterImpl::GetOhosSensorReportingMode(int32_t type) +{ + return real_->GetOhosSensorReportingMode(type); +} + +double ArkSensorAdapterImpl::GetOhosSensorDefaultSupportedFrequency(int32_t type) +{ + return real_->GetOhosSensorDefaultSupportedFrequency(type); +} + +double ArkSensorAdapterImpl::GetOhosSensorMinSupportedFrequency(int32_t type) +{ + return real_->GetOhosSensorMinSupportedFrequency(type); +} + +double ArkSensorAdapterImpl::GetOhosSensorMaxSupportedFrequency(int32_t type) +{ + return real_->GetOhosSensorMaxSupportedFrequency(type); +} + +int32_t ArkSensorAdapterImpl::SubscribeOhosSensor(int32_t type, int64_t samplingInterval) +{ + return real_->SubscribeOhosSensor(type, samplingInterval); +} + +int32_t ArkSensorAdapterImpl::RegistOhosSensorCallback(int32_t sensorTypeId, + ArkWebRefPtr callbackAdapter) +{ + if (!(CHECK_REF_PTR_IS_NULL(callbackAdapter))) { + return real_->RegistOhosSensorCallback(sensorTypeId, + std::make_shared(callbackAdapter)); + } + return false; +} + +int32_t ArkSensorAdapterImpl::UnsubscribeOhosSensor(int32_t type) +{ + return real_->UnsubscribeOhosSensor(type); +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_adapter_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..f11880317611a6aea7ab5140dfbcc8fa93b9a229 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_adapter_impl.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#ifndef ARK_SENSOR_ADAPTER_IMPL_H +#define ARK_SENSOR_ADAPTER_IMPL_H +#pragma once + +#include "sensor_adapter.h" +#include "ohos_adapter/include/ark_sensor_adapter.h" + +namespace OHOS::ArkWeb { + +class ArkSensorAdapterImpl : public ArkSensorAdapter { +public: + ArkSensorAdapterImpl(std::shared_ptr); + + int32_t IsOhosSensorSupported(int32_t sensorTypeId) override; + + int32_t GetOhosSensorReportingMode(int32_t type) override; + + double GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) override; + + double GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) override; + + double GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) override; + + int32_t SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) override; + + int32_t RegistOhosSensorCallback(int32_t sensorTypeId, + ArkWebRefPtr callbackAdapter) override; + + int32_t UnsubscribeOhosSensor(int32_t sensorTypeId) override; + +private: + std::shared_ptr real_; + + IMPLEMENT_REFCOUNTING(ArkSensorAdapterImpl); +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_SENSOR_ADAPTER_IMPL_H diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_callback_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_callback_adapter_wrapper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d917c67283cf903b40863d0757ebd99eb54fad1 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_callback_adapter_wrapper.cpp @@ -0,0 +1,31 @@ +/* + * 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. + */ + +#include "ohos_adapter/bridge/ark_sensor_callback_adapter_wrapper.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { +ArkSensorCallbackAdapterWrapper::ArkSensorCallbackAdapterWrapper( + ArkWebRefPtr ref) + : ctocpp_(ref) +{} + +void ArkSensorCallbackAdapterWrapper::UpdateOhosSensorData(double timestamp, + double value1, double value2, double value3, double value4) +{ + ctocpp_->UpdateOhosSensorData(timestamp, value1, value2, value3, value4); +} +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_callback_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_callback_adapter_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..a30160c2a80e587e03f8a13e90f85cb4562c0901 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_callback_adapter_wrapper.h @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#ifndef ARK_SENSOR_CALLBACK_ADAPTER_WRAPPER_H +#define ARK_SENSOR_CALLBACK_ADAPTER_WRAPPER_H +#pragma once + +#include "sensor_adapter.h" +#include "ohos_adapter/include/ark_sensor_adapter.h" + +namespace OHOS::ArkWeb { + +class ArkSensorCallbackAdapterWrapper : public OHOS::NWeb::SensorCallbackAdapter { +public: + ArkSensorCallbackAdapterWrapper(ArkWebRefPtr); + + void UpdateOhosSensorData(double timestamp, + double value1, double value2, double value3, double value4) override; + +private: + ArkWebRefPtr ctocpp_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_SENSOR_CALLBACK_ADAPTER_WRAPPER_H diff --git a/ohos_interface/ohos_glue/ohos_adapter/include/ark_imf_adapter.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_imf_adapter.h index 0bd546403484fe2736c0c4984b124be273358ca4..415dd5a250ab7c01ce0fcc6755a1879ed67ffcfc 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/include/ark_imf_adapter.h +++ b/ohos_interface/ohos_glue/ohos_adapter/include/ark_imf_adapter.h @@ -72,6 +72,12 @@ public: /*--ark web()--*/ virtual uint32_t GetWindowId() = 0; + + /*--ark web()--*/ + virtual double GetPositionY() = 0; + + /*--ark web()--*/ + virtual double GetHeight() = 0; }; /*--ark web(source=webview)--*/ diff --git a/ohos_interface/ohos_glue/ohos_adapter/include/ark_net_connect_adapter.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_net_connect_adapter.h index 13c9ae780c0a4fe30832423ed9fe29b333347ef2..295be126f507a0ed3185e2daa1a1a68176ce6421 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/include/ark_net_connect_adapter.h +++ b/ohos_interface/ohos_glue/ohos_adapter/include/ark_net_connect_adapter.h @@ -22,6 +22,26 @@ namespace OHOS::ArkWeb { +/*--ark web(source=webview)--*/ +class ArkNetCapabilitiesAdapter : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual int32_t GetNetId() = 0; + + /*--ark web()--*/ + virtual uint32_t GetConnectType() = 0; + + /*--ark web()--*/ + virtual uint32_t GetConnectSubtype() = 0; +}; + +/*--ark web(source=webview)--*/ +class ArkNetConnectionPropertiesAdapter : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual int32_t GetNetId() = 0; +}; + /*--ark web(source=webcore)--*/ class ArkNetConnCallback : public virtual ArkWebBaseRefCounted { public: @@ -36,6 +56,14 @@ public: /*--ark web()--*/ virtual int32_t NetUnavailable() = 0; + + /*--ark web()--*/ + virtual int32_t OnNetCapabilitiesChanged( + const ArkWebRefPtr capabilites) = 0; + + /*--ark web()--*/ + virtual int32_t OnNetConnectionPropertiesChanged( + const ArkWebRefPtr properties) = 0; }; /*--ark web(source=webview)--*/ diff --git a/ohos_interface/ohos_glue/ohos_adapter/include/ark_ohos_adapter_helper.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_ohos_adapter_helper.h index edd90eff7c4194937ea63848bbe2cd7a37bc144f..61b9e1343835bc56dc11042ac4d69ae48f7d2038 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/include/ark_ohos_adapter_helper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/include/ark_ohos_adapter_helper.h @@ -53,6 +53,7 @@ #include "ohos_adapter/include/ark_screen_capture_adapter.h" #include "ohos_adapter/include/ark_soc_perf_client_adapter.h" #include "ohos_adapter/include/ark_system_properties_adapter.h" +#include "ohos_adapter/include/ark_sensor_adapter.h" namespace OHOS::ArkWeb { @@ -184,6 +185,9 @@ public: /*--ark web()--*/ virtual ArkWebRefPtr CreateOhosImageDecoderAdapter() = 0; + + /*--ark web()--*/ + virtual ArkWebRefPtr CreateSensorAdapter() = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/include/ark_sensor_adapter.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_sensor_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..32a83406e6dda4a79075922170e023bbe2119e90 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_adapter/include/ark_sensor_adapter.h @@ -0,0 +1,64 @@ +/* + * 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. + */ + +#ifndef ARK_SENSOR_ADAPTER_H +#define ARK_SENSOR_ADAPTER_H +#pragma once + +#include "base/include/ark_web_base_ref_counted.h" +#include "base/include/ark_web_types.h" + +namespace OHOS::ArkWeb { + +/*--ark web(source=webcore)--*/ +class ArkSensorCallbackAdapter : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual void UpdateOhosSensorData(double timestamp, + double value1, double value2, double value3, double value4) = 0; +}; + +/*--ark web(source=webview)--*/ +class ArkSensorAdapter : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual int32_t IsOhosSensorSupported(int32_t sensorTypeId) = 0; + + /*--ark web()--*/ + virtual int32_t GetOhosSensorReportingMode(int32_t type) = 0; + + /*--ark web()--*/ + virtual double GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) = 0; + + /*--ark web()--*/ + virtual double GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) = 0; + + /*--ark web()--*/ + virtual double GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) = 0; + + /*--ark web()--*/ + virtual int32_t SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) = 0; + + /*--ark web()--*/ + virtual int32_t RegistOhosSensorCallback(int32_t sensorTypeId, + ArkWebRefPtr callbackAdapter) = 0; + + /*--ark web()--*/ + virtual int32_t UnsubscribeOhosSensor(int32_t sensorTypeId) = 0; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_SENSOR_ADAPTER_H diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.cpp index 5b55bcb92b88ad7a56e96c816e64cc5747936763..ecc4dba418eda08f8581faeb73c8c78d180c5763 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.cpp @@ -212,4 +212,9 @@ ArkWebRefPtr ArkWebEngineImpl::GetAdsBlockManager() } return new ArkWebAdsBlockManagerImpl(nweb_adsBlock_manager); } + +void ArkWebEngineImpl::TrimMemoryByPressureLevel(int32_t memoryLevel) +{ + nweb_engine_->TrimMemoryByPressureLevel(memoryLevel); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.h index 28236ab74b6127835de0a4da22f33028b398a124..b883c699477e9f29700872cae82a6745e87f10bc 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.h @@ -79,6 +79,8 @@ public: ArkWebRefPtr GetAdsBlockManager() override; + void TrimMemoryByPressureLevel(int32_t memoryLevel) override; + private: std::shared_ptr nweb_engine_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.cpp index 6e6c298ae4d16ae4fb4f9f35be78261de097aa86..daa984ee23d31fc5036a49f806c5126a71f8f380 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.cpp @@ -977,4 +977,16 @@ void ArkWebHandlerWrapper::OnAdsBlocked( ArkWebStringVectorStructRelease(stAdsBlocked); ArkWebStringStructRelease(stUrl); } + +void ArkWebHandlerWrapper::OnCursorUpdate(double x, double y, double width, double height) +{ + ark_web_handler_->OnCursorUpdate(x, y, width, height); +} + +void ArkWebHandlerWrapper::ReportDynamicFrameLossEvent(const std::string& sceneId, bool isStart) +{ + ArkWebString stSceneId = ArkWebStringClassToStruct(sceneId); + ark_web_handler_->ReportDynamicFrameLossEvent(stSceneId, isStart); + ArkWebStringStructRelease(stSceneId); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.h index 7e5ad0c6a21322a085c08c5f62614dd35eadc26a..be4a72f0ac287ff89769f52563ed4455ef7580e9 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.h @@ -594,6 +594,11 @@ public: void OnCustomKeyboardClose() override; void OnAdsBlocked(const std::string &url, const std::vector &adsBlocked) override; + + void OnCursorUpdate(double x, double y, double width, double height) override; + + void ReportDynamicFrameLossEvent(const std::string& sceneId, bool isStart) override; + private: ArkWebRefPtr ark_web_handler_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp index 6276b5fd99deedbabd2f0df4f5fc48adc549affa..3e29003e1ad792662b6f61cdb9bb3a1ea798d533 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp @@ -1095,7 +1095,6 @@ void ArkWebNWebImpl::WebSendTouchpadFlingEvent(double x, ArkWebBasicVectorStructToClass(pressedCodes)); } - void ArkWebNWebImpl::SendAccessibilityHoverEvent(int32_t x, int32_t y) { nweb_nweb_->SendAccessibilityHoverEvent(x, y); @@ -1108,4 +1107,29 @@ void ArkWebNWebImpl::RegisterArkJSfunction(const ArkWebString& object_name, cons ArkWebStringVectorStructToClass(method_list), ArkWebStringVectorStructToClass(async_method_list), object_id, ArkWebStringStructToClass(permission)); } + +void ArkWebNWebImpl::ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) +{ + nweb_nweb_->ResizeVisibleViewport(width, height, isKeyboard); +} + +void ArkWebNWebImpl::SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) +{ + nweb_nweb_->SetBackForwardCacheOptions(size, timeToLive); +} + +void ArkWebNWebImpl::SetAutofillCallback(ArkWebRefPtr callback) +{ + if (CHECK_REF_PTR_IS_NULL(callback)) { + nweb_nweb_->SetAutofillCallback(nullptr); + return; + } + + nweb_nweb_->SetAutofillCallback(std::make_shared(callback)); +} + +void ArkWebNWebImpl::FillAutofillData(const ArkWebMessage& data) +{ + nweb_nweb_->FillAutofillData(data.nweb_message); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.h index db22e8e3f9594d608beb7f92ac0c1748d8b9e1dd..a569bf9ebc7ee16c9884a110410de612d87101a3 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.h @@ -1237,6 +1237,7 @@ public: double vx, double vy, const ArkWebInt32Vector& pressedCodes) override; + /** * @brief Set url trust list with error message. * @@ -1266,6 +1267,38 @@ public: */ void RegisterArkJSfunction(const ArkWebString& object_name, const ArkWebStringVector& method_list, const ArkWebStringVector& async_method_list, const int32_t object_id, const ArkWebString& permission) override; + + /** + * @brief resize visual viewport. + * + * @param width width. + * @param height height. + * @param iskeyboard from keybord. + */ + /*--ark web()--*/ + void ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) override; + + /** + * @brief set backforward cache options. + * @param size The size of the back forward cache could saved. + * @param timeToLive The time of the back forward cache page could stay. + */ + /*--ark web()--*/ + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) override; + + /** + * @brief set the callback of the autofill event. + * @param callback callback. + */ + /*--ark web()--*/ + void SetAutofillCallback(ArkWebRefPtr callback) override; + + /** + * @brief fill autofill data. + * @param data data. + */ + /*--ark web()--*/ + void FillAutofillData(const ArkWebMessage& data) override; private: std::shared_ptr nweb_nweb_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.cpp index c08317fa5aa6bcbbe18306488e88909625b0be68..5c26e07551ae573ccf60a4ed89c7e3856987772e 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.cpp @@ -240,4 +240,9 @@ ArkWebEngineWrapper::GetAdsBlockManager() { return std::make_shared(ark_web_adsblock_manager); } + +void ArkWebEngineWrapper::TrimMemoryByPressureLevel(int32_t memoryLevel) +{ + ark_web_engine_->TrimMemoryByPressureLevel(memoryLevel); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.h index 6400bfcdd2f3ef7da0bf0937f10f8d25ae846066..ec6ea672a5a63dccb6ff51ceeba87ceceeceecd0 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.h @@ -76,6 +76,8 @@ public: void EnableWholeWebPageDrawing() override; std::shared_ptr GetAdsBlockManager() override; + + void TrimMemoryByPressureLevel(int32_t memoryLevel) override; private: ArkWebRefPtr ark_web_engine_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.cpp index 580d80a55db3104076aff953a015346ab4c0ee19..5e044922b0347b76b6cce2e7ebe847503eda1df5 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.cpp @@ -867,4 +867,14 @@ void ArkWebHandlerImpl::OnAdsBlocked(const ArkWebString &url, const ArkWebString nweb_handler_->OnAdsBlocked(ArkWebStringStructToClass(url), ArkWebStringVectorStructToClass(adsBlocked)); } + +void ArkWebHandlerImpl::OnCursorUpdate(double x, double y, double width, double height) +{ + nweb_handler_->OnCursorUpdate(x, y, width, height); +} + +void ArkWebHandlerImpl::ReportDynamicFrameLossEvent(const ArkWebString& sceneId, bool isStart) +{ + nweb_handler_->ReportDynamicFrameLossEvent(ArkWebStringStructToClass(sceneId), isStart); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.h index c9a0edae044334886b103685e042d128e9d9f9d5..7ae31ebeafc379f20009e532df462fb4bb808afe 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.h @@ -557,6 +557,11 @@ public: void OnCustomKeyboardClose() override; void OnAdsBlocked(const ArkWebString &url, const ArkWebStringVector &adsBlocked) override; + + void OnCursorUpdate(double x, double y, double width, double height) override; + + void ReportDynamicFrameLossEvent(const ArkWebString& sceneId, bool isStart) override; + private: std::shared_ptr nweb_handler_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp index db4de86e522ad3c3c0643a68ec6b0d5ee3f234d3..c1d619613d02bb367a68955f28c7f53c11f57039 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp @@ -1304,4 +1304,30 @@ void ArkWebNWebWrapper::RegisterArkJSfunction(const std::string& object_name, ArkWebStringVectorStructRelease(stAsyncMethods); ArkWebStringStructRelease(stPermission); } + +void ArkWebNWebWrapper::ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) +{ + ark_web_nweb_->ResizeVisibleViewport(width, height, isKeyboard); +} + +void ArkWebNWebWrapper::SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) +{ + ark_web_nweb_->SetBackForwardCacheOptions(size, timeToLive); +} + +void ArkWebNWebWrapper::SetAutofillCallback(std::shared_ptr callback) +{ + if (CHECK_SHARED_PTR_IS_NULL(callback)) { + ark_web_nweb_->SetAutofillCallback(nullptr); + } else { + ark_web_nweb_->SetAutofillCallback(new ArkWebMessageValueCallbackImpl(callback)); + } +} + +void ArkWebNWebWrapper::FillAutofillData(std::shared_ptr data) +{ + ArkWebMessage ark_web_message; + ark_web_message.nweb_message = data; + ark_web_nweb_->FillAutofillData(ark_web_message); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.h index 454294bb022a311a569bfd55c99cf0d30087b309..78dc0b7c35b6e29a49eb54a5c0542f1cdd3a1268 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.h @@ -1245,6 +1245,7 @@ public: double vx, double vy, const std::vector& pressedCodes) override; + /** * @brief Set url trust list with error message. */ @@ -1275,6 +1276,38 @@ public: const std::vector& async_method_list, const int32_t object_id, const std::string& permission) override; + + /** + * @brief resize visual viewport. + * + * @param width width. + * @param height height. + * @param iskeyboard from keybord. + */ + /*--ark web()--*/ + void ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) override; + + /** + * @brief set backforward cache options. + * @param size The size of the back forward cache could saved. + * @param timeToLive The time of the back forward cache page could stay. + */ + /*--ark web()--*/ + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) override; + + /** + * @brief set the callback of the autofill event. + * @param callback callback. + */ + /*--ark web()--*/ + void SetAutofillCallback(std::shared_ptr callback) override; + + /** + * @brief fill autofill data. + * @param data data. + */ + /*--ark web()--*/ + void FillAutofillData(std::shared_ptr data) override; private: ArkWebRefPtr ark_web_nweb_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h index ab6194dcfbbef777ba036ef3f8afbe3da0545857..3208fffdc786bb7165f4fecb749a92d84162badd 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h @@ -108,6 +108,9 @@ public: /*--ark web()--*/ virtual ArkWebRefPtr GetAdsBlockManager() = 0; + + /*--ark web()--*/ + virtual void TrimMemoryByPressureLevel(int32_t memoryLevel) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_handler.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_handler.h index b17fc6b557913db891fa7512c1901a3c934d0feb..8e1685b22eb4cc249d623b5afeca6205c8b88120 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_handler.h +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_handler.h @@ -744,6 +744,24 @@ public: */ /*--ark web()--*/ virtual void OnAdsBlocked(const ArkWebString &url, const ArkWebStringVector &adsBlocked) = 0; + + /** + * @brief called when the cursor info is updated. + * + * @param x, y relative coordinates within web components of the cursor + * @param width, height width and height of the cursor + */ + /*--ark web()--*/ + virtual void OnCursorUpdate(double x, double y, double width, double height) = 0; + + /** + * @brief Called when web occurs frame loss event. + * + * @param sceneId The id of event scene. + * @param isStart True if is start. + */ + /*--ark web()--*/ + virtual void ReportDynamicFrameLossEvent(const ArkWebString& sceneId, bool isStart) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_nweb.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_nweb.h index 0bba501184ca9d2432574298dabbfcf223fcf7fc..bd1d175d480dedd123790fc04afc12511f9bc093 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_nweb.h +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_nweb.h @@ -1426,6 +1426,38 @@ public: /*--ark web()--*/ virtual void RegisterArkJSfunction(const ArkWebString& object_name, const ArkWebStringVector& method_list, const ArkWebStringVector& async_method_list, const int32_t object_id, const ArkWebString& permission) = 0; + + /** + * @brief resize visual viewport. + * + * @param width width. + * @param height height. + * @param iskeyboard from keybord. + */ + /*--ark web()--*/ + virtual void ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) = 0; + + /** + * @brief set backforward cache options. + * @param size The size of the back forward cache could saved. + * @param timeToLive The time of the back forward cache page could stay. + */ + /*--ark web()--*/ + virtual void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) = 0; + + /** + * @brief set the callback of the autofill event. + * @param callback callback. + */ + /*--ark web()--*/ + virtual void SetAutofillCallback(ArkWebRefPtr callback) = 0; + + /** + * @brief fill autofill data. + * @param data data. + */ + /*--ark web()--*/ + virtual void FillAutofillData(const ArkWebMessage& data) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_nweb/include/nweb_c_api.h b/ohos_nweb/include/nweb_c_api.h index 91ddad0226688c0209a6b310c4722ed890037a6c..933770ed4ea06cae53b9fd2a02e7b454cec68f56 100644 --- a/ohos_nweb/include/nweb_c_api.h +++ b/ohos_nweb/include/nweb_c_api.h @@ -75,6 +75,8 @@ NWEB_EXPORT void WebDownload_Resume(const WebDownloadItemCallbackWrapper *wrappe NWEB_EXPORT NWebDownloadItemState WebDownload_GetItemState(int32_t nwebId, long downloadItemId); +NWEB_EXPORT NWebDownloadItemState WebDownload_GetItemStateByGuid(const std::string& guid); + NWEB_EXPORT void WebDownloadItem_CreateWebDownloadItem(NWebDownloadItem **downloadItem); NWEB_EXPORT void WebDownloadItem_Destroy(NWebDownloadItem *downloadItem); diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index a6fa18a677da3b40a113bcdaf4f566516a29a6f9..d09266bd3261467dc91e94ed243fb79ad469c0b6 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -86,6 +86,10 @@ public: void EnableWholeWebPageDrawing(); std::shared_ptr GetAdsBlockManager(); + void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaTakeOver); + + void TrimMemoryByPressureLevel(int32_t memoryLevel); + private: NWebHelper() = default; bool LoadLib(bool from_ark); @@ -97,6 +101,7 @@ private: std::string bundlePath_; std::shared_ptr nwebEngine_ = nullptr; std::string customSchemeCmdLine_; + std::vector backForwardCacheCmdLine_; }; } // namespace OHOS::NWeb diff --git a/ohos_nweb/include/nweb_init_params.h b/ohos_nweb/include/nweb_init_params.h index 8cfe711d2bd5a80d199412acd603bf13066ed753..9f1b2374278a594222d96ba569993c0298b91d2b 100644 --- a/ohos_nweb/include/nweb_init_params.h +++ b/ohos_nweb/include/nweb_init_params.h @@ -22,201 +22,235 @@ namespace OHOS::NWeb { class NWebDOHConfigImpl : public NWebDOHConfig { public: - NWebDOHConfigImpl() = default; - ~NWebDOHConfigImpl() = default; + NWebDOHConfigImpl() = default; + ~NWebDOHConfigImpl() = default; - void SetMode(int mode) { - mode_ = mode; - } + void SetMode(int mode) + { + mode_ = mode; + } - int GetMode() override { - return mode_; - } + int GetMode() override + { + return mode_; + } - void SetConfig(const std::string &config) { - config_ = config; - } + void SetConfig(const std::string& config) + { + config_ = config; + } - std::string GetConfig() override { - return config_; - } + std::string GetConfig() override + { + return config_; + } private: - int mode_ = -1; - std::string config_; + int mode_ = -1; + std::string config_; }; class NWebCreateInfoImpl : public NWebCreateInfo { public: - NWebCreateInfoImpl() = default; - ~NWebCreateInfoImpl() = default; + NWebCreateInfoImpl() = default; + ~NWebCreateInfoImpl() = default; - void SetWidth(uint32_t width) { - width_ = width; - } + void SetWidth(uint32_t width) + { + width_ = width; + } - uint32_t GetWidth() override { - return width_; - } + uint32_t GetWidth() override + { + return width_; + } - void SetHeight(uint32_t height) { - height_ = height; - } + void SetHeight(uint32_t height) + { + height_ = height; + } - uint32_t GetHeight() override { - return height_; - } + uint32_t GetHeight() override + { + return height_; + } - void SetIsIncognitoMode(bool isIncognitoMode) { - isIncognitoMode_ = isIncognitoMode; - } + void SetIsIncognitoMode(bool isIncognitoMode) + { + isIncognitoMode_ = isIncognitoMode; + } - bool GetIsIncognitoMode() override { - return isIncognitoMode_; - } + bool GetIsIncognitoMode() override + { + return isIncognitoMode_; + } - void SetProducerSurface(void *producerSurface) { - producerSurface_ = producerSurface; - } + void SetProducerSurface(void* producerSurface) + { + producerSurface_ = producerSurface; + } - void *GetProducerSurface() override { - return producerSurface_; - } + void* GetProducerSurface() override + { + return producerSurface_; + } - void SetEnhanceSurfaceInfo(void *enhanceSurfaceInfo) { - enhanceSurfaceInfo_ = enhanceSurfaceInfo; - } + void SetEnhanceSurfaceInfo(void* enhanceSurfaceInfo) + { + enhanceSurfaceInfo_ = enhanceSurfaceInfo; + } - void *GetEnhanceSurfaceInfo() override { - return enhanceSurfaceInfo_; - } + void* GetEnhanceSurfaceInfo() override + { + return enhanceSurfaceInfo_; + } - void SetEngineInitArgs(std::shared_ptr initArgs) { - initArgs_ = initArgs; - } + void SetEngineInitArgs(std::shared_ptr initArgs) + { + initArgs_ = initArgs; + } - std::shared_ptr GetEngineInitArgs() override { - return initArgs_; - } + std::shared_ptr GetEngineInitArgs() override + { + return initArgs_; + } - void SetOutputFrameCallback( - std::shared_ptr outputFrameCallback) { - outputFrameCallback_ = outputFrameCallback; - } + void SetOutputFrameCallback(std::shared_ptr outputFrameCallback) + { + outputFrameCallback_ = outputFrameCallback; + } - std::shared_ptr GetOutputFrameCallback() override { - return outputFrameCallback_; - } + std::shared_ptr GetOutputFrameCallback() override + { + return outputFrameCallback_; + } private: - uint32_t width_ = 0; - uint32_t height_ = 0; + uint32_t width_ = 0; + uint32_t height_ = 0; - bool isIncognitoMode_ = false; + bool isIncognitoMode_ = false; - void *producerSurface_ = nullptr; - void *enhanceSurfaceInfo_ = nullptr; + void* producerSurface_ = nullptr; + void* enhanceSurfaceInfo_ = nullptr; - std::shared_ptr initArgs_ = nullptr; - std::shared_ptr outputFrameCallback_ = nullptr; + std::shared_ptr initArgs_ = nullptr; + std::shared_ptr outputFrameCallback_ = nullptr; }; class NWebEngineInitArgsImpl : public NWebEngineInitArgs { public: - NWebEngineInitArgsImpl() = default; - ~NWebEngineInitArgsImpl() = default; + NWebEngineInitArgsImpl() = default; + ~NWebEngineInitArgsImpl() = default; - void AddArg(const std::string &arg) { - argsToAdd_.emplace_back(arg); - } + void AddArg(const std::string& arg) + { + argsToAdd_.emplace_back(arg); + } - void AddDeleteArg(const std::string &arg) { - argsToDelete_.emplace_back(arg); - } + void AddDeleteArg(const std::string& arg) + { + argsToDelete_.emplace_back(arg); + } - void SetDumpPath(const std::string &dumpPath) { - dumpPath_ = dumpPath; - } + void SetDumpPath(const std::string& dumpPath) + { + dumpPath_ = dumpPath; + } - std::string GetDumpPath() override { - return dumpPath_; - } + std::string GetDumpPath() override + { + return dumpPath_; + } - void SetIsPopup(bool isPopup) { - isPopup_ = isPopup; - } + void SetIsPopup(bool isPopup) + { + isPopup_ = isPopup; + } - bool GetIsPopup() override { - return isPopup_; - } + bool GetIsPopup() override + { + return isPopup_; + } - void SetIsFrameInfoDump(bool isFrameInfoDump) { - isFrameInfoDump_ = isFrameInfoDump; - } + void SetIsFrameInfoDump(bool isFrameInfoDump) + { + isFrameInfoDump_ = isFrameInfoDump; + } - bool GetIsFrameInfoDump() override { - return isFrameInfoDump_; - } + bool GetIsFrameInfoDump() override + { + return isFrameInfoDump_; + } - void SetIsEnhanceSurface(bool isEnhanceSurface) { - isEnhanceSurface_ = isEnhanceSurface; - } + void SetIsEnhanceSurface(bool isEnhanceSurface) + { + isEnhanceSurface_ = isEnhanceSurface; + } - bool GetIsEnhanceSurface() override { - return isEnhanceSurface_; - } + bool GetIsEnhanceSurface() override + { + return isEnhanceSurface_; + } - void SetIsMultiRendererProcess(bool isMultiRendererProcess) { - isMultiRendererProcess_ = isMultiRendererProcess; - } + void SetIsMultiRendererProcess(bool isMultiRendererProcess) + { + isMultiRendererProcess_ = isMultiRendererProcess; + } - bool GetIsMultiRendererProcess() override { - return isMultiRendererProcess_; - } + bool GetIsMultiRendererProcess() override + { + return isMultiRendererProcess_; + } - void SetArgsToAdd(const std::list &argsToAdd) { - argsToAdd_ = argsToAdd; - } + void SetArgsToAdd(const std::list& argsToAdd) + { + argsToAdd_ = argsToAdd; + } - std::list GetArgsToAdd() override { - return argsToAdd_; - } + std::list GetArgsToAdd() override + { + return argsToAdd_; + } - void SetArgsToDelete(const std::list &argsToDelete) { - argsToDelete_ = argsToDelete; - } + void SetArgsToDelete(const std::list& argsToDelete) + { + argsToDelete_ = argsToDelete; + } - std::list GetArgsToDelete() override { - return argsToDelete_; - } + std::list GetArgsToDelete() override + { + return argsToDelete_; + } - void SetSharedRenderProcessToken(const std::string& sharedRenderProcessToken) - { - sharedRenderProcessToken_ = sharedRenderProcessToken; - } + void SetSharedRenderProcessToken(const std::string& sharedRenderProcessToken) + { + sharedRenderProcessToken_ = sharedRenderProcessToken; + } - std::string GetSharedRenderProcessToken() override - { - return sharedRenderProcessToken_; - } + std::string GetSharedRenderProcessToken() override + { + return sharedRenderProcessToken_; + } private: - std::string dumpPath_; + std::string dumpPath_; - bool isPopup_ = false; - bool isFrameInfoDump_ = false; - bool isEnhanceSurface_ = false; - bool isMultiRendererProcess_ = false; + bool isPopup_ = false; + bool isFrameInfoDump_ = false; + bool isEnhanceSurface_ = false; + bool isMultiRendererProcess_ = false; - std::list argsToAdd_; - std::list argsToDelete_; - std::string sharedRenderProcessToken_; + std::list argsToAdd_; + std::list argsToDelete_; + std::string sharedRenderProcessToken_; }; class NWebEnginePrefetchArgsImpl : public NWebEnginePrefetchArgs { public: - NWebEnginePrefetchArgsImpl(const std::string &url, const std::string &method, const std::string &formData) - : url_(url), method_(method), form_data_(formData) {} + NWebEnginePrefetchArgsImpl(const std::string& url, const std::string& method, const std::string& formData) + : url_(url), method_(method), form_data_(formData) + {} ~NWebEnginePrefetchArgsImpl() = default; diff --git a/ohos_nweb/prebuilts/arm/NWeb.hap b/ohos_nweb/prebuilts/arm/NWeb.hap index ac7f3c56cec071b3cc946e81bf962a17d3656f12..74bbe17657c5fdef52b07bbee18b87e258f9d70b 100644 --- a/ohos_nweb/prebuilts/arm/NWeb.hap +++ b/ohos_nweb/prebuilts/arm/NWeb.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fd59e132e126e3df85c2b1f6123c46e32c8d60f4093451172fb9d19cef01c7b5 -size 79363768 +oid sha256:5a65a26b648b94c2b2083d104e50c792396ff6f5f35c9d4c1f0e7556bed4233b +size 122936924 diff --git a/ohos_nweb/prebuilts/arm64/NWeb.hap b/ohos_nweb/prebuilts/arm64/NWeb.hap index 3ea02155baa902570061dccb1679d298449f1477..f003dfd7f8eb09b47c44e2ec826e774e80a6280a 100644 --- a/ohos_nweb/prebuilts/arm64/NWeb.hap +++ b/ohos_nweb/prebuilts/arm64/NWeb.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e4ed361a5946db6afb8e9d6b894c7e1e368d483b5f7b083da80469e668788589 -size 90156696 +oid sha256:3169d53d1d80bdd38c769c14b40948c9c771bac4e2e1523eff7f2bf9762da93e +size 190643577 diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index f9d4065ffbb77b4544164bc88d9039f02ff78af3..a50af0d31e4425212d41786296696d06996c516d 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -73,6 +73,7 @@ static bool g_isFirstTimeStartUp = false; DO(WebDownload_Pause) \ DO(WebDownload_Resume) \ DO(WebDownload_GetItemState) \ + DO(WebDownload_GetItemStateByGuid) \ DO(WebDownloadItem_Guid) \ DO(WebDownloadItem_GetDownloadItemId) \ DO(WebDownloadItem_GetState) \ @@ -279,12 +280,20 @@ extern "C" void WebDownload_Resume(const WebDownloadItemCallbackWrapper *wrapper extern "C" NWebDownloadItemState WebDownload_GetItemState(int32_t nwebId, long downloadItemId) { - if (!g_nwebCApi->impl_WebDownload_GetItemState) { + if (!g_nwebCApi || !g_nwebCApi->impl_WebDownload_GetItemState) { return NWebDownloadItemState::MAX_DOWNLOAD_STATE; } return g_nwebCApi->impl_WebDownload_GetItemState(nwebId, downloadItemId); } +extern "C" NWebDownloadItemState WebDownload_GetItemStateByGuid(const std::string& guid) +{ + if (!g_nwebCApi || !g_nwebCApi->impl_WebDownload_GetItemStateByGuid) { + return NWebDownloadItemState::MAX_DOWNLOAD_STATE; + } + return g_nwebCApi->impl_WebDownload_GetItemStateByGuid(guid); +} + extern "C" char *WebDownloadItem_Guid(const NWebDownloadItem *downloadItem) { if (!g_nwebCApi->impl_WebDownloadItem_Guid) { @@ -811,6 +820,11 @@ bool NWebHelper::InitAndRun(bool from_ark) std::string simplifiedLocale = baseLanguage + "-" + systemRegion; initArgs->AddArg(std::string("--lang=").append(simplifiedLocale)); + for (auto backForwardCacheCmdLine : backForwardCacheCmdLine_) { + initArgs->AddArg(backForwardCacheCmdLine); + WVLOG_I("Add command line when init web engine: %{public}s", backForwardCacheCmdLine.c_str()); + } + nwebEngine_->InitializeWebEngine(initArgs); return true; } @@ -1077,6 +1091,18 @@ void NWebHelper::ClearHostIP(const std::string& hostName) nwebEngine_->ClearHostIP(hostName); } +void NWebHelper::EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaTakeOver) +{ + this->backForwardCacheCmdLine_.emplace_back("--enable-bfcache"); + if (enableNativeEmbed) { + this->backForwardCacheCmdLine_.emplace_back("--enable-cache-native-embed"); + } + + if (enableMediaTakeOver) { + this->backForwardCacheCmdLine_.emplace_back("--enable-cache-media-take-over"); + } +} + void NWebHelper::EnableWholeWebPageDrawing() { if (nwebEngine_ == nullptr) { @@ -1116,6 +1142,16 @@ std::shared_ptr NWebHelper::GetAdsBlockManager() return nwebEngine_->GetAdsBlockManager(); } +void NWebHelper::TrimMemoryByPressureLevel(int32_t memoryLevel) +{ + if (nwebEngine_ == nullptr) { + WVLOG_E("nweb engine is nullptr"); + return; + } + + nwebEngine_->TrimMemoryByPressureLevel(memoryLevel); +} + NWebAdapterHelper &NWebAdapterHelper::Instance() { static NWebAdapterHelper helper; diff --git a/test/unittest/aafwk_app_client_adapter/nweb_aafwk_adapter_test.cpp b/test/unittest/aafwk_app_client_adapter/nweb_aafwk_adapter_test.cpp index 6cc55f1dc8abbde434cae4a3472326ed6f31b4cc..abddfdb86b1bae790109ca9e0a3f3fe571c09afd 100644 --- a/test/unittest/aafwk_app_client_adapter/nweb_aafwk_adapter_test.cpp +++ b/test/unittest/aafwk_app_client_adapter/nweb_aafwk_adapter_test.cpp @@ -490,6 +490,8 @@ HWTEST_F(NWebAafwkAdapterTest, NWebAafwkAdapter_browserHost_020, TestSize.Level1 MessageParcel reply; MessageOption option; host->OnRemoteRequest(code, data, reply, option); + code = 100; + host->OnRemoteRequest(code, data, reply, option); } /** diff --git a/test/unittest/net_connect_adapter_impl_test/net_connect_adapter_impl_test.cpp b/test/unittest/net_connect_adapter_impl_test/net_connect_adapter_impl_test.cpp index 6c7d65a98ee6ec3b01445e94b58355db93c36d4c..0f06a309c35a954a712dc7d5eb86d856ba3e458d 100644 --- a/test/unittest/net_connect_adapter_impl_test/net_connect_adapter_impl_test.cpp +++ b/test/unittest/net_connect_adapter_impl_test/net_connect_adapter_impl_test.cpp @@ -140,6 +140,16 @@ public: { return 0; } + int32_t OnNetCapabilitiesChanged( + const std::shared_ptr capabilities) override + { + return 0; + } + int32_t OnNetConnectionPropertiesChanged( + const std::shared_ptr properties) override + { + return 0; + } }; /** diff --git a/test/unittest/net_connect_callback_impl_test/net_connect_callback_impl_test.cpp b/test/unittest/net_connect_callback_impl_test/net_connect_callback_impl_test.cpp index 65cb471281906b6ab82edc4f086540dce317992f..878cfdd912f97563aed1a561874b8eb8157c3604 100644 --- a/test/unittest/net_connect_callback_impl_test/net_connect_callback_impl_test.cpp +++ b/test/unittest/net_connect_callback_impl_test/net_connect_callback_impl_test.cpp @@ -81,6 +81,16 @@ public: { return 0; } + int32_t OnNetCapabilitiesChanged( + const std::shared_ptr capabilities) override + { + return 0; + } + int32_t OnNetConnectionPropertiesChanged( + const std::shared_ptr properties) override + { + return 0; + } }; /** diff --git a/test/unittest/nweb_helper_test/nweb_helper_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_test.cpp index 33fcc2acc27c138399b54e2bcb6d6dd1c0270410..756abd93b4a3910ecaf7e3bc1ead3ffd0ed53119 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_test.cpp @@ -143,6 +143,8 @@ public: { return nullptr; } + + void EnableBackForwardCache(bool nativeEmbed, bool mediaTakeOver) {} }; void NwebHelperTest::SetUpTestCase(void) @@ -192,6 +194,7 @@ HWTEST_F(NwebHelperTest, NWebHelper_SetBundlePath_001, TestSize.Level1) NWebHelper::Instance().PrefetchResource(nullptr, {}, "web_test", 0); NWebHelper::Instance().ClearPrefetchedResource({"web_test"}); NWebAdapterHelper::Instance().ReadConfigIfNeeded(); + NWebHelper::Instance().EnableBackForwardCache(true, true); result = NWebHelper::Instance().InitAndRun(false); EXPECT_FALSE(result); ApplicationContextMock *contextMock = new ApplicationContextMock(); @@ -325,6 +328,7 @@ HWTEST_F(NwebHelperTest, NWebHelper_GetConfigPath_005, TestSize.Level1) NWebHelper::Instance().PrefetchResource(nullptr, {}, "web_test", 0); NWebHelper::Instance().ClearPrefetchedResource({"web_test"}); NWebHelper::Instance().bundlePath_.clear(); + NWebHelper::Instance().EnableBackForwardCache(true, true); bool result = NWebHelper::Instance().InitAndRun(false); EXPECT_FALSE(result); NWebHelper::Instance().SetConnectionTimeout(1); @@ -438,7 +442,6 @@ HWTEST_F(NwebHelperTest, NWebHelper_WebDownloadItem_IsPaused_007, TestSize.Level WebDownloadItem_SetReceivedBytes(downloadItem, 1); WebDownloadItem_SetTotalBytes(downloadItem, 1); WebDownloadItem_SetReceivedSlices(downloadItem, "test_web"); - char* guid = WebDownloadItem_Guid(downloadItem); EXPECT_NE(guid, nullptr); int64_t totalBytes = WebDownloadItem_TotalBytes(downloadItem); @@ -453,6 +456,10 @@ HWTEST_F(NwebHelperTest, NWebHelper_WebDownloadItem_IsPaused_007, TestSize.Level EXPECT_NE(eTag, nullptr); char* mimeType = WebDownloadItem_MimeType(downloadItem); EXPECT_NE(mimeType, nullptr); + long itemId = WebDownloadItem_GetDownloadItemId(downloadItem); + auto state1 = WebDownload_GetItemState(nWebId, itemId); + auto state2 = WebDownload_GetItemStateByGuid("test_web"); + EXPECT_EQ(state1, state2); } /** @@ -471,6 +478,8 @@ HWTEST_F(NwebHelperTest, NWebHelper_GetWebEngineHandler_008, TestSize.Level1) EXPECT_EQ(nweb, nullptr); std::shared_ptr cook = NWebHelper::Instance().GetCookieManager(); EXPECT_EQ(cook, nullptr); + auto manager = NWebHelper::Instance().GetAdsBlockManager(); + EXPECT_EQ(manager, nullptr); std::shared_ptr config = std::make_shared(); NWebHelper::Instance().SetHttpDns(config); NWebHelper::Instance().PrepareForPageLoad("web_test", true, 0); @@ -493,6 +502,8 @@ HWTEST_F(NwebHelperTest, NWebHelper_GetWebEngineHandler_008, TestSize.Level1) EXPECT_TRUE(result); cook = NWebHelper::Instance().GetCookieManager(); EXPECT_NE(cook, nullptr); + manager = NWebHelper::Instance().GetAdsBlockManager(); + EXPECT_NE(manager, nullptr); NWebHelper::Instance().SetWebTag(1, "webtag"); NWebHelper::Instance().libHandleWebEngine_ = nullptr; @@ -600,12 +611,14 @@ HWTEST_F(NwebHelperTest, NWebHelper_EnableWholeWebPageDrawing_001, TestSize.Leve */ HWTEST_F(NwebHelperTest, NWebHelper_GetAdsBlockManager_001, TestSize.Level1) { + NWebHelper::Instance().nwebEngine_ = nullptr; + std::shared_ptr create_info = std::make_shared(); + std::shared_ptr nweb = NWebHelper::Instance().CreateNWeb(create_info); + EXPECT_EQ(nweb, nullptr); + nweb = NWebHelper::Instance().GetNWeb(1); + EXPECT_EQ(nweb, nullptr); auto manager = NWebHelper::Instance().GetAdsBlockManager(); - bool result = false; - if (manager != nullptr) { - result = true; - } - EXPECT_EQ(RESULT_OK, result); + EXPECT_EQ(manager, nullptr); } } // namespace OHOS::NWeb } diff --git a/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn b/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn index e36c4bced23a98577d29a5f3c9ed1b5c028d44cb..68f70db254165f23d10faac17413c2a011d6b011 100644 --- a/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn +++ b/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("nweb_hiviewdfx_adapter_test") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "init:libbegetutil", ] } diff --git a/test/unittest/ohos_adapter/hiviewdfx_adapter_test/hiviewdfx_adapter_test.cpp b/test/unittest/ohos_adapter/hiviewdfx_adapter_test/hiviewdfx_adapter_test.cpp index 8b27bc9c657a3826f9a506de481a412d3ed5dcca..08bfbc64f72a7532396a96cff5147840453bc50c 100644 --- a/test/unittest/ohos_adapter/hiviewdfx_adapter_test/hiviewdfx_adapter_test.cpp +++ b/test/unittest/ohos_adapter/hiviewdfx_adapter_test/hiviewdfx_adapter_test.cpp @@ -18,6 +18,9 @@ #include "ohos_adapter_helper.h" #include "hitrace_adapter_impl.h" +#include "parameters.h" +using namespace OHOS; + using testing::ext::TestSize; namespace OHOS::NWeb { @@ -88,15 +91,12 @@ HWTEST(HiViewDFXAdapterTest, NormalScene, TestSize.Level1) */ HWTEST(HiViewDFXAdapterTest, NormalScene_01, TestSize.Level1) { - uint64_t val = (1ULL << 24); - std::string value = std::to_string(val); - HiTraceAdapterImpl::GetInstance().UpdateOHOSTraceTag(value.c_str()); OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().StartOHOSTrace("test"); OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().CountOHOSTrace("test", 1); OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().FinishOHOSTrace(); - val = (1ULL << 39); - value = std::to_string(val); - HiTraceAdapterImpl::GetInstance().UpdateOHOSTraceTag(value.c_str()); + uint64_t val = (1ULL << 24); + std::string value = std::to_string(val); + OHOS::system::SetParameter("debug.hitrace.tags.enableflags", value); OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().StartOHOSTrace("test"); OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().CountOHOSTrace("test", 1); OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().FinishOHOSTrace(); diff --git a/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn b/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ba7d1c9d92ff911ff2a73f0bc62f880e34f3911c --- /dev/null +++ b/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn @@ -0,0 +1,53 @@ +# 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. + +import("//build/test.gni") + +module_output_path = "web/webview" + +config("module_private_config") { + visibility = [ ":*" ] + + include_dirs = [ + "../../../../ohos_adapter/ohos_image_adapter/include", + "../../../../ohos_interface/include/ohos_adpter/ohos_image_decoder_adapter.h", + ] +} + +ohos_unittest("ohos_image_decoder_adapter_test") { + module_out_path = module_output_path + + sources = [ "ohos_image_decoder_adapter_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "../../../../ohos_adapter:nweb_ohos_adapter", + "../../../../ohos_nweb:libnweb", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "graphic_2d:libnative_image", + "hilog:libhilog", + "image_framework:image_native", + "image_framework:image_utils", + ] +} + +group("unittest") { + testonly = true + deps = [ ":ohos_image_decoder_adapter_test" ] +} diff --git a/test/unittest/ohos_adapter/ohos_image_adapter/ohos_image_decoder_adapter_test.cpp b/test/unittest/ohos_adapter/ohos_image_adapter/ohos_image_decoder_adapter_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1c6b78a163b525030804f7cf9473db4b4ad3bf13 --- /dev/null +++ b/test/unittest/ohos_adapter/ohos_image_adapter/ohos_image_decoder_adapter_test.cpp @@ -0,0 +1,493 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include + +#define private public +#include "pixel_map.h" +#include "directory_ex.h" +#include "image_source.h" +#include "image_utils.h" +#include "ohos_image_decoder_adapter_impl.h" +#undef private + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +namespace NWeb { +namespace { + +static const std::string IMAGE_FILE_PATH = "/data/local/tmp/image/test.heic"; + +bool ReadFileToBuffer(const std::string &filePath, uint8_t *buffer, size_t bufferSize) +{ + std::string realPath; + if (!OHOS::PathToRealPath(filePath, realPath)) { + return false; + } + + if (buffer == nullptr) { + return false; + } + + FILE *fp = fopen(realPath.c_str(), "rb"); + if (fp == nullptr) { + return false; + } + if (fseek(fp, 0, SEEK_END) != 0) { + return false; + } + size_t fileSize = ftell(fp); + if (fseek(fp, 0, SEEK_SET) != 0) { + return false; + } + if (bufferSize < fileSize) { + fclose(fp); + return false; + } + size_t retSize = fread(buffer, 1, fileSize, fp); + if (retSize != fileSize) { + fclose(fp); + return false; + } + int ret = fclose(fp); + if (ret != 0) { + return true; + } + return true; +} + +bool TestInitImage(OhosImageDecoderAdapterImpl &imageDecoderAdapterImpl, uint8_t *buffer) +{ + size_t bufferSize = 0; + bool boolRes = Media::ImageUtils::GetFileSize(IMAGE_FILE_PATH, bufferSize); + if (!boolRes) { + return false; + } + + buffer = static_cast(malloc(bufferSize)); + if (buffer == nullptr) { + return false; + } + + boolRes = ReadFileToBuffer(IMAGE_FILE_PATH, buffer, bufferSize); + if (!boolRes) { + free(buffer); + return false; + } + + boolRes = imageDecoderAdapterImpl.ParseImageInfo(buffer, bufferSize); + if (!boolRes) { + free(buffer); + return false; + } + return true; +} + +bool TestDecodeImage(OhosImageDecoderAdapterImpl &imageDecoderAdapterImpl, uint8_t *buffer) +{ + size_t bufferSize = 0; + bool boolRes = Media::ImageUtils::GetFileSize(IMAGE_FILE_PATH, bufferSize); + if (!boolRes) { + return false; + } + + buffer = static_cast(malloc(bufferSize)); + if (buffer == nullptr) { + return false; + } + + boolRes = ReadFileToBuffer(IMAGE_FILE_PATH, buffer, bufferSize); + if (!boolRes) { + free(buffer); + return false; + } + + boolRes = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + if (!boolRes) { + free(buffer); + return false; + } + return true; +} +} // namespace + +class OhosImageAdapterTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void OhosImageAdapterTest::SetUpTestCase(void) +{} + +void OhosImageAdapterTest::TearDownTestCase(void) +{} + +void OhosImageAdapterTest::SetUp(void) +{} + +void OhosImageAdapterTest::TearDown(void) +{} + +/** + * @tc.name: OhosImageAdapterTest_ParseImageInfo_001 + * @tc.desc: ParseImageInfo. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_ParseImageInfo_001, TestSize.Level1) +{ + uint8_t data[32] = {0}; + uint32_t size = sizeof(data); + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + bool result = imageDecoderAdapterImpl.ParseImageInfo(nullptr, size); + EXPECT_FALSE(result); + + result = imageDecoderAdapterImpl.ParseImageInfo(data, 0); + EXPECT_FALSE(result); + + result = imageDecoderAdapterImpl.ParseImageInfo(data, size); + EXPECT_FALSE(result); + + size_t bufferSize = 0; + bool boolRes = Media::ImageUtils::GetFileSize(IMAGE_FILE_PATH, bufferSize); + EXPECT_TRUE(boolRes); + + uint8_t *buffer = static_cast(malloc(bufferSize)); + EXPECT_NE(buffer, nullptr); + + boolRes = ReadFileToBuffer(IMAGE_FILE_PATH, buffer, bufferSize); + EXPECT_TRUE(boolRes); + + boolRes = imageDecoderAdapterImpl.ParseImageInfo(buffer, (uint32_t)bufferSize); + EXPECT_TRUE(boolRes); + + free(buffer); +} + +/** + * @tc.name: OhosImageAdapterTest_GetEncodedFormat_002 + * @tc.desc: GetEncodedFormat. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetEncodedFormat_002, TestSize.Level1) +{ + uint8_t *buffer = nullptr; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + bool ret = TestInitImage(imageDecoderAdapterImpl, buffer); + EXPECT_TRUE(ret); + std::string format = imageDecoderAdapterImpl.GetEncodedFormat(); + EXPECT_NE(format, ""); + + free(buffer); +} + +/** + * @tc.name: OhosImageAdapterTest_GetImageWidth_003 + * @tc.desc: GetImageWidth. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetImageWidth_003, TestSize.Level1) +{ + uint8_t *buffer = nullptr; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + bool ret = TestInitImage(imageDecoderAdapterImpl, buffer); + EXPECT_TRUE(ret); + int32_t width = imageDecoderAdapterImpl.GetImageWidth(); + EXPECT_NE(width, 0); + + free(buffer); +} + +/** + * @tc.name: OhosImageAdapterTest_GetImageHeight_004 + * @tc.desc: GetImageHeight. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetImageHeight_004, TestSize.Level1) +{ + uint8_t *buffer = nullptr; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + bool ret = TestInitImage(imageDecoderAdapterImpl, buffer); + EXPECT_TRUE(ret); + int32_t heigth = imageDecoderAdapterImpl.GetImageHeight(); + EXPECT_NE(heigth, 0); + + free(buffer); +} + +/** + * @tc.name: OhosImageAdapterTest_DecodeToPixelMap_005 + * @tc.desc: DecodeToPixelMap. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_DecodeToPixelMap_005, TestSize.Level1) +{ + size_t bufferSize = 0; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(nullptr, bufferSize); + EXPECT_FALSE(ret); + + bool boolRes = Media::ImageUtils::GetFileSize(IMAGE_FILE_PATH, bufferSize); + + uint8_t *buffer = static_cast(malloc(bufferSize)); + + boolRes = ReadFileToBuffer(IMAGE_FILE_PATH, buffer, bufferSize); + EXPECT_TRUE(boolRes); + + ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + EXPECT_TRUE(ret); + + free(buffer); +} + +/** + * @tc.name: OhosImageAdapterTest_GetFd_006 + * @tc.desc: GetFd. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetFd_006, TestSize.Level1) +{ + uint8_t *buffer = nullptr; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + int32_t fd = imageDecoderAdapterImpl.GetFd(); + EXPECT_EQ(fd, -1); + + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); + EXPECT_TRUE(ret); + + fd = imageDecoderAdapterImpl.GetFd(); + EXPECT_NE(fd, -1); + + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); + pixelMap->FreePixelMap(); + fd = imageDecoderAdapterImpl.GetFd(); + EXPECT_EQ(fd, -1); + + free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); +} + +/** + * @tc.name: OhosImageAdapterTest_GetStride_007 + * @tc.desc: GetStride. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetStride_007, TestSize.Level1) +{ + uint8_t *buffer = nullptr; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + int32_t stride = imageDecoderAdapterImpl.GetStride(); + EXPECT_EQ(stride, 0); + + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); + EXPECT_TRUE(ret); + + stride = imageDecoderAdapterImpl.GetStride(); + EXPECT_NE(stride, 0); + + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); + pixelMap->FreePixelMap(); + stride = imageDecoderAdapterImpl.GetStride(); + EXPECT_EQ(stride, 0); + + free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); +} + +/** + * @tc.name: OhosImageAdapterTest_GetOffset_008 + * @tc.desc: GetOffset. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetOffset_008, TestSize.Level1) +{ + uint8_t *buffer = nullptr; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + int32_t offset = imageDecoderAdapterImpl.GetOffset(); + EXPECT_EQ(offset, 0); + + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); + EXPECT_TRUE(ret); + + offset = imageDecoderAdapterImpl.GetOffset(); + EXPECT_EQ(offset, 0); + + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); + pixelMap->FreePixelMap(); + offset = imageDecoderAdapterImpl.GetOffset(); + EXPECT_EQ(offset, 0); + + free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); +} + +/** + * @tc.name: OhosImageAdapterTest_GetSize_009 + * @tc.desc: GetSize. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetSize_009, TestSize.Level1) +{ + uint8_t *buffer = nullptr; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + uint64_t size = imageDecoderAdapterImpl.GetSize(); + EXPECT_EQ(size, 0); + + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); + EXPECT_TRUE(ret); + + size = imageDecoderAdapterImpl.GetSize(); + EXPECT_NE(size, 0); + + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); + pixelMap->FreePixelMap(); + size = imageDecoderAdapterImpl.GetSize(); + EXPECT_EQ(size, 0); + + free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); +} + +/** + * @tc.name: OhosImageAdapterTest_GetNativeWindowBuffer_010 + * @tc.desc: GetNativeWindowBuffer. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetNativeWindowBuffer_010, TestSize.Level1) +{ + uint8_t *buffer = nullptr; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + void* windowBuffer = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + EXPECT_EQ(windowBuffer, nullptr); + + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); + EXPECT_TRUE(ret); + + windowBuffer = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + EXPECT_NE(windowBuffer, nullptr); + + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); + pixelMap->FreePixelMap(); + windowBuffer = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + EXPECT_NE(windowBuffer, nullptr); + + free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); +} + + +/** + * @tc.name: OhosImageAdapterTest_GetPlanesCount_011 + * @tc.desc: GetPlanesCount. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetPlanesCount_011, TestSize.Level1) +{ + uint8_t *buffer = nullptr; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + int32_t planesCount = imageDecoderAdapterImpl.GetPlanesCount(); + EXPECT_EQ(planesCount, 0); + + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); + EXPECT_TRUE(ret); + + planesCount = imageDecoderAdapterImpl.GetPlanesCount(); + EXPECT_EQ(planesCount, 0); + + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); + pixelMap->FreePixelMap(); + planesCount = imageDecoderAdapterImpl.GetPlanesCount(); + EXPECT_EQ(planesCount, 0); + + free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); +} + +/** + * @tc.name: OhosImageAdapterTest_Decode_012 + * @tc.desc: Decode. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_Decode_012, TestSize.Level1) +{ + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + uint8_t data[32] = {0}; + uint32_t size = sizeof(data); + bool ret = imageDecoderAdapterImpl.Decode(data, size, AllocatorType::kDmaAlloc, false); + EXPECT_FALSE(ret); + + ret = imageDecoderAdapterImpl.Decode(nullptr, size, AllocatorType::kDmaAlloc, false); + EXPECT_FALSE(ret); + + ret = imageDecoderAdapterImpl.Decode(data, 0, AllocatorType::kDmaAlloc, false); + EXPECT_FALSE(ret); + + size_t bufferSize = 0; + bool boolRes = Media::ImageUtils::GetFileSize(IMAGE_FILE_PATH, bufferSize); + uint8_t *buffer = static_cast(malloc(bufferSize)); + boolRes = ReadFileToBuffer(IMAGE_FILE_PATH, buffer, bufferSize); + EXPECT_TRUE(boolRes); + + ret = imageDecoderAdapterImpl.Decode(buffer, bufferSize, AllocatorType::kDmaAlloc, true); + EXPECT_TRUE(ret); + + ret = imageDecoderAdapterImpl.Decode(buffer, bufferSize, AllocatorType::kDmaAlloc, false); + EXPECT_TRUE(ret); + + free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); +} + +} // namespace NWeb +} // namespace OHOS