From 73bba867c436c8b574e6b61986e3eeab9eff0a62 Mon Sep 17 00:00:00 2001 From: ji_xinliu Date: Tue, 4 Jun 2024 16:23:24 +0800 Subject: [PATCH 001/126] =?UTF-8?q?isNeedRefresh=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E9=BB=84=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ji_xinliu --- interfaces/native/native_interface_arkweb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/native/native_interface_arkweb.h b/interfaces/native/native_interface_arkweb.h index f615ce5d..226ea32c 100644 --- a/interfaces/native/native_interface_arkweb.h +++ b/interfaces/native/native_interface_arkweb.h @@ -91,7 +91,7 @@ void OH_NativeArkWeb_RunJavaScript(const char* webTag, const char* jsCode, Nativ * @since 11 */ void OH_NativeArkWeb_RegisterJavaScriptProxy(const char* webTag, const char* objName, const char** methodList, - NativeArkWeb_OnJavaScriptProxyCallback* callback, int32_t size, bool needRefresh); + NativeArkWeb_OnJavaScriptProxyCallback* callback, int32_t size, bool isNeedRefresh); /* * @brief Deletes the registered object which th given name. -- Gitee From 1ad3ddd28dd9756f8a7b97eb7675b38005fc2923 Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Wed, 26 Jun 2024 11:23:02 +0800 Subject: [PATCH 002/126] Add BFCache interface. Signed-off-by: gaojianhao1 --- .../kits/cj/include/webview_controller_impl.h | 2 + .../kits/cj/src/webview_controller_impl.cpp | 10 ++ .../napi_webview_controller.cpp | 107 ++++++++++++++++++ .../napi_webview_controller.h | 14 +++ .../webviewcontroller/webview_controller.cpp | 10 ++ .../webviewcontroller/webview_controller.h | 2 + ohos_interface/include/ohos_nweb/nweb.h | 6 + .../include/ohos_nweb/nweb_engine.h | 2 + .../bridge/webcore/ark_web_engine_impl.cpp | 5 + .../bridge/webcore/ark_web_engine_impl.h | 2 + .../bridge/webcore/ark_web_nweb_impl.cpp | 5 + .../bridge/webcore/ark_web_nweb_impl.h | 6 + .../bridge/webview/ark_web_engine_wrapper.cpp | 4 + .../bridge/webview/ark_web_engine_wrapper.h | 2 + .../bridge/webview/ark_web_nweb_wrapper.cpp | 5 + .../bridge/webview/ark_web_nweb_wrapper.h | 6 + .../ohos_nweb/include/ark_web_engine.h | 3 + .../ohos_nweb/include/ark_web_nweb.h | 6 + ohos_nweb/include/nweb_helper.h | 2 + ohos_nweb/src/nweb_helper.cpp | 10 ++ 20 files changed, 209 insertions(+) diff --git a/interfaces/kits/cj/include/webview_controller_impl.h b/interfaces/kits/cj/include/webview_controller_impl.h index ddcb4a51..db30340e 100644 --- a/interfaces/kits/cj/include/webview_controller_impl.h +++ b/interfaces/kits/cj/include/webview_controller_impl.h @@ -153,6 +153,8 @@ namespace OHOS::Webview { void Stop(); + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive); + public: static std::string customeSchemeCmdLine_; static bool existNweb_; diff --git a/interfaces/kits/cj/src/webview_controller_impl.cpp b/interfaces/kits/cj/src/webview_controller_impl.cpp index 03b8e08a..34e53145 100644 --- a/interfaces/kits/cj/src/webview_controller_impl.cpp +++ b/interfaces/kits/cj/src/webview_controller_impl.cpp @@ -609,4 +609,14 @@ 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); + } } \ No newline at end of file diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 38f761bf..9a92099b 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -490,6 +490,8 @@ 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), }; napi_value constructor = nullptr; napi_define_class(env, WEBVIEW_CONTROLLER_CLASS_NAME.c_str(), WEBVIEW_CONTROLLER_CLASS_NAME.length(), @@ -5439,6 +5441,111 @@ napi_value NapiWebviewController::PrecompileJavaScript(napi_env env, napi_callba return promise; } +bool ParseBackForwardCacheSupportedFeature(napi_env env, napi_value obj, BackForwardCacheSupportedFeature& feature) +{ + std::map> featuresBooleanProperties = { + {"nativeEmbed", [](const BackForwardCacheSupportedFeature& feature) { return feature.nativeEmbed; }}, + {"mediaIntercept", [](const BackForwardCacheSupportedFeature& feature) { return feature.mediaIntercept; }}, + }; + + for (const auto& property : featuresBooleanProperties) { + napi_value propertyObj = nullptr; + napi_get_named_property(env, obj, property.first.c_str(), &propertyObj); + bool featureProperty = property.second(feature); + if (!NapiParseUtils::ParseBoolean(env, propertyObj, featureProperty)) { + return false; + } + } + + return true; +} + +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) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "one")); + return result; + } + + napi_value obj = argv[0]; + BackForwardCacheSupportedFeature feature; + if (!ParseBackForwardCacheSupportedFeature(env, obj, feature)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + "BusinessError: 401. Parameter error. Wrong param of features."); + return result; + } + + WVLOG_I("The value of supported ativeEmbed is: %{public}d", feature.nativeEmbed); + WVLOG_I("The value of supported mediaIntercept is: %{public}d", feature.mediaIntercept); + + NWebHelper::Instance().EnableBackForwardCache(feature.nativeEmbed, feature.mediaIntercept); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; +} + +bool ParseBackForwardCacheOptions(napi_env env, napi_value obj, BackForwardCacheOptions& option) +{ + std::map> optionsBooleanProperties = { + {"size", [](const BackForwardCacheOptions& option) { return option.size; }}, + {"timeToLive", [](const BackForwardCacheOptions& option) { return option.timeToLive; }}, + }; + + for (const auto& property : optionsBooleanProperties) { + napi_value propertyObj = nullptr; + napi_get_named_property(env, obj, property.first.c_str(), &propertyObj); + bool optionProperty = property.second(option); + if (!NapiParseUtils::ParseBoolean(env, propertyObj, optionProperty)) { + return false; + } + } + + return true; +} + +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); + if (argc != INTEGER_ONE) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "one")); + return result; + } + + WebviewController* webviewController = GetWebviewController(env, info); + if (!webviewController) { + WVLOG_E("InjectOfflineResource: init webview controller error."); + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); + return result; + } + + napi_value obj = argv[0]; + BackForwardCacheOptions option; + if (!ParseBackForwardCacheOptions(env, obj, option)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + "BusinessError: 401. Parameter error. Wrong param of options."); + return result; + } + + WVLOG_I("The value of backforward cache option size is: %{public}d", option.size); + WVLOG_I("The value of backforward cache option timeToLive is: %{public}d", option.timeToLive); + + webviewController->SetBackForwardCacheOptions(option.size, option.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; diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h index bab044a4..33962ca3 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -61,6 +61,16 @@ struct OfflineResourceValue { napi_value type; }; +struct BackForwardCacheSupportedFeature { + bool nativeEmbed = true; + bool mediaIntercept = true; +}; + +struct BackForwardCacheOptions { + int32_t size = 1; + int32_t timeToLive = 600; +}; + class NapiWebviewController { public: NapiWebviewController() {} @@ -348,6 +358,10 @@ 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 int32_t maxFdNum_; static std::atomic usedFd_; }; diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp index 354fa4bf..52a53a71 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp @@ -1942,5 +1942,15 @@ void WebviewController::SetPathAllowingUniversalAccess( } nweb_ptr->SetPathAllowingUniversalAccess(pathList, moduleName_, errorPath); } + +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 e7623fc3..743e89ff 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.h @@ -372,6 +372,8 @@ public: void SetPathAllowingUniversalAccess(const std::vector& pathList, std::string& errorPath); + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive); + private: int ConverToWebHitTestType(int hitType); diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 18bdc317..feac8f12 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -1356,6 +1356,12 @@ public: */ virtual void PerformAction(int64_t accessibilityId, uint32_t action, const std::map& actionArguments) {} + + /** + * @brief Set backforward cache options. + */ + /*--ark web()--*/ + virtual void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) { return; } }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 41853edc..351e5224 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 EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) {}; }; } // namespace OHOS::NWeb 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 5b55bcb9..d94b0c6b 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::EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) +{ + nweb_engine_->EnableBackForwardCache(enableNativeEmbed, enableMediaIntercept); +} } // 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 28236ab7..63243ef5 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 EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) override; + private: std::shared_ptr nweb_engine_; }; 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 cbca90c1..86cd96a8 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 @@ -1055,4 +1055,9 @@ void ArkWebNWebImpl::PerformAction(int64_t accessibility_id, uint32_t action, { nweb_nweb_->PerformAction(accessibility_id, action, ArkWebStringMapStructToClass(actionArguments)); } + +void ArkWebNWebImpl::SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) +{ + nweb_nweb_->SetBackForwardCacheOptions(size, timeToLive); +} } // 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 a464c2d0..625478b7 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 @@ -1189,6 +1189,12 @@ public: /*--ark web()--*/ void PerformAction(int64_t accessibility_id, uint32_t action, const ArkWebStringMap& actionArguments) override; + + /** + * @brief set backforward cache options. + */ + /*--ark web()--*/ + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) 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 c08317fa..b384e5bf 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,8 @@ ArkWebEngineWrapper::GetAdsBlockManager() { return std::make_shared(ark_web_adsblock_manager); } + +void ArkWebEngineWrapper::EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) { + ark_web_engine_->EnableBackForwardCache(enableNativeEmbed, enableMediaIntercept); +} } // 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 6400bfcd..865d41b8 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 EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) override; private: ArkWebRefPtr ark_web_engine_; }; 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 8c12aaf1..77dc35c8 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 @@ -1233,4 +1233,9 @@ void ArkWebNWebWrapper::PerformAction(int64_t accessibility_id, uint32_t action, ArkWebStringMapStructRelease(stArguments); } + +void ArkWebNWebWrapper::SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) +{ + ark_web_nweb_->SetBackForwardCacheOptions(size, timeToLive); +} } // 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 23940f2d..86da31a1 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 @@ -1199,6 +1199,12 @@ public: /*--ark web()--*/ void PerformAction(int64_t accessibilityId, uint32_t action, const std::map& actionArguments) override; + + /** + * @brief set backforward cache options. + */ + /*--ark web()--*/ + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) 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 ab6194dc..30021b2c 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 EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) = 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 480beb61..5fde82e3 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 @@ -1351,6 +1351,12 @@ public: /*--ark web()--*/ virtual void PerformAction(int64_t accessibilityId, uint32_t action, const ArkWebStringMap& actionArguments) = 0; + + /** + * @brief set backforward cache options. + */ + /*--ark web()--*/ + virtual void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index a6fa18a6..bc953614 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -86,6 +86,8 @@ public: void EnableWholeWebPageDrawing(); std::shared_ptr GetAdsBlockManager(); + void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept); + private: NWebHelper() = default; bool LoadLib(bool from_ark); diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index d29a0d00..3a546cbd 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -1092,6 +1092,16 @@ void NWebHelper::ClearHostIP(const std::string& hostName) nwebEngine_->ClearHostIP(hostName); } +void NWebHelper::EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) +{ + if (nwebEngine_ == nullptr) { + WVLOG_E("nweb engine is nullptr"); + return; + } + + nwebEngine_->EnableBackForwardCache(enableNativeEmbed, enableMediaIntercept); +} + void NWebHelper::EnableWholeWebPageDrawing() { if (nwebEngine_ == nullptr) { -- Gitee From e076f9b3dbf6bc33d973a7a19b1b0409bdbd9e10 Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Sat, 29 Jun 2024 16:54:35 +0800 Subject: [PATCH 003/126] Add BFCache interface. Signed-off-by: gaojianhao1 --- .../webviewcontroller/back_forward_cache_options.h | 4 ++-- .../webviewcontroller/napi_webview_controller.cpp | 12 ++++++------ .../napi/webviewcontroller/napi_webview_controller.h | 10 ---------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h index 6c8cf081..16ef7d2a 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h @@ -38,7 +38,7 @@ private: napi_env env_; int32_t size_; int32_t timeToLive_; -} +}; class BackForwardCacheSupportFeatures { public: @@ -53,7 +53,7 @@ private: napi_env env_; bool nativeEmbed_; bool mediaIntercept_; -} +}; } } diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 0a39d7c3..890a084e 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -5488,10 +5488,10 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call napi_unwrap(env, obj, (void**)&features); napi_create_reference(env, obj, 1, &features->delegate_); - WVLOG_I("The value of supported ativeEmbed is: %{public}d", feature.IsEnableNativeEmbed()); - WVLOG_I("The value of supported mediaIntercept is: %{public}d", feature.IsEnableMediaIntercept()); + WVLOG_I("The value of supported ativeEmbed is: %{public}d", features->IsEnableNativeEmbed()); + WVLOG_I("The value of supported mediaIntercept is: %{public}d", features->IsEnableMediaIntercept()); - NWebHelper::Instance().EnableBackForwardCache(feature.IsEnableNativeEmbed(), feature.IsEnableMediaIntercept()); + NWebHelper::Instance().EnableBackForwardCache(feature->IsEnableNativeEmbed(), feature->IsEnableMediaIntercept()); NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } @@ -5522,10 +5522,10 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ napi_unwrap(env, obj, (void**)&options); napi_create_reference(env, obj, 1, &options->delegate_); - WVLOG_I("The value of backforward cache option size is: %{public}d", options.GetSize()); - WVLOG_I("The value of backforward cache option timeToLive is: %{public}d", options.GetTimeToLive()); + WVLOG_I("The value of backforward cache option size is: %{public}d", options->GetSize()); + WVLOG_I("The value of backforward cache option timeToLive is: %{public}d", options->GetTimeToLive()); - webviewController->SetBackForwardCacheOptions(option.size, option.timeToLive); + webviewController->SetBackForwardCacheOptions(options->GetSize(), options->GetTimeToLive()); NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h index 33962ca3..5877ee94 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -61,16 +61,6 @@ struct OfflineResourceValue { napi_value type; }; -struct BackForwardCacheSupportedFeature { - bool nativeEmbed = true; - bool mediaIntercept = true; -}; - -struct BackForwardCacheOptions { - int32_t size = 1; - int32_t timeToLive = 600; -}; - class NapiWebviewController { public: NapiWebviewController() {} -- Gitee From 3ebea90ef3b5291e91e76e009f57680d34dfa063 Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Sat, 29 Jun 2024 17:56:42 +0800 Subject: [PATCH 004/126] Add BFCache interface. Signed-off-by: gaojianhao1 --- interfaces/kits/napi/BUILD.gn | 2 + .../back_forward_cache_options.cpp | 27 +--- .../back_forward_cache_options.h | 6 +- .../napi_back_forward_cache_options.cpp | 130 ++++++++++++++++++ .../napi_back_forward_cache_options.h | 52 +++++++ .../napi_webview_controller.cpp | 2 +- 6 files changed, 193 insertions(+), 26 deletions(-) create mode 100644 interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp create mode 100644 interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index 38175046..964b8e49 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -53,6 +53,8 @@ ohos_shared_library("webview_napi") { "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/webviewcontroller/back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp index e4167ce1..f3fe444f 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp @@ -17,22 +17,14 @@ #include -#include "back_forward_cache_options.h" #include "napi_parse_utils.h" #include "nweb_log.h" #include "business_error.h" #include "web_errors.h" namespace OHOS::NWeb { -namespace { -BackForwardCacheOptions::BackForwardCacheOptions(napi_env env) - : env_(env) -{ - WVLOG_D("Created a BackForwardCacheOptions class."); -} - -BackForwardCacheOptions::BackForwardCacheOptions(napi_env env, int32_t size, int32_t timeToLive) - : env_(env), size_(size), timeToLive_(timeToLive) +BackForwardCacheOptions::BackForwardCacheOptions(int32_t size, int32_t timeToLive) + : size_(size), timeToLive_(timeToLive) { WVLOG_D("Created a BackForwardCacheOptions class. Value size: %{public}d timeToLive: %{public}d.", size_, timeToLive_); } @@ -47,27 +39,20 @@ int32_t BackForwardCacheOptions::GetTimeToLive() return timeToLive_; } -BackForwardCacheSupportFeatures::BackForwardCacheSupportedFeature(napi_env env) - : env_(env) -{ - WVLOG_D("Created a BackForwardCacheSupportedFeature class."); -} - -BackForwardCacheSupportFeatures::BackForwardCacheSupportFeatures(napi_env env, bool nativeEmbed, bool mediaIntercept) - : env_(env), nativeEmbed_(nativeEmbed), mediaIntercept_(mediaIntercept) +BackForwardCacheSupportFeatures::BackForwardCacheSupportFeatures(bool nativeEmbed, bool mediaIntercept) + : nativeEmbed_(nativeEmbed), mediaIntercept_(mediaIntercept) { WVLOG_D("Created a BackForwardCacheSupportFeatures class. Value nativeEmbed: %{public}d mediaIntercept: %{public}d.", nativeEmbed_, mediaIntercept_); } -bool BackForwardCacheSupportedFeature::IsEnableNativeEmbed() +bool BackForwardCacheSupportFeatures::IsEnableNativeEmbed() { return nativeEmbed_; } -bool BackForwardCacheSupportedFeature::IsEnableMediaIntercept() +bool BackForwardCacheSupportFeatures::IsEnableMediaIntercept() { return mediaIntercept_; } -} } \ 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 index 16ef7d2a..ed28ed1b 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h @@ -27,7 +27,7 @@ namespace OHOS { namespace NWeb { class BackForwardCacheOptions { public: - explicit BackForwardCacheOptions(napi_env env); + BackForwardCacheOptions(napi_env env); BackForwardCacheOptions(napi_env env, int32_t size, int32_t timeToLive); int32_t GetSize(); int32_t GetTimeToLive(); @@ -35,14 +35,13 @@ public: napi_ref delegate_ = nullptr; private: - napi_env env_; int32_t size_; int32_t timeToLive_; }; class BackForwardCacheSupportFeatures { public: - explicit BackForwardCacheSupportFeatures(napi_env env); + BackForwardCacheSupportFeatures(napi_env env); BackForwardCacheSupportFeatures(napi_env env, bool nativeEmbed, bool mediaIntercept); bool IsEnableNativeEmbed(); bool IsEnableMediaIntercept(); @@ -50,7 +49,6 @@ public: napi_ref delegate_ = nullptr; private: - napi_env env_; bool nativeEmbed_; bool mediaIntercept_; }; 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 00000000..e4687d61 --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp @@ -0,0 +1,130 @@ +/* + * 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 "business_error.h" +#include "nweb_log.h" +#include "napi_parse_utils.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; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data); + + BackForwardCacheOptions *options = new BackForwardCacheOptions(env); + + napi_wrap( + env, thisVar, options, + [](napi_env /* env */, void *data, void * /* hint */) { + BackForwardCacheOptions *options = (BackForwardCacheOptions *)data; + delete options; + }, + nullptr, nullptr); + + return thisVar; +} + +napi_value NapiBackForwardCacheSupportFeatures::JS_Constructor(napi_env env, napi_callback_info info) +{ + WVLOG_I("NapiBackForwardCacheSupportFeatures::JS_Constructor is called"); + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data); + + BackForwardCacheSupportFeatures *features = new BackForwardCacheSupportFeatures(env); + + napi_wrap( + env, thisVar, features, + [](napi_env /* env */, void *data, void * /* hint */) { + BackForwardCacheSupportFeatures *features = (BackForwardCacheSupportFeatures *)data; + delete features; + }, + nullptr, nullptr); + + return thisVar; +} + +napi_value NapiBackForwardCacheOptions::JS_GetSize(napi_env env, napi_callback_info info) +{ + WVLOG_D("NapiBackForwardCacheOptions::JS_GetSize"); + return nullptr; +} + +napi_value NapiBackForwardCacheOptions::JS_GetTimeToLive(napi_env env, napi_callback_info info) +{ + WVLOG_D("NapiBackForwardCacheOptions::JS_GetTimeToLive"); + return nullptr; +} + +napi_value NapiBackForwardCacheSupportFeatures::JS_IsEnableNativeEmbed(napi_env env, napi_callback_info info) +{ + WVLOG_D("NapiBackForwardCacheSupportFeatures::JS_IsEnableNativeEmbed"); + return nullptr; +} + +napi_value NapiBackForwardCacheSupportFeatures::JS_IsEnableMediaIntercept(napi_env env, napi_callback_info info) +{ + WVLOG_D("NapiBackForwardCacheSupportFeatures::JS_IsEnableMediaIntercept"); + return nullptr; +} + +napi_value NapiBackForwardCacheOptions::Init(napi_env env, napi_value exports) +{ + WVLOG_D("NapiBackForwardCacheOptions::Init"); + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("getSize", JS_GetSize), + DECLARE_NAPI_FUNCTION("getTimeToLive", JS_GetTimeToLive), + }; + napi_value backForwardCacheOptions = nullptr; + napi_define_class(env, BACK_FORWARD_CACHE_OPTIONS.c_str(), BACK_FORWARD_CACHE_OPTIONS.length(), + JS_Constructor, nullptr, + sizeof(properties) / sizeof(properties[0]), properties, &backForwardCacheOption); + napi_set_named_property(env, exports, BACK_FORWARD_CACHE_OPTIONS.c_str(), + backForwardCacheOption); + return exports; +} + +napi_value NapiBackForwardCacheSupportFeatures::Init(napi_env env, napi_value exports) +{ + WVLOG_D("NapiBackForwardCacheSupportFeatures::Init"); + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("isEnableNativeEmbed", JS_IsEnableNativeEmbed), + DECLARE_NAPI_FUNCTION("isEnableMediaIntercept", JS_IsEnableMediaIntercept), + }; + napi_value backForwardCacheSupportFeature = nullptr; + napi_define_class(env, BACK_FORWARD_CACHE_SUPPORT_FEATURES.c_str(), BACK_FORWARD_CACHE_SUPPORT_FEATURES.length(), + JS_Constructor, nullptr, + sizeof(properties) / sizeof(properties[0]), properties, &backForwardCacheSupportFeature); + napi_set_named_property(env, exports, BACK_FORWARD_CACHE_SUPPORT_FEATURES.c_str(), + backForwardCacheSupportFeature); + 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 00000000..1d0c8f71 --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h @@ -0,0 +1,52 @@ +/* + * 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_SUPPORT_FEATURES = "BackForwardCacheSupportFeatures"; + +class NapiBackForwardCacheOptions { +public: + BackForwardCacheOptions() = default; + ~BackForwardCacheOptions() = default; + + static napi_value Init(napi_env env, napi_value exports); + static napi_value JS_Constructor(napi_env env, napi_callback_info info); + static napi_value JS_GetSize(napi_env env, napi_callback_info info); + static napi_value JS_GetTimeToLive(napi_env env, napi_callback_info info); +}; + +class NapiBackForwardCacheSupportFeatures { +public: + BackForwardCacheSupportFeatures() = default; + ~BackForwardCacheSupportFeatures() = default; + + static napi_value Init(napi_env env, napi_value exports); + static napi_value JS_Constructor(napi_env env, napi_callback_info info); + static napi_value JS_IsEnableNativeEmbed(napi_env env, napi_callback_info info); + static napi_value JS_IsEnableMediaIntercept(napi_env env, napi_callback_info info); +}; + +} +} \ No newline at end of file diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 890a084e..8e8a4269 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -5491,7 +5491,7 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call WVLOG_I("The value of supported ativeEmbed is: %{public}d", features->IsEnableNativeEmbed()); WVLOG_I("The value of supported mediaIntercept is: %{public}d", features->IsEnableMediaIntercept()); - NWebHelper::Instance().EnableBackForwardCache(feature->IsEnableNativeEmbed(), feature->IsEnableMediaIntercept()); + NWebHelper::Instance().EnableBackForwardCache(features->IsEnableNativeEmbed(), features->IsEnableMediaIntercept()); NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } -- Gitee From 011f6a0152f43d111c36b66c72fa8d1bdd44c932 Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Mon, 1 Jul 2024 14:06:39 +0800 Subject: [PATCH 005/126] Add class constructor. Signed-off-by: gaojianhao1 --- .../common/napi_webview_native_module.cpp | 3 + .../back_forward_cache_options.cpp | 14 +++- .../back_forward_cache_options.h | 16 ++-- .../napi_back_forward_cache_options.cpp | 80 ++++++++++++++++--- .../napi_back_forward_cache_options.h | 12 +-- .../napi_webview_controller.cpp | 16 ++-- 6 files changed, 109 insertions(+), 32 deletions(-) diff --git a/interfaces/kits/napi/common/napi_webview_native_module.cpp b/interfaces/kits/napi/common/napi_webview_native_module.cpp index d09ed21f..00ad3d24 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); + NapiBackForwardCacheSupportFeatures::Init(env, exports); return exports; } EXTERN_C_END diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp index f3fe444f..caac1d11 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp @@ -23,8 +23,13 @@ #include "web_errors.h" namespace OHOS::NWeb { +BackForwardCacheOptions::BackForwardCacheOptions() +{ + WVLOG_D("Created a BackForwardCacheOptions class."); +} + BackForwardCacheOptions::BackForwardCacheOptions(int32_t size, int32_t timeToLive) - : size_(size), timeToLive_(timeToLive) + :size_(size), timeToLive_(timeToLive) { WVLOG_D("Created a BackForwardCacheOptions class. Value size: %{public}d timeToLive: %{public}d.", size_, timeToLive_); } @@ -39,8 +44,13 @@ int32_t BackForwardCacheOptions::GetTimeToLive() return timeToLive_; } +BackForwardCacheSupportFeatures::BackForwardCacheSupportFeatures() +{ + WVLOG_D("Created a BackForwardCacheSupportFeatures class."); +} + BackForwardCacheSupportFeatures::BackForwardCacheSupportFeatures(bool nativeEmbed, bool mediaIntercept) - : nativeEmbed_(nativeEmbed), mediaIntercept_(mediaIntercept) + :nativeEmbed_(nativeEmbed), mediaIntercept_(mediaIntercept) { WVLOG_D("Created a BackForwardCacheSupportFeatures class. Value nativeEmbed: %{public}d mediaIntercept: %{public}d.", nativeEmbed_, mediaIntercept_); } diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h index ed28ed1b..e58e675b 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h @@ -27,30 +27,30 @@ namespace OHOS { namespace NWeb { class BackForwardCacheOptions { public: - BackForwardCacheOptions(napi_env env); - BackForwardCacheOptions(napi_env env, int32_t size, int32_t timeToLive); + BackForwardCacheOptions(); + BackForwardCacheOptions(int32_t size, int32_t timeToLive); int32_t GetSize(); int32_t GetTimeToLive(); napi_ref delegate_ = nullptr; private: - int32_t size_; - int32_t timeToLive_; + int32_t size_ = 1; + int32_t timeToLive_ = 600; }; class BackForwardCacheSupportFeatures { public: - BackForwardCacheSupportFeatures(napi_env env); - BackForwardCacheSupportFeatures(napi_env env, bool nativeEmbed, bool mediaIntercept); + BackForwardCacheSupportFeatures(); + BackForwardCacheSupportFeatures(bool nativeEmbed, bool mediaIntercept); bool IsEnableNativeEmbed(); bool IsEnableMediaIntercept(); napi_ref delegate_ = nullptr; private: - bool nativeEmbed_; - bool mediaIntercept_; + bool nativeEmbed_ = true; + bool mediaIntercept_ = true; }; } diff --git a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp index e4687d61..875b1290 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp @@ -21,9 +21,11 @@ #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; @@ -35,15 +37,43 @@ napi_value NapiBackForwardCacheOptions::JS_Constructor(napi_env env, napi_callba WVLOG_I("NapiBackForwardCacheOptions::JS_Constructor is called"); napi_value thisVar = nullptr; void *data = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data); - - BackForwardCacheOptions *options = new BackForwardCacheOptions(env); + size_t argc = 2; + napi_value argv[2] = {0}; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + + BackForwardCacheOptions *options = nullptr; + if (argc == 0) + options = new BackForwardCacheOptions(); + else if (argc == 2) { + int32_t size = 0; + if (!NapiParseUtils::ParseInt32(env, argv[0], size) || (size <= 0 || size > 50)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + "BusinessError: 401. Parameter error. The type of param 'size' must be integer and value between 1 and 50."); + return thisVar; + } + + int32_t timeToLive = 0; + if (!NapiParseUtils::ParseInt32(env, argv[1], timeToLive)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + "BusinessError: 401. Parameter error. The type of param 'timeToLive' must be integer."); + return thisVar; + } + + options = new BackForwardCacheOptions(size, timeToLive); + napi_set_named_property(env, thisVar, "size_", argv[0]); + napi_set_named_property(env, thisVar, "timeToLive_", argv[1]); + } else { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_TWO, "none", "two")); + return thisVar; + } napi_wrap( env, thisVar, options, [](napi_env /* env */, void *data, void * /* hint */) { BackForwardCacheOptions *options = (BackForwardCacheOptions *)data; delete options; + options = nullptr; }, nullptr, nullptr); @@ -55,15 +85,43 @@ napi_value NapiBackForwardCacheSupportFeatures::JS_Constructor(napi_env env, nap WVLOG_I("NapiBackForwardCacheSupportFeatures::JS_Constructor is called"); napi_value thisVar = nullptr; void *data = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data); - - BackForwardCacheSupportFeatures *features = new BackForwardCacheSupportFeatures(env); + size_t argc = 2; + napi_value argv[2] = {0}; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + + BackForwardCacheSupportFeatures *features = nullptr; + if (argc == 0) + features = new BackForwardCacheSupportFeatures(); + else if (argc == 2) { + bool nativeEmbed = true; + if (!NapiParseUtils::ParseBoolean(env, argv[0], nativeEmbed)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "nativeEmbed", "boolean")); + return thisVar; + } + + bool mediaIntercept = true; + if (!NapiParseUtils::ParseBoolean(env, argv[1], mediaIntercept)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "mediaIntercept", "boolean")); + return thisVar; + } + + features = new BackForwardCacheSupportFeatures(nativeEmbed, mediaIntercept); + napi_set_named_property(env, thisVar, "nativeEmbed_", argv[0]); + napi_set_named_property(env, thisVar, "mediaIntercept_", argv[1]); + } else { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_TWO, "none", "two")); + return thisVar; + } napi_wrap( env, thisVar, features, [](napi_env /* env */, void *data, void * /* hint */) { BackForwardCacheSupportFeatures *features = (BackForwardCacheSupportFeatures *)data; delete features; + features = nullptr; }, nullptr, nullptr); @@ -104,9 +162,9 @@ napi_value NapiBackForwardCacheOptions::Init(napi_env env, napi_value exports) napi_value backForwardCacheOptions = nullptr; napi_define_class(env, BACK_FORWARD_CACHE_OPTIONS.c_str(), BACK_FORWARD_CACHE_OPTIONS.length(), JS_Constructor, nullptr, - sizeof(properties) / sizeof(properties[0]), properties, &backForwardCacheOption); + sizeof(properties) / sizeof(properties[0]), properties, &backForwardCacheOptions); napi_set_named_property(env, exports, BACK_FORWARD_CACHE_OPTIONS.c_str(), - backForwardCacheOption); + backForwardCacheOptions); return exports; } @@ -117,12 +175,12 @@ napi_value NapiBackForwardCacheSupportFeatures::Init(napi_env env, napi_value ex DECLARE_NAPI_FUNCTION("isEnableNativeEmbed", JS_IsEnableNativeEmbed), DECLARE_NAPI_FUNCTION("isEnableMediaIntercept", JS_IsEnableMediaIntercept), }; - napi_value backForwardCacheSupportFeature = nullptr; + napi_value backForwardCacheSupportFeatures = nullptr; napi_define_class(env, BACK_FORWARD_CACHE_SUPPORT_FEATURES.c_str(), BACK_FORWARD_CACHE_SUPPORT_FEATURES.length(), JS_Constructor, nullptr, - sizeof(properties) / sizeof(properties[0]), properties, &backForwardCacheSupportFeature); + sizeof(properties) / sizeof(properties[0]), properties, &backForwardCacheSupportFeatures); napi_set_named_property(env, exports, BACK_FORWARD_CACHE_SUPPORT_FEATURES.c_str(), - backForwardCacheSupportFeature); + backForwardCacheSupportFeatures); return exports; } diff --git a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h index 1d0c8f71..41e3d497 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h @@ -28,8 +28,8 @@ const std::string BACK_FORWARD_CACHE_SUPPORT_FEATURES = "BackForwardCacheSupport class NapiBackForwardCacheOptions { public: - BackForwardCacheOptions() = default; - ~BackForwardCacheOptions() = default; + 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); @@ -39,8 +39,8 @@ public: class NapiBackForwardCacheSupportFeatures { public: - BackForwardCacheSupportFeatures() = default; - ~BackForwardCacheSupportFeatures() = default; + NapiBackForwardCacheSupportFeatures() = default; + ~NapiBackForwardCacheSupportFeatures() = default; static napi_value Init(napi_env env, napi_value exports); static napi_value JS_Constructor(napi_env env, napi_callback_info info); @@ -49,4 +49,6 @@ public: }; } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 8e8a4269..07b4907a 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -5484,9 +5484,11 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call } BackForwardCacheSupportFeatures* features = nullptr; - napi_value obj = argv[0]; - napi_unwrap(env, obj, (void**)&features); - napi_create_reference(env, obj, 1, &features->delegate_); + napi_status status = napi_unwrap(env, argv[INTEGER_ZERO], (void**)&features) + if (status != napi_ok || features == nullptr) { + WVLOG_E("BACKFORWARDCACHE:: unwrap features failed."); + return result; + } WVLOG_I("The value of supported ativeEmbed is: %{public}d", features->IsEnableNativeEmbed()); WVLOG_I("The value of supported mediaIntercept is: %{public}d", features->IsEnableMediaIntercept()); @@ -5518,9 +5520,11 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ } BackForwardCacheOptions* options = nullptr; - napi_value obj = argv[0]; - napi_unwrap(env, obj, (void**)&options); - napi_create_reference(env, obj, 1, &options->delegate_); + napi_status status = napi_unwrap(env, argv[INTEGER_ZERO], (void**)&options) + if (status != napi_ok || options == nullptr) { + WVLOG_E("BACKFORWARDCACHE:: unwrap options failed."); + return result; + } WVLOG_I("The value of backforward cache option size is: %{public}d", options->GetSize()); WVLOG_I("The value of backforward cache option timeToLive is: %{public}d", options->GetTimeToLive()); -- Gitee From a9639f2eb1eed5b8e55721aab19dc7fb84303648 Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Wed, 3 Jul 2024 13:32:11 +0800 Subject: [PATCH 006/126] Add interface Signed-off-by: gaojianhao1 --- .../napi_webview_controller.cpp | 72 +++++++++---------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 0f6d9ec6..65fb6b5f 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -5503,30 +5503,26 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call bool mediaTakeOver = false; napi_value embedObj = nullptr; napi_value mediaObj = nullptr; - if (napi_has_named_property(env, argv[INTEGER_ZERO], "nativeEmbed", &embedObj) == napi_ok) { - if (napi_get_named_property(env, argv[INTEGER_ZERO], "nativeEmbed", &embedObj) != napi_ok) { - WVLOG_E("Failed to get BackForwardCacheOptions nativeEmbed value."); - return result; - } + if (napi_get_named_property(env, argv[INTEGER_ZERO], "nativeEmbed", &embedObj) != napi_ok) { + WVLOG_E("Failed to get BackForwardCacheOptions nativeEmbed value."); + return result; + } - if (!NapiParseUtils::ParseBoolean(env, mediaObj, nativeEmbed)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "nativeEmbed", "bool")); - return result; - } + if (!NapiParseUtils::ParseBoolean(env, embedObj, nativeEmbed)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "nativeEmbed", "bool")); + return result; } - if (napi_has_named_property(env, argv[INTEGER_ZERO], "mediaTakeOver", &mediaObj) == napi_ok) { - if (napi_get_named_property(env, argv[INTEGER_ZERO], "mediaTakeOver", &mediaObj) != napi_ok) { - WVLOG_E("Failed to get BackForwardCacheOptions mediaTakeOver value."); - return result; - } + if (napi_get_named_property(env, argv[INTEGER_ZERO], "mediaTakeOver", &mediaObj) != napi_ok) { + WVLOG_E("Failed to get BackForwardCacheOptions mediaTakeOver value."); + return result; + } - if (!NapiParseUtils::ParseBoolean(env, mediaObj, mediaTakeOver)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "mediaTakeOver", "bool")); - return result; - } + if (!NapiParseUtils::ParseBoolean(env, mediaObj, mediaTakeOver)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "mediaTakeOver", "bool")); + return result; } WVLOG_I("The value of supported ativeEmbed is: %{public}d", nativeEmbed); @@ -5555,30 +5551,26 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ int32_t timeToLive = 600; napi_value sizeObj = nullptr; napi_value timeToLiveObj = nullptr; - if (napi_has_named_property(env, argv[INTEGER_ZERO], "size", &sizeObj) == napi_ok) { - if (napi_get_named_property(env, argv[INTEGER_ZERO], "size", &sizeObj) != napi_ok) { - WVLOG_E("Failed to get BackForwardCacheOptions size value."); - return result; - } + if (napi_get_named_property(env, argv[INTEGER_ZERO], "size", &sizeObj) != napi_ok) { + WVLOG_E("Failed to get BackForwardCacheOptions size value."); + return result; + } - if (!NapiParseUtils::ParseInt32(env, sizeObj, size)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "size", "int")); - return result; - } + if (!NapiParseUtils::ParseInt32(env, sizeObj, size)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "size", "int")); + return result; } - if (napi_has_named_property(env, argv[INTEGER_ZERO], "timeToLive", &timeToLiveObj) == napi_ok) { - if (napi_get_named_property(env, argv[INTEGER_ZERO], "timeToLive", &timeToLiveObj) != napi_ok) { - WVLOG_E("Failed to get BackForwardCacheOptions timeToLive value."); - return result; - } + if (napi_get_named_property(env, argv[INTEGER_ZERO], "timeToLive", &timeToLiveObj) != napi_ok) { + WVLOG_E("Failed to get BackForwardCacheOptions timeToLive value."); + return result; + } - if (!NapiParseUtils::ParseInt32(env, timeToLiveObj, timeToLive)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "timeToLive", "int")); - return result; - } + if (!NapiParseUtils::ParseInt32(env, timeToLiveObj, timeToLive)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "timeToLive", "int")); + return result; } WebviewController* webviewController = GetWebviewController(env, info); -- Gitee From 92fc5e7e26dd8d197a68a39b38ef56e4bbf455d3 Mon Sep 17 00:00:00 2001 From: xiongjun_gitee Date: Mon, 1 Jul 2024 10:59:09 +0800 Subject: [PATCH 007/126] add ResizeVisibleViewport Signed-off-by: xiongjun_gitee --- ohos_interface/include/ohos_nweb/nweb.h | 9 +++++++++ .../ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp | 6 +++++- .../ohos_nweb/bridge/webcore/ark_web_nweb_impl.h | 11 +++++++++++ .../ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp | 5 +++++ .../ohos_nweb/bridge/webview/ark_web_nweb_wrapper.h | 11 +++++++++++ .../ohos_glue/ohos_nweb/include/ark_web_nweb.h | 10 ++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 14a9fe83..a3019b9d 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -1430,6 +1430,15 @@ 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) {} }; } // namespace OHOS::NWeb 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 6276b5fd..1ccff32b 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,9 @@ 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); +} } // 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 db22e8e3..fff3e1f1 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,16 @@ 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; private: std::shared_ptr nweb_nweb_; }; 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 db4de86e..79fe1cc4 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,9 @@ 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); +} } // 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 454294bb..c2adcd0e 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,16 @@ 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; private: ArkWebRefPtr ark_web_nweb_; }; 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 0bba5011..55dd314b 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,16 @@ 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; }; } // namespace OHOS::ArkWeb -- Gitee From 68a3e02b86951a367b5eab5732690721969e3a3a Mon Sep 17 00:00:00 2001 From: zhushengle Date: Wed, 3 Jul 2024 19:25:26 +0800 Subject: [PATCH 008/126] =?UTF-8?q?feat:=20WebCore=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=85=AC=E7=89=88sysroot=EF=BC=8C=E4=BD=BF=E7=94=A8=E8=83=B6?= =?UTF-8?q?=E6=B0=B4=E5=B1=82=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushengle Change-Id: I933070816ce9f6bcbced405f04cf985644d932f5 --- ohos_interface/ohos_glue/BUILD_webcore.gn | 5 ++++- .../ohos_glue/base/bridge/ark_web_bridge_helper.cpp | 2 ++ ohos_interface/ohos_glue/base/bridge/ark_web_bridge_helper.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ohos_interface/ohos_glue/BUILD_webcore.gn b/ohos_interface/ohos_glue/BUILD_webcore.gn index 9e56406b..34cf21e4 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" ] 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 df9dbaaf..9b835fbb 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 71dbd3ab..75f0818a 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(); -- Gitee From bac9c8178ca72c80c7b635ae7401fdb955687eda Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Wed, 3 Jul 2024 20:59:46 +0800 Subject: [PATCH 009/126] Add interface of bfcache. Signed-off-by: gaojianhao1 --- .../back_forward_cache_options.cpp | 12 ---- .../back_forward_cache_options.h | 6 -- .../napi_back_forward_cache_options.cpp | 56 +------------------ .../napi_webview_controller.cpp | 14 ++--- .../webviewcontroller/webview_controller.h | 1 + ohos_interface/include/ohos_nweb/nweb.h | 10 ++-- .../include/ohos_nweb/nweb_engine.h | 2 - .../bridge/webcore/ark_web_engine_impl.cpp | 5 -- .../bridge/webcore/ark_web_nweb_impl.h | 12 ++-- .../bridge/webview/ark_web_engine_wrapper.cpp | 4 -- .../bridge/webview/ark_web_engine_wrapper.h | 2 - .../bridge/webview/ark_web_nweb_wrapper.h | 12 ++-- .../ohos_nweb/include/ark_web_engine.h | 3 - .../ohos_nweb/include/ark_web_nweb.h | 12 ++-- ohos_nweb/include/nweb_helper.h | 2 - ohos_nweb/src/nweb_helper.cpp | 5 +- .../nweb_helper_test/nweb_helper_test.cpp | 3 + 17 files changed, 35 insertions(+), 126 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp index caac1d11..d8b61a59 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp @@ -28,12 +28,6 @@ BackForwardCacheOptions::BackForwardCacheOptions() WVLOG_D("Created a BackForwardCacheOptions class."); } -BackForwardCacheOptions::BackForwardCacheOptions(int32_t size, int32_t timeToLive) - :size_(size), timeToLive_(timeToLive) -{ - WVLOG_D("Created a BackForwardCacheOptions class. Value size: %{public}d timeToLive: %{public}d.", size_, timeToLive_); -} - int32_t BackForwardCacheOptions::GetSize() { return size_; @@ -49,12 +43,6 @@ BackForwardCacheSupportFeatures::BackForwardCacheSupportFeatures() WVLOG_D("Created a BackForwardCacheSupportFeatures class."); } -BackForwardCacheSupportFeatures::BackForwardCacheSupportFeatures(bool nativeEmbed, bool mediaIntercept) - :nativeEmbed_(nativeEmbed), mediaIntercept_(mediaIntercept) -{ - WVLOG_D("Created a BackForwardCacheSupportFeatures class. Value nativeEmbed: %{public}d mediaIntercept: %{public}d.", nativeEmbed_, mediaIntercept_); -} - bool BackForwardCacheSupportFeatures::IsEnableNativeEmbed() { return nativeEmbed_; diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h index e58e675b..e9eca1d8 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h @@ -28,12 +28,9 @@ namespace NWeb { class BackForwardCacheOptions { public: BackForwardCacheOptions(); - BackForwardCacheOptions(int32_t size, int32_t timeToLive); int32_t GetSize(); int32_t GetTimeToLive(); - napi_ref delegate_ = nullptr; - private: int32_t size_ = 1; int32_t timeToLive_ = 600; @@ -42,12 +39,9 @@ private: class BackForwardCacheSupportFeatures { public: BackForwardCacheSupportFeatures(); - BackForwardCacheSupportFeatures(bool nativeEmbed, bool mediaIntercept); bool IsEnableNativeEmbed(); bool IsEnableMediaIntercept(); - napi_ref delegate_ = nullptr; - private: bool nativeEmbed_ = true; bool mediaIntercept_ = true; diff --git a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp index 875b1290..2751af4c 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp @@ -41,32 +41,7 @@ napi_value NapiBackForwardCacheOptions::JS_Constructor(napi_env env, napi_callba napi_value argv[2] = {0}; napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - BackForwardCacheOptions *options = nullptr; - if (argc == 0) - options = new BackForwardCacheOptions(); - else if (argc == 2) { - int32_t size = 0; - if (!NapiParseUtils::ParseInt32(env, argv[0], size) || (size <= 0 || size > 50)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - "BusinessError: 401. Parameter error. The type of param 'size' must be integer and value between 1 and 50."); - return thisVar; - } - - int32_t timeToLive = 0; - if (!NapiParseUtils::ParseInt32(env, argv[1], timeToLive)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - "BusinessError: 401. Parameter error. The type of param 'timeToLive' must be integer."); - return thisVar; - } - - options = new BackForwardCacheOptions(size, timeToLive); - napi_set_named_property(env, thisVar, "size_", argv[0]); - napi_set_named_property(env, thisVar, "timeToLive_", argv[1]); - } else { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_TWO, "none", "two")); - return thisVar; - } + BackForwardCacheOptions *options = new BackForwardCacheOptions(); napi_wrap( env, thisVar, options, @@ -89,32 +64,7 @@ napi_value NapiBackForwardCacheSupportFeatures::JS_Constructor(napi_env env, nap napi_value argv[2] = {0}; napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - BackForwardCacheSupportFeatures *features = nullptr; - if (argc == 0) - features = new BackForwardCacheSupportFeatures(); - else if (argc == 2) { - bool nativeEmbed = true; - if (!NapiParseUtils::ParseBoolean(env, argv[0], nativeEmbed)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "nativeEmbed", "boolean")); - return thisVar; - } - - bool mediaIntercept = true; - if (!NapiParseUtils::ParseBoolean(env, argv[1], mediaIntercept)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "mediaIntercept", "boolean")); - return thisVar; - } - - features = new BackForwardCacheSupportFeatures(nativeEmbed, mediaIntercept); - napi_set_named_property(env, thisVar, "nativeEmbed_", argv[0]); - napi_set_named_property(env, thisVar, "mediaIntercept_", argv[1]); - } else { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_TWO, "none", "two")); - return thisVar; - } + BackForwardCacheSupportFeatures *features = new BackForwardCacheSupportFeatures(); napi_wrap( env, thisVar, features, @@ -173,7 +123,7 @@ napi_value NapiBackForwardCacheSupportFeatures::Init(napi_env env, napi_value ex WVLOG_D("NapiBackForwardCacheSupportFeatures::Init"); napi_property_descriptor properties[] = { DECLARE_NAPI_FUNCTION("isEnableNativeEmbed", JS_IsEnableNativeEmbed), - DECLARE_NAPI_FUNCTION("isEnableMediaIntercept", JS_IsEnableMediaIntercept), + DECLARE_NAPI_FUNCTION("isEnableMediaTakeOver", JS_IsEnableMediaTakeOver), }; napi_value backForwardCacheSupportFeatures = nullptr; napi_define_class(env, BACK_FORWARD_CACHE_SUPPORT_FEATURES.c_str(), BACK_FORWARD_CACHE_SUPPORT_FEATURES.length(), diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 65fb6b5f..22d27115 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -5510,7 +5510,7 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call if (!NapiParseUtils::ParseBoolean(env, embedObj, nativeEmbed)) { BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "nativeEmbed", "bool")); + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "nativeEmbed", "bool")); return result; } @@ -5521,13 +5521,10 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call if (!NapiParseUtils::ParseBoolean(env, mediaObj, mediaTakeOver)) { BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "mediaTakeOver", "bool")); + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "mediaTakeOver", "bool")); return result; } - WVLOG_I("The value of supported ativeEmbed is: %{public}d", nativeEmbed); - WVLOG_I("The value of supported mediaIntercept is: %{public}d", mediaTakeOver); - NWebHelper::Instance().EnableBackForwardCache(nativeEmbed, mediaTakeOver); NAPI_CALL(env, napi_get_undefined(env, &result)); return result; @@ -5558,7 +5555,7 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ if (!NapiParseUtils::ParseInt32(env, sizeObj, size)) { BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "size", "int")); + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "size", "int")); return result; } @@ -5569,7 +5566,7 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ if (!NapiParseUtils::ParseInt32(env, timeToLiveObj, timeToLive)) { BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYEPS_ERROR, "timeToLive", "int")); + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "timeToLive", "int")); return result; } @@ -5580,9 +5577,6 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ return result; } - WVLOG_I("The value of backforward cache option size is: %{public}d", size); - WVLOG_I("The value of backforward cache option timeToLive is: %{public}d", timeToLive); - webviewController->SetBackForwardCacheOptions(size, timeToLive); NAPI_CALL(env, napi_get_undefined(env, &result)); return result; diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.h b/interfaces/kits/napi/webviewcontroller/webview_controller.h index 687962b8..508d8d16 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.h @@ -370,6 +370,7 @@ public: void SetPathAllowingUniversalAccess(const std::vector& pathList, std::string& errorPath); + void ScrollToWithAnime(float x, float y, int32_t duration) ; void ScrollByWithAnime(float deltaX, float deltaY, int32_t duration) ; diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 1c9bef3a..4702f902 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -1377,11 +1377,6 @@ public: */ virtual void ScrollByWithAnime(float delta_x, float delta_y, int32_t duration) {} - /** - * @brief Set backforward cache options. - */ - virtual void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) { return; } - /** * @brief Send mouse wheel event. */ @@ -1435,6 +1430,11 @@ 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 Set backforward cache options. + */ + virtual void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) { return; } }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 351e5224..41853edc 100644 --- a/ohos_interface/include/ohos_nweb/nweb_engine.h +++ b/ohos_interface/include/ohos_nweb/nweb_engine.h @@ -82,8 +82,6 @@ public: virtual std::shared_ptr GetAdsBlockManager() { return nullptr; }; - - virtual void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) {}; }; } // namespace OHOS::NWeb 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 d94b0c6b..5b55bcb9 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,9 +212,4 @@ ArkWebRefPtr ArkWebEngineImpl::GetAdsBlockManager() } return new ArkWebAdsBlockManagerImpl(nweb_adsBlock_manager); } - -void ArkWebEngineImpl::EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) -{ - nweb_engine_->EnableBackForwardCache(enableNativeEmbed, enableMediaIntercept); -} } // 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 ac1b9431..51b5992d 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 @@ -1212,12 +1212,6 @@ public: /*--ark web()--*/ void ScrollByWithAnime(float delta_x, float delta_y, int32_t duration) override; - /** - * @brief set backforward cache options. - */ - /*--ark web()--*/ - void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) override; - /** * @brief Send mouse wheel event. */ @@ -1272,6 +1266,12 @@ 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 set backforward cache options. + */ + /*--ark web()--*/ + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) 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 b384e5bf..c08317fa 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,8 +240,4 @@ ArkWebEngineWrapper::GetAdsBlockManager() { return std::make_shared(ark_web_adsblock_manager); } - -void ArkWebEngineWrapper::EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) { - ark_web_engine_->EnableBackForwardCache(enableNativeEmbed, enableMediaIntercept); -} } // 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 865d41b8..6400bfcd 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,8 +76,6 @@ public: void EnableWholeWebPageDrawing() override; std::shared_ptr GetAdsBlockManager() override; - - void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) override; private: ArkWebRefPtr ark_web_engine_; }; 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 084049c7..4b6748ce 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 @@ -1220,12 +1220,6 @@ public: /*--ark web()--*/ void ScrollByWithAnime(float delta_x, float delta_y, int32_t duration) override; - /** - * @brief set backforward cache options. - */ - /*--ark web()--*/ - void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) override; - /** * @brief Send mouse wheel event. */ @@ -1281,6 +1275,12 @@ public: const std::vector& async_method_list, const int32_t object_id, const std::string& permission) override; + + /** + * @brief set backforward cache options. + */ + /*--ark web()--*/ + void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) 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 30021b2c..ab6194dc 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,9 +108,6 @@ public: /*--ark web()--*/ virtual ArkWebRefPtr GetAdsBlockManager() = 0; - - /*--ark web()--*/ - virtual void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) = 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 d7a13572..76b15033 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 @@ -1372,12 +1372,6 @@ public: /*--ark web()--*/ virtual void ScrollByWithAnime(float delta_x, float delta_y, int32_t duration) = 0; - /** - * @brief set backforward cache options. - */ - /*--ark web()--*/ - virtual void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) = 0; - /** * @brief Send mouse wheel event. */ @@ -1432,6 +1426,12 @@ 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 set backforward cache options. + */ + /*--ark web()--*/ + virtual void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index e5c7f0f4..b65860d1 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -86,8 +86,6 @@ public: void EnableWholeWebPageDrawing(); std::shared_ptr GetAdsBlockManager(); - void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept); - private: NWebHelper() = default; bool LoadLib(bool from_ark); diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index 74acf808..d51b4520 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -814,7 +814,7 @@ bool NWebHelper::InitAndRun(bool from_ark) if (backForwardCacheCmdLine_.size() != 0) { for (auto backForwardCacheCmdLine : backForwardCacheCmdLine_) { initArgs->AddArg(backForwardCacheCmdLine); - WVLOG_I("Add command line: %{public}s", backForwardCacheCmdLine.c_str()); + WVLOG_I("Add command line when init web engine: %{public}s", backForwardCacheCmdLine.c_str()); } } @@ -1087,15 +1087,12 @@ void NWebHelper::ClearHostIP(const std::string& hostName) void NWebHelper::EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) { this->backForwardCacheCmdLine_.emplace_back("--enable-bfcache"); - WVLOG_I("The value of backForwardCacheCmdLin_ size is %{public}d", this->backForwardCacheCmdLine_.size()); if (enableNativeEmbed) { this->backForwardCacheCmdLine_.emplace_back("--enable-cache-native-embed"); - WVLOG_I("The value of backForwardCacheCmdLin_ size is %{public}d", this->backForwardCacheCmdLine_.size()); } if (enableNativeEmbed) { this->backForwardCacheCmdLine_.emplace_back("--enable-cache-media-intercept"); - WVLOG_I("The value of backForwardCacheCmdLin_ size is %{public}d", this->backForwardCacheCmdLine_.size()); } } diff --git a/test/unittest/nweb_helper_test/nweb_helper_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_test.cpp index 33fcc2ac..2ebb7da7 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(); -- Gitee From f1be1859473dbb902120f98779fdb6a712f40f57 Mon Sep 17 00:00:00 2001 From: tengfan3 Date: Thu, 4 Jul 2024 14:32:37 +0800 Subject: [PATCH 010/126] =?UTF-8?q?=E4=BC=A0=E6=84=9F=E5=99=A8=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=8F=8A=E6=9D=83=E9=99=90=E5=AF=B9=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tengfan3 --- bundle.json | 1 + config.gni | 5 + ohos_adapter/BUILD.gn | 7 + .../include/ohos_adapter_helper_impl.h | 2 + .../src/ohos_adapter_helper_impl.cpp | 12 + .../include/sensor_adapter_impl.h | 58 ++++ .../src/sensor_adapter_impl.cpp | 303 ++++++++++++++++++ ohos_glue/BUILD.gn | 8 + .../ohos_adapter/ohos_adapter_helper.h | 3 + .../include/ohos_adapter/sensor_adapter.h | 65 ++++ .../include/ohos_nweb/nweb_access_request.h | 3 +- ohos_interface/ohos_glue/BUILD_webcore.gn | 8 + .../base/include/ark_web_bridge_types.h | 2 + .../ark_ohos_adapter_helper_wrapper.cpp | 11 + .../webcore/ark_ohos_adapter_helper_wrapper.h | 2 + .../webcore/ark_sensor_adapter_wrapper.cpp | 73 +++++ .../webcore/ark_sensor_adapter_wrapper.h | 45 +++ .../ark_sensor_callback_adapter_impl.cpp | 30 ++ .../ark_sensor_callback_adapter_impl.h | 40 +++ .../webview/ark_ohos_adapter_helper_impl.cpp | 8 +- .../webview/ark_ohos_adapter_helper_impl.h | 2 + .../webview/ark_sensor_adapter_impl.cpp | 73 +++++ .../bridge/webview/ark_sensor_adapter_impl.h | 54 ++++ .../ark_sensor_callback_adapter_wrapper.cpp | 31 ++ .../ark_sensor_callback_adapter_wrapper.h | 38 +++ .../include/ark_ohos_adapter_helper.h | 4 + .../ohos_adapter/include/ark_sensor_adapter.h | 64 ++++ 27 files changed, 950 insertions(+), 2 deletions(-) create mode 100644 ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h create mode 100644 ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp create mode 100644 ohos_interface/include/ohos_adapter/sensor_adapter.h create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_adapter_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_adapter_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_callback_adapter_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_sensor_callback_adapter_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_adapter_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_adapter_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_callback_adapter_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_sensor_callback_adapter_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_adapter/include/ark_sensor_adapter.h diff --git a/bundle.json b/bundle.json index 068d0402..c7c93faf 100644 --- a/bundle.json +++ b/bundle.json @@ -71,6 +71,7 @@ "relational_store", "resource_schedule_service", "samgr", + "sensor", "soc_perf", "time_service", "window_manager", diff --git a/config.gni b/config.gni index cd08c730..84868dae 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/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 22071d4d..7cdb4fc0 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" ] @@ -286,6 +287,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/ohos_adapter_helper/include/ohos_adapter_helper_impl.h b/ohos_adapter/ohos_adapter_helper/include/ohos_adapter_helper_impl.h index 7ca517ce..7bd751b8 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 66b6a8f3..8c429eac 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/sensor_adapter/include/sensor_adapter_impl.h b/ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h new file mode 100644 index 00000000..8d3c78b2 --- /dev/null +++ b/ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h @@ -0,0 +1,58 @@ +/* + * 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; + + 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 00000000..d6f6328f --- /dev/null +++ b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp @@ -0,0 +1,303 @@ +/* + * 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 }, + {8 /* ABSOLUTE_ORIENTATION_EULER_ANGLES}*/, SENSOR_TYPE_ID_ORIENTATION } + }; + 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" }, + {8 /* ABSOLUTE_ORIENTATION_EULER_ANGLES}*/, "OhosOrientationService" } + }; + 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_ORIENTATION: + 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::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: { + AccelData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); + } + break; + } + case SENSOR_TYPE_ID_GRAVITY: { + GravityData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); + } + break; + } + case SENSOR_TYPE_ID_LINEAR_ACCELERATION: { + LinearAccelData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); + } + break; + } + case SENSOR_TYPE_ID_GYROSCOPE: { + GyroscopeData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); + } + break; + } + case SENSOR_TYPE_ID_ORIENTATION: { + OrientationData* data = reinterpret_cast(event->data); + if (data != nullptr) { + callback->UpdateOhosSensorData(event->timestamp, data->beta, data->gamma, data->alpha, 0.0f); + } + break; + } + default: + break; + } +} + +int32_t SensorAdapterImpl::SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) { + WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d, samplingInterval: %{public}lld", + sensorTypeId, samplingInterval); + 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 e4386d88..15f54a18 100644 --- a/ohos_glue/BUILD.gn +++ b/ohos_glue/BUILD.gn @@ -655,6 +655,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", @@ -817,6 +821,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 +941,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/ohos_adapter_helper.h b/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h index 6a82adfe..0b89991c 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 00000000..c3253b0e --- /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_access_request.h b/ohos_interface/include/ohos_nweb/nweb_access_request.h index 703f989f..a41853f4 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/ohos_glue/BUILD_webcore.gn b/ohos_interface/ohos_glue/BUILD_webcore.gn index 9e56406b..c8201e33 100644 --- a/ohos_interface/ohos_glue/BUILD_webcore.gn +++ b/ohos_interface/ohos_glue/BUILD_webcore.gn @@ -647,6 +647,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 +779,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", @@ -919,6 +925,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/include/ark_web_bridge_types.h b/ohos_interface/ohos_glue/base/include/ark_web_bridge_types.h index 7507c246..66af6e05 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,8 @@ 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, /*Note: Only add an enum value before ARK_WEB_BRIDGE_BUTT*/ ARK_WEB_BRIDGE_BUTT 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 45706409..6d4ae170 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 85af3fee..398b8b28 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 00000000..0f1765b9 --- /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 00000000..8db4f15e --- /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 00000000..1714e840 --- /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 00000000..0bca27d8 --- /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/webview/ark_ohos_adapter_helper_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_adapter_helper_impl.cpp index fb8d79ff..e52ff0a7 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 2ab29309..a29b699d 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 00000000..472ef827 --- /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 00000000..f1188031 --- /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 00000000..4d917c67 --- /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 00000000..a30160c2 --- /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_ohos_adapter_helper.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_ohos_adapter_helper.h index edd90eff..61b9e134 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 00000000..32a83406 --- /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 -- Gitee From 608f6a2a83f508b552ea4c644a7d83290725c4d1 Mon Sep 17 00:00:00 2001 From: jidehong Date: Thu, 4 Jul 2024 15:08:14 +0800 Subject: [PATCH 011/126] =?UTF-8?q?openssl/ssl.h=E6=98=BE=E5=BC=8F?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jidehong --- bundle.json | 4 ++-- ohos_adapter/BUILD.gn | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bundle.json b/bundle.json index 068d0402..496eeb4c 100644 --- a/bundle.json +++ b/bundle.json @@ -76,8 +76,8 @@ "window_manager", "netstack", "protobuf", - "libxml2" - + "libxml2", + "openssl" ], "third_party": [ "chromium", diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 2b0e2b7f..6255f152 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -149,6 +149,7 @@ ohos_shared_library("nweb_ohos_adapter") { "samgr:samgr_proxy", "time_service:time_client", "window_manager:libdm", + "openssl" ] if (webview_soc_perf_enable) { -- Gitee From ff9da6a258e20babed88988fafaad8a9ca04be11 Mon Sep 17 00:00:00 2001 From: jidehong Date: Thu, 4 Jul 2024 15:25:58 +0800 Subject: [PATCH 012/126] =?UTF-8?q?openssl/ssl.h=E6=98=BE=E5=BC=8F?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jidehong --- ohos_adapter/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 6255f152..eb9d74d7 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -149,7 +149,7 @@ ohos_shared_library("nweb_ohos_adapter") { "samgr:samgr_proxy", "time_service:time_client", "window_manager:libdm", - "openssl" + "openssl:libssl_shared" ] if (webview_soc_perf_enable) { -- Gitee From cf16a5094a26a17e79adfad3c05dc25341cbf9b6 Mon Sep 17 00:00:00 2001 From: ZhaoPengfei Date: Thu, 4 Jul 2024 15:33:59 +0800 Subject: [PATCH 013/126] =?UTF-8?q?=E5=8F=96=E6=B6=88webview=E9=BB=98?= =?UTF-8?q?=E8=AE=A4120fps=E5=B8=A7=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ZhaoPengfei --- ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp b/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp index 4b79df9c..0a7c3f8e 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; } -- Gitee From cc50784be17cff7c63013b9c8a2b4f513146aaa6 Mon Sep 17 00:00:00 2001 From: zhangyanchuan Date: Tue, 2 Jul 2024 20:47:35 +0800 Subject: [PATCH 014/126] =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=89=98=E7=AE=A1?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=9BBFCache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyanchuan --- .../webviewcontroller/napi_native_media_player.cpp | 10 ++++++---- .../webviewcontroller/native_media_player_impl.cpp | 2 +- .../include/ohos_nweb/nweb_native_media_player.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp b/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp index a49293da..9251d793 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( - "EnterBFCache", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::EnterBFCache))), + DECLARE_NAPI_STATIC_PROPERTY("EnterBackForwardCache", + NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::EnterBackForwardCache))), DECLARE_NAPI_STATIC_PROPERTY( "EnterBackground", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::EnterBackground))), DECLARE_NAPI_STATIC_PROPERTY( - "PausedOverTime", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::PausedOverTime))), + "AutoCleanup", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::AutoCleanup))), }; napi_value enumValue = nullptr; diff --git a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp index ae5aa70a..a0bbf6d4 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/ohos_interface/include/ohos_nweb/nweb_native_media_player.h b/ohos_interface/include/ohos_nweb/nweb_native_media_player.h index 4aa810c1..dffc7eda 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 { EnterBackForwardCache = 0, EnterBackground, AutoCleanup }; enum class NetworkState { EMPTY = 0, IDLE, LOADING, NETWORK_ERROR }; -- Gitee From 07123b2e07797a446dd59903f63bbec91eaeea83 Mon Sep 17 00:00:00 2001 From: lie Date: Thu, 4 Jul 2024 20:01:49 +0800 Subject: [PATCH 015/126] add bfcache status for samelayer Signed-off-by: lie Change-Id: I53e7174efa8622f9fe2ee197e8dbbbb3e89529fb --- ohos_interface/include/ohos_nweb/nweb_handler.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index f27bea9b..459752ea 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 { -- Gitee From b314ef36ee11ee3c145bc673208e4e31dde9dbc5 Mon Sep 17 00:00:00 2001 From: kirby Date: Fri, 5 Jul 2024 10:35:52 +0800 Subject: [PATCH 016/126] ffi fix codecheck Signed-off-by: kirby --- .../webview_javascript_result_callback.h | 2 +- .../webview_javascript_result_callback.cpp | 64 +++++++++---------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/interfaces/kits/cj/include/webview_javascript_result_callback.h b/interfaces/kits/cj/include/webview_javascript_result_callback.h index bc4c5637..1a313945 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/src/webview_javascript_result_callback.cpp b/interfaces/kits/cj/src/webview_javascript_result_callback.cpp index f3ca8d1d..358cbc75 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; } -- Gitee From 96c0160fce97f2048ee974fb40efb79fa82bcad9 Mon Sep 17 00:00:00 2001 From: hwchenhongyu Date: Fri, 5 Jul 2024 02:29:37 +0000 Subject: [PATCH 017/126] change tags to uint Signed-off-by: hwchenhongyu --- ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp b/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp index 27ef05c3..8b9a6b36 100644 --- a/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp +++ b/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp @@ -62,7 +62,7 @@ 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); + uint64_t tags = static_cast(ConvertToInt(enable, 0)); firstAceEnable_ = tags & HITRACE_TAG_ACE; return (tags & HITRACE_TAG_NWEB); } -- Gitee From feabfcc6f0feb0d3c572759ed10f4436d9f9aef5 Mon Sep 17 00:00:00 2001 From: zhengenhao0 Date: Fri, 5 Jul 2024 14:17:42 +0800 Subject: [PATCH 018/126] update NWeb.hap in master to 0705 Signed-off-by: zhengenhao0 --- ohos_nweb/prebuilts/arm/NWeb.hap | 4 ++-- ohos_nweb/prebuilts/arm64/NWeb.hap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_nweb/prebuilts/arm/NWeb.hap b/ohos_nweb/prebuilts/arm/NWeb.hap index ac7f3c56..2916f731 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:98f54394d9240f9a37c4fef8f799fe876aac74a86d70a74eba262ca59931dbda +size 79497971 diff --git a/ohos_nweb/prebuilts/arm64/NWeb.hap b/ohos_nweb/prebuilts/arm64/NWeb.hap index 3ea02155..da5358b4 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:bb1c4bf27de592f9096fcc03d95ac5213ab388d144783ee326df17ac586f59bb +size 90255633 -- Gitee From 2eb396e916e9b5b368f8f65dbf5bb1fd2edcca07 Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Fri, 5 Jul 2024 15:50:20 +0800 Subject: [PATCH 019/126] Add interface enableBackForwardCache and setBackForwardCacheOptions. Signed-off-by: gaojianhao1 --- .../back_forward_cache_options.cpp | 14 +++- .../back_forward_cache_options.h | 10 ++- .../napi_back_forward_cache_options.cpp | 10 +-- .../napi_back_forward_cache_options.h | 2 +- .../napi_webview_controller.cpp | 73 +++++++------------ .../bridge/webcore/ark_web_engine_impl.h | 2 +- ohos_nweb/include/nweb_helper.h | 2 + ohos_nweb/src/nweb_helper.cpp | 12 ++- 8 files changed, 60 insertions(+), 65 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp index d8b61a59..7945a393 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp @@ -38,6 +38,16 @@ int32_t BackForwardCacheOptions::GetTimeToLive() return timeToLive_; } +static int32_t BackForwardCacheOptions::GetDefaultSize() +{ + return default_size_; +} + +static int32_t BackForwardCacheOptions::GetDefaultTimeToLive() +{ + return default_time_to_live_; +} + BackForwardCacheSupportFeatures::BackForwardCacheSupportFeatures() { WVLOG_D("Created a BackForwardCacheSupportFeatures class."); @@ -48,9 +58,9 @@ bool BackForwardCacheSupportFeatures::IsEnableNativeEmbed() return nativeEmbed_; } -bool BackForwardCacheSupportFeatures::IsEnableMediaIntercept() +bool BackForwardCacheSupportFeatures::isEnableMediaTakeOver() { - return mediaIntercept_; + 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 index e9eca1d8..0c54d321 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h @@ -30,21 +30,25 @@ public: BackForwardCacheOptions(); int32_t GetSize(); int32_t GetTimeToLive(); + static int32_t GetDefaultSize(); + static int32_t GetDefaultTimeToLive(); private: int32_t size_ = 1; int32_t timeToLive_ = 600; + int32_t default_size_ = 1; + int32_t default_time_to_live_ = 600; }; class BackForwardCacheSupportFeatures { public: BackForwardCacheSupportFeatures(); bool IsEnableNativeEmbed(); - bool IsEnableMediaIntercept(); + bool isEnableMediaTakeOver(); private: - bool nativeEmbed_ = true; - bool mediaIntercept_ = true; + bool nativeEmbed_ = false; + bool mediaTakeOver_ = false; }; } diff --git a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp index 2751af4c..c43df7d4 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp @@ -80,25 +80,25 @@ napi_value NapiBackForwardCacheSupportFeatures::JS_Constructor(napi_env env, nap napi_value NapiBackForwardCacheOptions::JS_GetSize(napi_env env, napi_callback_info info) { - WVLOG_D("NapiBackForwardCacheOptions::JS_GetSize"); + WVLOG_D("NapiBackForwardCacheOptions::JS_GetSize."); return nullptr; } napi_value NapiBackForwardCacheOptions::JS_GetTimeToLive(napi_env env, napi_callback_info info) { - WVLOG_D("NapiBackForwardCacheOptions::JS_GetTimeToLive"); + WVLOG_D("NapiBackForwardCacheOptions::JS_GetTimeToLive."); return nullptr; } napi_value NapiBackForwardCacheSupportFeatures::JS_IsEnableNativeEmbed(napi_env env, napi_callback_info info) { - WVLOG_D("NapiBackForwardCacheSupportFeatures::JS_IsEnableNativeEmbed"); + WVLOG_D("NapiBackForwardCacheSupportFeatures::JS_IsEnableNativeEmbed."); return nullptr; } -napi_value NapiBackForwardCacheSupportFeatures::JS_IsEnableMediaIntercept(napi_env env, napi_callback_info info) +napi_value NapiBackForwardCacheSupportFeatures::JS_IsEnableMediaTakeOver(napi_env env, napi_callback_info info) { - WVLOG_D("NapiBackForwardCacheSupportFeatures::JS_IsEnableMediaIntercept"); + WVLOG_D("NapiBackForwardCacheSupportFeatures::JS_IsEnableMediaTakeOver."); return nullptr; } diff --git a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h index 41e3d497..68e3eaa5 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h @@ -45,7 +45,7 @@ public: static napi_value Init(napi_env env, napi_value exports); static napi_value JS_Constructor(napi_env env, napi_callback_info info); static napi_value JS_IsEnableNativeEmbed(napi_env env, napi_callback_info info); - static napi_value JS_IsEnableMediaIntercept(napi_env env, napi_callback_info info); + static napi_value JS_IsEnableMediaTakeOver(napi_env env, napi_callback_info info); }; } diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index e676a922..66a2ee97 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -5494,8 +5494,8 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call napi_get_undefined(env, &result); 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")); + NWebHelper::Instance().EnableBackForwardCache(false, false); + NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } @@ -5503,26 +5503,16 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call bool mediaTakeOver = false; napi_value embedObj = nullptr; napi_value mediaObj = nullptr; - if (napi_get_named_property(env, argv[INTEGER_ZERO], "nativeEmbed", &embedObj) != napi_ok) { - WVLOG_E("Failed to get BackForwardCacheOptions nativeEmbed value."); - return result; - } - - if (!NapiParseUtils::ParseBoolean(env, embedObj, nativeEmbed)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "nativeEmbed", "bool")); - return result; + 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) { - WVLOG_E("Failed to get BackForwardCacheOptions mediaTakeOver value."); - return result; - } - - if (!NapiParseUtils::ParseBoolean(env, mediaObj, mediaTakeOver)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "mediaTakeOver", "bool")); - return result; + if (!NapiParseUtils::ParseBoolean(env, mediaObj, mediaTakeOver)) { + mediaTakeOver = false; + } } NWebHelper::Instance().EnableBackForwardCache(nativeEmbed, mediaTakeOver); @@ -5538,9 +5528,17 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ 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("InjectOfflineResource: init webview controller error."); + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); + return result; + } + if (argc != INTEGER_ONE) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "one")); + webviewController->SetBackForwardCacheOptions( + BackForwardCacheOptions::GetDefaultSize(), BackForwardCacheOptions::GetDefaultTimeToLive()); + NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } @@ -5548,33 +5546,16 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ 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) { - WVLOG_E("Failed to get BackForwardCacheOptions size value."); - return result; - } - - if (!NapiParseUtils::ParseInt32(env, sizeObj, size)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "size", "int")); - return result; + if (napi_get_named_property(env, argv[INTEGER_ZERO], "size", &sizeObj) == napi_ok) { + if (!NapiParseUtils::ParseInt32(env, sizeObj, size)) { + size = BackForwardCacheOptions::GetDefaultSize(); + } } - if (napi_get_named_property(env, argv[INTEGER_ZERO], "timeToLive", &timeToLiveObj) != napi_ok) { - WVLOG_E("Failed to get BackForwardCacheOptions timeToLive value."); - return result; - } - - if (!NapiParseUtils::ParseInt32(env, timeToLiveObj, timeToLive)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "timeToLive", "int")); - return result; - } - - WebviewController* webviewController = GetWebviewController(env, info); - if (!webviewController) { - WVLOG_E("InjectOfflineResource: init webview controller error."); - BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); - return result; + if (napi_get_named_property(env, argv[INTEGER_ZERO], "timeToLive", &timeToLiveObj) == napi_ok) { + if (!NapiParseUtils::ParseInt32(env, timeToLiveObj, timeToLive)) { + timeToLive = BackForwardCacheOptions::GetDefaultTimeToLive(); + } } webviewController->SetBackForwardCacheOptions(size, timeToLive); 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 63243ef5..7271bdbb 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,7 +79,7 @@ public: ArkWebRefPtr GetAdsBlockManager() override; - void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) override; + void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaTakeOver) override; private: std::shared_ptr nweb_engine_; diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index b65860d1..5654b55d 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -86,6 +86,8 @@ public: void EnableWholeWebPageDrawing(); std::shared_ptr GetAdsBlockManager(); + void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaTakeOver); + private: NWebHelper() = default; bool LoadLib(bool from_ark); diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index d51b4520..ef78f8f2 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -811,11 +811,9 @@ bool NWebHelper::InitAndRun(bool from_ark) std::string simplifiedLocale = baseLanguage + "-" + systemRegion; initArgs->AddArg(std::string("--lang=").append(simplifiedLocale)); - if (backForwardCacheCmdLine_.size() != 0) { - for (auto backForwardCacheCmdLine : backForwardCacheCmdLine_) { - initArgs->AddArg(backForwardCacheCmdLine); - WVLOG_I("Add command line when init web engine: %{public}s", backForwardCacheCmdLine.c_str()); - } + for (auto backForwardCacheCmdLine : backForwardCacheCmdLine_) { + initArgs->AddArg(backForwardCacheCmdLine); + WVLOG_I("Add command line when init web engine: %{public}s", backForwardCacheCmdLine.c_str()); } nwebEngine_->InitializeWebEngine(initArgs); @@ -1084,7 +1082,7 @@ void NWebHelper::ClearHostIP(const std::string& hostName) nwebEngine_->ClearHostIP(hostName); } -void NWebHelper::EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaIntercept) +void NWebHelper::EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaTakeOver) { this->backForwardCacheCmdLine_.emplace_back("--enable-bfcache"); if (enableNativeEmbed) { @@ -1092,7 +1090,7 @@ void NWebHelper::EnableBackForwardCache(bool enableNativeEmbed, bool enableMedia } if (enableNativeEmbed) { - this->backForwardCacheCmdLine_.emplace_back("--enable-cache-media-intercept"); + this->backForwardCacheCmdLine_.emplace_back("--enable-cache-media-take-over"); } } -- Gitee From b11d75f6166ff9a9d310bb6ebbd875124c896a53 Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Fri, 5 Jul 2024 17:18:23 +0800 Subject: [PATCH 020/126] Add interface. Signed-off-by: gaojianhao1 --- .../common/napi_webview_native_module.cpp | 2 +- .../back_forward_cache_options.cpp | 18 ++---- .../back_forward_cache_options.h | 13 ++-- .../napi_back_forward_cache_options.cpp | 62 +++++-------------- .../napi_back_forward_cache_options.h | 12 ++-- .../napi_webview_controller.cpp | 10 +-- .../bridge/webcore/ark_web_engine_impl.h | 2 - .../nweb_helper_test/nweb_helper_test.cpp | 3 +- 8 files changed, 38 insertions(+), 84 deletions(-) diff --git a/interfaces/kits/napi/common/napi_webview_native_module.cpp b/interfaces/kits/napi/common/napi_webview_native_module.cpp index 00ad3d24..40478420 100644 --- a/interfaces/kits/napi/common/napi_webview_native_module.cpp +++ b/interfaces/kits/napi/common/napi_webview_native_module.cpp @@ -53,7 +53,7 @@ static napi_value WebViewExport(napi_env env, napi_value exports) WebFunctionInit(env, exports); NapiNativeMediaPlayerHandler::Init(env, exports); NapiBackForwardCacheOptions::Init(env, exports); - NapiBackForwardCacheSupportFeatures::Init(env, exports); + NapiBackForwardCacheSupportedFeatures::Init(env, exports); return exports; } EXTERN_C_END diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp index 7945a393..f6fcbb15 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.cpp @@ -38,27 +38,17 @@ int32_t BackForwardCacheOptions::GetTimeToLive() return timeToLive_; } -static int32_t BackForwardCacheOptions::GetDefaultSize() +BackForwardCacheSupportedFeatures::BackForwardCacheSupportedFeatures() { - return default_size_; + WVLOG_D("Created a BackForwardCacheSupportedFeatures class."); } -static int32_t BackForwardCacheOptions::GetDefaultTimeToLive() -{ - return default_time_to_live_; -} - -BackForwardCacheSupportFeatures::BackForwardCacheSupportFeatures() -{ - WVLOG_D("Created a BackForwardCacheSupportFeatures class."); -} - -bool BackForwardCacheSupportFeatures::IsEnableNativeEmbed() +bool BackForwardCacheSupportedFeatures::IsEnableNativeEmbed() { return nativeEmbed_; } -bool BackForwardCacheSupportFeatures::isEnableMediaTakeOver() +bool BackForwardCacheSupportedFeatures::IsEnableMediaTakeOver() { return mediaTakeOver_; } diff --git a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h index 0c54d321..e11da84d 100644 --- a/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h +++ b/interfaces/kits/napi/webviewcontroller/back_forward_cache_options.h @@ -23,6 +23,9 @@ #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 { @@ -30,21 +33,17 @@ public: BackForwardCacheOptions(); int32_t GetSize(); int32_t GetTimeToLive(); - static int32_t GetDefaultSize(); - static int32_t GetDefaultTimeToLive(); private: int32_t size_ = 1; int32_t timeToLive_ = 600; - int32_t default_size_ = 1; - int32_t default_time_to_live_ = 600; }; -class BackForwardCacheSupportFeatures { +class BackForwardCacheSupportedFeatures { public: - BackForwardCacheSupportFeatures(); + BackForwardCacheSupportedFeatures(); bool IsEnableNativeEmbed(); - bool isEnableMediaTakeOver(); + bool IsEnableMediaTakeOver(); private: bool nativeEmbed_ = false; diff --git a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp index c43df7d4..f149c600 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.cpp @@ -55,21 +55,21 @@ napi_value NapiBackForwardCacheOptions::JS_Constructor(napi_env env, napi_callba return thisVar; } -napi_value NapiBackForwardCacheSupportFeatures::JS_Constructor(napi_env env, napi_callback_info info) +napi_value NapiBackForwardCacheSupportedFeatures::JS_Constructor(napi_env env, napi_callback_info info) { - WVLOG_I("NapiBackForwardCacheSupportFeatures::JS_Constructor is called"); + 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); - BackForwardCacheSupportFeatures *features = new BackForwardCacheSupportFeatures(); + BackForwardCacheSupportedFeatures *features = new BackForwardCacheSupportedFeatures(); napi_wrap( env, thisVar, features, [](napi_env /* env */, void *data, void * /* hint */) { - BackForwardCacheSupportFeatures *features = (BackForwardCacheSupportFeatures *)data; + BackForwardCacheSupportedFeatures *features = (BackForwardCacheSupportedFeatures *)data; delete features; features = nullptr; }, @@ -78,59 +78,27 @@ napi_value NapiBackForwardCacheSupportFeatures::JS_Constructor(napi_env env, nap return thisVar; } -napi_value NapiBackForwardCacheOptions::JS_GetSize(napi_env env, napi_callback_info info) -{ - WVLOG_D("NapiBackForwardCacheOptions::JS_GetSize."); - return nullptr; -} - -napi_value NapiBackForwardCacheOptions::JS_GetTimeToLive(napi_env env, napi_callback_info info) -{ - WVLOG_D("NapiBackForwardCacheOptions::JS_GetTimeToLive."); - return nullptr; -} - -napi_value NapiBackForwardCacheSupportFeatures::JS_IsEnableNativeEmbed(napi_env env, napi_callback_info info) -{ - WVLOG_D("NapiBackForwardCacheSupportFeatures::JS_IsEnableNativeEmbed."); - return nullptr; -} - -napi_value NapiBackForwardCacheSupportFeatures::JS_IsEnableMediaTakeOver(napi_env env, napi_callback_info info) -{ - WVLOG_D("NapiBackForwardCacheSupportFeatures::JS_IsEnableMediaTakeOver."); - return nullptr; -} - napi_value NapiBackForwardCacheOptions::Init(napi_env env, napi_value exports) { WVLOG_D("NapiBackForwardCacheOptions::Init"); - napi_property_descriptor properties[] = { - DECLARE_NAPI_FUNCTION("getSize", JS_GetSize), - DECLARE_NAPI_FUNCTION("getTimeToLive", JS_GetTimeToLive), - }; napi_value backForwardCacheOptions = nullptr; - napi_define_class(env, BACK_FORWARD_CACHE_OPTIONS.c_str(), BACK_FORWARD_CACHE_OPTIONS.length(), - JS_Constructor, nullptr, - sizeof(properties) / sizeof(properties[0]), properties, &backForwardCacheOptions); + 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 NapiBackForwardCacheSupportFeatures::Init(napi_env env, napi_value exports) +napi_value NapiBackForwardCacheSupportedFeatures::Init(napi_env env, napi_value exports) { - WVLOG_D("NapiBackForwardCacheSupportFeatures::Init"); - napi_property_descriptor properties[] = { - DECLARE_NAPI_FUNCTION("isEnableNativeEmbed", JS_IsEnableNativeEmbed), - DECLARE_NAPI_FUNCTION("isEnableMediaTakeOver", JS_IsEnableMediaTakeOver), - }; - napi_value backForwardCacheSupportFeatures = nullptr; - napi_define_class(env, BACK_FORWARD_CACHE_SUPPORT_FEATURES.c_str(), BACK_FORWARD_CACHE_SUPPORT_FEATURES.length(), - JS_Constructor, nullptr, - sizeof(properties) / sizeof(properties[0]), properties, &backForwardCacheSupportFeatures); - napi_set_named_property(env, exports, BACK_FORWARD_CACHE_SUPPORT_FEATURES.c_str(), - backForwardCacheSupportFeatures); + 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; } diff --git a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h index 68e3eaa5..2d04145c 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h +++ b/interfaces/kits/napi/webviewcontroller/napi_back_forward_cache_options.h @@ -24,7 +24,7 @@ namespace OHOS { namespace NWeb { const std::string BACK_FORWARD_CACHE_OPTIONS = "BackForwardCacheOptions"; -const std::string BACK_FORWARD_CACHE_SUPPORT_FEATURES = "BackForwardCacheSupportFeatures"; +const std::string BACK_FORWARD_CACHE_SUPPORTED_FEATURES = "BackForwardCacheSupportedFeatures"; class NapiBackForwardCacheOptions { public: @@ -33,19 +33,15 @@ public: static napi_value Init(napi_env env, napi_value exports); static napi_value JS_Constructor(napi_env env, napi_callback_info info); - static napi_value JS_GetSize(napi_env env, napi_callback_info info); - static napi_value JS_GetTimeToLive(napi_env env, napi_callback_info info); }; -class NapiBackForwardCacheSupportFeatures { +class NapiBackForwardCacheSupportedFeatures { public: - NapiBackForwardCacheSupportFeatures() = default; - ~NapiBackForwardCacheSupportFeatures() = default; + 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); - static napi_value JS_IsEnableNativeEmbed(napi_env env, napi_callback_info info); - static napi_value JS_IsEnableMediaTakeOver(napi_env env, napi_callback_info info); }; } diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 66a2ee97..87ec385a 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -5494,6 +5494,7 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call 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; @@ -5530,14 +5531,15 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); WebviewController* webviewController = GetWebviewController(env, info); if (!webviewController) { - WVLOG_E("InjectOfflineResource: init webview controller error."); + 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( - BackForwardCacheOptions::GetDefaultSize(), BackForwardCacheOptions::GetDefaultTimeToLive()); + BFCACHE_DEFAULT_SIZE, BFCACHE_DEFAULT_TIMETOLIVE); NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } @@ -5548,13 +5550,13 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ napi_value timeToLiveObj = nullptr; if (napi_get_named_property(env, argv[INTEGER_ZERO], "size", &sizeObj) == napi_ok) { if (!NapiParseUtils::ParseInt32(env, sizeObj, size)) { - size = BackForwardCacheOptions::GetDefaultSize(); + size = BFCACHE_DEFAULT_SIZE; } } if (napi_get_named_property(env, argv[INTEGER_ZERO], "timeToLive", &timeToLiveObj) == napi_ok) { if (!NapiParseUtils::ParseInt32(env, timeToLiveObj, timeToLive)) { - timeToLive = BackForwardCacheOptions::GetDefaultTimeToLive(); + timeToLive = BFCACHE_DEFAULT_TIMETOLIVE; } } 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 7271bdbb..28236ab7 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,8 +79,6 @@ public: ArkWebRefPtr GetAdsBlockManager() override; - void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaTakeOver) override; - private: std::shared_ptr nweb_engine_; }; diff --git a/test/unittest/nweb_helper_test/nweb_helper_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_test.cpp index 2ebb7da7..51d27e0f 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_test.cpp @@ -144,7 +144,7 @@ public: return nullptr; } - void EnableBackForwardCache(bool nativeEmbed, bool mediaTakeOver); + void EnableBackForwardCache(bool nativeEmbed, bool mediaTakeOver) {} }; void NwebHelperTest::SetUpTestCase(void) @@ -328,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); -- Gitee From edf7fa1c12aea31b522070fd464b4f6727fbc80a Mon Sep 17 00:00:00 2001 From: zhangyanchuan Date: Mon, 8 Jul 2024 10:59:20 +0800 Subject: [PATCH 021/126] =?UTF-8?q?=E4=BF=AE=E6=94=B9so=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=BA=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyanchuan --- .../bridge/webcore/ark_web_adapter_bridge_helper.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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 bec20dfb..1180d736 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 -- Gitee From 1decc31279e47af4cbf451600bb6a7ee4ed5e6b0 Mon Sep 17 00:00:00 2001 From: abc12133 Date: Fri, 5 Jul 2024 15:17:35 +0800 Subject: [PATCH 022/126] add autofill interface Signed-off-by: abc12133 --- ohos_interface/include/ohos_nweb/nweb.h | 12 +++++ .../include/ohos_nweb/nweb_autofill.h | 53 +++++++++++++++++++ .../bridge/webcore/ark_web_nweb_impl.cpp | 15 ++++++ .../bridge/webcore/ark_web_nweb_impl.h | 14 +++++ .../bridge/webview/ark_web_nweb_wrapper.cpp | 16 ++++++ .../bridge/webview/ark_web_nweb_wrapper.h | 14 +++++ .../ohos_nweb/include/ark_web_nweb.h | 14 +++++ 7 files changed, 138 insertions(+) create mode 100644 ohos_interface/include/ohos_nweb/nweb_autofill.h diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index a3019b9d..857b4083 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -1439,6 +1439,18 @@ public: * @param iskeyboard from keybord. */ virtual void ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) {} + + /** + * @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_autofill.h b/ohos_interface/include/ohos_nweb/nweb_autofill.h new file mode 100644 index 00000000..fde1e7fa --- /dev/null +++ b/ohos_interface/include/ohos_nweb/nweb_autofill.h @@ -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. + */ + +#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_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_NAME = "name"; +const std::string NWEB_AUTOFILL_NICKNAME = "nickname"; +const std::string NWEB_AUTOFILL_EMAIL = "email"; +const std::string NWEB_AUTOFILL_STREET_ADDRESS = "street-address"; +const std::string NWEB_AUTOFILL_ID_CARD_NUMBER = "id-card-number"; +const std::string NWEB_AUTOFILL_TEL_NATIONAL = "tel-national"; + +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/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 1ccff32b..3733848f 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 @@ -1112,4 +1112,19 @@ void ArkWebNWebImpl::ResizeVisibleViewport(uint32_t width, uint32_t height, bool { nweb_nweb_->ResizeVisibleViewport(width, height, isKeyboard); } + +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 fff3e1f1..936ec594 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 @@ -1277,6 +1277,20 @@ public: */ /*--ark web()--*/ void ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) 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_nweb_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp index 79fe1cc4..568c4d89 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 @@ -1309,4 +1309,20 @@ void ArkWebNWebWrapper::ResizeVisibleViewport(uint32_t width, uint32_t height, b { ark_web_nweb_->ResizeVisibleViewport(width, height, isKeyboard); } + +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 c2adcd0e..b5605cf4 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 @@ -1286,6 +1286,20 @@ public: */ /*--ark web()--*/ void ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) 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_nweb.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_nweb.h index 55dd314b..9578b335 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 @@ -1436,6 +1436,20 @@ public: */ /*--ark web()--*/ virtual void ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) = 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 -- Gitee From bcaca0d0e95b83c8bcc4f3b84770c71fd8a74499 Mon Sep 17 00:00:00 2001 From: zhangshengfeng Date: Mon, 8 Jul 2024 14:33:22 +0800 Subject: [PATCH 023/126] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangshengfeng --- interfaces/kits/napi/js/webview_export.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/napi/js/webview_export.js b/interfaces/kits/napi/js/webview_export.js index 872b6e5c..d71c3d6e 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); -- Gitee From d12862a617d45ffef3950ad2d61452ca63de7880 Mon Sep 17 00:00:00 2001 From: zgit2021 Date: Fri, 5 Jul 2024 17:22:08 +0800 Subject: [PATCH 024/126] adapt to customDialog's keyboard avoid Signed-off-by: zgit2021 Change-Id: I8f44ebf6a49be0159480064cb4c127ecfd0adacd --- .../src/imf_adapter_impl.cpp | 10 +++++++--- ohos_interface/include/ohos_adapter/imf_adapter.h | 10 ++++++++++ ohos_interface/include/ohos_nweb/nweb_handler.h | 8 ++++++++ .../webcore/ark_imf_text_config_adapter_impl.cpp | 9 +++++++++ .../bridge/webcore/ark_imf_text_config_adapter_impl.h | 4 ++++ .../webview/ark_imftext_config_adapter_wrapper.cpp | 9 +++++++++ .../webview/ark_imftext_config_adapter_wrapper.h | 4 ++++ .../ohos_glue/ohos_adapter/include/ark_imf_adapter.h | 6 ++++++ .../bridge/webcore/ark_web_handler_wrapper.cpp | 5 +++++ .../ohos_nweb/bridge/webcore/ark_web_handler_wrapper.h | 3 +++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.cpp | 5 +++++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.h | 3 +++ .../ohos_glue/ohos_nweb/include/ark_web_handler.h | 9 +++++++++ 13 files changed, 82 insertions(+), 3 deletions(-) diff --git a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp index e2b5bc8f..4d832a19 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_interface/include/ohos_adapter/imf_adapter.h b/ohos_interface/include/ohos_adapter/imf_adapter.h index 5aa58b69..fca87684 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_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index 459752ea..21214671 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -966,6 +966,14 @@ 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) {} }; } // namespace OHOS::NWeb 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 b1fbadd3..54d23bc9 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 2fa22142..1d6762f0 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/webview/ark_imftext_config_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_config_adapter_wrapper.cpp index 61ef624f..af7aa231 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 6f03508c..b7121b0d 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/include/ark_imf_adapter.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_imf_adapter.h index 0bd54640..415dd5a2 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_nweb/bridge/webcore/ark_web_handler_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.cpp index 6e6c298a..7cd66db5 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,9 @@ 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); +} } // 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 7e5ad0c6..9ac67292 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,9 @@ 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; + private: ArkWebRefPtr ark_web_handler_; }; 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 580d80a5..14693cd4 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,9 @@ 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); +} } // 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 c9a0edae..42707294 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,9 @@ public: void OnCustomKeyboardClose() override; void OnAdsBlocked(const ArkWebString &url, const ArkWebStringVector &adsBlocked) override; + + void OnCursorUpdate(double x, double y, double width, double height) override; + private: std::shared_ptr nweb_handler_; }; 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 b17fc6b5..b9352634 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,15 @@ 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; }; } // namespace OHOS::ArkWeb -- Gitee From 883ae653895f519e8af98382cda3975de2012009 Mon Sep 17 00:00:00 2001 From: Wanpucheng Date: Mon, 8 Jul 2024 19:10:54 +0800 Subject: [PATCH 025/126] =?UTF-8?q?=E8=A7=A3=E5=86=B3ArkWeb=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=BC=A9=E8=BF=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Wanpucheng --- ohos_nweb/include/nweb_init_params.h | 306 +++++++++++++++------------ 1 file changed, 170 insertions(+), 136 deletions(-) diff --git a/ohos_nweb/include/nweb_init_params.h b/ohos_nweb/include/nweb_init_params.h index 8cfe711d..9f1b2374 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; -- Gitee From d2a67d87e60f8cc81d5071bea5a5e835f782c198 Mon Sep 17 00:00:00 2001 From: zhangyanchuan Date: Tue, 9 Jul 2024 14:40:54 +0800 Subject: [PATCH 026/126] =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=89=98=E7=AE=A1?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=9BBFCache(=E5=90=8C=E6=AD=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=8E=A5=E5=8F=A3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyanchuan --- .../napi/webviewcontroller/napi_native_media_player.cpp | 8 ++++---- .../include/ohos_nweb/nweb_native_media_player.h | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp b/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp index 9251d793..17ca2f7c 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_native_media_player.cpp @@ -178,12 +178,12 @@ napi_status NapiNativeMediaPlayerHandler::ExportEnumSuspendType(napi_env env, na const std::string NPI_SUSPEND_TYPE_ENUM_NAME = "SuspendType"; napi_property_descriptor properties[] = { - DECLARE_NAPI_STATIC_PROPERTY("EnterBackForwardCache", - NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::EnterBackForwardCache))), + DECLARE_NAPI_STATIC_PROPERTY("ENTER_BACK_FORWARD_CACHE", + NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::ENTER_BACK_FORWARD_CACHE))), 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( - "AutoCleanup", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::AutoCleanup))), + "AUTO_CLEANUP", NapiParseUtils::ToInt32Value(env, static_cast(SuspendType::AUTO_CLEANUP))), }; napi_value enumValue = nullptr; 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 dffc7eda..c3bd0075 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,14 @@ 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 { EnterBackForwardCache = 0, EnterBackground, AutoCleanup }; +enum class SuspendType { + ENTER_BACK_FORWARD_CACHE = 0, + ENTER_BACKGROUND, + AUTO_CLEANUP, + EnterBackForwardCache = 0, + EnterBackground, + AutoCleanup +}; enum class NetworkState { EMPTY = 0, IDLE, LOADING, NETWORK_ERROR }; -- Gitee From b797bae1c5a72547bf15c43a23aca5d38ae53cdd Mon Sep 17 00:00:00 2001 From: zhangyanchuan Date: Tue, 9 Jul 2024 16:11:08 +0800 Subject: [PATCH 027/126] =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=89=98=E7=AE=A1?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=9BBFCache(=E5=90=8C=E6=AD=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=8E=A5=E5=8F=A3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyanchuan --- .../include/ohos_nweb/nweb_native_media_player.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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 c3bd0075..609d9a6b 100644 --- a/ohos_interface/include/ohos_nweb/nweb_native_media_player.h +++ b/ohos_interface/include/ohos_nweb/nweb_native_media_player.h @@ -31,14 +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 { - ENTER_BACK_FORWARD_CACHE = 0, - ENTER_BACKGROUND, - AUTO_CLEANUP, - EnterBackForwardCache = 0, - EnterBackground, - AutoCleanup -}; +enum class SuspendType { ENTER_BACK_FORWARD_CACHE = 0, ENTER_BACKGROUND, AUTO_CLEANUP }; enum class NetworkState { EMPTY = 0, IDLE, LOADING, NETWORK_ERROR }; -- Gitee From a1973f14752f073a8a79f3d2a2d7c27acc6f71eb Mon Sep 17 00:00:00 2001 From: tengfan3 Date: Tue, 9 Jul 2024 23:29:24 +0800 Subject: [PATCH 028/126] =?UTF-8?q?=E4=BC=A0=E6=84=9F=E5=99=A8=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=EF=BC=8C=E8=BF=BD=E5=8A=A0=E4=BC=A0=E6=84=9F=E5=99=A8?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tengfan3 --- .../include/sensor_adapter_impl.h | 17 ++ .../src/sensor_adapter_impl.cpp | 213 ++++++++++++++---- 2 files changed, 180 insertions(+), 50 deletions(-) diff --git a/ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h b/ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h index 8d3c78b2..319e3cb9 100644 --- a/ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h +++ b/ohos_adapter/sensor_adapter/include/sensor_adapter_impl.h @@ -51,6 +51,23 @@ 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{}; }; diff --git a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp index d6f6328f..e244a577 100644 --- a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp +++ b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp @@ -26,14 +26,18 @@ std::unordered_map> SensorAdapterIm constexpr double NANOSECONDS_IN_SECOND = 1000000000.0; constexpr double DEFAULT_SAMPLE_PERIOD = 200000000.0; -SensorTypeId SensorTypeToOhosSensorType(int sensorTypeId) { +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 }, - {8 /* ABSOLUTE_ORIENTATION_EULER_ANGLES}*/, SENSOR_TYPE_ID_ORIENTATION } + {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()) { @@ -42,13 +46,17 @@ SensorTypeId SensorTypeToOhosSensorType(int sensorTypeId) { return ohosSensorTypeId; } -std::string SensorTypeToSensorUserName(int sensorTypeId) { +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" }, - {8 /* ABSOLUTE_ORIENTATION_EULER_ANGLES}*/, "OhosOrientationService" } + {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); @@ -60,17 +68,19 @@ std::string SensorTypeToSensorUserName(int sensorTypeId) { SensorCallbackImpl::SensorCallbackImpl( std::shared_ptr callbackAdapter) - : callbackAdapter_(callbackAdapter) { -} + : callbackAdapter_(callbackAdapter) +{} void SensorCallbackImpl::UpdateOhosSensorData(double timestamp, - double value1, double value2, double value3, double value4) { + 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 SensorAdapterImpl::IsOhosSensorSupported(int32_t sensorTypeId) +{ int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); if (ohosSensorTypeId != SENSOR_TYPE_ID_NONE) { SensorInfo* sensorInfo = nullptr; @@ -92,7 +102,8 @@ int32_t SensorAdapterImpl::IsOhosSensorSupported(int32_t sensorTypeId) { return SENSOR_ERROR; } -int32_t SensorAdapterImpl::GetOhosSensorReportingMode(int32_t sensorTypeId) { +int32_t SensorAdapterImpl::GetOhosSensorReportingMode(int32_t sensorTypeId) +{ int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); int32_t reportingMode = -1; switch (ohosSensorTypeId) { @@ -100,7 +111,10 @@ int32_t SensorAdapterImpl::GetOhosSensorReportingMode(int32_t sensorTypeId) { 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: @@ -109,7 +123,8 @@ int32_t SensorAdapterImpl::GetOhosSensorReportingMode(int32_t sensorTypeId) { return reportingMode; } -double SensorAdapterImpl::GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) { +double SensorAdapterImpl::GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) +{ int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); double defaultFrequency = 0.0; if (ohosSensorTypeId != SENSOR_TYPE_ID_NONE) { @@ -120,7 +135,8 @@ double SensorAdapterImpl::GetOhosSensorDefaultSupportedFrequency(int32_t sensorT return defaultFrequency; } -double SensorAdapterImpl::GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) { +double SensorAdapterImpl::GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) +{ int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); double minFrequency = 0.0; if (ohosSensorTypeId == SENSOR_TYPE_ID_NONE) { @@ -148,7 +164,8 @@ double SensorAdapterImpl::GetOhosSensorMinSupportedFrequency(int32_t sensorTypeI return minFrequency; } -double SensorAdapterImpl::GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) { +double SensorAdapterImpl::GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) +{ int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); double maxFrequency = 0.0; if (ohosSensorTypeId == SENSOR_TYPE_ID_NONE) { @@ -176,60 +193,154 @@ double SensorAdapterImpl::GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeI return maxFrequency; } -void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) { +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; + callback = findIter->second; } if ((event == nullptr) || (callback == nullptr)) { WVLOG_E("OhosSensorCallback Error."); return; } switch (event->sensorTypeId) { - case SENSOR_TYPE_ID_ACCELEROMETER: { - AccelData* data = reinterpret_cast(event->data); - if (data != nullptr) { - callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); - } + case SENSOR_TYPE_ID_ACCELEROMETER: + handleAccelerometerData(callback, event); break; - } - case SENSOR_TYPE_ID_GRAVITY: { - GravityData* data = reinterpret_cast(event->data); - if (data != nullptr) { - callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); - } + case SENSOR_TYPE_ID_GRAVITY: + handleGravityData(callback, event); break; - } - case SENSOR_TYPE_ID_LINEAR_ACCELERATION: { - LinearAccelData* data = reinterpret_cast(event->data); - if (data != nullptr) { - callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); - } + case SENSOR_TYPE_ID_LINEAR_ACCELERATION: + handleLinearAccelerometerData(callback, event); break; - } - case SENSOR_TYPE_ID_GYROSCOPE: { - GyroscopeData* data = reinterpret_cast(event->data); - if (data != nullptr) { - callback->UpdateOhosSensorData(event->timestamp, data->x, data->y, data->z, 0.0f); - } + case SENSOR_TYPE_ID_GYROSCOPE: + handleCyroscopeData(callback, event); break; - } - case SENSOR_TYPE_ID_ORIENTATION: { - OrientationData* data = reinterpret_cast(event->data); - if (data != nullptr) { - callback->UpdateOhosSensorData(event->timestamp, data->beta, data->gamma, data->alpha, 0.0f); - } + 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, samplingInterval: %{public}lld", - sensorTypeId, samplingInterval); +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; @@ -269,7 +380,8 @@ int32_t SensorAdapterImpl::SubscribeOhosSensor(int32_t sensorTypeId, int64_t sam } int32_t SensorAdapterImpl::RegistOhosSensorCallback(int32_t sensorTypeId, - std::shared_ptr callbackAdapter) { + std::shared_ptr callbackAdapter) +{ int32_t ohosSensorTypeId = SensorTypeToOhosSensorType(sensorTypeId); if (ohosSensorTypeId != SENSOR_TYPE_ID_NONE) { auto callback = std::make_shared(callbackAdapter); @@ -280,7 +392,8 @@ int32_t SensorAdapterImpl::RegistOhosSensorCallback(int32_t sensorTypeId, return SENSOR_PARAMETER_ERROR; } -int32_t SensorAdapterImpl::UnsubscribeOhosSensor(int32_t sensorTypeId) { +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) { -- Gitee From a48b66b92540b99a016c206b68adf7f37554183c Mon Sep 17 00:00:00 2001 From: cxcxfan Date: Tue, 9 Jul 2024 22:06:06 +0800 Subject: [PATCH 029/126] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E4=B8=A2=E5=B8=A7?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cxcxfan --- ohos_interface/include/ohos_nweb/nweb_handler.h | 2 ++ .../ohos_nweb/bridge/webcore/ark_web_handler_wrapper.cpp | 5 +++++ .../ohos_nweb/bridge/webcore/ark_web_handler_wrapper.h | 2 ++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.cpp | 5 +++++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.h | 2 ++ .../ohos_glue/ohos_nweb/include/ark_web_handler.h | 8 ++++++++ 6 files changed, 24 insertions(+) diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index 459752ea..796f28be 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -966,6 +966,8 @@ public: * */ virtual void OnAdsBlocked(const std::string& url, const std::vector& adsBlocked) {} + + virtual void ReportDynamicFrameLossEvent(const std::string& sceneId, bool isStart) {} }; } // namespace OHOS::NWeb 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 6e6c298a..b97225a6 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,9 @@ void ArkWebHandlerWrapper::OnAdsBlocked( ArkWebStringVectorStructRelease(stAdsBlocked); ArkWebStringStructRelease(stUrl); } + +void ArkWebHandlerWrapper::ReportDynamicFrameLossEvent(const std::string& sceneId, bool isStart) +{ + ark_web_handler_->ReportDynamicFrameLossEvent(ArkWebStringClassToStruct(sceneId), isStart); +} } // 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 7e5ad0c6..07854481 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,8 @@ public: void OnCustomKeyboardClose() override; void OnAdsBlocked(const std::string &url, const std::vector &adsBlocked) 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/webview/ark_web_handler_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.cpp index 580d80a5..c36a95d1 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,9 @@ void ArkWebHandlerImpl::OnAdsBlocked(const ArkWebString &url, const ArkWebString nweb_handler_->OnAdsBlocked(ArkWebStringStructToClass(url), ArkWebStringVectorStructToClass(adsBlocked)); } + +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 c9a0edae..de13b3ed 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,8 @@ public: void OnCustomKeyboardClose() override; void OnAdsBlocked(const ArkWebString &url, const ArkWebStringVector &adsBlocked) override; + + void ReportDynamicFrameLossEvent(const ArkWebString& sceneId, bool isStart) override; private: std::shared_ptr nweb_handler_; }; 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 b17fc6b5..86d8144b 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,14 @@ public: */ /*--ark web()--*/ virtual void OnAdsBlocked(const ArkWebString &url, const ArkWebStringVector &adsBlocked) = 0; + + /** + * @brief Report dynamic frame loss event. + * + * @param isStart true if is start. + */ + /*--ark web()--*/ + virtual void ReportDynamicFrameLossEvent(const ArkWebString& sceneId, bool isStart) = 0; }; } // namespace OHOS::ArkWeb -- Gitee From b377185863f98c1d5387aca8f89b64053246fbeb Mon Sep 17 00:00:00 2001 From: tengfan Date: Tue, 9 Jul 2024 21:45:47 +0800 Subject: [PATCH 030/126] trim memory by pressure level Signed-off-by: tengfan --- .../napi_webview_controller.cpp | 43 +++++++++++++++++++ .../napi_webview_controller.h | 3 ++ .../webviewcontroller/webview_controller.h | 5 +++ .../include/ohos_nweb/nweb_engine.h | 2 + .../bridge/webcore/ark_web_engine_impl.cpp | 5 +++ .../bridge/webcore/ark_web_engine_impl.h | 2 + .../bridge/webview/ark_web_engine_wrapper.cpp | 5 +++ .../bridge/webview/ark_web_engine_wrapper.h | 2 + .../ohos_nweb/include/ark_web_engine.h | 3 ++ ohos_nweb/include/nweb_helper.h | 2 + ohos_nweb/src/nweb_helper.cpp | 10 +++++ 11 files changed, 82 insertions(+) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 87ec385a..c2de4111 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -529,6 +529,8 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) 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(), @@ -712,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; } @@ -6172,5 +6186,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 5877ee94..5a0c1ae9 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; @@ -352,6 +353,8 @@ private: 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/webview_controller.h b/interfaces/kits/napi/webviewcontroller/webview_controller.h index 508d8d16..58764995 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.h @@ -117,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: diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 41853edc..616b166f 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/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 5b55bcb9..ecc4dba4 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 28236ab7..b883c699 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/webview/ark_web_engine_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.cpp index c08317fa..5c26e075 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 6400bfcd..ec6ea672 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/include/ark_web_engine.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h index ab6194dc..3208fffd 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_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index 5654b55d..d09266bd 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -88,6 +88,8 @@ public: void EnableBackForwardCache(bool enableNativeEmbed, bool enableMediaTakeOver); + void TrimMemoryByPressureLevel(int32_t memoryLevel); + private: NWebHelper() = default; bool LoadLib(bool from_ark); diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index ef78f8f2..d2d633f0 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -1133,6 +1133,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; -- Gitee From 6c37b14fa234169db8215f9b964426fe3490fec9 Mon Sep 17 00:00:00 2001 From: echoorchid Date: Mon, 8 Jul 2024 15:30:30 +0800 Subject: [PATCH 031/126] add log for OnActive and OnInactive Signed-off-by: echoorchid --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 87ec385a..cdb2288e 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -1152,11 +1152,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; } @@ -1166,11 +1167,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; } -- Gitee From ad66eb63044fae2dd98fe89e3a0074d4fe732639 Mon Sep 17 00:00:00 2001 From: kirby Date: Wed, 10 Jul 2024 14:08:46 +0800 Subject: [PATCH 032/126] fix null ptr err Signed-off-by: kirby --- interfaces/kits/cj/src/web_cookie_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/cj/src/web_cookie_manager.cpp b/interfaces/kits/cj/src/web_cookie_manager.cpp index 5810abfc..8956d29d 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; -- Gitee From 532daa7fbb4cf4053985cb305be4e8a22343417f Mon Sep 17 00:00:00 2001 From: zhengenhao0 Date: Wed, 10 Jul 2024 15:05:59 +0800 Subject: [PATCH 033/126] update NWeb.hap in master to 0710 Signed-off-by: zhengenhao0 --- ohos_nweb/prebuilts/arm/NWeb.hap | 4 ++-- ohos_nweb/prebuilts/arm64/NWeb.hap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_nweb/prebuilts/arm/NWeb.hap b/ohos_nweb/prebuilts/arm/NWeb.hap index 2916f731..e1f086df 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:98f54394d9240f9a37c4fef8f799fe876aac74a86d70a74eba262ca59931dbda -size 79497971 +oid sha256:683b1427ef008ab1046561128138933a52d3188709659fbe34b60c7e921156f2 +size 122977436 diff --git a/ohos_nweb/prebuilts/arm64/NWeb.hap b/ohos_nweb/prebuilts/arm64/NWeb.hap index da5358b4..e82ba550 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:bb1c4bf27de592f9096fcc03d95ac5213ab388d144783ee326df17ac586f59bb -size 90255633 +oid sha256:f7063bd3158146f488df3794da6148cf24a9c74deb56293a31499c664e03d512 +size 190665927 -- Gitee From d7c73bc2f970706f555928d239a0c8df9a721a3b Mon Sep 17 00:00:00 2001 From: LXinJie Date: Wed, 10 Jul 2024 17:45:15 +0800 Subject: [PATCH 034/126] liuxinjie6@huawei.com Signed-off-by: LXinJie --- .../src/aafwk_render_scheduler_impl.cpp | 2 +- .../include/hitrace_adapter_impl.h | 7 ---- .../src/hitrace_adapter_impl.cpp | 32 ++++++++----------- .../nweb_aafwk_adapter_test.cpp | 2 ++ .../hiviewdfx_adapter_test/BUILD.gn | 1 + .../hiviewdfx_adapter_test.cpp | 12 +++---- 6 files changed, 24 insertions(+), 32 deletions(-) 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 c4785d8e..d95ea28d 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/hiviewdfx_adapter/include/hitrace_adapter_impl.h b/ohos_adapter/hiviewdfx_adapter/include/hitrace_adapter_impl.h index 227957c6..97cde921 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 8b9a6b36..62faf1a0 100644 --- a/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp +++ b/ohos_adapter/hiviewdfx_adapter/src/hitrace_adapter_impl.cpp @@ -63,46 +63,42 @@ bool HiTraceAdapterImpl::IsHiTraceEnable() int changed = 0; const char *enable = CachedParameterGetChanged(g_Handle, &changed); uint64_t tags = static_cast(ConvertToInt(enable, 0)); - firstAceEnable_ = tags & HITRACE_TAG_ACE; 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/test/unittest/aafwk_app_client_adapter/nweb_aafwk_adapter_test.cpp b/test/unittest/aafwk_app_client_adapter/nweb_aafwk_adapter_test.cpp index 6cc55f1d..abddfdb8 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/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn b/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn index e36c4bce..68f70db2 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 8b27bc9c..08bfbc64 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(); -- Gitee From d83d31b4604192692d7c79d98df7108e3652a42f Mon Sep 17 00:00:00 2001 From: zhaodan_123 Date: Thu, 11 Jul 2024 10:21:09 +0800 Subject: [PATCH 035/126] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=9A=E8=BF=87Gui?= =?UTF-8?q?d=E8=8E=B7=E5=8F=96ItemState=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaodan_123 Change-Id: Ib712ef8df0f475f1ba0ad3e00d6f6b970b80e2a6 Signed-off-by: zhaodan_123 --- .../napi/webviewcontroller/napi_web_download_item.cpp | 9 +++++---- ohos_nweb/include/nweb_c_api.h | 2 ++ ohos_nweb/src/nweb_helper.cpp | 11 ++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_web_download_item.cpp b/interfaces/kits/napi/webviewcontroller/napi_web_download_item.cpp index 0c9742d5..a912fbdf 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/ohos_nweb/include/nweb_c_api.h b/ohos_nweb/include/nweb_c_api.h index 91ddad02..933770ed 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/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index d2d633f0..432995c8 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) { -- Gitee From b880bdb1930b2e236fc4c177575cd1e8838f4c36 Mon Sep 17 00:00:00 2001 From: jidehong Date: Thu, 11 Jul 2024 20:58:57 +0800 Subject: [PATCH 036/126] =?UTF-8?q?openssl/ssl.h=E6=98=BE=E5=BC=8F?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jidehong --- ohos_adapter/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index eb9d74d7..003f6c53 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -149,7 +149,7 @@ ohos_shared_library("nweb_ohos_adapter") { "samgr:samgr_proxy", "time_service:time_client", "window_manager:libdm", - "openssl:libssl_shared" + "openssl:libssl_shared", ] if (webview_soc_perf_enable) { -- Gitee From b97b13e32104390db400acf25e6d00a4c4e5e970 Mon Sep 17 00:00:00 2001 From: jidehong Date: Fri, 12 Jul 2024 10:16:23 +0800 Subject: [PATCH 037/126] =?UTF-8?q?openssl/ssl.h=E6=98=BE=E5=BC=8F?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jidehong --- ohos_adapter/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 003f6c53..249ec11a 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -143,13 +143,13 @@ 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", "samgr:samgr_proxy", "time_service:time_client", "window_manager:libdm", - "openssl:libssl_shared", ] if (webview_soc_perf_enable) { -- Gitee From c8db7da92409bb6aeb83f6bd9d2eae06e461227b Mon Sep 17 00:00:00 2001 From: jidehong Date: Sat, 13 Jul 2024 16:29:40 +0800 Subject: [PATCH 038/126] =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E7=BC=96=E8=AF=91?= =?UTF-8?q?=EF=BC=8Ces2abc=5Fconfig.gni=E6=96=87=E4=BB=B6=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jidehong --- interfaces/kits/napi/js/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/napi/js/BUILD.gn b/interfaces/kits/napi/js/BUILD.gn index 6eea6350..8ea861dd 100644 --- a/interfaces/kits/napi/js/BUILD.gn +++ b/interfaces/kits/napi/js/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") +import("//build/config/components/ets_frontend/es2abc_config.gni") import("//build/ohos.gni") es2abc_gen_abc("gen_webview_export_abc") { -- Gitee From 09b2e6857be4d53615f0b4f4161797826adbd491 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 13 Jul 2024 23:33:47 +0800 Subject: [PATCH 039/126] web log Signed-off-by: unknown --- ohos_interface/ohos_glue/base/include/ark_web_log_utils.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 164ff908..f2bf1b2e 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__) -- Gitee From a62110d9d25608a6126ffc5bd332f688922e6747 Mon Sep 17 00:00:00 2001 From: abc12133 Date: Mon, 15 Jul 2024 14:27:33 +0800 Subject: [PATCH 040/126] add extra autofill type Signed-off-by: abc12133 --- ohos_interface/include/ohos_nweb/nweb_autofill.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ohos_interface/include/ohos_nweb/nweb_autofill.h b/ohos_interface/include/ohos_nweb/nweb_autofill.h index f84a0c6e..8dbff39d 100644 --- a/ohos_interface/include/ohos_nweb/nweb_autofill.h +++ b/ohos_interface/include/ohos_nweb/nweb_autofill.h @@ -26,20 +26,28 @@ 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_NICKNAME = "nickname"; +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_STREET_ADDRESS = "street-address"; +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_TEL_NATIONAL = "tel-national"; +const std::string NWEB_AUTOFILL_NICKNAME = "nickname"; enum NWebAutofillEvent { UNKNOWN = 0, -- Gitee From 1f5c918f8d91901115ea09bbb4a0e0e8b9a1f321 Mon Sep 17 00:00:00 2001 From: wuxinzao Date: Mon, 15 Jul 2024 16:02:16 +0800 Subject: [PATCH 041/126] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86image=20deco?= =?UTF-8?q?de=E6=8E=A5=E5=8F=A3=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuxinzao --- bundle.json | 1 + .../ohos_adapter/ohos_image_adapter/BUILD.gn | 50 +++ .../ohos_image_decoder_adapter_test.cpp | 406 ++++++++++++++++++ 3 files changed, 457 insertions(+) create mode 100644 test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn create mode 100644 test/unittest/ohos_adapter/ohos_image_adapter/ohos_image_decoder_adapter_test.cpp diff --git a/bundle.json b/bundle.json index 2165b09f..4e86bbfc 100644 --- a/bundle.json +++ b/bundle.json @@ -262,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/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn b/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn new file mode 100644 index 00000000..54dffc3b --- /dev/null +++ b/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2022 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_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 00000000..5a645152 --- /dev/null +++ b/test/unittest/ohos_adapter/ohos_image_adapter/ohos_image_decoder_adapter_test.cpp @@ -0,0 +1,406 @@ +/* + * Copyright (c) 2022 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 "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/sample1.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; +} +} // 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 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); + bool 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) +{ + size_t bufferSize = 0; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + 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); + + bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + EXPECT_TRUE(ret); + + int32_t Fd = imageDecoderAdapterImpl.GetFd(); + EXPECT_NE(Fd, -1); + + free(buffer); +} + +/** + * @tc.name: OhosImageAdapterTest_GetStride_007 + * @tc.desc: GetStride. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetStride_007, TestSize.Level1) +{ + size_t bufferSize = 0; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + 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); + + bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + EXPECT_TRUE(ret); + + int32_t stride = imageDecoderAdapterImpl.GetStride(); + EXPECT_NE(stride, 0); + + free(buffer); +} + +/** + * @tc.name: OhosImageAdapterTest_GetOffset_008 + * @tc.desc: GetOffset. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetOffset_008, TestSize.Level1) +{ + size_t bufferSize = 0; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + 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); + + bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + EXPECT_TRUE(ret); + + int32_t offset = imageDecoderAdapterImpl.GetOffset(); + EXPECT_EQ(offset, 0); + + free(buffer); +} + +/** + * @tc.name: OhosImageAdapterTest_GetSize_009 + * @tc.desc: GetSize. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetSize_009, TestSize.Level1) +{ + size_t bufferSize = 0; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + 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); + + bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + EXPECT_TRUE(ret); + + uint64_t size = imageDecoderAdapterImpl.GetSize(); + EXPECT_NE(size, 0); + + free(buffer); +} + +/** + * @tc.name: OhosImageAdapterTest_GetNativeWindowBuffer_010 + * @tc.desc: GetNativeWindowBuffer. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetNativeWindowBuffer_010, TestSize.Level1) +{ + size_t bufferSize = 0; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + 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); + + bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + EXPECT_TRUE(ret); + + void* offset = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + EXPECT_NE(offset, nullptr); + + free(buffer); +} + + +/** + * @tc.name: OhosImageAdapterTest_GetPlanesCount_011 + * @tc.desc: GetPlanesCount. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetPlanesCount_011, TestSize.Level1) +{ + size_t bufferSize = 0; + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + + 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); + + bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + EXPECT_TRUE(ret); + + int32_t planesCount = imageDecoderAdapterImpl.GetPlanesCount(); + EXPECT_EQ(planesCount, 0); + + free(buffer); +} + +} // namespace NWeb +} // namespace OHOS -- Gitee From 8dd3af42e34de639e420bc89dcb9791106a5a945 Mon Sep 17 00:00:00 2001 From: j00466033 Date: Mon, 15 Jul 2024 17:14:28 +0800 Subject: [PATCH 042/126] =?UTF-8?q?adblock=20tdd=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: j00466033 --- .../nweb_helper_test/nweb_helper_test.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/unittest/nweb_helper_test/nweb_helper_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_test.cpp index 51d27e0f..4c3db95c 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_test.cpp @@ -475,6 +475,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); @@ -497,6 +499,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; @@ -604,12 +608,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 } -- Gitee From db49a788bfc3a38542086195209ba8ea6873664e Mon Sep 17 00:00:00 2001 From: wuxinzao Date: Mon, 15 Jul 2024 17:20:18 +0800 Subject: [PATCH 043/126] =?UTF-8?q?=E6=A3=80=E8=A7=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuxinzao --- test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn | 2 +- .../ohos_image_adapter/ohos_image_decoder_adapter_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn b/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn index 54dffc3b..ffce0550 100644 --- a/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn +++ b/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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 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 index 5a645152..9b06a23e 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 -- Gitee From fe2bd40ff8d61f46c191efa40bdc9b78b1a52b88 Mon Sep 17 00:00:00 2001 From: zhengenhao0 Date: Tue, 16 Jul 2024 14:47:58 +0800 Subject: [PATCH 044/126] update NWeb.hap in master to 0716 Signed-off-by: zhengenhao0 --- ohos_nweb/prebuilts/arm/NWeb.hap | 4 ++-- ohos_nweb/prebuilts/arm64/NWeb.hap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_nweb/prebuilts/arm/NWeb.hap b/ohos_nweb/prebuilts/arm/NWeb.hap index e1f086df..74bbe176 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:683b1427ef008ab1046561128138933a52d3188709659fbe34b60c7e921156f2 -size 122977436 +oid sha256:5a65a26b648b94c2b2083d104e50c792396ff6f5f35c9d4c1f0e7556bed4233b +size 122936924 diff --git a/ohos_nweb/prebuilts/arm64/NWeb.hap b/ohos_nweb/prebuilts/arm64/NWeb.hap index e82ba550..f003dfd7 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:f7063bd3158146f488df3794da6148cf24a9c74deb56293a31499c664e03d512 -size 190665927 +oid sha256:3169d53d1d80bdd38c769c14b40948c9c771bac4e2e1523eff7f2bf9762da93e +size 190643577 -- Gitee From 5445af47238b61644a6ab0527c7399b6e8b39651 Mon Sep 17 00:00:00 2001 From: wuxinzao Date: Tue, 16 Jul 2024 15:56:34 +0800 Subject: [PATCH 045/126] =?UTF-8?q?=E6=A3=80=E8=A7=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuxinzao --- .../include/ohos_image_decoder_adapter_impl.h | 1 + .../ohos_adapter/ohos_image_adapter/BUILD.gn | 5 +- .../ohos_image_decoder_adapter_test.cpp | 197 +++++++++++++----- 3 files changed, 147 insertions(+), 56 deletions(-) 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 4e8af4e6..f520112b 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/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn b/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn index ffce0550..ba7d1c9d 100644 --- a/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn +++ b/test/unittest/ohos_adapter/ohos_image_adapter/BUILD.gn @@ -18,7 +18,10 @@ module_output_path = "web/webview" config("module_private_config") { visibility = [ ":*" ] - include_dirs = [ "../../../../ohos_adapter/ohos_image_adapter/include" ] + 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") { 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 index 9b06a23e..02e60fef 100644 --- 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 @@ -20,6 +20,7 @@ #include #define private public +#include "pixel_map.h" #include "directory_ex.h" #include "image_source.h" #include "image_utils.h" @@ -34,7 +35,7 @@ namespace OHOS { namespace NWeb { namespace { -static const std::string IMAGE_FILE_PATH = "/data/local/tmp/sample1.heic"; +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) { @@ -79,7 +80,7 @@ bool TestInitImage(OhosImageDecoderAdapterImpl &imageDecoderAdapterImpl, uint8_t size_t bufferSize = 0; bool boolRes = Media::ImageUtils::GetFileSize(IMAGE_FILE_PATH, bufferSize); if (!boolRes) { - return false; + return false; } buffer = static_cast(malloc(bufferSize)); @@ -100,6 +101,33 @@ bool TestInitImage(OhosImageDecoderAdapterImpl &imageDecoderAdapterImpl, uint8_t } 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 { @@ -227,13 +255,17 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_DecodeToPixelMap_005, TestSi 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); - bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + + ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); EXPECT_TRUE(ret); free(buffer); @@ -247,23 +279,26 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_DecodeToPixelMap_005, TestSi */ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetFd_006, TestSize.Level1) { - size_t bufferSize = 0; + uint8_t *buffer = nullptr; OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; - bool boolRes = Media::ImageUtils::GetFileSize(IMAGE_FILE_PATH, bufferSize); + int32_t fd = imageDecoderAdapterImpl.GetFd(); + EXPECT_EQ(fd, -1); - uint8_t *buffer = static_cast(malloc(bufferSize)); - - boolRes = ReadFileToBuffer(IMAGE_FILE_PATH, buffer, bufferSize); - EXPECT_TRUE(boolRes); - - bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); EXPECT_TRUE(ret); - int32_t Fd = imageDecoderAdapterImpl.GetFd(); - EXPECT_NE(Fd, -1); + fd = imageDecoderAdapterImpl.GetFd(); + EXPECT_NE(fd, -1); + + auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + pixelMap->FreePixelMap(); + fd = imageDecoderAdapterImpl.GetFd(); + EXPECT_EQ(fd, -1); free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); } /** @@ -274,23 +309,26 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetFd_006, TestSize.Level1) */ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetStride_007, TestSize.Level1) { - size_t bufferSize = 0; + uint8_t *buffer = nullptr; OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; - 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); + int32_t stride = imageDecoderAdapterImpl.GetStride(); + EXPECT_EQ(stride, 0); - bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); EXPECT_TRUE(ret); - int32_t stride = imageDecoderAdapterImpl.GetStride(); + stride = imageDecoderAdapterImpl.GetStride(); EXPECT_NE(stride, 0); + auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + pixelMap->FreePixelMap(); + stride = imageDecoderAdapterImpl.GetStride(); + EXPECT_EQ(stride, 0); + free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); } /** @@ -301,23 +339,26 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetStride_007, TestSize.Leve */ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetOffset_008, TestSize.Level1) { - size_t bufferSize = 0; + uint8_t *buffer = nullptr; OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; - 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); + int32_t offset = imageDecoderAdapterImpl.GetOffset(); + EXPECT_EQ(offset, 0); - bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); EXPECT_TRUE(ret); - int32_t offset = imageDecoderAdapterImpl.GetOffset(); + offset = imageDecoderAdapterImpl.GetOffset(); + EXPECT_EQ(offset, 0); + + auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + pixelMap->FreePixelMap(); + offset = imageDecoderAdapterImpl.GetOffset(); EXPECT_EQ(offset, 0); free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); } /** @@ -328,23 +369,26 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetOffset_008, TestSize.Leve */ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetSize_009, TestSize.Level1) { - size_t bufferSize = 0; + uint8_t *buffer = nullptr; OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; - 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); + uint64_t size = imageDecoderAdapterImpl.GetSize(); + EXPECT_EQ(size, 0); - bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); EXPECT_TRUE(ret); - uint64_t size = imageDecoderAdapterImpl.GetSize(); + size = imageDecoderAdapterImpl.GetSize(); EXPECT_NE(size, 0); + auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + pixelMap->FreePixelMap(); + size = imageDecoderAdapterImpl.GetSize(); + EXPECT_EQ(size, 0); + free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); } /** @@ -355,23 +399,26 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetSize_009, TestSize.Level1 */ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetNativeWindowBuffer_010, TestSize.Level1) { - size_t bufferSize = 0; + uint8_t *buffer = nullptr; OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; - 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); + void* offset = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + EXPECT_EQ(offset, nullptr); - bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); EXPECT_TRUE(ret); - void* offset = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + offset = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + EXPECT_NE(offset, nullptr); + + auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + pixelMap->FreePixelMap(); + offset = imageDecoderAdapterImpl.GetNativeWindowBuffer(); EXPECT_NE(offset, nullptr); free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); } @@ -383,23 +430,63 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetNativeWindowBuffer_010, T */ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetPlanesCount_011, TestSize.Level1) { - size_t bufferSize = 0; + uint8_t *buffer = nullptr; OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; - bool boolRes = Media::ImageUtils::GetFileSize(IMAGE_FILE_PATH, bufferSize); + int32_t planesCount = imageDecoderAdapterImpl.GetPlanesCount(); + EXPECT_EQ(planesCount, 0); - uint8_t *buffer = static_cast(malloc(bufferSize)); + 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); - bool ret = imageDecoderAdapterImpl.DecodeToPixelMap(buffer, bufferSize); + ret = imageDecoderAdapterImpl.Decode(buffer, bufferSize, AllocatorType::kDmaAlloc, true); EXPECT_TRUE(ret); - int32_t planesCount = imageDecoderAdapterImpl.GetPlanesCount(); - EXPECT_EQ(planesCount, 0); + ret = imageDecoderAdapterImpl.Decode(buffer, bufferSize, AllocatorType::kDmaAlloc, false); + EXPECT_TRUE(ret); free(buffer); + + imageDecoderAdapterImpl.ReleasePixelMap(); } } // namespace NWeb -- Gitee From a5ff3c9f53f1cf2cb6572aabcf2473ccfa4bbd96 Mon Sep 17 00:00:00 2001 From: wuxinzao Date: Tue, 16 Jul 2024 16:26:16 +0800 Subject: [PATCH 046/126] =?UTF-8?q?=E6=A3=80=E8=A7=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuxinzao --- .../include/ohos_image_decoder_adapter_impl.h | 2 +- .../ohos_image_decoder_adapter_test.cpp | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) 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 f520112b..02e5125c 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,7 +50,7 @@ public: void* GetNativeWindowBuffer() override; int32_t GetPlanesCount() override; void ReleasePixelMap() override; - Media::PixelMap* getPixelMap() { return pixelMap_.get(); }; + Media::PixelMap* GetPixelMap() { return pixelMap_.get(); } private: Media::ImageInfo imageInfo_; 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 index 02e60fef..1c6b78a1 100644 --- 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 @@ -291,7 +291,7 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetFd_006, TestSize.Level1) fd = imageDecoderAdapterImpl.GetFd(); EXPECT_NE(fd, -1); - auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); pixelMap->FreePixelMap(); fd = imageDecoderAdapterImpl.GetFd(); EXPECT_EQ(fd, -1); @@ -321,7 +321,7 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetStride_007, TestSize.Leve stride = imageDecoderAdapterImpl.GetStride(); EXPECT_NE(stride, 0); - auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); pixelMap->FreePixelMap(); stride = imageDecoderAdapterImpl.GetStride(); EXPECT_EQ(stride, 0); @@ -351,7 +351,7 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetOffset_008, TestSize.Leve offset = imageDecoderAdapterImpl.GetOffset(); EXPECT_EQ(offset, 0); - auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); pixelMap->FreePixelMap(); offset = imageDecoderAdapterImpl.GetOffset(); EXPECT_EQ(offset, 0); @@ -381,7 +381,7 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetSize_009, TestSize.Level1 size = imageDecoderAdapterImpl.GetSize(); EXPECT_NE(size, 0); - auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); pixelMap->FreePixelMap(); size = imageDecoderAdapterImpl.GetSize(); EXPECT_EQ(size, 0); @@ -402,19 +402,19 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetNativeWindowBuffer_010, T uint8_t *buffer = nullptr; OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; - void* offset = imageDecoderAdapterImpl.GetNativeWindowBuffer(); - EXPECT_EQ(offset, nullptr); + void* windowBuffer = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + EXPECT_EQ(windowBuffer, nullptr); bool ret = TestDecodeImage(imageDecoderAdapterImpl, buffer); EXPECT_TRUE(ret); - offset = imageDecoderAdapterImpl.GetNativeWindowBuffer(); - EXPECT_NE(offset, nullptr); + windowBuffer = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + EXPECT_NE(windowBuffer, nullptr); - auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); pixelMap->FreePixelMap(); - offset = imageDecoderAdapterImpl.GetNativeWindowBuffer(); - EXPECT_NE(offset, nullptr); + windowBuffer = imageDecoderAdapterImpl.GetNativeWindowBuffer(); + EXPECT_NE(windowBuffer, nullptr); free(buffer); @@ -442,7 +442,7 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetPlanesCount_011, TestSize planesCount = imageDecoderAdapterImpl.GetPlanesCount(); EXPECT_EQ(planesCount, 0); - auto* pixelMap = imageDecoderAdapterImpl.getPixelMap(); + auto* pixelMap = imageDecoderAdapterImpl.GetPixelMap(); pixelMap->FreePixelMap(); planesCount = imageDecoderAdapterImpl.GetPlanesCount(); EXPECT_EQ(planesCount, 0); -- Gitee From ce6c7deb9c3c0dcb00a048797f6991c9c8831f53 Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Tue, 16 Jul 2024 23:21:45 +0800 Subject: [PATCH 047/126] Fix BFCache Bug. Signed-off-by: gaojianhao1 --- ohos_nweb/src/nweb_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index 432995c8..a50af0d3 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -1098,7 +1098,7 @@ void NWebHelper::EnableBackForwardCache(bool enableNativeEmbed, bool enableMedia this->backForwardCacheCmdLine_.emplace_back("--enable-cache-native-embed"); } - if (enableNativeEmbed) { + if (enableMediaTakeOver) { this->backForwardCacheCmdLine_.emplace_back("--enable-cache-media-take-over"); } } -- Gitee From 22098f2c5e9ea1186c301c00d8cc31b8d2b42c26 Mon Sep 17 00:00:00 2001 From: zhaodan_123 Date: Tue, 16 Jul 2024 19:15:05 +0800 Subject: [PATCH 048/126] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96Ite?= =?UTF-8?q?mState=E7=9A=84ttd=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7f0e0b2d74719c7cd0dbe27bef44c7f27a7b64b8 Signed-off-by: zhaodan_123 --- test/unittest/nweb_helper_test/nweb_helper_test.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/unittest/nweb_helper_test/nweb_helper_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_test.cpp index 4c3db95c..756abd93 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_test.cpp @@ -442,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); @@ -457,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); } /** -- Gitee From 9abccc22aee0a16b99be0e0fb61614d0629d17de Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Mon, 8 Jul 2024 03:05:56 +0000 Subject: [PATCH 049/126] Issue: https://gitee.com/openharmony/ability_ability_base/issues/IAB0NZ?from=project-issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comment: 消除ability_ability_base中all_dependent_configs Signed-off-by: jiangzhijun8 --- ohos_adapter/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 98fac467..ff1ee11c 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -109,7 +109,6 @@ ohos_shared_library("nweb_ohos_adapter") { external_deps = [ "ability_base:extractortool", - "ability_base:want", "ability_base:zuri", "ability_runtime:ability_manager", "ability_runtime:abilitykit_native", @@ -151,6 +150,7 @@ ohos_shared_library("nweb_ohos_adapter") { "time_service:time_client", "window_manager:libdm", ] + public_external_deps = [ "ability_base:want" ] if (webview_soc_perf_enable) { external_deps += [ "soc_perf:socperf_client" ] -- Gitee From 563fb999662186db48854c1b36690c49f9c3f91e Mon Sep 17 00:00:00 2001 From: xushawly Date: Wed, 17 Jul 2024 14:43:23 +0800 Subject: [PATCH 050/126] =?UTF-8?q?=E7=BD=91=E7=BB=9C=E5=8F=91=E7=94=9F?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E6=97=B6=E5=B0=86=E7=BD=91=E7=BB=9C=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BC=A0=E5=88=B0=E5=86=85=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xushawly Change-Id: I9bc392253f750ef2a44e6165cab5b33b477c5fab Signed-off-by: xushawly --- ohos_adapter/BUILD.gn | 2 + .../include/net_capabilities_adapter_impl.h | 49 ++++++++++++++++++ .../net_connection_properties_adapter_impl.h | 39 +++++++++++++++ .../src/net_capabilities_adapter_impl.cpp | 50 +++++++++++++++++++ .../src/net_connect_callback_impl.cpp | 2 +- ...net_connection_properties_adapter_impl.cpp | 30 +++++++++++ ohos_glue/BUILD.gn | 8 +++ .../ohos_adapter/net_connect_adapter.h | 22 ++++++++ ohos_interface/ohos_glue/BUILD_webcore.gn | 8 +++ .../base/include/ark_web_bridge_types.h | 2 + .../ark_net_capabilities_adapter_wrapper.cpp | 38 ++++++++++++++ .../ark_net_capabilities_adapter_wrapper.h | 41 +++++++++++++++ .../webcore/ark_net_conn_callback_impl.cpp | 26 ++++++++++ .../webcore/ark_net_conn_callback_impl.h | 6 +++ ..._connection_properties_adapter_wrapper.cpp | 28 +++++++++++ ...et_connection_properties_adapter_wrapper.h | 37 ++++++++++++++ .../ark_net_capabilities_adapter_impl.cpp | 38 ++++++++++++++ .../ark_net_capabilities_adapter_impl.h | 43 ++++++++++++++++ .../webview/ark_net_conn_callback_wrapper.cpp | 22 ++++++++ .../webview/ark_net_conn_callback_wrapper.h | 4 ++ ...net_connection_properties_adapter_impl.cpp | 29 +++++++++++ ...k_net_connection_properties_adapter_impl.h | 39 +++++++++++++++ .../include/ark_net_connect_adapter.h | 28 +++++++++++ .../net_connect_adapter_impl_test.cpp | 10 ++++ .../net_connect_callback_impl_test.cpp | 10 ++++ 25 files changed, 610 insertions(+), 1 deletion(-) create mode 100644 ohos_adapter/net_connect_adapter/include/net_capabilities_adapter_impl.h create mode 100644 ohos_adapter/net_connect_adapter/include/net_connection_properties_adapter_impl.h create mode 100644 ohos_adapter/net_connect_adapter/src/net_capabilities_adapter_impl.cpp create mode 100644 ohos_adapter/net_connect_adapter/src/net_connection_properties_adapter_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_capabilities_adapter_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_capabilities_adapter_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_connection_properties_adapter_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_net_connection_properties_adapter_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_capabilities_adapter_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_capabilities_adapter_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_connection_properties_adapter_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_net_connection_properties_adapter_impl.h diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 2b044fca..80246774 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -245,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", 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 00000000..c53b9526 --- /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 00000000..c453e8e1 --- /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 00000000..0d63e0ea --- /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 ded4a479..a3dd17ca 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 00000000..340aa4aa --- /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_glue/BUILD.gn b/ohos_glue/BUILD.gn index 15f54a18..df67451d 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", @@ -777,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", diff --git a/ohos_interface/include/ohos_adapter/net_connect_adapter.h b/ohos_interface/include/ohos_adapter/net_connect_adapter.h index 64c9f798..6920cc34 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/ohos_glue/BUILD_webcore.gn b/ohos_interface/ohos_glue/BUILD_webcore.gn index 5d6803d7..87ff0a23 100644 --- a/ohos_interface/ohos_glue/BUILD_webcore.gn +++ b/ohos_interface/ohos_glue/BUILD_webcore.gn @@ -595,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", @@ -884,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", 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 66af6e05..ee115fa4 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 @@ -245,6 +245,8 @@ enum ArkWebBridgeType { 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/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 00000000..71ed0cf4 --- /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 00000000..a7fdd7f5 --- /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 17c2e6bc..fc76257a 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 4287d40f..7c9bc9f1 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 00000000..9d9f88b2 --- /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 00000000..80287efb --- /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/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 00000000..999fc701 --- /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 00000000..a9f60eff --- /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 f23a6c97..89ac8d56 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 78975cec..03539aa9 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 00000000..a80f77d9 --- /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 00000000..fd1d7570 --- /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/include/ark_net_connect_adapter.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_net_connect_adapter.h index 13c9ae78..295be126 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/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 6c7d65a9..0f06a309 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 65cb4712..878cfdd9 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; + } }; /** -- Gitee From 0e394495a3ff2edaee5dde46c915e29c0742240b Mon Sep 17 00:00:00 2001 From: xushawly Date: Fri, 19 Jul 2024 11:58:28 +0800 Subject: [PATCH 051/126] =?UTF-8?q?=E4=BF=AE=E6=AD=A3ArkNetCapabilitiesAda?= =?UTF-8?q?pterWrapper=E7=B1=BB=E7=9A=84NetConnectType=E5=92=8CNetConnectS?= =?UTF-8?q?ubtype=E7=B1=BB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xushawly Change-Id: I87fa42e0081a6ff868a4b6cc54f0be877dddc132 Signed-off-by: xushawly --- .../webcore/ark_net_capabilities_adapter_wrapper.cpp | 8 ++++---- .../bridge/webcore/ark_net_capabilities_adapter_wrapper.h | 4 ++-- .../bridge/webview/ark_net_capabilities_adapter_impl.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) 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 index 71ed0cf4..6f3bc6da 100644 --- 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 @@ -25,14 +25,14 @@ int32_t ArkNetCapabilitiesAdapterWrapper::GetNetId() return ctocpp_->GetNetId(); } -OHOS::NWeb::ConnectType ArkNetCapabilitiesAdapterWrapper::GetConnectType() +OHOS::NWeb::NetConnectType ArkNetCapabilitiesAdapterWrapper::GetConnectType() { - return static_cast(ctocpp_->GetConnectType()); + return static_cast(ctocpp_->GetConnectType()); } -OHOS::NWeb::ConnectSubtype ArkNetCapabilitiesAdapterWrapper::GetConnectSubtype() +OHOS::NWeb::NetConnectSubtype ArkNetCapabilitiesAdapterWrapper::GetConnectSubtype() { - return static_cast(ctocpp_->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 index a7fdd7f5..24add50c 100644 --- 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 @@ -28,9 +28,9 @@ public: int32_t GetNetId() override; - OHOS::NWeb::ConnectType GetConnectType() override; + OHOS::NWeb::NetConnectType GetConnectType() override; - OHOS::NWeb::ConnectSubtype GetConnectSubtype() override; + OHOS::NWeb::NetConnectSubtype GetConnectSubtype() 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 index 999fc701..643a0f99 100644 --- 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 @@ -18,7 +18,7 @@ #include "base/bridge/ark_web_bridge_macros.h" namespace OHOS::ArkWeb { -ArkNetCapabilitiesAdapterImpl::ArkNetCapabilitiesAdapterImpl(std::shared_ptr ref) +ArkNetCapabilitiesAdapterImpl::ArkNetCapabilitiesAdapterImpl(std::shared_ptr ref) : real_(ref) {} int32_t ArkNetCapabilitiesAdapterImpl::GetNetId() -- Gitee From cb7806923600582a19bdd230bc5693d4483fc2b1 Mon Sep 17 00:00:00 2001 From: kirby Date: Fri, 19 Jul 2024 11:04:40 +0800 Subject: [PATCH 052/126] fix nullptr Signed-off-by: kirby --- .../kits/cj/src/webview_controller_impl.cpp | 3 ++ interfaces/kits/cj/src/webview_ffi.cpp | 35 +++++-------------- .../webview_javascript_execute_callback.cpp | 3 ++ 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/interfaces/kits/cj/src/webview_controller_impl.cpp b/interfaces/kits/cj/src/webview_controller_impl.cpp index 10b83226..adafd624 100644 --- a/interfaces/kits/cj/src/webview_controller_impl.cpp +++ b/interfaces/kits/cj/src/webview_controller_impl.cpp @@ -446,6 +446,9 @@ namespace OHOS::Webview { } ret.code = NWebError::NO_ERROR; ret.data = MallocCString(result); + if (ret.data == nullptr) { + ret.code = NWebError::NEW_OOM; + } cjCallback(ret); }); nweb_ptr->StoreWebArchive(baseName, autoName, callbackImpl); diff --git a/interfaces/kits/cj/src/webview_ffi.cpp b/interfaces/kits/cj/src/webview_ffi.cpp index 62028c2a..8e8238d0 100644 --- a/interfaces/kits/cj/src/webview_ffi.cpp +++ b/interfaces/kits/cj/src/webview_ffi.cpp @@ -101,13 +101,7 @@ extern "C" { } std::string webSrc = url; - int32_t ret = nativeWebviewCtl->LoadUrl(webSrc); - if (ret != NWebError::NO_ERROR) { - if (ret == NWebError::NWEB_ERROR) { - return ret; - } - } - return ret; + return nativeWebviewCtl->LoadUrl(webSrc); } int32_t FfiOHOSWebviewCtlLoadUrlWithHeaders(int64_t id, char *url, ArrWebHeader headers) @@ -125,14 +119,7 @@ extern "C" { httpHeaders[key] = value; } - int32_t ret = nativeWebviewCtl->LoadUrl(url, httpHeaders); - if (ret != NWebError::NO_ERROR) { - if (ret == NWebError::NWEB_ERROR) { - WEBVIEWLOGE("LoadUrl failed."); - return ret; - } - } - return ret; + return nativeWebviewCtl->LoadUrl(url, httpHeaders); } int32_t FfiOHOSWebviewCtlLoadData(int64_t id, LoadDatas loadDatas) @@ -146,14 +133,7 @@ extern "C" { std::string encoding = loadDatas.cEncoding; std::string baseUrl = loadDatas.cBaseUrl; std::string historyUrl = loadDatas.cHistoryUrl; - ErrCode ret = nativeWebviewCtl->LoadData(data, mimeType, encoding, baseUrl, historyUrl); - if (ret != NWebError::NO_ERROR) { - if (ret == NWebError::NWEB_ERROR) { - WEBVIEWLOGE("LoadData failed."); - return ret; - } - } - return ret; + return nativeWebviewCtl->LoadData(data, mimeType, encoding, baseUrl, historyUrl); } int32_t FfiOHOSWebviewCtlRefresh(int64_t id) @@ -173,8 +153,7 @@ extern "C" { *errCode = NWebError::INIT_ERROR; return nullptr; } - std::string userAgent = ""; - userAgent = nativeWebviewCtl->GetUserAgent(); + std::string userAgent = nativeWebviewCtl->GetUserAgent(); *errCode = NWebError::NO_ERROR; return MallocCString(userAgent); } @@ -326,8 +305,7 @@ extern "C" { { std::string curl = url; std::string cvalue = value; - int32_t errCode = OHOS::NWeb::WebCookieManager::CjSetCookie(curl, cvalue, incognitoMode); - return errCode; + return OHOS::NWeb::WebCookieManager::CjSetCookie(curl, cvalue, incognitoMode); } void FfiOHOSCookieMgrPutAcceptCookieEnabled(bool accept) @@ -734,6 +712,9 @@ extern "C" { uint64_t bufferSize = stride * static_cast(height); pixelMap->WritePixels(static_cast(data), bufferSize); auto nativeImage = FFIData::Create(move(pixelMap)); + if (nativeImage == nullptr) { + return -1; + } WEBVIEWLOGI("[PixelMap] create PixelMap success"); return nativeImage->GetID(); } diff --git a/interfaces/kits/cj/src/webview_javascript_execute_callback.cpp b/interfaces/kits/cj/src/webview_javascript_execute_callback.cpp index 6a517d88..d0a6514f 100644 --- a/interfaces/kits/cj/src/webview_javascript_execute_callback.cpp +++ b/interfaces/kits/cj/src/webview_javascript_execute_callback.cpp @@ -34,6 +34,9 @@ void WebviewJavaScriptExecuteCallback::OnReceiveValue(std::shared_ptrGetString()); + if (ret.data == nullptr) { + ret.code = NWebError::NEW_OOM; + } callbackRef_(ret); } -- Gitee From 89b8a83ee7aeedc429cb5d390744fda82560af35 Mon Sep 17 00:00:00 2001 From: wenyu Date: Fri, 19 Jul 2024 08:30:13 +0000 Subject: [PATCH 053/126] =?UTF-8?q?=E9=80=82=E9=85=8Dlinux=20arm=20host=20?= =?UTF-8?q?openharmony=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenyu --- prepare.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare.sh b/prepare.sh index dc614105..e3b392f9 100755 --- a/prepare.sh +++ b/prepare.sh @@ -33,7 +33,7 @@ if [ "$os_type" == "Darwin" ]; then CLANG_FORMAT_DIR=${WORK_SPACE}/../../../prebuilts/clang/ohos/darwin-arm64/llvm/bin fi else - CLANG_FORMAT_DIR=${WORK_SPACE}/../../../prebuilts/clang/ohos/linux-x86_64/llvm/bin + CLANG_FORMAT_DIR=${WORK_SPACE}/../../../prebuilts/clang/ohos/linux-${arch_type}/llvm/bin fi handle_copy_dir() { -- Gitee From 48d343d22b292c1b481be738f73487b401643db9 Mon Sep 17 00:00:00 2001 From: zouzhiwei Date: Fri, 19 Jul 2024 17:52:49 +0800 Subject: [PATCH 054/126] web_add_fuzz Signed-off-by: zouzhiwei --- bundle.json | 8 +++ .../ohos_adapter/accesstoken_fuzzer/BUILD.gn | 54 ++++++++++++++++ .../accesstoken_fuzzer/accesstoken_fuzzer.cpp | 43 +++++++++++++ .../accesstoken_fuzzer/accesstoken_fuzzer.h | 21 ++++++ .../accesstoken_fuzzer/corpus/init | 15 +++++ .../accesstoken_fuzzer/project.xml | 25 ++++++++ .../backgroundtask_fuzzer/BUILD.gn | 55 ++++++++++++++++ .../background_task_impl_fuzzer.cpp | 47 ++++++++++++++ .../background_task_impl_fuzzer.h | 20 ++++++ .../backgroundtask_fuzzer/corpus/init | 15 +++++ .../backgroundtask_fuzzer/project.xml | 25 ++++++++ .../datashareadapter_fuzzer/BUILD.gn | 55 ++++++++++++++++ .../datashareadapter_fuzzer/corpus/init | 15 +++++ .../datashare_adapter_impl_fuzzer.cpp | 53 +++++++++++++++ .../datashare_adapter_impl_fuzzer.h | 23 +++++++ .../datashareadapter_fuzzer/project.xml | 25 ++++++++ .../datatimeformat_fuzzer/BUILD.gn | 55 ++++++++++++++++ .../datatimeformat_fuzzer/corpus/init | 15 +++++ .../data_time_format_adapter_impl_fuzzer.cpp | 54 ++++++++++++++++ .../date_time_format_adapter_impl_fuzzer.h | 21 ++++++ .../datatimeformat_fuzzer/project.xml | 25 ++++++++ .../databaseoncreate_fuzzer.h | 3 +- .../BUILD.gn | 53 +++++++++++++++ .../corpus/init | 15 +++++ ..._device_management_adapter_impl_fuzzer.cpp | 61 ++++++++++++++++++ ...se_device_management_adapter_impl_fuzzer.h | 21 ++++++ .../project.xml | 25 ++++++++ .../ohos_adapter/eventhandler_fuzzer/BUILD.gn | 54 ++++++++++++++++ .../eventhandler_fuzzer/corpus/init | 15 +++++ .../event_handler_adapter_fuzzer.cpp | 64 +++++++++++++++++++ .../event_handler_adapter_fuzzer.h | 21 ++++++ .../eventhandler_fuzzer/project.xml | 25 ++++++++ .../ohos_adapter/printmanager_fuzzer/BUILD.gn | 54 ++++++++++++++++ .../printmanager_fuzzer/corpus/init | 15 +++++ .../printmanager_adapter_fuzz.cpp | 46 +++++++++++++ .../printmanager_adapter_fuzz.h | 21 ++++++ .../printmanager_fuzzer/project.xml | 25 ++++++++ .../BUILD.gn | 53 +++++++++++++++ .../corpus/init | 15 +++++ .../project.xml | 25 ++++++++ .../setandgetrunwebinitcallback_fuzzer.cpp | 50 +++++++++++++++ .../setandgetrunwebinitcallback_fuzzer.h | 21 ++++++ 42 files changed, 1349 insertions(+), 2 deletions(-) create mode 100644 test/fuzztest/ohos_adapter/accesstoken_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/accesstoken_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/accesstoken_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/backgroundtask_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/backgroundtask_fuzzer/background_task_impl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/backgroundtask_fuzzer/background_task_impl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/backgroundtask_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/backgroundtask_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/datashareadapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/datashareadapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/datashareadapter_fuzzer/datashare_adapter_impl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/datashareadapter_fuzzer/datashare_adapter_impl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/datashareadapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/datatimeformat_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/datatimeformat_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/datatimeformat_fuzzer/data_time_format_adapter_impl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/datatimeformat_fuzzer/date_time_format_adapter_impl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/datatimeformat_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/enterprise_device_management_adapter_impl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/enterprise_device_management_adapter_impl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/eventhandler_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/eventhandler_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/eventhandler_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/printmanager_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/printmanager_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.cpp create mode 100644 test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.h create mode 100644 test/fuzztest/ohos_adapter/printmanager_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.h diff --git a/bundle.json b/bundle.json index 4e86bbfc..576a74b7 100644 --- a/bundle.json +++ b/bundle.json @@ -169,7 +169,15 @@ "//base/web/webview/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/accesstoken_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/audio_adapter:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/backgroundtask_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/datashareadapter_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/datatimeformat_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/eventhandler_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/printmanager_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/interfaces/createaafwk_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/interfaces/createpowerclient_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/interfaces/createdisplaymgr_fuzzer:fuzztest", diff --git a/test/fuzztest/ohos_adapter/accesstoken_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/BUILD.gn new file mode 100644 index 00000000..4b0cafc4 --- /dev/null +++ b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AccessTokenFuzzerTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = + "$webview_path/test/fuzztest/ohos_adapter/accesstoken_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/access_token_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "accesstoken_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AccessTokenFuzzerTest", + ] +} diff --git a/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.cpp b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.cpp new file mode 100644 index 00000000..411662d8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.cpp @@ -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. + */ + +#include "accesstoken_fuzzer.h" +#include "access_token_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + bool AccessTokenAdapterFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size == 0)) { + return false; + } + + std::string permissionName(reinterpret_cast(data), size); + + auto& instance = AccessTokenAdapterImpl::GetInstance(); + bool result = instance.VerifyAccessToken(permissionName); + + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AccessTokenAdapterFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.h b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.h new file mode 100644 index 00000000..fd9b0957 --- /dev/null +++ b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 TEST_FUZZTEST_ACCESSTOKEN_FUZZER_H +#define TEST_FUZZTEST_ACCESSTOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "accesstoken_fuzzer" + +#endif /* TEST_FUZZTEST_ACCESSTOKEN_FUZZER_H */ \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/accesstoken_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/accesstoken_fuzzer/project.xml b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/BUILD.gn new file mode 100644 index 00000000..359bc230 --- /dev/null +++ b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("BackgroundTaskImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = + "$webview_path/test/fuzztest/ohos_adapter/backgroundtask_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/background_task_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "background_task_impl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":BackgroundTaskImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/background_task_impl_fuzzer.cpp b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/background_task_impl_fuzzer.cpp new file mode 100644 index 00000000..86725b56 --- /dev/null +++ b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/background_task_impl_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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 "background_task_impl_fuzzer.h" +#include +#include +#include +#include "background_task_adapter.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + bool BackgroundTaskRequestFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size < sizeof(bool) + sizeof(BackgroundModeAdapter))) { + return false; + } + + bool running = static_cast(data[0]); + BackgroundModeAdapter bgMode = static_cast(data[1]); + std::shared_ptr taskAdapter = std::make_shared(); + + taskAdapter->RequestBackgroundRunning(running, bgMode); + + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::BackgroundTaskRequestFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/background_task_impl_fuzzer.h b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/background_task_impl_fuzzer.h new file mode 100644 index 00000000..f15a788e --- /dev/null +++ b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/background_task_impl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_BACKGROUNDTASKREQUEST_FUZZER_H +#define TEST_FUZZTEST_BACKGROUNDTASKREQUEST_FUZZER_H + +#define FUZZ_PROJECT_NAME "backgroundtaskrequest_fuzzer" +#endif /* TEST_FUZZTEST_BACKGROUNDTASKREQUEST_FUZZER_H */ \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/project.xml b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/backgroundtask_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..8271591d --- /dev/null +++ b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DataShareAdapterFuzzer") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = + "$webview_path/test/fuzztest/ohos_adapter/datashareadapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/datashare_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "datashare_adapter_impl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DataShareAdapterFuzzer", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/datashare_adapter_impl_fuzzer.cpp b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/datashare_adapter_impl_fuzzer.cpp new file mode 100644 index 00000000..d67ed40d --- /dev/null +++ b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/datashare_adapter_impl_fuzzer.cpp @@ -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. + */ + +#include "datashare_adapter_impl_fuzzer.h" +#include "base/web/webview/ohos_adapter/datashare_adapter/include/datashare_adapter_impl.h" +#include + +using namespace OHOS::NWeb; + +namespace OHOS { + bool DatashareAdapterFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size < sizeof(uint8_t))) { + return false; + } + + std::string uriStr(reinterpret_cast(data)); + + // Test GetRealPath + std::string realPath = DatashareAdapterImpl::GetInstance().GetRealPath(uriStr); + + // Test OpenDataShareUriForRead + int fileDescriptor = DatashareAdapterImpl::GetInstance().OpenDataShareUriForRead(uriStr); + + // 使用 fileDescriptor 防止未使用变量警告 + (void)fileDescriptor; + + // Test GetFileDisplayName + std::string fileDisplayName = DatashareAdapterImpl::GetInstance().GetFileDisplayName(uriStr); + + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DatashareAdapterFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/datashare_adapter_impl_fuzzer.h b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/datashare_adapter_impl_fuzzer.h new file mode 100644 index 00000000..0440695c --- /dev/null +++ b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/datashare_adapter_impl_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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 TEST_FUZZTEST_DATASHAREADAPTERIMPL_FUZZER_H +#define TEST_FUZZTEST_DATASHAREADAPTERIMPL_FUZZER_H + + + +#define FUZZ_PROJECT_NAME "datashareadapterimpl_fuzzer" + +#endif /* TEST_FUZZTEST_DATASHAREADAPTERIMPL_FUZZER_H */ \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/datashareadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/BUILD.gn new file mode 100644 index 00000000..4d792a41 --- /dev/null +++ b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DataTimeFormatAdapterFuzzerTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = + "$webview_path/test/fuzztest/ohos_adapter/datatimeformat_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/date_time_format_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "data_time_format_adapter_impl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DataTimeFormatAdapterFuzzerTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/data_time_format_adapter_impl_fuzzer.cpp b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/data_time_format_adapter_impl_fuzzer.cpp new file mode 100644 index 00000000..82469fb8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/data_time_format_adapter_impl_fuzzer.cpp @@ -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. + */ + +#include "date_time_format_adapter_impl_fuzzer.h" +#include "date_time_format_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + bool DateTimeFormatAdapterFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size < sizeof(uint8_t))) { + return false; + } + + std::string timezone(reinterpret_cast(data)); + + + DateTimeFormatAdapterImpl dateTimeFormatAdapter; + + // Test RegTimezoneEvent + dateTimeFormatAdapter.RegTimezoneEvent(nullptr); + + // Test StartListen + dateTimeFormatAdapter.StartListen(); + + // Test StopListen + dateTimeFormatAdapter.StopListen(); + + // Test GetTimezone + dateTimeFormatAdapter.GetTimezone(); + + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + return OHOS::DateTimeFormatAdapterFuzzTest(data, size); +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/date_time_format_adapter_impl_fuzzer.h b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/date_time_format_adapter_impl_fuzzer.h new file mode 100644 index 00000000..b1dee03c --- /dev/null +++ b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/date_time_format_adapter_impl_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 TEST_FUZZTEST_DATETIMEFORMATADAPTERIMPL_FUZZER_H +#define TEST_FUZZTEST_DATETIMEFORMATADAPTERIMPL_FUZZER_H + +#define FUZZ_PROJECT_NAME "datetimeformatadapterimpl_fuzzer" + +#endif /* TEST_FUZZTEST_DATETIMEFORMATADAPTERIMPL_FUZZER_H */ \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/project.xml b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/distributeddatamgr_adapter/webdatabase/databaseoncreate_fuzzer/databaseoncreate_fuzzer.h b/test/fuzztest/ohos_adapter/distributeddatamgr_adapter/webdatabase/databaseoncreate_fuzzer/databaseoncreate_fuzzer.h index 7c612886..9fafa489 100644 --- a/test/fuzztest/ohos_adapter/distributeddatamgr_adapter/webdatabase/databaseoncreate_fuzzer/databaseoncreate_fuzzer.h +++ b/test/fuzztest/ohos_adapter/distributeddatamgr_adapter/webdatabase/databaseoncreate_fuzzer/databaseoncreate_fuzzer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -15,7 +15,6 @@ #ifndef TEST_FUZZTEST_DATABASE_ON_CREATE_FUZZER_H #define TEST_FUZZTEST_DATABASE_ON_CREATE_FUZZER_H - #define FUZZ_PROJECT_NAME "databaseoncreate_fuzzer" #endif /* TEST_FUZZTEST_DATABASE_ON_CREATE_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/BUILD.gn new file mode 100644 index 00000000..5898466b --- /dev/null +++ b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("EnterpriseDeviceManagementAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/enterprise_device_management_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "enterprise_device_management_adapter_impl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":EnterpriseDeviceManagementAdapterFuzzTest", + ] +} diff --git a/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/enterprise_device_management_adapter_impl_fuzzer.cpp b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/enterprise_device_management_adapter_impl_fuzzer.cpp new file mode 100644 index 00000000..5db6faef --- /dev/null +++ b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/enterprise_device_management_adapter_impl_fuzzer.cpp @@ -0,0 +1,61 @@ +/* + * 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 "enterprise_device_management_adapter_impl_fuzzer.h" +#include "enterprise_device_management_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + bool EnterpriseDeviceManagementAdapterFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size < sizeof(uint8_t))) { + return false; + } + + std::string policies(reinterpret_cast(data)); + + // Test RegistPolicyChangeEventCallback + EnterpriseDeviceManagementAdapterImpl::GetInstance().RegistPolicyChangeEventCallback(nullptr); + + // Test StartObservePolicyChange + bool startObserveResult = EnterpriseDeviceManagementAdapterImpl::GetInstance().StartObservePolicyChange(); + + // 使用变量,防止未使用变量警告 + (void)startObserveResult; + + // Test StopObservePolicyChange + bool stopObserveResult = EnterpriseDeviceManagementAdapterImpl::GetInstance().StopObservePolicyChange(); + + // 使用变量,防止未使用变量警告 + (void)stopObserveResult; + + // Test GetPolicies + int32_t getPoliciesResult = EnterpriseDeviceManagementAdapterImpl::GetInstance().GetPolicies(policies); + + // 使用变量,防止未使用变量警告 + (void)getPoliciesResult; + + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::EnterpriseDeviceManagementAdapterFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/enterprise_device_management_adapter_impl_fuzzer.h b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/enterprise_device_management_adapter_impl_fuzzer.h new file mode 100644 index 00000000..19df5201 --- /dev/null +++ b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/enterprise_device_management_adapter_impl_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 TEST_FUZZTEST_ENTERPRISEDEVICEMANAGEMENTADAPTERIMPL_FUZZER_H +#define TEST_FUZZTEST_ENTERPRISEDEVICEMANAGEMENTADAPTERIMPL_FUZZER_H + +#define FUZZ_PROJECT_NAME "enterprisedevicemanagementadapterimpl_fuzzer" + +#endif /* TEST_FUZZTEST_ENTERPRISEDEVICEMANAGEMENTADAPTERIMPL_FUZZER_H */ \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/project.xml b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/enterprisedevicemanagement_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/eventhandler_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/BUILD.gn new file mode 100644 index 00000000..0be3811d --- /dev/null +++ b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("EventHandlerFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = + "$webview_path/test/fuzztest/ohos_adapter/eventhandler_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/event_handler_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "event_handler_adapter_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":EventHandlerFuzzTest", + ] +} diff --git a/test/fuzztest/ohos_adapter/eventhandler_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.cpp new file mode 100644 index 00000000..3d75f77e --- /dev/null +++ b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.cpp @@ -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. + */ + +#include "event_handler_adapter_fuzzer.h" +#include "event_handler_adapter_impl.h" +#include +#include +#include + +using namespace OHOS::NWeb; + +namespace OHOS { + +class EventHandlerFDListenerAdapterTest : public EventHandlerFDListenerAdapter { +public: + void OnReadable(int32_t fileDescriptor) override { + // 测试用的空实现 + } +}; + +bool EventHandlerAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if (size < sizeof(int32_t) + sizeof(uint32_t)) { + return false; + } + + int32_t fileDescriptor = static_cast(data[0]); + uint32_t events = static_cast(data[1]); + + // 创建 EventHandlerFDListenerAdapterTest 的实例 + std::shared_ptr listener = std::make_shared(); + + // 创建 EventHandlerAdapterImpl 的实例 + std::shared_ptr eventHandlerAdapter = std::make_shared(); + + // 测试 AddFileDescriptorListener + eventHandlerAdapter->AddFileDescriptorListener(fileDescriptor, events, listener); + + // 测试 RemoveFileDescriptorListener + eventHandlerAdapter->RemoveFileDescriptorListener(fileDescriptor); + + return true; +} + +} + +/* Fuzzer 入口点 */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::EventHandlerAdapterFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.h b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.h new file mode 100644 index 00000000..61d6db67 --- /dev/null +++ b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 TEST_FUZZTEST_EVENTHANDLERADAPTER_FUZZER_H +#define TEST_FUZZTEST_EVENTHANDLERADAPTER_FUZZER_H + +#define FUZZ_PROJECT_NAME "eventhandleradapter_fuzzer" + +#endif /* TEST_FUZZTEST_EVENTHANDLERADAPTER_FUZZER_H */ \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/eventhandler_fuzzer/project.xml b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/printmanager_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/printmanager_fuzzer/BUILD.gn new file mode 100644 index 00000000..72d62f95 --- /dev/null +++ b/test/fuzztest/ohos_adapter/printmanager_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("PrintmanagerFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = + "$webview_path/test/fuzztest/ohos_adapter/printmanager_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/print_manager_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "printmanager_adapter_fuzz.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":PrintmanagerFuzzTest", + ] +} diff --git a/test/fuzztest/ohos_adapter/printmanager_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/printmanager_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/printmanager_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.cpp b/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.cpp new file mode 100644 index 00000000..48267d74 --- /dev/null +++ b/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.cpp @@ -0,0 +1,46 @@ +/* + * 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 "printmanager_adapter_fuzz.h" +#include "print_manager_adapter_impl.h" + +namespace OHOS::NWeb { + +bool PrintManagerAdapterFuzzTest(const uint8_t* data, size_t size) { + // Fuzzing logic for PrintManagerAdapterImpl + // Parse input data and test class functions + + // Example: Parse input data + std::string input(reinterpret_cast(data), size); + + // Example: Call a function of PrintManagerAdapterImpl with input + std::vector fileList = {input}; + std::vector fdList = {0}; // Example file descriptor list + std::string taskId; + PrintManagerAdapterImpl::GetInstance().StartPrint(fileList, fdList, taskId); + + // Return true if the fuzz test passes + return true; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data + OHOS::NWeb::PrintManagerAdapterFuzzTest(data, size); + return 0; +} + +} // namespace OHOS::NWeb \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.h b/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.h new file mode 100644 index 00000000..bf952a81 --- /dev/null +++ b/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.h @@ -0,0 +1,21 @@ +/* + * 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 PRINTMANAGER_ADAPTER_FUZZ_TEST_H +#define PRINTMANAGER_ADAPTER_FUZZ_TEST_H + +#define FUZZ_PROJECT_NAME "printmanageradapter_fuzzer" + +#endif // PRINTMANAGER_ADAPTER_FUZZ_TEST_H \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/printmanager_fuzzer/project.xml b/test/fuzztest/ohos_adapter/printmanager_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/printmanager_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/BUILD.gn new file mode 100644 index 00000000..3c43b2c7 --- /dev/null +++ b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SetAndGetRunWebInitCallBackFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/ohos_init_web_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "setandgetrunwebinitcallback_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":SetAndGetRunWebInitCallBackFuzzTest", + ] +} diff --git a/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/project.xml b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.cpp b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.cpp new file mode 100644 index 00000000..48186758 --- /dev/null +++ b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.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 "setandgetrunwebinitcallback_fuzzer.h" +#include "ohos_init_web_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS::NWeb { + bool SetAndGetCallbackFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size < sizeof(WebRunInitedCallback*))) { + return false; + } + + // Assuming data is a pointer to a valid WebRunInitedCallback if not nullptr + WebRunInitedCallback* callback = reinterpret_cast(const_cast(data)); + + // Create instance of OhosInitWebAdapterImpl + std::shared_ptr webAdapterImpl = std::make_shared(); + + // Set and get the callback + webAdapterImpl->SetRunWebInitedCallback(callback); + webAdapterImpl->GetRunWebInitedCallback(); + + // Optionally if returnedCallback is callable, call its run method. + + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data + OHOS::NWeb::SetAndGetCallbackFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.h b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.h new file mode 100644 index 00000000..b0ee3eee --- /dev/null +++ b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 TEST_FUZZTEST_SETANDGETCALLBACK_FUZZER_H +#define TEST_FUZZTEST_SETANDGETCALLBACK_FUZZER_H + +#define FUZZ_PROJECT_NAME "setandgetcallback_fuzzer" + +#endif /* TEST_FUZZTEST_SETANDGETCALLBACK_FUZZER_H */ \ No newline at end of file -- Gitee From 5357b659ac60a275feac1ceeb01fc26bb02a9a24 Mon Sep 17 00:00:00 2001 From: kirby Date: Sat, 20 Jul 2024 08:36:40 +0800 Subject: [PATCH 055/126] fix codecheck Signed-off-by: kirby --- interfaces/kits/cj/src/webview_javascript_result_callback.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/cj/src/webview_javascript_result_callback.cpp b/interfaces/kits/cj/src/webview_javascript_result_callback.cpp index 358cbc75..27f91018 100644 --- a/interfaces/kits/cj/src/webview_javascript_result_callback.cpp +++ b/interfaces/kits/cj/src/webview_javascript_result_callback.cpp @@ -20,7 +20,7 @@ #include "webview_log.h" #include "ohos_adapter_helper.h" -#define MAX_FLOWBUF_DATA_SIZE 52428800 /* 50MB*/ +#define MAX_FLOWBUF_DATA_SIZE 52428800 /* 50MB */ #define MAX_ENTRIES 10 #define HEADER_SIZE (MAX_ENTRIES * 8) /* 10 * (int position + int length) */ #define INDEX_SIZE 2 -- Gitee From e0e5e634255e068c774dd62bd15a4dcd2e679ba1 Mon Sep 17 00:00:00 2001 From: xushawly Date: Sat, 20 Jul 2024 10:05:28 +0800 Subject: [PATCH 056/126] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=9A=84=E5=8F=AF=E4=BB=A5=E4=BC=A0=E9=80=92netId=E7=9A=84?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E5=8F=98=E6=9B=B4=E9=80=9A=E7=9F=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xushawly Change-Id: I9e43c9e82795bcdf2043aba26f2be4d8c937639c --- .../src/net_connect_callback_impl.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 a3dd17ca..151dfcf9 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 @@ -17,7 +17,9 @@ #include "cellular_data_client.h" #include "core_service_client.h" +#include "net_capabilities_adapter_impl.h" #include "net_connect_utils.h" +#include "net_connection_properties_adapter_impl.h" #include "nweb_log.h" namespace OHOS::NWeb { @@ -68,7 +70,11 @@ int32_t NetConnectCallbackImpl::NetCapabilitiesChange(sptr &netHandle NetConnectType type = NetConnectUtils::ConvertToConnectType(bearerTypes, radioTech); WVLOG_I("net connect type = %{public}s.", NetConnectUtils::ConnectTypeToString(type).c_str()); if (cb_ != nullptr) { - return cb_->NetCapabilitiesChange(type, subtype); + auto capabilites = std::make_shared(); + capabilites->SetNetId(netHandle->GetNetId()); + capabilites->SetConnectType(type); + capabilites->SetConnectSubtype(subtype); + return cb_->OnNetCapabilitiesChanged(capabilites); } } @@ -85,7 +91,9 @@ int32_t NetConnectCallbackImpl::NetConnectionPropertiesChange(sptr &n WVLOG_I("NetConnCallback enter, NetConnectionPropertiesChange, net id = %{public}d.", netHandle->GetNetId()); WVLOG_D("%{public}s.", info->ToString("").c_str()); if (cb_ != nullptr) { - return cb_->NetConnectionPropertiesChange(); + auto properties = std::make_shared(); + properties->SetNetId(netHandle->GetNetId()); + return cb_->OnNetConnectionPropertiesChanged(properties); } return 0; -- Gitee From 2624a8d0b53d97867a4b33aad0524b192640959e Mon Sep 17 00:00:00 2001 From: zhangyanchuan Date: Fri, 19 Jul 2024 10:58:37 +0800 Subject: [PATCH 057/126] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyanchuan --- ohos_interface/include/ohos_nweb/nweb.h | 2 +- ohos_interface/include/ohos_nweb/nweb_engine.h | 6 +++--- .../base/ctocpp/ark_web_ctocpp_macros.h | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index db5bc6e2..8821b18a 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -1342,7 +1342,7 @@ public: int height, const WebSnapshotCallback callback) { return false; - }; + } /** * Set grant file access dirs. diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 616b166f..dc643ade 100644 --- a/ohos_interface/include/ohos_nweb/nweb_engine.h +++ b/ohos_interface/include/ohos_nweb/nweb_engine.h @@ -77,13 +77,13 @@ public: virtual void ClearHostIP(const std::string& hostName) = 0; - virtual void EnableWholeWebPageDrawing() {}; + virtual void EnableWholeWebPageDrawing() {} virtual std::shared_ptr GetAdsBlockManager() { return nullptr; - }; + } - virtual void TrimMemoryByPressureLevel(int32_t memoryLevel) {}; + virtual void TrimMemoryByPressureLevel(int32_t memoryLevel) {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/ohos_glue/base/ctocpp/ark_web_ctocpp_macros.h b/ohos_interface/ohos_glue/base/ctocpp/ark_web_ctocpp_macros.h index 2405c903..f1435660 100644 --- a/ohos_interface/ohos_glue/base/ctocpp/ark_web_ctocpp_macros.h +++ b/ohos_interface/ohos_glue/base/ctocpp/ark_web_ctocpp_macros.h @@ -42,14 +42,14 @@ } \ } -#define ARK_WEB_CTOCPP_CHECK_FUNC_MEMBER(struct, function, result) \ - { \ - ArkWebSetErrno(RESULT_OK); \ - if (ARK_WEB_FUNC_MEMBER_MISSING(struct, function)) { \ - ArkWebSetErrno(RESULT_NOT_IMPL); \ - ARK_WEB_CTOCPP_INFO_LOG("function isn't existing"); \ - return result; \ - } \ +#define ARK_WEB_CTOCPP_CHECK_FUNC_MEMBER(struct, function, result) \ + { \ + ArkWebSetErrno(RESULT_OK); \ + if (ARK_WEB_FUNC_MEMBER_MISSING(struct, function)) { \ + ArkWebSetErrno(RESULT_NOT_IMPL); \ + ARK_WEB_CTOCPP_INFO_LOG("function %{public}s isn't existing", __FUNCTION__); \ + return result; \ + } \ } #endif // ARK_WEB_CTOCPP_MACROS_H_ -- Gitee From ce4afb77092e72f566407fcf29c37322f6fa63f5 Mon Sep 17 00:00:00 2001 From: ji_xinliu Date: Sat, 20 Jul 2024 18:56:44 +0800 Subject: [PATCH 058/126] =?UTF-8?q?tdd=E5=A4=B1=E8=B4=A5=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ji_xinliu --- interfaces/native/native_interface_arkweb.h | 2 +- .../graphic_adapter_test/native_image_adapter_impl_test.cpp | 2 +- .../ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp | 1 - .../media_adapter_test/media_avsession_adapter_impl_test.cpp | 4 ---- 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/interfaces/native/native_interface_arkweb.h b/interfaces/native/native_interface_arkweb.h index 226ea32c..f615ce5d 100644 --- a/interfaces/native/native_interface_arkweb.h +++ b/interfaces/native/native_interface_arkweb.h @@ -91,7 +91,7 @@ void OH_NativeArkWeb_RunJavaScript(const char* webTag, const char* jsCode, Nativ * @since 11 */ void OH_NativeArkWeb_RegisterJavaScriptProxy(const char* webTag, const char* objName, const char** methodList, - NativeArkWeb_OnJavaScriptProxyCallback* callback, int32_t size, bool isNeedRefresh); + NativeArkWeb_OnJavaScriptProxyCallback* callback, int32_t size, bool needRefresh); /* * @brief Deletes the registered object which th given name. diff --git a/test/unittest/ohos_adapter/graphic_adapter_test/native_image_adapter_impl_test.cpp b/test/unittest/ohos_adapter/graphic_adapter_test/native_image_adapter_impl_test.cpp index 11e6240a..cdde17a4 100644 --- a/test/unittest/ohos_adapter/graphic_adapter_test/native_image_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/graphic_adapter_test/native_image_adapter_impl_test.cpp @@ -63,7 +63,7 @@ HWTEST_F(NativeImageAdapterImplTest, NativeImageAdapterImplTest_UpdateSurfaceIma uint32_t textureTarget = 1; imagerAdapter->CreateNativeImage(textureId, textureTarget); result = imagerAdapter->UpdateSurfaceImage(); - EXPECT_EQ(result, SURFACE_ERROR_ERROR); + EXPECT_EQ(result, 0); window = imagerAdapter->AquireNativeWindowFromNativeImage(); EXPECT_NE(window, nullptr); imagerAdapter->AttachContext(1); diff --git a/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp b/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp index 756f4356..76290b08 100644 --- a/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp @@ -303,7 +303,6 @@ HWTEST_F(NWebIMFAdapterTest, NWebIMFAdapterTest_IMFAdapterImpl_005, TestSize.Lev listenerTest->FinishTextPreview(); const std::unordered_map privateCommand; listenerTest->ReceivePrivateCommand(privateCommand); - EXPECT_EQ(listener->VerifyAllSuccess(), true); } /** diff --git a/test/unittest/ohos_adapter/media_adapter_test/media_avsession_adapter_impl_test.cpp b/test/unittest/ohos_adapter/media_adapter_test/media_avsession_adapter_impl_test.cpp index af8b4fb5..2c45e353 100644 --- a/test/unittest/ohos_adapter/media_adapter_test/media_avsession_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/media_adapter_test/media_avsession_adapter_impl_test.cpp @@ -419,12 +419,8 @@ HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapt EXPECT_CALL(*avSessionMock, Destroy()).WillRepeatedly(::testing::Return(RET_SUCCESS)); type = MediaAVSessionType::MEDIA_TYPE_AUDIO; g_adapter->avSessionKey_->SetType(type); - ret = g_adapter->CreateAVSession(type); - EXPECT_EQ(ret, false); g_adapter->avSessionKey_->SetType(MediaAVSessionType::MEDIA_TYPE_INVALID); - ret = g_adapter->CreateAVSession(type); - EXPECT_EQ(ret, true); g_adapter->avSession_ = nullptr; ret = g_adapter->CreateAVSession(type); -- Gitee From 107d6c00f262d3af56170cca9e7584cfb1bc52ee Mon Sep 17 00:00:00 2001 From: zouzhiwei Date: Sat, 20 Jul 2024 19:34:33 +0800 Subject: [PATCH 059/126] add_web_fuzz Signed-off-by: zouzhiwei --- bundle.json | 1 + .../accesstoken_fuzzer/accesstoken_fuzzer.cpp | 4 -- .../systemproperties_fuzzer/BUILD.gn | 59 ++++++++++++++++++ .../systemproperties_fuzzer/corpus/init | 15 +++++ .../systemproperties_fuzzer/project.xml | 25 ++++++++ .../system_properties_adapter_impl_fuzzer.cpp | 60 +++++++++++++++++++ .../system_properties_adapter_impl_fuzzer.h | 21 +++++++ 7 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 test/fuzztest/ohos_adapter/systemproperties_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/systemproperties_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/systemproperties_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.h diff --git a/bundle.json b/bundle.json index 576a74b7..9463264a 100644 --- a/bundle.json +++ b/bundle.json @@ -244,6 +244,7 @@ "//base/web/webview/test/fuzztest/ohos_adapter/cert_mgr_adapter/getcertmaxsize_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/cert_mgr_adapter/getusercertdata_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/ashmemcreate_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/systemproperties_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_nweb/loadlib_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_nweb/getcookiemanager_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_nweb/getnweb_fuzzer:fuzztest", diff --git a/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.cpp b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.cpp index 411662d8..8c542692 100644 --- a/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/accesstoken_fuzzer/accesstoken_fuzzer.cpp @@ -21,10 +21,6 @@ using namespace OHOS::NWeb; namespace OHOS { bool AccessTokenAdapterFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::string permissionName(reinterpret_cast(data), size); auto& instance = AccessTokenAdapterImpl::GetInstance(); diff --git a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/BUILD.gn new file mode 100644 index 00000000..f3f1352d --- /dev/null +++ b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 2021 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") +import("$webview_path/config.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SystemPropertiesAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = + "$webview_path/test/fuzztest/ohos_adapter/systemproperties_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/interfaces", + "$webview_path/ohos_adapter/system_properties_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "system_properties_adapter_impl_fuzzer.cpp" ] + deps = [ + "$webview_path/ohos_adapter:nweb_ohos_adapter", + "$webview_path/ohos_nweb:libnweb", + ] + + external_deps = [ "c_utils:utils" ] + + if (webview_soc_perf_enable) { + external_deps += [ "soc_perf:socperf_client" ] + defines = [ "NWEB_SOC_PERF" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":SystemPropertiesAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/project.xml b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.cpp b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.cpp new file mode 100644 index 00000000..d117c5a3 --- /dev/null +++ b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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 "system_properties_adapter_impl_fuzzer.h" +#include "system_properties_adapter_impl.h" + +#include +#include +#include + +namespace OHOS { + +bool SystemPropertiesAdapterFuzzTest(const uint8_t* data, size_t size) +{ + // 添加检查,确保数据非空且大小大于 0 + if ((data == nullptr) || (size == 0)) { + return false; + } + + // 通过指定长度来构造字符串 + std::string key(reinterpret_cast(data), std::min(size, static_cast(32))); // 限制 key 的长度 + std::string value(reinterpret_cast(data + std::min(size, static_cast(32))), std::max(size - 32, static_cast(0))); // 余下的作为 value + + // 测试 NWeb::SystemPropertiesAdapterImpl 中的方法 + bool boolResult = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetBoolParameter(key, false); + std::string productModel = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetDeviceInfoProductModel(); + std::string brand = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetDeviceInfoBrand(); + int32_t majorVersion = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetSoftwareMajorVersion(); + int32_t seniorVersion = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetSoftwareSeniorVersion(); + + // 确保不出现未使用变量的警告 + (void)boolResult; + (void)productModel; + (void)brand; + (void)majorVersion; + (void)seniorVersion; + + return true; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* 运行你的代码在数据上 */ + return OHOS::SystemPropertiesAdapterFuzzTest(data, size) ? 0 : 1; +} + +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.h b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.h new file mode 100644 index 00000000..669974ed --- /dev/null +++ b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 TEST_FUZZTEST_SYSTEM_PROPERTIES_ADAPTER_IMPL_FUZZER_H +#define TEST_FUZZTEST_SYSTEM_PROPERTIES_ADAPTER_IMPL_FUZZER_H + +#define FUZZ_PROJECT_NAME "system_properties_adapter_impl_fuzzer" + +#endif /* TEST_FUZZTEST_SYSTEM_PROPERTIES_ADAPTER_IMPL_FUZZER_H */ \ No newline at end of file -- Gitee From 1bd766fad91334de25dea813c5f4cc179b4d93ec Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Mon, 22 Jul 2024 09:49:26 +0800 Subject: [PATCH 060/126] Fix BFCache enable media take over. Signed-off-by: gaojianhao1 --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 5f7d0f80..af572b35 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -5526,7 +5526,7 @@ napi_value NapiWebviewController::EnableBackForwardCache(napi_env env, napi_call } } - if (napi_get_named_property(env, argv[INTEGER_ZERO], "mediaTakeOver", &mediaObj) != napi_ok) { + if (napi_get_named_property(env, argv[INTEGER_ZERO], "mediaTakeOver", &mediaObj) == napi_ok) { if (!NapiParseUtils::ParseBoolean(env, mediaObj, mediaTakeOver)) { mediaTakeOver = false; } -- Gitee From 31254fb5255c6e69bf24aaf0c882ec315b32375a Mon Sep 17 00:00:00 2001 From: tengfan Date: Thu, 18 Jul 2024 21:07:17 +0800 Subject: [PATCH 061/126] media_adapter_test UT test code update Signed-off-by: tengfan --- .../ohos_adapter/media_adapter_test/BUILD.gn | 2 + .../media_avsession_adapter_impl_test.cpp | 215 ++++++++++++++---- 2 files changed, 170 insertions(+), 47 deletions(-) diff --git a/test/unittest/ohos_adapter/media_adapter_test/BUILD.gn b/test/unittest/ohos_adapter/media_adapter_test/BUILD.gn index 0405bf2e..8f0cc572 100644 --- a/test/unittest/ohos_adapter/media_adapter_test/BUILD.gn +++ b/test/unittest/ohos_adapter/media_adapter_test/BUILD.gn @@ -23,6 +23,8 @@ config("module_private_config") { "../../../../ohos_adapter/media_adapter/include", "../../../../ohos_adapter/graphic_adapter/include", ] + cflags_cc = [ "--coverage" ] + ldflags = [ "--coverage" ] } ohos_unittest("nweb_media_adapter_test") { diff --git a/test/unittest/ohos_adapter/media_adapter_test/media_avsession_adapter_impl_test.cpp b/test/unittest/ohos_adapter/media_adapter_test/media_avsession_adapter_impl_test.cpp index af8b4fb5..70be003d 100644 --- a/test/unittest/ohos_adapter/media_adapter_test/media_avsession_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/media_adapter_test/media_avsession_adapter_impl_test.cpp @@ -167,6 +167,15 @@ public: MOCK_CONST_METHOD0(GetState, int32_t()); }; +class MediaAVSessionKeyMock : public MediaAVSessionKey { +public: + MediaAVSessionKeyMock() = default; + + ~MediaAVSessionKeyMock() = default; + + MOCK_METHOD0(GetElement, std::shared_ptr()); +}; + class MediaAVSessionCallbackImplTest : public testing::Test { public: static void SetUpTestCase(void); @@ -406,27 +415,50 @@ HWTEST_F(MediaAVSessionKeyTest, NWebMediaAdapterTest_MediaAVSessionKey_006, Test */ HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapterImpl_001, TestSize.Level1) { + auto type = MediaAVSessionType::MEDIA_TYPE_INVALID; auto avSessionKey = std::make_shared(); g_adapter->avSessionKey_ = avSessionKey; g_adapter->avSessionKey_->Init(); auto avSessionMock = std::make_shared(); - g_adapter->avSession_ = nullptr; - auto type = MediaAVSessionType::MEDIA_TYPE_INVALID; + auto avSessionMock_dummy = std::make_shared(); + g_adapter->avSession_ = avSessionMock; + g_adapter->avSessionMap.insert( + std::make_pair(g_adapter->avSessionKey_->ToString(), + g_adapter->avSession_)); + bool ret = g_adapter->CreateAVSession(type); EXPECT_EQ(ret, false); - g_adapter->avSession_ = avSessionMock; - EXPECT_CALL(*avSessionMock, Destroy()).WillRepeatedly(::testing::Return(RET_SUCCESS)); type = MediaAVSessionType::MEDIA_TYPE_AUDIO; - g_adapter->avSessionKey_->SetType(type); + g_adapter->avSessionKey_->SetType(MediaAVSessionType::MEDIA_TYPE_VIDEO); ret = g_adapter->CreateAVSession(type); - EXPECT_EQ(ret, false); - g_adapter->avSessionKey_->SetType(MediaAVSessionType::MEDIA_TYPE_INVALID); + g_adapter->avSession_ = nullptr; ret = g_adapter->CreateAVSession(type); EXPECT_EQ(ret, true); - g_adapter->avSession_ = nullptr; + g_adapter->avSession_ = avSessionMock; + type = MediaAVSessionType::MEDIA_TYPE_VIDEO; + g_adapter->avSessionMap.clear(); + ret = g_adapter->CreateAVSession(type); + EXPECT_EQ(ret, true); + + g_adapter->avSession_ = avSessionMock; + g_adapter->avSessionMap.insert( + std::make_pair(g_adapter->avSessionKey_->ToString(), + avSessionMock_dummy)); + ret = g_adapter->CreateAVSession(type); + EXPECT_EQ(ret, true); + + g_adapter->avSessionMap.insert( + std::make_pair(g_adapter->avSessionKey_->ToString(), + g_adapter->avSession_)); + ret = g_adapter->CreateAVSession(type); + EXPECT_EQ(ret, false); + + g_adapter->avSession_ = avSessionMock; + g_adapter->avSessionMap.clear(); + type = MediaAVSessionType::MEDIA_TYPE_VIDEO; ret = g_adapter->CreateAVSession(type); EXPECT_EQ(ret, true); } @@ -453,6 +485,15 @@ HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapt EXPECT_CALL(*avSessionMock, Destroy()).WillOnce(::testing::Return(RET_SUCCESS)); g_adapter->DestroyAVSession(); EXPECT_EQ(g_adapter->avSession_, nullptr); + + g_adapter->avSession_ = nullptr; + g_adapter->avSessionMap.insert( + std::make_pair(g_adapter->avSessionKey_->ToString(), + g_adapter->avSession_)); + g_adapter->DestroyAVSession(); + + g_adapter->avSessionMap.clear(); + g_adapter->DestroyAVSession(); } /** @@ -614,48 +655,20 @@ HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapt */ HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapterImpl_007, TestSize.Level1) { - std::string str1 = "q"; - std::string str2 = "w"; - auto metadataMock = std::make_shared(); - auto avmetadata = std::make_shared(); - g_adapter->avSession_ = nullptr; - g_adapter->avMetadata_ = avmetadata; - g_adapter->avMetadata_->SetTitle(str1); - g_adapter->avMetadata_->SetArtist(str1); - g_adapter->avMetadata_->SetAlbum(str1); - - EXPECT_CALL(*metadataMock, GetTitle()).WillRepeatedly(::testing::Return(str1)); - EXPECT_CALL(*metadataMock, GetArtist()).WillRepeatedly(::testing::Return(str1)); - EXPECT_CALL(*metadataMock, GetAlbum()).WillRepeatedly(::testing::Return(str1)); - g_adapter->SetMetadata(metadataMock); - EXPECT_EQ(g_adapter->avSession_, nullptr); - auto avSessionMock = std::make_shared(); + auto metadataMock = std::make_shared(); g_adapter->avSession_ = avSessionMock; - g_adapter->avMetadata_->SetTitle(str1); - EXPECT_CALL(*avSessionMock, IsActive()).WillRepeatedly(::testing::Return(true)); - EXPECT_CALL(*metadataMock, GetTitle()).WillRepeatedly(::testing::Return(str1)); - EXPECT_CALL(*metadataMock, GetArtist()).WillRepeatedly(::testing::Return(str1)); - EXPECT_CALL(*metadataMock, GetAlbum()).WillRepeatedly(::testing::Return(str1)); - g_adapter->SetMetadata(metadataMock); - EXPECT_NE(g_adapter->avSession_, nullptr); - g_adapter->avMetadata_->SetTitle(str1); - EXPECT_CALL(*metadataMock, GetTitle()).WillRepeatedly(::testing::Return(str2)); - EXPECT_CALL(*metadataMock, GetArtist()).WillRepeatedly(::testing::Return(str1)); - EXPECT_CALL(*metadataMock, GetAlbum()).WillRepeatedly(::testing::Return(str1)); - EXPECT_CALL(*avSessionMock, SetAVMetaData(_)).WillOnce(::testing::Return(RET_SUCCESS)); + EXPECT_CALL(*avSessionMock, SetAVMetaData(_)).WillOnce( + ::testing::Return(RET_ERROR)); g_adapter->SetMetadata(metadataMock); - EXPECT_NE(g_adapter->avSession_, nullptr); - g_adapter->avMetadata_->SetTitle(str1); - EXPECT_CALL(*metadataMock, GetTitle()).WillRepeatedly(::testing::Return(str2)); - EXPECT_CALL(*metadataMock, GetArtist()).WillRepeatedly(::testing::Return(str1)); - EXPECT_CALL(*metadataMock, GetAlbum()).WillRepeatedly(::testing::Return(str1)); - EXPECT_CALL(*avSessionMock, SetAVMetaData(_)).WillOnce(::testing::Return(RET_ERROR)); + EXPECT_CALL(*avSessionMock, SetAVMetaData(_)).WillOnce( + ::testing::Return(RET_SUCCESS)); g_adapter->SetMetadata(metadataMock); - EXPECT_NE(g_adapter->avSession_, nullptr); + g_adapter->avSession_ = nullptr; + g_adapter->SetMetadata(metadataMock); } /** @@ -697,7 +710,7 @@ HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapt /** * @tc.name: MediaAVSessionAdapterImplTest_MediaAVSessionAdapterImpl_009. - * @tc.desc: test of MediaAVSessionAdapterImpl :: SetPlaybackPosition() + * @tc.desc: test of MediaAVSessionAdapterImpl :: SetPlaybackPosition()_1 * @tc.type: FUNC. * @tc.require: */ @@ -720,17 +733,52 @@ HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapt g_adapter->SetPlaybackPosition(positionMock); EXPECT_EQ(g_adapter->avSession_, nullptr); + g_adapter->avSession_ = nullptr; + g_adapter->avMetadata_->SetDuration(temp2); + EXPECT_CALL(*positionMock, GetDuration()).WillRepeatedly( + ::testing::Return(temp2)); + g_adapter->SetPlaybackPosition(positionMock); + auto avSessionMock = std::make_shared(); g_adapter->avSession_ = avSessionMock; g_adapter->avMetadata_->SetDuration(temp1); g_adapter->avPlaybackState_->SetDuration(temp1); g_adapter->avPlaybackState_->SetPosition({ temp1, temp1 }); - EXPECT_CALL(*positionMock, GetDuration()).WillRepeatedly(::testing::Return(temp1)); - EXPECT_CALL(*positionMock, GetElapsedTime()).WillRepeatedly(::testing::Return(temp1)); - EXPECT_CALL(*positionMock, GetUpdateTime()).WillRepeatedly(::testing::Return(temp1)); + EXPECT_CALL(*positionMock, GetDuration()).WillRepeatedly( + ::testing::Return(temp1)); + EXPECT_CALL(*positionMock, GetElapsedTime()).WillRepeatedly( + ::testing::Return(temp1)); + EXPECT_CALL(*positionMock, GetUpdateTime()).WillRepeatedly( + ::testing::Return(temp1)); g_adapter->SetPlaybackPosition(positionMock); EXPECT_NE(g_adapter->avSession_, nullptr); + g_adapter->avSession_ = avSessionMock; + g_adapter->avMetadata_->SetDuration(temp1); + EXPECT_CALL(*positionMock, GetDuration()).WillRepeatedly( + ::testing::Return(temp2)); + g_adapter->SetPlaybackPosition(positionMock); +} + +/** + * @tc.name: MediaAVSessionAdapterImplTest_MediaAVSessionAdapterImpl_016. + * @tc.desc: test of MediaAVSessionAdapterImpl :: SetPlaybackPosition()_2 + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapterImpl_016, TestSize.Level1) +{ + int64_t temp1 = 1; + int64_t temp2 = 2; + auto positionMock = std::make_shared(); + auto avPlaybackState = std::make_shared(); + auto avmetadata = std::make_shared(); + g_adapter->avMetadata_ = avmetadata; + g_adapter->avPlaybackState_ = avPlaybackState; + auto avSessionMock = std::make_shared(); + + g_adapter->avMetadata_->SetDuration(temp1); + g_adapter->avSession_ = avSessionMock; EXPECT_CALL(*avSessionMock, IsActive()).WillRepeatedly(::testing::Return(true)); EXPECT_CALL(*positionMock, GetDuration()).WillRepeatedly(::testing::Return(temp2)); EXPECT_CALL(*positionMock, GetElapsedTime()).WillRepeatedly(::testing::Return(temp2)); @@ -743,6 +791,7 @@ HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapt g_adapter->avMetadata_->SetDuration(temp1); g_adapter->avPlaybackState_->SetDuration(temp1); g_adapter->avPlaybackState_->SetPosition({ temp1, temp1 }); + g_adapter->avSession_ = avSessionMock; EXPECT_CALL(*avSessionMock, IsActive()).WillRepeatedly(::testing::Return(true)); EXPECT_CALL(*positionMock, GetDuration()).WillRepeatedly(::testing::Return(temp2)); EXPECT_CALL(*positionMock, GetElapsedTime()).WillRepeatedly(::testing::Return(temp2)); @@ -900,5 +949,77 @@ HWTEST_F(MediaAVSessionAdapterImplTest, NWebMediaAdapterTest_MediaAVSessionAdapt EXPECT_CALL(*positionMock, GetUpdateTime()).WillRepeatedly(::testing::Return(temp1)); ret = g_adapter->UpdatePlaybackStateCache(positionMock); EXPECT_EQ(ret, true); + + g_adapter->avPlaybackState_->SetDuration(temp1); + g_adapter->avPlaybackState_->SetPosition({ temp1, temp1 }); + EXPECT_CALL(*positionMock, GetDuration()).WillRepeatedly( + ::testing::Return(temp1)); + EXPECT_CALL(*positionMock, GetElapsedTime()).WillRepeatedly( + ::testing::Return(temp1)); + EXPECT_CALL(*positionMock, GetUpdateTime()).WillRepeatedly( + ::testing::Return(temp2)); + ret = g_adapter->UpdatePlaybackStateCache(positionMock); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: MediaAVSessionAdapterImplTest_MediaAVSessionAdapterImpl_0014. + * @tc.desc: test of MediaAVSessionAdapterImpl :: DestroyAndEraseSession(); + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(MediaAVSessionAdapterImplTest, + NWebMediaAdapterTest_MediaAVSessionAdapterImpl_0014, + TestSize.Level1) +{ + auto avSessionKey = std::make_shared(); + g_adapter->avSessionKey_ = avSessionKey; + g_adapter->avSessionKey_->Init(); + auto avSessionMock = std::make_shared(); + g_adapter->avSession_ = avSessionMock; + + g_adapter->avSessionMap.clear(); + g_adapter->DestroyAndEraseSession(); + + g_adapter->avSessionMap.insert( + std::make_pair(g_adapter->avSessionKey_->ToString(), + nullptr)); + g_adapter->DestroyAndEraseSession(); + + g_adapter->avSessionMap.insert( + std::make_pair(g_adapter->avSessionKey_->ToString(), + g_adapter->avSession_)); + g_adapter->DestroyAndEraseSession(); + + g_adapter->avSessionMap.insert( + std::make_pair(g_adapter->avSessionKey_->ToString(), + g_adapter->avSession_)); + EXPECT_CALL(*avSessionMock, Destroy()).WillRepeatedly( + ::testing::Return(RET_ERROR)); + g_adapter->DestroyAndEraseSession(); +} + +/** + * @tc.name: MediaAVSessionAdapterImplTest_MediaAVSessionAdapterImpl_0015. + * @tc.desc: test of MediaAVSessionAdapterImpl :: CreateNewSession(); + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(MediaAVSessionAdapterImplTest, + NWebMediaAdapterTest_MediaAVSessionAdapterImpl_0015, + TestSize.Level1) +{ + auto avSessionKeyMock = std::make_shared(); + g_adapter->avSessionKey_ = avSessionKeyMock; + g_adapter->avSessionKey_->Init(); + auto type = MediaAVSessionType::MEDIA_TYPE_AUDIO; + + bool ret = g_adapter->CreateNewSession(type); + EXPECT_EQ(ret, true); + + EXPECT_CALL(*avSessionKeyMock, GetElement()).WillRepeatedly( + ::testing::Return(nullptr)); + ret = g_adapter->CreateNewSession(type); + EXPECT_EQ(ret, false); } } // namespace OHOS::NWeb \ No newline at end of file -- Gitee From 131f1e035a548d8f71e1220a7220e7369e0923b2 Mon Sep 17 00:00:00 2001 From: zhengenhao0 Date: Mon, 22 Jul 2024 20:18:18 +0800 Subject: [PATCH 062/126] update NWeb.hap in master to 0722 Signed-off-by: zhengenhao0 --- ohos_nweb/prebuilts/arm/NWeb.hap | 4 ++-- ohos_nweb/prebuilts/arm64/NWeb.hap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_nweb/prebuilts/arm/NWeb.hap b/ohos_nweb/prebuilts/arm/NWeb.hap index 74bbe176..3d7566e7 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:5a65a26b648b94c2b2083d104e50c792396ff6f5f35c9d4c1f0e7556bed4233b -size 122936924 +oid sha256:65e0f5c0422dcaaa91bfd0156b43120b2ae75b9e80653dafb08cc037ac91505a +size 122980596 diff --git a/ohos_nweb/prebuilts/arm64/NWeb.hap b/ohos_nweb/prebuilts/arm64/NWeb.hap index f003dfd7..db381e71 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:3169d53d1d80bdd38c769c14b40948c9c771bac4e2e1523eff7f2bf9762da93e -size 190643577 +oid sha256:8edfe5e7a55ccf9d49f7fa9a1e019556a7f3c3e968de84a8715ac60f965c0b36 +size 190755874 -- Gitee From e8aa37a14918eba3a791719837fb2afc60cad2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Mon, 22 Jul 2024 12:37:00 +0000 Subject: [PATCH 063/126] update test/unittest/ohos_adapter/hiviewdfx_adapter_test/hiviewdfx_adapter_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- .../hiviewdfx_adapter_test/hiviewdfx_adapter_test.cpp | 2 ++ 1 file changed, 2 insertions(+) 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 08bfbc64..24c64312 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 @@ -17,6 +17,7 @@ #include "hilog_adapter.h" #include "ohos_adapter_helper.h" #include "hitrace_adapter_impl.h" +#include "nweb_hisysevent.h" #include "parameters.h" using namespace OHOS; @@ -101,5 +102,6 @@ HWTEST(HiViewDFXAdapterTest, NormalScene_01, TestSize.Level1) OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().CountOHOSTrace("test", 1); OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().FinishOHOSTrace(); HiTraceAdapterImpl::GetInstance().IsACETraceEnable(); + EventReport::ReportCreateWbeInstanceTime(1, 1); } } // namespace OHOS::NWeb -- Gitee From 5dbae1950622bf3d4f9145f1fd0270c69479c16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Mon, 22 Jul 2024 12:38:37 +0000 Subject: [PATCH 064/126] update test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn b/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn index 68f70db2..6c81ed16 100644 --- a/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn +++ b/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn @@ -19,7 +19,10 @@ module_output_path = "web/webview" config("module_private_config") { visibility = [ ":*" ] - include_dirs = [ "$webview_path/ohos_adapter/hiviewdfx_adapter/include" ] + include_dirs = [ + "$webview_path/ohos_adapter/hiviewdfx_adapter/include", + "$webview_path/ohos_nweb/include", + ] } ohos_unittest("nweb_hiviewdfx_adapter_test") { -- Gitee From a6a043072c2b392ed759e14664ff42f6df7eedac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Mon, 22 Jul 2024 13:09:23 +0000 Subject: [PATCH 065/126] update test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn b/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn index 6c81ed16..b9331569 100644 --- a/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn +++ b/test/unittest/ohos_adapter/hiviewdfx_adapter_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_unittest("nweb_hiviewdfx_adapter_test") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "init:libbegetutil", + "webview:libnweb", ] } -- Gitee From 06d27a60acfdf45d3fb46ba8cbf399bba70896ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Tue, 23 Jul 2024 01:32:40 +0000 Subject: [PATCH 066/126] update test/unittest/ohos_adapter/hiviewdfx_adapter_test/hiviewdfx_adapter_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- .../hiviewdfx_adapter_test/hiviewdfx_adapter_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 24c64312..40d4002b 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 @@ -102,6 +102,6 @@ HWTEST(HiViewDFXAdapterTest, NormalScene_01, TestSize.Level1) OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().CountOHOSTrace("test", 1); OhosAdapterHelper::GetInstance().GetHiTraceAdapterInstance().FinishOHOSTrace(); HiTraceAdapterImpl::GetInstance().IsACETraceEnable(); - EventReport::ReportCreateWbeInstanceTime(1, 1); + EventReport::ReportCreateWebInstanceTime(1, 1); } } // namespace OHOS::NWeb -- Gitee From 37fb6666116fb5a3fe7817b4ece6bce45487bcb8 Mon Sep 17 00:00:00 2001 From: chenzhiz Date: Tue, 23 Jul 2024 14:31:07 +0800 Subject: [PATCH 067/126] =?UTF-8?q?=E6=B7=BB=E5=8A=A0TDD=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E9=AB=98=E5=88=86=E6=94=AF=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenzhiz --- .../audio_adapter_impl_test.cpp | 103 ++++++++++++++++++ .../camera_adapter_impl_test.cpp | 18 +++ .../imf_adapter_impl_test.cpp | 96 ++++++++++++++++ 3 files changed, 217 insertions(+) diff --git a/test/unittest/audio_adapter_impl_test/audio_adapter_impl_test.cpp b/test/unittest/audio_adapter_impl_test/audio_adapter_impl_test.cpp index 82f7083b..04fedc21 100644 --- a/test/unittest/audio_adapter_impl_test/audio_adapter_impl_test.cpp +++ b/test/unittest/audio_adapter_impl_test/audio_adapter_impl_test.cpp @@ -255,6 +255,15 @@ public: void OnResume() override {}; }; +class AudioOutputChangeCallbackMock : public AudioOutputChangeCallbackAdapter { +public: + AudioOutputChangeCallbackMock() = default; + + virtual ~AudioOutputChangeCallbackMock() = default; + + void OnOutputDeviceChange(int32_t reason) override {}; +}; + class AudioCapturerCallbackMock : public AudioCapturerReadCallbackAdapter { public: AudioCapturerCallbackMock() = default; @@ -1094,5 +1103,99 @@ HWTEST_F(NWebAudioAdapterTest, NWebAudioAdapterTest_AudioAdapterImpl_028, TestSi deviceName = AudioSystemManagerAdapterImpl::GetInstance().GetDeviceName(DeviceType::DEVICE_TYPE_NONE); EXPECT_EQ(deviceName, DEVICE_TYPE_NONE_TEST); } + +/** + * @tc.name: NWebAudioAdapterTest_AudioAdapterImpl_029. + * @tc.desc: Audio adapter unittest. + * @tc.type: FUNC. + * @tc.require:I5HRX9 + */ +HWTEST_F(NWebAudioAdapterTest, NWebAudioAdapterTest_GetChangeReason_029, TestSize.Level1) +{ + std::array reasonArray = { + AudioStreamDeviceChangeReason::UNKNOWN, + AudioStreamDeviceChangeReason::NEW_DEVICE_AVAILABLE, + AudioStreamDeviceChangeReason::OLD_DEVICE_UNAVALIABLE, + AudioStreamDeviceChangeReason::OVERRODE, + }; + + std::shared_ptr cb = std::make_shared(); + EXPECT_NE(cb, nullptr); + auto callBack = std::make_shared(cb); + EXPECT_NE(callBack, nullptr); + + for (auto& reason : reasonArray) + callBack->GetChangeReason(reason); + + AudioAdapterDeviceChangeReason testReason = callBack->GetChangeReason(static_cast(-1)); + EXPECT_EQ(testReason, AudioAdapterDeviceChangeReason::UNKNOWN); +} + +/** + * @tc.name: NWebAudioAdapterTest_GetChangeReason_030. + * @tc.desc: Audio adapter unittest. + * @tc.type: FUNC. + * @tc.require:I5HRX9 + */ +HWTEST_F(NWebAudioAdapterTest, NWebAudioAdapterTest_OnOutputDeviceChange_030, TestSize.Level1) +{ + std::shared_ptr cb = std::make_shared(); + EXPECT_NE(cb, nullptr); + auto callBack = std::make_shared(cb); + ASSERT_NE(callBack, nullptr); + + DeviceInfo deviceInfo; + + AudioStreamDeviceChangeReason reason = AudioStreamDeviceChangeReason::UNKNOWN; + callBack->OnOutputDeviceChange(deviceInfo, reason); + + reason = AudioStreamDeviceChangeReason::NEW_DEVICE_AVAILABLE; + callBack->OnOutputDeviceChange(deviceInfo, reason); + + reason = AudioStreamDeviceChangeReason::OLD_DEVICE_UNAVALIABLE; + callBack->OnOutputDeviceChange(deviceInfo, reason); + + reason = AudioStreamDeviceChangeReason::OVERRODE; + callBack->OnOutputDeviceChange(deviceInfo, reason); + + reason = static_cast(-1); + callBack->OnOutputDeviceChange(deviceInfo, reason); + + callBack->cb_ = nullptr; + callBack->OnOutputDeviceChange(deviceInfo, reason); +} + +/** + * @tc.name: NWebAudioAdapterTest_SetAudioOutputChangeCallback_031. + * @tc.desc: Audio adapter unittest. + * @tc.type: FUNC. + * @tc.require:I5HRX9 + */ +HWTEST_F(NWebAudioAdapterTest, NWebAudioAdapterTest_SetAudioOutputChangeCallback_031, TestSize.Level1) +{ + auto audioOutputChange = std::make_shared(); + ASSERT_NE(audioOutputChange, nullptr); + int32_t retNum = audioOutputChange->SetAudioOutputChangeCallback(nullptr); + EXPECT_NE(retNum, 0); + + std::shared_ptr callback = std::make_shared(); + ASSERT_NE(callback, nullptr); + retNum = audioOutputChange->SetAudioOutputChangeCallback(callback); + EXPECT_NE(retNum, 0); + + AudioRendererOptions rendererOptions; + AudioRendererInfo renderInfo; + rendererOptions.streamInfo.samplingRate = AudioSamplingRate::SAMPLE_RATE_44100; + rendererOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM; + rendererOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S16LE; + rendererOptions.streamInfo.channels = AudioChannel::STEREO; + rendererOptions.rendererInfo = renderInfo; + audioOutputChange->audio_renderer_ = AudioRenderer::Create(rendererOptions); + ASSERT_NE(audioOutputChange->audio_renderer_, nullptr); + + retNum = audioOutputChange->SetAudioOutputChangeCallback(callback); + EXPECT_EQ(retNum, 0); +} + } // namespace NWeb } // namespace OHOS diff --git a/test/unittest/ohos_adapter/camera_adapter_impl_test/camera_adapter_impl_test.cpp b/test/unittest/ohos_adapter/camera_adapter_impl_test/camera_adapter_impl_test.cpp index e482d18b..c8d0058c 100644 --- a/test/unittest/ohos_adapter/camera_adapter_impl_test/camera_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/camera_adapter_impl_test/camera_adapter_impl_test.cpp @@ -536,6 +536,8 @@ HWTEST_F(CameraAdapterImplTest, CameraAdapterImplTest_InitCameraInput_010, TestS adapter.isCapturing_ = true; bool isExist = adapter.IsExistCaptureTask(); EXPECT_TRUE(isExist); + result = adapter.StartStream(deviceId, nullptr, nullptr); + EXPECT_NE(result, 0); result = adapter.StartStream(deviceId, captureParams, nullptr); EXPECT_NE(result, 0); adapter.status_ = CameraStatusAdapter::AVAILABLE; @@ -591,4 +593,20 @@ HWTEST_F(CameraAdapterImplTest, CameraAdapterImplTest_CameraManagerAdapterCallba adapter.statusCallback_ = nullptr; adapter.OnCameraStatusChanged(cameraStatusInfo); } + +/** + * @tc.name: CameraAdapterImplTest_CameraStatus_012 + * @tc.desc: CameraManagerAdapterCallback. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CameraAdapterImplTest, CameraAdapterImplTest_CameraStatus_012, TestSize.Level1) +{ + auto callback = std::make_shared(); + CameraManagerAdapterImpl& adapter = CameraManagerAdapterImpl::GetInstance(); + CameraStatusAdapter status = adapter.GetCameraStatus(); + + adapter.SetCameraStatus(status); +} + } // namespace OHOS::NWeb diff --git a/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp b/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp index 76290b08..635b91ac 100644 --- a/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp @@ -65,6 +65,82 @@ public: } }; +class IMFInputAttributeAdapterMock : public IMFInputAttributeAdapter { +public: + IMFInputAttributeAdapterMock() = default; + + ~IMFInputAttributeAdapterMock() override = default; + + int32_t GetInputPattern() override + { + return 0; + } + + int32_t GetEnterKeyType() override + { + return 0; + } +}; + +class IMFSelectionRangeAdapterMock : public IMFSelectionRangeAdapter { +public: + IMFSelectionRangeAdapterMock() = default; + + ~IMFSelectionRangeAdapterMock() override = default; + + int32_t GetStart() override + { + return 0; + } + + int32_t GetEnd() override + { + return 0; + } +}; + +class IMFTextConfigTest : public IMFTextConfigAdapter { +public: + IMFTextConfigTest() = default; + ~IMFTextConfigTest() override = default; + + std::shared_ptr GetInputAttribute() + { + auto mock = std::make_shared(); + return mock; + } + + std::shared_ptr GetCursorInfo() + { + auto mock = std::make_shared(); + return mock; + } + + std::shared_ptr GetSelectionRange() + { + auto mock = std::make_shared(); + return mock; + } + + uint32_t GetWindowId() + { + WVLOG_I("test GetWindowId"); + return 0; + } + + double GetPositionY() + { + WVLOG_I("test GetPositionY"); + return 0.0; + } + + double GetHeight() + { + WVLOG_I("test GetHeight"); + return 0.0; + } +}; + class IMFTextListenerTest : public IMFTextListenerAdapter { public: IMFTextListenerTest() = default; @@ -410,4 +486,24 @@ HWTEST_F(NWebIMFAdapterTest, NWebIMFAdapterTest_IMFAdapterImpl_009, TestSize.Lev privateCommand = { { "previewTextStyle", "underline" } }; listenerTest->ReceivePrivateCommand(privateCommand); } + +/** + * @tc.name: NWebIMFAdapterTest_InsertText_010. + * @tc.desc: IMF adapter unittest. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(NWebIMFAdapterTest, NWebIMFAdapterTest_InsertText_010, TestSize.Level1) +{ + auto listener = std::make_shared(); + auto config = std::make_shared(); + bool result = g_imf->Attach(listener, true, nullptr, false); + EXPECT_FALSE(result); + + result = g_imf->Attach(listener, true, config, false); + EXPECT_FALSE(result); + EXPECT_NE(g_imf->textListener_, nullptr); + g_imf->HideTextInput(); +} + } // namespace OHOS::NWeb -- Gitee From dc7e34e2dccb7f2891d2ce7baaf9f642e8e40510 Mon Sep 17 00:00:00 2001 From: fengjinyuan0804 Date: Tue, 23 Jul 2024 16:45:12 +0800 Subject: [PATCH 068/126] =?UTF-8?q?=E6=96=B0=E5=A2=9Efuzzy=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=20Signed-off-by:=20fengjinyuan0804=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bundle.json | 1 + .../ohos_adapter/audio_adapter/BUILD.gn | 4 + .../audiodevicechange_fuzzer/BUILD.gn | 89 +++++++++++++++++++ .../audiodevicechange_fuzzer.cpp | 46 ++++++++++ .../audiodevicechange_fuzzer.h | 21 +++++ .../audiodevicechange_fuzzer/corpus/init | 15 ++++ .../audiodevicechange_fuzzer/project.xml | 25 ++++++ .../audiodevicedesc_fuzzer/BUILD.gn | 46 ++++++++++ .../audiodevicedesc_fuzzer.cpp | 48 ++++++++++ .../audiodevicedesc_fuzzer.h | 21 +++++ .../audiodevicedesc_fuzzer/corpus/init | 15 ++++ .../audiodevicedesc_fuzzer/project.xml | 25 ++++++ .../audiogetdevice_fuzzer/BUILD.gn | 46 ++++++++++ .../audiogetdevice_fuzzer.cpp | 55 ++++++++++++ .../audiogetdevice_fuzzer.h | 21 +++++ .../audiogetdevice_fuzzer/corpus/init | 15 ++++ .../audiogetdevice_fuzzer/project.xml | 25 ++++++ .../audiorenderadapter_fuzzer/BUILD.gn | 89 +++++++++++++++++++ .../audiorenderadapter_fuzzer.cpp | 71 +++++++++++++++ .../audiorenderadapter_fuzzer.h | 21 +++++ .../audiorenderadapter_fuzzer/corpus/init | 15 ++++ .../audiorenderadapter_fuzzer/project.xml | 25 ++++++ .../resschedadapter_fuzzer/BUILD.gn | 55 ++++++++++++ .../resschedadapter_fuzzer/corpus/init | 15 ++++ .../resschedadapter_fuzzer/project.xml | 25 ++++++ .../resschedadapter_fuzz.cpp | 51 +++++++++++ .../resschedadapter_fuzz.h | 20 +++++ 27 files changed, 905 insertions(+) create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/audiodevicechange_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/audiodevicechange_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/audiodevicedesc_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/audiodevicedesc_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/audiogetdevice_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/audiogetdevice_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/audiorenderadapter_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/audiorenderadapter_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/resschedadapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/resschedadapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/resschedadapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp create mode 100644 test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.h diff --git a/bundle.json b/bundle.json index 9463264a..3e903462 100644 --- a/bundle.json +++ b/bundle.json @@ -171,6 +171,7 @@ "//base/web/webview/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/accesstoken_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/audio_adapter:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/resschedadapter_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/backgroundtask_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/datashareadapter_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/datatimeformat_fuzzer:fuzztest", diff --git a/test/fuzztest/ohos_adapter/audio_adapter/BUILD.gn b/test/fuzztest/ohos_adapter/audio_adapter/BUILD.gn index 88f5250c..4cf3271c 100644 --- a/test/fuzztest/ohos_adapter/audio_adapter/BUILD.gn +++ b/test/fuzztest/ohos_adapter/audio_adapter/BUILD.gn @@ -30,8 +30,11 @@ group("fuzztest") { deps += [ "audioabandon_fuzzer:AudioAbandonFuzzTest", "audiocreaterender_fuzzer:AudioCreateRenderFuzzTest", + "audiodevicechange_fuzzer:AudioDeviceChangeFuzzTest", + "audiodevicedesc_fuzzer:AudioDeviceDescFuzzTest", "audiogetchannel_fuzzer:AudioGetChannelFuzzTest", "audiogetcontent_fuzzer:AudioGetContentFuzzTest", + "audiogetdevice_fuzzer:AudioGetDeviceFuzzTest", "audiogetformat_fuzzer:AudioGetFormatFuzzTest", "audiogetlatency_fuzzer:AudioGetLatencyFuzzTest", "audiogetsampling_fuzzer:AudioGetSamplingFuzzTest", @@ -40,6 +43,7 @@ group("fuzztest") { "audiointerrupt_fuzzer:AudioInterruptFuzzTest", "audiooutputdevices_fuzzer:AudioOutputDevicesFuzzTest", "audioreleaserender_fuzzer:AudioReleaseRenderFuzzTest", + "audiorenderadapter_fuzzer:AudioRendererAdapterFuzzTest", "audiorequest_fuzzer:AudioRequestFuzzTest", "audiosetcallback_fuzzer:AudioSetCallbackFuzzTest", "audiosetstreamtype_fuzzer:AudioSetStreamtypeFuzzTest", diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/BUILD.gn new file mode 100644 index 00000000..a73ee043 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/BUILD.gn @@ -0,0 +1,89 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") +import("$webview_path/config.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AudioDeviceChangeFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer" + configs = [ "../:audio_adapter_fuzztest_config" ] + + include_dirs = [ + "$webview_path/test/ohos_nweb", + "$webview_path/ohos_adapter/audio_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "audiodevicechange_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + external_deps = [ + "ability_base:extractortool", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "ability_runtime:app_context", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "app_file_service:fileuri_native", + "background_task_mgr:bgtaskmgr_innerkits", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "certificate_manager:cert_manager_sdk", + "common_event_service:cesfwk_innerkits", + "data_share:datashare_common", + "data_share:datashare_consumer", + "eventhandler:libeventhandler", + "file_api:remote_uri_native", + "graphic_2d:libcomposer", + "graphic_2d:libnative_image", + "graphic_2d:librender_service_client", + "graphic_surface:surface", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "huks:libhukssdk", + "image_framework:image_native", + "imf:inputmethod_client", + "init:libbeget_proxy", + "init:libbegetutil", + "input:libmmi-client", + "ipc:ipc_core", + "napi:ace_napi", + "netmanager_base:net_conn_manager_if", + "pasteboard:pasteboard_client", + "relational_store:native_rdb", + "resource_schedule_service:ressched_client", + "samgr:samgr_proxy", + "time_service:time_client", + "window_manager:libdm", + ] + + if (webview_audio_enable) { + external_deps += [ + "audio_framework:audio_client", + "audio_framework:audio_renderer", + ] + } +} diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/audiodevicechange_fuzzer.cpp b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/audiodevicechange_fuzzer.cpp new file mode 100644 index 00000000..b1c73c92 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/audiodevicechange_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 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 "audiodevicechange_fuzzer.h" + +#include +#include + +#include "audio_renderer_adapter_impl.h" +#include "audio_system_manager_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + bool AudioDeviceChangeFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size == 0)) { + return false; + } + std::shared_ptr cb = nullptr; + AudioManagerDeviceChangeCallbackAdapterImpl adapter(cb); + DeviceChangeAction deviceChangeAction; + adapter.OnDeviceChange(deviceChangeAction); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AudioDeviceChangeFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/audiodevicechange_fuzzer.h b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/audiodevicechange_fuzzer.h new file mode 100644 index 00000000..c3880ec9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/audiodevicechange_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_AUDIO_DEVICE_CHANGE_FUZZER_H +#define TEST_FUZZTEST_AUDIO_DEVICE_CHANGE_FUZZER_H + +#define FUZZ_PROJECT_NAME "audiodevicechange_fuzzer" +#endif /* TEST_FUZZTEST_AUDIO_DEVICE_CHANGE_FUZZER_H */ + diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/project.xml b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicechange_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/BUILD.gn new file mode 100644 index 00000000..787b8dc6 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") +import("$webview_path/config.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AudioDeviceDescFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer" + configs = [ "../:audio_adapter_fuzztest_config" ] + + include_dirs = [ + "$webview_path/test/ohos_nweb", + "$webview_path/ohos_adapter/audio_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "audiodevicedesc_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + if (webview_audio_enable) { + external_deps = [ + "audio_framework:audio_client", + "audio_framework:audio_renderer", + ] + } +} diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/audiodevicedesc_fuzzer.cpp b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/audiodevicedesc_fuzzer.cpp new file mode 100644 index 00000000..d12eaf4e --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/audiodevicedesc_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 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 "audiodevicedesc_fuzzer.h" + +#include +#include + +#include "audio_device_desc_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + bool AudioDeviceDescFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size == 0)) { + return false; + } + int32_t id = 0; + std::string name((const char*) data, size); + std::shared_ptr deviceAdapterImpl = std::make_shared(); + deviceAdapterImpl->GetDeviceId(); + deviceAdapterImpl->GetDeviceName(); + deviceAdapterImpl->SetDeviceId(id); + deviceAdapterImpl->SetDeviceName(name); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AudioDeviceDescFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/audiodevicedesc_fuzzer.h b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/audiodevicedesc_fuzzer.h new file mode 100644 index 00000000..cb12aaf2 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/audiodevicedesc_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_AUDIO_DEVICE_DESC_FUZZER_H +#define TEST_FUZZTEST_AUDIO_DEVICE_DESC_FUZZER_H + +#define FUZZ_PROJECT_NAME "audiodevicedesc_fuzzer" +#endif /* TEST_FUZZTEST_AUDIO_DEVICE_DESC_FUZZER_H */ + diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/project.xml b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiodevicedesc_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/BUILD.gn new file mode 100644 index 00000000..dadb9a59 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") +import("$webview_path/config.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AudioGetDeviceFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer" + configs = [ "../:audio_adapter_fuzztest_config" ] + + include_dirs = [ + "$webview_path/test/ohos_nweb", + "$webview_path/ohos_adapter/audio_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "audiogetdevice_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + if (webview_audio_enable) { + external_deps = [ + "audio_framework:audio_client", + "audio_framework:audio_renderer", + ] + } +} diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/audiogetdevice_fuzzer.cpp b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/audiogetdevice_fuzzer.cpp new file mode 100644 index 00000000..d9dcc0c1 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/audiogetdevice_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 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 "audiogetdevice_fuzzer.h" + +#include +#include + +#include "audio_renderer_adapter_impl.h" +#include "audio_system_manager_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + bool AudioGetDeviceFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size == 0)) { + return false; + } + int32_t deviceId = 0; + bool isInput = 0; + std::string language((const char*) data, size); + AudioSystemManagerAdapterImpl::GetInstance().GetDeviceName(DeviceType::DEVICE_TYPE_INVALID); + AudioSystemManagerAdapterImpl::GetInstance().GetDevices(AdapterDeviceFlag::OUTPUT_DEVICES_FLAG); + AudioSystemManagerAdapterImpl::GetInstance().SelectAudioDeviceById(deviceId, isInput); + AudioSystemManagerAdapterImpl::GetInstance().GetDefaultOutputDevice(); + AudioSystemManagerAdapterImpl::GetInstance().GetDefaultInputDevice(); + AudioSystemManagerAdapterImpl::GetInstance().UnsetDeviceChangeCallback(); + AudioSystemManagerAdapterImpl::GetInstance().SetLanguage(language); + std::shared_ptr callback = nullptr; + AudioSystemManagerAdapterImpl::GetInstance().SetAudioManagerInterruptCallback(callback); + AudioSystemManagerAdapterImpl::GetInstance().UnsetDeviceChangeCallback(); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AudioGetDeviceFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/audiogetdevice_fuzzer.h b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/audiogetdevice_fuzzer.h new file mode 100644 index 00000000..6f12b5f9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/audiogetdevice_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_AUDIO_GET_DEVICE_FUZZER_H +#define TEST_FUZZTEST_AUDIO_GET_DEVICE_FUZZER_H + +#define FUZZ_PROJECT_NAME "audiogetdevice_fuzzer" +#endif /* TEST_FUZZTEST_AUDIO_GET_DEVICE_FUZZER_H */ + diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/project.xml b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiogetdevice_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..fd51720b --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/BUILD.gn @@ -0,0 +1,89 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") +import("$webview_path/config.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AudioRendererAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer" + configs = [ "../:audio_adapter_fuzztest_config" ] + + include_dirs = [ + "$webview_path/test/ohos_nweb", + "$webview_path/ohos_adapter/audio_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "audiorenderadapter_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + external_deps = [ + "ability_base:extractortool", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "ability_runtime:app_context", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "app_file_service:fileuri_native", + "background_task_mgr:bgtaskmgr_innerkits", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "certificate_manager:cert_manager_sdk", + "common_event_service:cesfwk_innerkits", + "data_share:datashare_common", + "data_share:datashare_consumer", + "eventhandler:libeventhandler", + "file_api:remote_uri_native", + "graphic_2d:libcomposer", + "graphic_2d:libnative_image", + "graphic_2d:librender_service_client", + "graphic_surface:surface", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "huks:libhukssdk", + "image_framework:image_native", + "imf:inputmethod_client", + "init:libbeget_proxy", + "init:libbegetutil", + "input:libmmi-client", + "ipc:ipc_core", + "napi:ace_napi", + "netmanager_base:net_conn_manager_if", + "pasteboard:pasteboard_client", + "relational_store:native_rdb", + "resource_schedule_service:ressched_client", + "samgr:samgr_proxy", + "time_service:time_client", + "window_manager:libdm", + ] + + if (webview_audio_enable) { + external_deps += [ + "audio_framework:audio_client", + "audio_framework:audio_renderer", + ] + } +} diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/audiorenderadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/audiorenderadapter_fuzzer.cpp new file mode 100644 index 00000000..68831000 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/audiorenderadapter_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 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 "audiorenderadapter_fuzzer.h" + +#include +#include + +#include "audio_renderer_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + bool AudioRendererAdapterFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size == 0)) { + return false; + } + AudioRendererAdapterImpl audioRendererAdapterImpl; + uint8_t buffer[100]; + size_t bufferSize = sizeof(buffer); + float volume = 0.5; + AudioAdapterSamplingRate samplingRate = AudioAdapterSamplingRate::SAMPLE_RATE_44100; + AudioAdapterEncodingType encodingType = AudioAdapterEncodingType::ENCODING_PCM; + AudioAdapterSampleFormat sampleFormat = AudioAdapterSampleFormat::SAMPLE_S16LE; + AudioAdapterChannel channel = AudioAdapterChannel::STEREO; + AudioAdapterContentType contentType = AudioAdapterContentType::CONTENT_TYPE_MUSIC; + AudioAdapterStreamUsage streamUsage = AudioAdapterStreamUsage::STREAM_USAGE_MEDIA; + audioRendererAdapterImpl.Create(nullptr, ""); + audioRendererAdapterImpl.Start(); + audioRendererAdapterImpl.Pause(); + audioRendererAdapterImpl.Stop(); + audioRendererAdapterImpl.Release(); + audioRendererAdapterImpl.Write(buffer, bufferSize); + uint64_t latency; + audioRendererAdapterImpl.GetLatency(latency); + audioRendererAdapterImpl.SetVolume(volume); + audioRendererAdapterImpl.GetVolume(); + audioRendererAdapterImpl.SetAudioRendererCallback(nullptr); + audioRendererAdapterImpl.SetAudioOutputChangeCallback(nullptr); + audioRendererAdapterImpl.SetInterruptMode(true); + audioRendererAdapterImpl.IsRendererStateRunning(); + audioRendererAdapterImpl.GetAudioSamplingRate(samplingRate); + audioRendererAdapterImpl.GetAudioEncodingType(encodingType); + audioRendererAdapterImpl.GetAudioSampleFormat(sampleFormat); + audioRendererAdapterImpl.GetAudioChannel(channel); + audioRendererAdapterImpl.GetAudioContentType(contentType); + audioRendererAdapterImpl.GetAudioStreamUsage(streamUsage); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AudioRendererAdapterFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/audiorenderadapter_fuzzer.h b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/audiorenderadapter_fuzzer.h new file mode 100644 index 00000000..c3880ec9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/audiorenderadapter_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_AUDIO_DEVICE_CHANGE_FUZZER_H +#define TEST_FUZZTEST_AUDIO_DEVICE_CHANGE_FUZZER_H + +#define FUZZ_PROJECT_NAME "audiodevicechange_fuzzer" +#endif /* TEST_FUZZTEST_AUDIO_DEVICE_CHANGE_FUZZER_H */ + diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiorenderadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..a602042c --- /dev/null +++ b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ResSchedAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = + "$webview_path/test/fuzztest/ohos_adapter/resschedadapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/res_sched_adapter/src", + "$webview_path/ohos_interface/include/ohos_adapter", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "resschedadapter_fuzz.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ResSchedAdapterFuzzTest", + ] +} diff --git a/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp new file mode 100644 index 00000000..59585748 --- /dev/null +++ b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 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 "resschedadapter_fuzz.h" +#include "res_sched_client_adapter.h" + +#include +#include + +using namespace OHOS::NWeb; + +namespace OHOS { + bool ResSchedAdapterFuzzTest(const uint8_t* data, size_t size) + { + if ((data == nullptr) || (size == 0)) { + return false; + } + int32_t windowId = 0; + int32_t nwebId = 0; + pid_t pid = 0; + ResSchedClientAdapter resSchedClientAdapter; + resSchedClientAdapter.ReportVideoPlaying(ResSchedStatusAdapter::WEB_ACTIVE, pid); + resSchedClientAdapter.ReportScreenCapture(ResSchedStatusAdapter::WEB_ACTIVE, pid); + resSchedClientAdapter.ReportRenderProcessStatus(ResSchedStatusAdapter::WEB_ACTIVE, pid); + resSchedClientAdapter.ReportNWebInit(ResSchedStatusAdapter::WEB_ACTIVE, nwebId); + resSchedClientAdapter.ReportWindowId(windowId, nwebId); + resSchedClientAdapter.ReportScene( + ResSchedStatusAdapter::WEB_ACTIVE, ResSchedSceneAdapter::KEYBOARD_CLICK, nwebId); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::ResSchedAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.h b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.h new file mode 100644 index 00000000..e76feeff --- /dev/null +++ b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_RES_SCHED_ADAPTER_FUZZ_H +#define TEST_FUZZTEST_RES_SCHED_ADAPTER_FUZZ_H + +#define FUZZ_PROJECT_NAME "resschedadapter_fuzzer" +#endif /* TEST_FUZZTEST_RES_SCHED_ADAPTER_FUZZ_H */ -- Gitee From 6d8fe72a592dd82350c952bea0e295e7b4c5b338 Mon Sep 17 00:00:00 2001 From: chenzhiz Date: Tue, 23 Jul 2024 21:05:29 +0800 Subject: [PATCH 069/126] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenzhiz --- .../audio_adapter_impl_test/audio_adapter_impl_test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unittest/audio_adapter_impl_test/audio_adapter_impl_test.cpp b/test/unittest/audio_adapter_impl_test/audio_adapter_impl_test.cpp index 04fedc21..e7efa391 100644 --- a/test/unittest/audio_adapter_impl_test/audio_adapter_impl_test.cpp +++ b/test/unittest/audio_adapter_impl_test/audio_adapter_impl_test.cpp @@ -1127,7 +1127,9 @@ HWTEST_F(NWebAudioAdapterTest, NWebAudioAdapterTest_GetChangeReason_029, TestSiz for (auto& reason : reasonArray) callBack->GetChangeReason(reason); - AudioAdapterDeviceChangeReason testReason = callBack->GetChangeReason(static_cast(-1)); + AudioAdapterDeviceChangeReason testReason = callBack->GetChangeReason( + static_cast(-1) + ); EXPECT_EQ(testReason, AudioAdapterDeviceChangeReason::UNKNOWN); } -- Gitee From 7d9c3ab5a3d6fa4334544b0ba3f1d295930b2e1b Mon Sep 17 00:00:00 2001 From: huangjunjie Date: Tue, 23 Jul 2024 19:14:11 +0800 Subject: [PATCH 070/126] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UT=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangjunjie --- OAT.xml | 1 + test/resource/image/images/test.heic | Bin 0 -> 7879 bytes test/resource/image/ohos_test.xml | 22 ++++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 test/resource/image/images/test.heic create mode 100644 test/resource/image/ohos_test.xml diff --git a/OAT.xml b/OAT.xml index 4aa4f7ad..71e70d97 100644 --- a/OAT.xml +++ b/OAT.xml @@ -64,6 +64,7 @@ Note:If the text contains special characters, please escape them according to th + diff --git a/test/resource/image/images/test.heic b/test/resource/image/images/test.heic new file mode 100644 index 0000000000000000000000000000000000000000..01e1ebb1627ec1a133b227e8f25d3fb4b82a87e8 GIT binary patch literal 7879 zcmYjSWmFtWlVxy+1lPgcA-EIV-7V3gfIs;jF1Gz<(3skH~h#Svu93G)~Ku&ouy!q&>u0tN=a?r7y<{?GYeP}*8Lxcyhc zz_@@cJpR@HGNud2!|^``;O|Zi0y$a#uZ8#5u!8-^{OhyzwD?c4N|1}2%ip6okc)-$ zU-tOxkOBbA{>uNt;2h@p<^CQ91`CejZz7R603Go5_D=xZ|1E=5SaHg~UOGv@e{%o7 zD-VGS0J%vqk>?VC&?G+WU#(bD{S8I>2x2zPC=OVsk9e&oE7V8sP81T)b(+h7SPy>){cC&G&oAog87{ z`h)WR7$TKkCk+<7ZP%wp1+*{BcLq|LSZbniLUZUurjo{Ro` zND`m@-0-}b67kBZlwziR!2X)^O4bvmw~Nekd^oG+PJ*#MZuBVh$6?@!NFQD>EYb|z zE#$j9&uga=4;ul@XuJOL;&v8b?O!YuX3>VSKy7t~>i_QcJE%h%szVDBXvKHHX7sc< z7`Th=MRd0fO?p0|v#W+O3+N3S9X#xs9D+j45a}v!%gURC6FaUsXE0CW=s#QT2kyN` zW)&axs@dwyMJ1#3TN>hN&3B%``093`%Y%rm&^m2ZG!S#)p(?lz9eLn0(QoxIW3e@2h zcB>YBcre>E$OWqM9HLrRxrCu>3(P=g21MfR1Bgk9e z+lfiyj8M97d7?pgEqcQX|Iw_o>L7XxP8I-dQ^VmX>fwLaL|3In{*3LVGRM4tD4sTs z9)LXLO~o3nhV-33@D#lH_GMs1v~?M#lSz7qm1aTO{AiM*kVdl>WreXyst7V$r-$jx z<8lvEK)pbT6wl|=pu26OcXMNPr{mFwp50b)ifURYrg$tmW+Y%Qf{E?UX}A*}mMi49 zU~(kM0ZESBW9qC&UlJA>0$}An34-fJZA;DG=0h)uC(X$JOLej@13cOplZ)M_Mdws6o{!hKZLdUIVCKdM zj~eaOR?HX0^x)e*D@lfQ+r6u~*yus#kELYVeiNJ>bU^NkiwQ)vWGu-BM|g|SsblL0 zt9aBT)e$@OTC@3c3%Ue3OBY!h75x()?iBMv&BV23Fye+YmqwKmwYlx4yj2CH@Q5oA z3llH~yU)vy>P4D<6@Sb9Hnj3-uAco;^ZTEAXwEo$Wh|ViMR572TqzhlMMWWj&6g3V z_nwPzmcntEKC=B+X;-sgkBnz~ubXmlHT|EO7D!zbdc&<~?b}a07v70>^1EJFza{fl5a*;GFAz_rO@`_P8_l6%^=Bt5wk#b8Be)fe zKJK9xE#D?A!^+pr8LeWF-LREj-gHfe!G^$LB5G~*B>M#Y77Yo%2#wuiB!&~3Y})1R zZ(R7~j#8j${;5rA-u8L4Mg4liXwg1UC&KMFOWTT{_ilxgPzifpMD4Y??og@gUg*vn z0tjI>NK)9i5@TP%+It!5qtlEhBADuYrudqK+!)WGk96YJw#7+2z+-Cgylmk3Y_R{w zB=Mvdsr|Bz@iVJGFiFC@L7Y9r9984QAmD?-1%$y%4D=lw~a<9_eEf zqkw&Ee!o8PgkwI7mV_ML(tZ4BP0w^0-c@HPkrJ~1b>?BC zXcm-3@^u<*recBnIwR02k`XBkuxxp4*<#{S!o^`zk0G3Q6-JC#x5F4QQ&}V2;Xr_C zejd`f;}9)VxHENE7Z@_}oEM97w26EvIh=RH)DT})gE0&FO+P`MyBEW%(6b$na;C33 zCQkn=r#LW)%#~Zv&k`U|n0YbC3SHOLtSrRTJ^FV3jhr33VN7}R<1g`*?XfjQL;5M$ zERHzIX-!afZe_v~8>;>(NB2|*%>$C6+ZAhrz!`wg#YbR&^NF`@O`2#m~uuNXmi zSQTDPGew56nNz-hG6#%Vg$3d#C~>*09J+{!-Vgr4k@d~3{`950Yp6xqG%8@55`Vi= zXGo{KY#Mn*dm4iy-oB}icVO{{?rMHY9vy4&XV&BoXzDj?ClZODJC(uV7c>~kT3N^$ z!pXaNI8yjLyHwe)$FmkG$Was=S z8gBc-pS3)*2~Leu0ndPdzjp-NN;Ap*%4|9$$b6k^&6Cg@8ms_D~3y^=$$r{Ij%Yud*M1H7o6k4>#eXJ|g+SMN1geC7fFZMk=gM0nt zrZj42w0n5el0kf%t1@I9DfHEkeCxHB3M1ZESH{G z5eovkMf;jcD(p!|>ewbf5^Lq#P}bZ!f5q(xein|9iItK^CaT@HS9&5c=`@c7J2x~a zLR1Jcsb@aT8!G;~Ud-NNiaJoD`O~xE!>cCbLE?u3|GjtQmR51x_H9PplX045?@8;C z2}m4-s9DWEFYT2A7#Rl>m(;)8??d8&2XeAIKy+FtGRNqzEopibc9BOT=Ndy zwgko%q+e0wIBbb?7Y&)S8G+9{9G(>VtiV7DcO6qE0hz!mLEP^pADcRuP9iqu^%?Ni z#-KH)_ag4SbdRDC(^<_Ism=>cc~{`Zpz}WzC-y=s;iDm=NaY zN{k5J1u2FGv~yeef>EF%vN>joUv1)aZNW3U0^qYI=jf&J`V`;h^~IV0~&=;%F{@|K8JYOHUZdR-Y z#%MQ^pY5Q@S%jlTg*e$W)6Nh#v@YfpCh7ak(f4cR9qn_Y?QUW5i=4b%?t7A5__D!^RC7(WjkHy?fK6MLJm zI+ZP(=bM&jH>ctlJM3Jdq+=O1CNQMHPyhT?;H9x6>Q9gl;fAiCi^G@q++RZ!^xXYr z=&RnDfKO7sI-gW!$Ti>)9prIs2w%)c6!%GqgUWv16f>vwjT^5HfntR*y<^2$7J!ND z#owlc~A`B|dFOD!9t0BDu^8M2qm+by8~HW0xVLtMz85taisN`Ksf2d3yknhraYn2n>DC%EiX{aR zgLL?N&jZsqzz@sR-9J6=g)7j^mlGB3Gkc5u{HZ<)EQr!(pg85mZM+qLk%CJ!XNtIp zRRhcFE)e|11Ldpe{QTD-3|5+4fnPAgl{j`3x{o)%yqhKVi^0m#d9@yCGiUZAKf5LM z=2{rcm(JK-=syP!K%#$5B);?H|LrD8x9J-shI}3{JSW`wEV@$>w%dpn)(pixV6Mu4YEQp20VW#3yBmvo&;tHX2uYAa`iCTW<|P zoCC`-=Xy@%U}A*6-OoqpW{ZQXOr zWiIbu;=o2Ij*!AIDZ1=oahnI92M0&iSK1LjU6Ej8Tv|~?dHa?y>zNmL_SXL#!$>H5 zFb#4_phUoLomXgxM&9dL^Mq^r#*8;obex`85BV*JL2%+*I|(_{aQ_a^F|##4k5!&wyE%*|!?oqU)+f%mn&qC*X zi8bT1=tFIK&C{E&Hpg_>mc5;d9rKIb-$yr+m`e|32SN|mX|v)eMck#a`^CrCDeYK>~8HCacu>^=(Wr?zS5b9V9QtDo@ zaX#BNGp=;zH*;~)?ue^T%_B#<;wwRC9dcUcRPSkF(9VKt(gp)rNk-)Ft6)4z+&(eG_=9E)riTqvA#7WjH6BM8a$n5*@!n?H>wdBDe z$`0)|EzS6l31(4S=8H3qTZwlz5gtnu{A zW86+9W3UHu4yf>Udw(L91*L{1G&yTSWGPspwjae$SuCOs_5=L3#w9tBr?-AEcP&3GZqgV(0iUcoJR6I&#>n-WP~sB-no89DgO*BLP>HKJ{>he zgKVk{b#|Y`QB(F#>(zkV-v{Bx*YQTNW}7fiIesqjLUL+E@R zX4j28NO0t%ACvPY@-w8UcrP-absRah#f$|`EX+brFsq~2Ja}VyAlsXnrS~suI9$e@ zpQ@kPv@*RePaTVDz8nR~R6=E`A-}X>kJg&G17h@qbIi;Gw-$%Fw#i8z&c$E{YHNMe zOc~XmK8!Ba9@eWhou}4k1tg0uIUf>Gl-Zfb?Yd8Tlt3H^IZa0zl#Fu# zX07`A-`{E7KT`D@%wC7CYAaOgC7}PRA}Kr5dtxw={;`djfUr^TTlv1``_bx*6XAie$p7-?FTbm?S3Rni70z?Dxg@w4= zKk0B@uQa6XsgD1?1A@prvY4yG?)z7`_yg%S2dQv?fU~2gNP5mZB(xr|wHYwfg;-5D ziA%b0>Dm_?u(_F_bi~fg9@*K}|DjS)Y(*5PBs_j7@v}zz^`Ppi-If(|c(k#H@Jh~v z>~qHA(iz;T4d~MJUOJd{?28v!qoYqiOivp3=AocO64>j}t!VI&NhLknO%XSG=Dh)) zX}RR%Ag@>2wgaW@BO52JSa(AR1o$#|7` z7U9MM7v_op=rqt$OKe7MWSls`FfVrHe_X@&HNyEI-p~4i%HDAdo0+G3?$Rp%v zg#Yy^dMwL%Y$0XR$CBC#jka6SWOscQypCeQ<9$(GHIdWp5N|a5yK$GDn0 zzsA_tCeCOO?QACK(Z55$G~ShnGoV&VMso4sC-QB3x49ac2mP2 z>e(3iny+si&Z7{kI)-jqvfSY{U>B=zR3;Inrr+-lf%3jo^jBBwFh@%V(5#$H(C&JB zH|_D{cNOdx0r3N|qV)qLMQ6+g8rcJ^=@^Wtr5QX5sYqHYf!|z|&!BvJsf0b>ABS6% zO{6#Lm`?J{-io9+wLkDC)T*TpBWmW+8?L^Mt)4fxH?ZE_%8VZ-g@rHNQbEeur@=&2GcA% zkvtf}y=#*gG z)uxQuV;*T)9}4zVxt*j@Wdu~ITfXW2Pv z_TC#k4Y-^aruJ0O$z2ZM*Aq#~D*}J-b9s*f9%eLL@$|Joz17O*#;0pmlWB2p-BO15 zCObM~RL^wjn)-{aoWqmSt~$0S$KfKjjm6ckXe&QOqEdp_rt7v&AH9jbBmQx!6lC^XT$aRar+4$Zq;c%Y6}xN_ejD^|)$sfq zdV9UKX&Pf0-s%lGQKm&=p5fkPG=Y~?Mom*8s-~{*{D=;3Jc-iNw-x^U>Ko@m1!6x0 z1_>l7XED2(g^28tlie3TALWQ|i!32_!(fY%+i5H$IpUN6K6<_BPLz7VRakB@(tAuC z%SKzbIZnH1f@R{F`tcMIy*|T~S5O<{P*oOVSAJ7i!r-M#G3zkx{3uGrpkP1fQe?dT zuCgjaeA#${M~pC1ePrcEQ@NX2e`DN@)lGz7XY@h6wan}{|IF$_Px>WtS%(Hf9X>zF zp*{1uB4V^2xLjUX{as7B_W_d$WZG~(%DL{Om5P|5UUInbwefX)D)n)vjUA#8Gwd(V z9@#Q4K+30hXi}WNY#b%+=V72|k;O)6Mc7R(#?+KUxb&N4%*xqGtCaM!MN-0g)|Y{{ zR)m}fJ!)e~q0pATS`?4Xle*3d@ZjYV;alu}-CLVFLj6M#?$Hg03k*|?AkKYW?#P+p zF`7;fWHbt^d0`YJ!{l4kEoAgLOhu1R1D?H5BT=3ETc3opj;1cg<+;Y7Aj9{?GW$;g zvA?y$!wJj%%8`T(@|7Nq)sG(6B%PXZibk_DSjiD)dI;+y3s+$Vz~9G+$i1{oN{n%3 z11`lLr#%h=ZlA%1K35nI(ZI#xn;b(kmU`Ub=uX;9sS4qlt};4`<9GvtpfrQv)|SP> zs=|O9D!s}hPJW!cUawjqO5kNhK&7KimF(npVnc+ucHw?o1b{K17$BurDE71z6Grt^ zUbduLKAXBds}0-=QchMA!R%9gPp=981s#_r=;tMsXfRh%-v0iBtg}#Fa?W9|*=|p4 zQ}Xo?b#vCA?WG!OlFYI2tGHFziggBaW~#K2ELFQbk%OM~sGoS$Q8SEzoPyyi4Z}7O zF?nmkw%?J>eXewJxU;hC-|`jv^KL_?Tyr@Q=$&Y8cTn_7+|@<2Wvo z3X*`^y}*#Gmmb6}k9r#sQ44G;)3B0h`)kWwBh zS@rFDINAj3PBOD&rb;o{0S@N-X=MSwK5vm%>}N!6%T_D{B9ufZB~u(M2TENRtdQ5T&~xze$!bR#AMugB@NU@mcd+>K6;LP641sW8@^9LHy zab)Yajd9T#NC4zM_fCqSqO?y#$)sjaDJ9lfKWtFg?*f%~CiTDz!rrD@#D>-_;rJ|WT^&0Xu$gT`5hiph1RY0T zn$ya8&}#emFH_R8>(hQGIIpwWc^DE<*TS19rMl0Sh+LjsXFSTn^-xTl*-2esK-Mq> zKNavZg0bPysrk(O$f#izobl1Y{arTBZlF#6i&&+~Tb`;kPRn56Q4CeIS%1($S5?sS zmf9-+Ei3ckll#GuLfM?%_*G@4tIpKNd;}%x8{7$0*FQwHyvq$pztJF7`nhQoDyavR zxdxBs#h~$_%7>mNp3E_C?LQFdM_ARYDWe$Qt}BT`EoQq+U{;F)CZq)B>}#WVCdKT4lTydBC{ v>QtRQU#Ve~>Vt&gqr6le`=k|#Vg^7TYw$WI@+xfdE*8qwsVPtO_rU)F4~*sC literal 0 HcmV?d00001 diff --git a/test/resource/image/ohos_test.xml b/test/resource/image/ohos_test.xml new file mode 100644 index 00000000..9ed25a0f --- /dev/null +++ b/test/resource/image/ohos_test.xml @@ -0,0 +1,22 @@ + + + + + + + + -- Gitee From ec1cccdac9d2b1b21f74be2051fa71e9b3c074cd Mon Sep 17 00:00:00 2001 From: huangjunjie Date: Tue, 23 Jul 2024 13:38:50 +0000 Subject: [PATCH 071/126] update test/resource/image/ohos_test.xml. Signed-off-by: huangjunjie --- test/resource/image/ohos_test.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/resource/image/ohos_test.xml b/test/resource/image/ohos_test.xml index 9ed25a0f..ef51afd0 100644 --- a/test/resource/image/ohos_test.xml +++ b/test/resource/image/ohos_test.xml @@ -1,5 +1,5 @@ - + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..2b8fe7e6 --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/BUILD.gn @@ -0,0 +1,57 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("NativeImageAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/graphic_adapter/include", + "$webview_path/ohos_nweb/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "nativeimageadapter_fuzzer.cpp" ] + + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_runtime:app_manager", + "c_utils:utils", + "graphic_2d:libcomposer", + "graphic_surface:surface", + "hilog:libhilog", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":NativeImageAdapterFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/nativeimageadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/nativeimageadapter_fuzzer.cpp new file mode 100644 index 00000000..d48cca8e --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/nativeimageadapter_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * 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 "nativeimageadapter_fuzzer.h" +#define CAMERA_MANAGER_ADAPTER_IMPL + +#define private public +#include "iconsumer_surface.h" +#include "native_image_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + +bool NativeImageAdapterFuzzTest(const uint8_t* data, size_t size) +{ + std::shared_ptr imagerAdapter = std::make_shared(); + imagerAdapter->UpdateSurfaceImage(); + imagerAdapter->AquireNativeWindowFromNativeImage(); + imagerAdapter->AttachContext(1); + imagerAdapter->DetachContext(); + uint32_t textureId = 1; + uint32_t textureTarget = 1; + imagerAdapter->CreateNativeImage(textureId, textureTarget); + imagerAdapter->UpdateSurfaceImage(); + imagerAdapter->AquireNativeWindowFromNativeImage(); + imagerAdapter->AttachContext(1); + imagerAdapter->DetachContext(); + imagerAdapter->GetTimestamp(); + float matrix[16] = { 0 }; + imagerAdapter->GetTransformMatrix(matrix); + uint64_t surfaceId = 1; + imagerAdapter->GetSurfaceId(&surfaceId); + imagerAdapter->SetOnFrameAvailableListener(nullptr); + imagerAdapter->UnsetOnFrameAvailableListener(); + imagerAdapter->DestroyNativeImage(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::NativeImageAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/nativeimageadapter_fuzzer.h b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/nativeimageadapter_fuzzer.h new file mode 100644 index 00000000..e998db53 --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/nativeimageadapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H +#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H + +#define FUZZ_PROJECT_NAME "nativeimageadapter_fuzzer" +#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/nativeimageadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..6f29d0bd --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/BUILD.gn @@ -0,0 +1,59 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("VsyncAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/graphic_adapter/include", + "$webview_path/ohos_nweb/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "vsyncadapter_fuzzer.cpp" ] + + defines = [ "NWEB_CAMERA_ENABLE" ] + + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_runtime:app_manager", + "c_utils:utils", + "graphic_2d:libcomposer", + "graphic_surface:surface", + "hilog:libhilog", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":VsyncAdapterFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/vsyncadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/vsyncadapter_fuzzer.cpp new file mode 100644 index 00000000..03db3cbe --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/vsyncadapter_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * 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 "vsyncadapter_fuzzer.h" + +#include + +#define private public +#include "vsync_adapter_impl.h" +#undef private + +using namespace OHOS::NWeb; + +namespace OHOS { +static void OnVsyncCallback() {} + +bool CameraManagerAdapterFuzzTest(const uint8_t* data, size_t size) +{ + VSyncAdapterImpl& adapter = VSyncAdapterImpl::GetInstance(); + adapter.Init(); + adapter.Init(); + + VSyncAdapterImpl vsyncAdapter; + void* client = nullptr; + adapter.OnVsync(1, client); + client = &vsyncAdapter; + adapter.OnVsync(1, client); + adapter.VsyncCallbackInner(1); + adapter.GetVSyncPeriod(); + adapter.SetFrameRateLinkerEnable(true); + adapter.SetFramePreferredRate(0); + adapter.frameRateLinker_ = nullptr; + adapter.SetFrameRateLinkerEnable(true); + adapter.SetFramePreferredRate(0); + adapter.vsyncHandler_ = nullptr; + adapter.SetOnVsyncCallback(OnVsyncCallback); + adapter.SetOnVsyncEndCallback(OnVsyncCallback); + adapter.OnVsync(1, client); + adapter.SetIsGPUProcess(false); + + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::CameraManagerAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/vsyncadapter_fuzzer.h b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/vsyncadapter_fuzzer.h new file mode 100644 index 00000000..ece410e1 --- /dev/null +++ b/test/fuzztest/ohos_adapter/graphic_adapter/vsyncadapter_fuzzer/vsyncadapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H +#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H + +#define FUZZ_PROJECT_NAME "cameramanageradapter_fuzzer" +#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/interfaces/createaafwk_fuzzer/createaafwk_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/createaafwk_fuzzer/createaafwk_fuzzer.cpp index 4e73d428..eb0a5cc9 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createaafwk_fuzzer/createaafwk_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/createaafwk_fuzzer/createaafwk_fuzzer.cpp @@ -22,16 +22,16 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateAafwkFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - auto &helper = OhosAdapterHelper::GetInstance(); - helper.CreateAafwkAdapter(); - return true; +bool CreateAafwkFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + auto& helper = OhosAdapterHelper::GetInstance(); + helper.CreateAafwkAdapter(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/createaafwk_fuzzer/createaafwk_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/createaafwk_fuzzer/createaafwk_fuzzer.h index 773f3d28..a972192d 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createaafwk_fuzzer/createaafwk_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/createaafwk_fuzzer/createaafwk_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "createaafwk_fuzzer" #endif /* TEST_FUZZTEST_CREATE_AAFWK_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/interfaces/createaudiorender_fuzzer/createaudiorender_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/createaudiorender_fuzzer/createaudiorender_fuzzer.cpp index 2e10dda1..5bc412b5 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createaudiorender_fuzzer/createaudiorender_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/createaudiorender_fuzzer/createaudiorender_fuzzer.cpp @@ -22,15 +22,15 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateAudioRenderFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - OhosAdapterHelper::GetInstance().CreateAudioRendererAdapter(); - return true; +bool CreateAudioRenderFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + OhosAdapterHelper::GetInstance().CreateAudioRendererAdapter(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/createaudiorender_fuzzer/createaudiorender_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/createaudiorender_fuzzer/createaudiorender_fuzzer.h index 3f1ae4d3..0cb93c3c 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createaudiorender_fuzzer/createaudiorender_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/createaudiorender_fuzzer/createaudiorender_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "createaudiorender_fuzzer" #endif /* TEST_FUZZTEST_CREATE_AUDIO_RENDER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/interfaces/createaudiosystem_fuzzer/createaudiosystem_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/createaudiosystem_fuzzer/createaudiosystem_fuzzer.cpp index b3b67c25..9ba702b5 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createaudiosystem_fuzzer/createaudiosystem_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/createaudiosystem_fuzzer/createaudiosystem_fuzzer.cpp @@ -22,15 +22,15 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateAudioSystemFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - OhosAdapterHelper::GetInstance().GetAudioSystemManager(); - return true; +bool CreateAudioSystemFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + OhosAdapterHelper::GetInstance().GetAudioSystemManager(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/createaudiosystem_fuzzer/createaudiosystem_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/createaudiosystem_fuzzer/createaudiosystem_fuzzer.h index 3d3f0f59..701efa2a 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createaudiosystem_fuzzer/createaudiosystem_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/createaudiosystem_fuzzer/createaudiosystem_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "createaudiosystem_fuzzer" #endif /* TEST_FUZZTEST_CREATE_AUDIO_SYSTEM_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/interfaces/createdisplaymgr_fuzzer/createdisplaymgr_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/createdisplaymgr_fuzzer/createdisplaymgr_fuzzer.cpp index 2da433b6..e5c9cb4b 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createdisplaymgr_fuzzer/createdisplaymgr_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/createdisplaymgr_fuzzer/createdisplaymgr_fuzzer.cpp @@ -22,15 +22,15 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateDisplayMgrFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - OhosAdapterHelper::GetInstance().CreateDisplayMgrAdapter(); - return true; +bool CreateDisplayMgrFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + OhosAdapterHelper::GetInstance().CreateDisplayMgrAdapter(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/createdisplaymgr_fuzzer/createdisplaymgr_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/createdisplaymgr_fuzzer/createdisplaymgr_fuzzer.h index b4e20916..4cc2fe16 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createdisplaymgr_fuzzer/createdisplaymgr_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/createdisplaymgr_fuzzer/createdisplaymgr_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "createdisplaymgr_fuzzer" #endif /* TEST_FUZZTEST_CREATE_DISPLAY_MGR_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/interfaces/creategetdatabase_fuzzer/creategetdatabase_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/creategetdatabase_fuzzer/creategetdatabase_fuzzer.cpp index c6e603e5..6b57568a 100644 --- a/test/fuzztest/ohos_adapter/interfaces/creategetdatabase_fuzzer/creategetdatabase_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/creategetdatabase_fuzzer/creategetdatabase_fuzzer.cpp @@ -22,15 +22,15 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateGetDataBaseFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - OhosAdapterHelper::GetInstance().GetOhosWebDataBaseAdapterInstance(); - return true; +bool CreateGetDataBaseFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + OhosAdapterHelper::GetInstance().GetOhosWebDataBaseAdapterInstance(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/creategetdatabase_fuzzer/creategetdatabase_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/creategetdatabase_fuzzer/creategetdatabase_fuzzer.h index ca2a63ea..f4efaf24 100644 --- a/test/fuzztest/ohos_adapter/interfaces/creategetdatabase_fuzzer/creategetdatabase_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/creategetdatabase_fuzzer/creategetdatabase_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "creategetdatabase_fuzzer" #endif /* TEST_FUZZTEST_CREATE_GET_DATA_BASE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/interfaces/creategetpasteboard_fuzzer/creategetpasteboard_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/creategetpasteboard_fuzzer/creategetpasteboard_fuzzer.cpp index d64b0bb2..1edef752 100644 --- a/test/fuzztest/ohos_adapter/interfaces/creategetpasteboard_fuzzer/creategetpasteboard_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/creategetpasteboard_fuzzer/creategetpasteboard_fuzzer.cpp @@ -22,15 +22,15 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateGetPasteBoardFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - OhosAdapterHelper::GetInstance().GetPasteBoard(); - return true; +bool CreateGetPasteBoardFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + OhosAdapterHelper::GetInstance().GetPasteBoard(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/creategetpasteboard_fuzzer/creategetpasteboard_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/creategetpasteboard_fuzzer/creategetpasteboard_fuzzer.h index a571ccbe..514a5889 100644 --- a/test/fuzztest/ohos_adapter/interfaces/creategetpasteboard_fuzzer/creategetpasteboard_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/creategetpasteboard_fuzzer/creategetpasteboard_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "creategetpasteboard_fuzzer" #endif /* TEST_FUZZTEST_CREATE_GET_PASTE_BOARD_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/interfaces/createmmiadapter_fuzzer/createmmiadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/createmmiadapter_fuzzer/createmmiadapter_fuzzer.cpp index 8b6f28eb..ee5b29cf 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createmmiadapter_fuzzer/createmmiadapter_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/createmmiadapter_fuzzer/createmmiadapter_fuzzer.cpp @@ -22,15 +22,15 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateMmiAdapterFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - OhosAdapterHelper::GetInstance().CreateMMIAdapter(); - return true; +bool CreateMmiAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + OhosAdapterHelper::GetInstance().CreateMMIAdapter(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/createmmiadapter_fuzzer/createmmiadapter_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/createmmiadapter_fuzzer/createmmiadapter_fuzzer.h index fc96b05c..1372b7b8 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createmmiadapter_fuzzer/createmmiadapter_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/createmmiadapter_fuzzer/createmmiadapter_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "createmmiadapter_fuzzer" #endif /* TEST_FUZZTEST_CREATE_MMI_ADAPTER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/interfaces/createnetconnect_fuzzer/createnetconnect_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/createnetconnect_fuzzer/createnetconnect_fuzzer.cpp index f38c2a24..9ec107d7 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createnetconnect_fuzzer/createnetconnect_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/createnetconnect_fuzzer/createnetconnect_fuzzer.cpp @@ -22,15 +22,15 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateNetConnectFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - OhosAdapterHelper::GetInstance().CreateNetConnectAdapter(); - return true; +bool CreateNetConnectFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + OhosAdapterHelper::GetInstance().CreateNetConnectAdapter(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/createnetconnect_fuzzer/createnetconnect_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/createnetconnect_fuzzer/createnetconnect_fuzzer.h index 57ec6962..62ca793f 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createnetconnect_fuzzer/createnetconnect_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/createnetconnect_fuzzer/createnetconnect_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "createnetconnect_fuzzer" #endif /* TEST_FUZZTEST_CREATE_NET_CONNECT_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/interfaces/createpowerclient_fuzzer/createpowerclient_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/createpowerclient_fuzzer/createpowerclient_fuzzer.cpp index 1476cea3..9e38f8b1 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createpowerclient_fuzzer/createpowerclient_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/createpowerclient_fuzzer/createpowerclient_fuzzer.cpp @@ -22,15 +22,15 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreatePowerClientFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - OhosAdapterHelper::GetInstance().CreatePowerMgrClientAdapter(); - return true; +bool CreatePowerClientFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + OhosAdapterHelper::GetInstance().CreatePowerMgrClientAdapter(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/createpowerclient_fuzzer/createpowerclient_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/createpowerclient_fuzzer/createpowerclient_fuzzer.h index bb28971a..496da5b5 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createpowerclient_fuzzer/createpowerclient_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/createpowerclient_fuzzer/createpowerclient_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "createpowerclient_fuzzer" #endif /* TEST_FUZZTEST_CREATE_POWER_CLIENT_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/interfaces/createsocperclient_fuzzer/createsocperclient_fuzzer.cpp b/test/fuzztest/ohos_adapter/interfaces/createsocperclient_fuzzer/createsocperclient_fuzzer.cpp index 753601c8..6f765e7c 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createsocperclient_fuzzer/createsocperclient_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/interfaces/createsocperclient_fuzzer/createsocperclient_fuzzer.cpp @@ -22,15 +22,15 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateSocperClientFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - OhosAdapterHelper::GetInstance().CreateSocPerfClientAdapter(); - return true; +bool CreateSocperClientFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + OhosAdapterHelper::GetInstance().CreateSocPerfClientAdapter(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/interfaces/createsocperclient_fuzzer/createsocperclient_fuzzer.h b/test/fuzztest/ohos_adapter/interfaces/createsocperclient_fuzzer/createsocperclient_fuzzer.h index 15a12f5f..546dd220 100644 --- a/test/fuzztest/ohos_adapter/interfaces/createsocperclient_fuzzer/createsocperclient_fuzzer.h +++ b/test/fuzztest/ohos_adapter/interfaces/createsocperclient_fuzzer/createsocperclient_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "createsocperclient_fuzzer" #endif /* TEST_FUZZTEST_CREATE_SOCPER_CLIENT_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..7408aaa3 --- /dev/null +++ b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/BUILD.gn @@ -0,0 +1,61 @@ +# Copyright (c) 2021 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") +import("$webview_path/config.gni") + +##############################fuzztest########################################## +ohos_fuzztest("KeyStoreAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/interfaces", + "$webview_path/ohos_adapter/keystore_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "keystoreadapterimpl_fuzzer.cpp" ] + deps = [ + "$webview_path/ohos_adapter:nweb_ohos_adapter", + "$webview_path/ohos_nweb:libnweb", + ] + + external_deps = [ "c_utils:utils" ] + + if (webview_soc_perf_enable) { + external_deps += [ + "huks:libhukssdk", + "soc_perf:socperf_client", + ] + defines = [ "NWEB_SOC_PERF" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":KeyStoreAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/keystoreadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/keystoreadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..39fa021b --- /dev/null +++ b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/keystoreadapterimpl_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 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 "keystoreadapterimpl_fuzzer.h" + +#include + +#include "keystore_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool ApplyKeystoreAdapterImplFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return false; + } + struct HksParamSet* paramSet; + struct HksParam decryptParams[] = { { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_AES }, + { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_DECRYPT }, + { .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_AES_KEY_SIZE_256 }, + { .tag = HKS_TAG_PADDING, .uint32Param = HKS_PADDING_NONE }, + { .tag = HKS_TAG_BLOCK_MODE, .uint32Param = HKS_MODE_CBC } }; + int32_t result = KeystoreAdapterImpl::GetInstance().InitParamSet( + nullptr, decryptParams, sizeof(decryptParams) / sizeof(HksParam)); + result = + KeystoreAdapterImpl::GetInstance().InitParamSet(¶mSet, nullptr, sizeof(decryptParams) / sizeof(HksParam)); + result = KeystoreAdapterImpl::GetInstance().InitParamSet( + ¶mSet, decryptParams, sizeof(decryptParams) / sizeof(HksParam)); + std::string alias = "test"; + std::string plainData = "web_test"; + std::string encryptString = KeystoreAdapterImpl::GetInstance().EncryptKey(alias, plainData); + std::string DecryptString = KeystoreAdapterImpl::GetInstance().DecryptKey(alias, encryptString); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::ApplyKeystoreAdapterImplFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/keystoreadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/keystoreadapterimpl_fuzzer.h new file mode 100644 index 00000000..1e22f1cf --- /dev/null +++ b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/keystoreadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_KEYSTOREADAPTERIMPL_FUZZER_H +#define TEST_FUZZTEST_KEYSTOREADAPTERIMPL_FUZZER_H + +#define FUZZ_PROJECT_NAME "keystoreadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_KEYSTOREADAPTERIMPL_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/keystore_adapter/keystoreadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/BUILD.gn similarity index 82% rename from test/fuzztest/ohos_adapter/datatimeformat_fuzzer/BUILD.gn rename to test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/BUILD.gn index 4d792a41..d9b83ce2 100644 --- a/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/BUILD.gn @@ -17,12 +17,11 @@ import("//build/config/features.gni") import("//build/test.gni") ##############################fuzztest########################################## -ohos_fuzztest("DataTimeFormatAdapterFuzzerTest") { +ohos_fuzztest("CreateLocationProxyAdapterFuzzTest") { module_out_path = webview_fuzz_test_path - fuzz_config_file = - "$webview_path/test/fuzztest/ohos_adapter/datatimeformat_fuzzer" + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer" include_dirs = [ - "$webview_path/ohos_adapter/date_time_format_adapter/include", + "$webview_path/ohos_adapter/location_adapter/include", "$webview_path/test/fuzztest", ] cflags = [ @@ -31,7 +30,7 @@ ohos_fuzztest("DataTimeFormatAdapterFuzzerTest") { "-Wno-unused-variable", "-fno-omit-frame-pointer", ] - sources = [ "data_time_format_adapter_impl_fuzzer.cpp" ] + sources = [ "createlocationproxyadapter_fuzzer.cpp" ] deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] external_deps = [ @@ -49,7 +48,7 @@ group("fuzztest") { deps = [] deps += [ # deps file - ":DataTimeFormatAdapterFuzzerTest", + ":CreateLocationProxyAdapterFuzzTest", ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/data_time_format_adapter_impl_fuzzer.cpp b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/createlocationproxyadapter_fuzzer.cpp similarity index 41% rename from test/fuzztest/ohos_adapter/datatimeformat_fuzzer/data_time_format_adapter_impl_fuzzer.cpp rename to test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/createlocationproxyadapter_fuzzer.cpp index 82469fb8..345d1e31 100644 --- a/test/fuzztest/ohos_adapter/datatimeformat_fuzzer/data_time_format_adapter_impl_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/createlocationproxyadapter_fuzzer.cpp @@ -13,42 +13,32 @@ * limitations under the License. */ -#include "date_time_format_adapter_impl_fuzzer.h" -#include "date_time_format_adapter_impl.h" - -using namespace OHOS::NWeb; - -namespace OHOS { - bool DateTimeFormatAdapterFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(uint8_t))) { - return false; - } - - std::string timezone(reinterpret_cast(data)); - - - DateTimeFormatAdapterImpl dateTimeFormatAdapter; - - // Test RegTimezoneEvent - dateTimeFormatAdapter.RegTimezoneEvent(nullptr); - - // Test StartListen - dateTimeFormatAdapter.StartListen(); - - // Test StopListen - dateTimeFormatAdapter.StopListen(); - - // Test GetTimezone - dateTimeFormatAdapter.GetTimezone(); - - return true; - } -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - return OHOS::DateTimeFormatAdapterFuzzTest(data, size); +#include "createlocationproxyadapter_fuzzer.h" + +#include "location_instance_impl.h" +#include "location_proxy_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool CreateLocationProxyAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + OHOS::NWeb::LocationInstanceImpl locationInstance; + + auto locationProxyAdapter = locationInstance.CreateLocationProxyAdapter(); + + auto locationRequestConfig = locationInstance.CreateLocationRequestConfig(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::CreateLocationProxyAdapterFuzzTest(data, size); + return 0; } \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/createlocationproxyadapter_fuzzer.h b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/createlocationproxyadapter_fuzzer.h new file mode 100644 index 00000000..e0177b77 --- /dev/null +++ b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/createlocationproxyadapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "createlocationproxyadapter_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/location_adapter/createlocationproxyadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..56e4a177 --- /dev/null +++ b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/BUILD.gn @@ -0,0 +1,96 @@ +# Copyright (c) 2021 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") +import("$webview_path/config.gni") + +##############################fuzztest########################################## +ohos_fuzztest("OhosImageDecoderAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = + "$webview_path/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/interfaces", + "$webview_path/ohos_adapter/ohos_image_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + include_dirs += [ + "../ohos_nweb/include", + "aafwk_adapter/include", + "access_token_adapter/include", + "audio_adapter/include", + "battery_mgr_adapter/include", + "camera_adapter/include", + "cert_mgr_adapter/include", + "datashare_adapter/include", + "date_time_format_adapter/include", + "display_manager_adapter/include", + "distributeddatamgr_adapter/webdatabase/include", + "enterprise_device_management_adapter/include", + "event_handler_adapter/include", + "flowbuffer_adapter/include", + "graphic_adapter/include", + "hiviewdfx_adapter/include", + "inputmethodframework_adapter/include", + "keystore_adapter/include", + "location_adapter/include", + "media_adapter/include", + "multimodalinput_adapter/include", + "net_connect_adapter/include", + "net_proxy_adapter/include", + "ohos_adapter_helper/include", + "ohos_image_adapter/include", + "ohos_init_web_adapter/include", + "ohos_resource_adapter/include", + "pasteboard_adapter/include", + "power_mgr_adapter/include", + "print_manager_adapter/include", + "screen_capture_adapter/include", + "soc_perf_adapter/include", + "system_properties_adapter/include", + ] + + sources = [ "ohosimagedecoderadapterimpl_fuzzer.cpp" ] + deps = [ + "$webview_path/ohos_adapter:nweb_ohos_adapter", + "$webview_path/ohos_nweb:libnweb", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "image_framework:image", + "image_framework:image_native", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":OhosImageDecoderAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/ohosimagedecoderadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/ohosimagedecoderadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..d70a6822 --- /dev/null +++ b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/ohosimagedecoderadapterimpl_fuzzer.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 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 "ohosimagedecoderadapterimpl_fuzzer.h" + +#include +#include + +#include "image_source.h" +#include "image_type.h" +#include "media_errors.h" +#include "ohos_adapter_helper.h" + +using namespace OHOS::NWeb; +const std::string DEFAULT_MOUSE_DRAG_IMAGE { "/system/etc/device_status/drag_icon/Copy_Drag.svg" }; + +namespace OHOS { + +bool ValidateInput(const uint8_t* data, size_t size) +{ + return (data != nullptr) && (size >= sizeof(int32_t)); +} + +std::shared_ptr CreateDecoderAdapter() +{ + return OhosAdapterHelper::GetInstance().CreateOhosImageDecoderAdapter(); +} + +void HandleAbnormalCase(const std::shared_ptr& adapter) +{ + size_t len = 0; + std::unique_ptr rawData; + + adapter->ParseImageInfo(rawData.get(), len); + adapter->DecodeToPixelMap(rawData.get(), len); +} + +bool ProcessImageSource(std::shared_ptr& adapter) +{ + uint32_t errorCode = 0; + OHOS::Media::SourceOptions opts; + auto imageSource = OHOS::Media::ImageSource::CreateImageSource(DEFAULT_MOUSE_DRAG_IMAGE, opts, errorCode); + if (!imageSource || errorCode != Media::SUCCESS) { + return false; + } + + OHOS::Media::DecodeOptions decodeOpts; + auto pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode); + if (!pixelMap || errorCode != OHOS::Media::SUCCESS) { + return false; + } + + const uint8_t* imageData = pixelMap->GetPixels(); + if (!imageData) { + return false; + } + + size_t len = pixelMap->GetPixelBytes(); + adapter->ParseImageInfo(imageData, len); + adapter->DecodeToPixelMap(imageData, len); + return true; +} + +bool ApplyOhosImageDecoderAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if (!ValidateInput(data, size)) { + return false; + } + + auto adapter = CreateDecoderAdapter(); + if (!adapter) { + return false; + } + + HandleAbnormalCase(adapter); + return ProcessImageSource(adapter); +} + +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::ApplyOhosImageDecoderAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/ohosimagedecoderadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/ohosimagedecoderadapterimpl_fuzzer.h new file mode 100644 index 00000000..32621fcf --- /dev/null +++ b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/ohosimagedecoderadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_OHOSIMAGEDECODERADAPTERIMPL_FUZZER_H +#define TEST_FUZZTEST_OHOSIMAGEDECODERADAPTERIMPL_FUZZER_H + +#define FUZZ_PROJECT_NAME "ohosimagedecoderadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_OHOSIMAGEDECODERADAPTERIMPL_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/ohosimageadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee From b6f1207d501c6f868ec000e70d2a9c31bc6ffd8f Mon Sep 17 00:00:00 2001 From: zouzhiwei Date: Fri, 2 Aug 2024 16:36:07 +0800 Subject: [PATCH 097/126] web_add_fuzz2 Signed-off-by: zouzhiwei --- bundle.json | 9 ++ .../bufferinfoadapterimpl_fuzzer/BUILD.gn | 54 +++++++ .../bufferinfoadapterimpl_fuzzer.cpp | 60 ++++++++ .../bufferinfoadapterimpl_fuzzer.h | 20 +++ .../bufferinfoadapterimpl_fuzzer/corpus/init | 15 ++ .../bufferinfoadapterimpl_fuzzer/project.xml | 25 ++++ .../capabilitydataadapterimpl_fuzzer/BUILD.gn | 54 +++++++ .../capabilitydataadapterimpl_fuzzer.cpp | 62 ++++++++ .../capabilitydataadapterimpl_fuzzer.h | 20 +++ .../corpus/init | 15 ++ .../project.xml | 25 ++++ .../codecformatadapterimpl_fuzzer/BUILD.gn | 54 +++++++ .../codecformatadapterimpl_fuzzer.cpp | 54 +++++++ .../codecformatadapterimpl_fuzzer.h | 20 +++ .../codecformatadapterimpl_fuzzer/corpus/init | 15 ++ .../codecformatadapterimpl_fuzzer/project.xml | 25 ++++ .../mediaavsessionadapterimpl_fuzzer/BUILD.gn | 65 +++++++++ .../corpus/init | 15 ++ .../mediaavsessionadapterimpl_fuzzer.cpp | 85 +++++++++++ .../mediaavsessionadapterimpl_fuzzer.h | 20 +++ .../project.xml | 25 ++++ .../BUILD.gn | 56 ++++++++ .../corpus/init | 15 ++ .../mediacodecdecoderadapterimpl_fuzzer.cpp | 133 ++++++++++++++++++ .../mediacodecdecoderadapterimpl_fuzzer.h | 20 +++ .../project.xml | 25 ++++ .../BUILD.gn | 60 ++++++++ .../corpus/init | 15 ++ .../mediacodecencoderadapterimpl_fuzzer.cpp | 116 +++++++++++++++ .../mediacodecencoderadapterimpl_fuzzer.h | 20 +++ .../project.xml | 25 ++++ .../mediacodeclistadapterimpl_fuzzer/BUILD.gn | 54 +++++++ .../corpus/init | 15 ++ .../mediacodeclistadapterimpl_fuzzer.cpp | 50 +++++++ .../mediacodeclistadapterimpl_fuzzer.h | 20 +++ .../project.xml | 25 ++++ .../ohosbufferadapterimpl_fuzzer/BUILD.gn | 54 +++++++ .../ohosbufferadapterimpl_fuzzer/corpus/init | 15 ++ .../ohosbufferadapterimpl_fuzzer.cpp | 56 ++++++++ .../ohosbufferadapterimpl_fuzzer.h | 20 +++ .../ohosbufferadapterimpl_fuzzer/project.xml | 25 ++++ .../BUILD.gn | 60 ++++++++ .../corpus/init | 15 ++ .../playerframeworkadapterimpl_fuzzer.cpp | 95 +++++++++++++ .../playerframeworkadapterimpl_fuzzer.h | 20 +++ .../project.xml | 25 ++++ 46 files changed, 1771 insertions(+) create mode 100644 test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/mediacodecdecoderadapterimpl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/mediacodecdecoderadapterimpl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/mediacodecencoderadapterimpl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/mediacodecencoderadapterimpl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/mediacodeclistadapterimpl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/mediacodeclistadapterimpl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/playerframeworkadapterimpl_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/playerframeworkadapterimpl_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/project.xml diff --git a/bundle.json b/bundle.json index f8e23916..beeff4d4 100644 --- a/bundle.json +++ b/bundle.json @@ -246,6 +246,15 @@ "//base/web/webview/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/cert_mgr_adapter/getcertmaxsize_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/cert_mgr_adapter/getusercertdata_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/ashmemcreate_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/systemproperties_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_nweb/loadlib_fuzzer:fuzztest", diff --git a/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..5fa04d29 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("BufferInfoAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/media_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bufferinfoadapterimpl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":BufferInfoAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..57f70ebf --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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 "bufferinfoadapterimpl_fuzzer.h" + +#include + +#include "buffer_info_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool BufferInfoAdapterImplFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + OHOS::NWeb::BufferInfoAdapterImpl bufferInfoAdapterImpl; + int64_t time; + int32_t usesize; + int32_t offset; + if (memcpy_s(&time, sizeof(int64_t), data, sizeof(int64_t)) != 0) { + return true; + } + if (memcpy_s(&usesize, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return true; + } + if (memcpy_s(&offset, sizeof(int64_t), data, sizeof(int64_t)) != 0) { + return true; + } + bufferInfoAdapterImpl.SetPresentationTimeUs(time); + bufferInfoAdapterImpl.SetSize(usesize); + bufferInfoAdapterImpl.SetOffset(offset); + + bufferInfoAdapterImpl.GetPresentationTimeUs(); + bufferInfoAdapterImpl.GetSize(); + bufferInfoAdapterImpl.GetOffset(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::BufferInfoAdapterImplFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.h new file mode 100644 index 00000000..1a1c71c4 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "bufferinfoadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..baddce07 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("CapabilityDataAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/media_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "capabilitydataadapterimpl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":CapabilityDataAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..602f6092 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.cpp @@ -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. + */ + +#include "capabilitydataadapterimpl_fuzzer.h" + +#include + +#include "capability_data_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool CapabilityDataAdapterImplFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + OHOS::NWeb::CapabilityDataAdapterImpl capabilityDataAdapter; + + int32_t width; + int32_t height; + int32_t frameRate; + if (memcpy_s(&width, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return true; + } + if (memcpy_s(&height, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return true; + } + if (memcpy_s(&frameRate, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return true; + } + + capabilityDataAdapter.SetMaxWidth(width); + capabilityDataAdapter.SetMaxHeight(height); + capabilityDataAdapter.SetMaxframeRate(frameRate); + + capabilityDataAdapter.GetMaxWidth(); + capabilityDataAdapter.GetMaxHeight(); + capabilityDataAdapter.GetMaxframeRate(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::CapabilityDataAdapterImplFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.h new file mode 100644 index 00000000..b4861d85 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "capabilitydataadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..65a24474 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("CodecFormatAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/media_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "codecformatadapterimpl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":CodecFormatAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..2a9bbf95 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.cpp @@ -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. + */ + +#include "codecformatadapterimpl_fuzzer.h" + +#include + +#include "codec_format_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool CreateLocationProxyAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + OHOS::NWeb::CodecFormatAdapterImpl codecFormatAdapter; + int32_t width; + int32_t height; + if (memcpy_s(&width, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return true; + } + if (memcpy_s(&height, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return true; + } + codecFormatAdapter.SetWidth(width); + codecFormatAdapter.SetHeight(height); + + codecFormatAdapter.GetWidth(); + codecFormatAdapter.GetHeight(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::CreateLocationProxyAdapterFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.h new file mode 100644 index 00000000..fc7eb20e --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "codecformatadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..625e9469 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("MediaAVSessionCallbackImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/media_adapter/include", + "$webview_path/ohos_adapter/graphic_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "mediaavsessionadapterimpl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:want", + "ability_runtime:app_context", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "av_codec:av_codec_client", + "av_session:avsession_client", + "av_session:avsession_client", + "c_utils:utils", + "graphic_2d:libcomposer", + "graphic_surface:surface", + "graphic_surface:surface", + "input:libmmi-client", + "media_foundation:media_foundation", + "player_framework:media_client", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":MediaAVSessionCallbackImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..1452fd31 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.cpp @@ -0,0 +1,85 @@ +/* + * 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 "mediaavsessionadapterimpl_fuzzer.h" + +#define private public +#include +#include +#include + +#include "media_avsession_adapter.h" +#include "media_avsession_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +class MediaAVSessionCallbackAdapterMock : public MediaAVSessionCallbackAdapter { +public: + MediaAVSessionCallbackAdapterMock() = default; + void Play() {}; + void Pause() {}; + void Stop() {}; + void SeekTo(int64_t millisTime) {}; +}; + +bool MediaAVSessionCallbackImplFuzzTest(const uint8_t* data, size_t size) +{ + std::shared_ptr mediaAvSessionCB; + std::shared_ptr callbackImpl = + std::make_shared(mediaAvSessionCB); + + int64_t time = 100; + + callbackImpl->OnPlay(); + callbackImpl->OnPause(); + callbackImpl->OnStop(); + callbackImpl->OnSeek(time); + + std::shared_ptr key = std::make_shared(); + key->Init(); + key->GetPID(); + key->GetElement(); + key->GetType(); + key->ToString(); + + std::shared_ptr avSessionAdapter = std::make_shared(); + auto mediaAVSessionCallbackAdapterMock = std::make_shared(); + auto avSessionKey = std::make_shared(); + avSessionAdapter->avSessionKey_ = avSessionKey; + avSessionAdapter->avSessionKey_->Init(); + avSessionAdapter->avSession_ = nullptr; + auto type = MediaAVSessionType::MEDIA_TYPE_INVALID; + avSessionAdapter->CreateAVSession(type); + type = MediaAVSessionType::MEDIA_TYPE_AUDIO; + avSessionAdapter->CreateAVSession(type); + + avSessionAdapter->DestroyAVSession(); + avSessionAdapter->RegistCallback(mediaAVSessionCallbackAdapterMock); + avSessionAdapter->IsActivated(); + avSessionAdapter->Activate(); + avSessionAdapter->DeActivate(); + + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::MediaAVSessionCallbackImplFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.h new file mode 100644 index 00000000..fc7eb20e --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "codecformatadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..f9ec2d73 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("MediaCodecDecoderAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/media_adapter/include", + "$webview_path/ohos_adapter/graphic_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "mediacodecdecoderadapterimpl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "av_codec:av_codec_client", + "av_session:avsession_client", + "c_utils:utils", + "graphic_surface:surface", + "media_foundation:media_foundation", + "player_framework:media_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":MediaCodecDecoderAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/mediacodecdecoderadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/mediacodecdecoderadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..a3186a26 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/mediacodecdecoderadapterimpl_fuzzer.cpp @@ -0,0 +1,133 @@ +/* + * 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 "mediacodecdecoderadapterimpl_fuzzer.h" + +#include + +#include "avsharedmemory.h" +#include "avsharedmemorybase.h" +#include "media_codec_decoder_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +class DecoderCallbackAdapterMock : public DecoderCallbackAdapter { +public: + DecoderCallbackAdapterMock() = default; + + ~DecoderCallbackAdapterMock() override = default; + + void OnError(ErrorType errorType, int32_t errorCode) override {} + + void OnStreamChanged(int32_t width, int32_t height, double frameRate) override {} + + void OnNeedInputData(uint32_t index, std::shared_ptr buffer) override {} + + void OnNeedOutputData(uint32_t index, std::shared_ptr info, BufferFlag flag) override {} +}; + +class DecoderFormatAdapterMock : public DecoderFormatAdapter { +public: + DecoderFormatAdapterMock() = default; + + int32_t GetWidth() override + { + return width; + } + + int32_t GetHeight() override + { + return height; + } + + double GetFrameRate() override + { + return frameRate; + } + + void SetWidth(int32_t w) override + { + width = w; + } + + void SetHeight(int32_t h) override + { + height = h; + } + + void SetFrameRate(double fr) override + { + frameRate = fr; + } + + int32_t width; + int32_t height; + double frameRate; +}; + +bool MediaCodecDecoderAdapterImplFuzzTest(const uint8_t* data, size_t size) +{ + NWeb::MediaCodecDecoderAdapterImpl mediaCodecDecoderAdapterImpl; + NWeb::DecoderAdapterCode code = mediaCodecDecoderAdapterImpl.CreateVideoDecoderByMime("testmimeType"); + std::shared_ptr format = std::make_unique(); + AVCodecBufferInfo info; + code = mediaCodecDecoderAdapterImpl.CreateVideoDecoderByName("testname"); + code = mediaCodecDecoderAdapterImpl.ConfigureDecoder(format); + code = mediaCodecDecoderAdapterImpl.SetParameterDecoder(format); + + void* window = nullptr; + code = mediaCodecDecoderAdapterImpl.SetOutputSurface(window); + code = mediaCodecDecoderAdapterImpl.PrepareDecoder(); + code = mediaCodecDecoderAdapterImpl.StartDecoder(); + code = mediaCodecDecoderAdapterImpl.StopDecoder(); + code = mediaCodecDecoderAdapterImpl.FlushDecoder(); + code = mediaCodecDecoderAdapterImpl.ResetDecoder(); + code = mediaCodecDecoderAdapterImpl.ReleaseDecoder(); + + code = mediaCodecDecoderAdapterImpl.QueueInputBufferDec(0, 0, 0, 0, BufferFlag::CODEC_BUFFER_FLAG_NONE); + + code = mediaCodecDecoderAdapterImpl.GetOutputFormatDec(format); + + code = mediaCodecDecoderAdapterImpl.ReleaseOutputBufferDec(0, true); + + std::shared_ptr decoderCallback = std::make_shared(nullptr); + + decoderCallback->OnError(OHOS::MediaAVCodec::AVCodecErrorType::AVCODEC_ERROR_INTERNAL, 0); + decoderCallback->OnOutputFormatChanged(OHOS::MediaAVCodec::Format()); + decoderCallback->OnInputBufferAvailable(0, nullptr); + decoderCallback->OnOutputBufferAvailable(0, OHOS::MediaAVCodec::AVCodecBufferInfo(), + OHOS::MediaAVCodec::AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE, nullptr); + + std::shared_ptr callback = std::make_shared(); + std::shared_ptr decoderCallbackNoNull = + std::make_shared(callback); + decoderCallbackNoNull->OnError(OHOS::MediaAVCodec::AVCodecErrorType::AVCODEC_ERROR_INTERNAL, 0); + decoderCallbackNoNull->OnOutputFormatChanged(OHOS::MediaAVCodec::Format()); + decoderCallbackNoNull->OnOutputBufferAvailable( + 0, info, OHOS::MediaAVCodec::AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE, nullptr); + std::shared_ptr memory = std::make_shared(1, 1.0, "test"); + decoderCallbackNoNull->OnInputBufferAvailable(1, memory); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::MediaCodecDecoderAdapterImplFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/mediacodecdecoderadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/mediacodecdecoderadapterimpl_fuzzer.h new file mode 100644 index 00000000..c153caeb --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/mediacodecdecoderadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "mediacodecdecoderadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecdecoderadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..6d2d4048 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("MediaCodecEncoderAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/media_adapter/include", + "$webview_path/ohos_adapter/graphic_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "mediacodecencoderadapterimpl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_runtime:app_manager", + "av_codec:av_codec_client", + "av_session:avsession_client", + "c_utils:utils", + "graphic_2d:libcomposer", + "graphic_surface:surface", + "graphic_surface:surface", + "media_foundation:media_foundation", + "player_framework:media_client", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":MediaCodecEncoderAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/mediacodecencoderadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/mediacodecencoderadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..9ab86fc9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/mediacodecencoderadapterimpl_fuzzer.cpp @@ -0,0 +1,116 @@ +/* + * 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 "mediacodecencoderadapterimpl_fuzzer.h" + +#include "avsharedmemory.h" +#include "avsharedmemorybase.h" +#include "media_codec_encoder_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +class EncoderCallbackAdapterMock : public CodecCallbackAdapter { +public: + EncoderCallbackAdapterMock() = default; + + ~EncoderCallbackAdapterMock() override = default; + + void OnError(ErrorType errorType, int32_t errorCode) override {} + + void OnStreamChanged(const std::shared_ptr formatApadter_) override {} + + void OnNeedInputData(uint32_t index, std::shared_ptr buffer) override {} + + void OnNeedOutputData(uint32_t index, std::shared_ptr info, BufferFlag flag, + std::shared_ptr buffer) override + {} +}; + +class CodecConfigParaAdapterMock : public CodecConfigParaAdapter { +public: + CodecConfigParaAdapterMock() = default; + + int32_t GetWidth() override + { + return width; + } + + int32_t GetHeight() override + { + return height; + } + + int64_t GetBitRate() override + { + return bitRate; + } + + double GetFrameRate() override + { + return frameRate; + } + + int32_t width; + int32_t height; + int64_t bitRate; + double frameRate; +}; + +bool CreateLocationProxyAdapterFuzzTest(const uint8_t* data, size_t size) +{ + NWeb::MediaCodecEncoderAdapterImpl mediaCodecEncoderAdapterImpl; + std::shared_ptr callbackImpl = std::make_shared(); + std::shared_ptr config = std::make_shared(); + + mediaCodecEncoderAdapterImpl.CreateVideoCodecByMime("video/avc"); + mediaCodecEncoderAdapterImpl.SetCodecCallback(nullptr); + mediaCodecEncoderAdapterImpl.SetCodecCallback(callbackImpl); + mediaCodecEncoderAdapterImpl.Configure(nullptr); + mediaCodecEncoderAdapterImpl.Configure(config); + mediaCodecEncoderAdapterImpl.Prepare(); + mediaCodecEncoderAdapterImpl.Start(); + mediaCodecEncoderAdapterImpl.Stop(); + mediaCodecEncoderAdapterImpl.Reset(); + mediaCodecEncoderAdapterImpl.Release(); + mediaCodecEncoderAdapterImpl.CreateInputSurface(); + mediaCodecEncoderAdapterImpl.ReleaseOutputBuffer(0, true); + mediaCodecEncoderAdapterImpl.RequestKeyFrameSoon(); + mediaCodecEncoderAdapterImpl.GetErrorType(AVCodecErrorType::AVCODEC_ERROR_INTERNAL); + mediaCodecEncoderAdapterImpl.GetBufferFlag(AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE); + + std::shared_ptr cb = nullptr; + std::shared_ptr memory = std::make_shared(1, 1.0, "test"); + + NWeb::EncoderCallbackImpl encoderCallback(cb); + + encoderCallback.OnError(OHOS::MediaAVCodec::AVCodecErrorType::AVCODEC_ERROR_INTERNAL, 0); + encoderCallback.OnOutputFormatChanged(OHOS::MediaAVCodec::Format()); + encoderCallback.OnInputBufferAvailable(0, nullptr); + encoderCallback.OnInputBufferAvailable(1, memory); + encoderCallback.OnOutputBufferAvailable(0, OHOS::MediaAVCodec::AVCodecBufferInfo(), + OHOS::MediaAVCodec::AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE, nullptr); + + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::CreateLocationProxyAdapterFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/mediacodecencoderadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/mediacodecencoderadapterimpl_fuzzer.h new file mode 100644 index 00000000..4670ddbe --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/mediacodecencoderadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "mediacodecencoderadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodecencoderadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..eb0e52af --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("MediaCodecListAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/media_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "mediacodeclistadapterimpl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":MediaCodecListAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/mediacodeclistadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/mediacodeclistadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..bd0e3f3d --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/mediacodeclistadapterimpl_fuzzer.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 "mediacodeclistadapterimpl_fuzzer.h" + +#include +#include +#include + +#include "media_codec_list_adapter_impl.h" + +using namespace OHOS::NWeb; +namespace OHOS { +bool MediaCodecListAdapterImplFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return false; + } + + OHOS::NWeb::MediaCodecListAdapterImpl& mediaCodecListAdapterImpl = + OHOS::NWeb::MediaCodecListAdapterImpl::GetInstance(); + + std::string mime(reinterpret_cast(data), size); + bool isEncoder = true; + + std::shared_ptr capabilityAdapter = + mediaCodecListAdapterImpl.GetCodecCapability(mime, isEncoder); + + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::MediaCodecListAdapterImplFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/mediacodeclistadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/mediacodeclistadapterimpl_fuzzer.h new file mode 100644 index 00000000..c153caeb --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/mediacodeclistadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "mediacodecdecoderadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/mediacodeclistadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..af4774c0 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("OhosBufferAdapterImplFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/media_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ohosbufferadapterimpl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":OhosBufferAdapterImplFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..801da421 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.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 "ohosbufferadapterimpl_fuzzer.h" + +#include + +#include "ohos_buffer_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool OhosBufferAdapterImplFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + OHOS::NWeb::OhosBufferAdapterImpl ohosBufferAdapterImpl; + + uint8_t* addr = const_cast(data); + uint32_t bufferSize; + + if (memcpy_s(&bufferSize, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return true; + } + + ohosBufferAdapterImpl.SetAddr(addr); + + ohosBufferAdapterImpl.SetBufferSize(bufferSize); + + ohosBufferAdapterImpl.GetAddr(); + + ohosBufferAdapterImpl.GetBufferSize(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::OhosBufferAdapterImplFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.h new file mode 100644 index 00000000..c153caeb --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "mediacodecdecoderadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/BUILD.gn new file mode 100644 index 00000000..4593c0c8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/BUILD.gn @@ -0,0 +1,60 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("PlayerFrameworkAdapterImpl_fuzzerFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/media_adapter/include", + "$webview_path/ohos_adapter/graphic_adapter/include", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "playerframeworkadapterimpl_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "ability_runtime:app_manager", + "av_codec:av_codec_client", + "av_session:avsession_client", + "c_utils:utils", + "graphic_2d:libcomposer", + "graphic_surface:surface", + "graphic_surface:surface", + "media_foundation:media_foundation", + "player_framework:media_client", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":PlayerFrameworkAdapterImpl_fuzzerFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/playerframeworkadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/playerframeworkadapterimpl_fuzzer.cpp new file mode 100644 index 00000000..40ccb6eb --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/playerframeworkadapterimpl_fuzzer.cpp @@ -0,0 +1,95 @@ +/* + * 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 "playerframeworkadapterimpl_fuzzer.h" + +#include "ohos_adapter_helper.h" +#include "player_framework_adapter_impl.h" +using namespace OHOS::NWeb; + +namespace OHOS { +class PlayerCallbackTest : public PlayerCallbackAdapter { +public: + PlayerCallbackTest() = default; + ~PlayerCallbackTest() override = default; + void OnInfo(PlayerOnInfoType type, int32_t extra, int32_t value) override + { + infoType_ = type; + } + void OnError(PlayerAdapterErrorType errorType) override + { + errorType_ = errorType; + } + PlayerOnInfoType infoType_ = PlayerOnInfoType::INFO_TYPE_UNSET; + PlayerAdapterErrorType errorType_ = PlayerAdapterErrorType::INVALID_CODE; +}; + +bool PlayerFrameworkAdapterImpl_fuzzerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + + int32_t currentTime = static_cast(size); + int32_t duration = static_cast(size); + + std::shared_ptr callbackAdapter = nullptr; + PlayerCallbackImpl playerCallback(callbackAdapter); + + playerCallback.OnInfo(Media::PlayerOnInfoType::INFO_TYPE_EOS, 0, Media::Format()); + playerCallback.OnError(0, ""); + PlayerAdapterImpl playerAdapter; + playerAdapter.SetPlayerCallback(nullptr); + playerAdapter.SetSource(""); + playerAdapter.SetSource(0, 0, 0); + playerAdapter.SetVideoSurface(nullptr); + playerAdapter.SetVolume(0.0, 0.0); + playerAdapter.Seek(0, PlayerSeekMode::SEEK_PREVIOUS_SYNC); + playerAdapter.Play(); + playerAdapter.Pause(); + playerAdapter.PrepareAsync(); + playerAdapter.GetCurrentTime(currentTime); + playerAdapter.GetDuration(duration); + playerAdapter.SetPlaybackSpeed(PlaybackRateMode::SPEED_FORWARD_1_00_X); + + auto callbackTest = std::make_unique(); + std::shared_ptr playerCallbackMock = + std::make_shared(std::move(callbackTest)); + std::unique_ptr playerAdapterNormal = std::make_unique(); + ; + playerAdapterNormal->SetPlayerCallback(std::move(callbackTest)); + auto surfaceAdapter = NWeb::OhosAdapterHelper::GetInstance().CreateConsumerSurfaceAdapter(); + playerAdapterNormal->SetVideoSurface(std::move(surfaceAdapter)); + playerAdapterNormal->SetSource(""); + playerAdapterNormal->SetSource(-1, 0, 0); + playerAdapterNormal->SetVolume(0.0, 0.0); + playerAdapterNormal->Seek(0, PlayerSeekMode::SEEK_PREVIOUS_SYNC); + playerAdapterNormal->Play(); + playerAdapterNormal->Pause(); + playerAdapterNormal->PrepareAsync(); + playerAdapterNormal->GetCurrentTime(currentTime); + playerAdapterNormal->GetDuration(duration); + playerAdapter.SetPlaybackSpeed(PlaybackRateMode::SPEED_FORWARD_1_00_X); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::PlayerFrameworkAdapterImpl_fuzzerFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/playerframeworkadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/playerframeworkadapterimpl_fuzzer.h new file mode 100644 index 00000000..052f3210 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/playerframeworkadapterimpl_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H +#define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "playerframeworkadapterimpl_fuzzer" +#endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/project.xml b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/media_adapter/playerframeworkadapterimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee From def8e1be088e796718942a4c3744cbd8902dfa6d Mon Sep 17 00:00:00 2001 From: tengfan Date: Fri, 2 Aug 2024 17:14:03 +0800 Subject: [PATCH 098/126] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=BB=91=E5=8A=A8=E5=81=8F=E7=A7=BB=E9=87=8F=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tengfan --- .../napi_webview_controller.cpp | 26 +++++++++++++++++++ .../napi_webview_controller.h | 2 ++ .../webviewcontroller/webview_controller.cpp | 8 ++++++ .../webviewcontroller/webview_controller.h | 2 ++ ohos_interface/include/ohos_nweb/nweb.h | 7 +++++ .../bridge/webcore/ark_web_nweb_impl.cpp | 5 ++++ .../bridge/webcore/ark_web_nweb_impl.h | 8 ++++++ .../bridge/webview/ark_web_nweb_wrapper.cpp | 5 ++++ .../bridge/webview/ark_web_nweb_wrapper.h | 8 ++++++ .../ohos_nweb/include/ark_web_nweb.h | 8 ++++++ 10 files changed, 79 insertions(+) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 52e46366..300a8c02 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -532,6 +532,8 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("setBackForwardCacheOptions", NapiWebviewController::SetBackForwardCacheOptions), DECLARE_NAPI_STATIC_FUNCTION("trimMemoryByPressureLevel", NapiWebviewController::TrimMemoryByPressureLevel), + DECLARE_NAPI_FUNCTION("getScrollOffset", + NapiWebviewController::GetScrollOffset), }; napi_value constructor = nullptr; napi_define_class(env, WEBVIEW_CONTROLLER_CLASS_NAME.c_str(), WEBVIEW_CONTROLLER_CLASS_NAME.length(), @@ -6259,5 +6261,29 @@ napi_value NapiWebviewController::TrimMemoryByPressureLevel(napi_env env, NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } + +napi_value NapiWebviewController::GetScrollOffset(napi_env env, + napi_callback_info info) +{ + napi_value result = nullptr; + napi_value horizontal; + napi_value vertical; + float offsetX = 0; + float offsetY = 0; + + WebviewController* webviewController = GetWebviewController(env, info); + if (!webviewController) { + return nullptr; + } + + webviewController->GetScrollOffset(&offsetX, &offsetY); + + napi_create_object(env, &result); + napi_create_double(env, static_cast(offsetX), &horizontal); + napi_create_double(env, static_cast(offsetY), &vertical); + napi_set_named_property(env, result, "horizontal", horizontal); + napi_set_named_property(env, result, "vertical", vertical); + 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 5a0c1ae9..e1283155 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -355,6 +355,8 @@ private: static napi_value TrimMemoryByPressureLevel(napi_env env, napi_callback_info info); + static napi_value GetScrollOffset(napi_env env, napi_callback_info info); + static int32_t maxFdNum_; static std::atomic usedFd_; }; diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp index 6480d7fb..6eae9375 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp @@ -1983,5 +1983,13 @@ void WebviewController::SetBackForwardCacheOptions(int32_t size, int32_t timeToL nweb_ptr->SetBackForwardCacheOptions(size, timeToLive); } + +void WebviewController::GetScrollOffset(float* offset_x, float* offset_y) +{ + auto nweb_ptr = NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->GetScrollOffset(offset_x, offset_y); + } +} } // namespace NWeb } // namespace OHOS diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.h b/interfaces/kits/napi/webviewcontroller/webview_controller.h index 58764995..06bd73a0 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.h @@ -381,6 +381,8 @@ public: void ScrollByWithAnime(float deltaX, float deltaY, int32_t duration) ; void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive); + + void GetScrollOffset(float* offset_x, float* offset_y); private: int ConverToWebHitTestType(int hitType); diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 9ff67f72..56ba3991 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -1465,6 +1465,13 @@ public: * @param fillContent fillContent */ virtual void OnAutofillCancel(const std::string& fillContent) {} + + /** + * @brief Get the current scroll offset of the webpage. + * @param offset_x The current horizontal scroll offset of the webpage. + * @param offset_y The current vertical scroll offset of the webpage. + */ + virtual void GetScrollOffset(float* offset_x, float* offset_y) {} }; } // namespace OHOS::NWeb 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 afe7aee3..47865926 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 @@ -1137,4 +1137,9 @@ void ArkWebNWebImpl::OnAutofillCancel(const ArkWebString& fillContent) { nweb_nweb_->OnAutofillCancel(ArkWebStringStructToClass(fillContent)); } + +void ArkWebNWebImpl::GetScrollOffset(float* offset_x, float* offset_y) +{ + nweb_nweb_->GetScrollOffset(offset_x, offset_y); +} } // 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 e5ffb7e5..3894cb3e 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 @@ -1306,6 +1306,14 @@ public: */ /*--ark web()--*/ void OnAutofillCancel(const ArkWebString& fillContent) override; + + /** + * @brief Get the current scroll offset of the webpage. + * @param offset_x The current horizontal scroll offset of the webpage. + * @param offset_y The current vertical scroll offset of the webpage. + */ + /*--ark web()--*/ + void GetScrollOffset(float* offset_x, float* offset_y) override; private: std::shared_ptr nweb_nweb_; }; 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 9b861ef8..aea2b1d8 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 @@ -1339,4 +1339,9 @@ void ArkWebNWebWrapper::OnAutofillCancel(const std::string& fillContent) ArkWebStringStructRelease(stFillContent); } + +void ArkWebNWebWrapper::GetScrollOffset(float* offset_x, float* offset_y) +{ + ark_web_nweb_->GetScrollOffset(offset_x, offset_y); +} } // 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 1cfbcdc2..d63826ec 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 @@ -1315,6 +1315,14 @@ public: */ /*--ark web()--*/ void OnAutofillCancel(const std::string& fillContent) override; + + /** + * @brief Get the current scroll offset of the webpage. + * @param offset_x The current horizontal scroll offset of the webpage. + * @param offset_y The current vertical scroll offset of the webpage. + */ + /*--ark web()--*/ + void GetScrollOffset(float* offset_x, float* offset_y) override; private: ArkWebRefPtr ark_web_nweb_; }; 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 27c195e2..ecfff288 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 @@ -1465,6 +1465,14 @@ public: */ /*--ark web()--*/ virtual void OnAutofillCancel(const ArkWebString& fillContent) = 0; + + /** + * @brief Get the current scroll offset of the webpage. + * @param offset_x The current horizontal scroll offset of the webpage. + * @param offset_y The current vertical scroll offset of the webpage. + */ + /*--ark web()--*/ + virtual void GetScrollOffset(float* offset_x, float* offset_y) = 0; }; } // namespace OHOS::ArkWeb -- Gitee From 327e6930456892717d8a38f827958b826beda445 Mon Sep 17 00:00:00 2001 From: zouzhiwei Date: Sat, 3 Aug 2024 15:03:43 +0800 Subject: [PATCH 099/126] web_add_fuzz4 Signed-off-by: zouzhiwei --- bundle.json | 8 ++ .../aafwkattachrender_fuzzer/BUILD.gn | 3 + .../aafwkattachrender_fuzzer.cpp | 31 +++-- .../aafwkattachrender_fuzzer.h | 1 - .../aafwkbrowserclientadapter_fuzzer/BUILD.gn | 54 ++++++++ .../aafwkbrowserclientadapter_fuzzer.cpp | 107 +++++++++++++++ .../aafwkbrowserclientadapter_fuzzer.h | 20 +++ .../corpus/init | 15 +++ .../project.xml | 25 ++++ .../aafwkbrowserhost_fuzzer/BUILD.gn | 54 ++++++++ .../aafwkbrowserhost_fuzzer.cpp | 69 ++++++++++ .../aafwkbrowserhost_fuzzer.h | 20 +++ .../aafwkbrowserhost_fuzzer/corpus/init | 15 +++ .../aafwkbrowserhost_fuzzer/project.xml | 25 ++++ .../aafwkrenderscheduler_fuzzer/BUILD.gn | 4 + .../aafwkrenderscheduler_fuzzer.cpp | 62 +++++---- .../aafwkrenderscheduler_fuzzer.h | 1 - .../aafwkstartrender_fuzzer.cpp | 42 +++--- .../aafwkstartrender_fuzzer.h | 1 - .../ohos_adapter/audio_adapter/BUILD.gn | 1 - .../cameramanageradapter_fuzzer/BUILD.gn | 68 ++++++++++ .../cameramanageradapter_fuzzer.cpp | 126 ++++++++++++++++++ .../cameramanageradapter_fuzzer.h | 20 +++ .../cameramanageradapter_fuzzer/corpus/init | 15 +++ .../cameramanageradapter_fuzzer/project.xml | 25 ++++ .../BUILD.gn | 68 ++++++++++ .../camerasurfacebufferadapter_fuzzer.cpp | 68 ++++++++++ .../camerasurfacebufferadapter_fuzzer.h | 20 +++ .../corpus/init | 15 +++ .../project.xml | 25 ++++ .../formatadapter_fuzzer/BUILD.gn | 64 +++++++++ .../formatadapter_fuzzer/corpus/init | 15 +++ .../formatadapter_fuzzer.cpp | 50 +++++++ .../formatadapter_fuzzer.h | 20 +++ .../formatadapter_fuzzer/project.xml | 25 ++++ .../videocapturerangeadapter_fuzzer/BUILD.gn | 64 +++++++++ .../corpus/init | 15 +++ .../project.xml | 25 ++++ .../videocapturerangeadapter_fuzzer.cpp | 52 ++++++++ .../videocapturerangeadapter_fuzzer.h | 20 +++ .../BUILD.gn | 64 +++++++++ .../corpus/init | 15 +++ .../project.xml | 25 ++++ .../videocontrolsupportadapter_fuzzer.cpp | 54 ++++++++ .../videocontrolsupportadapter_fuzzer.h | 20 +++ .../BUILD.gn | 64 +++++++++ .../corpus/init | 15 +++ .../project.xml | 25 ++++ .../videodevicedescriptoradapter_fuzzer.cpp | 62 +++++++++ .../videodevicedescriptoradapter_fuzzer.h | 20 +++ 50 files changed, 1663 insertions(+), 59 deletions(-) create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/aafwkbrowserclientadapter_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/aafwkbrowserclientadapter_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/formatadapter_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/formatadapter_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/videocapturerangeadapter_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/videocapturerangeadapter_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/videocontrolsupportadapter_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/videocontrolsupportadapter_fuzzer.h create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/videodevicedescriptoradapter_fuzzer.cpp create mode 100644 test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/videodevicedescriptoradapter_fuzzer.h diff --git a/bundle.json b/bundle.json index f8e23916..e8990550 100644 --- a/bundle.json +++ b/bundle.json @@ -165,12 +165,20 @@ "//base/web/webview/test/fuzztest/ontouchrelease_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/registerarkjsfunction_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/zoom_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/putbackgroundcolor_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/unregisterarkjsfunction_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/sendkeyevent_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/accesstoken_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/audio_adapter:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/resschedadapter_fuzzer:fuzztest", diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/BUILD.gn index f6e93f68..22dbb4ae 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/BUILD.gn @@ -31,13 +31,16 @@ ohos_fuzztest("AafwkAttachRenderFuzzTest") { sources = [ "aafwkattachrender_fuzzer.cpp" ] deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] external_deps = [ + "ability_base:want", "ability_runtime:app_manager", + "bundle_framework:appexecfwk_base", "c_utils:utils", "graphic_2d:libcomposer", "graphic_2d:libgraphic_utils", "graphic_2d:libnative_image", "graphic_2d:librender_service_client", "graphic_surface:surface", + "hilog:libhilog", "ipc:ipc_core", ] } diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/aafwkattachrender_fuzzer.cpp b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/aafwkattachrender_fuzzer.cpp index 4b1a2ad5..e6157883 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/aafwkattachrender_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/aafwkattachrender_fuzzer.cpp @@ -18,23 +18,34 @@ #include #include -#include "aafwk_render_scheduler_impl.h" #include "aafwk_app_mgr_client_adapter_impl.h" +#include "aafwk_render_scheduler_impl.h" using namespace OHOS::NWeb; +using namespace OHOS::AppExecFwk; namespace OHOS { - bool AafwkAttachRenderFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - AafwkAppMgrClientAdapterImpl render; - std::shared_ptr adapter = nullptr; - render.AttachRenderProcess(adapter); - return true; +bool AafwkAttachRenderFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + AafwkAppMgrClientAdapterImpl render; + std::shared_ptr adapter = nullptr; + render.AttachRenderProcess(adapter); + std::shared_ptr newadapter = std::make_shared(); + std::string renderParam = "test"; + int32_t ipcFd = 0; + int32_t sharedFd = 0; + int32_t crashFd = 0; + pid_t renderPid = 0; + newadapter->StartRenderProcess(renderParam, ipcFd, sharedFd, crashFd, renderPid); + pid_t red = 1; + int statused = 1; + newadapter->GetRenderProcessTerminationStatus(red, statused); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/aafwkattachrender_fuzzer.h b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/aafwkattachrender_fuzzer.h index fccbd577..569c41a6 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/aafwkattachrender_fuzzer.h +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkattachrender_fuzzer/aafwkattachrender_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "aafwkattachrender_fuzzer" #endif /* TEST_FUZZTEST_AAFWK_ATTACH_RENDER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..4aeac8e4 --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AafwkBrowserClientAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer" + + include_dirs = [ "$webview_path/ohos_adapter/aafwk_adapter/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "aafwkbrowserclientadapter_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + external_deps = [ + "ability_runtime:app_manager", + "c_utils:utils", + "graphic_2d:libcomposer", + "graphic_2d:libgraphic_utils", + "graphic_2d:libnative_image", + "graphic_2d:librender_service_client", + "graphic_surface:surface", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AafwkBrowserClientAdapterFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/aafwkbrowserclientadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/aafwkbrowserclientadapter_fuzzer.cpp new file mode 100644 index 00000000..0d19c51d --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/aafwkbrowserclientadapter_fuzzer.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022 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 + +#define private public +#include "aafwk_app_mgr_client_adapter_impl.h" +#include "aafwk_browser_client_adapter_impl.h" +#include "aafwk_browser_host_impl.h" +#include "aafwk_render_scheduler_impl.h" +#undef private + +#include "aafwk_browser_client_adapter.h" +#include "aafwk_render_scheduler_host_adapter.h" +#include "app_mgr_client.h" +#include "ibrowser.h" +#include "iconsumer_surface.h" +#include "iremote_proxy.h" +#include "irender_scheduler.h" +#include "ohos_adapter_helper.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +class MockBrowserClient : public BrowserClient { + explicit MockBrowserClient(const sptr& impl); + + sptr QueryRenderSurface(int32_t surface_id); + + void ReportThread(int32_t status, int32_t process_id, int32_t thread_id, int32_t role); + + void PassSurface(sptr surface, int64_t surface_id); + + void DestroyRenderSurface(int32_t surface_id); +}; + +sptr MockBrowserClient::QueryRenderSurface(int32_t surface_id) +{ + (void)surface_id; + return nullptr; +} + +void MockBrowserClient::ReportThread(int32_t status, int32_t process_id, int32_t thread_id, int32_t role) +{ + (void)status; + (void)process_id; + (void)thread_id; + (void)role; +} + +void MockBrowserClient::PassSurface(sptr surface, int64_t surface_id) +{ + (void)surface; + (void)surface_id; +} + +void MockBrowserClient::DestroyRenderSurface(int32_t surface_id) +{ + (void)surface_id; +} + +bool AafwkBrowserClientAdapterFuzzTest(const uint8_t* data, size_t size) +{ + sptr impl; + auto client = new BrowserClient(impl); + int32_t surface_id = 0; + client->QueryRenderSurface(surface_id); + int32_t status = 0; + int32_t process_id = 0; + int32_t thread_id = 0; + int32_t role = 0; + sptr surface; + client->ReportThread(status, process_id, thread_id, role); + client->PassSurface(surface, surface_id); + client->DestroyRenderSurface(surface_id); + + std::shared_ptr clientAdapter = std::make_shared(); + clientAdapter->QueryRenderSurface(surface_id); + ResSchedStatusAdapter newstatus = ResSchedStatusAdapter::THREAD_CREATED; + ResSchedRoleAdapter newrole = ResSchedRoleAdapter::USER_INTERACT; + clientAdapter->ReportThread(newstatus, process_id, thread_id, newrole); + clientAdapter->PassSurface(surface_id); + clientAdapter->DestroyRenderSurface(surface_id); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AafwkBrowserClientAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/aafwkbrowserclientadapter_fuzzer.h b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/aafwkbrowserclientadapter_fuzzer.h new file mode 100644 index 00000000..b578cc7c --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/aafwkbrowserclientadapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_AAFWK_RENDER_SCHEDULER_FUZZER_H +#define TEST_FUZZTEST_AAFWK_RENDER_SCHEDULER_FUZZER_H + +#define FUZZ_PROJECT_NAME "aafwkbrowserclientadapter_fuzzer" +#endif /* TEST_FUZZTEST_AAFWK_RENDER_SCHEDULER_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserclientadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/BUILD.gn new file mode 100644 index 00000000..cd6058cb --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AafwkBrowserHostFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer" + + include_dirs = [ "$webview_path/ohos_adapter/aafwk_adapter/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "aafwkbrowserhost_fuzzer.cpp" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + external_deps = [ + "ability_runtime:app_manager", + "c_utils:utils", + "graphic_2d:libcomposer", + "graphic_2d:libgraphic_utils", + "graphic_2d:libnative_image", + "graphic_2d:librender_service_client", + "graphic_surface:surface", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AafwkBrowserHostFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.cpp b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.cpp new file mode 100644 index 00000000..dfba6bcf --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 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 "aafwkbrowserhost_fuzzer.h" + +#include +#include + +#define private public +#include "aafwk_app_mgr_client_adapter_impl.h" +#include "aafwk_browser_host_impl.h" +#include "aafwk_render_scheduler_impl.h" +#undef private + +#include "aafwk_render_scheduler_host_adapter.h" +#include "app_mgr_client.h" +#include "ohos_adapter_helper.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool AafwkBrowserHostFuzzTest(const uint8_t* data, size_t size) +{ + std::shared_ptr hostAdapter = nullptr; + auto host = new AafwkBrowserHostImpl(hostAdapter); + uint32_t code = 0; + int32_t surface_id = 0; + MessageParcel newdata; + MessageParcel reply; + MessageOption option; + host->OnRemoteRequest(code, newdata, reply, option); + code = 0; + host->OnRemoteRequest(code, newdata, reply, option); + host->HandleQueryRenderSurface(newdata, reply); + host->HandleReportThread(newdata, reply); + host->HandlePassSurface(newdata, reply); + host->HandleDestroyRenderSurface(newdata, reply); + host->QueryRenderSurface(surface_id); + int32_t status = 0; + int32_t process_id = 0; + int32_t thread_id = 0; + int32_t role = 0; + sptr surface; + host->ReportThread(status, process_id, thread_id, role); + host->PassSurface(surface, surface_id); + host->DestroyRenderSurface(surface_id); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AafwkBrowserHostFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.h b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.h new file mode 100644 index 00000000..0d3bef16 --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_AAFWK_RENDER_SCHEDULER_FUZZER_H +#define TEST_FUZZTEST_AAFWK_RENDER_SCHEDULER_FUZZER_H + +#define FUZZ_PROJECT_NAME "aafwkbrowserhost_fuzzer" +#endif /* TEST_FUZZTEST_AAFWK_RENDER_SCHEDULER_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/project.xml b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/BUILD.gn index 82dfc07e..1421a410 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/BUILD.gn @@ -30,14 +30,18 @@ ohos_fuzztest("AafwkRenderSchedulerFuzzTest") { ] sources = [ "aafwkrenderscheduler_fuzzer.cpp" ] deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + external_deps = [ + "ability_base:want", "ability_runtime:app_manager", + "bundle_framework:appexecfwk_base", "c_utils:utils", "graphic_2d:libcomposer", "graphic_2d:libgraphic_utils", "graphic_2d:libnative_image", "graphic_2d:librender_service_client", "graphic_surface:surface", + "hilog:libhilog", "ipc:ipc_core", ] } diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.cpp b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.cpp index 2479e5be..73bde4f8 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.cpp @@ -18,37 +18,51 @@ #include #include +#define private public +#include "aafwk_app_mgr_client_adapter_impl.h" +#include "aafwk_browser_host_impl.h" #include "aafwk_render_scheduler_impl.h" +#undef private + +#include "aafwk_render_scheduler_host_adapter.h" +#include "app_mgr_client.h" +#include "ohos_adapter_helper.h" using namespace OHOS::NWeb; +using namespace OHOS::AppExecFwk; namespace OHOS { - bool AafwkRenderSchedulerFuzzTest(const uint8_t* data, size_t size) - { - constexpr int fdNum = 3; - if ((data == nullptr) || size < fdNum * sizeof(int32_t)) { - return false; - } - std::shared_ptr adapter = nullptr; - AafwkRenderSchedulerImpl render(adapter); - int32_t ipcFd = 0; - int32_t sharedFd = 0; - int32_t crashFd = 0; - if (memcpy_s(&ipcFd, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return false; - } - if (memcpy_s(&sharedFd, sizeof(int32_t), data + sizeof(int32_t), sizeof(int32_t)) != 0) { - return false; - } - - if (memcpy_s(&crashFd, sizeof(int32_t), data + sizeof(int32_t) + sizeof(int32_t), sizeof(int32_t)) != 0) { - return false; - } - - render.NotifyBrowserFd(ipcFd, sharedFd, crashFd, nullptr); - return true; +bool AafwkRenderSchedulerFuzzTest(const uint8_t* data, size_t size) +{ + constexpr int fdNum = 3; + if ((data == nullptr) || size < fdNum * sizeof(int32_t)) { + return false; + } + std::shared_ptr adapter = nullptr; + AafwkRenderSchedulerImpl render(adapter); + int32_t ipcFd = 0; + int32_t sharedFd = 0; + int32_t crashFd = 0; + if (memcpy_s(&ipcFd, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return false; + } + if (memcpy_s(&sharedFd, sizeof(int32_t), data + sizeof(int32_t), sizeof(int32_t)) != 0) { + return false; } + + if (memcpy_s(&crashFd, sizeof(int32_t), data + sizeof(int32_t) + sizeof(int32_t), sizeof(int32_t)) != 0) { + return false; + } + + render.NotifyBrowserFd(ipcFd, sharedFd, crashFd, nullptr); + std::shared_ptr newrender = std::make_shared(adapter); + + newrender->NotifyBrowserFd(ipcFd, sharedFd, crashFd, nullptr); + newrender->renderSchedulerHostAdapter_ = nullptr; + newrender->NotifyBrowserFd(ipcFd, sharedFd, crashFd, nullptr); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.h b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.h index 408e6eb4..93bcf9ce 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.h +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "aafwkrenderscheduler_fuzzer" #endif /* TEST_FUZZTEST_AAFWK_RENDER_SCHEDULER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer/aafwkstartrender_fuzzer.cpp b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer/aafwkstartrender_fuzzer.cpp index 20c86908..b952ddd1 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer/aafwkstartrender_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer/aafwkstartrender_fuzzer.cpp @@ -18,34 +18,34 @@ #include #include -#include "aafwk_render_scheduler_impl.h" #include "aafwk_app_mgr_client_adapter_impl.h" +#include "aafwk_render_scheduler_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool AafwkStartRenderFuzzTest(const uint8_t* data, size_t size) - { - constexpr int fdNum = 2; - if ((data == nullptr) || (size < fdNum * sizeof(int32_t))) { - return false; - } - AafwkAppMgrClientAdapterImpl render; - int32_t ipcFd; - int32_t sharedFd = 0; - int32_t crashFd; - std::string renderParam((const char *)data, size); - pid_t renderPid = 0; - if (memcpy_s(&ipcFd, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return false; - } - if (memcpy_s(&crashFd, sizeof(int32_t), data + sizeof(int32_t), sizeof(int32_t)) != 0) { - return false; - } - render.StartRenderProcess(renderParam, ipcFd, sharedFd, crashFd, renderPid); - return true; +bool AafwkStartRenderFuzzTest(const uint8_t* data, size_t size) +{ + constexpr int fdNum = 2; + if ((data == nullptr) || (size < fdNum * sizeof(int32_t))) { + return false; + } + AafwkAppMgrClientAdapterImpl render; + int32_t ipcFd; + int32_t sharedFd = 0; + int32_t crashFd; + std::string renderParam((const char*)data, size); + pid_t renderPid = 0; + if (memcpy_s(&ipcFd, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return false; + } + if (memcpy_s(&crashFd, sizeof(int32_t), data + sizeof(int32_t), sizeof(int32_t)) != 0) { + return false; } + render.StartRenderProcess(renderParam, ipcFd, sharedFd, crashFd, renderPid); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer/aafwkstartrender_fuzzer.h b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer/aafwkstartrender_fuzzer.h index 0e7ad881..5a53010b 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer/aafwkstartrender_fuzzer.h +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkstartrender_fuzzer/aafwkstartrender_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "aafwkstartrender_fuzzer" #endif /* TEST_FUZZTEST_AAFWK_START_RENDER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/audio_adapter/BUILD.gn b/test/fuzztest/ohos_adapter/audio_adapter/BUILD.gn index 4cf3271c..7be642ed 100644 --- a/test/fuzztest/ohos_adapter/audio_adapter/BUILD.gn +++ b/test/fuzztest/ohos_adapter/audio_adapter/BUILD.gn @@ -43,7 +43,6 @@ group("fuzztest") { "audiointerrupt_fuzzer:AudioInterruptFuzzTest", "audiooutputdevices_fuzzer:AudioOutputDevicesFuzzTest", "audioreleaserender_fuzzer:AudioReleaseRenderFuzzTest", - "audiorenderadapter_fuzzer:AudioRendererAdapterFuzzTest", "audiorequest_fuzzer:AudioRequestFuzzTest", "audiosetcallback_fuzzer:AudioSetCallbackFuzzTest", "audiosetstreamtype_fuzzer:AudioSetStreamtypeFuzzTest", diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..efa9c65a --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("CameraManagerAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/camera_adapter/include", + "$webview_path/ohos_adapter/camera_adapter/src", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "cameramanageradapter_fuzzer.cpp" ] + + defines = [ "NWEB_CAMERA_ENABLE" ] + + deps = [ + "$webview_path/ohos_adapter:nweb_ohos_adapter", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "camera_framework:camera_framework", + "drivers_interface_camera:metadata", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "webview:libnweb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":CameraManagerAdapterFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.cpp new file mode 100644 index 00000000..27726395 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.cpp @@ -0,0 +1,126 @@ +/* + * 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 "cameramanageradapter_fuzzer.h" +#define CAMERA_MANAGER_ADAPTER_IMPL +#define private public +#include "camera_device.h" +#include "camera_manager.h" +#include "camera_manager_adapter_impl.cpp" +#include "camera_manager_adapter_impl.h" +#include "nweb_surface_adapter.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +class CameraStatusCallbackAdapterMock : public CameraStatusCallbackAdapter { +public: + CameraStatusCallbackAdapterMock() {} + ~CameraStatusCallbackAdapterMock() override = default; + + void OnCameraStatusChanged(NWeb::CameraStatusAdapter cameraStatusAdapter, std::string callBackDeviceId) override {} +}; + +class CameraBufferListenerAdapterMock : public CameraBufferListenerAdapter { +public: + CameraBufferListenerAdapterMock() {} + ~CameraBufferListenerAdapterMock() override = default; + + void OnBufferAvailable(std::shared_ptr surface, + std::shared_ptr buffer, + std::shared_ptr rotationInfo) override + {} +}; + +class VideoCaptureParamsAdapterMock : public VideoCaptureParamsAdapter { +public: + VideoCaptureParamsAdapterMock() = default; + + uint32_t GetWidth() override + { + return width; + } + + uint32_t GetHeight() override + { + return height; + } + + float GetFrameRate() override + { + return frameRate; + } + + VideoPixelFormatAdapter GetPixelFormat() override + { + return pixelFormat; + } + + bool GetEnableFaceDetection() override + { + return enableFaceDetection; + } + + uint32_t width; + uint32_t height; + float frameRate; + VideoPixelFormatAdapter pixelFormat; + bool enableFaceDetection; +}; + +bool CameraManagerAdapterFuzzTest(const uint8_t* data, size_t size) +{ + const std::string deviceId((const char*)data, size); + bool ForegroundFlag = static_cast(data[0]); + auto callback = std::make_shared(); + auto listenerAdapter = std::make_shared(); + std::shared_ptr captureParams = std::make_shared(); + CameraManagerAdapterImpl& adapter = CameraManagerAdapterImpl::GetInstance(); + int32_t result = CameraManagerAdapterImpl::GetInstance().Create(callback); + result = CameraManagerAdapterImpl::GetInstance().Create(callback); + + adapter.Create(callback); + std::vector> devicesDiscriptor = adapter.GetDevicesInfo(); + std::vector exposureModesAdapter; + result = adapter.GetExposureModes(exposureModesAdapter); + ExposureModeAdapter exposureModeAdapter; + result = adapter.GetCurrentExposureMode(exposureModeAdapter); + std::shared_ptr rangeVal = adapter.GetExposureCompensation(); + rangeVal = nullptr; + rangeVal = adapter.GetCaptionRangeById(RangeIDAdapter::RANGE_ID_EXP_COMPENSATION); + adapter.GetCurrentFocusMode(); + adapter.IsFocusModeSupported(FocusModeAdapter::FOCUS_MODE_CONTINUOUS_AUTO); + adapter.IsFlashModeSupported(FlashModeAdapter::FLASH_MODE_OPEN); + adapter.RestartSession(); + adapter.StopSession(CameraStopType::NORMAL); + adapter.ReleaseCameraManger(); + adapter.GetCameraStatus(); + adapter.SetCameraStatus(static_cast(-1)); + adapter.GetCurrentDeviceId(); + adapter.IsExistCaptureTask(); + adapter.SetForegroundFlag(ForegroundFlag); + adapter.StartStream(deviceId, captureParams, listenerAdapter); + + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::CameraManagerAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.h b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.h new file mode 100644 index 00000000..ece410e1 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H +#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H + +#define FUZZ_PROJECT_NAME "cameramanageradapter_fuzzer" +#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..00ec9109 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("CameraSurfaceBufferAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/camera_adapter/include", + "$webview_path/ohos_adapter/camera_adapter/src", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "camerasurfacebufferadapter_fuzzer.cpp" ] + + deps = [ + "$webview_path/ohos_adapter:nweb_ohos_adapter", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + defines = [ "NWEB_CAMERA_ENABLE" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "camera_framework:camera_framework", + "drivers_interface_camera:metadata", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "webview:libnweb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":CameraSurfaceBufferAdapterFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.cpp new file mode 100644 index 00000000..616a8ddb --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 "camerasurfacebufferadapter_fuzzer.h" +#define CAMERA_MANAGER_ADAPTER_IMPL +#include "camera_manager_adapter_impl.cpp" +#include "camera_manager_adapter_impl.h" +#include "nweb_surface_adapter.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + +class CameraBufferListenerAdapterMock : public CameraBufferListenerAdapter { +public: + CameraBufferListenerAdapterMock() {} + ~CameraBufferListenerAdapterMock() override = default; + + void OnBufferAvailable(std::shared_ptr surface, + std::shared_ptr buffer, + std::shared_ptr rotationInfo) override + {} +}; + +bool CameraSurfaceBufferAdapterFuzzTest(const uint8_t* data, size_t size) +{ + sptr surface = IConsumerSurface::Create(); + auto listenerAdapter = std::make_shared(); + auto listener = std::make_shared(SurfaceType::PREVIEW, surface, listenerAdapter); + listener->OnBufferAvailable(); + + auto listenerSurfaceAdapter = std::make_shared(surface); + listenerSurfaceAdapter->ReleaseBuffer(nullptr, -1); + NWebSurfaceAdapter::Instance(); + + auto adapterImpl = std::make_shared(nullptr); + int32_t result = adapterImpl->GetFileDescriptor(); + result = adapterImpl->GetWidth(); + result = adapterImpl->GetHeight(); + result = adapterImpl->GetStride(); + result = adapterImpl->GetFormat(); + adapterImpl->GetSize(); + sptr buffer = adapterImpl->GetBuffer(); + adapterImpl->GetBufferAddr(); + + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::CameraSurfaceBufferAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.h b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.h new file mode 100644 index 00000000..da6d9006 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H +#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H + +#define FUZZ_PROJECT_NAME "camerasurfacebufferadapter_fuzzer" +#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..ca3bea27 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("FormatAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/camera_adapter/include", + "$webview_path/ohos_adapter/camera_adapter/src", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "formatadapter_fuzzer.cpp" ] + + defines = [ "NWEB_CAMERA_ENABLE" ] + + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "camera_framework:camera_framework", + "drivers_interface_camera:metadata", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "webview:libnweb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":FormatAdapterFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/formatadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/formatadapter_fuzzer.cpp new file mode 100644 index 00000000..d6590abc --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/formatadapter_fuzzer.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 "formatadapter_fuzzer.h" +#define FORMAT_ADAPTER_IMPL +#define private public +#include "camera_manager_adapter_impl.h" +#include "format_adapter_impl.cpp" +#include "format_adapter_impl.h" +#include "nweb_surface_adapter.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + +bool FormatAdapterFuzzTest(const uint8_t* data, size_t size) +{ + OHOS::NWeb::FormatAdapterImpl adapter; + adapter.SetWidth(1); + adapter.SetHeight(1); + adapter.SetFrameRate(1); + adapter.SetPixelFormat(VideoPixelFormatAdapter::FORMAT_UNKNOWN); + + adapter.GetWidth(); + adapter.GetHeight(); + adapter.GetFrameRate(); + adapter.GetPixelFormat(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FormatAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/formatadapter_fuzzer.h b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/formatadapter_fuzzer.h new file mode 100644 index 00000000..96993612 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/formatadapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H +#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H + +#define FUZZ_PROJECT_NAME "formatadapter_fuzzer" +#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..09378d22 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("VideoCaptureRangeAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/camera_adapter/include", + "$webview_path/ohos_adapter/camera_adapter/src", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "videocapturerangeadapter_fuzzer.cpp" ] + + defines = [ "NWEB_CAMERA_ENABLE" ] + + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "camera_framework:camera_framework", + "drivers_interface_camera:metadata", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "webview:libnweb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":VideoCaptureRangeAdapterFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/videocapturerangeadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/videocapturerangeadapter_fuzzer.cpp new file mode 100644 index 00000000..e5131afa --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/videocapturerangeadapter_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * 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 "videocapturerangeadapter_fuzzer.h" + +#define private public +#include "camera_manager_adapter_impl.h" +#include "video_capture_range_adapter_impl.cpp" +#include "video_capture_range_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + +bool VideoCaptureRangeAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + OHOS::NWeb::VideoCaptureRangeAdapterImpl adapter; + adapter.SetMin(0.0); + adapter.SetMax(1.0); + adapter.SetStep(1.0); + adapter.SetCurrent(0.0); + + adapter.GetMin(); + adapter.GetMax(); + adapter.GetStep(); + adapter.GetCurrent(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::VideoCaptureRangeAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/videocapturerangeadapter_fuzzer.h b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/videocapturerangeadapter_fuzzer.h new file mode 100644 index 00000000..eafd7827 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer/videocapturerangeadapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H +#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H + +#define FUZZ_PROJECT_NAME "videocapturerangeadapter_fuzzer" +#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..2659af36 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("VideoControlSupportAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/camera_adapter/include", + "$webview_path/ohos_adapter/camera_adapter/src", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "videocontrolsupportadapter_fuzzer.cpp" ] + + defines = [ "NWEB_CAMERA_ENABLE" ] + + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "camera_framework:camera_framework", + "drivers_interface_camera:metadata", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "webview:libnweb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":VideoControlSupportAdapterFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/videocontrolsupportadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/videocontrolsupportadapter_fuzzer.cpp new file mode 100644 index 00000000..53b7f7b2 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/videocontrolsupportadapter_fuzzer.cpp @@ -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. + */ + +#include "videocontrolsupportadapter_fuzzer.h" + +#define private public +#include "camera_device.h" +#include "camera_manager.h" +#include "camera_manager_adapter_impl.h" +#include "nweb_surface_adapter.h" +#include "video_control_support_adapter_impl.cpp" +#include "video_control_support_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + +bool VideoControlSupportAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + OHOS::NWeb::VideoControlSupportAdapterImpl adapter; + adapter.SetPan(true); + adapter.SetTilt(true); + adapter.SetZoom(true); + + // 获取adapter的值并忽略它们 + adapter.GetPan(); + adapter.GetTilt(); + adapter.GetZoom(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::VideoControlSupportAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/videocontrolsupportadapter_fuzzer.h b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/videocontrolsupportadapter_fuzzer.h new file mode 100644 index 00000000..bb8e2309 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer/videocontrolsupportadapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H +#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H + +#define FUZZ_PROJECT_NAME "videocontrolsupportadapter_fuzzer" +#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..cf761f33 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("VideoDeviceDescriptorAdapterFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer" + include_dirs = [ + "$webview_path/ohos_adapter/camera_adapter/include", + "$webview_path/ohos_adapter/camera_adapter/src", + "$webview_path/test/fuzztest", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "videodevicedescriptoradapter_fuzzer.cpp" ] + + defines = [ "NWEB_CAMERA_ENABLE" ] + + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "camera_framework:camera_framework", + "drivers_interface_camera:metadata", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "webview:libnweb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":VideoDeviceDescriptorAdapterFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/corpus/init new file mode 100644 index 00000000..6248ced8 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/videodevicedescriptoradapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/videodevicedescriptoradapter_fuzzer.cpp new file mode 100644 index 00000000..aa1473eb --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/videodevicedescriptoradapter_fuzzer.cpp @@ -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. + */ + +#include "videodevicedescriptoradapter_fuzzer.h" + +#define private public +#include "camera_manager_adapter_impl.h" +#include "nweb_surface_adapter.h" +#include "video_device_descriptor_adapter_impl.cpp" +#include "video_device_descriptor_adapter_impl.h" + +using namespace OHOS::NWeb; + +namespace OHOS { + +bool VideoDeviceDescriptorAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + VideoDeviceDescriptorAdapterImpl adapter; + std::string name((const char*)data, size); + std::string deviceId((const char*)data, size); + std::string modelId((const char*)data, size); + adapter.SetDisplayName(name); + adapter.SetDeviceId(deviceId); + adapter.SetModelId(modelId); + + adapter.SetTransportType(VideoTransportType::VIDEO_TRANS_TYPE_USB); + + adapter.SetFacingMode(VideoFacingModeAdapter::FACING_USER); + + adapter.GetDisplayName(); + adapter.GetDeviceId(); + adapter.GetModelId(); + adapter.GetControlSupport(); + adapter.GetTransportType(); + adapter.GetFacingMode(); + adapter.GetSupportCaptureFormats(); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::VideoDeviceDescriptorAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/videodevicedescriptoradapter_fuzzer.h b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/videodevicedescriptoradapter_fuzzer.h new file mode 100644 index 00000000..368b2f27 --- /dev/null +++ b/test/fuzztest/ohos_adapter/camera_adapter/videodevicedescriptoradapter_fuzzer/videodevicedescriptoradapter_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H +#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H + +#define FUZZ_PROJECT_NAME "videodevicedescriptoradapter_fuzzer" +#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ -- Gitee From 95a9ed7abb3d23d663d0d3e69e710b767be9b5d4 Mon Sep 17 00:00:00 2001 From: zouzhiwei Date: Wed, 31 Jul 2024 17:12:25 +0800 Subject: [PATCH 100/126] web_add_fuzz Signed-off-by: zouzhiwei --- bundle.json | 4 + ohos_nweb/etc/para/web.para | 2 +- .../getdeviceids_fuzzer.cpp | 18 +- .../getdeviceids_fuzzer/getdeviceids_fuzzer.h | 1 - .../getkeyboardtype_fuzzer.cpp | 27 +- .../getkeyboardtype_fuzzer.h | 1 - .../ondeviceadded_fuzzer.cpp | 33 +-- .../ondeviceadded_fuzzer.h | 1 - .../ondeviceremoved_fuzzer.cpp | 33 +-- .../ondeviceremoved_fuzzer.h | 1 - .../registerdevlistener_fuzzer.cpp | 24 +- .../registerdevlistener_fuzzer.h | 1 - .../unregisterdevlistener_fuzzer.cpp | 19 +- .../unregisterdevlistener_fuzzer.h | 1 - .../addhtmlrecord_fuzzer.cpp | 29 +- .../addhtmlrecord_fuzzer.h | 1 - .../clipboardtoimagealphatype_fuzzer.cpp | 20 +- .../clipboardtoimagealphatype_fuzzer.h | 1 - .../clipboardtoimagecolortype_fuzzer.cpp | 20 +- .../clipboardtoimagecolortype_fuzzer.h | 1 - .../getimgdata_fuzzer/getimgdata_fuzzer.h | 1 - .../getmimetype_fuzzer/getmimetype_fuzzer.cpp | 29 +- .../getmimetype_fuzzer/getmimetype_fuzzer.h | 1 - .../getrecordat_fuzzer/getrecordat_fuzzer.cpp | 34 +-- .../getrecordat_fuzzer/getrecordat_fuzzer.h | 1 - .../imagetoclipboardalphatype_fuzzer.cpp | 20 +- .../imagetoclipboardalphatype_fuzzer.h | 1 - .../imagetoclipboardcolortype_fuzzer.cpp | 20 +- .../imagetoclipboardcolortype_fuzzer.h | 1 - .../onpasteboardchanged_fuzzer.cpp | 19 +- .../onpasteboardchanged_fuzzer.h | 1 - .../openremoteuri_fuzzer.cpp | 21 +- .../openremoteuri_fuzzer.h | 1 - ...removepasteboardchangedobserver_fuzzer.cpp | 15 +- .../removepasteboardchangedobserver_fuzzer.h | 1 - .../setcustomdata_fuzzer.cpp | 21 +- .../setcustomdata_fuzzer.h | 1 - .../sethtmltext_fuzzer/sethtmltext_fuzzer.cpp | 28 +- .../sethtmltext_fuzzer/sethtmltext_fuzzer.h | 1 - .../setplaintext_fuzzer.cpp | 23 +- .../setplaintext_fuzzer/setplaintext_fuzzer.h | 1 - .../seturi_fuzzer/seturi_fuzzer.cpp | 27 +- .../seturi_fuzzer/seturi_fuzzer.h | 1 - .../createrunninglock_fuzzer.cpp | 18 +- .../createrunninglock_fuzzer.h | 1 - .../isused_fuzzer/isused_fuzzer.cpp | 18 +- .../isused_fuzzer/isused_fuzzer.h | 1 - .../lock_fuzzer/lock_fuzzer.cpp | 20 +- .../lock_fuzzer/lock_fuzzer.h | 1 - .../unlock_fuzzer/unlock_fuzzer.cpp | 18 +- .../unlock_fuzzer/unlock_fuzzer.h | 1 - .../printmanager_adapter_fuzz.cpp | 136 ++++++--- .../printmanager_adapter_fuzz.h | 34 +-- .../resschedadapter_fuzz.cpp | 88 ++++-- .../setandgetrunwebinitcallback_fuzzer.cpp | 53 ++-- .../setandgetrunwebinitcallback_fuzzer.h | 6 +- .../applysocperfconfigbyid_fuzzer.cpp | 25 +- .../applysocperfconfigbyid_fuzzer.h | 1 - .../systemproperties_fuzzer/BUILD.gn | 27 +- .../system_properties_adapter_impl_fuzzer.cpp | 110 ++++---- .../system_properties_adapter_impl_fuzzer.h | 34 +-- .../copyframe_fuzzer/copyframe_fuzzer.cpp | 4 +- .../copyframe_fuzzer/copyframe_fuzzer.h | 1 - .../flushbuffer_fuzzer/flushbuffer_fuzzer.cpp | 6 +- .../flushbuffer_fuzzer/flushbuffer_fuzzer.h | 1 - .../getcookiemanager_fuzzer.cpp | 2 +- .../getcookiemanager_fuzzer.h | 1 - .../getdatabase_fuzzer/getdatabase_fuzzer.cpp | 2 +- .../getdatabase_fuzzer/getdatabase_fuzzer.h | 1 - .../getnweb_fuzzer/getnweb_fuzzer.cpp | 9 +- .../ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.h | 1 - .../getwebstorage_fuzzer.cpp | 2 +- .../getwebstorage_fuzzer.h | 1 - .../ohos_nweb/hisysevent_fuzzer/BUILD.gn | 55 ++++ .../ohos_nweb/hisysevent_fuzzer/corpus/init | 15 + .../hisysevent_fuzzer/hisysevent_fuzzer.cpp | 46 +++ .../hisysevent_fuzzer/hisysevent_fuzzer.h | 20 ++ .../ohos_nweb/hisysevent_fuzzer/project.xml | 25 ++ .../ohos_nweb/initandrun_fuzzer/BUILD.gn | 55 ++++ .../ohos_nweb/initandrun_fuzzer/corpus/init | 15 + .../initandrun_fuzzer/initandrun_fuzzer.cpp | 48 ++++ .../initandrun_fuzzer/initandrun_fuzzer.h | 20 ++ .../ohos_nweb/initandrun_fuzzer/project.xml | 25 ++ .../loadlib_fuzzer/loadlib_fuzzer.cpp | 9 +- .../ohos_nweb/loadlib_fuzzer/loadlib_fuzzer.h | 1 - test/fuzztest/ohos_nweb/napi_fuzzer/BUILD.gn | 55 ++++ .../ohos_nweb/napi_fuzzer/corpus/init | 15 + .../ohos_nweb/napi_fuzzer/napi_fuzzer.cpp | 98 +++++++ .../ohos_nweb/napi_fuzzer/napi_fuzzer.h | 20 ++ .../ohos_nweb/napi_fuzzer/project.xml | 25 ++ .../ohos_nweb/nwebhelper_fuzzer/BUILD.gn | 71 +++++ .../ohos_nweb/nwebhelper_fuzzer/corpus/init | 15 + .../nwebhelper_fuzzer/nweb_create_window.cpp | 105 +++++++ .../nwebhelper_fuzzer/nweb_create_window.h | 230 +++++++++++++++ .../nwebhelper_fuzzer/nwebhelper_fuzzer.cpp | 261 ++++++++++++++++++ .../nwebhelper_fuzzer/nwebhelper_fuzzer.h | 20 ++ .../ohos_nweb/nwebhelper_fuzzer/project.xml | 25 ++ .../requestbuffer_fuzzer.cpp | 4 +- .../requestbuffer_fuzzer.h | 1 - .../selectcertrequest_fuzzer.cpp | 10 +- .../selectcertrequest_fuzzer.h | 1 - .../sethttpdns_fuzzer/sethttpdns_fuzzer.cpp | 6 +- .../sethttpdns_fuzzer/sethttpdns_fuzzer.h | 1 - 103 files changed, 1884 insertions(+), 543 deletions(-) create mode 100644 test/fuzztest/ohos_nweb/hisysevent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_nweb/hisysevent_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_nweb/hisysevent_fuzzer/hisysevent_fuzzer.cpp create mode 100644 test/fuzztest/ohos_nweb/hisysevent_fuzzer/hisysevent_fuzzer.h create mode 100644 test/fuzztest/ohos_nweb/hisysevent_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_nweb/initandrun_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_nweb/initandrun_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_nweb/initandrun_fuzzer/initandrun_fuzzer.cpp create mode 100644 test/fuzztest/ohos_nweb/initandrun_fuzzer/initandrun_fuzzer.h create mode 100644 test/fuzztest/ohos_nweb/initandrun_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_nweb/napi_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_nweb/napi_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_nweb/napi_fuzzer/napi_fuzzer.cpp create mode 100644 test/fuzztest/ohos_nweb/napi_fuzzer/napi_fuzzer.h create mode 100644 test/fuzztest/ohos_nweb/napi_fuzzer/project.xml create mode 100644 test/fuzztest/ohos_nweb/nwebhelper_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ohos_nweb/nwebhelper_fuzzer/corpus/init create mode 100644 test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nweb_create_window.cpp create mode 100644 test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nweb_create_window.h create mode 100644 test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nwebhelper_fuzzer.cpp create mode 100644 test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nwebhelper_fuzzer.h create mode 100644 test/fuzztest/ohos_nweb/nwebhelper_fuzzer/project.xml diff --git a/bundle.json b/bundle.json index f8e23916..68455cc8 100644 --- a/bundle.json +++ b/bundle.json @@ -258,6 +258,10 @@ "//base/web/webview/test/fuzztest/ohos_nweb/flushbuffer_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_nweb/sethttpdns_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_nweb/selectcertrequest_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_nweb/napi_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_nweb/initandrun_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_nweb/nwebhelper_fuzzer:fuzztest", + "//base/web/webview/test/fuzztest/ohos_nweb/hisysevent_fuzzer:fuzztest", "//base/web/webview/test/unittest/nweb_value_test:unittest", "//base/web/webview/test/unittest/display_manager_adapter_impl_test:unittest", "//base/web/webview/test/unittest/net_connect_adapter_test:unittest", diff --git a/ohos_nweb/etc/para/web.para b/ohos_nweb/etc/para/web.para index a0f53185..f9cdee6d 100644 --- a/ohos_nweb/etc/para/web.para +++ b/ohos_nweb/etc/para/web.para @@ -15,7 +15,7 @@ web.optimization=true web.debug.devtools = false web.debug.netlog = None web.debug.trace = false -web.debug.strictsiteIsolation.enable = false +web.debug.strictsiteIsolation.enable = none web.oop.gpu = None web.PRPPreload.enable = true persist.arkwebcore.install_path = /module_update/ArkWebCore/app/com.ohos.nweb/NWeb.hap diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.cpp index f724f7b9..f46deed3 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.cpp @@ -20,17 +20,17 @@ using namespace OHOS::NWeb; namespace OHOS { - bool GetDeviceIdsFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr AdapterImpl = std::make_shared(); - std::vector devList; - AdapterImpl->GetDeviceIds(devList); - return true; +bool GetDeviceIdsFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr AdapterImpl = std::make_shared(); + std::vector devList; + AdapterImpl->GetDeviceIds(devList); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.h index 1513eb01..88e3fe5a 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.h +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "getkeyboardtype_fuzzer" #endif /* TEST_FUZZTEST_GETKEYBOARDTYPE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.cpp index 8b8f2691..13f11085 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.cpp @@ -16,26 +16,27 @@ #include "getkeyboardtype_fuzzer.h" #include + #include "mmi_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool GetKeyboardTypeFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return false; - } - std::shared_ptr AdapterImpl = std::make_shared(); - int32_t deviceId; - if (memcpy_s(&deviceId, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return false; - } - int32_t type; - AdapterImpl->GetKeyboardType(deviceId, type); - return true; +bool GetKeyboardTypeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return false; + } + std::shared_ptr AdapterImpl = std::make_shared(); + int32_t deviceId; + if (memcpy_s(&deviceId, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return false; } + int32_t type; + AdapterImpl->GetKeyboardType(deviceId, type); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.h index 1513eb01..88e3fe5a 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.h +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "getkeyboardtype_fuzzer" #endif /* TEST_FUZZTEST_GETKEYBOARDTYPE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.cpp index 8c42c558..2da3d17a 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.cpp @@ -16,6 +16,7 @@ #include "ondeviceadded_fuzzer.h" #include + #include "mmi_adapter_impl.h" using namespace OHOS::NWeb; @@ -25,25 +26,25 @@ class MMIListenerTest : public MMIListenerAdapter { public: MMIListenerTest() = default; virtual ~MMIListenerTest() = default; - void OnDeviceAdded(int32_t deviceId, const std::string &type) override {}; - void OnDeviceRemoved(int32_t deviceId, const std::string &type) override {}; + void OnDeviceAdded(int32_t deviceId, const std::string& type) override {}; + void OnDeviceRemoved(int32_t deviceId, const std::string& type) override {}; }; - bool OnDeviceAddedFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return false; - } - std::shared_ptr listener = std::make_shared(); - auto listenerAdapterImpl = std::make_shared(listener); - int32_t deviceId; - if (memcpy_s(&deviceId, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return false; - } - std::string type((const char*) data, size); - listenerAdapterImpl->OnDeviceAdded(deviceId, type); - return true; +bool OnDeviceAddedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return false; + } + std::shared_ptr listener = std::make_shared(); + auto listenerAdapterImpl = std::make_shared(listener); + int32_t deviceId; + if (memcpy_s(&deviceId, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return false; } + std::string type((const char*)data, size); + listenerAdapterImpl->OnDeviceAdded(deviceId, type); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.h index 05c2a41c..43f33783 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.h +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "ondeviceadded_fuzzer" #endif /* TEST_FUZZTEST_ONDEVICEADDED_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.cpp index 0f2e590c..a6a128ec 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.cpp @@ -17,6 +17,7 @@ #include #include + #include "mmi_adapter_impl.h" using namespace OHOS::NWeb; @@ -26,25 +27,25 @@ class MMIListenerTest : public MMIListenerAdapter { public: MMIListenerTest() = default; virtual ~MMIListenerTest() = default; - void OnDeviceAdded(int32_t deviceId, const std::string &type) override {}; - void OnDeviceRemoved(int32_t deviceId, const std::string &type) override {}; + void OnDeviceAdded(int32_t deviceId, const std::string& type) override {}; + void OnDeviceRemoved(int32_t deviceId, const std::string& type) override {}; }; - bool OnDeviceRemovedFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return false; - } - std::shared_ptr listener = std::make_shared(); - auto listenerAdapterImpl = std::make_shared(listener); - int32_t deviceId; - if (memcpy_s(&deviceId, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return false; - } - std::string type((const char*) data, size); - listenerAdapterImpl->OnDeviceRemoved(deviceId, type); - return true; +bool OnDeviceRemovedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return false; + } + std::shared_ptr listener = std::make_shared(); + auto listenerAdapterImpl = std::make_shared(listener); + int32_t deviceId; + if (memcpy_s(&deviceId, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return false; } + std::string type((const char*)data, size); + listenerAdapterImpl->OnDeviceRemoved(deviceId, type); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.h index b485ad8d..a80a3b66 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.h +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "ondeviceremoved_fuzzer" #endif /* TEST_FUZZTEST_ONDEVICEREMOVED_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.cpp index fe12dfff..3769feb5 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.cpp @@ -23,21 +23,21 @@ class MMIListenerTest : public MMIListenerAdapter { public: MMIListenerTest() = default; virtual ~MMIListenerTest() = default; - void OnDeviceAdded(int32_t deviceId, const std::string &type) override {}; - void OnDeviceRemoved(int32_t deviceId, const std::string &type) override {}; + void OnDeviceAdded(int32_t deviceId, const std::string& type) override {}; + void OnDeviceRemoved(int32_t deviceId, const std::string& type) override {}; }; - bool RegisterDevListenerFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr listener = std::make_shared(); - std::shared_ptr AdapterImpl = std::make_shared(); - std::string type((const char*) data, size); - AdapterImpl->RegisterDevListener(type, listener); - return true; +bool RegisterDevListenerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr listener = std::make_shared(); + std::shared_ptr AdapterImpl = std::make_shared(); + std::string type((const char*)data, size); + AdapterImpl->RegisterDevListener(type, listener); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.h index 05c2a41c..43f33783 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.h +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "ondeviceadded_fuzzer" #endif /* TEST_FUZZTEST_ONDEVICEADDED_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.cpp index 2c55b744..fcd0cb29 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.cpp @@ -16,22 +16,23 @@ #include "unregisterdevlistener_fuzzer.h" #include + #include "mmi_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool UnregisterDevListenerFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr AdapterImpl = std::make_shared(); - std::string type((const char*) data, size); - AdapterImpl->UnregisterDevListener(type); - return true; +bool UnregisterDevListenerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr AdapterImpl = std::make_shared(); + std::string type((const char*)data, size); + AdapterImpl->UnregisterDevListener(type); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.h index 290728d5..5b6db8be 100755 --- a/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.h +++ b/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "unregisterdevlistener_fuzzer" #endif /* TEST_FUZZTEST_UNREGISTERDEVLISTENER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.cpp index 4e758fed..291d3174 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.cpp @@ -14,27 +14,28 @@ */ #include "addhtmlrecord_fuzzer.h" + #include "pasteboard_client_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool AddHtmlRecordFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::string html((const char*) data, size); - std::shared_ptr dataAdapterImpl = std::make_shared(); - dataAdapterImpl->AddHtmlRecord(html); - dataAdapterImpl->AddTextRecord(html); - dataAdapterImpl->GetMimeTypes(); - dataAdapterImpl->GetPrimaryHtml(); - dataAdapterImpl->GetPrimaryText(); - dataAdapterImpl->GetPrimaryMimeType(); - return true; +bool AddHtmlRecordFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::string html((const char*)data, size); + std::shared_ptr dataAdapterImpl = std::make_shared(); + dataAdapterImpl->AddHtmlRecord(html); + dataAdapterImpl->AddTextRecord(html); + dataAdapterImpl->GetMimeTypes(); + dataAdapterImpl->GetPrimaryHtml(); + dataAdapterImpl->GetPrimaryText(); + dataAdapterImpl->GetPrimaryMimeType(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.h index 08719896..1719c024 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "addhtmlrecord_fuzzer" #endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.cpp index ef89ad7e..a1f933e6 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.cpp @@ -21,18 +21,18 @@ using namespace OHOS::NWeb; namespace OHOS { - bool ClipboardToImageAlphaTypeFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr dataRecordAdapterImpl = - std::make_shared("pixelMap"); - ClipBoardImageAlphaType alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN; - dataRecordAdapterImpl->ClipboardToImageAlphaType(alphaType); - return true; +bool ClipboardToImageAlphaTypeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr dataRecordAdapterImpl = + std::make_shared("pixelMap"); + ClipBoardImageAlphaType alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN; + dataRecordAdapterImpl->ClipboardToImageAlphaType(alphaType); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.h index 8fecaf29..706ac86e 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "clipboardtoimagealphatype_fuzzer" #endif /* TEST_FUZZTEST_CLIPBOARDTOIMAGEALPHATYPE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.cpp index ff9db115..0a7a6afb 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.cpp @@ -21,18 +21,18 @@ using namespace OHOS::NWeb; namespace OHOS { - bool ClipboardToImageColorTypeFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr dataRecordAdapterImpl = - std::make_shared("pixelMap"); - ClipBoardImageColorType colorType = ClipBoardImageColorType::COLOR_TYPE_RGBA_8888; - dataRecordAdapterImpl->ClipboardToImageColorType(colorType); - return true; +bool ClipboardToImageColorTypeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr dataRecordAdapterImpl = + std::make_shared("pixelMap"); + ClipBoardImageColorType colorType = ClipBoardImageColorType::COLOR_TYPE_RGBA_8888; + dataRecordAdapterImpl->ClipboardToImageColorType(colorType); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.h index 6e495431..db85872a 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "clipboardtoimagecolortype_fuzzer" #endif /* TEST_FUZZTEST_CLIPBOARDTOIMAGECOLORTYPE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/getimgdata_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/getimgdata_fuzzer.h index 24d72dda..d6f02b50 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/getimgdata_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/getimgdata_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "getimgdata_fuzzer" #endif /* TEST_FUZZTEST_GETIMGDATA_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.cpp index 0699183f..9976d28c 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.cpp @@ -14,27 +14,28 @@ */ #include "getmimetype_fuzzer.h" + #include "pasteboard_client_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool GetMimeTypeFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::string text((const char*) data, size); - std::shared_ptr plainText = std::make_shared(text); - std::shared_ptr htmlText = std::make_shared(text); - std::shared_ptr dataRecordAdapterImpl = - std::make_shared(text, htmlText, plainText); - dataRecordAdapterImpl->GetMimeType(); - dataRecordAdapterImpl->GetHtmlText(); - dataRecordAdapterImpl->GetPlainText(); - return true; +bool GetMimeTypeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::string text((const char*)data, size); + std::shared_ptr plainText = std::make_shared(text); + std::shared_ptr htmlText = std::make_shared(text); + std::shared_ptr dataRecordAdapterImpl = + std::make_shared(text, htmlText, plainText); + dataRecordAdapterImpl->GetMimeType(); + dataRecordAdapterImpl->GetHtmlText(); + dataRecordAdapterImpl->GetPlainText(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.h index d67bb2b3..6849cf71 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "getmimetype_fuzzer" #endif /* TEST_FUZZTEST_GETMIMETYPE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.cpp index d49b56e7..78ab577f 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.cpp @@ -14,28 +14,30 @@ */ #include "getrecordat_fuzzer.h" -#include "pasteboard_client_adapter_impl.h" + #include + +#include "pasteboard_client_adapter_impl.h" using namespace OHOS::NWeb; using namespace OHOS::MiscServices; namespace OHOS { - bool GetRecordAtFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(size_t))) { - return false; - } - std::size_t index = 0; - if (memcpy_s(&index, sizeof(size_t), data, sizeof(size_t)) != 0) { - return false; - } - std::shared_ptr dataName = std::make_shared(); - std::shared_ptr dataAdapterImpl = std::make_shared(dataName); - dataAdapterImpl->GetRecordAt(index); - dataAdapterImpl->GetRecordCount(); - dataAdapterImpl->AllRecords(); - return true; +bool GetRecordAtFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(size_t))) { + return false; + } + std::size_t index = 0; + if (memcpy_s(&index, sizeof(size_t), data, sizeof(size_t)) != 0) { + return false; } + std::shared_ptr dataName = std::make_shared(); + std::shared_ptr dataAdapterImpl = std::make_shared(dataName); + dataAdapterImpl->GetRecordAt(index); + dataAdapterImpl->GetRecordCount(); + dataAdapterImpl->AllRecords(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.h index b36060ba..876fd5f9 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "getrecordat_fuzzer" #endif /* TEST_FUZZTEST_GETRECORDAT_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.cpp index 1f5de9c3..1b8c07d7 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.cpp @@ -21,18 +21,18 @@ using namespace OHOS::NWeb; namespace OHOS { - bool ImageToClipboardAlphaTypeFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr dataRecordAdapterImpl = - std::make_shared("pixelMap"); - Media::ImageInfo imgInfo; - dataRecordAdapterImpl->ImageToClipboardAlphaType(imgInfo); - return true; +bool ImageToClipboardAlphaTypeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr dataRecordAdapterImpl = + std::make_shared("pixelMap"); + Media::ImageInfo imgInfo; + dataRecordAdapterImpl->ImageToClipboardAlphaType(imgInfo); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.h index 1eb1929a..882e3f6d 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "imagetoclipboardalphatype_fuzzer" #endif /* TEST_FUZZTEST_IMAGETOCLIPBOARDALPHATYPE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.cpp index 4af931bf..1bce3c0e 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.cpp @@ -21,18 +21,18 @@ using namespace OHOS::NWeb; namespace OHOS { - bool ImageToClipboardColorTypeFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr dataRecordAdapterImpl = - std::make_shared("pixelMap"); - Media::ImageInfo imgInfo; - dataRecordAdapterImpl->ImageToClipboardColorType(imgInfo); - return true; +bool ImageToClipboardColorTypeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr dataRecordAdapterImpl = + std::make_shared("pixelMap"); + Media::ImageInfo imgInfo; + dataRecordAdapterImpl->ImageToClipboardColorType(imgInfo); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.h index 00671cee..f731ed56 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "imagetoclipboardcolortype_fuzzer" #endif /* TEST_FUZZTEST_IMAGETOCLIPBOARDCOLORTYPE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.cpp index 5634f1f5..fea1053d 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.cpp @@ -14,6 +14,7 @@ */ #include "onpasteboardchanged_fuzzer.h" + #include "pasteboard_client_adapter_impl.h" using namespace OHOS::NWeb; @@ -24,17 +25,17 @@ public: MockPasteboardObserver() = default; void OnPasteboardChanged() override {} }; - bool OnPasteboardChangedFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr observer = std::make_shared(); - PasteboardObserverAdapterImpl observerImpl(observer); - observerImpl.OnPasteboardChanged(); - return true; +bool OnPasteboardChangedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr observer = std::make_shared(); + PasteboardObserverAdapterImpl observerImpl(observer); + observerImpl.OnPasteboardChanged(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.h index 3f53ba2d..81fa5411 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "onpasteboardchanged_fuzzer" #endif /* TEST_FUZZTEST_ONPASTEBOARDCHANGED_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.cpp index 922b2810..c9e93f0c 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.cpp @@ -14,23 +14,24 @@ */ #include "openremoteuri_fuzzer.h" + #include "pasteboard_client_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool OpenRemoteUriFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::string path((const char*) data, size); - PasteBoardClientAdapterImpl::GetInstance().OpenRemoteUri(path); - PasteBoardClientAdapterImpl::GetInstance().IsLocalPaste(); - PasteBoardClientAdapterImpl::GetInstance().GetTokenId(); - return true; +bool OpenRemoteUriFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::string path((const char*)data, size); + PasteBoardClientAdapterImpl::GetInstance().OpenRemoteUri(path); + PasteBoardClientAdapterImpl::GetInstance().IsLocalPaste(); + PasteBoardClientAdapterImpl::GetInstance().GetTokenId(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.h index 842ae1b1..c2cd30f7 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "openremoteuri_fuzzer" #endif /* TEST_FUZZTEST_OPENREMOTEURI_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.cpp index 3b8af8dc..ba80ae3f 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.cpp @@ -14,6 +14,7 @@ */ #include "removepasteboardchangedobserver_fuzzer.h" + #include "pasteboard_client_adapter_impl.h" using namespace OHOS::NWeb; @@ -24,15 +25,15 @@ public: MockPasteboardObserver() = default; void OnPasteboardChanged() override {} }; - bool RemovePasteboardChangedObserverFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(-1); - return true; +bool RemovePasteboardChangedObserverFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(-1); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.h index 760a9767..dae4d331 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "removepasteboardchangedobserver_fuzzer" #endif /* TEST_FUZZTEST_REMOVEPASTEBOARDCHANGEDOBSERVER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.cpp index ea0e4ad1..320b0d7d 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.cpp @@ -14,23 +14,24 @@ */ #include "setcustomdata_fuzzer.h" + #include "pasteboard_client_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool SetCustomDataFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr dataRecordAdapterImpl = - std::make_shared("pixelMap"); - PasteCustomData testData; - dataRecordAdapterImpl->SetCustomData(testData); - return true; +bool SetCustomDataFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr dataRecordAdapterImpl = + std::make_shared("pixelMap"); + PasteCustomData testData; + dataRecordAdapterImpl->SetCustomData(testData); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.h index c61fd755..b81d976e 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "setcustomdata_fuzzer" #endif /* TEST_FUZZTEST_SETCUSTOMDATA_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.cpp index 071dc1a2..02f642e5 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.cpp @@ -22,22 +22,22 @@ using namespace OHOS::NWeb; using namespace OHOS::MiscServices; namespace OHOS { - bool SetHtmlTextFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr record = std::make_shared(); - std::shared_ptr dataRecordAdapterImpl = - std::make_shared(record); - dataRecordAdapterImpl->record_=nullptr; - std::string text((const char*) data, size); - std::shared_ptr dataRecordAdapter = PasteDataRecordAdapter::NewRecord(text); - std::shared_ptr htmlText = std::make_shared(text); - dataRecordAdapter->SetHtmlText(htmlText); - return true; +bool SetHtmlTextFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr record = std::make_shared(); + std::shared_ptr dataRecordAdapterImpl = + std::make_shared(record); + dataRecordAdapterImpl->record_ = nullptr; + std::string text((const char*)data, size); + std::shared_ptr dataRecordAdapter = PasteDataRecordAdapter::NewRecord(text); + std::shared_ptr htmlText = std::make_shared(text); + dataRecordAdapter->SetHtmlText(htmlText); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.h index 75844228..25b7699c 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "sethtmltext_fuzzer" #endif /* TEST_FUZZTEST_SETHTMLTEXT_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.cpp index 809c0ef5..d3d6c843 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.cpp @@ -14,24 +14,25 @@ */ #include "setplaintext_fuzzer.h" + #include "pasteboard_client_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool SetPlainTextFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::string text((const char*) data, size); - std::shared_ptr dataRecordAdapterImpl = - std::make_shared(text); - std::shared_ptr plainText = std::make_shared(text); - dataRecordAdapterImpl->SetPlainText(plainText); - return true; +bool SetPlainTextFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::string text((const char*)data, size); + std::shared_ptr dataRecordAdapterImpl = + std::make_shared(text); + std::shared_ptr plainText = std::make_shared(text); + dataRecordAdapterImpl->SetPlainText(plainText); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.h index b9684cb3..962c251e 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "setplaintext_fuzzer" #endif /* TEST_FUZZTEST_SETPLAINTEXT_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.cpp index 7ff03527..3b9b2cc3 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.cpp @@ -14,26 +14,27 @@ */ #include "seturi_fuzzer.h" + #include "pasteboard_client_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool SetUriFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::string text((const char*) data, size); - std::shared_ptr plainText = std::make_shared(text); - std::shared_ptr htmlText = std::make_shared(text); - std::shared_ptr dataRecordAdapterImpl = - PasteDataRecordAdapter::NewRecord(text, htmlText, plainText); - std::string uriString((const char*) data, size); - dataRecordAdapterImpl->SetUri(uriString); - return true; +bool SetUriFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::string text((const char*)data, size); + std::shared_ptr plainText = std::make_shared(text); + std::shared_ptr htmlText = std::make_shared(text); + std::shared_ptr dataRecordAdapterImpl = + PasteDataRecordAdapter::NewRecord(text, htmlText, plainText); + std::string uriString((const char*)data, size); + dataRecordAdapterImpl->SetUri(uriString); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.h index b49a05e8..540b1204 100755 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.h +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "seturi_fuzzer" #endif /* TEST_FUZZTEST_SETURL_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/power_mgr_adapter/createrunninglock_fuzzer/createrunninglock_fuzzer.cpp b/test/fuzztest/ohos_adapter/power_mgr_adapter/createrunninglock_fuzzer/createrunninglock_fuzzer.cpp index 9b6f9540..50b052e6 100644 --- a/test/fuzztest/ohos_adapter/power_mgr_adapter/createrunninglock_fuzzer/createrunninglock_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/power_mgr_adapter/createrunninglock_fuzzer/createrunninglock_fuzzer.cpp @@ -23,17 +23,17 @@ using namespace OHOS::NWeb; namespace OHOS { - bool CreateRunningLockFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::string name((const char *)data, size); - PowerMgrClientAdapterImpl powerMgrClientAdapter; - powerMgrClientAdapter.CreateRunningLock(name, RunningLockAdapterType::SCREEN); - return true; +bool CreateRunningLockFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::string name((const char*)data, size); + PowerMgrClientAdapterImpl powerMgrClientAdapter; + powerMgrClientAdapter.CreateRunningLock(name, RunningLockAdapterType::SCREEN); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/power_mgr_adapter/createrunninglock_fuzzer/createrunninglock_fuzzer.h b/test/fuzztest/ohos_adapter/power_mgr_adapter/createrunninglock_fuzzer/createrunninglock_fuzzer.h index b67d8cbd..9172b2b0 100644 --- a/test/fuzztest/ohos_adapter/power_mgr_adapter/createrunninglock_fuzzer/createrunninglock_fuzzer.h +++ b/test/fuzztest/ohos_adapter/power_mgr_adapter/createrunninglock_fuzzer/createrunninglock_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "createrunninglock_fuzzer" #endif /* TEST_FUZZTEST_CREATE_RUNNIG_LOCK_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/power_mgr_adapter/isused_fuzzer/isused_fuzzer.cpp b/test/fuzztest/ohos_adapter/power_mgr_adapter/isused_fuzzer/isused_fuzzer.cpp index b6dbf09f..58b97505 100644 --- a/test/fuzztest/ohos_adapter/power_mgr_adapter/isused_fuzzer/isused_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/power_mgr_adapter/isused_fuzzer/isused_fuzzer.cpp @@ -23,17 +23,17 @@ using namespace OHOS::NWeb; namespace OHOS { - bool IsUsedFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr lock; - RunningLockAdapterImpl runningLockAdapter(lock); - runningLockAdapter.IsUsed(); - return true; +bool IsUsedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr lock; + RunningLockAdapterImpl runningLockAdapter(lock); + runningLockAdapter.IsUsed(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/power_mgr_adapter/isused_fuzzer/isused_fuzzer.h b/test/fuzztest/ohos_adapter/power_mgr_adapter/isused_fuzzer/isused_fuzzer.h index 0a384abe..edeabda5 100644 --- a/test/fuzztest/ohos_adapter/power_mgr_adapter/isused_fuzzer/isused_fuzzer.h +++ b/test/fuzztest/ohos_adapter/power_mgr_adapter/isused_fuzzer/isused_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "isused_fuzzer" #endif /* TEST_FUZZTEST_IS_USED_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/power_mgr_adapter/lock_fuzzer/lock_fuzzer.cpp b/test/fuzztest/ohos_adapter/power_mgr_adapter/lock_fuzzer/lock_fuzzer.cpp index e7e085f4..60f9a317 100644 --- a/test/fuzztest/ohos_adapter/power_mgr_adapter/lock_fuzzer/lock_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/power_mgr_adapter/lock_fuzzer/lock_fuzzer.cpp @@ -23,18 +23,18 @@ using namespace OHOS::NWeb; namespace OHOS { - bool LockFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - uint32_t timeOutMs = static_cast(size); - std::shared_ptr lock; - RunningLockAdapterImpl runningLockAdapter(lock); - runningLockAdapter.Lock(timeOutMs); - return true; +bool LockFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + uint32_t timeOutMs = static_cast(size); + std::shared_ptr lock; + RunningLockAdapterImpl runningLockAdapter(lock); + runningLockAdapter.Lock(timeOutMs); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/power_mgr_adapter/lock_fuzzer/lock_fuzzer.h b/test/fuzztest/ohos_adapter/power_mgr_adapter/lock_fuzzer/lock_fuzzer.h index 4b901b4b..93855940 100644 --- a/test/fuzztest/ohos_adapter/power_mgr_adapter/lock_fuzzer/lock_fuzzer.h +++ b/test/fuzztest/ohos_adapter/power_mgr_adapter/lock_fuzzer/lock_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "lock_fuzzer" #endif /* TEST_FUZZTEST_LOCK_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/power_mgr_adapter/unlock_fuzzer/unlock_fuzzer.cpp b/test/fuzztest/ohos_adapter/power_mgr_adapter/unlock_fuzzer/unlock_fuzzer.cpp index 6ed2b7b1..42883ab2 100644 --- a/test/fuzztest/ohos_adapter/power_mgr_adapter/unlock_fuzzer/unlock_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/power_mgr_adapter/unlock_fuzzer/unlock_fuzzer.cpp @@ -23,17 +23,17 @@ using namespace OHOS::NWeb; namespace OHOS { - bool UnLockFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr lock; - RunningLockAdapterImpl runningLockAdapter(lock); - runningLockAdapter.UnLock(); - return true; +bool UnLockFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr lock; + RunningLockAdapterImpl runningLockAdapter(lock); + runningLockAdapter.UnLock(); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/power_mgr_adapter/unlock_fuzzer/unlock_fuzzer.h b/test/fuzztest/ohos_adapter/power_mgr_adapter/unlock_fuzzer/unlock_fuzzer.h index 782d3c30..82eb9482 100644 --- a/test/fuzztest/ohos_adapter/power_mgr_adapter/unlock_fuzzer/unlock_fuzzer.h +++ b/test/fuzztest/ohos_adapter/power_mgr_adapter/unlock_fuzzer/unlock_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "unlock_fuzzer" #endif /* TEST_FUZZTEST_UNLOCK_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.cpp b/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.cpp index 48267d74..d02ceca8 100644 --- a/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.cpp +++ b/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.cpp @@ -1,46 +1,96 @@ -/* - * 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 "printmanager_adapter_fuzz.h" -#include "print_manager_adapter_impl.h" - -namespace OHOS::NWeb { - -bool PrintManagerAdapterFuzzTest(const uint8_t* data, size_t size) { - // Fuzzing logic for PrintManagerAdapterImpl - // Parse input data and test class functions - - // Example: Parse input data - std::string input(reinterpret_cast(data), size); - - // Example: Call a function of PrintManagerAdapterImpl with input - std::vector fileList = {input}; - std::vector fdList = {0}; // Example file descriptor list - std::string taskId; - PrintManagerAdapterImpl::GetInstance().StartPrint(fileList, fdList, taskId); - - // Return true if the fuzz test passes - return true; -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - // Run your code on data - OHOS::NWeb::PrintManagerAdapterFuzzTest(data, size); - return 0; +/* + * 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 "printmanager_adapter_fuzz.h" + +#include +#include +#include +#include +#include + +#include "print_manager_adapter_impl.h" + +namespace OHOS::NWeb { + +const size_t MAX_LEN_STRING = 256; +const size_t MAX_FD_LIST_SIZE = 10; + +bool StartPrintFuzzTest(PrintManagerAdapterImpl& adapter, const uint8_t* data, size_t size) +{ + std::vector fileList; + std::vector fdList; + + for (size_t i = 0; i < (size % MAX_FD_LIST_SIZE + 1); ++i) { + std::string fileName(reinterpret_cast(data), std::min(size, MAX_LEN_STRING - 1)); + fileList.push_back(fileName); + fdList.push_back(i); + } + + std::string taskId; + + adapter.StartPrint(fileList, fdList, taskId); + return true; +} + +bool PrintFuzzTest(PrintManagerAdapterImpl& adapter, const uint8_t* data, size_t size) +{ + std::string printJobName(reinterpret_cast(data), std::min(size, MAX_LEN_STRING - 1)); + std::shared_ptr listener = nullptr; + PrintAttributesAdapter printAttributes; + + adapter.Print(printJobName, listener, printAttributes); + return true; +} + +bool PrintWithContextFuzzTest(PrintManagerAdapterImpl& adapter, const uint8_t* data, size_t size) +{ + std::string printJobName(reinterpret_cast(data), std::min(size, MAX_LEN_STRING - 1)); + std::shared_ptr listener = nullptr; + PrintAttributesAdapter printAttributes; + void* contextToken = nullptr; + + adapter.Print(printJobName, listener, printAttributes, contextToken); + + return true; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (size == 0) { + return 0; + } + + PrintManagerAdapterImpl& adapter = PrintManagerAdapterImpl::GetInstance(); + + enum PrintFuzzOperation { START_PRINT, PRINT, PRINT_WITH_CONTEXT, MAX_PRINT_OPERATION }; + + PrintFuzzOperation operation = static_cast(data[0] % MAX_PRINT_OPERATION); + + switch (operation) { + case START_PRINT: + return StartPrintFuzzTest(adapter, data + 1, size - 1); + case PRINT: + return PrintFuzzTest(adapter, data + 1, size - 1); + case PRINT_WITH_CONTEXT: + return PrintWithContextFuzzTest(adapter, data + 1, size - 1); + default: + return 0; + } + + return 0; } } // namespace OHOS::NWeb \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.h b/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.h index bf952a81..4713e91c 100644 --- a/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.h +++ b/test/fuzztest/ohos_adapter/printmanager_fuzzer/printmanager_adapter_fuzz.h @@ -1,21 +1,21 @@ -/* - * 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. - */ +/* + * 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 PRINTMANAGER_ADAPTER_FUZZ_TEST_H -#define PRINTMANAGER_ADAPTER_FUZZ_TEST_H +#ifndef PRINTMANAGER_ADAPTER_FUZZ_TEST_H +#define PRINTMANAGER_ADAPTER_FUZZ_TEST_H #define FUZZ_PROJECT_NAME "printmanageradapter_fuzzer" -#endif // PRINTMANAGER_ADAPTER_FUZZ_TEST_H \ No newline at end of file +#endif // PRINTMANAGER_ADAPTER_FUZZ_TEST_H \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp index 59585748..80261dc0 100644 --- a/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp +++ b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -14,38 +14,84 @@ */ #include "resschedadapter_fuzz.h" -#include "res_sched_client_adapter.h" +#include #include +#include #include +#include +#include + +#include "res_sched_client_adapter.h" using namespace OHOS::NWeb; namespace OHOS { - bool ResSchedAdapterFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; +namespace NWeb { + +bool ResSchedAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + + pid_t pid = static_cast(data[0] % 1000); + pid_t tid = static_cast(data[1] % 1000); + int32_t nwebId = static_cast(data[2] % 10); + uint32_t windowId = static_cast(data[3] % 1000); + + std::vector statuses = { ResSchedStatusAdapter::WEB_ACTIVE, + ResSchedStatusAdapter::WEB_INACTIVE, ResSchedStatusAdapter::THREAD_CREATED, + ResSchedStatusAdapter::THREAD_DESTROYED, ResSchedStatusAdapter::VIDEO_PLAYING_START, + ResSchedStatusAdapter::VIDEO_PLAYING_STOP, ResSchedStatusAdapter::SCREEN_CAPTURE_START, + ResSchedStatusAdapter::SCREEN_CAPTURE_STOP, ResSchedStatusAdapter::AUDIO_STATUS_START, + ResSchedStatusAdapter::AUDIO_STATUS_STOP, ResSchedStatusAdapter::WEB_SCENE_ENTER, + ResSchedStatusAdapter::WEB_SCENE_EXIT }; + + std::vector roles = { ResSchedRoleAdapter::USER_INTERACT, ResSchedRoleAdapter::NORMAL_DISPLAY, + ResSchedRoleAdapter::IMPORTANT_DISPLAY, ResSchedRoleAdapter::NORMAL_AUDIO, ResSchedRoleAdapter::IMPORTANT_AUDIO, + ResSchedRoleAdapter::IMAGE_DECODE }; + + ResSchedClientAdapter adapter; + + for (auto status : statuses) { + adapter.ReportVideoPlaying(status, pid); + adapter.ReportScreenCapture(status, pid); + adapter.ReportRenderProcessStatus(status, pid); + adapter.ReportNWebInit(status, nwebId); + adapter.ReportWindowId(windowId, nwebId); + + for (auto role : roles) { + adapter.ReportKeyThread(status, pid, tid, role); } - int32_t windowId = 0; - int32_t nwebId = 0; - pid_t pid = 0; - ResSchedClientAdapter resSchedClientAdapter; - resSchedClientAdapter.ReportVideoPlaying(ResSchedStatusAdapter::WEB_ACTIVE, pid); - resSchedClientAdapter.ReportScreenCapture(ResSchedStatusAdapter::WEB_ACTIVE, pid); - resSchedClientAdapter.ReportRenderProcessStatus(ResSchedStatusAdapter::WEB_ACTIVE, pid); - resSchedClientAdapter.ReportNWebInit(ResSchedStatusAdapter::WEB_ACTIVE, nwebId); - resSchedClientAdapter.ReportWindowId(windowId, nwebId); - resSchedClientAdapter.ReportScene( - ResSchedStatusAdapter::WEB_ACTIVE, ResSchedSceneAdapter::KEYBOARD_CLICK, nwebId); - return true; + + adapter.ReportAudioData(status, pid, tid); + adapter.ReportProcessInUse(pid); + adapter.ReportSiteIsolationMode(true); + adapter.ReportWindowStatus(status, pid, windowId, nwebId); + adapter.ReportScene(status, ResSchedSceneAdapter::CLICK, nwebId); + adapter.ReportScene(status, ResSchedSceneAdapter::LOAD_URL, nwebId); } + + adapter.ReportProcessInUse(0); + adapter.ReportWindowId(0, nwebId); + adapter.ReportKeyThread(statuses[0], pid, tid, static_cast(-1)); + adapter.ReportAudioData(statuses[0], pid, 0); + adapter.ReportSiteIsolationMode(true); + + adapter.ReportWindowId(0, nwebId); + adapter.ReportKeyThread(statuses[0], -1, tid, ResSchedRoleAdapter::USER_INTERACT); + adapter.ReportAudioData(statuses[0], pid, -1); + adapter.ReportWindowStatus(statuses[0], pid, windowId, -1); + adapter.ReportNWebInit(ResSchedStatusAdapter::WEB_SCENE_EXIT, -1); + + return true; } +} // namespace NWeb +} // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ - OHOS::ResSchedAdapterFuzzTest(data, size); + OHOS::NWeb::ResSchedAdapterFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.cpp b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.cpp index 48186758..9dcf956f 100644 --- a/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.cpp @@ -13,38 +13,39 @@ * limitations under the License. */ -#include "setandgetrunwebinitcallback_fuzzer.h" -#include "ohos_init_web_adapter_impl.h" +#include "setandgetrunwebinitcallback_fuzzer.h" -using namespace OHOS::NWeb; +#include "ohos_init_web_adapter_impl.h" -namespace OHOS::NWeb { - bool SetAndGetCallbackFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(WebRunInitedCallback*))) { - return false; - } +using namespace OHOS::NWeb; - // Assuming data is a pointer to a valid WebRunInitedCallback if not nullptr - WebRunInitedCallback* callback = reinterpret_cast(const_cast(data)); +namespace OHOS::NWeb { +bool SetAndGetCallbackFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(WebRunInitedCallback*))) { + return false; + } - // Create instance of OhosInitWebAdapterImpl - std::shared_ptr webAdapterImpl = std::make_shared(); + // Assuming data is a pointer to a valid WebRunInitedCallback if not nullptr + WebRunInitedCallback* callback = reinterpret_cast(const_cast(data)); - // Set and get the callback - webAdapterImpl->SetRunWebInitedCallback(callback); - webAdapterImpl->GetRunWebInitedCallback(); + // Create instance of OhosInitWebAdapterImpl + std::shared_ptr webAdapterImpl = std::make_shared(); - // Optionally if returnedCallback is callable, call its run method. + // Set and get the callback + webAdapterImpl->SetRunWebInitedCallback(callback); + webAdapterImpl->GetRunWebInitedCallback(); - return true; - } -} + // Optionally if returnedCallback is callable, call its run method. -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - // Run your code on data - OHOS::NWeb::SetAndGetCallbackFuzzTest(data, size); - return 0; + return true; +} +} // namespace OHOS::NWeb + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data + OHOS::NWeb::SetAndGetCallbackFuzzTest(data, size); + return 0; } \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.h b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.h index b0ee3eee..61fd030d 100644 --- a/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.h +++ b/test/fuzztest/ohos_adapter/setandgetrunwebinitedcallback_fuzzer/setandgetrunwebinitcallback_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef TEST_FUZZTEST_SETANDGETCALLBACK_FUZZER_H -#define TEST_FUZZTEST_SETANDGETCALLBACK_FUZZER_H +#ifndef TEST_FUZZTEST_SETANDGETCALLBACK_FUZZER_H +#define TEST_FUZZTEST_SETANDGETCALLBACK_FUZZER_H -#define FUZZ_PROJECT_NAME "setandgetcallback_fuzzer" +#define FUZZ_PROJECT_NAME "setandgetcallback_fuzzer" #endif /* TEST_FUZZTEST_SETANDGETCALLBACK_FUZZER_H */ \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.cpp b/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.cpp index f9439c30..bba362b5 100755 --- a/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.cpp @@ -16,25 +16,26 @@ #include "applysocperfconfigbyid_fuzzer.h" #include + #include "soc_perf_client_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool ApplySocPerfConfigByIdFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return false; - } - int32_t id; - if (memcpy_s(&id, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return false; - } - SocPerfClientAdapterImpl perfClientAdapterImpl; - perfClientAdapterImpl.ApplySocPerfConfigById(id); - return true; +bool ApplySocPerfConfigByIdFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return false; + } + int32_t id; + if (memcpy_s(&id, sizeof(int32_t), data, sizeof(int32_t)) != 0) { + return false; } + SocPerfClientAdapterImpl perfClientAdapterImpl; + perfClientAdapterImpl.ApplySocPerfConfigById(id); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.h b/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.h index 5d2c9b17..0f59a742 100755 --- a/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.h +++ b/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "applysocperfconfigbyid_fuzzer" #endif /* TEST_FUZZTEST_APPLYSOCPERFCONFIGBYID_FUZZER_H */ - diff --git a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/BUILD.gn index f3f1352d..c9667146 100644 --- a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# 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 @@ -15,15 +15,13 @@ import("//base/web/webview/web_aafwk.gni") import("//build/config/features.gni") import("//build/test.gni") -import("$webview_path/config.gni") ##############################fuzztest########################################## -ohos_fuzztest("SystemPropertiesAdapterImplFuzzTest") { +ohos_fuzztest("SystemPropertiesFuzzTest") { module_out_path = webview_fuzz_test_path fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/systemproperties_fuzzer" include_dirs = [ - "$webview_path/ohos_adapter/interfaces", "$webview_path/ohos_adapter/system_properties_adapter/include", "$webview_path/test/fuzztest", ] @@ -34,17 +32,15 @@ ohos_fuzztest("SystemPropertiesAdapterImplFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ "system_properties_adapter_impl_fuzzer.cpp" ] - deps = [ - "$webview_path/ohos_adapter:nweb_ohos_adapter", - "$webview_path/ohos_nweb:libnweb", - ] - - external_deps = [ "c_utils:utils" ] + deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter" ] - if (webview_soc_perf_enable) { - external_deps += [ "soc_perf:socperf_client" ] - defines = [ "NWEB_SOC_PERF" ] - } + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "image_framework:image_native", + "pasteboard:pasteboard_client", + ] } ############################################################################### @@ -53,7 +49,6 @@ group("fuzztest") { deps = [] deps += [ # deps file - ":SystemPropertiesAdapterImplFuzzTest", + ":SystemPropertiesFuzzTest", ] } -############################################################################### diff --git a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.cpp b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.cpp index d117c5a3..cd589fbc 100644 --- a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.cpp @@ -1,60 +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. - */ - -#include "system_properties_adapter_impl_fuzzer.h" -#include "system_properties_adapter_impl.h" - -#include -#include -#include - -namespace OHOS { - -bool SystemPropertiesAdapterFuzzTest(const uint8_t* data, size_t size) -{ - // 添加检查,确保数据非空且大小大于 0 - if ((data == nullptr) || (size == 0)) { - return false; - } - - // 通过指定长度来构造字符串 - std::string key(reinterpret_cast(data), std::min(size, static_cast(32))); // 限制 key 的长度 - std::string value(reinterpret_cast(data + std::min(size, static_cast(32))), std::max(size - 32, static_cast(0))); // 余下的作为 value - - // 测试 NWeb::SystemPropertiesAdapterImpl 中的方法 - bool boolResult = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetBoolParameter(key, false); - std::string productModel = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetDeviceInfoProductModel(); - std::string brand = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetDeviceInfoBrand(); - int32_t majorVersion = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetSoftwareMajorVersion(); - int32_t seniorVersion = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetSoftwareSeniorVersion(); - - // 确保不出现未使用变量的警告 - (void)boolResult; - (void)productModel; - (void)brand; - (void)majorVersion; - (void)seniorVersion; - - return true; -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* 运行你的代码在数据上 */ - return OHOS::SystemPropertiesAdapterFuzzTest(data, size) ? 0 : 1; -} +/* + * 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 "system_properties_adapter_impl_fuzzer.h" + +#include +#include +#include + +#include "system_properties_adapter_impl.h" + +namespace OHOS { + +bool SystemPropertiesAdapterFuzzTest(const uint8_t* data, size_t size) +{ + size_t keySize = std::min(size, static_cast(32)); + std::string key(reinterpret_cast(data), keySize); + + size_t valueSize = size > keySize ? size - keySize : 0; + std::string value(reinterpret_cast(data + keySize), valueSize); + + bool boolResult = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetBoolParameter(key, false); + std::string productModel = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetDeviceInfoProductModel(); + std::string brand = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetDeviceInfoBrand(); + int32_t majorVersion = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetSoftwareMajorVersion(); + int32_t seniorVersion = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetSoftwareSeniorVersion(); + + (void)boolResult; + (void)productModel; + (void)brand; + (void)majorVersion; + (void)seniorVersion; + + return true; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + return OHOS::SystemPropertiesAdapterFuzzTest(data, size) ? 0 : 1; +} } // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.h b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.h index 669974ed..7306a15b 100644 --- a/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.h +++ b/test/fuzztest/ohos_adapter/systemproperties_fuzzer/system_properties_adapter_impl_fuzzer.h @@ -1,21 +1,21 @@ -/* - * 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. - */ +/* + * 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 TEST_FUZZTEST_SYSTEM_PROPERTIES_ADAPTER_IMPL_FUZZER_H -#define TEST_FUZZTEST_SYSTEM_PROPERTIES_ADAPTER_IMPL_FUZZER_H +#ifndef TEST_FUZZTEST_SYSTEM_PROPERTIES_ADAPTER_IMPL_FUZZER_H +#define TEST_FUZZTEST_SYSTEM_PROPERTIES_ADAPTER_IMPL_FUZZER_H -#define FUZZ_PROJECT_NAME "system_properties_adapter_impl_fuzzer" +#define FUZZ_PROJECT_NAME "system_properties_adapter_impl_fuzzer" #endif /* TEST_FUZZTEST_SYSTEM_PROPERTIES_ADAPTER_IMPL_FUZZER_H */ \ No newline at end of file diff --git a/test/fuzztest/ohos_nweb/copyframe_fuzzer/copyframe_fuzzer.cpp b/test/fuzztest/ohos_nweb/copyframe_fuzzer/copyframe_fuzzer.cpp index d9ba3d19..7f2e146e 100644 --- a/test/fuzztest/ohos_nweb/copyframe_fuzzer/copyframe_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/copyframe_fuzzer/copyframe_fuzzer.cpp @@ -48,7 +48,7 @@ bool CopyFrameFuzzTest(const uint8_t* data, size_t size) if (width == 0 || height == 0) { return false; } - char *src = new char[BITS_PER_PIXEL] {0}; + char* src = new char[BITS_PER_PIXEL] { 0 }; if (src == nullptr) { return false; } @@ -56,7 +56,7 @@ bool CopyFrameFuzzTest(const uint8_t* data, size_t size) delete[] src; return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/copyframe_fuzzer/copyframe_fuzzer.h b/test/fuzztest/ohos_nweb/copyframe_fuzzer/copyframe_fuzzer.h index 0ca40a9f..a30c41a9 100644 --- a/test/fuzztest/ohos_nweb/copyframe_fuzzer/copyframe_fuzzer.h +++ b/test/fuzztest/ohos_nweb/copyframe_fuzzer/copyframe_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "copyframe_fuzzer" #endif /* TEST_FUZZTEST_COPYFRAME_FUZZER_H */ - diff --git a/test/fuzztest/ohos_nweb/flushbuffer_fuzzer/flushbuffer_fuzzer.cpp b/test/fuzztest/ohos_nweb/flushbuffer_fuzzer/flushbuffer_fuzzer.cpp index 36967be5..2dda4a8c 100644 --- a/test/fuzztest/ohos_nweb/flushbuffer_fuzzer/flushbuffer_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/flushbuffer_fuzzer/flushbuffer_fuzzer.cpp @@ -56,15 +56,15 @@ bool FlushBufferFuzzTest(const uint8_t* data, size_t size) return false; } g_surface = surfaceNode->GetSurface(); - if (g_surface== nullptr) { + if (g_surface == nullptr) { return false; } } - std::string result(reinterpret_cast(data), size); + std::string result(reinterpret_cast(data), size); surfaceAdapter.FlushBuffer(g_surface, surfaceBuffer, width, height); return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/flushbuffer_fuzzer/flushbuffer_fuzzer.h b/test/fuzztest/ohos_nweb/flushbuffer_fuzzer/flushbuffer_fuzzer.h index 8f6c48e0..47089a3a 100644 --- a/test/fuzztest/ohos_nweb/flushbuffer_fuzzer/flushbuffer_fuzzer.h +++ b/test/fuzztest/ohos_nweb/flushbuffer_fuzzer/flushbuffer_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "flushbuffer_fuzzer" #endif /* TEST_FUZZTEST_FLUSHBUFFER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_nweb/getcookiemanager_fuzzer/getcookiemanager_fuzzer.cpp b/test/fuzztest/ohos_nweb/getcookiemanager_fuzzer/getcookiemanager_fuzzer.cpp index c7ca6734..fd5acd38 100644 --- a/test/fuzztest/ohos_nweb/getcookiemanager_fuzzer/getcookiemanager_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/getcookiemanager_fuzzer/getcookiemanager_fuzzer.cpp @@ -31,7 +31,7 @@ bool GetCookieManagerFuzzTest(const uint8_t* data, size_t size) NWebHelper::Instance().GetCookieManager(); return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/getcookiemanager_fuzzer/getcookiemanager_fuzzer.h b/test/fuzztest/ohos_nweb/getcookiemanager_fuzzer/getcookiemanager_fuzzer.h index e2b77517..8a6a134b 100644 --- a/test/fuzztest/ohos_nweb/getcookiemanager_fuzzer/getcookiemanager_fuzzer.h +++ b/test/fuzztest/ohos_nweb/getcookiemanager_fuzzer/getcookiemanager_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "getcookiemanager_fuzzer" #endif /* TEST_FUZZTEST_GETCOOKIEMANAGER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_nweb/getdatabase_fuzzer/getdatabase_fuzzer.cpp b/test/fuzztest/ohos_nweb/getdatabase_fuzzer/getdatabase_fuzzer.cpp index 55b58c06..bcf2271e 100644 --- a/test/fuzztest/ohos_nweb/getdatabase_fuzzer/getdatabase_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/getdatabase_fuzzer/getdatabase_fuzzer.cpp @@ -31,7 +31,7 @@ bool GetDataBaseFuzzTest(const uint8_t* data, size_t size) NWebHelper::Instance().GetDataBase(); return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/getdatabase_fuzzer/getdatabase_fuzzer.h b/test/fuzztest/ohos_nweb/getdatabase_fuzzer/getdatabase_fuzzer.h index b15ab060..7b74961f 100644 --- a/test/fuzztest/ohos_nweb/getdatabase_fuzzer/getdatabase_fuzzer.h +++ b/test/fuzztest/ohos_nweb/getdatabase_fuzzer/getdatabase_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "getdatabase_fuzzer" #endif /* TEST_FUZZTEST_GETDATABASE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.cpp b/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.cpp index f29cf027..ce44dfc0 100644 --- a/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.cpp @@ -25,17 +25,18 @@ using namespace OHOS::NWeb; namespace OHOS { bool GetNwebFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return false; - } int32_t nweb_id; if (memcpy_s(&nweb_id, sizeof(int32_t), data, sizeof(int32_t)) != 0) { return false; } NWebHelper::Instance().GetNWeb(nweb_id); + + NWebHelper::Instance().SetWebTag(nweb_id, "NWeb"); + + NWebHelper::Instance().PrepareForPageLoad("", true, size); return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.h b/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.h index d33eb201..747f4bf3 100644 --- a/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.h +++ b/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "getnweb_fuzzer" #endif /* TEST_FUZZTEST_GETNWEB_FUZZER_H */ - diff --git a/test/fuzztest/ohos_nweb/getwebstorage_fuzzer/getwebstorage_fuzzer.cpp b/test/fuzztest/ohos_nweb/getwebstorage_fuzzer/getwebstorage_fuzzer.cpp index 27ac46ee..20760370 100644 --- a/test/fuzztest/ohos_nweb/getwebstorage_fuzzer/getwebstorage_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/getwebstorage_fuzzer/getwebstorage_fuzzer.cpp @@ -31,7 +31,7 @@ bool GetWebStorageFuzzTest(const uint8_t* data, size_t size) NWebHelper::Instance().GetWebStorage(); return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/getwebstorage_fuzzer/getwebstorage_fuzzer.h b/test/fuzztest/ohos_nweb/getwebstorage_fuzzer/getwebstorage_fuzzer.h index ce587461..8112f36d 100644 --- a/test/fuzztest/ohos_nweb/getwebstorage_fuzzer/getwebstorage_fuzzer.h +++ b/test/fuzztest/ohos_nweb/getwebstorage_fuzzer/getwebstorage_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "getwebstorage_fuzzer" #endif /* TEST_FUZZTEST_GETWEBSTORAGE_FUZZER_H */ - diff --git a/test/fuzztest/ohos_nweb/hisysevent_fuzzer/BUILD.gn b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/BUILD.gn new file mode 100644 index 00000000..2c9a428a --- /dev/null +++ b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("HiSysEventFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_nweb/hisysevent_fuzzer" + + include_dirs = [ + "$webview_path/test/ohos_nweb", + "$window_manager_path/interfaces/innerkits/wm", + "$webview_path/test/fuzztest", + "$webview_path/ohos_nweb/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hisysevent_fuzzer.cpp" ] + deps = [ "$graphic2d_path/rosen/modules/render_service_client:librender_service_client" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "webview:libnweb", + "window_manager:libwm", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":HiSysEventFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_nweb/hisysevent_fuzzer/corpus/init b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_nweb/hisysevent_fuzzer/hisysevent_fuzzer.cpp b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/hisysevent_fuzzer.cpp new file mode 100644 index 00000000..c23cde73 --- /dev/null +++ b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/hisysevent_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * 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 "hisysevent_fuzzer.h" + +#include +#include + +#include "nweb_hisysevent.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool HiSysEventFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return false; + } + int32_t nwebId; + if (memcpy_s(&nwebId, sizeof(int32_t), data, sizeof(int32_t)) != EOK) { + return false; + } + EventReport::ReportCreateWebInstanceTime(nwebId, nwebId); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::HiSysEventFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_nweb/hisysevent_fuzzer/hisysevent_fuzzer.h b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/hisysevent_fuzzer.h new file mode 100644 index 00000000..58a3b2a8 --- /dev/null +++ b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/hisysevent_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_HISYSEVENT_FUZZER_H +#define TEST_FUZZTEST_HISYSEVENT_FUZZER_H + +#define FUZZ_PROJECT_NAME "hisysevent_fuzzer" +#endif /* TEST_FUZZTEST_HISYSEVENT_FUZZER_H */ diff --git a/test/fuzztest/ohos_nweb/hisysevent_fuzzer/project.xml b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_nweb/hisysevent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_nweb/initandrun_fuzzer/BUILD.gn b/test/fuzztest/ohos_nweb/initandrun_fuzzer/BUILD.gn new file mode 100644 index 00000000..3ae88826 --- /dev/null +++ b/test/fuzztest/ohos_nweb/initandrun_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("InitAndRunFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_nweb/initandrun_fuzzer" + + include_dirs = [ + "$webview_path/test/ohos_nweb", + "$window_manager_path/interfaces/innerkits/wm", + "$webview_path/test/fuzztest", + "$webview_path/ohos_nweb/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "initandrun_fuzzer.cpp" ] + deps = [ "$graphic2d_path/rosen/modules/render_service_client:librender_service_client" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "webview:libnweb", + "window_manager:libwm", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":InitAndRunFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_nweb/initandrun_fuzzer/corpus/init b/test/fuzztest/ohos_nweb/initandrun_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_nweb/initandrun_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_nweb/initandrun_fuzzer/initandrun_fuzzer.cpp b/test/fuzztest/ohos_nweb/initandrun_fuzzer/initandrun_fuzzer.cpp new file mode 100644 index 00000000..cc6fdf41 --- /dev/null +++ b/test/fuzztest/ohos_nweb/initandrun_fuzzer/initandrun_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "initandrun_fuzzer.h" + +#include +#include + +#include "nweb_helper.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool InitAndRunFuzzTest(const uint8_t* data, size_t size) +{ + const std::string path("/data/app/el1/bundle/public/com.ohos.nweb"); + NWebHelper::Instance().SetBundlePath(path); + + NWebHelper::Instance().InitAndRun(false); + + if (data == nullptr) { + return false; + } + std::string pathTmp(reinterpret_cast(data), size); + NWebHelper::Instance().SetBundlePath(pathTmp); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::InitAndRunFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_nweb/initandrun_fuzzer/initandrun_fuzzer.h b/test/fuzztest/ohos_nweb/initandrun_fuzzer/initandrun_fuzzer.h new file mode 100644 index 00000000..0704b3f4 --- /dev/null +++ b/test/fuzztest/ohos_nweb/initandrun_fuzzer/initandrun_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_INIT_AND_RUN_FUZZER_H +#define TEST_FUZZTEST_INIT_AND_RUN_FUZZER_H + +#define FUZZ_PROJECT_NAME "initandrun_fuzzer" +#endif /* TEST_FUZZTEST_INIT_AND_RUN_FUZZER_H */ diff --git a/test/fuzztest/ohos_nweb/initandrun_fuzzer/project.xml b/test/fuzztest/ohos_nweb/initandrun_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_nweb/initandrun_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_nweb/loadlib_fuzzer/loadlib_fuzzer.cpp b/test/fuzztest/ohos_nweb/loadlib_fuzzer/loadlib_fuzzer.cpp index 86515d92..ddda1227 100644 --- a/test/fuzztest/ohos_nweb/loadlib_fuzzer/loadlib_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/loadlib_fuzzer/loadlib_fuzzer.cpp @@ -29,10 +29,17 @@ bool LoadLibFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size == 0)) { return false; } + + const std::string path("/data/app/el1/bundle/public/com.ohos.nweb"); + NWebHelper::Instance().SetBundlePath(path); + NWebAdapterHelper::Instance().Init(true); + + NWebAdapterHelper::Instance().Init(false); + return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/loadlib_fuzzer/loadlib_fuzzer.h b/test/fuzztest/ohos_nweb/loadlib_fuzzer/loadlib_fuzzer.h index ea926e43..cff41d94 100644 --- a/test/fuzztest/ohos_nweb/loadlib_fuzzer/loadlib_fuzzer.h +++ b/test/fuzztest/ohos_nweb/loadlib_fuzzer/loadlib_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "loadlib_fuzzer" #endif /* TEST_FUZZTEST_LOADLIB_FUZZER_H */ - diff --git a/test/fuzztest/ohos_nweb/napi_fuzzer/BUILD.gn b/test/fuzztest/ohos_nweb/napi_fuzzer/BUILD.gn new file mode 100644 index 00000000..36f778a4 --- /dev/null +++ b/test/fuzztest/ohos_nweb/napi_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("NapiFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_nweb/napi_fuzzer" + + include_dirs = [ + "$webview_path/test/ohos_nweb", + "$window_manager_path/interfaces/innerkits/wm", + "$webview_path/test/fuzztest", + "$webview_path/ohos_nweb/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "napi_fuzzer.cpp" ] + deps = [ "$graphic2d_path/rosen/modules/render_service_client:librender_service_client" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "webview:libnweb", + "window_manager:libwm", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":NapiFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_nweb/napi_fuzzer/corpus/init b/test/fuzztest/ohos_nweb/napi_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_nweb/napi_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_nweb/napi_fuzzer/napi_fuzzer.cpp b/test/fuzztest/ohos_nweb/napi_fuzzer/napi_fuzzer.cpp new file mode 100644 index 00000000..71319b9c --- /dev/null +++ b/test/fuzztest/ohos_nweb/napi_fuzzer/napi_fuzzer.cpp @@ -0,0 +1,98 @@ +/* + * 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_fuzzer.h" + +#include +#include + +#include "nweb_c_api.h" +#include "nweb_helper.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +bool NapiFuzzTest(const uint8_t* data, size_t size) +{ + const std::string path("/data/app/el1/bundle/public/com.ohos.nweb"); + NWebHelper::Instance().SetBundlePath(path); + + NWebHelper::Instance().Init(false); + + if (NWebHelper::Instance().LoadNWebSDK()) { + WebDownloadManager_PutDownloadCallback(nullptr); + WebDownloader_SetDownloadBeforeStart(nullptr, nullptr); + WebDownloader_SetDownloadDidUpdate(nullptr, nullptr); + WebDownloader_ResumeDownloadStatic(nullptr); + WebDownloader_StartDownload(size, NULL); + WebDownloader_CreateDownloadDelegateCallback(nullptr); + WebDownload_Continue(nullptr, nullptr); + WebDownload_CancelBeforeDownload(nullptr); + WebDownload_PauseBeforeDownload(nullptr); + WebDownload_ResumeBeforeDownload(nullptr); + WebDownload_Cancel(nullptr); + WebDownload_Pause(nullptr); + WebDownload_Resume(nullptr); + + WebDownload_GetItemState(size, size); + if (data != nullptr && size != 0) { + std::string dataTmp(reinterpret_cast(data), size); + WebDownload_GetItemStateByGuid(dataTmp); + } + WebDownloadItem_Guid(nullptr); + WebDownloadItem_GetDownloadItemId(nullptr); + WebDownloadItem_GetState(nullptr); + WebDownloadItem_CurrentSpeed(nullptr); + WebDownloadItem_PercentComplete(nullptr); + WebDownloadItem_TotalBytes(nullptr); + WebDownloadItem_ReceivedBytes(nullptr); + WebDownloadItem_FullPath(nullptr); + WebDownloadItem_Url(nullptr); + WebDownloadItem_OriginalUrl(nullptr); + WebDownloadItem_SuggestedFileName(nullptr); + WebDownloadItem_ContentDisposition(nullptr); + WebDownloadItem_ETag(nullptr); + WebDownloadItem_MimeType(nullptr); + WebDownloadItem_IsPaused(nullptr); + WebDownloadItem_Method(nullptr); + WebDownloadItem_LastErrorCode(nullptr); + WebDownloadItem_ReceivedSlices(nullptr); + WebDownloadItem_LastModified(nullptr); + WebDownloadItem_NWebId(nullptr); + WebDownloadItem_CreateWebDownloadItem(nullptr); + WebDownloadItem_Destroy(nullptr); + DestroyBeforeDownloadCallbackWrapper(nullptr); + DestroyDownloadItemCallbackWrapper(nullptr); + WebDownloadItem_SetGuid(nullptr, nullptr); + WebDownloadItem_SetUrl(nullptr, nullptr); + WebDownloadItem_SetFullPath(nullptr, nullptr); + WebDownloadItem_SetETag(nullptr, nullptr); + WebDownloadItem_SetLastModified(nullptr, nullptr); + WebDownloadItem_SetMimeType(nullptr, nullptr); + WebDownloadItem_SetReceivedBytes(nullptr, size); + WebDownloadItem_SetTotalBytes(nullptr, size); + WebDownloadItem_SetReceivedSlices(nullptr, nullptr); + } + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::NapiFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_nweb/napi_fuzzer/napi_fuzzer.h b/test/fuzztest/ohos_nweb/napi_fuzzer/napi_fuzzer.h new file mode 100644 index 00000000..bfb1090e --- /dev/null +++ b/test/fuzztest/ohos_nweb/napi_fuzzer/napi_fuzzer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 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 TEST_FUZZTEST_NAPI_FUZZER_H +#define TEST_FUZZTEST_NAPI_FUZZER_H + +#define FUZZ_PROJECT_NAME "napi_fuzzer" +#endif /* TEST_FUZZTEST_GETNWEB_FUZZER_H */ diff --git a/test/fuzztest/ohos_nweb/napi_fuzzer/project.xml b/test/fuzztest/ohos_nweb/napi_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_nweb/napi_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/BUILD.gn b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/BUILD.gn new file mode 100644 index 00000000..19708d95 --- /dev/null +++ b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/BUILD.gn @@ -0,0 +1,71 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/web/webview/web_aafwk.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("NWebHelperFuzzTest") { + module_out_path = webview_fuzz_test_path + fuzz_config_file = "$webview_path/test/fuzztest/ohos_nweb/nwebhelper_fuzzer" + + include_dirs = [ + "$webview_path/test/ohos_nweb", + "$window_manager_path/interfaces/innerkits/wm", + "$webview_path/test/fuzztest", + "$webview_path/ohos_nweb/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "nweb_create_window.cpp", + "nwebhelper_fuzzer.cpp", + ] + + deps = [ + "$graphic2d_path/rosen/modules/render_service_client:librender_service_client", + "$webview_path/ohos_nweb:web_configs", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_runtime:app_context", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "webview:libnweb", + "window_manager:libwm", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":NWebHelperFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/corpus/init b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/corpus/init new file mode 100644 index 00000000..e03503f8 --- /dev/null +++ b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/corpus/init @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 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. + */ +FUZZ diff --git a/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nweb_create_window.cpp b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nweb_create_window.cpp new file mode 100644 index 00000000..3796ba62 --- /dev/null +++ b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nweb_create_window.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2022 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 "nweb_create_window.h" + +#include +#include +#include +#include + +#include "nweb_adapter_helper.h" + +using namespace OHOS; +namespace OHOS::NWeb { +namespace { +const std::string ARG_URL = "--url"; +const std::string ARG_DUMP = "--dump-path"; +const std::string ARG_FRAME_INFO = "--frame-info"; +const std::string ARG_ADD_WEB_ENGINE_ARG = "--add-args"; +const std::string ARG_DELETE_WEB_ENGINE_ARG = "--delete-args"; +const std::string ARG_MULTI_RENDER_PROCESS = "--multi-renderer-process"; +const std::string ARG_NWEB_TEST_MOCK_BUNDLEPATH = "--bundle-installation-dir"; +const std::string MOCK_INSTALLATION_DIR = "/data/app/el1/bundle/public/com.ohos.nweb"; +const std::string ARG_WIDTH = "--width"; +const std::string ARG_HEIGHT = "--height"; +std::unordered_map g_argsMap; +sptr g_surface = nullptr; +} // namespace + +static bool HasArg(const std::string& arg) +{ + return (!g_argsMap.empty()) && (g_argsMap.find(arg) != g_argsMap.end()); +} + +static std::string GetArgValue(const std::string& arg) +{ + if (!HasArg(arg)) { + return ""; + } + return g_argsMap.at(arg); +} + +static std::list GetWebEngineArgs(const std::string& arg) +{ + std::string webEngineArgValue = GetArgValue(arg); + std::list webEngineArgList; + if (webEngineArgValue.empty()) { + return webEngineArgList; + } + uint32_t start = 0; + uint32_t pos = 0; + while (pos < webEngineArgValue.size()) { + if (webEngineArgValue[pos] == ',') { + webEngineArgList.emplace_back(webEngineArgValue.substr(start, pos - start)); + pos++; + start = pos; + } else { + pos++; + } + } + webEngineArgList.emplace_back(webEngineArgValue.substr(start, pos - start)); + webEngineArgList.emplace_back(ARG_NWEB_TEST_MOCK_BUNDLEPATH + "=" + MOCK_INSTALLATION_DIR); + return webEngineArgList; +} + +std::shared_ptr GetInitArgs(void) +{ + std::shared_ptr initArgs = std::make_shared(); + initArgs->SetDumpPath(GetArgValue(ARG_DUMP)); + initArgs->SetIsFrameInfoDump(HasArg(ARG_FRAME_INFO) ? true : false); + initArgs->SetIsMultiRendererProcess(HasArg(ARG_MULTI_RENDER_PROCESS) ? true : false); + initArgs->SetArgsToAdd(GetWebEngineArgs(ARG_ADD_WEB_ENGINE_ARG)); + initArgs->SetArgsToDelete(GetWebEngineArgs(ARG_DELETE_WEB_ENGINE_ARG)); + return initArgs; +} + +std::shared_ptr GetNwebForTest() +{ + if (!g_surface) { + Rosen::RSSurfaceNodeConfig config; + config.SurfaceNodeName = "webTestSurfaceName"; + auto surfaceNode = Rosen::RSSurfaceNode::Create(config, false); + if (surfaceNode == nullptr) { + return nullptr; + } + g_surface = surfaceNode->GetSurface(); + if (g_surface == nullptr) { + return nullptr; + } + } + return NWebAdapterHelper::Instance().CreateNWeb(g_surface, GetInitArgs()); +} +} // namespace OHOS::NWeb diff --git a/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nweb_create_window.h b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nweb_create_window.h new file mode 100644 index 00000000..d60d60d0 --- /dev/null +++ b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nweb_create_window.h @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2022 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_CREAT_WINDOW_H +#define NWEB_CREAT_WINDOW_H + +#include "nweb.h" +#include "nweb_init_params.h" + +#define private public +#include "ui/rs_surface_node.h" +#undef private + +namespace OHOS::NWeb { +std::shared_ptr GetInitArgs(void); +std::shared_ptr GetNwebForTest(); + +class NWebMock : public NWeb { +public: + void Resize(uint32_t width, uint32_t height, bool isKeyboard = false) override {} + void OnPause() override {} + void OnContinue() override {} + void OnDestroy() override {} + void OnFocus(const FocusReason& focusReason = FocusReason::FOCUS_DEFAULT) override {} + void OnBlur(const BlurReason& blurReason) override {} + void OnTouchPress(int32_t id, double x, double y, bool fromOverlay = false) override {} + void OnTouchRelease(int32_t id, double x = 0, double y = 0, bool fromOverlay = false) override {} + void OnTouchMove(int32_t id, double x, double y, bool fromOverlay = false) override {} + void OnTouchMove( + const std::vector>& touch_point_infos, bool fromOverlay = false) override + {} + void OnTouchCancel() override {} + void OnNavigateBack() override {} + bool SendKeyEvent(int32_t keyCode, int32_t keyAction) override + { + return true; + } + void SendMouseWheelEvent(double x, double y, double deltaX, double deltaY) override {} + void SendMouseEvent(int x, int y, int button, int action, int count) override {} + int Load(const std::string& url) override + { + return 0; + } + bool IsNavigatebackwardAllowed() override + { + return true; + } + bool IsNavigateForwardAllowed() override + { + return true; + } + bool CanNavigateBackOrForward(int numSteps) override + { + return true; + } + void NavigateBack() override {} + void NavigateForward() override {} + void NavigateBackOrForward(int step) override {} + void DeleteNavigateHistory() override {} + void Reload() override {} + int Zoom(float zoomFactor) override + { + return 0; + } + int ZoomIn() override + { + return 0; + } + int ZoomOut() override + { + return 0; + } + void Stop() override {} + void ExecuteJavaScript(const std::string& code) override {} + void ExecuteJavaScript( + const std::string& code, std::shared_ptr callback, bool extention) override + {} + std::shared_ptr GetPreference() override + { + return nullptr; + } + unsigned int GetWebId() override + { + return 0; + } + std::shared_ptr GetHitTestResult() override + { + std::shared_ptr test; + return test; + } + void PutBackgroundColor(int color) override {} + void InitialScale(float scale) override {} + void PutDownloadCallback(std::shared_ptr downloadListener) override {} + void PutReleaseSurfaceCallback(std::shared_ptr releaseSurfaceListener) override {} + void SetNWebHandler(std::shared_ptr handler) override {} + std::string Title() override + { + return nullptr; + } + int PageLoadProgress() override + { + return 0; + } + int ContentHeight() override + { + return 0; + } + float Scale() override + { + return 0; + } + int Load(const std::string& url, const std::map& additionalHttpHeaders) override + { + return 0; + } + int LoadWithDataAndBaseUrl(const std::string& baseUrl, const std::string& data, const std::string& mimeType, + const std::string& encoding, const std::string& historyUrl) override + { + return 0; + } + int LoadWithData(const std::string& data, const std::string& mimeType, const std::string& encoding) override + { + return 0; + } + void RegisterArkJSfunction( + const std::string& object_name, const std::vector& method_list, const int32_t object_id) override + {} + void UnregisterArkJSfunction(const std::string& object_name, const std::vector& method_list) override + {} + void SetNWebJavaScriptResultCallBack(std::shared_ptr callback) override {} + void PutFindCallback(std::shared_ptr findListener) override {} + void FindAllAsync(const std::string& searchStr) override {} + void ClearMatches() override {} + void FindNext(const bool forward) override {} + void StoreWebArchive( + const std::string& baseName, bool autoName, std::shared_ptr callback) override + {} + std::vector CreateWebMessagePorts() override + { + std::vector empty; + return empty; + } + void PostWebMessage( + const std::string& message, const std::vector& ports, const std::string& targetUri) override + {} + void ClosePort(const std::string& handle) override {} + void PostPortMessage(const std::string& handle, std::shared_ptr data) override {} + void SetPortMessageCallback(const std::string& handle, std::shared_ptr callback) override + {} + void SendDragEvent(std::shared_ptr dragEvent) override {} + void ClearSslCache() override {} + std::string GetUrl() override + { + return "/data"; + } + void ClearClientAuthenticationCache() override {} + void UpdateLocale(const std::string& language, const std::string& region) override {} + + const std::string GetOriginalUrl() override + { + return ""; + } + bool GetFavicon( + const void** data, size_t& width, size_t& height, ImageColorType& colorType, ImageAlphaType& alphaType) override + { + return false; + } + void PutNetworkAvailable(bool available) override {} + + void HasImages(std::shared_ptr callback) override {} + + void RemoveCache(bool include_disk_files) override {} + std::shared_ptr GetHistoryList() override + { + return nullptr; + } + std::vector SerializeWebState() override + { + std::vector empty; + return empty; + } + bool RestoreWebState(const std::vector& state) override + { + return false; + } + void PageUp(bool top) override {} + void PageDown(bool bottom) override {} + void ScrollTo(float x, float y) override {} + void ScrollBy(float deltaX, float deltaY) override {} + void SlideScroll(float vx, float vy) override {} + bool GetCertChainDerData(std::vector& certChainData, bool isSingleCert) override + { + return false; + } + void SetScreenOffSet(double x, double y) override {} + void SetAudioMuted(bool muted) override {} + void SetShouldFrameSubmissionBeforeDraw(bool should) override {} + void NotifyPopupWindowResult(bool result) override {} + void SetAudioResumeInterval(int32_t resumeInterval) override {} + void SetAudioExclusive(bool audioExclusive) override {} + void RegisterScreenLockFunction(int32_t windowId, std::shared_ptr callback) override {} + void UnRegisterScreenLockFunction(int32_t windowId) override {} + std::shared_ptr GetOrCreateDragData() override + { + return nullptr; + } + void SendTouchpadFlingEvent(double x, double y, double vx, double vy) override {} + int SetUrlTrustList(const std::string& urlTrustList) override + { + return 0; + } + int SetUrlTrustListWithErrMsg(const std::string& urlTrustList, std::string& detailErrMsg) override + { + return 0; + } +}; +} // namespace OHOS::NWeb +#endif diff --git a/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nwebhelper_fuzzer.cpp b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nwebhelper_fuzzer.cpp new file mode 100644 index 00000000..c5e22ae9 --- /dev/null +++ b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nwebhelper_fuzzer.cpp @@ -0,0 +1,261 @@ +/* + * 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 +#include + +#define private public +#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/application_context.h" +#include "nweb.h" +#include "nweb_adapter_helper.h" +#include "nweb_c_api.h" +#include "nweb_create_window.h" +#include "nweb_helper.h" +#include "nweb_init_params.h" +#include "nweb_log.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Rosen; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace { +sptr g_surface = nullptr; +const int DEFAULT_WIDTH = 2560; +const int DEFAULT_HEIGHT = 1396; +const int32_t NWEB_MAX_WIDTH = 7681; +const std::string MOCK_INSTALLATION_DIR = "/data/app/el1/bundle/public/com.ohos.nweb"; +std::shared_ptr g_applicationContext = nullptr; +} // namespace + +namespace AbilityRuntime { +std::shared_ptr Context::GetApplicationContext() +{ + return g_applicationContext; +} +} // namespace AbilityRuntime + +namespace NWeb { + +class NwebHelperTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +class ApplicationContextMock : public ApplicationContext { +public: + MOCK_CONST_METHOD0(GetBaseDir, std::string()); +}; + +class MockNWebEngine : public OHOS::NWeb::NWebEngine { +public: + std::shared_ptr CreateNWeb(std::shared_ptr create_info) + { + return nullptr; + } + + std::shared_ptr GetNWeb(int32_t nweb_id) + { + return nullptr; + } + + std::shared_ptr GetDataBase() + { + return nullptr; + } + + std::shared_ptr GetWebStorage() + { + return nullptr; + } + + std::shared_ptr GetCookieManager() + { + return nullptr; + } + + std::shared_ptr GetDownloadManager() + { + return nullptr; + } + + void SetWebTag(int32_t nweb_id, const char* web_tag) {} + + void InitializeWebEngine(std::shared_ptr init_args) {} + + void PrepareForPageLoad(const std::string& url, bool preconnectable, int32_t num_sockets) {} + + void SetWebDebuggingAccess(bool isEnableDebug) {} + + void AddIntelligentTrackingPreventionBypassingList(const std::vector& hosts) {} + + void RemoveIntelligentTrackingPreventionBypassingList(const std::vector& hosts) {} + void ClearIntelligentTrackingPreventionBypassingList() {} + + void PauseAllTimers() {} + + void ResumeAllTimers() {} + + void PrefetchResource(const std::shared_ptr& pre_args, + const std::map& additional_http_headers, const std::string& cache_key, + const uint32_t& cache_valid_time) + {} + + void SetRenderProcessMode(RenderProcessMode mode) {} + + RenderProcessMode GetRenderProcessMode() + { + return RenderProcessMode::SINGLE_MODE; + } + + void ClearPrefetchedResource(const std::vector& cache_key_list) {} + + void WarmupServiceWorker(const std::string& url) {} + + void SetHostIP(const std::string& hostName, const std::string& address, int32_t aliveTime) {} + + void ClearHostIP(const std::string& hostName) {} + + std::shared_ptr GetAdsBlockManager() + { + return nullptr; + } + + void EnableBackForwardCache(bool nativeEmbed, bool mediaTakeOver) {} +}; + +void NwebHelperTest::SetUpTestCase(void) +{ + RSSurfaceNodeConfig config; + config.SurfaceNodeName = "webTestSurfaceName"; + auto surfaceNode = RSSurfaceNode::Create(config, false); + g_surface = surfaceNode->GetSurface(); +} + +void NwebHelperTest::TearDownTestCase(void) {} + +void NwebHelperTest::SetUp(void) {} + +void NwebHelperTest::TearDown(void) {} + +std::unordered_map g_argsMap; + +bool NWebHelperFuzzTest(const uint8_t* data, size_t size) +{ + int32_t nweb_id = 1; + bool result = NWebHelper::Instance().LoadNWebSDK(); + (void)result; + NWebHelper::Instance().SetBundlePath(MOCK_INSTALLATION_DIR); + result = NWebAdapterHelper::Instance().Init(false); + (void)result; + std::shared_ptr create_info = std::make_shared(); + std::shared_ptr nweb = NWebHelper::Instance().CreateNWeb(create_info); + (void)nweb; + std::shared_ptr config = std::make_shared(); + NWebHelper::Instance().SetHttpDns(config); + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + (void)nwebHelper; + NWebHelper::Instance().PrepareForPageLoad("web_test", true, 0); + NWebHelper::Instance().WarmupServiceWorker("web_test"); + NWebHelper::Instance().PrefetchResource(nullptr, {}, "web_test", 0); + NWebHelper::Instance().ClearPrefetchedResource({ "web_test" }); + NWebAdapterHelper::Instance().ReadConfigIfNeeded(); + result = NWebHelper::Instance().InitAndRun(false); + (void)result; + ApplicationContextMock* contextMock = new ApplicationContextMock(); + g_applicationContext.reset(contextMock); + result = NWebHelper::Instance().InitAndRun(false); + (void)result; + NWebAdapterHelper::Instance().CreateNWeb(g_surface, GetInitArgs(), DEFAULT_WIDTH, DEFAULT_HEIGHT); + result = NWebHelper::Instance().InitAndRun(false); + (void)result; + NWebAdapterHelper::Instance().CreateNWeb(g_surface, GetInitArgs(), DEFAULT_WIDTH, DEFAULT_HEIGHT); + result = NWebHelper::Instance().LoadNWebSDK(); + (void)result; + result = NWebHelper::Instance().LoadNWebSDK(); + (void)result; + WebDownloadManager_PutDownloadCallback(nullptr); + g_applicationContext.reset(); + return true; +} + +bool NWebHelperFuzzTest_002(const uint8_t* data, size_t size) +{ + auto web_storage = NWebHelper::Instance().GetWebStorage(); + bool result = false; + if (web_storage != nullptr) { + result = true; + } + (void)result; + std::string config = NWebAdapterHelper::Instance().ParsePerfConfig("web", "test"); + (void)config; + NWebConfigHelper::Instance().perfConfig_.emplace("web/test", "web_test"); + config = NWebAdapterHelper::Instance().ParsePerfConfig("web", "test"); + (void)config; + return true; +} + +bool NWebHelperFuzzTest_003(const uint8_t* data, size_t size) +{ + auto dataBase = NWebHelper::Instance().GetDataBase(); + bool result = false; + if (dataBase != nullptr) { + result = true; + } + (void)result; + + NWebHelper::Instance().libHandleWebEngine_ = nullptr; + std::shared_ptr cook = NWebHelper::Instance().GetCookieManager(); + (void)cook; + + void* enhanceSurfaceInfo = nullptr; + int32_t temp = 1; + std::shared_ptr nweb = + NWebAdapterHelper::Instance().CreateNWeb(enhanceSurfaceInfo, GetInitArgs(), DEFAULT_WIDTH, DEFAULT_HEIGHT); + (void)nweb; + enhanceSurfaceInfo = static_cast(&temp); + nweb = NWebAdapterHelper::Instance().CreateNWeb(enhanceSurfaceInfo, GetInitArgs(), DEFAULT_WIDTH, DEFAULT_HEIGHT); + (void)nweb; + nweb = NWebAdapterHelper::Instance().CreateNWeb(enhanceSurfaceInfo, GetInitArgs(), DEFAULT_WIDTH, NWEB_MAX_WIDTH); + (void)nweb; + nweb = NWebAdapterHelper::Instance().CreateNWeb(enhanceSurfaceInfo, GetInitArgs(), NWEB_MAX_WIDTH, DEFAULT_HEIGHT); + (void)nweb; + std::shared_ptr create_info = std::make_shared(); + nweb = NWebHelper::Instance().CreateNWeb(create_info); + (void)nweb; + return true; +} + +} // namespace NWeb +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::NWeb::NWebHelperFuzzTest(data, size); + OHOS::NWeb::NWebHelperFuzzTest_002(data, size); + OHOS::NWeb::NWebHelperFuzzTest_003(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nwebhelper_fuzzer.h b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nwebhelper_fuzzer.h new file mode 100644 index 00000000..3d473aea --- /dev/null +++ b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/nwebhelper_fuzzer.h @@ -0,0 +1,20 @@ +/* + * 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 TEST_FUZZTEST_NWEB_HELPER_FUZZER_H +#define TEST_FUZZTEST_NWEB_HELPER_FUZZER_H + +#define FUZZ_PROJECT_NAME "nwebhelper_fuzzer" +#endif /* TEST_FUZZTEST_NWEB_HELPER_FUZZER_H */ diff --git a/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/project.xml b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/project.xml new file mode 100644 index 00000000..85e7ef2c --- /dev/null +++ b/test/fuzztest/ohos_nweb/nwebhelper_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ohos_nweb/requestbuffer_fuzzer/requestbuffer_fuzzer.cpp b/test/fuzztest/ohos_nweb/requestbuffer_fuzzer/requestbuffer_fuzzer.cpp index 6f53af0e..0a09777f 100644 --- a/test/fuzztest/ohos_nweb/requestbuffer_fuzzer/requestbuffer_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/requestbuffer_fuzzer/requestbuffer_fuzzer.cpp @@ -56,14 +56,14 @@ bool RequestBufferFuzzTest(const uint8_t* data, size_t size) return false; } g_surface = surfaceNode->GetSurface(); - if (g_surface== nullptr) { + if (g_surface == nullptr) { return false; } } surfaceAdapter.RequestBuffer(g_surface, width, height); return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/requestbuffer_fuzzer/requestbuffer_fuzzer.h b/test/fuzztest/ohos_nweb/requestbuffer_fuzzer/requestbuffer_fuzzer.h index 4753266f..9db0c309 100644 --- a/test/fuzztest/ohos_nweb/requestbuffer_fuzzer/requestbuffer_fuzzer.h +++ b/test/fuzztest/ohos_nweb/requestbuffer_fuzzer/requestbuffer_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "requestbuffer_fuzzer" #endif /* TEST_FUZZTEST_REQUESTBUFFER_FUZZER_H */ - diff --git a/test/fuzztest/ohos_nweb/selectcertrequest_fuzzer/selectcertrequest_fuzzer.cpp b/test/fuzztest/ohos_nweb/selectcertrequest_fuzzer/selectcertrequest_fuzzer.cpp index 3527a091..558079e9 100644 --- a/test/fuzztest/ohos_nweb/selectcertrequest_fuzzer/selectcertrequest_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/selectcertrequest_fuzzer/selectcertrequest_fuzzer.cpp @@ -19,9 +19,9 @@ #include #include "nweb.h" +#include "nweb_adapter_helper.h" #include "nweb_handler.h" #include "nweb_helper.h" -#include "nweb_adapter_helper.h" #include "nweb_js_ssl_select_cert_result.h" using namespace OHOS::NWeb; @@ -34,17 +34,17 @@ bool SelectCertRequestFuzzTest(const uint8_t* data, size_t size) } OHOS::NWeb::NWebHandler handler; std::shared_ptr result = nullptr; - std::string host((const char *)data, size); + std::string host((const char*)data, size); int port; if (memcpy_s(&port, sizeof(int), data, sizeof(int)) != 0) { return false; } - std::vector keyTypes = {host}; - std::vector issuers = {host}; + std::vector keyTypes = { host }; + std::vector issuers = { host }; handler.OnSslSelectCertRequestByJS(result, host, port, keyTypes, issuers); return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/selectcertrequest_fuzzer/selectcertrequest_fuzzer.h b/test/fuzztest/ohos_nweb/selectcertrequest_fuzzer/selectcertrequest_fuzzer.h index aa9ea751..25668f85 100644 --- a/test/fuzztest/ohos_nweb/selectcertrequest_fuzzer/selectcertrequest_fuzzer.h +++ b/test/fuzztest/ohos_nweb/selectcertrequest_fuzzer/selectcertrequest_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "selectcertrequest_fuzzer" #endif /* TEST_FUZZTEST_SELECTCERTREQUEST_FUZZER_H */ - diff --git a/test/fuzztest/ohos_nweb/sethttpdns_fuzzer/sethttpdns_fuzzer.cpp b/test/fuzztest/ohos_nweb/sethttpdns_fuzzer/sethttpdns_fuzzer.cpp index 3121dd29..ba8828d4 100644 --- a/test/fuzztest/ohos_nweb/sethttpdns_fuzzer/sethttpdns_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/sethttpdns_fuzzer/sethttpdns_fuzzer.cpp @@ -19,9 +19,9 @@ #include #include "nweb.h" +#include "nweb_adapter_helper.h" #include "nweb_handler.h" #include "nweb_helper.h" -#include "nweb_adapter_helper.h" #include "nweb_init_params.h" using namespace OHOS::NWeb; @@ -32,7 +32,7 @@ bool SetHttpDnsFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size < sizeof(int))) { return false; } - std::string dohConfig((const char *)data, size); + std::string dohConfig((const char*)data, size); int mode; if (memcpy_s(&mode, sizeof(int), data, sizeof(int)) != 0) { return false; @@ -44,7 +44,7 @@ bool SetHttpDnsFuzzTest(const uint8_t* data, size_t size) NWebHelper::Instance().SetHttpDns(config); return true; } -} +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_nweb/sethttpdns_fuzzer/sethttpdns_fuzzer.h b/test/fuzztest/ohos_nweb/sethttpdns_fuzzer/sethttpdns_fuzzer.h index 592a7490..b35e6675 100644 --- a/test/fuzztest/ohos_nweb/sethttpdns_fuzzer/sethttpdns_fuzzer.h +++ b/test/fuzztest/ohos_nweb/sethttpdns_fuzzer/sethttpdns_fuzzer.h @@ -18,4 +18,3 @@ #define FUZZ_PROJECT_NAME "sethttpdns_fuzzer" #endif /* TEST_FUZZTEST_SETHTTPDNS_FUZZER_H */ - -- Gitee From 8e4d32e4b96e9c128e0af7b6abecdeae54d77b81 Mon Sep 17 00:00:00 2001 From: fredranking Date: Fri, 2 Aug 2024 20:34:52 +0800 Subject: [PATCH 101/126] fix sandbox path error, pre logic get real path,not sandbox Signed-off-by: fredranking --- .../include/ohos_adapter_helper_impl.h | 2 + .../src/ohos_adapter_helper_impl.cpp | 6 ++ .../include/ohos_resource_adapter_impl.h | 3 + .../src/ohos_resource_adapter_impl.cpp | 77 +++++++++++-------- .../ohos_adapter/ohos_adapter_helper.h | 2 + .../ark_ohos_adapter_helper_wrapper.cpp | 8 ++ .../webcore/ark_ohos_adapter_helper_wrapper.h | 2 + .../webview/ark_ohos_adapter_helper_impl.cpp | 6 ++ .../webview/ark_ohos_adapter_helper_impl.h | 2 + .../include/ark_ohos_adapter_helper.h | 3 + 10 files changed, 77 insertions(+), 34 deletions(-) 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 7bd751b8..93256f49 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 @@ -112,6 +112,8 @@ public: std::unique_ptr CreateOhosImageDecoderAdapter() override; std::unique_ptr CreateSensorAdapter() override; + + void SetArkWebCoreHapPathOverride(const std::string& hapPath) 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 8c429eac..0b4fe7f3 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 @@ -335,4 +335,10 @@ std::unique_ptr OhosAdapterHelperImpl::CreateSensorAdapter() return nullptr; #endif } + +void OhosAdapterHelperImpl::SetArkWebCoreHapPathOverride(const std::string& hapPath) +{ + OhosResourceAdapterImpl::SetArkWebCoreHapPathOverride(hapPath); +} + } // namespace OHOS::NWeb diff --git a/ohos_adapter/ohos_resource_adapter/include/ohos_resource_adapter_impl.h b/ohos_adapter/ohos_resource_adapter/include/ohos_resource_adapter_impl.h index 0375a43a..c3ff7f4a 100644 --- a/ohos_adapter/ohos_resource_adapter/include/ohos_resource_adapter_impl.h +++ b/ohos_adapter/ohos_resource_adapter/include/ohos_resource_adapter_impl.h @@ -70,6 +70,8 @@ public: static bool GetResourceString(const std::string& bundleName, const std::string& moduleName, const int32_t resId, std::string& result); + static void SetArkWebCoreHapPathOverride(const std::string& hapPath); + private: void Init(const std::string& hapPath); @@ -92,6 +94,7 @@ private: std::shared_ptr sysExtractor_; std::shared_ptr extractor_; + static std::string arkWebCoreHapPathOverride_; }; } // namespace OHOS::NWeb diff --git a/ohos_adapter/ohos_resource_adapter/src/ohos_resource_adapter_impl.cpp b/ohos_adapter/ohos_resource_adapter/src/ohos_resource_adapter_impl.cpp index 8fa3183b..1e13bada 100644 --- a/ohos_adapter/ohos_resource_adapter/src/ohos_resource_adapter_impl.cpp +++ b/ohos_adapter/ohos_resource_adapter/src/ohos_resource_adapter_impl.cpp @@ -37,7 +37,12 @@ using namespace OHOS::AbilityBase; namespace { const std::string NWEB_HAP_PATH = "/system/app/com.ohos.nweb/NWeb.hap"; const std::string NWEB_HAP_PATH_1 = "/system/app/NWeb/NWeb.hap"; +const std::string ARKWEBCORE_HAP_SANDBOX_PATH = "/data/storage/el1/bundle/nweb/entry.hap"; +const std::string PERSIST_ARKWEBCORE_INSTALL_PATH = "persist.arkwebcore.install_path"; const std::string NWEB_HAP_PATH_MODULE_UPDATE = "/module_update/ArkWebCore/app/com.ohos.nweb/NWeb.hap"; +const std::string HAP_REAL_PATH_PREFIX = "/data/app/el1/bundle/public/"; +const std::string HAP_SANDBOX_PATH_PREFIX = "/data/storage/el1/bundle/nweb/"; + const std::string NWEB_BUNDLE_NAME = "com.ohos.nweb"; const std::string NWEB_PACKAGE = "entry"; const std::string RAWFILE_PREFIX = "resources/rawfile/"; @@ -52,22 +57,6 @@ constexpr uint32_t START_YEAR = 1900; namespace OHOS::NWeb { namespace { -sptr GetBundleMgrProxy() -{ - auto systemAbilityMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!systemAbilityMgr) { - WVLOG_E("fail to get system ability mgr."); - return nullptr; - } - auto remoteObject = systemAbilityMgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - if (!remoteObject) { - WVLOG_E("fail to get bundle manager proxy."); - return nullptr; - } - WVLOG_D("get bundle manager proxy success."); - return iface_cast(remoteObject); -} - std::shared_ptr GetResourceMgr( const std::string& bundleName, const std::string& moduleName) { @@ -130,19 +119,39 @@ bool ParseRawFile(const std::string& rawFile, return true; } -std::string GetNWebHapPath() +std::string convertToSandboxPath(const std::string& installPath) { - auto iBundleMgr = GetBundleMgrProxy(); - if (iBundleMgr) { - OHOS::AppExecFwk::AbilityInfo abilityInfo; - OHOS::AppExecFwk::HapModuleInfo hapModuleInfo; - abilityInfo.bundleName = NWEB_BUNDLE_NAME; - abilityInfo.package = NWEB_PACKAGE; - if (iBundleMgr->GetHapModuleInfo(abilityInfo, hapModuleInfo)) { - WVLOG_D("get hap module info success. %{public}s", hapModuleInfo.hapPath.c_str()); - return hapModuleInfo.hapPath; + if (installPath.empty()) { + return ""; + } + size_t result = installPath.find(HAP_REAL_PATH_PREFIX); + if (result != std::string::npos) { + size_t pos = installPath.find_last_of('/'); + if (pos != std::string::npos && pos != installPath.size() - 1) { + return HAP_SANDBOX_PATH_PREFIX + installPath.substr(pos + 1); } } + return installPath; +} + +std::string GetNWebHapPath(const std::string& arkWebCoreHapPathOverride) +{ + if (access(arkWebCoreHapPathOverride.c_str(), F_OK) == 0) { + WVLOG_D("eixt HAP_arkWebCoreHapPathOverride"); + return convertToSandboxPath(arkWebCoreHapPathOverride); + } + + std::string installPath = convertToSandboxPath(OHOS::system::GetParameter(PERSIST_ARKWEBCORE_INSTALL_PATH, "")); + WVLOG_D("install_path,%{public}s", installPath.c_str()); + if (access(installPath.c_str(), F_OK) == 0) { + return installPath; + } + + if (access(ARKWEBCORE_HAP_SANDBOX_PATH.c_str(), F_OK) == 0) { + WVLOG_D("eixt ARKWEBCORE_HAP_SANDBOX_PATH"); + return ARKWEBCORE_HAP_SANDBOX_PATH; + } + if (access(NWEB_HAP_PATH.c_str(), F_OK) == 0) { WVLOG_D("eixt NWEB_HAP_PATH"); return NWEB_HAP_PATH; @@ -158,13 +167,6 @@ std::string GetNWebHapPath() return NWEB_HAP_PATH_MODULE_UPDATE; } WVLOG_W("access nweb hap module update path failed, errno(%{public}d): %{public}s", errno, strerror(errno)); - std::string install_path = - OHOS::system::GetParameter("persist.arkwebcore.install_path", NWEB_HAP_PATH_MODULE_UPDATE); - if (access(install_path.c_str(), F_OK) == 0) { - WVLOG_D("eixt install_path"); - return install_path; - } - WVLOG_E("access nweb install path failed, errno(%{public}d): %{public}s", errno, strerror(errno)); return ""; } } // namespace @@ -217,6 +219,7 @@ bool OhosFileMapperImpl::UnzipData(uint8_t** dest, size_t& len) return false; } +std::string OhosResourceAdapterImpl::arkWebCoreHapPathOverride_ = ""; OhosResourceAdapterImpl::OhosResourceAdapterImpl(const std::string& hapPath) { Init(hapPath); @@ -225,7 +228,7 @@ OhosResourceAdapterImpl::OhosResourceAdapterImpl(const std::string& hapPath) void OhosResourceAdapterImpl::Init(const std::string& hapPath) { bool newCreate = false; - std::string nwebHapPath = GetNWebHapPath(); + std::string nwebHapPath = GetNWebHapPath(arkWebCoreHapPathOverride_); if (!nwebHapPath.empty()) { sysExtractor_ = ExtractorUtil::GetExtractor(nwebHapPath, newCreate); if (!sysExtractor_) { @@ -444,4 +447,10 @@ std::shared_ptr OhosResourceAdapterImpl::GetRawFileMapper( bool isCompressed = fileMap->IsCompressed(); return std::make_shared(std::move(fileMap), isCompressed ? manager: nullptr); } + +void OhosResourceAdapterImpl::SetArkWebCoreHapPathOverride(const std::string& hapPath) +{ + arkWebCoreHapPathOverride_ = hapPath; +} + } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h b/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h index 0b89991c..4802666d 100644 --- a/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h +++ b/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h @@ -146,6 +146,8 @@ public: virtual std::unique_ptr CreateOhosImageDecoderAdapter() = 0; virtual std::unique_ptr CreateSensorAdapter() = 0; + + virtual void SetArkWebCoreHapPathOverride(const std::string& hapPath) = 0; }; } // namespace OHOS::NWeb 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 6d4ae170..4b1f2cde 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 @@ -459,4 +459,12 @@ std::unique_ptr ArkOhosAdapterHelperWrapper::CreateSensorAd return std::make_unique(adapter); } + +void ArkOhosAdapterHelperWrapper::SetArkWebCoreHapPathOverride(const std::string& hapPath) +{ + ArkWebString str = ArkWebStringClassToStruct(hapPath); + ctocpp_->SetArkWebCoreHapPathOverride(str); + ArkWebStringStructRelease(str); +} + } // 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 3290249d..688209e5 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 @@ -110,6 +110,8 @@ public: std::unique_ptr CreateSensorAdapter() override; + void SetArkWebCoreHapPathOverride(const std::string& hapPath) override; + private: ArkWebRefPtr ctocpp_; }; 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 e52ff0a7..49368063 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 @@ -377,4 +377,10 @@ ArkWebRefPtr ArkOhosAdapterHelperImpl::CreateSensorAdapter() std::shared_ptr shared = std::move(adapter); return new ArkSensorAdapterImpl(shared); } + +void ArkOhosAdapterHelperImpl::SetArkWebCoreHapPathOverride(const ArkWebString& hapPath) +{ + real_.SetArkWebCoreHapPathOverride(ArkWebStringStructToClass(hapPath)); +} + } // 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 1efa2b1a..76e238a0 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 @@ -110,6 +110,8 @@ public: ArkWebRefPtr CreateSensorAdapter() override; + void SetArkWebCoreHapPathOverride(const ArkWebString& hapPath) override; + private: NWeb::OhosAdapterHelper& real_; 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 61b9e134..c88cecf5 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 @@ -188,6 +188,9 @@ public: /*--ark web()--*/ virtual ArkWebRefPtr CreateSensorAdapter() = 0; + + /*--ark web()--*/ + virtual void SetArkWebCoreHapPathOverride(const ArkWebString& hapPath) = 0; }; } // namespace OHOS::ArkWeb -- Gitee From 92cee32b3739ecf78817cea0252c71c4bfd7abe7 Mon Sep 17 00:00:00 2001 From: "lxlxlx310@163.com" Date: Mon, 5 Aug 2024 09:20:10 +0800 Subject: [PATCH 102/126] =?UTF-8?q?=E4=BF=AE=E6=94=B9EnableSafeBrowsing?= =?UTF-8?q?=E6=97=A0controller=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lxlxlx310@163.com --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 300a8c02..907462b5 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -909,7 +909,10 @@ napi_value NapiWebviewController::EnableSafeBrowsing(napi_env env, napi_callback WebviewController *controller = nullptr; napi_unwrap(env, thisVar, (void **)&controller); - if (!controller || !controller->IsInit()) { + if (!controller) { + return result; + } + if (!controller->IsInit()) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); return result; } -- Gitee From e974252e65a68abf42257871c683d970c5170931 Mon Sep 17 00:00:00 2001 From: maohongyi Date: Mon, 5 Aug 2024 17:34:34 +0800 Subject: [PATCH 103/126] DTS:2024070220722 Signed-off-by: maohongyi --- interfaces/kits/napi/js/webview_export.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/napi/js/webview_export.js b/interfaces/kits/napi/js/webview_export.js index d71c3d6e..87fd6b15 100644 --- a/interfaces/kits/napi/js/webview_export.js +++ b/interfaces/kits/napi/js/webview_export.js @@ -16,6 +16,7 @@ let cert = requireInternal('security.cert'); let webview = requireInternal('web.webview'); let picker = requireNapi('file.picker'); +let photoAccessHelper = requireNapi('file.photoAccessHelper'); let cameraPicker = requireNapi('multimedia.cameraPicker'); let camera = requireNapi('multimedia.camera'); let accessControl = requireNapi('abilityAccessCtrl'); @@ -197,21 +198,21 @@ function isContainVideoMimeType(acceptTypes) { function selectPicture(param, selectResult) { try { let photoResultArray = []; - let photoSelectOptions = new picker.PhotoSelectOptions(); + let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); if (param.getMode() === FileSelectorMode.FileOpenMode) { console.log('allow select single photo or video'); photoSelectOptions.maxSelectNumber = 1; } let acceptTypes = param.getAcceptType(); - photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE; + photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE; if (isContainImageMimeType(acceptTypes) && !isContainVideoMimeType(acceptTypes)) { - photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; + photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; } if (!isContainImageMimeType(acceptTypes) && isContainVideoMimeType(acceptTypes)) { - photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.VIDEO_TYPE; + photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.VIDEO_TYPE; } - let photoPicker = new picker.PhotoViewPicker(); + let photoPicker = new photoAccessHelper.PhotoViewPicker(); photoPicker.select(photoSelectOptions).then((photoSelectResult) => { if (photoSelectResult.photoUris.length <= 0) { return; -- Gitee From f0dd38d9d24bccbe3727d7eee9259b692b0e07ec Mon Sep 17 00:00:00 2001 From: LGH W Date: Mon, 5 Aug 2024 20:30:16 +0800 Subject: [PATCH 104/126] add the judgement of nullptr Signed-off-by: LGH W --- .../audio_adapter/src/audio_renderer_adapter_impl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ohos_adapter/audio_adapter/src/audio_renderer_adapter_impl.cpp b/ohos_adapter/audio_adapter/src/audio_renderer_adapter_impl.cpp index c9da4cf3..1545191e 100644 --- a/ohos_adapter/audio_adapter/src/audio_renderer_adapter_impl.cpp +++ b/ohos_adapter/audio_adapter/src/audio_renderer_adapter_impl.cpp @@ -291,6 +291,10 @@ void AudioRendererAdapterImpl::SetInterruptMode(bool audioExclusive) bool AudioRendererAdapterImpl::IsRendererStateRunning() { + if (audio_renderer_ == nullptr) { + WVLOG_E("audio rendderer is nullptr"); + return false; + } return audio_renderer_->GetStatus() == OHOS::AudioStandard::RendererState::RENDERER_RUNNING; } -- Gitee From 2675e9e776bc94be0b3f7b61d1e54c596b809d3c Mon Sep 17 00:00:00 2001 From: zhengenhao0 Date: Tue, 6 Aug 2024 11:04:28 +0800 Subject: [PATCH 105/126] update NWeb.hap in master to 0806 Signed-off-by: zhengenhao0 --- ohos_nweb/prebuilts/arm/NWeb.hap | 4 ++-- ohos_nweb/prebuilts/arm64/NWeb.hap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_nweb/prebuilts/arm/NWeb.hap b/ohos_nweb/prebuilts/arm/NWeb.hap index da2e26b6..9287c4a0 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:931aab929033ac735a3fbfd3df4865bbcf64b061e67a858cd445e86dafe8607d -size 123013317 +oid sha256:253ebe9cb72e7dfeab708074099c3c3d0257e1c0f535c122bd9c328c56fe70d0 +size 123027815 diff --git a/ohos_nweb/prebuilts/arm64/NWeb.hap b/ohos_nweb/prebuilts/arm64/NWeb.hap index ba759931..8d5b44ee 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:e7b179dc941b9194e0619b194c7f28559295c12cc8c71efd1ba6372ca8fca8eb -size 190821282 +oid sha256:04c890447ccf036163f6770be2bba17393e54ead39e230761f10e004c3081615 +size 190817249 -- Gitee From 0a42f04d634be3da52304096189501f0b8c2745f Mon Sep 17 00:00:00 2001 From: chenxin128 Date: Mon, 29 Jul 2024 15:41:09 +0800 Subject: [PATCH 106/126] =?UTF-8?q?SA=20IDL=20=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenxin128 --- sa/BUILD.gn | 18 ++++++-- sa/include/app_fwk_update_service_proxy.h | 45 -------------------- sa/include/app_fwk_update_service_stub.h | 38 ----------------- sa/include/iapp_fwk_update_service.h | 39 ----------------- sa/src/app_fwk_update_service.cpp | 33 ++++++++------ sa/src/app_fwk_update_service_proxy.cpp | 52 ----------------------- sa/src/app_fwk_update_service_stub.cpp | 47 -------------------- 7 files changed, 35 insertions(+), 237 deletions(-) delete mode 100644 sa/include/app_fwk_update_service_proxy.h delete mode 100644 sa/include/app_fwk_update_service_stub.h delete mode 100644 sa/include/iapp_fwk_update_service.h delete mode 100644 sa/src/app_fwk_update_service_proxy.cpp delete mode 100644 sa/src/app_fwk_update_service_stub.cpp diff --git a/sa/BUILD.gn b/sa/BUILD.gn index 34f07aeb..32482cd5 100644 --- a/sa/BUILD.gn +++ b/sa/BUILD.gn @@ -10,7 +10,7 @@ # 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/config/components/idl_tool/idl.gni") import("//build/ohos.gni") group("app_fwk_update") { @@ -21,6 +21,16 @@ group("app_fwk_update") { ] } +idl_interface_sources = [ + "${target_gen_dir}/app_fwk_update_servic_proxy.cpp", + "${target_gen_dir}/app_fwk_update_servic_stub.cpp", +] + +idl_gen_interface("app_fwk_update_service_interface") { + src_idl = rebase_path("IAppFwkUpdateService.idl") + dst_file = string_join(",", idl_interface_sources) +} + ohos_sa_profile("app_fwk_update_service_profile") { sources = [ "8350.json" ] part_name = "webview" @@ -36,15 +46,17 @@ ohos_prebuilt_etc("app_fwk_update_service_cfg") { ohos_shared_library("app_fwk_update_service") { shlib_type = "sa" defines = [ "HILOG_TAG=\"app_fwk_update_service\"" ] + output_values = get_target_outputs(":app_fwk_update_service_interface") sources = [ "../sa/include/app_fwk_update_service.h", "../sa/src/app_fwk_update_service.cpp", - "../sa/src/app_fwk_update_service_proxy.cpp", - "../sa/src/app_fwk_update_service_stub.cpp", ] + sources += filter_include(output_values, [ "*.cpp" ]) + deps = [ ":app_fwk_update_service_interface" ] include_dirs = [ "../sa/include", "../ohos_nweb/include", + "${target_gen_dir}", ] cflags = [ diff --git a/sa/include/app_fwk_update_service_proxy.h b/sa/include/app_fwk_update_service_proxy.h deleted file mode 100644 index 5ceb5a89..00000000 --- a/sa/include/app_fwk_update_service_proxy.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H -#define OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H - -#include "iapp_fwk_update_service.h" -#include - -namespace OHOS { -namespace NWeb { -class AppFwkUpdateServiceProxy : public IRemoteProxy { -public: - explicit AppFwkUpdateServiceProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} - - virtual ~AppFwkUpdateServiceProxy() - {} - - ErrCode RequestUpdateService( - const std::string& bundleName) override; - -private: - static constexpr int32_t COMMAND_REQUEST_UPDATE_SERVICE = MIN_TRANSACTION_ID + 0; - - static inline BrokerDelegator delegator_; -}; -} // namespace NWeb -} // namespace OHOS -#endif // OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H - diff --git a/sa/include/app_fwk_update_service_stub.h b/sa/include/app_fwk_update_service_stub.h deleted file mode 100644 index 91fd6d5e..00000000 --- a/sa/include/app_fwk_update_service_stub.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 OHOS_NWEB_APPFWKUPDATESERVICESTUB_H -#define OHOS_NWEB_APPFWKUPDATESERVICESTUB_H - -#include "iapp_fwk_update_service.h" -#include - -namespace OHOS { -namespace NWeb { -class AppFwkUpdateServiceStub : public IRemoteStub { -public: - int32_t OnRemoteRequest( - uint32_t code, - MessageParcel& data, - MessageParcel& reply, - MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_REQUEST_UPDATE_SERVICE = MIN_TRANSACTION_ID + 0; -}; -} // namespace NWeb -} // namespace OHOS -#endif // OHOS_NWEB_APPFWKUPDATESERVICESTUB_H - diff --git a/sa/include/iapp_fwk_update_service.h b/sa/include/iapp_fwk_update_service.h deleted file mode 100644 index 45989e99..00000000 --- a/sa/include/iapp_fwk_update_service.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 OHOS_NWEB_IAPPFWKUPDATESERVICE_H -#define OHOS_NWEB_IAPPFWKUPDATESERVICE_H - -#include -#include -#include - -namespace OHOS { -namespace NWeb { -class IAppFwkUpdateService : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NWeb.IAppFwkUpdateService"); - - virtual ErrCode RequestUpdateService( - const std::string& bundleName) = 0; -protected: - const int VECTOR_MAX_SIZE = 102400; - const int LIST_MAX_SIZE = 102400; - const int MAP_MAX_SIZE = 102400; -}; -} // namespace NWeb -} // namespace OHOS -#endif // OHOS_NWEB_IAPPFWKUPDATESERVICE_H - diff --git a/sa/src/app_fwk_update_service.cpp b/sa/src/app_fwk_update_service.cpp index 4ea7ad12..89f0dec6 100644 --- a/sa/src/app_fwk_update_service.cpp +++ b/sa/src/app_fwk_update_service.cpp @@ -33,7 +33,8 @@ namespace OHOS::NWeb { const std::string PACKAGE_CHANGE_EVENT = "usual.event.PACKAGE_CHANGED"; -const std::string ARK_WEB_BUNDLE_NAME = "com.ohos.nweb"; +const std::string ARK_WEB_DEFAULT_BUNDLE_NAME = "com.ohos.nweb"; +const int RETRY_COUNT = 2; REGISTER_SYSTEM_ABILITY_BY_ID(AppFwkUpdateService, SUBSYS_WEBVIEW_SYS_UPDATE_SERVICE_ID, false); constexpr int32_t TASK_DELAY_TIME = 60000; // 1min = 1*60*1000 @@ -52,7 +53,9 @@ void PackageChangedReceiver::OnReceiveEvent(const EventFwk::CommonEventData& dat return; } std::string bundleName = data.GetWant().GetBundle(); - if (bundleName != ARK_WEB_BUNDLE_NAME) { + std::string package_name = + OHOS::system::GetParameter("persist.arkwebcore.package_name", ARK_WEB_DEFAULT_BUNDLE_NAME); + if (bundleName != package_name) { WVLOG_I("Bundle name is not nweb."); return; } @@ -125,7 +128,9 @@ bool AppFwkUpdateService::Init(const SystemAbilityOnDemandReason& startReason) } } } - if (bundleName != ARK_WEB_BUNDLE_NAME) { + std::string package_name = + OHOS::system::GetParameter("persist.arkwebcore.package_name", ARK_WEB_DEFAULT_BUNDLE_NAME); + if (bundleName != package_name) { WVLOG_I("Bundle name is not nweb."); return false; } @@ -155,22 +160,23 @@ void AppFwkUpdateService::SendAppSpawnMessage(const std::string& bundleName) { WVLOG_I("Send appspawn message start,uid = %{public}d.", getuid()); int ret = 0; + int retryCount = 0; AppSpawnClientHandle clientHandle = nullptr; AppSpawnReqMsgHandle reqHandle = 0; do { ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); if (ret != 0) { - WVLOG_I("Failed to create reqMgr."); - break; + WVLOG_I("Failed to create reqMgr,retry count = %{public}d.", retryCount); + continue; } ret = AppSpawnReqMsgCreate(MSG_UPDATE_MOUNT_POINTS, bundleName.c_str(), &reqHandle); if (ret != 0) { - WVLOG_I("Failed to create req."); - return; + WVLOG_I("Failed to create req,retry count = %{public}d.", retryCount); + continue; } AppSpawnResult result = {}; ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); - } while (0); + } while (++retryCount < RETRY_COUNT && ret != 0); AppSpawnClientDestroy(clientHandle); WVLOG_I("Send appspawn message success."); } @@ -179,22 +185,23 @@ void AppFwkUpdateService::SendNWebSpawnMesage(const std::string& bundleName) { WVLOG_I("Send nweb spawn messagestart,uid = %{public}d.", getuid()); int ret = 0; + int retryCount = 0; AppSpawnClientHandle clientHandle = nullptr; AppSpawnReqMsgHandle reqHandle = 0; do { ret = AppSpawnClientInit(NWEBSPAWN_SERVER_NAME, &clientHandle); if (ret != 0) { - WVLOG_I("Failed to create reqMgr."); - break; + WVLOG_I("Failed to create reqMgr,retry count = %{public}d.", retryCount); + continue; } ret = AppSpawnReqMsgCreate(MSG_RESTART_SPAWNER, bundleName.c_str(), &reqHandle); if (ret != 0) { - WVLOG_I("Failed to create req."); - return; + WVLOG_I("Failed to create req,retry count = %{public}d.", retryCount); + continue; } AppSpawnResult result = {}; ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); - } while (0); + } while (++retryCount < RETRY_COUNT && ret != 0); AppSpawnClientDestroy(clientHandle); WVLOG_I("Send nweb spawn message success."); } diff --git a/sa/src/app_fwk_update_service_proxy.cpp b/sa/src/app_fwk_update_service_proxy.cpp deleted file mode 100644 index a2eab080..00000000 --- a/sa/src/app_fwk_update_service_proxy.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 "app_fwk_update_service_proxy.h" - -namespace OHOS { -namespace NWeb { -ErrCode AppFwkUpdateServiceProxy::RequestUpdateService( - const std::string& bundleName) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_INVALID_VALUE; - } - - if (!data.WriteString16(Str8ToStr16(bundleName))) { - return ERR_INVALID_DATA; - } - - sptr remote = Remote(); - if (remote == nullptr) { - return ERR_INVALID_DATA; - } - int32_t result = remote->SendRequest(COMMAND_REQUEST_UPDATE_SERVICE, data, reply, option); - if (FAILED(result)) { - return result; - } - - ErrCode errCode = reply.ReadInt32(); - if (FAILED(errCode)) { - return errCode; - } - - return ERR_OK; -} -} // namespace NWeb -} // namespace OHOS diff --git a/sa/src/app_fwk_update_service_stub.cpp b/sa/src/app_fwk_update_service_stub.cpp deleted file mode 100644 index 43adecf5..00000000 --- a/sa/src/app_fwk_update_service_stub.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 "app_fwk_update_service_stub.h" - -namespace OHOS { -namespace NWeb { -int32_t AppFwkUpdateServiceStub::OnRemoteRequest( - uint32_t code, - MessageParcel& data, - MessageParcel& reply, - MessageOption& option) -{ - std::u16string localDescriptor = GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (localDescriptor != remoteDescriptor) { - return ERR_TRANSACTION_FAILED; - } - switch (code) { - case COMMAND_REQUEST_UPDATE_SERVICE: { - std::string bundleName = Str16ToStr8(data.ReadString16()); - ErrCode errCode = RequestUpdateService(bundleName); - if (!reply.WriteInt32(errCode)) { - return ERR_INVALID_VALUE; - } - return ERR_NONE; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - - return ERR_TRANSACTION_FAILED; -} -} // namespace NWeb -} // namespace OHOS -- Gitee From 527c5d4115299740e648eed8b1b717934ddfdbcf Mon Sep 17 00:00:00 2001 From: Delthin <1059661071@qq.com> Date: Wed, 7 Aug 2024 08:36:36 +0800 Subject: [PATCH 107/126] =?UTF-8?q?Add=2013=20api:=20int32=5Ft=20GetMediaP?= =?UTF-8?q?laybackState()=EF=BC=9B=20void=20CloseCamera();=20void=20StopCa?= =?UTF-8?q?mera();=20void=20StartCamera();=20bool=20GetPrintBackground();?= =?UTF-8?q?=20void=20SetPrintBackground(bool=20enable);=20bool=20GetScroll?= =?UTF-8?q?able();=20void=20SetScrollable(bool=20enable);=20bool=20IsAdsBl?= =?UTF-8?q?ockEnabledForCurPage();=20void=20EnableAdsBlock(bool=20enable);?= =?UTF-8?q?=20bool=20IsAdsBlockEnabled();=20bool=20IsIntelligentTrackingPr?= =?UTF-8?q?eventionEnabled();=20void=20EnableIntelligentTrackingPrevention?= =?UTF-8?q?(bool=20enable);=201=20enum:=20MediaPlaybackState;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/cj/include/webview_controller_impl.h | 33 +++++ interfaces/kits/cj/include/webview_ffi.h | 15 ++ .../kits/cj/src/webview_controller_impl.cpp | 125 +++++++++++++++++ interfaces/kits/cj/src/webview_ffi.cpp | 129 ++++++++++++++++++ 4 files changed, 302 insertions(+) diff --git a/interfaces/kits/cj/include/webview_controller_impl.h b/interfaces/kits/cj/include/webview_controller_impl.h index ddcb4a51..eda733f2 100644 --- a/interfaces/kits/cj/include/webview_controller_impl.h +++ b/interfaces/kits/cj/include/webview_controller_impl.h @@ -50,6 +50,13 @@ namespace OHOS::Webview { DANGEROUS = 5 }; + enum class MediaPlaybackState : int { + NONE = 0, + PLAYING = 1, + PAUSED = 2, + STOPPED = 3 + }; + class __attribute__((visibility("default"))) WebviewControllerImpl : public OHOS::FFI::FFIData { DECL_TYPE(WebviewControllerImpl, OHOS::FFI::FFIData) public: @@ -153,6 +160,32 @@ namespace OHOS::Webview { void Stop(); + int32_t GetMediaPlaybackState(); + + void CloseCamera(); + + void StopCamera(); + + void StartCamera(); + + bool GetPrintBackground(); + + void SetPrintBackground(bool enable); + + bool GetScrollable(); + + void SetScrollable(bool enable); + + bool IsAdsBlockEnabledForCurPage(); + + void EnableAdsBlock(bool enable); + + bool IsAdsBlockEnabled(); + + bool IsIntelligentTrackingPreventionEnabled(); + + void EnableIntelligentTrackingPrevention(bool enable); + public: static std::string customeSchemeCmdLine_; static bool existNweb_; diff --git a/interfaces/kits/cj/include/webview_ffi.h b/interfaces/kits/cj/include/webview_ffi.h index af456fc2..5e76149d 100644 --- a/interfaces/kits/cj/include/webview_ffi.h +++ b/interfaces/kits/cj/include/webview_ffi.h @@ -69,6 +69,21 @@ extern "C" { FFI_EXPORT int32_t FfiOHOSWebviewCtlRemoveCache(int64_t id, bool clearRom); FFI_EXPORT int64_t FfiOHOSWebviewCtlGetBackForwardEntries(int64_t id, int32_t *errCode); FFI_EXPORT int32_t FfiOHOSWebviewCtlStop(int64_t id); + FFI_EXPORT int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlCloseCamera(int64_t id); + FFI_EXPORT int32_t FfiOHOSWebviewCtlStopCamera(int64_t id); + FFI_EXPORT int32_t FfiOHOSWebviewCtlStartCamera(int64_t id); + FFI_EXPORT bool FfiOHOSWebviewCtlGetPrintBackground(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlSetPrintBackground(int64_t id, bool enable); + FFI_EXPORT bool FfiOHOSWebviewCtlGetScrollable(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlSetScrollable(int64_t id, bool enable); + FFI_EXPORT bool FfiOHOSWebviewCtlIsAdsBlockEnabledForCurPage(int64_t id); + FFI_EXPORT void FfiOHOSWebviewCtlEnableAdsBlock(int64_t id, bool enable); + FFI_EXPORT bool FfiOHOSWebviewCtlIsAdsBlockEnabled(int64_t id); + FFI_EXPORT bool FfiOHOSWebviewCtlIsIntelligentTrackingPreventionEnabled(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlEnableIntelligentTrackingPrevention(int64_t id, bool enable); + // BackForwardList FFI_EXPORT int32_t FfiOHOSBackForwardListCurrentIndex(int64_t id, int32_t *errCode); diff --git a/interfaces/kits/cj/src/webview_controller_impl.cpp b/interfaces/kits/cj/src/webview_controller_impl.cpp index 10b83226..267428db 100644 --- a/interfaces/kits/cj/src/webview_controller_impl.cpp +++ b/interfaces/kits/cj/src/webview_controller_impl.cpp @@ -607,4 +607,129 @@ namespace OHOS::Webview { } return; } + + int32_t WebviewControllerImpl::GetMediaPlaybackState() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return static_cast(MediaPlaybackState::NONE); + } + return nweb_ptr->GetMediaPlaybackState(); + } + + void WebviewControllerImpl::CloseCamera() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + return nweb_ptr->CloseCamera(); + } + return; + } + + void WebviewControllerImpl::StopCamera() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + return nweb_ptr->StopCamera(); + } + return; + } + + void WebviewControllerImpl::StartCamera() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + return nweb_ptr->StartCamera(); + } + return; + } + + bool WebviewControllerImpl::GetPrintBackground() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->GetPrintBackground(); + } + + void WebviewControllerImpl::SetPrintBackground(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->SetPrintBackground(enable); + } + return; + } + + bool WebviewControllerImpl::GetScrollable() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return true; + } + std::shared_ptr setting = nweb_ptr->GetPreference(); + if (!setting) { + return true; + } + return setting->GetScrollable(); + } + + void WebviewControllerImpl::SetScrollable(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return; + } + std::shared_ptr setting = nweb_ptr->GetPreference(); + if (!setting) { + return; + } + return setting->SetScrollable(enable); + } + + bool WebviewControllerImpl::IsAdsBlockEnabledForCurPage() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->IsAdsBlockEnabledForCurPage(); + } + + void WebviewControllerImpl::EnableAdsBlock(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->EnableAdsBlock(enable); + } + return; + } + + bool WebviewControllerImpl::IsAdsBlockEnabled() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->IsAdsBlockEnabled(); + } + + bool WebviewControllerImpl::IsIntelligentTrackingPreventionEnabled() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->IsIntelligentTrackingPreventionEnabled(); + } + + void WebviewControllerImpl::EnableIntelligentTrackingPrevention(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->EnableIntelligentTrackingPrevention(enable); + } + return; + } } diff --git a/interfaces/kits/cj/src/webview_ffi.cpp b/interfaces/kits/cj/src/webview_ffi.cpp index 62028c2a..2b7109ef 100644 --- a/interfaces/kits/cj/src/webview_ffi.cpp +++ b/interfaces/kits/cj/src/webview_ffi.cpp @@ -643,6 +643,135 @@ extern "C" { return NWebError::NO_ERROR; } + int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + } + return nativeWebviewCtl->GetMediaPlaybackState(); + } + + int32_t FfiOHOSWebviewCtlCloseCamera(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->CloseCamera(); + return NWebError::NO_ERROR; + } + + int32_t FfiOHOSWebviewCtlStopCamera(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->StopCamera(); + return NWebError::NO_ERROR; + } + + int32_t FfiOHOSWebviewCtlStartCamera(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->StartCamera(); + return NWebError::NO_ERROR; + } + + bool FfiOHOSWebviewCtlGetPrintBackground(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool printBackground = nativeWebviewCtl->GetPrintBackground(); + *errCode = NWebError::NO_ERROR; + return printBackground; + } + + int32_t FfiOHOSWebviewCtlSetPrintBackground(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->SetPrintBackground(enable); + return NWebError::NO_ERROR; + } + + bool FfiOHOSWebviewCtlGetScrollable(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool scrollable = nativeWebviewCtl->GetScrollable(); + *errCode = NWebError::NO_ERROR; + return scrollable; + } + + int32_t FfiOHOSWebviewCtlSetScrollable(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->SetScrollable(enable); + return NWebError::NO_ERROR; + } + + bool FfiOHOSWebviewCtlIsAdsBlockEnabledForCurPage(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return false; + } + return nativeWebviewCtl->IsAdsBlockEnabledForCurPage(); + } + + void FfiOHOSWebviewCtlEnableAdsBlock(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + nativeWebviewCtl->EnableAdsBlock(enable); + } + + bool FfiOHOSWebviewCtlIsAdsBlockEnabled(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return false; + } + return nativeWebviewCtl->IsAdsBlockEnabled(); + } + + bool FfiOHOSWebviewCtlIsIntelligentTrackingPreventionEnabled(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool intelligentTrackingPreventionEnabled = nativeWebviewCtl->IsIntelligentTrackingPreventionEnabled(); + *errCode = NWebError::NO_ERROR; + return intelligentTrackingPreventionEnabled; + } + + int32_t FfiOHOSWebviewCtlEnableIntelligentTrackingPrevention(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->EnableIntelligentTrackingPrevention(enable); + return NWebError::NO_ERROR; + } + // BackForwardList int32_t FfiOHOSBackForwardListCurrentIndex(int64_t id, int32_t *errCode) { -- Gitee From 02b3b4ba7f8b6ddc08a8a883bd724b1bc1e24b89 Mon Sep 17 00:00:00 2001 From: jeffreyliu Date: Wed, 7 Aug 2024 11:24:13 +0800 Subject: [PATCH 108/126] Bugfix for unhandled scope Signed-off-by: jeffreyliu Change-Id: I1af369d0eb5d8e178bb1e0dfdd6c3e6e5cc00fff --- .../webviewcontroller/webview_javascript_result_callback.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interfaces/kits/napi/webviewcontroller/webview_javascript_result_callback.cpp b/interfaces/kits/napi/webviewcontroller/webview_javascript_result_callback.cpp index ce07709f..6ec6ff2a 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_javascript_result_callback.cpp +++ b/interfaces/kits/napi/webviewcontroller/webview_javascript_result_callback.cpp @@ -1126,15 +1126,18 @@ std::shared_ptr WebviewJavaScriptResultCallBack::GetJavaScriptResultS } auto flowbufferAdapter = OhosAdapterHelper::GetInstance().CreateFlowbufferAdapter(); if (!flowbufferAdapter) { + napi_close_handle_scope(jsObj->GetEnv(), scope); return ret; } auto ashmem = flowbufferAdapter->CreateAshmemWithFd(fd, MAX_FLOWBUF_DATA_SIZE + HEADER_SIZE, PROT_READ); if (!ashmem) { + napi_close_handle_scope(jsObj->GetEnv(), scope); return ret; } std::vector argv = {}; if(!ConstructArgv(ashmem, args, argv, jsObj, routingId)) { + napi_close_handle_scope(jsObj->GetEnv(), scope); return ret; } close(fd); -- Gitee From 3501f8d692ba86cd6c4f13d7022e33bbd98419d7 Mon Sep 17 00:00:00 2001 From: 15503460968 Date: Wed, 7 Aug 2024 16:03:25 +0800 Subject: [PATCH 109/126] =?UTF-8?q?=E8=A1=A5=E5=85=85tdd=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 15503460968 --- .../include/imf_adapter_impl.h | 1 - .../src/imf_adapter_impl.cpp | 14 ------------- .../imf_adapter_impl_test.cpp | 20 +++++++++++++++++++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ohos_adapter/inputmethodframework_adapter/include/imf_adapter_impl.h b/ohos_adapter/inputmethodframework_adapter/include/imf_adapter_impl.h index b0790882..46b3ae7e 100644 --- a/ohos_adapter/inputmethodframework_adapter/include/imf_adapter_impl.h +++ b/ohos_adapter/inputmethodframework_adapter/include/imf_adapter_impl.h @@ -87,7 +87,6 @@ private: const std::string PREVIEW_TEXT_STYLE_KEY = "previewTextStyle"; const std::string PREVIEW_TEXT_STYLE_UNDERLINE = "underline"; const std::string AUTO_FILL_PARAMS_USERNAME = "com.autofill.params.userName"; - const std::string AUTO_FILL_PARAMS_NEWPASSWORD = "com.autofill.params.newPassword"; const std::string AUTO_FILL_PARAMS_OTHERACCOUNT = "com.autofill.params.otherAccount"; }; diff --git a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp index d7284efe..cc4942ae 100644 --- a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp +++ b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp @@ -241,14 +241,6 @@ int32_t IMFTextListenerAdapterImpl::ReceivePrivateCommand( } } - item = privateCommand.find(AUTO_FILL_PARAMS_NEWPASSWORD); - if (item != privateCommand.end()) { - if (listener_) { - std::string content = std::get(item->second); - listener_->AutoFillWithIMFEvent(false, false, true, content); - } - } - item = privateCommand.find(AUTO_FILL_PARAMS_OTHERACCOUNT); if (item != privateCommand.end()) { if (listener_) { @@ -415,12 +407,6 @@ bool IMFAdapterImpl::ParseFillContentJsonValue(const std::string& commandValue, map.insert(std::make_pair("userName", userName->valuestring)); } } - if (cJSON_HasObjectItem(sourceJson, "newPassword")) { - cJSON* newPassword = cJSON_GetObjectItem(sourceJson, "newPassword"); - if (newPassword != nullptr && cJSON_IsString(newPassword) && newPassword->valuestring != nullptr) { - map.insert(std::make_pair("newPassword", newPassword->valuestring)); - } - } if (cJSON_HasObjectItem(sourceJson, "hasAccount")) { cJSON* hasAccount = cJSON_GetObjectItem(sourceJson, "hasAccount"); if (hasAccount != nullptr && cJSON_IsString(hasAccount) && hasAccount->valuestring != nullptr) { diff --git a/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp b/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp index 635b91ac..9ae50f22 100644 --- a/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/imf_adapter_test/imf_adapter_impl_test.cpp @@ -485,6 +485,10 @@ HWTEST_F(NWebIMFAdapterTest, NWebIMFAdapterTest_IMFAdapterImpl_009, TestSize.Lev listenerTest->ReceivePrivateCommand(privateCommand); privateCommand = { { "previewTextStyle", "underline" } }; listenerTest->ReceivePrivateCommand(privateCommand); + privateCommand = { { "com.autofill.params.userName", "test" } }; + listenerTest->ReceivePrivateCommand(privateCommand); + privateCommand = { { "com.autofill.params.otherAccount", true } }; + listenerTest->ReceivePrivateCommand(privateCommand); } /** @@ -506,4 +510,20 @@ HWTEST_F(NWebIMFAdapterTest, NWebIMFAdapterTest_InsertText_010, TestSize.Level1) g_imf->HideTextInput(); } +/** + * @tc.name: NWebIMFAdapterTest_InsertText_011. + * @tc.desc: IMF adapter unittest. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(NWebIMFAdapterTest, NWebIMFAdapterTest_InsertText_011, TestSize.Level1) +{ + EXPECT_NE(g_imf, nullptr); + std::string commandKey = "autofill.cancel"; + std::string commandValue = "{\"userName\":\"test\",\"hasAccount\":\"test\"}"; + g_imf->SendPrivateCommand(commandKey, commandValue); + commandKey = "test"; + g_imf->SendPrivateCommand(commandKey, commandValue); +} + } // namespace OHOS::NWeb -- Gitee From 43f3c0e64ea8b496e90298c64e2e4453f44506ab Mon Sep 17 00:00:00 2001 From: ZhaoPengfei Date: Wed, 7 Aug 2024 23:11:32 +0800 Subject: [PATCH 110/126] add api for ltpo Signed-off-by: ZhaoPengfei --- bundle.json | 2 +- config.gni | 5 ++++ ohos_adapter/BUILD.gn | 5 ++++ .../include/vsync_adapter_impl.h | 4 ++++ .../src/vsync_adapter_impl.cpp | 23 ++++++++++++++++++ .../include/system_properties_adapter_impl.h | 2 ++ .../src/system_properties_adapter_impl.cpp | 5 ++++ .../include/ohos_adapter/graphic_adapter.h | 3 ++- .../ohos_adapter/system_properties_adapter.h | 2 ++ .../ark_system_properties_adapter_wrapper.cpp | 8 +++++++ .../ark_system_properties_adapter_wrapper.h | 1 + .../webcore/ark_vsync_adapter_wrapper.h | 11 +++++++++ .../ark_system_properties_adapter_impl.cpp | 4 ++++ .../ark_system_properties_adapter_impl.h | 1 + .../bridge/webview/ark_vsync_adapter_impl.cpp | 8 ++++++- .../bridge/webview/ark_vsync_adapter_impl.h | 1 + .../include/ark_graphic_adapter.h | 4 +++- .../include/ark_system_properties_adapter.h | 3 +++ ohos_nweb/etc/web_config.xml | 19 ++------------- ohos_nweb/include/nweb_adapter_helper.h | 1 + ohos_nweb/include/nweb_config_helper.h | 4 ++++ ohos_nweb/src/nweb_config_helper.cpp | 24 +++++++++++++++++++ ohos_nweb/src/nweb_helper.cpp | 5 ++++ 23 files changed, 124 insertions(+), 21 deletions(-) diff --git a/bundle.json b/bundle.json index c2095500..45a7a03c 100644 --- a/bundle.json +++ b/bundle.json @@ -84,7 +84,7 @@ ], "third_party": [ "chromium", - "cef" + "cef" ] }, "build": { diff --git a/config.gni b/config.gni index 84868dae..1e2c6aa1 100644 --- a/config.gni +++ b/config.gni @@ -25,6 +25,7 @@ declare_args() { webview_enterprise_device_manager_enable = true webview_media_avsession_enable = true webview_sensors_sensor_enable = true + webview_graphic_2d_ext_enable = true if (defined(global_parts_info) && !defined(global_parts_info.resourceschedule_soc_perf)) { @@ -80,4 +81,8 @@ declare_args() { !defined(global_parts_info.sensors_sensor)) { webview_sensors_sensor_enable = false } + if (defined(global_parts_info) && + !defined(global_parts_info.graphic_graphic_2d_ext)) { + webview_graphic_2d_ext_enable = false + } } diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 49be81da..e82ff1b7 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -301,4 +301,9 @@ ohos_shared_library("nweb_ohos_adapter") { subsystem_name = "web" deps = [ "../ohos_nweb:web_configs" ] + + if (webview_graphic_2d_ext_enable) { + external_deps += [ "graphic_2d_ext:libaps_client" ] + defines += [ "NWEB_GRAPHIC_2D_EXT_ENABLE" ] + } } diff --git a/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h b/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h index 5d13d097..49be040b 100644 --- a/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h +++ b/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h @@ -41,6 +41,8 @@ public: void SetOnVsyncCallback(void (*callback)()) override; void SetIsGPUProcess(bool isGPU); void SetOnVsyncEndCallback(void (*onVsyncEndCallback)()) override; + + void SetScene(const std::string& sceneName, uint32_t state) override; private: static void OnVsync(int64_t timestamp, void* data); void VsyncCallbackInner(int64_t nanoTimestamp); @@ -61,6 +63,8 @@ private: static void (*onVsyncEndCallback_)(); bool frameRateLinkerEnable_ = false; bool isGPUProcess_ = false; + + std::string pkgName_ {""}; }; } // namespace OHOS::NWeb diff --git a/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp b/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp index 0c1f7aea..17bfd20c 100644 --- a/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp +++ b/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp @@ -16,6 +16,10 @@ #include "vsync_adapter_impl.h" #include "aafwk_browser_client_adapter_impl.h" +#include "application_context.h" +#if defined(NWEB_GRAPHIC_2D_EXT_ENABLE) +#include "aps_manager.h" +#endif #include "nweb_log.h" #include "res_sched_client_adapter.h" #include "system_properties_adapter_impl.h" @@ -25,6 +29,9 @@ namespace OHOS::NWeb { namespace { const std::string THREAD_NAME = "VSync-webview"; constexpr int32_t WEBVIEW_FRAME_RATE_TYPE = 4; +#if defined(NWEB_GRAPHIC_2D_EXT_ENABLE) +constexpr int32_t APS_MANAGER_CLOSE_ALL = 2; +#endif } void (*VSyncAdapterImpl::callback_)() = nullptr; @@ -43,6 +50,9 @@ VSyncAdapterImpl::~VSyncAdapterImpl() vsyncHandler_ = nullptr; } hasReportedKeyThread_ = false; +#if defined(NWEB_GRAPHIC_2D_EXT_ENABLE) + Rosen::ApsManager::GetInstance().SetScene(pkgName_, "WEB_LIST_FLING", APS_MANAGER_CLOSE_ALL); +#endif } VSyncAdapterImpl& VSyncAdapterImpl::GetInstance() @@ -205,4 +215,17 @@ void VSyncAdapterImpl::SetOnVsyncEndCallback(void (*onVsyncEndCallback)()) WVLOG_D("callback function: %{public}ld", (long)onVsyncEndCallback); onVsyncEndCallback_ = onVsyncEndCallback; } + +void VSyncAdapterImpl::SetScene(const std::string& sceneName, uint32_t state) { + WVLOG_D("APSManagerAdapterImpl SetScene sceneName=%{public}s state=%{public}u", sceneName.c_str(), state); +#if defined(NWEB_GRAPHIC_2D_EXT_ENABLE) + if (pkgName_.empty()) { + auto appInfo = AbilityRuntime::ApplicationContext::GetInstance()->GetApplicationInfo(); + if (appInfo != nullptr) { + pkgName_ = appInfo->bundleName.c_str(); + } + } + Rosen::ApsManager::GetInstance().SetScene(pkgName_, sceneName, state); +#endif +} } // namespace OHOS::NWeb diff --git a/ohos_adapter/system_properties_adapter/include/system_properties_adapter_impl.h b/ohos_adapter/system_properties_adapter/include/system_properties_adapter_impl.h index 5374542a..cf6d4962 100644 --- a/ohos_adapter/system_properties_adapter/include/system_properties_adapter_impl.h +++ b/ohos_adapter/system_properties_adapter/include/system_properties_adapter_impl.h @@ -73,6 +73,8 @@ public: std::vector GetLTPOConfig(const std::string& settingName) override; std::string GetOOPGPUStatus() override; + + bool IsLTPODynamicApp(const std::string& bundleName) override; private: SystemPropertiesAdapterImpl(); diff --git a/ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp b/ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp index c5864c08..e5c25abc 100644 --- a/ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp +++ b/ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp @@ -316,4 +316,9 @@ std::vector SystemPropertiesAdapterImpl::GetLTPOConfig(const s { return NWebConfigHelper::Instance().GetPerfConfig(settingName); } + +bool SystemPropertiesAdapterImpl::IsLTPODynamicApp(const std::string& bundleName) +{ + return NWebConfigHelper::Instance().IsLTPODynamicApp(bundleName); +} } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_adapter/graphic_adapter.h b/ohos_interface/include/ohos_adapter/graphic_adapter.h index 4ce61994..662456ab 100644 --- a/ohos_interface/include/ohos_adapter/graphic_adapter.h +++ b/ohos_interface/include/ohos_adapter/graphic_adapter.h @@ -44,6 +44,8 @@ public: virtual void SetOnVsyncCallback(void (*callback)()) = 0; virtual void SetOnVsyncEndCallback(void (*onVsyncEndCallback)()) {} + + virtual void SetScene(const std::string& sceneName, uint32_t state) = 0; }; // be consistent with rom/foundation/graphic/graphic_2d/interfaces/inner_api/common/graphic_common_c.h:GSError @@ -288,7 +290,6 @@ public: virtual int32_t FlushBuffer(std::shared_ptr buffer, int32_t fence, std::shared_ptr config) = 0; }; - } // namespace OHOS::NWeb #endif // GRAPHIC_ADAPTER_H diff --git a/ohos_interface/include/ohos_adapter/system_properties_adapter.h b/ohos_interface/include/ohos_adapter/system_properties_adapter.h index 351e3169..050ac381 100644 --- a/ohos_interface/include/ohos_adapter/system_properties_adapter.h +++ b/ohos_interface/include/ohos_adapter/system_properties_adapter.h @@ -88,6 +88,8 @@ public: virtual std::vector GetLTPOConfig(const std::string& settingName) = 0; virtual std::string GetOOPGPUStatus() = 0; + + virtual bool IsLTPODynamicApp(const std::string& bundleName) = 0; }; } // namespace OHOS::NWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_system_properties_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_system_properties_adapter_wrapper.cpp index eb58cd05..81b1223e 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_system_properties_adapter_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_system_properties_adapter_wrapper.cpp @@ -211,4 +211,12 @@ std::string ArkSystemPropertiesAdapterWrapper::GetOOPGPUStatus() ArkWebStringStructRelease(str); return result; } + +bool ArkSystemPropertiesAdapterWrapper::IsLTPODynamicApp(const std::string& bundleName) +{ + ArkWebString ark_bundle_name = ArkWebStringClassToStruct(bundleName); + bool result = ctocpp_->IsLTPODynamicApp(ark_bundle_name); + ArkWebStringStructRelease(ark_bundle_name); + return result; +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_system_properties_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_system_properties_adapter_wrapper.h index a3bedcff..12a363fe 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_system_properties_adapter_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_system_properties_adapter_wrapper.h @@ -69,6 +69,7 @@ public: std::string GetOOPGPUStatus() override; + bool IsLTPODynamicApp(const std::string& bundleName) override; private: ArkWebRefPtr ctocpp_; }; diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.h index 7dac11d8..940beafa 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.h @@ -37,10 +37,21 @@ public: void SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCallback) override; + void SetScene(const std::string& sceneName, uint32_t state) override; private: ArkWebRefPtr ctocpp_; }; +void ArkVSyncAdapterWrapper::SetScene(const std::string& sceneName, uint32_t state) +{ + if (!ctocpp_) { + return; + } + ArkWebString ark_value = ArkWebStringClassToStruct(sceneName); + ctocpp_->SetScene(ark_value, state); + ArkWebStringStructRelease(ark_value); +} + } // namespace OHOS::ArkWeb #endif // ARK_VSYNC_ADAPTER_WRAPPER_H diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.cpp index 95f3352f..434b2632 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.cpp @@ -148,4 +148,8 @@ ArkWebString ArkSystemPropertiesAdapterImpl::GetOOPGPUStatus() return ArkWebStringClassToStruct(str); } +bool ArkSystemPropertiesAdapterImpl::IsLTPODynamicApp(ArkWebString bundleName) +{ + return real_.IsLTPODynamicApp(ArkWebStringStructToClass(bundleName)); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.h index b3933306..3ed061f3 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.h @@ -68,6 +68,7 @@ public: ArkWebString GetOOPGPUStatus() override; + bool IsLTPODynamicApp(ArkWebString settingName) override; private: NWeb::SystemPropertiesAdapter& real_; diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_vsync_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_vsync_adapter_impl.cpp index 94776186..a5362872 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_vsync_adapter_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_vsync_adapter_impl.cpp @@ -50,4 +50,10 @@ void ArkVSyncAdapterImpl::SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCallba { return real_.SetOnVsyncEndCallback(onVsyncEndCallback); } -} // namespace OHOS::ArkWeb + +void ArkVSyncAdapterImpl::SetScene(const ArkWebString& sceneName, uint32_t state) +{ + std::string sceneNameStr = ArkWebStringStructToClass(sceneName); + return real_.SetScene(sceneNameStr, state); +} +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_vsync_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_vsync_adapter_impl.h index ffeb602a..02fcb488 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_vsync_adapter_impl.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_vsync_adapter_impl.h @@ -38,6 +38,7 @@ public: void SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCallback) override; + void SetScene(const ArkWebString& sceneName, uint32_t state) override; private: NWeb::VSyncAdapter& real_; diff --git a/ohos_interface/ohos_glue/ohos_adapter/include/ark_graphic_adapter.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_graphic_adapter.h index ca7f4151..28f8235d 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/include/ark_graphic_adapter.h +++ b/ohos_interface/ohos_glue/ohos_adapter/include/ark_graphic_adapter.h @@ -44,6 +44,9 @@ public: /*--ark web()--*/ virtual void SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCallback) = 0; + + /*--ark web()--*/ + virtual void SetScene(const ArkWebString& sceneName, uint32_t state) = 0; }; /*--ark web(source=webcore)--*/ @@ -225,7 +228,6 @@ public: virtual int32_t FlushBuffer(ArkWebRefPtr buffer, int32_t fence, ArkWebRefPtr config) = 0; }; - } // namespace OHOS::ArkWeb #endif // Ark_GRAPHIC_ADAPTER_H diff --git a/ohos_interface/ohos_glue/ohos_adapter/include/ark_system_properties_adapter.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_system_properties_adapter.h index b95ff8e2..a6bcef62 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/include/ark_system_properties_adapter.h +++ b/ohos_interface/ohos_glue/ohos_adapter/include/ark_system_properties_adapter.h @@ -89,6 +89,9 @@ public: /*--ark web()--*/ virtual ArkWebString GetOOPGPUStatus() = 0; + + /*--ark web()--*/ + virtual bool IsLTPODynamicApp(ArkWebString bundleName) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_nweb/etc/web_config.xml b/ohos_nweb/etc/web_config.xml index c40748bb..afb862ef 100644 --- a/ohos_nweb/etc/web_config.xml +++ b/ohos_nweb/etc/web_config.xml @@ -71,28 +71,13 @@ - - - - - - - - - - - - - - - - - + + diff --git a/ohos_nweb/include/nweb_adapter_helper.h b/ohos_nweb/include/nweb_adapter_helper.h index 3e33fb04..b9b4a9ac 100644 --- a/ohos_nweb/include/nweb_adapter_helper.h +++ b/ohos_nweb/include/nweb_adapter_helper.h @@ -47,6 +47,7 @@ public: void ReadConfigIfNeeded(); std::string ParsePerfConfig(const std::string &configNodeName, const std::string &argsNodeName); std::vector GetPerfConfig(const std::string& settingName); + bool IsLTPODynamicApp(const std::string& bundleName); private: NWebAdapterHelper() = default; diff --git a/ohos_nweb/include/nweb_config_helper.h b/ohos_nweb/include/nweb_config_helper.h index e2e77c0c..a9d9a92d 100644 --- a/ohos_nweb/include/nweb_config_helper.h +++ b/ohos_nweb/include/nweb_config_helper.h @@ -31,6 +31,7 @@ public: void ReadConfigIfNeeded(); std::string ParsePerfConfig(const std::string &configNodeName, const std::string &argsNodeName); std::vector GetPerfConfig(const std::string& settingName); + bool IsLTPODynamicApp(const std::string& bundleName); private: NWebConfigHelper() = default; @@ -42,8 +43,11 @@ private: void ParseWebConfigXml(const std::string &configFilePath, std::shared_ptr initArgs); void WriteConfigValueToSysPara(const std::string &configName, const std::string &value); void ParseDeleteConfig(const xmlNodePtr &rootPtr, std::shared_ptr initArgs); + void ParseNWebLTPOApp(xmlNodePtr nodePtr); + std::map perfConfig_; std::map> ltpoConfig_; + std::set ltpoAllowedApps_ {}; }; } // namespace OHOS diff --git a/ohos_nweb/src/nweb_config_helper.cpp b/ohos_nweb/src/nweb_config_helper.cpp index eb5444d5..fcc63224 100644 --- a/ohos_nweb/src/nweb_config_helper.cpp +++ b/ohos_nweb/src/nweb_config_helper.cpp @@ -36,6 +36,7 @@ const std::string PERFORMANCE_CONFIG = "performanceConfig"; // The config used in base/web/webview const std::string BASE_WEB_CONFIG = "baseWebConfig"; const std::string WEB_ANIMATION_DYNAMIC_SETTING_CONFIG = "property_animation_dynamic_settings"; +const std::string WEB_ANIMATION_DYNAMIC_APP = "DYNAMIC_APPS"; const auto XML_ATTR_NAME = "name"; const auto XML_ATTR_MIN = "min"; const auto XML_ATTR_MAX = "max"; @@ -296,6 +297,10 @@ void NWebConfigHelper::ParseNWebLTPOConfig(xmlNodePtr nodePtr) continue; } std::string settingName = (char *)xmlGetProp(curNodePtr, BAD_CAST(XML_ATTR_NAME)); + if (settingName == WEB_ANIMATION_DYNAMIC_APP) { + ParseNWebLTPOApp(curNodePtr); + continue; + } std::vector frameRateSetting; for (xmlNodePtr curDynamicNodePtr = curNodePtr->xmlChildrenNode; curDynamicNodePtr; curDynamicNodePtr = curDynamicNodePtr->next) { @@ -316,6 +321,25 @@ void NWebConfigHelper::ParseNWebLTPOConfig(xmlNodePtr nodePtr) } } +void NWebConfigHelper::ParseNWebLTPOApp(xmlNodePtr nodePtr) +{ + for (xmlNodePtr curDynamicNodePtr = nodePtr->xmlChildrenNode; curDynamicNodePtr; + curDynamicNodePtr = curDynamicNodePtr->next) { + if (curDynamicNodePtr->name == nullptr || curDynamicNodePtr->type == XML_COMMENT_NODE) { + WVLOG_E("invalid node!"); + continue; + } + std::string bundleName = (char *)xmlGetProp(curDynamicNodePtr, BAD_CAST(XML_ATTR_NAME)); + ltpoAllowedApps_.emplace(bundleName); + WVLOG_D("ltpo dynamic app: %{public}s", bundleName.c_str()); + } +} + +bool NWebConfigHelper::IsLTPODynamicApp(const std::string& bundleName) +{ + return ltpoAllowedApps_.find(bundleName) != ltpoAllowedApps_.end(); +} + std::vector NWebConfigHelper::GetPerfConfig(const std::string& settingName) { if (ltpoConfig_.find(settingName) == ltpoConfig_.end()) { diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index 6b9e0d5e..c7d4c0d5 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -1253,4 +1253,9 @@ std::string NWebAdapterHelper::ParsePerfConfig(const std::string &configNodeName std::string config = NWebConfigHelper::Instance().ParsePerfConfig(configNodeName, argsNodeName); return config; } + +bool NWebAdapterHelper::IsLTPODynamicApp(const std::string& bundleName) +{ + return NWebConfigHelper::Instance().IsLTPODynamicApp(bundleName); +} } // namespace OHOS::NWeb \ No newline at end of file -- Gitee From 6fbbba11bfb15f60b524752895e31caa1fea0950 Mon Sep 17 00:00:00 2001 From: ZhaoPengfei Date: Thu, 8 Aug 2024 10:59:24 +0800 Subject: [PATCH 111/126] fix according to review opinion Signed-off-by: ZhaoPengfei --- .../bridge/webcore/ark_vsync_adapter_wrapper.cpp | 10 ++++++++++ .../bridge/webcore/ark_vsync_adapter_wrapper.h | 11 ----------- .../webview/ark_system_properties_adapter_impl.cpp | 2 +- .../webview/ark_system_properties_adapter_impl.h | 2 +- .../include/ark_system_properties_adapter.h | 2 +- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.cpp index 7c1c4bf4..60a40a73 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.cpp @@ -67,4 +67,14 @@ void ArkVSyncAdapterWrapper::SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCal } return ctocpp_->SetOnVsyncEndCallback(onVsyncEndCallback); } + +void ArkVSyncAdapterWrapper::SetScene(const std::string& sceneName, uint32_t state) +{ + if (!ctocpp_) { + return; + } + ArkWebString ark_value = ArkWebStringClassToStruct(sceneName); + ctocpp_->SetScene(ark_value, state); + ArkWebStringStructRelease(ark_value); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.h index 940beafa..970a52cb 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_vsync_adapter_wrapper.h @@ -41,17 +41,6 @@ public: private: ArkWebRefPtr ctocpp_; }; - -void ArkVSyncAdapterWrapper::SetScene(const std::string& sceneName, uint32_t state) -{ - if (!ctocpp_) { - return; - } - ArkWebString ark_value = ArkWebStringClassToStruct(sceneName); - ctocpp_->SetScene(ark_value, state); - ArkWebStringStructRelease(ark_value); -} - } // namespace OHOS::ArkWeb #endif // ARK_VSYNC_ADAPTER_WRAPPER_H diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.cpp index 434b2632..1371fd27 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.cpp @@ -148,7 +148,7 @@ ArkWebString ArkSystemPropertiesAdapterImpl::GetOOPGPUStatus() return ArkWebStringClassToStruct(str); } -bool ArkSystemPropertiesAdapterImpl::IsLTPODynamicApp(ArkWebString bundleName) +bool ArkSystemPropertiesAdapterImpl::IsLTPODynamicApp(const ArkWebString& bundleName) { return real_.IsLTPODynamicApp(ArkWebStringStructToClass(bundleName)); } diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.h index 3ed061f3..c09572c0 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_system_properties_adapter_impl.h @@ -68,7 +68,7 @@ public: ArkWebString GetOOPGPUStatus() override; - bool IsLTPODynamicApp(ArkWebString settingName) override; + bool IsLTPODynamicApp(const ArkWebString& settingName) override; private: NWeb::SystemPropertiesAdapter& real_; diff --git a/ohos_interface/ohos_glue/ohos_adapter/include/ark_system_properties_adapter.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_system_properties_adapter.h index a6bcef62..cec9e2ec 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/include/ark_system_properties_adapter.h +++ b/ohos_interface/ohos_glue/ohos_adapter/include/ark_system_properties_adapter.h @@ -91,7 +91,7 @@ public: virtual ArkWebString GetOOPGPUStatus() = 0; /*--ark web()--*/ - virtual bool IsLTPODynamicApp(ArkWebString bundleName) = 0; + virtual bool IsLTPODynamicApp(const ArkWebString& bundleName) = 0; }; } // namespace OHOS::ArkWeb -- Gitee From 95fa51abef4a06dce5e6a778f8659e1712e5a241 Mon Sep 17 00:00:00 2001 From: yueyang Date: Thu, 8 Aug 2024 15:35:45 +0800 Subject: [PATCH 112/126] =?UTF-8?q?17100018=E6=8A=A5=E9=94=99=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yueyang --- interfaces/kits/cj/src/web_errors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/cj/src/web_errors.cpp b/interfaces/kits/cj/src/web_errors.cpp index 93295db9..c9277f6a 100644 --- a/interfaces/kits/cj/src/web_errors.cpp +++ b/interfaces/kits/cj/src/web_errors.cpp @@ -36,7 +36,7 @@ const std::string TYPE_NOT_MATCH_WITCH_VALUE_MSG = "The type and value of the me const std::string NEW_OOM_MSG = "Memory allocation failed."; const std::string DOWNLOAD_NOT_PAUSED_MSG = "The download task is not paused."; const std::string NO_VALID_CONTROLLER_FOR_DOWNLOAD_MSG = "No valid WebviewController is associated."; -const std::string NO_DOWNLOAD_DELEGATE_SET_MSG = "No valid WebviewController is associated."; +const std::string NO_DOWNLOAD_DELEGATE_SET_MSG = "No WebDownloadDelegate has been set yet."; const std::string DOWNLOAD_NOT_START_MSG = "The download task is not started yet."; const std::string REGISTER_CUSTOM_SCHEME_FAILED_MSG = "Failed to register custom schemes."; const std::string HTTP_BODY_STREAN_INIT_FAILED_MSG = "Failed to initialize the HTTP body stream."; -- Gitee From b6d89f236188eb1cd39f7b10072cb3b7617f0279 Mon Sep 17 00:00:00 2001 From: liyang Date: Thu, 8 Aug 2024 21:02:25 +0800 Subject: [PATCH 113/126] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=9A=90=E7=A7=81?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E8=B1=81=E5=85=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyang --- .../screen_capture_adapter_impl_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/ohos_adapter/screen_capture_adapter_impl_test/screen_capture_adapter_impl_test.cpp b/test/unittest/ohos_adapter/screen_capture_adapter_impl_test/screen_capture_adapter_impl_test.cpp index 9f16b9e9..be15be85 100644 --- a/test/unittest/ohos_adapter/screen_capture_adapter_impl_test/screen_capture_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/screen_capture_adapter_impl_test/screen_capture_adapter_impl_test.cpp @@ -46,6 +46,7 @@ public: MOCK_METHOD1(SetMicrophoneEnabled, int32_t(bool)); MOCK_METHOD1(SetCanvasRotation, int32_t(bool)); MOCK_METHOD2(ResizeCanvas, int32_t(int32_t, int32_t)); + MOCK_METHOD1(SkipPrivacyMode, int32_t(std::vector&)); MOCK_METHOD0(StartScreenCapture, int32_t()); MOCK_METHOD1(StartScreenCaptureWithSurface, int32_t(sptr)); MOCK_METHOD0(StopScreenCapture, int32_t()); -- Gitee From 3353625b8dd4b3dc508126d0a5c121e628cfc072 Mon Sep 17 00:00:00 2001 From: h30059230 Date: Thu, 8 Aug 2024 20:23:06 +0800 Subject: [PATCH 114/126] =?UTF-8?q?Decription:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=99=BA=E6=85=A7=E5=B0=8F=E5=AD=A6app=E5=88=87=E5=88=B0?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=B2=A1=E6=9C=89=E5=A3=B0=E9=9F=B3=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20IssueNo:=20https://gitee.com/openharmony/w?= =?UTF-8?q?eb=5Fwebview/issues/IAITD5=3Ffrom=3Dproject-issue=20Feature=20o?= =?UTF-8?q?r=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: h30059230 --- .../src/media_avsession_adapter_impl.cpp | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/ohos_adapter/media_adapter/src/media_avsession_adapter_impl.cpp b/ohos_adapter/media_adapter/src/media_avsession_adapter_impl.cpp index d0e13a37..bfec063b 100644 --- a/ohos_adapter/media_adapter/src/media_avsession_adapter_impl.cpp +++ b/ohos_adapter/media_adapter/src/media_avsession_adapter_impl.cpp @@ -18,8 +18,13 @@ #include "ability_manager_client.h" #include "avsession_errors.h" #include "avsession_manager.h" +#include "bundle_mgr_proxy.h" #include "element_name.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" #include "nweb_log.h" +#include "parameters.h" +#include "system_ability_definition.h" namespace OHOS::NWeb { @@ -107,18 +112,55 @@ void MediaAVSessionCallbackImpl::OnCastDisplayChange( } void MediaAVSessionKey::Init() { - WVLOG_I("media avsession adapter Init in"); pid_ = getprocpid(); element_ = AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility(); - WVLOG_I("media avsession adapter Init AAFwk BundleName=%{public}s, AbilityName=%{public}s", - element_.GetBundleName().c_str(), element_.GetAbilityName().c_str()); auto context = AbilityRuntime::ApplicationContext::GetApplicationContext(); if (context) { element_.SetBundleName(context->GetBundleName()); - WVLOG_I("media avsession adapter Init context BundleName()=%{public}s", context->GetBundleName().c_str()); } type_ = MediaAVSessionType::MEDIA_TYPE_INVALID; - WVLOG_I("media avsession adapter Init out"); + + // SA application can get AbilityName by GetTopAbility, but others cannnot. + if (!element_.GetAbilityName().empty()){ + return; + } + + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + WVLOG_E("get SystemAbilityManager failed"); + return; + } + sptr remoteObject = + systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (remoteObject == nullptr) { + WVLOG_E("get Bundle Manager failed"); + return; + } + auto bundleMgr = iface_cast(remoteObject); + if (bundleMgr == nullptr) { + WVLOG_E("get Bundle Manager failed"); + return; + } + AppExecFwk::BundleInfo bundleInfo; + auto flag = (static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | + static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY)); + if (bundleMgr->GetBundleInfoForSelf(flag, bundleInfo) != 0) { + WVLOG_E("get bundle info failed"); + return; + } + auto hapModuleInfos = bundleInfo.hapModuleInfos; + if (hapModuleInfos.empty()) { + WVLOG_E("get hapModuleInfos failed"); + return; + } + auto abilityInfos = hapModuleInfos[0].abilityInfos; + if (abilityInfos.empty()) { + WVLOG_E("get abilityInfos failed"); + return; + } + element_.SetAbilityName(abilityInfos[0].name); + return; } int32_t MediaAVSessionKey::GetPID() { -- Gitee From 498243ad2a7c2ef4291ee2627a1aa494d8a17ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Sat, 10 Aug 2024 10:11:45 +0000 Subject: [PATCH 115/126] =?UTF-8?q?update=20ohos=5Fnweb/src/nweb=5Fhelper.?= =?UTF-8?q?cpp.=20=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97=E7=AD=89=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- ohos_nweb/src/nweb_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index c7d4c0d5..db85d222 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -139,7 +139,7 @@ void LoadNWebCApi(void *handle, NWebCApi *api) bool LoadNWebSDK(void *handle) { if (g_nwebCApi) { - WVLOG_E("LoadNWebSDK had loaded."); + WVLOG_I("LoadNWebSDK had loaded."); return true; } -- Gitee From 5f4db7144860ccc72d77bc163f4eb2f689b77a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Sat, 10 Aug 2024 18:56:24 +0800 Subject: [PATCH 116/126] fix fuzztest crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- .../aafwkbrowserhost_fuzzer.cpp | 7 - .../aafwkrenderscheduler_fuzzer.cpp | 5 - .../audiogetcontent_fuzzer.cpp | 27 ++- .../audiogetlatency_fuzzer.cpp | 18 +- .../audiointerrupt_fuzzer.cpp | 27 ++- .../cameramanageradapter_fuzzer/BUILD.gn | 68 ------ .../cameramanageradapter_fuzzer.cpp | 126 ------------ .../cameramanageradapter_fuzzer.h | 20 -- .../cameramanageradapter_fuzzer/corpus/init | 15 -- .../cameramanageradapter_fuzzer/project.xml | 25 --- .../BUILD.gn | 68 ------ .../corpus/init | 15 -- .../project.xml | 25 --- .../getcertmaxsize_fuzzer.cpp | 20 +- .../getusercertdata_fuzzer.cpp | 18 +- .../pmscreatedatabase_fuzzer.cpp | 2 +- .../event_handler_adapter_fuzzer.cpp | 4 +- .../flowbufferadapter_fuzzer/BUILD.gn | 6 +- .../flowbufferadapter_fuzzer.cpp} | 67 +++--- .../flowbufferadapter_fuzzer.h} | 10 +- .../bufferinfoadapterimpl_fuzzer.cpp | 16 +- .../capabilitydataadapterimpl_fuzzer.cpp | 15 +- .../codecformatadapterimpl_fuzzer.cpp | 11 +- .../mediaavsessionadapterimpl_fuzzer/BUILD.gn | 4 +- .../mediaavsessionadapterimpl_fuzzer.cpp | 4 +- .../mediaavsessionadapterimpl_fuzzer.h | 2 +- .../ohosbufferadapterimpl_fuzzer.cpp | 6 +- .../getdeviceids_fuzzer/BUILD.gn | 0 .../getdeviceids_fuzzer/corpus/init | 0 .../getdeviceids_fuzzer.cpp | 0 .../getdeviceids_fuzzer/getdeviceids_fuzzer.h | 0 .../getdeviceids_fuzzer/project.xml | 0 .../getkeyboardtype_fuzzer/BUILD.gn | 0 .../getkeyboardtype_fuzzer/corpus/init | 0 .../getkeyboardtype_fuzzer.cpp | 0 .../getkeyboardtype_fuzzer.h | 0 .../getkeyboardtype_fuzzer/project.xml | 0 .../ondeviceadded_fuzzer/BUILD.gn | 0 .../ondeviceadded_fuzzer/corpus/init | 0 .../ondeviceadded_fuzzer.cpp | 0 .../ondeviceadded_fuzzer.h | 0 .../ondeviceadded_fuzzer/project.xml | 0 .../ondeviceremoved_fuzzer/BUILD.gn | 0 .../ondeviceremoved_fuzzer/corpus/init | 0 .../ondeviceremoved_fuzzer.cpp | 0 .../ondeviceremoved_fuzzer.h | 0 .../ondeviceremoved_fuzzer/project.xml | 0 .../registerdevlistener_fuzzer/BUILD.gn | 0 .../registerdevlistener_fuzzer/corpus/init | 0 .../registerdevlistener_fuzzer/project.xml | 0 .../registerdevlistener_fuzzer.cpp | 0 .../registerdevlistener_fuzzer.h | 0 .../unregisterdevlistener_fuzzer/BUILD.gn | 0 .../unregisterdevlistener_fuzzer/corpus/init | 0 .../unregisterdevlistener_fuzzer/project.xml | 0 .../unregisterdevlistener_fuzzer.cpp | 0 .../unregisterdevlistener_fuzzer.h | 0 .../addhtmlrecord_fuzzer/BUILD.gn | 0 .../addhtmlrecord_fuzzer.cpp | 0 .../addhtmlrecord_fuzzer.h | 0 .../addhtmlrecord_fuzzer/corpus/init | 0 .../addhtmlrecord_fuzzer/project.xml | 0 .../clipboardtoimagealphatype_fuzzer/BUILD.gn | 0 .../clipboardtoimagealphatype_fuzzer.cpp | 0 .../clipboardtoimagealphatype_fuzzer.h | 0 .../corpus/init | 0 .../project.xml | 0 .../clipboardtoimagecolortype_fuzzer/BUILD.gn | 0 .../clipboardtoimagecolortype_fuzzer.cpp | 0 .../clipboardtoimagecolortype_fuzzer.h | 0 .../corpus/init | 0 .../project.xml | 0 .../getimgdata_fuzzer/BUILD.gn | 0 .../getimgdata_fuzzer/corpus/init | 0 .../getimgdata_fuzzer/getimgdata_fuzzer.h | 0 .../getimgdata_fuzzer/project.xml | 0 .../getmimetype_fuzzer/BUILD.gn | 0 .../getmimetype_fuzzer/corpus/init | 0 .../getmimetype_fuzzer/getmimetype_fuzzer.cpp | 0 .../getmimetype_fuzzer/getmimetype_fuzzer.h | 0 .../getmimetype_fuzzer/project.xml | 0 .../getrecordat_fuzzer/BUILD.gn | 0 .../getrecordat_fuzzer/corpus/init | 0 .../getrecordat_fuzzer/getrecordat_fuzzer.cpp | 0 .../getrecordat_fuzzer/getrecordat_fuzzer.h | 0 .../getrecordat_fuzzer/project.xml | 0 .../imagetoclipboardalphatype_fuzzer/BUILD.gn | 0 .../corpus/init | 0 .../imagetoclipboardalphatype_fuzzer.cpp | 8 + .../imagetoclipboardalphatype_fuzzer.h | 0 .../project.xml | 0 .../imagetoclipboardcolortype_fuzzer/BUILD.gn | 0 .../corpus/init | 0 .../imagetoclipboardcolortype_fuzzer.cpp | 0 .../imagetoclipboardcolortype_fuzzer.h | 0 .../project.xml | 0 .../onpasteboardchanged_fuzzer/BUILD.gn | 0 .../onpasteboardchanged_fuzzer/corpus/init | 0 .../onpasteboardchanged_fuzzer.cpp | 0 .../onpasteboardchanged_fuzzer.h | 0 .../onpasteboardchanged_fuzzer/project.xml | 0 .../openremoteuri_fuzzer/BUILD.gn | 0 .../openremoteuri_fuzzer/corpus/init | 0 .../openremoteuri_fuzzer.cpp | 0 .../openremoteuri_fuzzer.h | 0 .../openremoteuri_fuzzer/project.xml | 0 .../BUILD.gn | 0 .../corpus/init | 0 .../project.xml | 0 ...removepasteboardchangedobserver_fuzzer.cpp | 3 +- .../removepasteboardchangedobserver_fuzzer.h | 0 .../setcustomdata_fuzzer/BUILD.gn | 0 .../setcustomdata_fuzzer/corpus/init | 0 .../setcustomdata_fuzzer/project.xml | 0 .../setcustomdata_fuzzer.cpp | 0 .../setcustomdata_fuzzer.h | 0 .../sethtmltext_fuzzer/BUILD.gn | 0 .../sethtmltext_fuzzer/corpus/init | 0 .../sethtmltext_fuzzer/project.xml | 0 .../sethtmltext_fuzzer/sethtmltext_fuzzer.cpp | 0 .../sethtmltext_fuzzer/sethtmltext_fuzzer.h | 0 .../setplaintext_fuzzer/BUILD.gn | 0 .../setplaintext_fuzzer/corpus/init | 0 .../setplaintext_fuzzer/project.xml | 0 .../setplaintext_fuzzer.cpp | 0 .../setplaintext_fuzzer/setplaintext_fuzzer.h | 0 .../pasteboard_adapter/seturi_fuzzer/BUILD.gn | 0 .../seturi_fuzzer/corpus/init | 0 .../seturi_fuzzer/project.xml | 0 .../seturi_fuzzer/seturi_fuzzer.cpp | 0 .../seturi_fuzzer/seturi_fuzzer.h | 0 .../resschedadapter_fuzz.cpp | 194 +++++++++--------- .../applysocperfconfigbyid_fuzzer.cpp | 6 +- .../applysocperfconfigbyid_fuzzer.h | 0 .../applysocperfconfigbyid_fuzzer/corpus/init | 0 .../applysocperfconfigbyid_fuzzer/project.xml | 0 .../getnweb_fuzzer/getnweb_fuzzer.cpp | 6 +- 137 files changed, 230 insertions(+), 618 deletions(-) delete mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.cpp delete mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.h delete mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/corpus/init delete mode 100644 test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/project.xml delete mode 100644 test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/corpus/init delete mode 100644 test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/project.xml rename test/fuzztest/ohos_adapter/{camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.cpp => flowbufferadapter_fuzzer/flowbufferadapter_fuzzer.cpp} (32%) rename test/fuzztest/ohos_adapter/{camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.h => flowbufferadapter_fuzzer/flowbufferadapter_fuzzer.h} (68%) mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/getimgdata_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.h mode change 100755 => 100644 test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/corpus/init mode change 100755 => 100644 test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/project.xml diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.cpp b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.cpp index dfba6bcf..4cd27b0c 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkbrowserhost_fuzzer/aafwkbrowserhost_fuzzer.cpp @@ -47,15 +47,8 @@ bool AafwkBrowserHostFuzzTest(const uint8_t* data, size_t size) host->HandleReportThread(newdata, reply); host->HandlePassSurface(newdata, reply); host->HandleDestroyRenderSurface(newdata, reply); - host->QueryRenderSurface(surface_id); - int32_t status = 0; - int32_t process_id = 0; - int32_t thread_id = 0; - int32_t role = 0; sptr surface; - host->ReportThread(status, process_id, thread_id, role); host->PassSurface(surface, surface_id); - host->DestroyRenderSurface(surface_id); return true; } } // namespace OHOS diff --git a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.cpp b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.cpp index 73bde4f8..3d8f74a0 100644 --- a/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/aafwk_adapter/aafwkrenderscheduler_fuzzer/aafwkrenderscheduler_fuzzer.cpp @@ -55,11 +55,6 @@ bool AafwkRenderSchedulerFuzzTest(const uint8_t* data, size_t size) } render.NotifyBrowserFd(ipcFd, sharedFd, crashFd, nullptr); - std::shared_ptr newrender = std::make_shared(adapter); - - newrender->NotifyBrowserFd(ipcFd, sharedFd, crashFd, nullptr); - newrender->renderSchedulerHostAdapter_ = nullptr; - newrender->NotifyBrowserFd(ipcFd, sharedFd, crashFd, nullptr); return true; } } // namespace OHOS diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp b/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp index e3e981c3..8c829921 100644 --- a/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp @@ -17,22 +17,33 @@ #include #include +#include #include "audio_renderer_adapter_impl.h" using namespace OHOS::NWeb; namespace OHOS { - bool AudioGetContentFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - AudioRendererAdapterImpl adapter; - adapter.GetAudioContentType(AudioAdapterContentType::CONTENT_TYPE_SPEECH); - return true; +bool AudioGetContentFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::array contentArray = { + AudioAdapterContentType::CONTENT_TYPE_UNKNOWN, + AudioAdapterContentType::CONTENT_TYPE_SPEECH, + AudioAdapterContentType::CONTENT_TYPE_MUSIC, + AudioAdapterContentType::CONTENT_TYPE_MOVIE, + AudioAdapterContentType::CONTENT_TYPE_SONIFICATION, + AudioAdapterContentType::CONTENT_TYPE_RINGTONE, + }; + for (auto& content : contentArray) + AudioRendererAdapterImpl::GetAudioContentType(content); + + AudioRendererAdapterImpl::GetAudioContentType(static_cast(-1)); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiogetlatency_fuzzer/audiogetlatency_fuzzer.cpp b/test/fuzztest/ohos_adapter/audio_adapter/audiogetlatency_fuzzer/audiogetlatency_fuzzer.cpp index 6872df8d..c4955834 100644 --- a/test/fuzztest/ohos_adapter/audio_adapter/audiogetlatency_fuzzer/audiogetlatency_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiogetlatency_fuzzer/audiogetlatency_fuzzer.cpp @@ -23,17 +23,17 @@ using namespace OHOS::NWeb; namespace OHOS { - bool AudioGetLatencyFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - AudioRendererAdapterImpl adapter; - uint64_t latency = 0; - adapter.GetLatency(latency); - return true; +bool AudioGetLatencyFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr adapter = std::make_shared(); + uint64_t latency = 0; + adapter->GetLatency(latency); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiointerrupt_fuzzer/audiointerrupt_fuzzer.cpp b/test/fuzztest/ohos_adapter/audio_adapter/audiointerrupt_fuzzer/audiointerrupt_fuzzer.cpp index b451bdf7..523251f0 100644 --- a/test/fuzztest/ohos_adapter/audio_adapter/audiointerrupt_fuzzer/audiointerrupt_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiointerrupt_fuzzer/audiointerrupt_fuzzer.cpp @@ -24,18 +24,25 @@ using namespace OHOS::NWeb; namespace OHOS { - bool AudioInterruptFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return false; - } - std::shared_ptr cb = nullptr; - AudioManagerCallbackAdapterImpl adapter(cb); - InterruptAction interruptAction; - adapter.OnInterrupt(interruptAction); - return true; +bool AudioInterruptFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; } + std::shared_ptr cb = nullptr; + AudioManagerCallbackAdapterImpl adapter(cb); + InterruptAction interruptAction; + interruptAction.interruptHint = InterruptHint::INTERRUPT_HINT_PAUSE; + adapter.OnInterrupt(interruptAction); + interruptAction.interruptHint = InterruptHint::INTERRUPT_HINT_STOP; + adapter.OnInterrupt(interruptAction); + interruptAction.interruptHint = InterruptHint::INTERRUPT_HINT_RESUME; + adapter.OnInterrupt(interruptAction); + interruptAction.interruptHint = static_cast(-1); + adapter.OnInterrupt(interruptAction); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/BUILD.gn deleted file mode 100644 index efa9c65a..00000000 --- a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +0,0 @@ -# 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. - -#####################hydra-fuzz################### -import("//base/web/webview/web_aafwk.gni") -import("//build/config/features.gni") -import("//build/test.gni") - -##############################fuzztest########################################## -ohos_fuzztest("CameraManagerAdapterFuzzTest") { - module_out_path = webview_fuzz_test_path - fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer" - include_dirs = [ - "$webview_path/ohos_adapter/camera_adapter/include", - "$webview_path/ohos_adapter/camera_adapter/src", - "$webview_path/test/fuzztest", - ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "cameramanageradapter_fuzzer.cpp" ] - - defines = [ "NWEB_CAMERA_ENABLE" ] - - deps = [ - "$webview_path/ohos_adapter:nweb_ohos_adapter", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "camera_framework:camera_framework", - "drivers_interface_camera:metadata", - "graphic_2d:librender_service_client", - "hilog:libhilog", - "init:libbegetutil", - "ipc:ipc_core", - "webview:libnweb", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [] - deps += [ - # deps file - ":CameraManagerAdapterFuzzTest", - ] -} -############################################################################### diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.cpp deleted file mode 100644 index 27726395..00000000 --- a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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 "cameramanageradapter_fuzzer.h" -#define CAMERA_MANAGER_ADAPTER_IMPL -#define private public -#include "camera_device.h" -#include "camera_manager.h" -#include "camera_manager_adapter_impl.cpp" -#include "camera_manager_adapter_impl.h" -#include "nweb_surface_adapter.h" - -using namespace OHOS::NWeb; - -namespace OHOS { -class CameraStatusCallbackAdapterMock : public CameraStatusCallbackAdapter { -public: - CameraStatusCallbackAdapterMock() {} - ~CameraStatusCallbackAdapterMock() override = default; - - void OnCameraStatusChanged(NWeb::CameraStatusAdapter cameraStatusAdapter, std::string callBackDeviceId) override {} -}; - -class CameraBufferListenerAdapterMock : public CameraBufferListenerAdapter { -public: - CameraBufferListenerAdapterMock() {} - ~CameraBufferListenerAdapterMock() override = default; - - void OnBufferAvailable(std::shared_ptr surface, - std::shared_ptr buffer, - std::shared_ptr rotationInfo) override - {} -}; - -class VideoCaptureParamsAdapterMock : public VideoCaptureParamsAdapter { -public: - VideoCaptureParamsAdapterMock() = default; - - uint32_t GetWidth() override - { - return width; - } - - uint32_t GetHeight() override - { - return height; - } - - float GetFrameRate() override - { - return frameRate; - } - - VideoPixelFormatAdapter GetPixelFormat() override - { - return pixelFormat; - } - - bool GetEnableFaceDetection() override - { - return enableFaceDetection; - } - - uint32_t width; - uint32_t height; - float frameRate; - VideoPixelFormatAdapter pixelFormat; - bool enableFaceDetection; -}; - -bool CameraManagerAdapterFuzzTest(const uint8_t* data, size_t size) -{ - const std::string deviceId((const char*)data, size); - bool ForegroundFlag = static_cast(data[0]); - auto callback = std::make_shared(); - auto listenerAdapter = std::make_shared(); - std::shared_ptr captureParams = std::make_shared(); - CameraManagerAdapterImpl& adapter = CameraManagerAdapterImpl::GetInstance(); - int32_t result = CameraManagerAdapterImpl::GetInstance().Create(callback); - result = CameraManagerAdapterImpl::GetInstance().Create(callback); - - adapter.Create(callback); - std::vector> devicesDiscriptor = adapter.GetDevicesInfo(); - std::vector exposureModesAdapter; - result = adapter.GetExposureModes(exposureModesAdapter); - ExposureModeAdapter exposureModeAdapter; - result = adapter.GetCurrentExposureMode(exposureModeAdapter); - std::shared_ptr rangeVal = adapter.GetExposureCompensation(); - rangeVal = nullptr; - rangeVal = adapter.GetCaptionRangeById(RangeIDAdapter::RANGE_ID_EXP_COMPENSATION); - adapter.GetCurrentFocusMode(); - adapter.IsFocusModeSupported(FocusModeAdapter::FOCUS_MODE_CONTINUOUS_AUTO); - adapter.IsFlashModeSupported(FlashModeAdapter::FLASH_MODE_OPEN); - adapter.RestartSession(); - adapter.StopSession(CameraStopType::NORMAL); - adapter.ReleaseCameraManger(); - adapter.GetCameraStatus(); - adapter.SetCameraStatus(static_cast(-1)); - adapter.GetCurrentDeviceId(); - adapter.IsExistCaptureTask(); - adapter.SetForegroundFlag(ForegroundFlag); - adapter.StartStream(deviceId, captureParams, listenerAdapter); - - return true; -} -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::CameraManagerAdapterFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.h b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.h deleted file mode 100644 index ece410e1..00000000 --- a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/cameramanageradapter_fuzzer.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H -#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H - -#define FUZZ_PROJECT_NAME "cameramanageradapter_fuzzer" -#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/corpus/init deleted file mode 100644 index 6248ced8..00000000 --- a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/corpus/init +++ /dev/null @@ -1,15 +0,0 @@ -/* - * 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. - */ -FUZZ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/project.xml deleted file mode 100644 index 7133b2b9..00000000 --- a/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/BUILD.gn deleted file mode 100644 index 00ec9109..00000000 --- a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +0,0 @@ -# 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. - -#####################hydra-fuzz################### -import("//base/web/webview/web_aafwk.gni") -import("//build/config/features.gni") -import("//build/test.gni") - -##############################fuzztest########################################## -ohos_fuzztest("CameraSurfaceBufferAdapterFuzzTest") { - module_out_path = webview_fuzz_test_path - fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer" - include_dirs = [ - "$webview_path/ohos_adapter/camera_adapter/include", - "$webview_path/ohos_adapter/camera_adapter/src", - "$webview_path/test/fuzztest", - ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "camerasurfacebufferadapter_fuzzer.cpp" ] - - deps = [ - "$webview_path/ohos_adapter:nweb_ohos_adapter", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - - defines = [ "NWEB_CAMERA_ENABLE" ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "camera_framework:camera_framework", - "drivers_interface_camera:metadata", - "graphic_2d:librender_service_client", - "hilog:libhilog", - "init:libbegetutil", - "ipc:ipc_core", - "webview:libnweb", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [] - deps += [ - # deps file - ":CameraSurfaceBufferAdapterFuzzTest", - ] -} -############################################################################### diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/corpus/init deleted file mode 100644 index 6248ced8..00000000 --- a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/corpus/init +++ /dev/null @@ -1,15 +0,0 @@ -/* - * 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. - */ -FUZZ diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/project.xml b/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/project.xml deleted file mode 100644 index 7133b2b9..00000000 --- a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/ohos_adapter/cert_mgr_adapter/getcertmaxsize_fuzzer/getcertmaxsize_fuzzer.cpp b/test/fuzztest/ohos_adapter/cert_mgr_adapter/getcertmaxsize_fuzzer/getcertmaxsize_fuzzer.cpp index b46b09cc..aeb944ff 100644 --- a/test/fuzztest/ohos_adapter/cert_mgr_adapter/getcertmaxsize_fuzzer/getcertmaxsize_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/cert_mgr_adapter/getcertmaxsize_fuzzer/getcertmaxsize_fuzzer.cpp @@ -20,18 +20,18 @@ using namespace OHOS::NWeb; namespace OHOS { - bool GetCertMaxSizeFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size <= 0)) { - return false; - } - CertManagerAdapterImpl cerImpl; - cerImpl.GetCertMaxSize(); - cerImpl.GetAppCertMaxSize(); - cerImpl.GetSytemRootCertData(0, const_cast(data)); - return true; +bool GetCertMaxSizeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return false; } + CertManagerAdapterImpl cerImpl; + cerImpl.GetCertMaxSize(); + cerImpl.GetAppCertMaxSize(); + cerImpl.GetSytemRootCertData(0, const_cast(data)); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/cert_mgr_adapter/getusercertdata_fuzzer/getusercertdata_fuzzer.cpp b/test/fuzztest/ohos_adapter/cert_mgr_adapter/getusercertdata_fuzzer/getusercertdata_fuzzer.cpp index 0369bafc..fe6ff389 100644 --- a/test/fuzztest/ohos_adapter/cert_mgr_adapter/getusercertdata_fuzzer/getusercertdata_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/cert_mgr_adapter/getusercertdata_fuzzer/getusercertdata_fuzzer.cpp @@ -20,17 +20,17 @@ using namespace OHOS::NWeb; namespace OHOS { - bool GetUserCertDataFuzzTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size <= 0)) { - return false; - } - CertManagerAdapterImpl cerImpl; - uint32_t certSum = cerImpl.GetUserRootCertSum(); - cerImpl.GetUserRootCertData(certSum, const_cast(data)); - return true; +bool GetUserCertDataFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return false; } + CertManagerAdapterImpl cerImpl; + uint32_t certSum = cerImpl.GetUserRootCertSum(); + cerImpl.GetUserRootCertData(certSum, const_cast(data)); + return true; } +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/test/fuzztest/ohos_adapter/distributeddatamgr_adapter/webdatabase/pmscreatedatabase_fuzzer/pmscreatedatabase_fuzzer.cpp b/test/fuzztest/ohos_adapter/distributeddatamgr_adapter/webdatabase/pmscreatedatabase_fuzzer/pmscreatedatabase_fuzzer.cpp index 481eca1d..6c36c4dc 100644 --- a/test/fuzztest/ohos_adapter/distributeddatamgr_adapter/webdatabase/pmscreatedatabase_fuzzer/pmscreatedatabase_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/distributeddatamgr_adapter/webdatabase/pmscreatedatabase_fuzzer/pmscreatedatabase_fuzzer.cpp @@ -29,7 +29,7 @@ bool PmsCreateDataBaseFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size == 0)) { return false; } - std::string dataBeseName((const char*)data, size); + std::string dataBeseName(reinterpret_cast(data), size); PermissionDataBaseRdbOpenCallBack callBack; OhosWebPermissionDataBaseAdapterImpl dataBase; dataBase.CreateDataBase(dataBeseName, callBack); diff --git a/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.cpp index 6756db3c..675cd50e 100644 --- a/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/eventhandler_fuzzer/event_handler_adapter_fuzzer.cpp @@ -31,8 +31,8 @@ public: bool EventHandlerAdapterFuzzTest(const uint8_t* data, size_t size) { - int32_t fileDescriptor = *reinterpret_cast(data); - uint32_t events = *reinterpret_cast(data + sizeof(int32_t)); + int32_t fileDescriptor = static_cast(size); + uint32_t events = static_cast(size); std::shared_ptr listener = std::make_shared(); diff --git a/test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/BUILD.gn index e0162fe9..bc986fc2 100644 --- a/test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("//build/test.gni") import("$webview_path/config.gni") ##############################fuzztest########################################## -ohos_fuzztest("FlowBufferAdapterImplFuzzTest") { +ohos_fuzztest("FlowBufferAdapterFuzzTest") { module_out_path = webview_fuzz_test_path fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer" @@ -33,7 +33,7 @@ ohos_fuzztest("FlowBufferAdapterImplFuzzTest") { "-Wno-unused-variable", "-fno-omit-frame-pointer", ] - sources = [ "flowbufferadapterimpl_fuzzer.cpp" ] + sources = [ "flowbufferadapter_fuzzer.cpp" ] deps = [ "$webview_path/ohos_adapter:nweb_ohos_adapter", "$webview_path/ohos_nweb:libnweb", @@ -51,7 +51,7 @@ group("fuzztest") { deps = [] deps += [ # deps file - ":FlowBufferAdapterImplFuzzTest", + ":FlowBufferAdapterFuzzTest", ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.cpp b/test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/flowbufferadapter_fuzzer.cpp similarity index 32% rename from test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.cpp rename to test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/flowbufferadapter_fuzzer.cpp index 616a8ddb..914b2b77 100644 --- a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/flowbufferadapter_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -13,48 +13,37 @@ * limitations under the License. */ -#include "camerasurfacebufferadapter_fuzzer.h" -#define CAMERA_MANAGER_ADAPTER_IMPL -#include "camera_manager_adapter_impl.cpp" -#include "camera_manager_adapter_impl.h" -#include "nweb_surface_adapter.h" +#include "flowbufferadapter_fuzzer.h" -using namespace OHOS::NWeb; - -namespace OHOS { +#include +#include -class CameraBufferListenerAdapterMock : public CameraBufferListenerAdapter { -public: - CameraBufferListenerAdapterMock() {} - ~CameraBufferListenerAdapterMock() override = default; +#include "ohos_adapter_helper.h" +#define private public +#include "flowbuffer_adapter_impl.h" - void OnBufferAvailable(std::shared_ptr surface, - std::shared_ptr buffer, - std::shared_ptr rotationInfo) override - {} -}; +using namespace OHOS::NWeb; -bool CameraSurfaceBufferAdapterFuzzTest(const uint8_t* data, size_t size) +namespace OHOS { +bool FlowBufferAdapterFuzzTest(const uint8_t* data, size_t size) { - sptr surface = IConsumerSurface::Create(); - auto listenerAdapter = std::make_shared(); - auto listener = std::make_shared(SurfaceType::PREVIEW, surface, listenerAdapter); - listener->OnBufferAvailable(); - - auto listenerSurfaceAdapter = std::make_shared(surface); - listenerSurfaceAdapter->ReleaseBuffer(nullptr, -1); - NWebSurfaceAdapter::Instance(); - - auto adapterImpl = std::make_shared(nullptr); - int32_t result = adapterImpl->GetFileDescriptor(); - result = adapterImpl->GetWidth(); - result = adapterImpl->GetHeight(); - result = adapterImpl->GetStride(); - result = adapterImpl->GetFormat(); - adapterImpl->GetSize(); - sptr buffer = adapterImpl->GetBuffer(); - adapterImpl->GetBufferAddr(); - + if ((data == nullptr) || (size < sizeof(int32_t))) { + return false; + } + auto flowbufferAdapter = OhosAdapterHelper::GetInstance().CreateFlowbufferAdapter(); + int fd = 0; + size_t scriptLength = 10; + auto ashmem = flowbufferAdapter->CreateAshmem(scriptLength, PROT_READ | PROT_WRITE, fd); + (void)ashmem; + flowbufferAdapter->StartPerformanceBoost(); + + auto flowbufferAdapter1 = OhosAdapterHelper::GetInstance().CreateFlowbufferAdapter(); + int fd1; + size_t scriptLength1 = 10; + flowbufferAdapter1->CreateAshmem(scriptLength1, PROT_READ | PROT_WRITE, fd1); + auto ashmem1 = flowbufferAdapter->CreateAshmemWithFd(fd1, scriptLength1, PROT_READ); + (void)ashmem1; + flowbufferAdapter1->StartPerformanceBoost(); return true; } } // namespace OHOS @@ -63,6 +52,6 @@ bool CameraSurfaceBufferAdapterFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::CameraSurfaceBufferAdapterFuzzTest(data, size); + OHOS::FlowBufferAdapterFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.h b/test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/flowbufferadapter_fuzzer.h similarity index 68% rename from test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.h rename to test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/flowbufferadapter_fuzzer.h index da6d9006..5e8da15f 100644 --- a/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer/camerasurfacebufferadapter_fuzzer.h +++ b/test/fuzztest/ohos_adapter/flowbufferadapter_fuzzer/flowbufferadapter_fuzzer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H -#define TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H +#ifndef TEST_FUZZTEST_FLOWBUFFERADAPTERIMPL_FUZZER_H +#define TEST_FUZZTEST_FLOWBUFFERADAPTERIMPL_FUZZER_H -#define FUZZ_PROJECT_NAME "camerasurfacebufferadapter_fuzzer" -#endif /* TEST_FUZZTEST_GETCERTMASIZE_FUZZER_H */ +#define FUZZ_PROJECT_NAME "flowbufferadapter_fuzzer" +#endif /* TEST_FUZZTEST_FLOWBUFFERADAPTERIMPL_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.cpp index 57f70ebf..088ec625 100644 --- a/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/media_adapter/bufferinfoadapterimpl_fuzzer/bufferinfoadapterimpl_fuzzer.cpp @@ -28,18 +28,10 @@ bool BufferInfoAdapterImplFuzzTest(const uint8_t* data, size_t size) return false; } OHOS::NWeb::BufferInfoAdapterImpl bufferInfoAdapterImpl; - int64_t time; - int32_t usesize; - int32_t offset; - if (memcpy_s(&time, sizeof(int64_t), data, sizeof(int64_t)) != 0) { - return true; - } - if (memcpy_s(&usesize, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return true; - } - if (memcpy_s(&offset, sizeof(int64_t), data, sizeof(int64_t)) != 0) { - return true; - } + int64_t time = 1; + int32_t usesize = static_cast(size); + int32_t offset = static_cast(size); + bufferInfoAdapterImpl.SetPresentationTimeUs(time); bufferInfoAdapterImpl.SetSize(usesize); bufferInfoAdapterImpl.SetOffset(offset); diff --git a/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.cpp index 602f6092..80d96a4c 100644 --- a/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/media_adapter/capabilitydataadapterimpl_fuzzer/capabilitydataadapterimpl_fuzzer.cpp @@ -29,18 +29,9 @@ bool CapabilityDataAdapterImplFuzzTest(const uint8_t* data, size_t size) } OHOS::NWeb::CapabilityDataAdapterImpl capabilityDataAdapter; - int32_t width; - int32_t height; - int32_t frameRate; - if (memcpy_s(&width, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return true; - } - if (memcpy_s(&height, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return true; - } - if (memcpy_s(&frameRate, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return true; - } + int32_t width = static_cast(size); + int32_t height = static_cast(size); + int32_t frameRate = static_cast(size); capabilityDataAdapter.SetMaxWidth(width); capabilityDataAdapter.SetMaxHeight(height); diff --git a/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.cpp index 2a9bbf95..3c51c871 100644 --- a/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/media_adapter/codecformatadapterimpl_fuzzer/codecformatadapterimpl_fuzzer.cpp @@ -28,14 +28,9 @@ bool CreateLocationProxyAdapterFuzzTest(const uint8_t* data, size_t size) return false; } OHOS::NWeb::CodecFormatAdapterImpl codecFormatAdapter; - int32_t width; - int32_t height; - if (memcpy_s(&width, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return true; - } - if (memcpy_s(&height, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return true; - } + int32_t width = static_cast(size); + int32_t height = static_cast(size); + codecFormatAdapter.SetWidth(width); codecFormatAdapter.SetHeight(height); diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/BUILD.gn index 625e9469..a62769cb 100644 --- a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/BUILD.gn @@ -17,7 +17,7 @@ import("//build/config/features.gni") import("//build/test.gni") ##############################fuzztest########################################## -ohos_fuzztest("MediaAVSessionCallbackImplFuzzTest") { +ohos_fuzztest("MediaAVSessionAdapterImplFuzzTest") { module_out_path = webview_fuzz_test_path fuzz_config_file = "$webview_path/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer" include_dirs = [ @@ -59,7 +59,7 @@ group("fuzztest") { deps = [] deps += [ # deps file - ":MediaAVSessionCallbackImplFuzzTest", + ":MediaAVSessionAdapterImplFuzzTest", ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.cpp index 1452fd31..91596398 100644 --- a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.cpp @@ -35,7 +35,7 @@ public: void SeekTo(int64_t millisTime) {}; }; -bool MediaAVSessionCallbackImplFuzzTest(const uint8_t* data, size_t size) +bool MediaAVSessionAdapterImplFuzzTest(const uint8_t* data, size_t size) { std::shared_ptr mediaAvSessionCB; std::shared_ptr callbackImpl = @@ -80,6 +80,6 @@ bool MediaAVSessionCallbackImplFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::MediaAVSessionCallbackImplFuzzTest(data, size); + OHOS::MediaAVSessionAdapterImplFuzzTest(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.h b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.h index fc7eb20e..ddb249c0 100644 --- a/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.h +++ b/test/fuzztest/ohos_adapter/media_adapter/mediaavsessionadapterimpl_fuzzer/mediaavsessionadapterimpl_fuzzer.h @@ -16,5 +16,5 @@ #ifndef TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H #define TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H -#define FUZZ_PROJECT_NAME "codecformatadapterimpl_fuzzer" +#define FUZZ_PROJECT_NAME "mediaavsessionadapterimpl_fuzzer" #endif /* TEST_FUZZTEST_ADDHTMLRECORD_FUZZER_H */ diff --git a/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.cpp b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.cpp index 801da421..dd220954 100644 --- a/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/media_adapter/ohosbufferadapterimpl_fuzzer/ohosbufferadapterimpl_fuzzer.cpp @@ -30,11 +30,7 @@ bool OhosBufferAdapterImplFuzzTest(const uint8_t* data, size_t size) OHOS::NWeb::OhosBufferAdapterImpl ohosBufferAdapterImpl; uint8_t* addr = const_cast(data); - uint32_t bufferSize; - - if (memcpy_s(&bufferSize, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return true; - } + uint32_t bufferSize = static_cast(size); ohosBufferAdapterImpl.SetAddr(addr); diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/getdeviceids_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/project.xml b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getdeviceids_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/getkeyboardtype_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/project.xml b/test/fuzztest/ohos_adapter/multimodalinput_adapter/getkeyboardtype_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/ondeviceadded_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/project.xml b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceadded_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/ondeviceremoved_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/project.xml b/test/fuzztest/ohos_adapter/multimodalinput_adapter/ondeviceremoved_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/project.xml b/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/registerdevlistener_fuzzer/registerdevlistener_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/project.xml b/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.cpp b/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.h b/test/fuzztest/ohos_adapter/multimodalinput_adapter/unregisterdevlistener_fuzzer/unregisterdevlistener_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/addhtmlrecord_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/addhtmlrecord_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/clipboardtoimagealphatype_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagealphatype_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/clipboardtoimagecolortype_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/clipboardtoimagecolortype_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/getimgdata_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/getimgdata_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/getimgdata_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/getmimetype_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/getmimetype_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/getrecordat_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/getrecordat_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.cpp old mode 100755 new mode 100644 index 1b8c07d7..4acc8f99 --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.cpp @@ -19,6 +19,7 @@ #undef private using namespace OHOS::NWeb; +using namespace OHOS::Media; namespace OHOS { bool ImageToClipboardAlphaTypeFuzzTest(const uint8_t* data, size_t size) @@ -29,6 +30,13 @@ bool ImageToClipboardAlphaTypeFuzzTest(const uint8_t* data, size_t size) std::shared_ptr dataRecordAdapterImpl = std::make_shared("pixelMap"); Media::ImageInfo imgInfo; + imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN; + dataRecordAdapterImpl->ImageToClipboardAlphaType(imgInfo); + imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; + dataRecordAdapterImpl->ImageToClipboardAlphaType(imgInfo); + imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL; + dataRecordAdapterImpl->ImageToClipboardAlphaType(imgInfo); + imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL; dataRecordAdapterImpl->ImageToClipboardAlphaType(imgInfo); return true; } diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/imagetoclipboardalphatype_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardalphatype_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/imagetoclipboardcolortype_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/imagetoclipboardcolortype_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/onpasteboardchanged_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/onpasteboardchanged_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/openremoteuri_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/openremoteuri_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.cpp old mode 100755 new mode 100644 index ba80ae3f..151f158f --- a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.cpp @@ -30,7 +30,8 @@ bool RemovePasteboardChangedObserverFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size == 0)) { return false; } - PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(-1); + int32_t callbackId = static_cast(size); + PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(callbackId); return true; } } // namespace OHOS diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/removepasteboardchangedobserver_fuzzer/removepasteboardchangedobserver_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/setcustomdata_fuzzer/setcustomdata_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/sethtmltext_fuzzer/sethtmltext_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/setplaintext_fuzzer/setplaintext_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/project.xml b/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.cpp b/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.cpp old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.h b/test/fuzztest/ohos_adapter/pasteboard_adapter/seturi_fuzzer/seturi_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp index 80261dc0..f0fd7a7a 100644 --- a/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp +++ b/test/fuzztest/ohos_adapter/resschedadapter_fuzzer/resschedadapter_fuzz.cpp @@ -1,97 +1,97 @@ -/* - * 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 "resschedadapter_fuzz.h" - -#include -#include -#include -#include -#include -#include - -#include "res_sched_client_adapter.h" - -using namespace OHOS::NWeb; - -namespace OHOS { -namespace NWeb { - -bool ResSchedAdapterFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return false; - } - - pid_t pid = static_cast(data[0] % 1000); - pid_t tid = static_cast(data[1] % 1000); - int32_t nwebId = static_cast(data[2] % 10); - uint32_t windowId = static_cast(data[3] % 1000); - - std::vector statuses = { ResSchedStatusAdapter::WEB_ACTIVE, - ResSchedStatusAdapter::WEB_INACTIVE, ResSchedStatusAdapter::THREAD_CREATED, - ResSchedStatusAdapter::THREAD_DESTROYED, ResSchedStatusAdapter::VIDEO_PLAYING_START, - ResSchedStatusAdapter::VIDEO_PLAYING_STOP, ResSchedStatusAdapter::SCREEN_CAPTURE_START, - ResSchedStatusAdapter::SCREEN_CAPTURE_STOP, ResSchedStatusAdapter::AUDIO_STATUS_START, - ResSchedStatusAdapter::AUDIO_STATUS_STOP, ResSchedStatusAdapter::WEB_SCENE_ENTER, - ResSchedStatusAdapter::WEB_SCENE_EXIT }; - - std::vector roles = { ResSchedRoleAdapter::USER_INTERACT, ResSchedRoleAdapter::NORMAL_DISPLAY, - ResSchedRoleAdapter::IMPORTANT_DISPLAY, ResSchedRoleAdapter::NORMAL_AUDIO, ResSchedRoleAdapter::IMPORTANT_AUDIO, - ResSchedRoleAdapter::IMAGE_DECODE }; - - ResSchedClientAdapter adapter; - - for (auto status : statuses) { - adapter.ReportVideoPlaying(status, pid); - adapter.ReportScreenCapture(status, pid); - adapter.ReportRenderProcessStatus(status, pid); - adapter.ReportNWebInit(status, nwebId); - adapter.ReportWindowId(windowId, nwebId); - - for (auto role : roles) { - adapter.ReportKeyThread(status, pid, tid, role); - } - - adapter.ReportAudioData(status, pid, tid); - adapter.ReportProcessInUse(pid); - adapter.ReportSiteIsolationMode(true); - adapter.ReportWindowStatus(status, pid, windowId, nwebId); - adapter.ReportScene(status, ResSchedSceneAdapter::CLICK, nwebId); - adapter.ReportScene(status, ResSchedSceneAdapter::LOAD_URL, nwebId); - } - - adapter.ReportProcessInUse(0); - adapter.ReportWindowId(0, nwebId); - adapter.ReportKeyThread(statuses[0], pid, tid, static_cast(-1)); - adapter.ReportAudioData(statuses[0], pid, 0); - adapter.ReportSiteIsolationMode(true); - - adapter.ReportWindowId(0, nwebId); - adapter.ReportKeyThread(statuses[0], -1, tid, ResSchedRoleAdapter::USER_INTERACT); - adapter.ReportAudioData(statuses[0], pid, -1); - adapter.ReportWindowStatus(statuses[0], pid, windowId, -1); - adapter.ReportNWebInit(ResSchedStatusAdapter::WEB_SCENE_EXIT, -1); - - return true; -} -} // namespace NWeb -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - OHOS::NWeb::ResSchedAdapterFuzzTest(data, size); - return 0; -} +/* + * 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 "resschedadapter_fuzz.h" + +#include +#include +#include +#include +#include +#include + +#include "res_sched_client_adapter.h" + +using namespace OHOS::NWeb; + +namespace OHOS { +namespace NWeb { + +bool ResSchedAdapterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + + pid_t pid = 1; + pid_t tid = 1; + int32_t nwebId = static_cast(size); + uint32_t windowId = static_cast(size); + + std::vector statuses = { ResSchedStatusAdapter::WEB_ACTIVE, + ResSchedStatusAdapter::WEB_INACTIVE, ResSchedStatusAdapter::THREAD_CREATED, + ResSchedStatusAdapter::THREAD_DESTROYED, ResSchedStatusAdapter::VIDEO_PLAYING_START, + ResSchedStatusAdapter::VIDEO_PLAYING_STOP, ResSchedStatusAdapter::SCREEN_CAPTURE_START, + ResSchedStatusAdapter::SCREEN_CAPTURE_STOP, ResSchedStatusAdapter::AUDIO_STATUS_START, + ResSchedStatusAdapter::AUDIO_STATUS_STOP, ResSchedStatusAdapter::WEB_SCENE_ENTER, + ResSchedStatusAdapter::WEB_SCENE_EXIT }; + + std::vector roles = { ResSchedRoleAdapter::USER_INTERACT, ResSchedRoleAdapter::NORMAL_DISPLAY, + ResSchedRoleAdapter::IMPORTANT_DISPLAY, ResSchedRoleAdapter::NORMAL_AUDIO, ResSchedRoleAdapter::IMPORTANT_AUDIO, + ResSchedRoleAdapter::IMAGE_DECODE }; + + ResSchedClientAdapter adapter; + + for (auto status : statuses) { + adapter.ReportVideoPlaying(status, pid); + adapter.ReportScreenCapture(status, pid); + adapter.ReportRenderProcessStatus(status, pid); + adapter.ReportNWebInit(status, nwebId); + adapter.ReportWindowId(windowId, nwebId); + + for (auto role : roles) { + adapter.ReportKeyThread(status, pid, tid, role); + } + + adapter.ReportAudioData(status, pid, tid); + adapter.ReportProcessInUse(pid); + adapter.ReportSiteIsolationMode(true); + adapter.ReportWindowStatus(status, pid, windowId, nwebId); + adapter.ReportScene(status, ResSchedSceneAdapter::CLICK, nwebId); + adapter.ReportScene(status, ResSchedSceneAdapter::LOAD_URL, nwebId); + } + + adapter.ReportProcessInUse(0); + adapter.ReportWindowId(0, nwebId); + adapter.ReportKeyThread(statuses[0], pid, tid, static_cast(-1)); + adapter.ReportAudioData(statuses[0], pid, 0); + adapter.ReportSiteIsolationMode(true); + + adapter.ReportWindowId(0, nwebId); + adapter.ReportKeyThread(statuses[0], -1, tid, ResSchedRoleAdapter::USER_INTERACT); + adapter.ReportAudioData(statuses[0], pid, -1); + adapter.ReportWindowStatus(statuses[0], pid, windowId, -1); + adapter.ReportNWebInit(ResSchedStatusAdapter::WEB_SCENE_EXIT, -1); + + return true; +} +} // namespace NWeb +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::NWeb::ResSchedAdapterFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.cpp b/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.cpp old mode 100755 new mode 100644 index bba362b5..30e29fe5 --- a/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.cpp @@ -27,10 +27,8 @@ bool ApplySocPerfConfigByIdFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size < sizeof(int32_t))) { return false; } - int32_t id; - if (memcpy_s(&id, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return false; - } + int32_t id = static_cast(size); + SocPerfClientAdapterImpl perfClientAdapterImpl; perfClientAdapterImpl.ApplySocPerfConfigById(id); return true; diff --git a/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.h b/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/applysocperfconfigbyid_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/corpus/init b/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/project.xml b/test/fuzztest/ohos_adapter/soc_perf_adapter/applysocperfconfigbyid_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.cpp b/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.cpp index ce44dfc0..d330b430 100644 --- a/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.cpp +++ b/test/fuzztest/ohos_nweb/getnweb_fuzzer/getnweb_fuzzer.cpp @@ -25,10 +25,8 @@ using namespace OHOS::NWeb; namespace OHOS { bool GetNwebFuzzTest(const uint8_t* data, size_t size) { - int32_t nweb_id; - if (memcpy_s(&nweb_id, sizeof(int32_t), data, sizeof(int32_t)) != 0) { - return false; - } + int32_t nweb_id = static_cast(size); + NWebHelper::Instance().GetNWeb(nweb_id); NWebHelper::Instance().SetWebTag(nweb_id, "NWeb"); -- Gitee From a2a1b8ad5664d47ecb2d5f6289d0ecfe419a5326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Sat, 10 Aug 2024 19:07:33 +0800 Subject: [PATCH 117/126] fix fuzztest crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- .../audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp b/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp index 8c829921..3e6e724b 100644 --- a/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp @@ -29,7 +29,8 @@ bool AudioGetContentFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size == 0)) { return false; } - std::array contentArray = { + int typenums = 6; + std::array contentArray = { AudioAdapterContentType::CONTENT_TYPE_UNKNOWN, AudioAdapterContentType::CONTENT_TYPE_SPEECH, AudioAdapterContentType::CONTENT_TYPE_MUSIC, -- Gitee From 45dcc5348a0dacb9758f4db18f87135375d1332e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Sat, 10 Aug 2024 19:18:58 +0800 Subject: [PATCH 118/126] fix fuzztest crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- bundle.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/bundle.json b/bundle.json index 45a7a03c..2ad4ee67 100644 --- a/bundle.json +++ b/bundle.json @@ -165,8 +165,6 @@ "//base/web/webview/test/fuzztest/ontouchrelease_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/registerarkjsfunction_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/zoom_fuzzer:fuzztest", - "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/cameramanageradapter_fuzzer:fuzztest", - "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/camerasurfacebufferadapter_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/formatadapter_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/videocapturerangeadapter_fuzzer:fuzztest", "//base/web/webview/test/fuzztest/ohos_adapter/camera_adapter/videocontrolsupportadapter_fuzzer:fuzztest", -- Gitee From 71dcac035c663c32176d4019fc49e31ef7e8fcb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Sat, 10 Aug 2024 20:09:05 +0800 Subject: [PATCH 119/126] fix fuzztest crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- .vscode/settings.json | 5 +++++ .../audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..889b02bd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "array": "cpp" + } +} \ No newline at end of file diff --git a/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp b/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp index 3e6e724b..ff45795d 100644 --- a/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp +++ b/test/fuzztest/ohos_adapter/audio_adapter/audiogetcontent_fuzzer/audiogetcontent_fuzzer.cpp @@ -29,7 +29,7 @@ bool AudioGetContentFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size == 0)) { return false; } - int typenums = 6; + constexpr int typenums = 6; std::array contentArray = { AudioAdapterContentType::CONTENT_TYPE_UNKNOWN, AudioAdapterContentType::CONTENT_TYPE_SPEECH, -- Gitee From 105ca6a088ea6c7aa35c5057539ef186c326256f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E4=BA=91=E5=B8=86?= Date: Sat, 10 Aug 2024 20:15:51 +0800 Subject: [PATCH 120/126] fix fuzztest crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖云帆 --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 889b02bd..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files.associations": { - "array": "cpp" - } -} \ No newline at end of file -- Gitee From 970dd70d7b536688187aa7f550a2ce2125ff974d Mon Sep 17 00:00:00 2001 From: wuliubao Date: Mon, 12 Aug 2024 10:01:35 +0800 Subject: [PATCH 121/126] =?UTF-8?q?IssueNo:#IAJACU=20Description:=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DSystemProperties=E6=97=A5=E5=BF=97=E7=BA=A7=E5=88=AB?= =?UTF-8?q?=E4=B8=8D=E5=87=86=E7=A1=AE=20Sig:=20SIG=5FApplicationFramework?= =?UTF-8?q?=20Feature=20or=20Bugfix:=20Feature=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuliubao --- .../src/system_properties_adapter_impl.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp b/ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp index e5c25abc..705f95ee 100644 --- a/ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp +++ b/ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp @@ -230,7 +230,7 @@ void SystemPropertiesAdapterImpl::AddAllSysPropWatchers() sysPropObserver_[item.second]; sysPropMutex_[item.second]; } else { - WVLOG_E("add watch error result: %{public}d", errNo); + WVLOG_I("add watch error result: %{public}d", errNo); } } } @@ -240,7 +240,7 @@ void SystemPropertiesAdapterImpl::RemoveAllSysPropWatchers() for (auto &item : PROP_KEY_MAP) { auto errNo = RemoveParameterWatcher(item.first.c_str(), nullptr, nullptr); if (errNo != 0) { - WVLOG_E("remove watch error result: %{public}d", errNo); + WVLOG_I("remove watch error result: %{public}d", errNo); } } } @@ -249,7 +249,7 @@ void SystemPropertiesAdapterImpl::DispatchAllWatcherInfo(const char* key, const { auto propKeyIt = PROP_KEY_MAP.find(key); if (propKeyIt == PROP_KEY_MAP.end()) { - WVLOG_E("sys prop change key is invalid: %{public}s", key); + WVLOG_I("sys prop change key is invalid: %{public}s", key); return; } @@ -257,7 +257,7 @@ void SystemPropertiesAdapterImpl::DispatchAllWatcherInfo(const char* key, const auto& keyObservers = sysPropObserver_[propkey]; if (keyObservers.size() == 0) { - WVLOG_E("no observers in this key: %{public}s", key); + WVLOG_I("no observers in this key: %{public}s", key); return; } @@ -271,12 +271,12 @@ void SystemPropertiesAdapterImpl::AttachSysPropObserver(PropertiesKey key, Syste { auto observerIt = sysPropObserver_.find(key); if (observerIt == sysPropObserver_.end()) { - WVLOG_E("properties key invalid in attach"); + WVLOG_I("properties key invalid in attach"); return; } if (observer == nullptr) { - WVLOG_E("properties key observer invalid in attach"); + WVLOG_I("properties key observer invalid in attach"); return; } @@ -289,12 +289,12 @@ void SystemPropertiesAdapterImpl::DetachSysPropObserver(PropertiesKey key, Syste { auto observerIt = sysPropObserver_.find(key); if (observerIt == sysPropObserver_.end()) { - WVLOG_E("properties key invalid in detach"); + WVLOG_I("properties key invalid in detach"); return; } if (observer == nullptr) { - WVLOG_E("properties key observer invalid in detach"); + WVLOG_I("properties key observer invalid in detach"); return; } -- Gitee From 1265e11525796b5e28a79f243a23f77b0f1ff710 Mon Sep 17 00:00:00 2001 From: yueyang Date: Mon, 12 Aug 2024 15:07:45 +0800 Subject: [PATCH 122/126] =?UTF-8?q?17100018=20=E6=8A=A5=E9=94=99=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yueyang --- interfaces/kits/napi/common/web_errors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/napi/common/web_errors.cpp b/interfaces/kits/napi/common/web_errors.cpp index eec5c783..44e393ae 100644 --- a/interfaces/kits/napi/common/web_errors.cpp +++ b/interfaces/kits/napi/common/web_errors.cpp @@ -37,7 +37,7 @@ const std::string TYPE_NOT_MATCH_WITCH_VALUE_MSG = "The type and value of the me const std::string NEW_OOM_MSG = "Memory allocation failed."; const std::string DOWNLOAD_NOT_PAUSED_MSG = "The download task is not paused."; const std::string NO_VALID_CONTROLLER_FOR_DOWNLOAD_MSG = "No valid WebviewController is associated."; -const std::string NO_DOWNLOAD_DELEGATE_SET_MSG = "No valid WebviewController is associated."; +const std::string NO_DOWNLOAD_DELEGATE_SET_MSG = "No WebDownloadDelegate has been set yet."; const std::string DOWNLOAD_NOT_START_MSG = "The download task is not started yet."; const std::string REGISTER_CUSTOM_SCHEME_FAILED_MSG = "Failed to register custom schemes."; const std::string HTTP_BODY_STREAN_INIT_FAILED_MSG = "Failed to initialize the HTTP body stream."; -- Gitee From 4fad676b108e2486f7fb116b38e7bf18af2c2f94 Mon Sep 17 00:00:00 2001 From: tengfan Date: Fri, 9 Aug 2024 16:23:41 +0800 Subject: [PATCH 123/126] createPDF Signed-off-by: tengfan --- interfaces/kits/napi/BUILD.gn | 1 + .../napi_webview_controller.cpp | 107 +++++++ .../napi_webview_controller.h | 2 + .../webviewcontroller/webview_controller.cpp | 42 +++ .../webviewcontroller/webview_controller.h | 6 + .../webview_createpdf_execute_callback.cpp | 270 ++++++++++++++++++ .../webview_createpdf_execute_callback.h | 90 ++++++ ohos_glue/BUILD.gn | 8 + ohos_interface/include/ohos_nweb/nweb.h | 23 ++ .../include/ohos_nweb/nweb_value_callback.h | 6 + ohos_interface/ohos_glue/BUILD_webcore.gn | 8 + .../base/include/ark_web_bridge_types.h | 2 + ...eb_array_buffer_value_callback_wrapper.cpp | 32 +++ ..._web_array_buffer_value_callback_wrapper.h | 41 +++ .../bridge/webcore/ark_web_nweb_impl.cpp | 17 ++ .../bridge/webcore/ark_web_nweb_impl.h | 10 + .../ark_web_pdfconfig_args_wrapper.cpp | 61 ++++ .../webcore/ark_web_pdfconfig_args_wrapper.h | 46 +++ ...k_web_array_buffer_value_callback_impl.cpp | 32 +++ ...ark_web_array_buffer_value_callback_impl.h | 41 +++ .../bridge/webview/ark_web_nweb_wrapper.cpp | 15 + .../bridge/webview/ark_web_nweb_wrapper.h | 10 + .../webview/ark_web_pdfconfig_args_impl.cpp | 57 ++++ .../webview/ark_web_pdfconfig_args_impl.h | 47 +++ .../ark_web_array_buffer_value_callback.h | 33 +++ .../ohos_nweb/include/ark_web_nweb.h | 12 + .../include/ark_web_pdfconfig_args.h | 54 ++++ ohos_nweb/include/nweb_init_params.h | 53 ++++ 28 files changed, 1126 insertions(+) create mode 100644 interfaces/kits/napi/webviewcontroller/webview_createpdf_execute_callback.cpp create mode 100644 interfaces/kits/napi/webviewcontroller/webview_createpdf_execute_callback.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_array_buffer_value_callback_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_array_buffer_value_callback_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_pdfconfig_args_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_pdfconfig_args_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_array_buffer_value_callback_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_array_buffer_value_callback_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_pdfconfig_args_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_pdfconfig_args_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/include/ark_web_array_buffer_value_callback.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/include/ark_web_pdfconfig_args.h diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index 964b8e49..536ed456 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -77,6 +77,7 @@ ohos_shared_library("webview_napi") { "webviewcontroller/web_scheme_handler_request.cpp", "webviewcontroller/web_scheme_handler_request.h", "webviewcontroller/webview_controller.cpp", + "webviewcontroller/webview_createpdf_execute_callback.cpp", "webviewcontroller/webview_hasimage_callback.cpp", "webviewcontroller/webview_javascript_execute_callback.cpp", "webviewcontroller/webview_javascript_result_callback.cpp", diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 907462b5..a7615713 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -39,6 +39,7 @@ #include "pixel_map_napi.h" #include "web_errors.h" #include "webview_javascript_execute_callback.h" +#include "webview_createpdf_execute_callback.h" #include "web_download_delegate.h" #include "web_download_manager.h" @@ -59,6 +60,11 @@ constexpr char URL_REGEXPR[] = "^http(s)?:\\/\\/.+"; constexpr size_t MAX_RESOURCES_COUNT = 30; constexpr size_t MAX_RESOURCE_SIZE = 10 * 1024 * 1024; constexpr size_t MAX_URL_TRUST_LIST_STR_LEN = 10 * 1024 * 1024; // 10M +constexpr double A4_WIDTH = 8.5; +constexpr double A4_HEIGHT = 11.0; +constexpr double SCALE_MIN = 0.1; +constexpr double SCALE_MAX = 2.0; +constexpr double HALF = 2.0; using WebPrintWriteResultCallback = std::function; bool ParsePrepareUrl(napi_env env, napi_value urlObj, std::string& url) @@ -336,6 +342,58 @@ std::shared_ptr ParsePrefetchArgs(napi_env env, napi_val return prefetchArgs; } +std::shared_ptr ParsePDFConfigArgs(napi_env env, napi_value preArgs) +{ + napi_value widthObj = nullptr; + double width = A4_WIDTH; + napi_get_named_property(env, preArgs, "width", &widthObj); + NapiParseUtils::ParseDouble(env, widthObj, width); + + napi_value heightObj = nullptr; + double height = A4_HEIGHT; + napi_get_named_property(env, preArgs, "height", &heightObj); + NapiParseUtils::ParseDouble(env, heightObj, height); + + napi_value scaleObj = nullptr; + double scale = 1.0; + napi_get_named_property(env, preArgs, "scale", &scaleObj); + NapiParseUtils::ParseDouble(env, scaleObj, scale); + scale = scale > SCALE_MAX ? SCALE_MAX : scale < SCALE_MIN ? SCALE_MIN : scale; + + napi_value marginTopObj = nullptr; + double marginTop = 0.0; + napi_get_named_property(env, preArgs, "marginTop", &marginTopObj); + NapiParseUtils::ParseDouble(env, marginTopObj, marginTop); + marginTop = marginTop >= height / HALF ? 0.0 : marginTop; + + napi_value marginBottomObj = nullptr; + double marginBottom = 0.0; + napi_get_named_property(env, preArgs, "marginBottom", &marginBottomObj); + NapiParseUtils::ParseDouble(env, marginBottomObj, marginBottom); + marginBottom = marginBottom >= height / HALF ? 0.0 : marginBottom; + + napi_value marginRightObj = nullptr; + double marginRight = 0.0; + napi_get_named_property(env, preArgs, "marginRight", &marginRightObj); + NapiParseUtils::ParseDouble(env, marginRightObj, marginRight); + marginRight = marginRight >= width / HALF ? 0.0 : marginRight; + + napi_value marginLeftObj = nullptr; + double marginLeft = 0.0; + napi_get_named_property(env, preArgs, "marginLeft", &marginLeftObj); + NapiParseUtils::ParseDouble(env, marginLeftObj, marginLeft); + marginLeft = marginLeft >= width / HALF ? 0.0 : marginLeft; + + napi_value shouldPrintBackgroundObj = nullptr; + bool shouldPrintBackground = false; + napi_get_named_property(env, preArgs, "shouldPrintBackground", &shouldPrintBackgroundObj); + NapiParseUtils::ParseBoolean(env, shouldPrintBackgroundObj, shouldPrintBackground); + + std::shared_ptr pdfConfig = std::make_shared( + width, height, scale, marginTop, marginBottom, marginRight, marginLeft, shouldPrintBackground); + return pdfConfig; +} + void JsErrorCallback(napi_env env, napi_ref jsCallback, int32_t err) { napi_value jsError = nullptr; @@ -449,6 +507,7 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("deleteJavaScriptRegister", NapiWebviewController::DeleteJavaScriptRegister), DECLARE_NAPI_FUNCTION("runJavaScript", NapiWebviewController::RunJavaScript), DECLARE_NAPI_FUNCTION("runJavaScriptExt", NapiWebviewController::RunJavaScriptExt), + DECLARE_NAPI_FUNCTION("createPdf", NapiWebviewController::RunCreatePDFExt), DECLARE_NAPI_FUNCTION("getUrl", NapiWebviewController::GetUrl), DECLARE_NAPI_FUNCTION("terminateRenderProcess", NapiWebviewController::TerminateRenderProcess), DECLARE_NAPI_FUNCTION("getOriginalUrl", NapiWebviewController::GetOriginalUrl), @@ -730,6 +789,7 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) napi_set_named_property(env, exports, WEB_PRESSURE_LEVEL_ENUM_NAME.c_str(), pressureLevelEnum); WebviewJavaScriptExecuteCallback::InitJSExcute(env, exports); + WebviewCreatePDFExecuteCallback::InitJSExcute(env, exports); return exports; } @@ -3227,6 +3287,53 @@ napi_value NapiWebviewController::RunJS(napi_env env, napi_callback_info info, b return RunJavaScriptInternal(env, info, script, extention); } +napi_value NapiWebviewController::RunCreatePDFExt(napi_env env, napi_callback_info info) +{ + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_ONE; + size_t argcPromise = INTEGER_ONE; + size_t argcCallback = INTEGER_TWO; + napi_value argv[INTEGER_TWO] = { 0 }; + + napi_get_undefined(env, &result); + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + + WebviewController* webviewController = nullptr; + napi_unwrap(env, thisVar, (void**)&webviewController); + + if (!webviewController || !webviewController->IsInit()) { + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); + return result; + } + + std::shared_ptr pdfConfig = ParsePDFConfigArgs(env, argv[INTEGER_ZERO]); + if (pdfConfig == nullptr) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); + return nullptr; + } + + if (argc == argcCallback) { + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + napi_ref jsCallback = nullptr; + napi_create_reference(env, argv[argcCallback - 1], 1, &jsCallback); + + if (jsCallback) { + webviewController->CreatePDFCallbackExt(env, pdfConfig, std::move(jsCallback)); + } + return result; + } else if (argc == argcPromise) { + napi_deferred deferred = nullptr; + napi_value promise = nullptr; + napi_create_promise(env, &deferred, &promise); + if (promise && deferred) { + webviewController->CreatePDFPromiseExt(env, pdfConfig, deferred); + } + return promise; + } + return result; +} + napi_value NapiWebviewController::RunJavaScriptInternal(napi_env env, napi_callback_info info, const std::string &script, bool extention) { diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h index e1283155..e2c5584f 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -184,6 +184,8 @@ private: static napi_value RunJavaScriptInternalExt(napi_env env, napi_callback_info info, bool extention); + static napi_value RunCreatePDFExt(napi_env env, napi_callback_info info); + static napi_value TerminateRenderProcess(napi_env env, napi_callback_info info); static napi_value GetUrl(napi_env env, napi_callback_info info); diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp index 6eae9375..fd7be95d 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp @@ -32,6 +32,7 @@ #include "nweb_log.h" #include "nweb_store_web_archive_callback.h" #include "web_errors.h" +#include "webview_createpdf_execute_callback.h" #include "webview_hasimage_callback.h" #include "webview_javascript_execute_callback.h" #include "webview_javascript_result_callback.h" @@ -1050,6 +1051,47 @@ void WebviewController::RunJavaScriptPromiseExt( nweb_ptr->ExecuteJavaScriptExt(fd, scriptLength, callbackImpl, extention); } +void WebviewController::CreatePDFCallbackExt( + napi_env env, std::shared_ptr pdfConfig, napi_ref pdfCallback) +{ + auto nweb_ptr = NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + napi_value setResult[RESULT_COUNT] = { 0 }; + setResult[PARAMZERO] = BusinessError::CreateError(env, NWebError::INIT_ERROR); + napi_get_null(env, &setResult[PARAMONE]); + + napi_value args[RESULT_COUNT] = { setResult[PARAMZERO], setResult[PARAMONE] }; + napi_value callback = nullptr; + napi_get_reference_value(env, pdfCallback, &callback); + napi_value callbackResult = nullptr; + napi_call_function(env, nullptr, callback, RESULT_COUNT, args, &callbackResult); + napi_delete_reference(env, pdfCallback); + return; + } + if (pdfCallback == nullptr) { + return; + } + auto callbackImpl = std::make_shared(env, pdfCallback, nullptr); + nweb_ptr->ExecuteCreatePDFExt(pdfConfig, callbackImpl); +} + +void WebviewController::CreatePDFPromiseExt( + napi_env env, std::shared_ptr pdfConfig, napi_deferred deferred) +{ + auto nweb_ptr = NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + napi_value pdfResult = nullptr; + pdfResult = NWebError::BusinessError::CreateError(env, NWebError::INIT_ERROR); + napi_reject_deferred(env, deferred, pdfResult); + return; + } + if (deferred == nullptr) { + return; + } + auto callbackImpl = std::make_shared(env, nullptr, deferred); + nweb_ptr->ExecuteCreatePDFExt(pdfConfig, callbackImpl); +} + std::string WebviewController::GetUrl() { std::string url = ""; diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.h b/interfaces/kits/napi/webviewcontroller/webview_controller.h index 06bd73a0..4e43b284 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.h @@ -383,6 +383,12 @@ public: void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive); void GetScrollOffset(float* offset_x, float* offset_y); + + void CreatePDFCallbackExt( + napi_env env, std::shared_ptr pdfConfig, napi_ref pdfCallback); + + void CreatePDFPromiseExt( + napi_env env, std::shared_ptr pdfConfig, napi_deferred deferred); private: int ConverToWebHitTestType(int hitType); diff --git a/interfaces/kits/napi/webviewcontroller/webview_createpdf_execute_callback.cpp b/interfaces/kits/napi/webviewcontroller/webview_createpdf_execute_callback.cpp new file mode 100644 index 00000000..b83e8d1f --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/webview_createpdf_execute_callback.cpp @@ -0,0 +1,270 @@ +/* + * 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 "business_error.h" +#include "napi_parse_utils.h" +#include "nweb_log.h" +#include "web_errors.h" +#include "webview_createpdf_execute_callback.h" +namespace OHOS::NWeb { +using namespace NWebError; +const std::string JS_EXT_ARR_CLASS_NAME = "PdfData"; +thread_local napi_ref g_jsArrExtClassRef; +// static +void WebviewCreatePDFExecuteCallback::InitJSExcute(napi_env env, napi_value exports) +{ + napi_value jsArrExtClass = nullptr; + napi_property_descriptor jsArrExtClsProperties[] = { DECLARE_NAPI_FUNCTION( + "pdfArrayBuffer", NapiArrayBufferExt::GetArrayBuffer) }; + napi_define_class(env, JS_EXT_ARR_CLASS_NAME.c_str(), JS_EXT_ARR_CLASS_NAME.length(), + NapiArrayBufferExt::JsConstructor, nullptr, sizeof(jsArrExtClsProperties) / sizeof(jsArrExtClsProperties[0]), + jsArrExtClsProperties, &jsArrExtClass); + napi_create_reference(env, jsArrExtClass, 1, &g_jsArrExtClassRef); + napi_set_named_property(env, exports, JS_EXT_ARR_CLASS_NAME.c_str(), jsArrExtClass); +} + +void WebviewCreatePDFExecuteCallback::OnReceiveValue(const char* result, const long size) +{ + uv_loop_s* loop = nullptr; + uv_work_t* work = nullptr; + + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { + return; + } + work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + return; + } + + ArrayBufferExecuteParam* param = new (std::nothrow) ArrayBufferExecuteParam(); + if (param == nullptr) { + delete work; + return; + } + param->env_ = env_; + param->callbackRef_ = callbackRef_; + param->deferred_ = deferred_; + param->result_ = new (std::nothrow) char[size + 1]; + if (memcpy_s(param->result_, size, result, size) != 0) { + WVLOG_E("[CreatePDF] memcpy failed"); + delete param->result_; + param->result_ = nullptr; + delete param; + param = nullptr; + delete work; + work = nullptr; + return; + } + param->size_ = size; + + work->data = reinterpret_cast(param); + + int ret = uv_queue_work_with_qos( + loop, work, [](uv_work_t* work) {}, UvAfterWorkCb, uv_qos_user_initiated); + if (ret != 0) { + if (param != nullptr) { + delete param->result_; + param->result_ = nullptr; + delete param; + param = nullptr; + } + if (work != nullptr) { + delete work; + work = nullptr; + } + } +} + +void WebviewCreatePDFExecuteCallback::UvAfterWorkCb(uv_work_t* work, int status) +{ + (void)status; + if (!work) { + return; + } + ArrayBufferExecuteParam* param = reinterpret_cast(work->data); + if (!param) { + delete work; + work = nullptr; + delete param->result_; + param->result_ = nullptr; + delete param; + param = nullptr; + return; + } + napi_handle_scope scope = nullptr; + napi_open_handle_scope(param->env_, &scope); + if (scope == nullptr) { + delete work; + work = nullptr; + delete param->result_; + param->result_ = nullptr; + delete param; + param = nullptr; + return; + } + if (param->callbackRef_) { + UvAfterWorkCbAsync(param->env_, param->callbackRef_, param->result_, param->size_); + } else if (param->deferred_) { + UvAfterWorkCbPromise(param->env_, param->deferred_, param->result_, param->size_); + } + + napi_close_handle_scope(param->env_, scope); + delete param->result_; + param->result_ = nullptr; + delete param; + param = nullptr; + delete work; + work = nullptr; +} + +void WebviewCreatePDFExecuteCallback::UvAfterWorkCbAsync( + napi_env env, napi_ref callbackRef, const char* result, const long size) +{ + napi_value setResult[INTEGER_TWO] = { 0 }; + + if (result == nullptr) { + setResult[INTEGER_ZERO] = BusinessError::CreateError(env, NWebError::INVALID_RESOURCE); + napi_get_null(env, &setResult[INTEGER_ONE]); + } else { + napi_get_undefined(env, &setResult[INTEGER_ZERO]); + napi_value jsArrExt = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, g_jsArrExtClassRef, &jsArrExt)); + NAPI_CALL_RETURN_VOID(env, napi_new_instance(env, jsArrExt, 0, NULL, &setResult[INTEGER_ONE])); + + WebJsArrayBufferExt* webArrayBufferExt = new (std::nothrow) WebJsArrayBufferExt(result, size); + if (webArrayBufferExt == nullptr) { + WVLOG_E("new WebJsArrayBufferExt failed."); + return; + } + + napi_status status = napi_wrap( + env, setResult[INTEGER_ONE], webArrayBufferExt, + [](napi_env env, void* data, void* hint) { + WebJsArrayBufferExt* webArrayBufferExt = static_cast(data); + delete webArrayBufferExt; + webArrayBufferExt = nullptr; + }, + nullptr, nullptr); + if (status != napi_status::napi_ok) { + WVLOG_E("napi_wrap failed"); + return; + } + } + napi_value args[INTEGER_TWO] = { setResult[INTEGER_ZERO], setResult[INTEGER_ONE] }; + napi_value callback = nullptr; + napi_value callbackResult = nullptr; + + napi_get_reference_value(env, callbackRef, &callback); + napi_call_function(env, nullptr, callback, INTEGER_TWO, args, &callbackResult); + napi_delete_reference(env, callbackRef); +} + +void WebviewCreatePDFExecuteCallback::UvAfterWorkCbPromise( + napi_env env, napi_deferred deferred, const char* result, const long size) +{ + napi_value setResult[INTEGER_TWO] = { 0 }; + setResult[INTEGER_ZERO] = NWebError::BusinessError::CreateError(env, NWebError::INVALID_RESOURCE); + + napi_value jsArrExt = nullptr; + napi_status status = napi_get_reference_value(env, g_jsArrExtClassRef, &jsArrExt); + if (status != napi_status::napi_ok) { + WVLOG_E("napi_get_reference_value failed."); + return; + } + status = napi_new_instance(env, jsArrExt, 0, NULL, &setResult[INTEGER_ONE]); + if (status != napi_status::napi_ok) { + WVLOG_E("napi_new_instance failed."); + return; + } + WebJsArrayBufferExt* webArrayBufferExt = new (std::nothrow) WebJsArrayBufferExt(result, size); + if (webArrayBufferExt == nullptr) { + WVLOG_E("new WebJsArrayBufferExt failed."); + return; + } + + status = napi_wrap( + env, setResult[INTEGER_ONE], webArrayBufferExt, + [](napi_env env, void* data, void* hint) { + WebJsArrayBufferExt* webArrayBufferExt = static_cast(data); + delete webArrayBufferExt; + webArrayBufferExt = nullptr; + }, + nullptr, nullptr); + if (status != napi_status::napi_ok) { + WVLOG_E("napi_wrap failed."); + return; + } + + napi_value args[INTEGER_TWO] = { setResult[INTEGER_ZERO], setResult[INTEGER_ONE] }; + if (result == nullptr) { + napi_reject_deferred(env, deferred, args[INTEGER_ZERO]); + } else { + napi_resolve_deferred(env, deferred, args[INTEGER_ONE]); + } +} + +napi_value NapiArrayBufferExt::JsConstructor(napi_env env, napi_callback_info info) +{ + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); + return thisVar; +} + +napi_value NapiArrayBufferExt::GetArrayBuffer(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 }; + + WebJsArrayBufferExt* webArrayBufferExt = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr)); + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&webArrayBufferExt)); + if (webArrayBufferExt == nullptr) { + WVLOG_E("unwrap webArrayBufferExt failed."); + return result; + } + + const char* pdfResult = webArrayBufferExt->GetPDFResult(); + const long size = webArrayBufferExt->GetPDFSize(); + napi_value arraybuffer = nullptr; + void* bufferData = nullptr; + + napi_status status = napi_create_arraybuffer(env, size, &bufferData, &arraybuffer); + if (status != napi_ok) { + WVLOG_E("[CreatePDF] create array buffer failed, status: %{public}d", status); + return nullptr; + } + if (memcpy_s(bufferData, size, pdfResult, size) != 0) { + WVLOG_E("[CreatePDF] memcpy failed"); + return nullptr; + } + status = napi_create_typedarray(env, napi_typedarray_type::napi_uint8_array, size, arraybuffer, 0, &result); + if (status != napi_ok) { + WVLOG_E("[CreatePDF] create typed array failed, status: %{public}d", status); + return nullptr; + } + napi_ref arraybufferRef; + napi_create_reference(env, arraybuffer, 1, &arraybufferRef); + + return result; +} + +} // namespace OHOS::NWeb diff --git a/interfaces/kits/napi/webviewcontroller/webview_createpdf_execute_callback.h b/interfaces/kits/napi/webviewcontroller/webview_createpdf_execute_callback.h new file mode 100644 index 00000000..802a9dac --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/webview_createpdf_execute_callback.h @@ -0,0 +1,90 @@ +/* + * 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_WEBVIEW_CREAT_PDF_EXECUTE_CALLBACK_H +#define NWEB_WEBVIEW_CREAT_PDF_EXECUTE_CALLBACK_H + +#include +#include + +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "napi_parse_utils.h" +#include "nweb_value_callback.h" +#include "nweb_web_message.h" + +namespace OHOS::NWeb { +enum class JsCreatePDFType : int { ARRAYBUFFER = 0 }; + +class NapiArrayBufferExt { +public: + NapiArrayBufferExt() = default; + ~NapiArrayBufferExt() = default; + + static napi_value JsConstructor(napi_env env, napi_callback_info info); + + static napi_value GetArrayBuffer(napi_env env, napi_callback_info info); +}; + +class WebJsArrayBufferExt { +public: + explicit WebJsArrayBufferExt(const char* value, const long size) : value_(value), size_(size) {}; + ~WebJsArrayBufferExt() = default; + + const char* GetPDFResult() const + { + return value_; + } + + long GetPDFSize() const + { + return size_; + } + +private: + const char* value_ = nullptr; + long size_ = 0; +}; + +class WebviewCreatePDFExecuteCallback : public NWebArrayBufferValueCallback { +public: + explicit WebviewCreatePDFExecuteCallback(napi_env env, napi_ref callbackRef, napi_deferred deferred) + : env_(env), callbackRef_(callbackRef), deferred_(deferred) + {} + ~WebviewCreatePDFExecuteCallback() = default; + void OnReceiveValue(const char* value, const long size) override; + +private: + struct ArrayBufferExecuteParam { + napi_env env_; + napi_ref callbackRef_; + napi_deferred deferred_; + char* result_; + long size_; + }; + + napi_env env_ = nullptr; + napi_ref callbackRef_ = nullptr; + napi_deferred deferred_ = nullptr; + + static void UvAfterWorkCb(uv_work_t* work, int status); + static void UvAfterWorkCbAsync(napi_env env, napi_ref callbackRef, const char* result, const long size); + static void UvAfterWorkCbPromise(napi_env env, napi_deferred deferred, const char* result, const long size); + +public: + static void InitJSExcute(napi_env env, napi_value exports); +}; + +} // namespace OHOS::NWeb +#endif diff --git a/ohos_glue/BUILD.gn b/ohos_glue/BUILD.gn index df67451d..5e72974d 100644 --- a/ohos_glue/BUILD.gn +++ b/ohos_glue/BUILD.gn @@ -229,6 +229,10 @@ action("ohos_glue_nweb_prepare") { "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_web_storage_wrapper.h", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_adsblock_manager_wrapper.cpp", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_adsblock_manager_wrapper.h", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_array_buffer_value_callback_impl.cpp", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_array_buffer_value_callback_impl.h", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_pdfconfig_args_impl.cpp", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_pdfconfig_args_impl.h", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_accessibility_event_callback_cpptoc.cpp", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_accessibility_event_callback_cpptoc.h", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_bool_value_callback_cpptoc.cpp", @@ -289,6 +293,10 @@ action("ohos_glue_nweb_prepare") { "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_value_vector_cpptoc.h", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_web_storage_origin_vector_value_callback_cpptoc.cpp", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_web_storage_origin_vector_value_callback_cpptoc.h", + "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_array_buffer_value_callback_cpptoc.cpp", + "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_array_buffer_value_callback_cpptoc.h", + "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_pdfconfig_args_cpptoc.cpp", + "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_pdfconfig_args_cpptoc.h", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_accessibility_node_info_ctocpp.cpp", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_accessibility_node_info_ctocpp.h", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_access_request_ctocpp.cpp", diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 56ba3991..34ab2178 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -192,6 +192,20 @@ public: virtual std::string GetFormData() = 0; }; +class OHOS_NWEB_EXPORT NWebPDFConfigArgs { +public: + virtual ~NWebPDFConfigArgs() = default; + + virtual double GetWidth() = 0; + virtual double GetHeight() = 0; + virtual double GetScale() = 0; + virtual double GetMarginTop() = 0; + virtual double GetMarginBottom() = 0; + virtual double GetMarginRight() = 0; + virtual double GetMarginLeft() = 0; + virtual bool GetShouldPrintBackground() = 0; +}; + enum class PrecompileError : int32_t { OK = 0, INTERNAL_ERROR = -1 }; class OHOS_NWEB_EXPORT CacheOptions { @@ -1472,6 +1486,15 @@ public: * @param offset_y The current vertical scroll offset of the webpage. */ virtual void GetScrollOffset(float* offset_x, float* offset_y) {} + + /** + * @brief ExecuteCreatePDFExt + * + * @param pdfConfig The current configuration when creating pdf. + * @param callback NWebArrayBufferValueCallback: CreatePDF running result. + */ + virtual void ExecuteCreatePDFExt(std::shared_ptr pdfConfig, + std::shared_ptr callback) {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_value_callback.h b/ohos_interface/include/ohos_nweb/nweb_value_callback.h index 21ad136d..bac7bb75 100644 --- a/ohos_interface/include/ohos_nweb/nweb_value_callback.h +++ b/ohos_interface/include/ohos_nweb/nweb_value_callback.h @@ -67,6 +67,12 @@ public: virtual void OnReceiveValue(const std::vector>& value) = 0; }; +class OHOS_NWEB_EXPORT NWebArrayBufferValueCallback { +public: + virtual ~NWebArrayBufferValueCallback() = default; + + virtual void OnReceiveValue(const char* value, const long size) = 0; +}; } // namespace OHOS::NWeb #endif // NWebValueCallback \ No newline at end of file diff --git a/ohos_interface/ohos_glue/BUILD_webcore.gn b/ohos_interface/ohos_glue/BUILD_webcore.gn index 87ff0a23..db706f12 100644 --- a/ohos_interface/ohos_glue/BUILD_webcore.gn +++ b/ohos_interface/ohos_glue/BUILD_webcore.gn @@ -60,6 +60,8 @@ component("ohos_nweb_glue_source") { "ohos_nweb/bridge/ark_web_adsblock_manager_impl.h", "ohos_nweb/bridge/ark_web_applink_callback_impl.cpp", "ohos_nweb/bridge/ark_web_applink_callback_impl.h", + "ohos_nweb/bridge/ark_web_array_buffer_value_callback_wrapper.cpp", + "ohos_nweb/bridge/ark_web_array_buffer_value_callback_wrapper.h", "ohos_nweb/bridge/ark_web_bool_value_callback_wrapper.cpp", "ohos_nweb/bridge/ark_web_bool_value_callback_wrapper.h", "ohos_nweb/bridge/ark_web_cache_options_wrapper.cpp", @@ -174,6 +176,8 @@ component("ohos_nweb_glue_source") { "ohos_nweb/bridge/ark_web_nweb_impl.h", "ohos_nweb/bridge/ark_web_output_frame_callback_wrapper.cpp", "ohos_nweb/bridge/ark_web_output_frame_callback_wrapper.h", + "ohos_nweb/bridge/ark_web_pdfconfig_args_wrapper.cpp", + "ohos_nweb/bridge/ark_web_pdfconfig_args_wrapper.h", "ohos_nweb/bridge/ark_web_preference_impl.cpp", "ohos_nweb/bridge/ark_web_preference_impl.h", "ohos_nweb/bridge/ark_web_quick_menu_callback_impl.cpp", @@ -356,6 +360,8 @@ component("ohos_nweb_glue_source") { "ohos_nweb/cpptoc/ark_web_web_storage_origin_vector_cpptoc.h", "ohos_nweb/ctocpp/ark_web_accessibility_event_callback_ctocpp.cpp", "ohos_nweb/ctocpp/ark_web_accessibility_event_callback_ctocpp.h", + "ohos_nweb/ctocpp/ark_web_array_buffer_value_callback_ctocpp.cpp", + "ohos_nweb/ctocpp/ark_web_array_buffer_value_callback_ctocpp.h", "ohos_nweb/ctocpp/ark_web_bool_value_callback_ctocpp.cpp", "ohos_nweb/ctocpp/ark_web_bool_value_callback_ctocpp.h", "ohos_nweb/ctocpp/ark_web_cache_options_ctocpp.cpp", @@ -392,6 +398,8 @@ component("ohos_nweb_glue_source") { "ohos_nweb/ctocpp/ark_web_nweb_create_info_ctocpp.h", "ohos_nweb/ctocpp/ark_web_output_frame_callback_ctocpp.cpp", "ohos_nweb/ctocpp/ark_web_output_frame_callback_ctocpp.h", + "ohos_nweb/ctocpp/ark_web_pdfconfig_args_ctocpp.cpp", + "ohos_nweb/ctocpp/ark_web_pdfconfig_args_ctocpp.h", "ohos_nweb/ctocpp/ark_web_release_surface_callback_ctocpp.cpp", "ohos_nweb/ctocpp/ark_web_release_surface_callback_ctocpp.h", "ohos_nweb/ctocpp/ark_web_resource_ready_callback_ctocpp.cpp", 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 ee115fa4..640ae093 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 @@ -111,6 +111,8 @@ enum ArkWebBridgeType { ARK_WEB_SYSTEM_CONFIGURATION = 86, ARK_WEB_ADS_BLOCK_MANAGER = 87, ARK_WEB_SPANSTRING_CONVERT_HTML_CALLBACK = 88, + ARK_WEB_ARRAY_BUFFER_VALUE_CALLBACK = 89, + ARK_WEB_PDFCONFIG_ARGS = 90, /*Note: Adapter interface bridge type*/ ARK_AAFWK_APP_MGR_CLIENT_ADAPTER = 10000, diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_array_buffer_value_callback_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_array_buffer_value_callback_wrapper.cpp new file mode 100644 index 00000000..28d3cc19 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_array_buffer_value_callback_wrapper.cpp @@ -0,0 +1,32 @@ +/* + * 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_nweb/bridge/ark_web_array_buffer_value_callback_wrapper.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebArrayBufferValueCallbackWrapper::ArkWebArrayBufferValueCallbackWrapper( + ArkWebRefPtr ark_web_array_buffer_value_callback) + : ark_web_array_buffer_value_callback_(ark_web_array_buffer_value_callback) +{} + +void ArkWebArrayBufferValueCallbackWrapper::OnReceiveValue(const char* value, const long size) +{ + ark_web_array_buffer_value_callback_->OnReceiveValue(value, size); +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_array_buffer_value_callback_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_array_buffer_value_callback_wrapper.h new file mode 100644 index 00000000..0fd28ca8 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_array_buffer_value_callback_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_WEB_ARRAY_BUFFER_VALUE_CALLBACK_WRAPPER_H_ +#define ARK_WEB_ARRAY_BUFFER_VALUE_CALLBACK_WRAPPER_H_ +#pragma once + +#include "include/nweb_value_callback.h" +#include "ohos_nweb/include/ark_web_array_buffer_value_callback.h" + +#include "base/include/ark_web_types.h" + +namespace OHOS::ArkWeb { + +class ArkWebArrayBufferValueCallbackWrapper : public OHOS::NWeb::NWebArrayBufferValueCallback { +public: + ArkWebArrayBufferValueCallbackWrapper( + ArkWebRefPtr ark_web_array_buffer_value_callback); + ~ArkWebArrayBufferValueCallbackWrapper() = default; + + void OnReceiveValue(const char* value, const long size) override; + +private: + ArkWebRefPtr ark_web_array_buffer_value_callback_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_ARRAY_BUFFER_VALUE_CALLBACK_WRAPPER_H_ 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 47865926..8c6bc160 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 @@ -17,6 +17,8 @@ #include "ohos_nweb/bridge/ark_web_accessibility_event_callback_wrapper.h" #include "ohos_nweb/bridge/ark_web_accessibility_node_info_impl.h" +#include "ohos_nweb/bridge/ark_web_array_buffer_value_callback_wrapper.h" +#include "ohos_nweb/bridge/ark_web_pdfconfig_args_wrapper.h" #include "ohos_nweb/bridge/ark_web_bool_value_callback_wrapper.h" #include "ohos_nweb/bridge/ark_web_cache_options_wrapper.h" #include "ohos_nweb/bridge/ark_web_core_struct_utils.h" @@ -1142,4 +1144,19 @@ void ArkWebNWebImpl::GetScrollOffset(float* offset_x, float* offset_y) { nweb_nweb_->GetScrollOffset(offset_x, offset_y); } + +void ArkWebNWebImpl::ExecuteCreatePDFExt( + ArkWebRefPtr pdfConfig, ArkWebRefPtr callback) +{ + if (CHECK_REF_PTR_IS_NULL(callback)) { + nweb_nweb_->ExecuteCreatePDFExt( + std::make_shared(CHECK_REF_PTR_IS_NULL(pdfConfig) ? nullptr : pdfConfig), + nullptr); + return; + } + + nweb_nweb_->ExecuteCreatePDFExt( + std::make_shared(CHECK_REF_PTR_IS_NULL(pdfConfig) ? nullptr : pdfConfig), + std::make_shared(callback)); +} } // 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 3894cb3e..6e7fd325 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 @@ -1314,6 +1314,16 @@ public: */ /*--ark web()--*/ void GetScrollOffset(float* offset_x, float* offset_y) override; + + /** + * @brief ExecuteCreatePDF + * + * @param pdfConfig The current configuration when creating pdf. + * @param callback NWebArrayBufferValueCallback: CreatePDF running result. + */ + /*--ark web()--*/ + void ExecuteCreatePDFExt( + ArkWebRefPtr pdfConfig, ArkWebRefPtr callback) override; private: std::shared_ptr nweb_nweb_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_pdfconfig_args_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_pdfconfig_args_wrapper.cpp new file mode 100644 index 00000000..82367e3d --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_pdfconfig_args_wrapper.cpp @@ -0,0 +1,61 @@ +/* + * 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 wrapperied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos_nweb/bridge/ark_web_pdfconfig_args_wrapper.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebPDFConfigArgsWrapper::ArkWebPDFConfigArgsWrapper( + ArkWebRefPtr ark_web_pdfconfig_args) + : ark_web_pdfconfig_args_(ark_web_pdfconfig_args) +{} + + +double ArkWebPDFConfigArgsWrapper::GetWidth() +{ + return ark_web_pdfconfig_args_->GetWidth(); +} +double ArkWebPDFConfigArgsWrapper::GetHeight() +{ + return ark_web_pdfconfig_args_->GetHeight(); +} +double ArkWebPDFConfigArgsWrapper::GetScale() +{ + return ark_web_pdfconfig_args_->GetScale(); +} +double ArkWebPDFConfigArgsWrapper::GetMarginTop() +{ + return ark_web_pdfconfig_args_->GetMarginTop(); +} +double ArkWebPDFConfigArgsWrapper::GetMarginBottom() +{ + return ark_web_pdfconfig_args_->GetMarginBottom(); +} +double ArkWebPDFConfigArgsWrapper::GetMarginRight() +{ + return ark_web_pdfconfig_args_->GetMarginRight(); +} +double ArkWebPDFConfigArgsWrapper::GetMarginLeft() +{ + return ark_web_pdfconfig_args_->GetMarginLeft(); +} +bool ArkWebPDFConfigArgsWrapper::GetShouldPrintBackground() +{ + return ark_web_pdfconfig_args_->GetShouldPrintBackground(); +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_pdfconfig_args_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_pdfconfig_args_wrapper.h new file mode 100644 index 00000000..5e5c328b --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_pdfconfig_args_wrapper.h @@ -0,0 +1,46 @@ +/* + * 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 wrapperied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARK_WEB_PDFCONFIG_ARGS_WRAPPER_H_ +#define ARK_WEB_PDFCONFIG_ARGS_WRAPPER_H_ +#pragma once + +#include "include/nweb.h" +#include "ohos_nweb/include/ark_web_pdfconfig_args.h" + +#include "base/include/ark_web_types.h" + +namespace OHOS::ArkWeb { + +class ArkWebPDFConfigArgsWrapper : public OHOS::NWeb::NWebPDFConfigArgs { +public: + ArkWebPDFConfigArgsWrapper(ArkWebRefPtr ark_web_pdfconfig_args); + ~ArkWebPDFConfigArgsWrapper() = default; + + double GetWidth() override; + double GetHeight() override; + double GetScale() override; + double GetMarginTop() override; + double GetMarginBottom() override; + double GetMarginRight() override; + double GetMarginLeft() override; + bool GetShouldPrintBackground() override; +private: + ArkWebRefPtr ark_web_pdfconfig_args_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_PDFCONFIG_ARGS_WRAPPER_H_ diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_array_buffer_value_callback_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_array_buffer_value_callback_impl.cpp new file mode 100644 index 00000000..3ab34506 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_array_buffer_value_callback_impl.cpp @@ -0,0 +1,32 @@ +/* + * 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_nweb/bridge/ark_web_array_buffer_value_callback_impl.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebArrayBufferValueCallbackImpl::ArkWebArrayBufferValueCallbackImpl( + std::shared_ptr nweb_array_buffer_value_callback) + : nweb_array_buffer_value_callback_(nweb_array_buffer_value_callback) +{} + +void ArkWebArrayBufferValueCallbackImpl::OnReceiveValue(const char* value, const long size) +{ + nweb_array_buffer_value_callback_->OnReceiveValue(value, size); +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_array_buffer_value_callback_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_array_buffer_value_callback_impl.h new file mode 100644 index 00000000..cbca5639 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_array_buffer_value_callback_impl.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_WEB_ARRAY_BUFFER_VALUE_CALLBACK_IMPL_H_ +#define ARK_WEB_ARRAY_BUFFER_VALUE_CALLBACK_IMPL_H_ +#pragma once + +#include "include/nweb_value_callback.h" +#include "ohos_nweb/include/ark_web_array_buffer_value_callback.h" + +namespace OHOS::ArkWeb { + +class ArkWebArrayBufferValueCallbackImpl : public ArkWebArrayBufferValueCallback { + IMPLEMENT_REFCOUNTING(ArkWebArrayBufferValueCallbackImpl); + +public: + ArkWebArrayBufferValueCallbackImpl( + std::shared_ptr nweb_array_buffer_value_callback); + ~ArkWebArrayBufferValueCallbackImpl() = default; + + void OnReceiveValue(const char* value, const long size) override; + +private: + std::shared_ptr nweb_array_buffer_value_callback_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_ARRAY_BUFFER_VALUE_CALLBACK_IMPL_H_ 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 aea2b1d8..727d3f95 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 @@ -17,6 +17,7 @@ #include "ohos_nweb/bridge/ark_web_accessibility_event_callback_impl.h" #include "ohos_nweb/bridge/ark_web_accessibility_node_info_wrapper.h" +#include "ohos_nweb/bridge/ark_web_array_buffer_value_callback_impl.h" #include "ohos_nweb/bridge/ark_web_bool_value_callback_impl.h" #include "ohos_nweb/bridge/ark_web_cache_options_impl.h" #include "ohos_nweb/bridge/ark_web_create_native_media_player_callback_impl.h" @@ -29,6 +30,7 @@ #include "ohos_nweb/bridge/ark_web_hit_test_result_wrapper.h" #include "ohos_nweb/bridge/ark_web_js_result_callback_impl.h" #include "ohos_nweb/bridge/ark_web_message_value_callback_impl.h" +#include "ohos_nweb/bridge/ark_web_pdfconfig_args_impl.h" #include "ohos_nweb/bridge/ark_web_preference_wrapper.h" #include "ohos_nweb/bridge/ark_web_release_surface_callback_impl.h" #include "ohos_nweb/bridge/ark_web_screen_lock_callback_impl.h" @@ -1344,4 +1346,17 @@ void ArkWebNWebWrapper::GetScrollOffset(float* offset_x, float* offset_y) { ark_web_nweb_->GetScrollOffset(offset_x, offset_y); } + +void ArkWebNWebWrapper::ExecuteCreatePDFExt(std::shared_ptr pdfConfig, + std::shared_ptr callback) +{ + if (CHECK_SHARED_PTR_IS_NULL(callback)) { + ark_web_nweb_->ExecuteCreatePDFExt( + new ArkWebPDFConfigArgsImpl(CHECK_SHARED_PTR_IS_NULL(pdfConfig) ? nullptr : pdfConfig), nullptr); + } else { + ark_web_nweb_->ExecuteCreatePDFExt( + new ArkWebPDFConfigArgsImpl(CHECK_SHARED_PTR_IS_NULL(pdfConfig) ? nullptr : pdfConfig), + new ArkWebArrayBufferValueCallbackImpl(callback)); + } +} } // 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 d63826ec..63ad7209 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 @@ -1323,6 +1323,16 @@ public: */ /*--ark web()--*/ void GetScrollOffset(float* offset_x, float* offset_y) override; + + /** + * @brief ExecuteCreatePDF + * + * @param pdfConfig The current configuration when creating pdf. + * @param callback NWebArrayBufferValueCallback: CreatePDF running result. + */ + /*--ark web()--*/ + void ExecuteCreatePDFExt(std::shared_ptr pdfConfig, + std::shared_ptr callback) override; private: ArkWebRefPtr ark_web_nweb_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_pdfconfig_args_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_pdfconfig_args_impl.cpp new file mode 100644 index 00000000..4d4e469a --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_pdfconfig_args_impl.cpp @@ -0,0 +1,57 @@ +/* + * 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_nweb/bridge/ark_web_pdfconfig_args_impl.h" + +namespace OHOS::ArkWeb { + +ArkWebPDFConfigArgsImpl::ArkWebPDFConfigArgsImpl(std::shared_ptr pdfConfig) + : nweb_pdfconfig_(pdfConfig) +{} + +double ArkWebPDFConfigArgsImpl::GetWidth() +{ + return nweb_pdfconfig_->GetWidth(); +} +double ArkWebPDFConfigArgsImpl::GetHeight() +{ + return nweb_pdfconfig_->GetHeight(); +} +double ArkWebPDFConfigArgsImpl::GetScale() +{ + return nweb_pdfconfig_->GetScale(); +} +double ArkWebPDFConfigArgsImpl::GetMarginTop() +{ + return nweb_pdfconfig_->GetMarginTop(); +} +double ArkWebPDFConfigArgsImpl::GetMarginBottom() +{ + return nweb_pdfconfig_->GetMarginBottom(); +} +double ArkWebPDFConfigArgsImpl::GetMarginRight() +{ + return nweb_pdfconfig_->GetMarginRight(); +} +double ArkWebPDFConfigArgsImpl::GetMarginLeft() +{ + return nweb_pdfconfig_->GetMarginLeft(); +} +bool ArkWebPDFConfigArgsImpl::GetShouldPrintBackground() +{ + return nweb_pdfconfig_->GetShouldPrintBackground(); +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_pdfconfig_args_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_pdfconfig_args_impl.h new file mode 100644 index 00000000..bfdb969c --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_pdfconfig_args_impl.h @@ -0,0 +1,47 @@ +/* + * 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_WEB_PDFCONFIG_ARGS_IMPL_H_ +#define ARK_WEB_PDFCONFIG_ARGS_IMPL_H_ +#pragma once + +#include "include/nweb.h" +#include "ohos_nweb/include/ark_web_pdfconfig_args.h" + +namespace OHOS::ArkWeb { + +class ArkWebPDFConfigArgsImpl : public ArkWebPDFConfigArgs { + IMPLEMENT_REFCOUNTING(ArkWebPDFConfigArgsImpl); + +public: + ArkWebPDFConfigArgsImpl(std::shared_ptr pdfConfig); + ~ArkWebPDFConfigArgsImpl() = default; + + double GetWidth() override; + double GetHeight() override; + double GetScale() override; + double GetMarginTop() override; + double GetMarginBottom() override; + double GetMarginRight() override; + double GetMarginLeft() override; + bool GetShouldPrintBackground() override; + +private: + std::shared_ptr nweb_pdfconfig_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_PDFCONFIG_ARGS_IMPL_H_ diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_array_buffer_value_callback.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_array_buffer_value_callback.h new file mode 100644 index 00000000..d172aaaa --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_array_buffer_value_callback.h @@ -0,0 +1,33 @@ +/* + * 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_WEB_ARRAY_BUFFER_VALUE_CALLBACK_H_ +#define ARK_WEB_ARRAY_BUFFER_VALUE_CALLBACK_H_ +#pragma once + +#include "base/include/ark_web_base_ref_counted.h" + +namespace OHOS::ArkWeb { + +/*--ark web(source=webview)--*/ +class ArkWebArrayBufferValueCallback : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual void OnReceiveValue(const char* value, const long size) = 0; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_ARRAY_BUFFER_VALUE_CALLBACK_H_ 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 ecfff288..0abe6707 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 @@ -19,6 +19,7 @@ #include "ohos_nweb/include/ark_web_accessibility_event_callback.h" #include "ohos_nweb/include/ark_web_accessibility_node_info.h" +#include "ohos_nweb/include/ark_web_array_buffer_value_callback.h" #include "ohos_nweb/include/ark_web_bool_value_callback.h" #include "ohos_nweb/include/ark_web_cache_options.h" #include "ohos_nweb/include/ark_web_create_native_media_player_callback.h" @@ -31,6 +32,7 @@ #include "ohos_nweb/include/ark_web_js_proxy_callback_vector.h" #include "ohos_nweb/include/ark_web_js_result_callback.h" #include "ohos_nweb/include/ark_web_message_value_callback.h" +#include "ohos_nweb/include/ark_web_pdfconfig_args.h" #include "ohos_nweb/include/ark_web_preference.h" #include "ohos_nweb/include/ark_web_release_surface_callback.h" #include "ohos_nweb/include/ark_web_screen_lock_callback.h" @@ -1473,6 +1475,16 @@ public: */ /*--ark web()--*/ virtual void GetScrollOffset(float* offset_x, float* offset_y) = 0; + + /** + * @brief ExecuteCreatePDFExt + * + * @param pdfConfig The current configuration when creating pdf. + * @param callback NWebArrayBufferValueCallback: CreatePDF running result. + */ + /*--ark web()--*/ + virtual void ExecuteCreatePDFExt(ArkWebRefPtr pdfConfig, + ArkWebRefPtr callback) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_pdfconfig_args.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_pdfconfig_args.h new file mode 100644 index 00000000..b4397f88 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_pdfconfig_args.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_WEB_PDFCONFIG_ARGS_H_ +#define ARK_WEB_PDFCONFIG_ARGS_H_ +#pragma once + +#include "base/include/ark_web_base_ref_counted.h" + +namespace OHOS::ArkWeb { + +/*--ark web(source=webview)--*/ +class ArkWebPDFConfigArgs : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual double GetWidth() = 0; + + /*--ark web()--*/ + virtual double GetHeight() = 0; + + /*--ark web()--*/ + virtual double GetScale() = 0; + + /*--ark web()--*/ + virtual double GetMarginTop() = 0; + + /*--ark web()--*/ + virtual double GetMarginBottom() = 0; + + /*--ark web()--*/ + virtual double GetMarginRight() = 0; + + /*--ark web()--*/ + virtual double GetMarginLeft() = 0; + + /*--ark web()--*/ + virtual bool GetShouldPrintBackground() = 0; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_PDFCONFIG_ARGS_H_ diff --git a/ohos_nweb/include/nweb_init_params.h b/ohos_nweb/include/nweb_init_params.h index 9f1b2374..4e850156 100644 --- a/ohos_nweb/include/nweb_init_params.h +++ b/ohos_nweb/include/nweb_init_params.h @@ -275,6 +275,59 @@ private: std::string form_data_; }; +class NWebPDFConfigArgsImpl : public NWebPDFConfigArgs { +public: + NWebPDFConfigArgsImpl(const double width, const double height, const double scale, const double marginTop, + const double marginBottom, const double marginRight, const double marginLeft, const bool shouldPrintBackground) + : width_(width), height_(height), scale_(scale), marginTop_(marginTop), marginBottom_(marginBottom), + marginRight_(marginRight), marginLeft_(marginLeft), shouldPrintBackground_(shouldPrintBackground) + {} + + ~NWebPDFConfigArgsImpl() = default; + + double GetWidth() override + { + return width_; + } + double GetHeight() override + { + return height_; + } + double GetScale() override + { + return scale_; + } + double GetMarginTop() override + { + return marginTop_; + } + double GetMarginBottom() override + { + return marginBottom_; + } + double GetMarginRight() override + { + return marginRight_; + } + double GetMarginLeft() override + { + return marginLeft_; + } + bool GetShouldPrintBackground() override + { + return shouldPrintBackground_; + } + +private: + double width_; + double height_; + double scale_; + double marginTop_; + double marginBottom_; + double marginRight_; + double marginLeft_; + bool shouldPrintBackground_; +}; } // namespace OHOS::NWeb #endif // NWEB_INIT_PARAMS_H -- Gitee From 783d451ba5a5e78a6dab52fce5b1320b8154a4c2 Mon Sep 17 00:00:00 2001 From: "lxlxlx310@163.com" Date: Mon, 12 Aug 2024 23:07:30 +0800 Subject: [PATCH 124/126] =?UTF-8?q?Web=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?scrollByWithResult?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lxlxlx310@163.com --- .../napi_webview_controller.cpp | 39 +++++++++++++++++++ .../napi_webview_controller.h | 1 + .../webviewcontroller/webview_controller.cpp | 10 +++++ .../webviewcontroller/webview_controller.h | 2 + ohos_interface/include/ohos_nweb/nweb.h | 11 ++++++ .../bridge/webcore/ark_web_nweb_impl.cpp | 5 +++ .../bridge/webcore/ark_web_nweb_impl.h | 10 +++++ .../bridge/webview/ark_web_nweb_wrapper.cpp | 5 +++ .../bridge/webview/ark_web_nweb_wrapper.h | 10 +++++ .../ohos_nweb/include/ark_web_nweb.h | 10 +++++ 10 files changed, 103 insertions(+) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index a7615713..80272cf2 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -593,6 +593,7 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) NapiWebviewController::TrimMemoryByPressureLevel), DECLARE_NAPI_FUNCTION("getScrollOffset", NapiWebviewController::GetScrollOffset), + DECLARE_NAPI_FUNCTION("scrollByWithResult", NapiWebviewController::ScrollByWithResult), }; napi_value constructor = nullptr; napi_define_class(env, WEBVIEW_CONTROLLER_CLASS_NAME.c_str(), WEBVIEW_CONTROLLER_CLASS_NAME.length(), @@ -6395,5 +6396,43 @@ napi_value NapiWebviewController::GetScrollOffset(napi_env env, napi_set_named_property(env, result, "vertical", vertical); return result; } + +napi_value NapiWebviewController::ScrollByWithResult(napi_env env, napi_callback_info info) +{ + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_TWO; + napi_value argv[INTEGER_TWO] = { 0 }; + float deltaX; + float deltaY; + + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + if (argc != INTEGER_TWO) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "two")); + return result; + } + + if (!NapiParseUtils::ParseFloat(env, argv[INTEGER_ZERO], deltaX)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "deltaX", "number")); + return result; + } + + if (!NapiParseUtils::ParseFloat(env, argv[INTEGER_ONE], deltaY)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "deltaY", "number")); + return result; + } + + WebviewController *webviewController = GetWebviewController(env, info); + if (!webviewController) { + return nullptr; + } + + bool scrollByWithResult = webviewController->ScrollByWithResult(deltaX, deltaY); + NAPI_CALL(env, napi_get_boolean(env, scrollByWithResult, &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 e2c5584f..82a9b113 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -359,6 +359,7 @@ private: static napi_value GetScrollOffset(napi_env env, napi_callback_info info); + static napi_value ScrollByWithResult(napi_env env, napi_callback_info info); static int32_t maxFdNum_; static std::atomic usedFd_; }; diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp index fd7be95d..0ac5ee72 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp @@ -2033,5 +2033,15 @@ void WebviewController::GetScrollOffset(float* offset_x, float* offset_y) nweb_ptr->GetScrollOffset(offset_x, offset_y); } } + +bool WebviewController::ScrollByWithResult(float deltaX, float deltaY) +{ + bool enabled = false; + auto nweb_ptr = NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + enabled = nweb_ptr->ScrollByWithResult(deltaX, deltaY); + } + return enabled; +} } // namespace NWeb } // namespace OHOS diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.h b/interfaces/kits/napi/webviewcontroller/webview_controller.h index 4e43b284..60292af2 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.h @@ -389,6 +389,8 @@ public: void CreatePDFPromiseExt( napi_env env, std::shared_ptr pdfConfig, napi_deferred deferred); + + bool ScrollByWithResult(float deltaX, float deltaY); private: int ConverToWebHitTestType(int hitType); diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 34ab2178..233912cc 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -1495,6 +1495,17 @@ public: */ virtual void ExecuteCreatePDFExt(std::shared_ptr pdfConfig, std::shared_ptr callback) {} + + /** + * Scroll by the delta distance if web is not foucsed. + * + * @param delta_x horizontal offset. + * @param delta_y vertical offset. + * @return false if web is focused. + */ + virtual bool ScrollByWithResult(float delta_x, float delta_y) { + return false; + }; }; } // namespace OHOS::NWeb 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 8c6bc160..ff9ccc82 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 @@ -1159,4 +1159,9 @@ void ArkWebNWebImpl::ExecuteCreatePDFExt( std::make_shared(CHECK_REF_PTR_IS_NULL(pdfConfig) ? nullptr : pdfConfig), std::make_shared(callback)); } + +bool ArkWebNWebImpl::ScrollByWithResult(float delta_x, float delta_y) +{ + return nweb_nweb_->ScrollByWithResult(delta_x, delta_y); +} } // 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 6e7fd325..eaddf189 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 @@ -1324,6 +1324,16 @@ public: /*--ark web()--*/ void ExecuteCreatePDFExt( ArkWebRefPtr pdfConfig, ArkWebRefPtr callback) override; + + /** + * Scroll by the delta distance if web is not foucsed. + * + * @param delta_x horizontal offset. + * @param delta_y vertical offset. + * @return false if web is focused. + */ + /*--ark web()--*/ + bool ScrollByWithResult(float delta_x, float delta_y) override; private: std::shared_ptr nweb_nweb_; }; 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 727d3f95..d7d4293f 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 @@ -1359,4 +1359,9 @@ void ArkWebNWebWrapper::ExecuteCreatePDFExt(std::shared_ptrScrollByWithResult(delta_x, delta_y); +} } // 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 63ad7209..b543c48e 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 @@ -1333,6 +1333,16 @@ public: /*--ark web()--*/ void ExecuteCreatePDFExt(std::shared_ptr pdfConfig, std::shared_ptr callback) override; + + /** + * @brief Scroll by the delta distance. + * @param delta_x: horizontal offset. + * @param delta_y: vertical offset. + * @return false if web don't scroll by the delta, when web is focused. + */ + /*--ark web()--*/ + bool ScrollByWithResult(float delta_x, float delta_y) override; + private: ArkWebRefPtr ark_web_nweb_; }; 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 0abe6707..bca0cf6e 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 @@ -1485,6 +1485,16 @@ public: /*--ark web()--*/ virtual void ExecuteCreatePDFExt(ArkWebRefPtr pdfConfig, ArkWebRefPtr callback) = 0; + + /** + * Scroll by the delta distance if web is not foucsed. + * + * @param delta_x horizontal offset. + * @param delta_y vertical offset. + * @return false if web is touched down. + */ + /*--ark web()--*/ + virtual bool ScrollByWithResult(float delta_x, float delta_y) = 0; }; } // namespace OHOS::ArkWeb -- Gitee From 8eb08e4e57e00ffd9cf108782114ac3edbe9aca2 Mon Sep 17 00:00:00 2001 From: fengjinyuan0804 Date: Mon, 12 Aug 2024 23:28:42 +0800 Subject: [PATCH 125/126] tdd dd Signed-off-by: fengjinyuan0804 --- .../unittest/nweb_config_helper_test/BUILD.gn | 53 +++++ .../nweb_config_helper.cpp | 218 ++++++++++++++++++ 2 files changed, 271 insertions(+) create mode 100644 test/unittest/nweb_config_helper_test/BUILD.gn create mode 100644 test/unittest/nweb_config_helper_test/nweb_config_helper.cpp diff --git a/test/unittest/nweb_config_helper_test/BUILD.gn b/test/unittest/nweb_config_helper_test/BUILD.gn new file mode 100644 index 00000000..0725e6f8 --- /dev/null +++ b/test/unittest/nweb_config_helper_test/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 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") +import("../../../web_aafwk.gni") + +module_output_path = "web/webview" + +ohos_unittest("nweb_config_helper_test") { + module_out_path = module_output_path + + sources = [ + "../common/nweb_create_window.cpp", + "nweb_config_helper_test.cpp", + "nweb_helper_test.cpp", + ] + + include_dirs = [ "../common" ] + + deps = [ + "$webview_path/ohos_nweb:web_configs", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_runtime:app_context", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "graphic_2d:librender_service_client", + "hilog:libhilog", + "webview:libnweb", + "window_manager:libwm", + ] + cflags_cc = [ "--coverage" ] + ldflags = [ "--coverage" ] +} + +group("unittest") { + testonly = true + deps = [ ":nweb_config_helper_test" ] +} diff --git a/test/unittest/nweb_config_helper_test/nweb_config_helper.cpp b/test/unittest/nweb_config_helper_test/nweb_config_helper.cpp new file mode 100644 index 00000000..c949e6ad --- /dev/null +++ b/test/unittest/nweb_config_helper_test/nweb_config_helper.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2022 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 "nweb_config_helper.h" +#include "nweb_init_params.h" + +using namespace testing; + +namespace OHOS { +namespace NWebConfig { + +class NWebConfigHelperTest : public ::testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void TearDown(); + +protected: + std::shared_ptr initArgs; + NWebConfigHelper nWebConfigHelper; + void SetUp() override + { + initArgs = std::make_shared(); + } +}; + +HWTEST_F(NWebConfigHelperTest, ParseWebConfigXml_FileNotFound, TestSize.Level0) +{ + std::string configFilePath = "nonexistent.xml"; + EXPECT_NO_THROW(NWebConfigHelper::Instance().ParseWebConfigXml(configFilePath, initArgs)); +} + +HWTEST_F(NWebConfigHelperTest, ParseWebConfigXml_InvalidRootElement, TestSize.Level0) +{ + std::string configFilePath = "invalid_root.xml"; + EXPECT_NO_THROW(NWebConfigHelper::Instance().ParseWebConfigXml(configFilePath, initArgs)); +} + +HWTEST_F(NWebConfigHelperTest, ParseWebConfigXml_ValidInitConfig, TestSize.Level0) +{ + std::string configFilePath = "valid_init.xml"; + EXPECT_NO_THROW(NWebConfigHelper::Instance().ParseWebConfigXml(configFilePath, initArgs)); +} + +HWTEST_F(NWebConfigHelperTest, ParseWebConfigXml_ValidDeleteConfig, TestSize.Level0) +{ + std::string configFilePath = "valid_delete.xml"; + EXPECT_NO_THROW(NWebConfigHelper::Instance().ParseWebConfigXml(configFilePath, initArgs)); +} + +HWTEST_F(NWebConfigHelperTest, ParseWebConfigXml_ValidPerformanceConfig, TestSize.Level0) +{ + std::string configFilePath = "valid_performance.xml"; + EXPECT_NO_THROW(NWebConfigHelper::Instance().ParseWebConfigXml(configFilePath, initArgs)); +} + +HWTEST_F(NWebConfigHelperTest, ParseWebConfigXml_ValidLTPOConfig, TestSize.Level0) +{ + std::string configFilePath = "valid_ltpo.xml"; + EXPECT_NO_THROW(NWebConfigHelper::Instance().ParseWebConfigXml(configFilePath, initArgs)); +} + + +HWTEST_F(NWebConfigHelperTest, GetPerfConfig_ShouldReturnEmptyVector_WhenSettingNameNotExist, TestSize.Level0) +{ + std::string settingName = "NonExistentSetting"; + std::vector result = NWebConfigHelper::Instance().GetPerfConfig(settingName); + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(NWebConfigHelperTest, GetPerfConfig_ShouldReturnNonEmptyVector_WhenSettingNameExist, TestSize.Level0) +{ + std::string settingName = "ExistentSetting"; + NWebConfigHelper::Instance().ltpoConfig_[settingName] = {FrameRateSetting(30)}; + std::vector result = NWebConfigHelper::Instance().GetPerfConfig(settingName); + EXPECT_FALSE(result.empty()); + EXPECT_EQ(result[0].frameRate, 30); +} + +HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_ShouldReturnEmptyString_WhenConfigNotFound, TestSize.Level0) +{ + std::string configNodeName = "non_existent_config"; + std::string argsNodeName = "non_existent_args"; + std::string result = NWebConfigHelper::Instance().ParsePerfConfig(configNodeName, argsNodeName); + EXPECT_EQ(result, ""); +} + +HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_ShouldReturnValue_WhenConfigFound, TestSize.Level0) +{ + std::string configNodeName = "existent_config"; + std::string argsNodeName = "existent_args"; + std::string expectedValue = "expected_value"; + NWebConfigHelper::Instance().perfConfig_[configNodeName + "/" + argsNodeName] = expectedValue; + std::string result = NWebConfigHelper::Instance().ParsePerfConfig(configNodeName, argsNodeName); + EXPECT_EQ(result, expectedValue); +} + +HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_NullNode, TestSize.Level0) +{ + xmlNodePtr node = nullptr; + NWebConfigHelper::Instance().ParsePerfConfig(node); + EXPECT_TRUE(NWebConfigHelper::Instance().perfConfig_.empty()); +} + +HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_CommentNode, TestSize.Level0) +{ + xmlNodePtr node = xmlNewNode(nullptr, "comment"); + NWebConfigHelper::Instance().ParsePerfConfig(node); + EXPECT_TRUE(NWebConfigHelper::Instance().perfConfig_.empty()); + xmlFreeNode(node); +} + +HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_ValidNode, TestSize.Level0) + { + xmlNodePtr node = xmlNewNode(nullptr, "node"); + xmlNodePtr childNode = xmlNewNode(nullptr, "childNode"); + xmlNodeAddContent(childNode, "value"); + xmlAddChild(node, childNode); + NWebConfigHelper::Instance().ParsePerfConfig(node); + EXPECT_EQ(hNWebConfigHelper::Instance().perfConfig_["node/childNode"], "value"); + xmlFreeNode(childNode); + xmlFreeNode(node); +} + +HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_InvalidChildNode, TestSize.Level0) + { + xmlNodePtr node = xmlNewNode(nullptr, "node"); + xmlNodePtr childNode = xmlNewNode(nullptr, "comment"); + xmlAddChild(node, childNode); + NWebConfigHelper::Instance().ParsePerfConfig(node); + EXPECT_TRUE(NWebConfigHelper::Instance().perfConfig_.empty()); + xmlFreeNode(childNode); + xmlFreeNode(node); +} + +HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_NullContent, TestSize.Level0) + { + xmlNodePtr node = xmlNewNode(nullptr, "node"); + xmlNodePtr childNode = xmlNewNode(nullptr, "childNode"); + xmlAddChild(node, childNode); + NWebConfigHelper::Instance().ParsePerfConfig(node); + EXPECT_TRUE(NWebConfigHelper::Instance().perfConfig_.empty()); + xmlFreeNode(childNode); + xmlFreeNode(node); + } + + +HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_NullRootPtr, TestSize.Level0) +{ + xmlNodePtr rootPtr = nullptr; + std::string result = NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs); + EXPECT_NULL(result); +} + + +HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_ValidNode) { + xmlNodePtr rootPtr = xmlNewNode(nullptr, "valid"); + xmlNodePtr childNodePtr = xmlNewNode(nullptr, "child"); + xmlAddChild(rootPtr, childNodePtr); + xmlChar *content = xmlNodeGetContent(childNodePtr); + xmlNodeSetContent(childNodePtr, content); + xmlFree(content); + NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs); +} + +HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_InvalidChildNode) { + xmlNodePtr rootPtr = xmlNewNode(nullptr, "valid"); + xmlNodePtr childNodePtr = xmlNewNode(nullptr, "invalid"); + xmlAddChild(rootPtr, childNodePtr); + NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs); +} + +HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_NullContent) { + xmlNodePtr rootPtr = xmlNewNode(nullptr, "valid"); + xmlNodePtr childNodePtr = xmlNewNode(nullptr, "child"); + xmlAddChild(rootPtr, childNodePtr); + NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs); +} + +HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_NotFoundConfig) { + xmlNodePtr rootPtr = xmlNewNode(nullptr, "valid"); + xmlNodePtr childNodePtr = xmlNewNode(nullptr, "child"); + xmlAddChild(rootPtr, childNodePtr); + xmlChar *content = xmlNodeGetContent(childNodePtr); + xmlNodeSetContent(childNodePtr, content); + xmlFree(content); + NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs); +} + +HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_EmptyParam) { + xmlNodePtr rootPtr = xmlNewNode(nullptr, "valid"); + xmlNodePtr childNodePtr = xmlNewNode(nullptr, "child"); + xmlAddChild(rootPtr, childNodePtr); + xmlChar *content = xmlNodeGetContent(childNodePtr); + xmlNodeSetContent(childNodePtr, content); + xmlFree(content); + NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs); +} + +} // NWebConfig +} // OHOS``` \ No newline at end of file -- Gitee From 484f672f1f934d7f778ac602fd07447248c3b0ff Mon Sep 17 00:00:00 2001 From: Delthin <1059661071@qq.com> Date: Wed, 7 Aug 2024 08:36:36 +0800 Subject: [PATCH 126/126] =?UTF-8?q?Add=2013=20api:=20int32=5Ft=20GetMediaP?= =?UTF-8?q?laybackState()=EF=BC=9B=20void=20CloseCamera();=20void=20StopCa?= =?UTF-8?q?mera();=20void=20StartCamera();=20bool=20GetPrintBackground();?= =?UTF-8?q?=20void=20SetPrintBackground(bool=20enable);=20bool=20GetScroll?= =?UTF-8?q?able();=20void=20SetScrollable(bool=20enable);=20bool=20IsAdsBl?= =?UTF-8?q?ockEnabledForCurPage();=20void=20EnableAdsBlock(bool=20enable);?= =?UTF-8?q?=20bool=20IsAdsBlockEnabled();=20bool=20IsIntelligentTrackingPr?= =?UTF-8?q?eventionEnabled();=20void=20EnableIntelligentTrackingPrevention?= =?UTF-8?q?(bool=20enable);=201=20enum:=20MediaPlaybackState;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Delthin <1059661071@qq.com> --- .../kits/cj/include/webview_controller_impl.h | 33 +++++ interfaces/kits/cj/include/webview_ffi.h | 15 ++ .../kits/cj/src/webview_controller_impl.cpp | 125 +++++++++++++++++ interfaces/kits/cj/src/webview_ffi.cpp | 129 ++++++++++++++++++ 4 files changed, 302 insertions(+) diff --git a/interfaces/kits/cj/include/webview_controller_impl.h b/interfaces/kits/cj/include/webview_controller_impl.h index ddcb4a51..eda733f2 100644 --- a/interfaces/kits/cj/include/webview_controller_impl.h +++ b/interfaces/kits/cj/include/webview_controller_impl.h @@ -50,6 +50,13 @@ namespace OHOS::Webview { DANGEROUS = 5 }; + enum class MediaPlaybackState : int { + NONE = 0, + PLAYING = 1, + PAUSED = 2, + STOPPED = 3 + }; + class __attribute__((visibility("default"))) WebviewControllerImpl : public OHOS::FFI::FFIData { DECL_TYPE(WebviewControllerImpl, OHOS::FFI::FFIData) public: @@ -153,6 +160,32 @@ namespace OHOS::Webview { void Stop(); + int32_t GetMediaPlaybackState(); + + void CloseCamera(); + + void StopCamera(); + + void StartCamera(); + + bool GetPrintBackground(); + + void SetPrintBackground(bool enable); + + bool GetScrollable(); + + void SetScrollable(bool enable); + + bool IsAdsBlockEnabledForCurPage(); + + void EnableAdsBlock(bool enable); + + bool IsAdsBlockEnabled(); + + bool IsIntelligentTrackingPreventionEnabled(); + + void EnableIntelligentTrackingPrevention(bool enable); + public: static std::string customeSchemeCmdLine_; static bool existNweb_; diff --git a/interfaces/kits/cj/include/webview_ffi.h b/interfaces/kits/cj/include/webview_ffi.h index af456fc2..5e76149d 100644 --- a/interfaces/kits/cj/include/webview_ffi.h +++ b/interfaces/kits/cj/include/webview_ffi.h @@ -69,6 +69,21 @@ extern "C" { FFI_EXPORT int32_t FfiOHOSWebviewCtlRemoveCache(int64_t id, bool clearRom); FFI_EXPORT int64_t FfiOHOSWebviewCtlGetBackForwardEntries(int64_t id, int32_t *errCode); FFI_EXPORT int32_t FfiOHOSWebviewCtlStop(int64_t id); + FFI_EXPORT int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlCloseCamera(int64_t id); + FFI_EXPORT int32_t FfiOHOSWebviewCtlStopCamera(int64_t id); + FFI_EXPORT int32_t FfiOHOSWebviewCtlStartCamera(int64_t id); + FFI_EXPORT bool FfiOHOSWebviewCtlGetPrintBackground(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlSetPrintBackground(int64_t id, bool enable); + FFI_EXPORT bool FfiOHOSWebviewCtlGetScrollable(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlSetScrollable(int64_t id, bool enable); + FFI_EXPORT bool FfiOHOSWebviewCtlIsAdsBlockEnabledForCurPage(int64_t id); + FFI_EXPORT void FfiOHOSWebviewCtlEnableAdsBlock(int64_t id, bool enable); + FFI_EXPORT bool FfiOHOSWebviewCtlIsAdsBlockEnabled(int64_t id); + FFI_EXPORT bool FfiOHOSWebviewCtlIsIntelligentTrackingPreventionEnabled(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSWebviewCtlEnableIntelligentTrackingPrevention(int64_t id, bool enable); + // BackForwardList FFI_EXPORT int32_t FfiOHOSBackForwardListCurrentIndex(int64_t id, int32_t *errCode); diff --git a/interfaces/kits/cj/src/webview_controller_impl.cpp b/interfaces/kits/cj/src/webview_controller_impl.cpp index 10b83226..267428db 100644 --- a/interfaces/kits/cj/src/webview_controller_impl.cpp +++ b/interfaces/kits/cj/src/webview_controller_impl.cpp @@ -607,4 +607,129 @@ namespace OHOS::Webview { } return; } + + int32_t WebviewControllerImpl::GetMediaPlaybackState() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return static_cast(MediaPlaybackState::NONE); + } + return nweb_ptr->GetMediaPlaybackState(); + } + + void WebviewControllerImpl::CloseCamera() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + return nweb_ptr->CloseCamera(); + } + return; + } + + void WebviewControllerImpl::StopCamera() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + return nweb_ptr->StopCamera(); + } + return; + } + + void WebviewControllerImpl::StartCamera() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + return nweb_ptr->StartCamera(); + } + return; + } + + bool WebviewControllerImpl::GetPrintBackground() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->GetPrintBackground(); + } + + void WebviewControllerImpl::SetPrintBackground(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->SetPrintBackground(enable); + } + return; + } + + bool WebviewControllerImpl::GetScrollable() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return true; + } + std::shared_ptr setting = nweb_ptr->GetPreference(); + if (!setting) { + return true; + } + return setting->GetScrollable(); + } + + void WebviewControllerImpl::SetScrollable(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return; + } + std::shared_ptr setting = nweb_ptr->GetPreference(); + if (!setting) { + return; + } + return setting->SetScrollable(enable); + } + + bool WebviewControllerImpl::IsAdsBlockEnabledForCurPage() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->IsAdsBlockEnabledForCurPage(); + } + + void WebviewControllerImpl::EnableAdsBlock(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->EnableAdsBlock(enable); + } + return; + } + + bool WebviewControllerImpl::IsAdsBlockEnabled() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->IsAdsBlockEnabled(); + } + + bool WebviewControllerImpl::IsIntelligentTrackingPreventionEnabled() + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return false; + } + return nweb_ptr->IsIntelligentTrackingPreventionEnabled(); + } + + void WebviewControllerImpl::EnableIntelligentTrackingPrevention(bool enable) + { + auto nweb_ptr = NWeb::NWebHelper::Instance().GetNWeb(nwebId_); + if (nweb_ptr) { + nweb_ptr->EnableIntelligentTrackingPrevention(enable); + } + return; + } } diff --git a/interfaces/kits/cj/src/webview_ffi.cpp b/interfaces/kits/cj/src/webview_ffi.cpp index 62028c2a..2b7109ef 100644 --- a/interfaces/kits/cj/src/webview_ffi.cpp +++ b/interfaces/kits/cj/src/webview_ffi.cpp @@ -643,6 +643,135 @@ extern "C" { return NWebError::NO_ERROR; } + int32_t FfiOHOSWebviewCtlGetMediaPlaybackState(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + } + return nativeWebviewCtl->GetMediaPlaybackState(); + } + + int32_t FfiOHOSWebviewCtlCloseCamera(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->CloseCamera(); + return NWebError::NO_ERROR; + } + + int32_t FfiOHOSWebviewCtlStopCamera(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->StopCamera(); + return NWebError::NO_ERROR; + } + + int32_t FfiOHOSWebviewCtlStartCamera(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->StartCamera(); + return NWebError::NO_ERROR; + } + + bool FfiOHOSWebviewCtlGetPrintBackground(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool printBackground = nativeWebviewCtl->GetPrintBackground(); + *errCode = NWebError::NO_ERROR; + return printBackground; + } + + int32_t FfiOHOSWebviewCtlSetPrintBackground(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->SetPrintBackground(enable); + return NWebError::NO_ERROR; + } + + bool FfiOHOSWebviewCtlGetScrollable(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool scrollable = nativeWebviewCtl->GetScrollable(); + *errCode = NWebError::NO_ERROR; + return scrollable; + } + + int32_t FfiOHOSWebviewCtlSetScrollable(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->SetScrollable(enable); + return NWebError::NO_ERROR; + } + + bool FfiOHOSWebviewCtlIsAdsBlockEnabledForCurPage(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return false; + } + return nativeWebviewCtl->IsAdsBlockEnabledForCurPage(); + } + + void FfiOHOSWebviewCtlEnableAdsBlock(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + nativeWebviewCtl->EnableAdsBlock(enable); + } + + bool FfiOHOSWebviewCtlIsAdsBlockEnabled(int64_t id) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return false; + } + return nativeWebviewCtl->IsAdsBlockEnabled(); + } + + bool FfiOHOSWebviewCtlIsIntelligentTrackingPreventionEnabled(int64_t id, int32_t *errCode) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + *errCode = NWebError::INIT_ERROR; + return false; + } + bool intelligentTrackingPreventionEnabled = nativeWebviewCtl->IsIntelligentTrackingPreventionEnabled(); + *errCode = NWebError::NO_ERROR; + return intelligentTrackingPreventionEnabled; + } + + int32_t FfiOHOSWebviewCtlEnableIntelligentTrackingPrevention(int64_t id, bool enable) + { + auto nativeWebviewCtl = FFIData::GetData(id); + if (nativeWebviewCtl == nullptr || !nativeWebviewCtl->IsInit()) { + return NWebError::INIT_ERROR; + } + nativeWebviewCtl->EnableIntelligentTrackingPrevention(enable); + return NWebError::NO_ERROR; + } + // BackForwardList int32_t FfiOHOSBackForwardListCurrentIndex(int64_t id, int32_t *errCode) { -- Gitee