From d283aa27fc85904b83f5d4354d75ede3e4456412 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Mon, 14 Jul 2025 20:33:01 +0800 Subject: [PATCH 001/124] =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E7=BC=96=E8=AF=91-?= =?UTF-8?q?=E9=85=8D=E5=90=88ability=5Fruntime=E5=88=A0=E9=99=A4public=5Fd?= =?UTF-8?q?eps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangzezhong --- ohos_adapter/BUILD.gn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index eb837da1a..ac73dd1ab 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -164,6 +164,7 @@ ohos_shared_library("nweb_ohos_adapter") { external_deps = [ "ability_base:extractortool", "ability_base:zuri", + "ability_runtime:ability_connect_callback_stub", "ability_runtime:ability_manager", "ability_runtime:abilitykit_native", "ability_runtime:app_context", -- Gitee From 7e9135c77a07bad43c1881f61cfc93466c3de927 Mon Sep 17 00:00:00 2001 From: yuzhouhang1 Date: Fri, 8 Aug 2025 14:55:26 +0800 Subject: [PATCH 002/124] change error log Signed-off-by: yuzhouhang --- .../src/ohos_resource_adapter_impl.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 0a58df645..1d579fa9b 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 @@ -486,14 +486,14 @@ std::string OhosResourceAdapterImpl::GetArkWebVersion() for (const auto& hapPath : hapPaths) { OHOS::AbilityBase::Extractor extractor(hapPath); if (!extractor.Init()) { - WVLOG_W("Failed to initialize extractor for HAP file: %{public}s", hapPath.c_str()); + WVLOG_E("Failed to initialize extractor for HAP file: %{public}s", hapPath.c_str()); continue; } std::ostringstream contentStream; bool ret = extractor.ExtractByName(packInfoPath, contentStream); if (!ret) { - WVLOG_W("Failed to extract pack.info from HAP: %{public}s", hapPath.c_str()); + WVLOG_E("Failed to extract pack.info from HAP: %{public}s", hapPath.c_str()); continue; } @@ -502,7 +502,7 @@ std::string OhosResourceAdapterImpl::GetArkWebVersion() Json::Value root; Json::Reader reader; if (!reader.parse(configContent, root)) { - WVLOG_W("Failed to parse pack.info from HAP: %{public}s", hapPath.c_str()); + WVLOG_E("Failed to parse pack.info from HAP: %{public}s", hapPath.c_str()); continue; } @@ -513,10 +513,10 @@ std::string OhosResourceAdapterImpl::GetArkWebVersion() return root["summary"]["app"]["version"]["name"].asString(); } - WVLOG_W("Version information not found in pack.info from HAP: %{public}s", hapPath.c_str()); + WVLOG_E("Version information not found in pack.info from HAP: %{public}s", hapPath.c_str()); } - WVLOG_W("Failed to get ArkWeb version from any of the specified paths"); + WVLOG_E("Failed to get ArkWeb version from any of the specified paths"); return ""; } -- Gitee From 38fddc1774176c2426c992b269081b7ca89c0a95 Mon Sep 17 00:00:00 2001 From: yourkindfather Date: Mon, 11 Aug 2025 11:36:46 +0800 Subject: [PATCH 003/124] =?UTF-8?q?=E5=8F=8C=E5=86=85=E6=A0=B8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AE=8F=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yourkindfather --- .../napi_webview_controller.cpp | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index df4f69f36..00b7b20b8 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -1187,7 +1187,8 @@ napi_value NapiWebviewController::SetWebDebuggingAccess(napi_env env, napi_callb } } - if (ArkWeb::getActiveWebEngineVersion() < ArkWeb::ArkWebEngineVersion::M132) { + if (IS_CALLING_FROM_M114()) { + WVLOG_W("SetWebDebuggingAccess unsupported engine version: M114"); webDebuggingPort = 0; } @@ -2899,7 +2900,9 @@ napi_value NapiWebviewController::GetTitle(napi_env env, napi_callback_info info napi_value NapiWebviewController::GetProgress(napi_env env, napi_callback_info info) { - if (ArkWeb::getActiveWebEngineVersion() < ArkWeb::ArkWebEngineVersion::M132) { + if (IS_CALLING_FROM_M114()) { + WVLOG_W("GetProgress unsupported engine version: M114"); + BusinessError::ThrowErrorByErrcode(env, CAPABILITY_NOT_SUPPORTED_ERROR); return nullptr; } @@ -6164,7 +6167,8 @@ napi_value NapiWebviewController::SetBackForwardCacheOptions(napi_env env, napi_ napi_value NapiWebviewController::SetAppCustomUserAgent(napi_env env, napi_callback_info info) { - if (ArkWeb::getActiveWebEngineVersion() < ArkWeb::ArkWebEngineVersion::M132) { + if (IS_CALLING_FROM_M114()) { + WVLOG_W("SetAppCustomUserAgent unsupported engine version: M114"); return nullptr; } @@ -6194,7 +6198,8 @@ napi_value NapiWebviewController::SetAppCustomUserAgent(napi_env env, napi_callb napi_value NapiWebviewController::SetUserAgentForHosts(napi_env env, napi_callback_info info) { - if (ArkWeb::getActiveWebEngineVersion() < ArkWeb::ArkWebEngineVersion::M132) { + if (IS_CALLING_FROM_M114()) { + WVLOG_W("SetUserAgentForHosts unsupported engine version: M114"); return nullptr; } @@ -7392,7 +7397,8 @@ napi_value NapiWebviewController::AvoidVisibleViewportBottom(napi_env env, napi_ napi_value NapiWebviewController::SetErrorPageEnabled(napi_env env, napi_callback_info info) { - if (ArkWeb::getActiveWebEngineVersion() < ArkWeb::ArkWebEngineVersion::M132) { + if (IS_CALLING_FROM_M114()) { + WVLOG_W("SetErrorPageEnabled unsupported engine version: M114"); return nullptr; } @@ -7434,7 +7440,8 @@ napi_value NapiWebviewController::GetErrorPageEnabled(napi_env env, napi_callbac { napi_value result = nullptr; bool getErrorPageEnabled = false; - if (ArkWeb::getActiveWebEngineVersion() < ArkWeb::ArkWebEngineVersion::M132) { + if (IS_CALLING_FROM_M114()) { + WVLOG_W("GetErrorPageEnabled unsupported engine version: M114"); NAPI_CALL(env, napi_get_boolean(env, getErrorPageEnabled, &result)); return result; } @@ -7584,6 +7591,7 @@ napi_value ArkWebTransfer::CreateWebMessagePortTransfer(napi_env env, napi_callb napi_value NapiWebviewController::EnablePrivateNetworkAccess(napi_env env, napi_callback_info info) { if (IS_CALLING_FROM_M114()) { + WVLOG_W("EnablePrivateNetworkAccess unsupported engine version: M114"); return nullptr; } @@ -7616,7 +7624,8 @@ napi_value NapiWebviewController::IsPrivateNetworkAccessEnabled(napi_env env, na { napi_value result = nullptr; bool pnaEnabled = false; - if (ArkWeb::getActiveWebEngineVersion() < ArkWeb::ArkWebEngineVersion::M132) { + if (IS_CALLING_FROM_M114()) { + WVLOG_W("IsPrivateNetworkAccessEnabled unsupported engine version: M114"); NAPI_CALL(env, napi_get_boolean(env, pnaEnabled, &result)); return result; } -- Gitee From fbd5199409afe33689a55fea33c46a29a0c503e0 Mon Sep 17 00:00:00 2001 From: sunbin55 Date: Tue, 12 Aug 2025 11:11:09 +0800 Subject: [PATCH 004/124] =?UTF-8?q?IssueNo:#ICSHB9:[Bug]:=20=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5=E3=80=82=20Descri?= =?UTF-8?q?ption:=20=E6=B8=B2=E6=9F=93=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=20Sig:=20SIG=5FApplicationFramework=20Feature=20or=20Bugfix:?= =?UTF-8?q?=20(Bugfix)=20Binary=20Source:=20No=20=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=B6=89=E5=8F=8A=E9=9D=9E=E5=85=BC=E5=AE=B9=E5=8F=98=E6=9B=B4?= =?UTF-8?q?:=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20TDD=E8=87=AA=E9=AA=8C?= =?UTF-8?q?=E7=BB=93=E6=9E=9C(=E5=A6=82=E6=9C=89=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90=E4=BE=9B=E5=9F=BA=E7=BA=BF?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5):=20(=E4=B8=8D=E6=B6=89?= =?UTF-8?q?=E5=8F=8A)=20XTS=E8=87=AA=E9=AA=8C=E7=BB=93=E6=9E=9C(=E5=A6=82?= =?UTF-8?q?=E6=9C=89=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E5=9F=BA=E7=BA=BF=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5?= =?UTF-8?q?):=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20Signed-off-by:=20sunbin55?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ark_ohos_drawing_text_adapter_wrapper.cpp | 6 +- .../ark_ohos_drawing_text_adapter_impl.cpp | 2 +- .../ark_ohos_drawing_text_adapter_impl.h | 16 +- .../drawing_text_adapter_test.cpp | 414 +++++++++--------- 4 files changed, 219 insertions(+), 219 deletions(-) diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.cpp index 4a095186a..573935e13 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.cpp @@ -25,7 +25,7 @@ ArkOhosDrawingTextFontAdapterWrapper::ArkOhosDrawingTextFontAdapterWrapper( int ArkOhosDrawingTextFontAdapterWrapper::GetSystemFontFullNamesByType(int32_t systemFontType, void** drawingArray) { - if (!ctocpp_) { + if (!ctocpp_) { WVLOG_E("ArkOhosDrawingTextFontAdapterWrapper::GetSystemFontFullNamesByType, ctocpp_ is null."); return -1; } @@ -90,7 +90,7 @@ int ArkOhosDrawingTextTypographyAdapterWrapper::GetDrawingArraySize(void* drawin WVLOG_E("ArkOhosDrawingTextTypographyAdapterWrapper::GetDrawingArraySize, ctocpp_ is null."); return -1; } - return ctocpp_->GetDrawingArraySize(drawingArray, sizeOfArray); + return ctocpp_->GetDrawingArraySize(drawingArray, sizeOfArray); } void ArkOhosDrawingTextTypographyAdapterWrapper::DestroySystemFontConfigInfo(void* fontConfigInfo) @@ -101,4 +101,4 @@ void ArkOhosDrawingTextTypographyAdapterWrapper::DestroySystemFontConfigInfo(voi } ctocpp_->DestroySystemFontConfigInfo(fontConfigInfo); } -} //namespace OHOS::ArkWeb \ No newline at end of file +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_drawing_text_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_drawing_text_adapter_impl.cpp index 1be2fbbc8..7a1833b07 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_drawing_text_adapter_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_drawing_text_adapter_impl.cpp @@ -54,7 +54,7 @@ ArkOhosDrawingTextTypographyAdapterImpl::ArkOhosDrawingTextTypographyAdapterImpl NWeb::OhosDrawingTextTypographyAdapter& ref) : real_(ref) {} int ArkOhosDrawingTextTypographyAdapterImpl::GetSystemFontConfigInfo(void* fontConfigInfoErrorCode, - void** fontConfigInfo) + void** fontConfigInfo) { return real_.GetSystemFontConfigInfo(fontConfigInfoErrorCode, fontConfigInfo); } diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_drawing_text_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_drawing_text_adapter_impl.h index 8f3cb0542..95ecb9fc4 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_drawing_text_adapter_impl.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_ohos_drawing_text_adapter_impl.h @@ -24,22 +24,22 @@ namespace OHOS::ArkWeb { class ArkOhosDrawingTextFontAdapterImpl : public ArkOhosDrawingTextFontAdapter { public: - ArkOhosDrawingTextFontAdapterImpl(NWeb::OhosDrawingTextFontAdapter&); + ArkOhosDrawingTextFontAdapterImpl(NWeb::OhosDrawingTextFontAdapter&); - int GetSystemFontFullNamesByType(int32_t systemFontType, void** drawingArray) override; + int GetSystemFontFullNamesByType(int32_t systemFontType, void** drawingArray) override; - int GetFontDescriptorByFullName(void* drawingString, int32_t systemFontType, void** drawingFontDescriptor) override; + int GetFontDescriptorByFullName(void* drawingString, int32_t systemFontType, void** drawingFontDescriptor) override; - int GetSystemFontFullNameByIndex(void* drawingArray, int32_t indexOfFullName, const void** drawingString) override; + int GetSystemFontFullNameByIndex(void* drawingArray, int32_t indexOfFullName, const void** drawingString) override; - void DestroySystemFontFullNames(void* drawingArray) override; + void DestroySystemFontFullNames(void* drawingArray) override; - void DestroyFontDescriptor(void* descriptor) override; + void DestroyFontDescriptor(void* descriptor) override; private: - OHOS::NWeb::OhosDrawingTextFontAdapter& real_; + OHOS::NWeb::OhosDrawingTextFontAdapter& real_; - IMPLEMENT_REFCOUNTING(ArkOhosDrawingTextFontAdapterImpl); + IMPLEMENT_REFCOUNTING(ArkOhosDrawingTextFontAdapterImpl); }; class ArkOhosDrawingTextTypographyAdapterImpl : public ArkOhosDrawingTextTypographyAdapter { diff --git a/test/unittest/ohos_adapter/drawing_text_adapter_test/drawing_text_adapter_test.cpp b/test/unittest/ohos_adapter/drawing_text_adapter_test/drawing_text_adapter_test.cpp index cdb972515..545c3ed74 100644 --- a/test/unittest/ohos_adapter/drawing_text_adapter_test/drawing_text_adapter_test.cpp +++ b/test/unittest/ohos_adapter/drawing_text_adapter_test/drawing_text_adapter_test.cpp @@ -13,209 +13,209 @@ * limitations under the License. */ - #include - #include - - #include "ohos_adapter_helper.h" - - #define private public - #include "ohos_drawing_text_adapter_impl.h" - #include "ohos_drawing_text_adapter.h" - - using namespace testing; - using namespace testing::ext; - - namespace OHOS { - namespace NWeb { - namespace { - const int NWEB_ERROR = -1; - const int RESULT_OK = 0; - } - - class DrawingTextAdapterImplTest : public testing::Test { - public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); - }; - - void DrawingTextAdapterImplTest::SetUpTestCase() {} - - void DrawingTextAdapterImplTest::TearDownTestCase() {} - - void DrawingTextAdapterImplTest::SetUp() {} - - void DrawingTextAdapterImplTest::TearDown() {} - - /** - * @tc.name: DrawingTextAdapterImplTest_001. - * @tc.desc: test DrawingTextFontAdapterImpl GetSystemFontFullNamesByType. - * @tc.type: FUNC. - * @tc.require: - */ - HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_001, TestSize.Level1) - { - std::shared_ptr drawingTextFontAdapter = - std::make_shared(); - EXPECT_TRUE(drawingTextFontAdapter != nullptr); - - ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::ALL; - void* drawingArray = nullptr; - int32_t errorCode = drawingTextFontAdapter->GetSystemFontFullNamesByType(systemFontType, &drawingArray); - EXPECT_EQ(errorCode, RESULT_OK); - EXPECT_NE(drawingArray, nullptr); - - systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; - errorCode = drawingTextFontAdapter->GetSystemFontFullNamesByType(systemFontType, &drawingArray); - EXPECT_EQ(errorCode, RESULT_OK); - } - - /** - * @tc.name: DrawingTextAdapterImplTest_002. - * @tc.desc: test DrawingTextFontAdapterImpl GetFontDescriptorByFullName. - * @tc.type: FUNC. - * @tc.require: - */ - HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_002, TestSize.Level1) - { - std::shared_ptr drawingTextFontAdapter = - std::make_shared(); - EXPECT_TRUE(drawingTextFontAdapter != nullptr); - - void* drawingString = nullptr; - ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; - void* drawingFontDescriptor = nullptr; - int32_t errorCode = drawingTextFontAdapter->GetFontDescriptorByFullName( - drawingString, systemFontType, &drawingFontDescriptor); - - EXPECT_EQ(errorCode, NWEB_ERROR); - EXPECT_EQ(drawingFontDescriptor, nullptr); - } - - /** - * @tc.name: DrawingTextAdapterImplTest_003. - * @tc.desc: test DrawingTextFontAdapterImpl GetSystemFontFullNameByIndex. - * @tc.type: FUNC. - * @tc.require: - */ - HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_003, TestSize.Level1) - { - std::shared_ptr drawingTextFontAdapter = - std::make_shared(); - EXPECT_TRUE(drawingTextFontAdapter != nullptr); - - void* drawingArray = nullptr; - int32_t indexOfFullName = 0; - const void* drawingString = nullptr; - int32_t errorCode = drawingTextFontAdapter->GetSystemFontFullNameByIndex( - drawingArray, indexOfFullName, &drawingString); - - EXPECT_EQ(errorCode, NWEB_ERROR); - EXPECT_EQ(drawingArray, nullptr); - } - - /** - * @tc.name: DrawingTextAdapterImplTest_004. - * @tc.desc: test DrawingTextFontAdapterImpl DestroySystemFontFullNames. - * @tc.type: FUNC. - * @tc.require: - */ - HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_004, TestSize.Level1) - { - std::shared_ptr drawingTextFontAdapter = - std::make_shared(); - EXPECT_TRUE(drawingTextFontAdapter != nullptr); - - void* drawingArray = nullptr; - drawingTextFontAdapter->DestroySystemFontFullNames(drawingArray); - - EXPECT_EQ(drawingArray, nullptr); - } - - /** - * @tc.name: DrawingTextAdapterImplTest_005. - * @tc.desc: test OhosDrawingTextTypographyAdapterImpl GetSystemFontConfigInfo. - * @tc.type: FUNC. - * @tc.require: - */ - HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_005, TestSize.Level1) - { - std::shared_ptr drawingTextTypographyAdapter = - std::make_shared(); - EXPECT_TRUE(drawingTextTypographyAdapter != nullptr); - - void* fontConfigInfoErrorCode = nullptr; - void* fontConfigInfo = nullptr; - int32_t errorCode = drawingTextTypographyAdapter->GetSystemFontConfigInfo(fontConfigInfoErrorCode, - &fontConfigInfo); - - EXPECT_EQ(errorCode, RESULT_OK); - EXPECT_NE(fontConfigInfo, nullptr); - } - - /** - * @tc.name: DrawingTextAdapterImplTest_006. - * @tc.desc: test OhosDrawingTextTypographyAdapterImpl GetDrawingArraySize. - * @tc.type: FUNC. - * @tc.require: - */ - HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_006, TestSize.Level1) - { - std::shared_ptr drawingTextTypographyAdapter = - std::make_shared(); - EXPECT_TRUE(drawingTextTypographyAdapter != nullptr); - - void* drawingArray = nullptr; - int32_t sizeOfArray = 0; - int32_t errorCode = drawingTextTypographyAdapter->GetDrawingArraySize(drawingArray, sizeOfArray); - - EXPECT_EQ(errorCode, RESULT_OK); - EXPECT_NE(sizeOfArray, NWEB_ERROR); - } - - /** - * @tc.name: DrawingTextAdapterImplTest_007. - * @tc.desc: test OhosDrawingTextTypographyAdapterImpl DestroySystemFontConfigInfo. - * @tc.type: FUNC. - * @tc.require: - */ - HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_007, TestSize.Level1) - { - std::shared_ptr drawingTextTypographyAdapter = - std::make_shared(); - EXPECT_TRUE(drawingTextTypographyAdapter != nullptr); - - void* fontConfigInfo = nullptr; - drawingTextTypographyAdapter->DestroySystemFontConfigInfo(fontConfigInfo); - - EXPECT_EQ(fontConfigInfo, nullptr); - } - - /** - * @tc.name: DrawingTextAdapterImplTest_008. - * @tc.desc: test OhosDrawingTextTypographyAdapterImpl DestroySystemFontDescriptor. - * @tc.type: FUNC. - * @tc.require: - */ - HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_008, TestSize.Level1) - { - std::shared_ptr drawingTextFontAdapter = - std::make_shared(); - EXPECT_TRUE(drawingTextFontAdapter != nullptr); - - void* drawingString = nullptr; - ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; - void* drawingFontDescriptor = nullptr; - int32_t errorCode = drawingTextFontAdapter->GetFontDescriptorByFullName( - drawingString, systemFontType, &drawingFontDescriptor); - - EXPECT_EQ(errorCode, NWEB_ERROR); - drawingTextFontAdapter->DestroyFontDescriptor(drawingFontDescriptor); - drawingFontDescriptor = nullptr; - } - - /** +#include +#include + +#include "ohos_adapter_helper.h" + +#define private public +#include "ohos_drawing_text_adapter_impl.h" +#include "ohos_drawing_text_adapter.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace NWeb { +namespace { +const int NWEB_ERROR = -1; +const int RESULT_OK = 0; +} + +class DrawingTextAdapterImplTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void DrawingTextAdapterImplTest::SetUpTestCase() {} + +void DrawingTextAdapterImplTest::TearDownTestCase() {} + +void DrawingTextAdapterImplTest::SetUp() {} + +void DrawingTextAdapterImplTest::TearDown() {} + +/** + * @tc.name: DrawingTextAdapterImplTest_001. + * @tc.desc: test DrawingTextFontAdapterImpl GetSystemFontFullNamesByType. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_001, TestSize.Level1) +{ + std::shared_ptr drawingTextFontAdapter = + std::make_shared(); + EXPECT_TRUE(drawingTextFontAdapter != nullptr); + + ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::ALL; + void* drawingArray = nullptr; + int32_t errorCode = drawingTextFontAdapter->GetSystemFontFullNamesByType(systemFontType, &drawingArray); + EXPECT_EQ(errorCode, RESULT_OK); + EXPECT_NE(drawingArray, nullptr); + + systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; + errorCode = drawingTextFontAdapter->GetSystemFontFullNamesByType(systemFontType, &drawingArray); + EXPECT_EQ(errorCode, RESULT_OK); +} + +/** + * @tc.name: DrawingTextAdapterImplTest_002. + * @tc.desc: test DrawingTextFontAdapterImpl GetFontDescriptorByFullName. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_002, TestSize.Level1) +{ + std::shared_ptr drawingTextFontAdapter = + std::make_shared(); + EXPECT_TRUE(drawingTextFontAdapter != nullptr); + + void* drawingString = nullptr; + ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; + void* drawingFontDescriptor = nullptr; + int32_t errorCode = drawingTextFontAdapter->GetFontDescriptorByFullName( + drawingString, systemFontType, &drawingFontDescriptor); + + EXPECT_EQ(errorCode, NWEB_ERROR); + EXPECT_EQ(drawingFontDescriptor, nullptr); +} + +/** + * @tc.name: DrawingTextAdapterImplTest_003. + * @tc.desc: test DrawingTextFontAdapterImpl GetSystemFontFullNameByIndex. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_003, TestSize.Level1) +{ + std::shared_ptr drawingTextFontAdapter = + std::make_shared(); + EXPECT_TRUE(drawingTextFontAdapter != nullptr); + + void* drawingArray = nullptr; + int32_t indexOfFullName = 0; + const void* drawingString = nullptr; + int32_t errorCode = drawingTextFontAdapter->GetSystemFontFullNameByIndex( + drawingArray, indexOfFullName, &drawingString); + + EXPECT_EQ(errorCode, NWEB_ERROR); + EXPECT_EQ(drawingArray, nullptr); +} + +/** + * @tc.name: DrawingTextAdapterImplTest_004. + * @tc.desc: test DrawingTextFontAdapterImpl DestroySystemFontFullNames. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_004, TestSize.Level1) +{ + std::shared_ptr drawingTextFontAdapter = + std::make_shared(); + EXPECT_TRUE(drawingTextFontAdapter != nullptr); + + void* drawingArray = nullptr; + drawingTextFontAdapter->DestroySystemFontFullNames(drawingArray); + + EXPECT_EQ(drawingArray, nullptr); +} + +/** + * @tc.name: DrawingTextAdapterImplTest_005. + * @tc.desc: test OhosDrawingTextTypographyAdapterImpl GetSystemFontConfigInfo. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_005, TestSize.Level1) +{ + std::shared_ptr drawingTextTypographyAdapter = + std::make_shared(); + EXPECT_TRUE(drawingTextTypographyAdapter != nullptr); + + void* fontConfigInfoErrorCode = nullptr; + void* fontConfigInfo = nullptr; + int32_t errorCode = drawingTextTypographyAdapter->GetSystemFontConfigInfo(fontConfigInfoErrorCode, + &fontConfigInfo); + + EXPECT_EQ(errorCode, RESULT_OK); + EXPECT_NE(fontConfigInfo, nullptr); +} + +/** + * @tc.name: DrawingTextAdapterImplTest_006. + * @tc.desc: test OhosDrawingTextTypographyAdapterImpl GetDrawingArraySize. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_006, TestSize.Level1) +{ + std::shared_ptr drawingTextTypographyAdapter = + std::make_shared(); + EXPECT_TRUE(drawingTextTypographyAdapter != nullptr); + + void* drawingArray = nullptr; + int32_t sizeOfArray = 0; + int32_t errorCode = drawingTextTypographyAdapter->GetDrawingArraySize(drawingArray, sizeOfArray); + + EXPECT_EQ(errorCode, RESULT_OK); + EXPECT_NE(sizeOfArray, NWEB_ERROR); +} + +/** + * @tc.name: DrawingTextAdapterImplTest_007. + * @tc.desc: test OhosDrawingTextTypographyAdapterImpl DestroySystemFontConfigInfo. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_007, TestSize.Level1) +{ + std::shared_ptr drawingTextTypographyAdapter = + std::make_shared(); + EXPECT_TRUE(drawingTextTypographyAdapter != nullptr); + + void* fontConfigInfo = nullptr; + drawingTextTypographyAdapter->DestroySystemFontConfigInfo(fontConfigInfo); + + EXPECT_EQ(fontConfigInfo, nullptr); +} + +/** + * @tc.name: DrawingTextAdapterImplTest_008. + * @tc.desc: test OhosDrawingTextTypographyAdapterImpl DestroySystemFontDescriptor. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_008, TestSize.Level1) +{ + std::shared_ptr drawingTextFontAdapter = + std::make_shared(); + EXPECT_TRUE(drawingTextFontAdapter != nullptr); + + void* drawingString = nullptr; + ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; + void* drawingFontDescriptor = nullptr; + int32_t errorCode = drawingTextFontAdapter->GetFontDescriptorByFullName( + drawingString, systemFontType, &drawingFontDescriptor); + + EXPECT_EQ(errorCode, NWEB_ERROR); + drawingTextFontAdapter->DestroyFontDescriptor(drawingFontDescriptor); + drawingFontDescriptor = nullptr; +} + +/** * @tc.name : DrawingTextAdapterImplTest_009 * @tc.number: Test GetSystemFontFullNamesByType function when drawingArray is nullptr * @tc.desc : FUNC. @@ -228,7 +228,7 @@ HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_009, TestSize.Le void* drawingArray = nullptr; EXPECT_EQ(-1, drawingTextFontAdapter->GetSystemFontFullNamesByType(systemFontType, &drawingArray)); } - + /** * @tc.name : DrawingTextAdapterImplTest_010 * @tc.number: Test if GetInstance() returns the same instance when called multiple times. @@ -242,7 +242,7 @@ HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_010, TestSize.Le auto& instance2 = drawingTextFontAdapter->GetInstance(); EXPECT_EQ(&instance1, &instance2); } - + /** * @tc.name : DrawingTextAdapterImplTest_011 * @tc.number: Test GetInstance function to ensure it returns the same instance on multiple calls @@ -257,5 +257,5 @@ HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_011, TestSize.Le auto& instance2 = drawingTextFontAdapter->GetInstance(); EXPECT_EQ(&instance1, &instance2); } - } // namespace NWeb - } // namespace OHOS \ No newline at end of file +} // namespace NWeb +} // namespace OHOS \ No newline at end of file -- Gitee From 74211df175a7d7fe59bb130b841ee7ef07bc9c05 Mon Sep 17 00:00:00 2001 From: ZhaoPengfei Date: Tue, 12 Aug 2025 11:17:00 +0800 Subject: [PATCH 005/124] move callback into locked area Signed-off-by: ZhaoPengfei --- .../graphic_adapter/include/vsync_adapter_impl.h | 1 - .../graphic_adapter/src/vsync_adapter_impl.cpp | 14 +++++--------- .../graphic_adapter_test/graphic_adapter_test.cpp | 1 + 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h b/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h index ee5ad1b0c..b29b2267d 100644 --- a/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h +++ b/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h @@ -65,7 +65,6 @@ private: }; std::shared_ptr frameRateLinker_; static void (*callback_)(); - static void (*onVsyncEndCallback_)(); bool frameRateLinkerEnable_ = false; bool isGPUProcess_ = false; std::string pkgName_ {""}; diff --git a/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp b/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp index 5db1fdac0..b7659644c 100644 --- a/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp +++ b/ohos_adapter/graphic_adapter/src/vsync_adapter_impl.cpp @@ -33,7 +33,6 @@ const std::string APS_CLIENT_SO = "/system/lib64/libaps_client.z.so"; } void (*VSyncAdapterImpl::callback_)() = nullptr; -void (*VSyncAdapterImpl::onVsyncEndCallback_)() = nullptr; VSyncAdapterImpl::~VSyncAdapterImpl() { @@ -127,13 +126,7 @@ void VSyncAdapterImpl::OnVsync(int64_t timestamp, void* client) { auto vsyncClient = static_cast(client); if (vsyncClient) { - if (callback_) { - callback_(); - } vsyncClient->VsyncCallbackInner(timestamp); - if (onVsyncEndCallback_) { - onVsyncEndCallback_(); - } } else { WVLOG_E("VsyncClient is null"); } @@ -143,6 +136,10 @@ void VSyncAdapterImpl::VsyncCallbackInner(int64_t timestamp) { std::unordered_map vsyncCallbacks; std::lock_guard lock(mtx_); + if (callback_) { + callback_(); + } + vsyncCallbacks = vsyncCallbacks_; vsyncCallbacks_.clear(); @@ -199,13 +196,12 @@ void VSyncAdapterImpl::SetFramePreferredRate(int32_t preferredRate) void VSyncAdapterImpl::SetOnVsyncCallback(void (*callback)()) { WVLOG_D("callback function: %{public}ld", (long)callback); + std::lock_guard lock(mtx_); callback_ = callback; } void VSyncAdapterImpl::SetOnVsyncEndCallback(void (*onVsyncEndCallback)()) { - WVLOG_D("onVsyncEndCallback function: %{public}ld", (long)onVsyncEndCallback); - onVsyncEndCallback_ = onVsyncEndCallback; } void VSyncAdapterImpl::SetIsGPUProcess(bool isGPU) diff --git a/test/unittest/ohos_adapter/graphic_adapter_test/graphic_adapter_test.cpp b/test/unittest/ohos_adapter/graphic_adapter_test/graphic_adapter_test.cpp index 00830b863..a56728b65 100644 --- a/test/unittest/ohos_adapter/graphic_adapter_test/graphic_adapter_test.cpp +++ b/test/unittest/ohos_adapter/graphic_adapter_test/graphic_adapter_test.cpp @@ -107,6 +107,7 @@ HWTEST_F(GraphicAdapterTest, GraphicAdapterTest_RequestVsync_001, TestSize.Level adapter.OnVsync(1, client); client = &vsyncAdapter; adapter.OnVsync(1, client); + adapter.VsyncCallbackInner(0); adapter.VsyncCallbackInner(1); int64_t period = adapter.GetVSyncPeriod(); EXPECT_EQ(period, 0); -- Gitee From 5c6711f86957cf940b0b535878a82e22ce45e602 Mon Sep 17 00:00:00 2001 From: xuefuzhang Date: Thu, 14 Aug 2025 15:38:38 +0800 Subject: [PATCH 006/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=B3=84=E9=9C=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuefuzhang --- interfaces/kits/cj/include/web_scheme_handler_request.h | 4 ++-- .../napi/webviewcontroller/web_scheme_handler_request.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/cj/include/web_scheme_handler_request.h b/interfaces/kits/cj/include/web_scheme_handler_request.h index 68169f350..ef69c421d 100644 --- a/interfaces/kits/cj/include/web_scheme_handler_request.h +++ b/interfaces/kits/cj/include/web_scheme_handler_request.h @@ -61,7 +61,7 @@ namespace OHOS::Webview { }; ~WebHttpBodyStreamImpl() { - if (!stream_) { + if (stream_) { OH_ArkWebResourceRequest_DestroyHttpBodyStream(stream_); stream_ = nullptr; } @@ -209,4 +209,4 @@ namespace OHOS::Webview { ArkWeb_ResourceHandler* handler_ = nullptr; }; } -#endif // WEB_SCHEME_HANDLER_REQUEST_H \ No newline at end of file +#endif // WEB_SCHEME_HANDLER_REQUEST_H diff --git a/interfaces/kits/napi/webviewcontroller/web_scheme_handler_request.cpp b/interfaces/kits/napi/webviewcontroller/web_scheme_handler_request.cpp index 12f390273..f30ebba9a 100644 --- a/interfaces/kits/napi/webviewcontroller/web_scheme_handler_request.cpp +++ b/interfaces/kits/napi/webviewcontroller/web_scheme_handler_request.cpp @@ -665,7 +665,7 @@ WebHttpBodyStream::WebHttpBodyStream(napi_env env, WebHttpBodyStream::~WebHttpBodyStream() { WVLOG_D("WebHttpBodyStream::~WebHttpBodyStream"); - if (!stream_) { + if (stream_) { OH_ArkWebResourceRequest_DestroyHttpBodyStream(stream_); stream_ = nullptr; } -- Gitee From 0cd81aaa0da3668d78988bb2b2448afc4a1ffaa3 Mon Sep 17 00:00:00 2001 From: SprucEovo Date: Mon, 18 Aug 2025 09:23:43 +0800 Subject: [PATCH 007/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SprucEovo --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 04999f2b5..060260b1d 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -6916,6 +6916,7 @@ napi_value NapiWebviewController::GetPageOffset(napi_env env, if (!webviewController) { return nullptr; } + webviewController->GetPageOffset(&offsetX, &offsetY); napi_create_object(env, &result); napi_create_double(env, static_cast(offsetX), &horizontal); napi_create_double(env, static_cast(offsetY), &vertical); -- Gitee From b6c479f9b31d3f001c7e47cb5ae6515dc466be37 Mon Sep 17 00:00:00 2001 From: taoxueao Date: Mon, 18 Aug 2025 02:30:48 +0000 Subject: [PATCH 008/124] update ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp. Signed-off-by: taoxueao --- .../src/system_properties_adapter_impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 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 7eb15da90..73e9970e2 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 @@ -188,9 +188,9 @@ std::string SystemPropertiesAdapterImpl::GetUserAgentOSName() std::string SystemPropertiesAdapterImpl::GetUserAgentOSVersion() { - return OHOS::system::GetParameter("const.product.os.dist.apiname", "").empty() ? - OHOS::system::GetParameter("const.product.os.dist.version", "") : - OHOS::system::GetParameter("const.product.os.dist.apiname", ""); + std::string apiname = OHOS::system::GetParameter("const.product.os.dist.apiname", ""); + std::string version = OHOS::system::GetParameter("const.product.os.dist.version", ""); + return apiname.empty() ? version : apiname; } std::string SystemPropertiesAdapterImpl::GetUserAgentBaseOSName() -- Gitee From 9c896373f3a71812da9d0c680c2b30c29893e2fc Mon Sep 17 00:00:00 2001 From: SprucEovo Date: Mon, 18 Aug 2025 10:47:27 +0800 Subject: [PATCH 009/124] =?UTF-8?q?=E8=93=9D=E9=BB=84=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SprucEovo --- 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 29518b169..e68300ece 100644 --- a/interfaces/kits/napi/js/webview_export.js +++ b/interfaces/kits/napi/js/webview_export.js @@ -79,9 +79,9 @@ function takePhoto(param, selectResult) { .then((pickerResult) => { selectResult.handleFileList([pickerResult.resultUri]); }).catch((error) => { - console.log('selectFile error:' + JSON.stringify(error)); - throw error; - }); + console.log('selectFile error:' + JSON.stringify(error)); + throw error; + }); } catch (error) { console.log('the pick call failed, error code' + JSON.stringify(error)); @@ -116,9 +116,9 @@ function selectFile(param, result) { let filePath = documentSelectResult; result.handleFileList(filePath); }).catch((error) => { - console.log('selectFile error: ' + JSON.stringify(error)); - throw error; - }); + console.log('selectFile error: ' + JSON.stringify(error)); + throw error; + }); } else { documentPicker.save(createDocumentSaveOptions(param)) .then((documentSaveResult) => { -- Gitee From 338a525e1fa505aabd52a3443ed7926a36259e11 Mon Sep 17 00:00:00 2001 From: SprucEovo Date: Mon, 18 Aug 2025 10:54:14 +0800 Subject: [PATCH 010/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SprucEovo --- 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 e68300ece..b943813e3 100644 --- a/interfaces/kits/napi/js/webview_export.js +++ b/interfaces/kits/napi/js/webview_export.js @@ -133,10 +133,10 @@ function selectFile(param, result) { let watcher = fileIo.createWatcher(tempPath, 0x4, () => { fileIo.copy(tempUri, filePaths[0]).then(() => { - console.log('Web save file succeeded in copying.'); + console.log('Web save file succeeded in copying. '); fileIo.unlink(tempPath); }).catch((err) => { - console.error(`Web save file failed to copy: ${JSON.stringify(err)}.`); + console.error(`Web save file failed to copy: ${JSON.stringify(err)}`); }).finally(() => { watcher.stop(); }); @@ -145,9 +145,9 @@ function selectFile(param, result) { } result.handleFileList([tempUri]); }).catch((error) => { - console.log('saveFile error: ' + JSON.stringify(error)); - throw error; - }); + console.log('saveFile error: ' + JSON.stringify(error)); + throw error; + }); } } catch (error) { console.log('picker error: ' + JSON.stringify(error)); @@ -496,7 +496,7 @@ Object.defineProperty(webview.WebviewController.prototype, 'fileSelectorShowFrom console.error(`openCustomDialog error code is ${error.code}, message is ${error.message}`); }); } else if (callback.fileparam.isCapture() && - (isContainImageMimeType(callback.fileparam.getAcceptType()) || isContainVideoMimeType(callback.fileparam.getAcceptType()))) { + (isContainImageMimeType(callback.fileparam.getAcceptType()) || isContainVideoMimeType(callback.fileparam.getAcceptType()))) { console.log('take photo will be directly invoked due to the capture property'); takePhoto(callback.fileparam, callback.fileresult); } else { -- Gitee From 7e32a4f7b1f6973e5768a13d439cf07c000bb57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9C=89=E5=BA=B7?= Date: Mon, 18 Aug 2025 11:47:24 +0800 Subject: [PATCH 011/124] 8/18 sync code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张有康 --- .../napi_webview_controller.cpp | 596 +++++++++--------- .../include/ohos_nweb/nweb_autofill.h | 4 +- .../ark_web_accessibility_node_info_impl.cpp | 10 +- .../ark_web_accessibility_node_info_impl.h | 4 +- 4 files changed, 308 insertions(+), 306 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 4771f5c3d..2eb0d05c1 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -72,14 +72,14 @@ constexpr int32_t MAX_DATABASE_SIZE_IN_MB = 100; constexpr uint32_t MAX_KEYS_COUNT = 100; constexpr size_t MAX_KEY_LENGTH = 2048; constexpr size_t MAX_URL_TRUST_LIST_STR_LEN = 10 * 1024 * 1024; // 10M +constexpr size_t BFCACHE_DEFAULT_SIZE = 1; +constexpr size_t BFCACHE_DEFAULT_TIMETOLIVE = 600; constexpr double A4_WIDTH = 8.27; constexpr double A4_HEIGHT = 11.69; constexpr double SCALE_MIN = 0.1; constexpr double SCALE_MAX = 2.0; constexpr double HALF = 2.0; constexpr double TEN_MILLIMETER_TO_INCH = 0.39; -constexpr size_t BFCACHE_DEFAULT_SIZE = 1; -constexpr size_t BFCACHE_DEFAULT_TIMETOLIVE = 600; constexpr const char* EVENT_ATTACH_STATE_CHANGE = "controllerAttachStateChange"; using WebPrintWriteResultCallback = std::function; @@ -630,7 +630,7 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getCustomUserAgent", NapiWebviewController::GetCustomUserAgent), DECLARE_NAPI_FUNCTION("setCustomUserAgent", NapiWebviewController::SetCustomUserAgent), DECLARE_NAPI_FUNCTION("getTitle", NapiWebviewController::GetTitle), - DECLARE_NAPI_FUNCTION("getProgress", NapiWebviewController::GetProgress), + DECLARE_NAPI_FUNCTION("getProgress", NapiWebviewController::GetProgress), DECLARE_NAPI_FUNCTION("getPageHeight", NapiWebviewController::GetPageHeight), DECLARE_NAPI_FUNCTION("backOrForward", NapiWebviewController::BackOrForward), DECLARE_NAPI_FUNCTION("storeWebArchive", NapiWebviewController::StoreWebArchive), @@ -654,6 +654,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), @@ -743,13 +744,12 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("setBackForwardCacheOptions", NapiWebviewController::SetBackForwardCacheOptions), DECLARE_NAPI_FUNCTION("scrollByWithResult", NapiWebviewController::ScrollByWithResult), DECLARE_NAPI_FUNCTION("updateInstanceId", NapiWebviewController::UpdateInstanceId), - DECLARE_NAPI_STATIC_FUNCTION("trimMemoryByPressureLevel", - NapiWebviewController::TrimMemoryByPressureLevel), DECLARE_NAPI_FUNCTION("getScrollOffset", NapiWebviewController::GetScrollOffset), DECLARE_NAPI_FUNCTION("getPageOffset", NapiWebviewController::GetPageOffset), - DECLARE_NAPI_FUNCTION("createPdf", NapiWebviewController::RunCreatePDFExt), + DECLARE_NAPI_STATIC_FUNCTION("trimMemoryByPressureLevel", + NapiWebviewController::TrimMemoryByPressureLevel), DECLARE_NAPI_FUNCTION("getLastHitTest", NapiWebviewController::GetLastHitTest), DECLARE_NAPI_FUNCTION("getAttachState", NapiWebviewController::GetAttachState), DECLARE_NAPI_FUNCTION("on", NapiWebviewController::On), @@ -972,6 +972,16 @@ 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 scrollTypeEnum = nullptr; + napi_property_descriptor scrollTypeProperties[] = { + DECLARE_NAPI_STATIC_PROPERTY("EVENT", NapiParseUtils::ToInt32Value(env, + static_cast(ScrollType::EVENT))), + }; + napi_define_class(env, WEB_SCROLL_TYPE_ENUM_NAME.c_str(), WEB_SCROLL_TYPE_ENUM_NAME.length(), + NapiParseUtils::CreateEnumConstructor, nullptr, sizeof(scrollTypeProperties) / + sizeof(scrollTypeProperties[0]), scrollTypeProperties, &scrollTypeEnum); + napi_set_named_property(env, exports, WEB_SCROLL_TYPE_ENUM_NAME.c_str(), scrollTypeEnum); + napi_value pressureLevelEnum = nullptr; napi_property_descriptor pressureLevelProperties[] = { DECLARE_NAPI_STATIC_PROPERTY("MEMORY_PRESSURE_LEVEL_MODERATE", NapiParseUtils::ToInt32Value(env, @@ -984,16 +994,6 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) sizeof(pressureLevelProperties[0]), pressureLevelProperties, &pressureLevelEnum); napi_set_named_property(env, exports, WEB_PRESSURE_LEVEL_ENUM_NAME.c_str(), pressureLevelEnum); - napi_value scrollTypeEnum = nullptr; - napi_property_descriptor scrollTypeProperties[] = { - DECLARE_NAPI_STATIC_PROPERTY("EVENT", NapiParseUtils::ToInt32Value(env, - static_cast(ScrollType::EVENT))), - }; - napi_define_class(env, WEB_SCROLL_TYPE_ENUM_NAME.c_str(), WEB_SCROLL_TYPE_ENUM_NAME.length(), - NapiParseUtils::CreateEnumConstructor, nullptr, sizeof(scrollTypeProperties) / - sizeof(scrollTypeProperties[0]), scrollTypeProperties, &scrollTypeEnum); - napi_set_named_property(env, exports, WEB_SCROLL_TYPE_ENUM_NAME.c_str(), scrollTypeEnum); - napi_value controllerAttachStateEnum = nullptr; napi_property_descriptor controllerAttachStateProperties[] = { DECLARE_NAPI_STATIC_PROPERTY("UNATTACHED", NapiParseUtils::ToInt32Value(env, @@ -4617,6 +4617,7 @@ napi_value NapiWebviewController::ScrollTo(napi_env env, napi_callback_info info BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); return nullptr; } + if (argc == INTEGER_THREE) { webviewController->ScrollToWithAnime(x, y, duration); } else { @@ -4668,6 +4669,7 @@ napi_value NapiWebviewController::ScrollBy(napi_env env, napi_callback_info info BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); return nullptr; } + if (argc == INTEGER_THREE) { webviewController->ScrollByWithAnime(deltaX, deltaY, duration); } else { @@ -5041,92 +5043,6 @@ napi_value NapiWebviewController::PrefetchResource(napi_env env, napi_callback_i return result; } -napi_value NapiWebviewController::ClearPrefetchedResource(napi_env env, napi_callback_info info) -{ - napi_value thisVar = nullptr; - napi_value result = nullptr; - size_t argc = INTEGER_ONE; - napi_value argv[INTEGER_ONE] = { 0 }; - napi_get_undefined(env, &result); - napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); - if (argc != INTEGER_ONE) { - WVLOG_E("BusinessError: 401. Arg count must be 1."); - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); - return nullptr; - } - - std::vector cacheKeyList; - if (!ParseCacheKeyList(env, argv[INTEGER_ZERO], &cacheKeyList)) { - WVLOG_E("BusinessError: 401. The type of 'cacheKeyList' must be Array of string."); - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); - return nullptr; - } - - NAPI_CALL(env, napi_get_undefined(env, &result)); - NWebHelper::Instance().ClearPrefetchedResource(cacheKeyList); - return result; -} - -napi_value NapiWebviewController::SetDownloadDelegate(napi_env env, napi_callback_info info) -{ - WVLOG_D("WebDownloader::JS_SetDownloadDelegate"); - NWebHelper::Instance().LoadNWebSDK(); - size_t argc = 1; - napi_value argv[1] = {0}; - napi_value thisVar = nullptr; - void* data = nullptr; - napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - - WebDownloadDelegate* delegate = nullptr; - napi_value obj = argv[0]; - napi_unwrap(env, obj, (void**)&delegate); - if (!delegate) { - WVLOG_E("[DOWNLOAD] WebDownloader::JS_SetDownloadDelegate delegate is null"); - (void)RemoveDownloadDelegateRef(env, thisVar); - return nullptr; - } - napi_create_reference(env, obj, 1, &delegate->delegate_); - - WebviewController *webviewController = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&webviewController)); - if (webviewController == nullptr || !webviewController->IsInit()) { - BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); - WVLOG_E("create message port failed, napi unwrap webviewController failed"); - return nullptr; - } - int32_t nwebId = webviewController->GetWebId(); - WebDownloadManager::AddDownloadDelegateForWeb(nwebId, delegate); - return nullptr; -} - -napi_value NapiWebviewController::StartDownload(napi_env env, napi_callback_info info) -{ - WVLOG_D("[DOWNLOAD] NapiWebviewController::StartDownload"); - size_t argc = 1; - napi_value argv[1] = {0}; - napi_value thisVar = nullptr; - void* data = nullptr; - napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - - WebviewController *webviewController = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&webviewController)); - if (webviewController == nullptr || !webviewController->IsInit()) { - BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); - WVLOG_E("create message port failed, napi unwrap webviewController failed"); - return nullptr; - } - - std::string url; - if (!ParsePrepareUrl(env, argv[INTEGER_ZERO], url)) { - BusinessError::ThrowErrorByErrcode(env, INVALID_URL); - return nullptr; - } - int32_t nwebId = webviewController->GetWebId(); - NWebHelper::Instance().LoadNWebSDK(); - WebDownloader_StartDownload(nwebId, url.c_str()); - return nullptr; -} - napi_value NapiWebviewController::CloseAllMediaPresentations(napi_env env, napi_callback_info info) { napi_value result = nullptr; @@ -5192,27 +5108,29 @@ napi_value NapiWebviewController::GetMediaPlaybackState(napi_env env, napi_callb return result; } -napi_value NapiWebviewController::SetConnectionTimeout(napi_env env, napi_callback_info info) +napi_value NapiWebviewController::ClearPrefetchedResource(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] = { nullptr }; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + 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; + WVLOG_E("BusinessError: 401. Arg count must be 1."); + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); + return nullptr; } - int32_t timeout = 0; - if (!NapiParseUtils::ParseInt32(env, argv[INTEGER_ZERO], timeout) || (timeout <= 0)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - "BusinessError: 401. Parameter error. The type of 'timeout' must be int and must be positive integer."); - return result; + std::vector cacheKeyList; + if (!ParseCacheKeyList(env, argv[INTEGER_ZERO], &cacheKeyList)) { + WVLOG_E("BusinessError: 401. The type of 'cacheKeyList' must be Array of string."); + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); + return nullptr; } - NWebHelper::Instance().SetConnectionTimeout(timeout); NAPI_CALL(env, napi_get_undefined(env, &result)); + NWebHelper::Instance().ClearPrefetchedResource(cacheKeyList); return result; } @@ -5564,6 +5482,91 @@ napi_value NapiWebPrintDocument::JsConstructor(napi_env env, napi_callback_info return thisVar; } +napi_value NapiWebviewController::SetDownloadDelegate(napi_env env, napi_callback_info info) +{ + WVLOG_D("WebDownloader::JS_SetDownloadDelegate"); + NWebHelper::Instance().LoadNWebSDK(); + + size_t argc = 1; + napi_value argv[1] = {0}; + napi_value thisVar = nullptr; + void* data = nullptr; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + + WebDownloadDelegate* delegate = nullptr; + napi_value obj = argv[0]; + napi_unwrap(env, obj, (void**)&delegate); + if (!delegate) { + WVLOG_E("[DOWNLOAD] WebDownloader::JS_SetDownloadDelegate delegate is null"); + (void)RemoveDownloadDelegateRef(env, thisVar); + return nullptr; + } + napi_create_reference(env, obj, 1, &delegate->delegate_); + + WebviewController *webviewController = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&webviewController)); + if (webviewController == nullptr || !webviewController->IsInit()) { + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); + WVLOG_E("create message port failed, napi unwrap webviewController failed"); + return nullptr; + } + int32_t nwebId = webviewController->GetWebId(); + WebDownloadManager::AddDownloadDelegateForWeb(nwebId, delegate); + return nullptr; +} + +napi_value NapiWebviewController::StartDownload(napi_env env, napi_callback_info info) +{ + WVLOG_D("[DOWNLOAD] NapiWebviewController::StartDownload"); + size_t argc = 1; + napi_value argv[1] = {0}; + napi_value thisVar = nullptr; + void* data = nullptr; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + + WebviewController *webviewController = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&webviewController)); + if (webviewController == nullptr || !webviewController->IsInit()) { + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR); + WVLOG_E("create message port failed, napi unwrap webviewController failed"); + return nullptr; + } + + std::string url; + if (!ParsePrepareUrl(env, argv[INTEGER_ZERO], url)) { + BusinessError::ThrowErrorByErrcode(env, INVALID_URL); + return nullptr; + } + int32_t nwebId = webviewController->GetWebId(); + NWebHelper::Instance().LoadNWebSDK(); + WebDownloader_StartDownload(nwebId, url.c_str()); + return nullptr; +} + +napi_value NapiWebviewController::SetConnectionTimeout(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { nullptr }; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc != INTEGER_ONE) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "one")); + return result; + } + + int32_t timeout = 0; + if (!NapiParseUtils::ParseInt32(env, argv[INTEGER_ZERO], timeout) || (timeout <= 0)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + "BusinessError: 401. Parameter error. The type of 'timeout' must be int and must be positive integer."); + return result; + } + + NWebHelper::Instance().SetConnectionTimeout(timeout); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; +} + napi_value NapiWebviewController::SetPrintBackground(napi_env env, napi_callback_info info) { napi_value result = nullptr; @@ -5746,6 +5749,7 @@ napi_value NapiWebviewController::EnableIntelligentTrackingPrevention( WebviewController *webviewController = GetWebviewController(env, info); if (!webviewController) { + WVLOG_E("EnableIntelligentTrackingPrevention failed for webviewController failed"); return result; } webviewController->EnableIntelligentTrackingPrevention(enabled); @@ -5767,6 +5771,7 @@ napi_value NapiWebviewController::IsIntelligentTrackingPreventionEnabled( WebviewController *webviewController = GetWebviewController(env, info); if (!webviewController) { + WVLOG_E("IsIntelligentTrackingPreventionEnabled failed for webviewController failed"); return result; } @@ -6248,29 +6253,6 @@ napi_value NapiWebviewController::SetUserAgentForHosts(napi_env env, napi_callba return result; } -napi_value NapiWebviewController::WarmupServiceWorker(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); - return result; - } - - std::string url; - if (!ParsePrepareUrl(env, argv[INTEGER_ZERO], url)) { - BusinessError::ThrowErrorByErrcode(env, INVALID_URL); - return result; - } - - NWebHelper::Instance().WarmupServiceWorker(url); - return result; -} - napi_value NapiWebviewController::InjectOfflineResources(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -6449,13 +6431,49 @@ napi_value NapiWebviewController::ClearHostIP(napi_env env, napi_callback_info i return result; } -napi_value NapiWebviewController::EnableWholeWebPageDrawing( - napi_env env, napi_callback_info info) +napi_value NapiWebviewController::WarmupServiceWorker(napi_env env, napi_callback_info info) { + napi_value thisVar = nullptr; napi_value result = nullptr; - NWebHelper::Instance().EnableWholeWebPageDrawing(); - NAPI_CALL(env, napi_get_undefined(env, &result)); - return result; + 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); + return result; + } + + std::string url; + if (!ParsePrepareUrl(env, argv[INTEGER_ZERO], url)) { + BusinessError::ThrowErrorByErrcode(env, INVALID_URL); + return result; + } + + NWebHelper::Instance().WarmupServiceWorker(url); + return result; +} + +napi_value NapiWebviewController::GetSurfaceId(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + WebviewController *webviewController = GetWebviewController(env, info); + if (!webviewController) { + return nullptr; + } + + std::string surfaceId = webviewController->GetSurfaceId(); + napi_create_string_utf8(env, surfaceId.c_str(), surfaceId.length(), &result); + return result; +} + +napi_value NapiWebviewController::EnableWholeWebPageDrawing( + napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + NWebHelper::Instance().EnableWholeWebPageDrawing(); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; } napi_value NapiWebviewController::EnableAdsBlock( @@ -6535,97 +6553,6 @@ napi_value NapiWebviewController::IsAdsBlockEnabledForCurPage(napi_env env, napi return result; } -napi_value NapiWebviewController::GetSurfaceId(napi_env env, napi_callback_info info) -{ - napi_value result = nullptr; - WebviewController *webviewController = GetWebviewController(env, info); - if (!webviewController) { - return nullptr; - } - - std::string surfaceId = webviewController->GetSurfaceId(); - napi_create_string_utf8(env, surfaceId.c_str(), surfaceId.length(), &result); - return result; -} - -napi_value NapiWebviewController::UpdateInstanceId(napi_env env, napi_callback_info info) -{ - WVLOG_D("Instance changed"); - napi_value result = nullptr; - napi_value thisVar = nullptr; - size_t argc = INTEGER_ONE; - napi_value argv[INTEGER_ONE] = { 0 }; - - napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); - if (argc != INTEGER_ONE) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); - return result; - } - - int32_t newId = 0; - if (!NapiParseUtils::ParseInt32(env, argv[INTEGER_ZERO], newId)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); - return result; - } - - WebviewController *webviewController = nullptr; - napi_status status = napi_unwrap(env, thisVar, (void **)&webviewController); - if ((!webviewController) || (status != napi_ok) || !webviewController->IsInit()) { - return result; - } - - webviewController->UpdateInstanceId(newId); - - NAPI_CALL(env, napi_get_undefined(env, &result)); - return result; -} - -napi_value NapiWebviewController::SetUrlTrustList(napi_env env, napi_callback_info info) -{ - WVLOG_D("SetUrlTrustList invoked"); - - napi_value result = nullptr; - NAPI_CALL(env, napi_get_undefined(env, &result)); - - napi_value thisVar = nullptr; - size_t argc = INTEGER_ONE; - napi_value argv[INTEGER_ONE] = { 0 }; - 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; - } - - std::string urlTrustList; - if (!NapiParseUtils::ParseString(env, argv[0], urlTrustList)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "urlTrustList", "string")); - return result; - } - if (urlTrustList.size() > MAX_URL_TRUST_LIST_STR_LEN) { - WVLOG_E("EnableAdsBlock: url trust list len is too large."); - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); - return result; - } - - WebviewController* webviewController = GetWebviewController(env, info); - if (!webviewController) { - WVLOG_E("webview controller is null or not init"); - return result; - } - - std::string detailMsg; - ErrCode ret = webviewController->SetUrlTrustList(urlTrustList, detailMsg); - if (ret != NO_ERROR) { - WVLOG_E("SetUrlTrustList failed, error code: %{public}d", ret); - BusinessError::ThrowErrorByErrcode(env, ret, - NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_DETAIL_ERROR_MSG, detailMsg.c_str())); - return result; - } - return result; -} - WebSnapshotCallback CreateWebPageSnapshotResultCallback( napi_env env, napi_ref jsCallback, bool check, int32_t inputWidth, int32_t inputHeight) { @@ -6817,6 +6744,84 @@ napi_value NapiWebviewController::WebPageSnapshot(napi_env env, napi_callback_in return result; } +napi_value NapiWebviewController::SetUrlTrustList(napi_env env, napi_callback_info info) +{ + WVLOG_D("SetUrlTrustList invoked"); + + napi_value result = nullptr; + NAPI_CALL(env, napi_get_undefined(env, &result)); + + napi_value thisVar = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + 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; + } + + std::string urlTrustList; + if (!NapiParseUtils::ParseString(env, argv[0], urlTrustList)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "urlTrustList", "string")); + return result; + } + if (urlTrustList.size() > MAX_URL_TRUST_LIST_STR_LEN) { + WVLOG_E("url trust list len is too large."); + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); + return result; + } + + WebviewController* webviewController = GetWebviewController(env, info); + if (!webviewController) { + WVLOG_E("webview controller is null or not init"); + return result; + } + + std::string detailMsg; + ErrCode ret = webviewController->SetUrlTrustList(urlTrustList, detailMsg); + if (ret != NO_ERROR) { + WVLOG_E("SetUrlTrustList failed, error code: %{public}d", ret); + BusinessError::ThrowErrorByErrcode(env, ret, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_DETAIL_ERROR_MSG, detailMsg.c_str())); + return result; + } + return result; +} + +napi_value NapiWebviewController::UpdateInstanceId(napi_env env, napi_callback_info info) +{ + WVLOG_D("Instance changed"); + napi_value result = nullptr; + napi_value thisVar = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + if (argc != INTEGER_ONE) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); + return result; + } + + int32_t newId = 0; + if (!NapiParseUtils::ParseInt32(env, argv[INTEGER_ZERO], newId)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); + return result; + } + + WebviewController *webviewController = nullptr; + napi_status status = napi_unwrap(env, thisVar, (void **)&webviewController); + if ((!webviewController) || (status != napi_ok) || !webviewController->IsInit()) { + return result; + } + + webviewController->UpdateInstanceId(newId); + + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; +} + napi_value NapiWebviewController::SetPathAllowingUniversalAccess( napi_env env, napi_callback_info info) { @@ -6867,33 +6872,42 @@ napi_value NapiWebviewController::SetPathAllowingUniversalAccess( return result; } -napi_value NapiWebviewController::TrimMemoryByPressureLevel(napi_env env, - napi_callback_info info) +napi_value NapiWebviewController::ScrollByWithResult(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; - } + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_TWO; + napi_value argv[INTEGER_TWO] = { 0 }; + float deltaX; + float deltaY; - if (!NapiParseUtils::ParseInt32(env, argv[INTEGER_ZERO], memoryLevel)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, - "PressureLevel", "number")); - return result; - } + 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; + } - memoryLevel = memoryLevel == 1 ? 0 : memoryLevel; - NWebHelper::Instance().TrimMemoryByPressureLevel(memoryLevel); - NAPI_CALL(env, napi_get_undefined(env, &result)); - 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; } napi_value NapiWebviewController::GetScrollOffset(napi_env env, @@ -6904,14 +6918,11 @@ napi_value NapiWebviewController::GetScrollOffset(napi_env env, 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); @@ -6945,42 +6956,33 @@ napi_value NapiWebviewController::GetPageOffset(napi_env env, return result; } -napi_value NapiWebviewController::ScrollByWithResult(napi_env env, napi_callback_info info) +napi_value NapiWebviewController::TrimMemoryByPressureLevel(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; - } + 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; + } - WebviewController *webviewController = GetWebviewController(env, info); - if (!webviewController) { - return nullptr; - } + if (!NapiParseUtils::ParseInt32(env, argv[INTEGER_ZERO], memoryLevel)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, + "PressureLevel", "number")); + return result; + } - bool scrollByWithResult = webviewController->ScrollByWithResult(deltaX, deltaY); - NAPI_CALL(env, napi_get_boolean(env, scrollByWithResult, &result)); - return result; + memoryLevel = memoryLevel == 1 ? 0 : memoryLevel; + NWebHelper::Instance().TrimMemoryByPressureLevel(memoryLevel); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; } napi_value NapiWebviewController::RemoveAllCache(napi_env env, napi_callback_info info) @@ -7614,7 +7616,7 @@ napi_value NapiWebviewController::EnablePrivateNetworkAccess(napi_env env, napi_ napi_value result = nullptr; size_t argc = INTEGER_ONE; napi_value argv[INTEGER_ONE] = {0}; - + NAPI_CALL(env, napi_get_undefined(env, &result)); napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); if (argc != INTEGER_ONE) { @@ -7622,18 +7624,18 @@ napi_value NapiWebviewController::EnablePrivateNetworkAccess(napi_env env, napi_ NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "one")); return result; } - + bool pnaEnabled = false; if (!NapiParseUtils::ParseBoolean(env, argv[0], pnaEnabled)) { BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "enable", "boolean")); return result; } - + NWebHelper::Instance().EnablePrivateNetworkAccess(pnaEnabled); return result; } - + napi_value NapiWebviewController::IsPrivateNetworkAccessEnabled(napi_env env, napi_callback_info info) { napi_value result = nullptr; diff --git a/ohos_interface/include/ohos_nweb/nweb_autofill.h b/ohos_interface/include/ohos_nweb/nweb_autofill.h index e3eb979fa..7fc117e61 100644 --- a/ohos_interface/include/ohos_nweb/nweb_autofill.h +++ b/ohos_interface/include/ohos_nweb/nweb_autofill.h @@ -54,8 +54,6 @@ const std::string NWEB_AUTOFILL_TEL_COUNTRY_CODE = "tel-country-code"; const std::string NWEB_AUTOFILL_EMAIL = "email"; const std::string NWEB_AUTOFILL_CC_NUMBER = "cc-number"; const std::string NWEB_AUTOFILL_ID_CARD_NUMBER = "id-card-number"; -const std::string NWEB_AUTOFILL_DETAIL_INFO_WITHOUT_STREET = "detail-info-without-street"; -const std::string NWEB_AUTOFILL_FORMAT_ADDRESS = "format-address"; const std::string NWEB_AUTOFILL_NICKNAME = "nickname"; const std::string NWEB_AUTOFILL_USERNAME = "username"; const std::string NWEB_AUTOFILL_PASSWORD = "password"; @@ -72,6 +70,8 @@ const std::string NWEB_AUTOFILL_LICENSE_FILE_NUMBER = "license-file-number"; const std::string NWEB_AUTOFILL_LICENSE_PLATE = "license-plate"; const std::string NWEB_AUTOFILL_ENGINE_NUMBER = "engine-number"; const std::string NWEB_AUTOFILL_LICENSE_CHASSIS_NUMBER = "license-chassis-number"; +const std::string NWEB_AUTOFILL_DETAIL_INFO_WITHOUT_STREET = "detail-info-without-street"; +const std::string NWEB_AUTOFILL_FORMAT_ADDRESS = "format-address"; enum NWebAutofillEvent { UNKNOWN = 0, diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_accessibility_node_info_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_accessibility_node_info_impl.cpp index be7881b6d..3f5741f08 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_accessibility_node_info_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_accessibility_node_info_impl.cpp @@ -289,11 +289,6 @@ ArkWebString ArkWebAccessibilityNodeInfoImpl::GetAccessibilityText() return ArkWebStringClassToStruct(nweb_accessibility_node_info_->GetAccessibilityText()); } -ArkWebString ArkWebAccessibilityNodeInfoImpl::GetHtmlElementId() -{ - return ArkWebStringClassToStruct(nweb_accessibility_node_info_->GetHtmlElementId()); -} - ArkWebString ArkWebAccessibilityNodeInfoImpl::GetComponentTypeDescription() { return ArkWebStringClassToStruct(nweb_accessibility_node_info_->GetComponentTypeDescription()); @@ -308,4 +303,9 @@ ArkWebString ArkWebAccessibilityNodeInfoImpl::GetExpandedState() { return ArkWebStringClassToStruct(nweb_accessibility_node_info_->GetExpandedState()); } + +ArkWebString ArkWebAccessibilityNodeInfoImpl::GetHtmlElementId() +{ + return ArkWebStringClassToStruct(nweb_accessibility_node_info_->GetHtmlElementId()); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_accessibility_node_info_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_accessibility_node_info_impl.h index be2a3d628..924f689f2 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_accessibility_node_info_impl.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_accessibility_node_info_impl.h @@ -136,14 +136,14 @@ public: ArkWebString GetAccessibilityText() override; - ArkWebString GetHtmlElementId() override; - ArkWebString GetComponentTypeDescription() override; int32_t GetCheckboxGroupSelectedStatus() override; ArkWebString GetExpandedState() override; + ArkWebString GetHtmlElementId() override; + private: std::shared_ptr nweb_accessibility_node_info_; }; -- Gitee From e510d69aedd6948021701d7eae22e5f68528ecd2 Mon Sep 17 00:00:00 2001 From: liubo Date: Mon, 18 Aug 2025 14:26:42 +0800 Subject: [PATCH 012/124] =?UTF-8?q?TDD=C3=90=C2=B8=C2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liubo419 --- test/unittest/arkweb_utils_test/BUILD.gn | 8 ++++++-- .../arkweb_utils_test/arkweb_utils_test.cpp | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/test/unittest/arkweb_utils_test/BUILD.gn b/test/unittest/arkweb_utils_test/BUILD.gn index 0d32168d4..f0f107a8e 100644 --- a/test/unittest/arkweb_utils_test/BUILD.gn +++ b/test/unittest/arkweb_utils_test/BUILD.gn @@ -24,6 +24,8 @@ config("module_private_config") { "$webview_path/arkweb_utils", "../../../ohos_nweb/include/", "../../../ohos_adapter/hiviewdfx_adapter/include/", + "../../../ohos_adapter/system_properties_adapter/include", + "../../../ohos_interface/include/ohos_adapter", ] } @@ -32,8 +34,10 @@ ohos_unittest("arkweb_utils_test") { sources = [ "arkweb_utils_test.cpp" ] configs = [ ":module_private_config" ] - deps = [ "$webview_path/arkweb_utils:libarkweb_utils" ] - + deps = [ + "$webview_path/arkweb_utils:libarkweb_utils", + "$webview_path/ohos_adapter:nweb_ohos_adapter" + ] external_deps = [ "ability_runtime:app_context", "ability_runtime:app_manager", diff --git a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp index 4f217e381..f3f426a7f 100644 --- a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp +++ b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp @@ -19,7 +19,10 @@ #include #include "arkweb_utils.h" +#include "nweb_config_helper.h" +#include "nweb_log.h" #include "parameters.h" +#include "system_properties_adapter_impl.h" using namespace testing::ext; @@ -229,7 +232,13 @@ TEST(arkweb_utils_test, GetArkwebInstallPath001) { auto aclPath = GetArkwebInstallPath(); bool res = (aclPath == SANDBOX_LEGACY_HAP_PATH || aclPath == PRECONFIG_LEGACY_HAP_PATH); - EXPECT_TRUE(res); + NWeb::ProductDeviceType result = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetProductDeviceType(); + if (result == NWeb::ProductDeviceType::DEVICE_TYPE_UNKNOWN) { + EXPECT_FALSE(res); + } else { + EXPECT_TRUE(res); + } + OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } @@ -240,7 +249,13 @@ TEST(arkweb_utils_test, GetArkwebInstallPath002) { auto aclPath = GetArkwebInstallPath(); bool res = (aclPath == SANDBOX_EVERGREEN_HAP_PATH || aclPath == PRECONFIG_EVERGREEN_HAP_PATH); - EXPECT_TRUE(res); + NWeb::ProductDeviceType result = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetProductDeviceType(); + if (result == NWeb::ProductDeviceType::DEVICE_TYPE_UNKNOWN) { + EXPECT_FALSE(res); + } else { + EXPECT_TRUE(res); + } + OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } } // namespace OHOS::NWeb \ No newline at end of file -- Gitee From c7158a349026016e150a960add1757cc647c52de Mon Sep 17 00:00:00 2001 From: SprucEovo Date: Mon, 18 Aug 2025 16:18:11 +0800 Subject: [PATCH 013/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SprucEovo --- ohos_nweb/src/nweb_config_helper.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ohos_nweb/src/nweb_config_helper.cpp b/ohos_nweb/src/nweb_config_helper.cpp index 6b1a91e4c..ff97c0fb5 100644 --- a/ohos_nweb/src/nweb_config_helper.cpp +++ b/ohos_nweb/src/nweb_config_helper.cpp @@ -575,12 +575,8 @@ void NWebConfigHelper::ParseWindowOrientationConfig(xmlNodePtr nodePtr, char* orientationPtr = (char *)xmlGetProp(curNodePtr,BAD_CAST(XML_ENABLE_WINDOW_ORIENTATION)); if (!bundleNamePtr || !orientationPtr) { WVLOG_E("invalid bundleNamePtr or orientationPtr!"); - if (bundleNamePtr) { - xmlFree(bundleNamePtr); - } - if (orientationPtr) { - xmlFree(orientationPtr); - } + xmlFree(bundleNamePtr); + xmlFree(orientationPtr); continue; } std::string bundleName(bundleNamePtr); -- Gitee From bb2823fbd7f12d9e9a603c251e4f7daeb00123e0 Mon Sep 17 00:00:00 2001 From: fenggechang Date: Mon, 18 Aug 2025 16:21:43 +0800 Subject: [PATCH 014/124] add errorcode for AvoidVisibleViewportBottom 114 Signed-off-by: fenggechang --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 4771f5c3d..c2263f1c8 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -7372,6 +7372,7 @@ napi_value NapiWebviewController::AvoidVisibleViewportBottom(napi_env env, napi_ { if (IS_CALLING_FROM_M114()) { WVLOG_W("AvoidVisibleViewportBottom unsupported engine version: M114"); + BusinessError::ThrowErrorByErrcode(env, CAPABILITY_NOT_SUPPORTED_ERROR); return nullptr; } napi_value thisVar = nullptr; -- Gitee From c0927c0795f63e8181037df0818c2da4b700ee39 Mon Sep 17 00:00:00 2001 From: fenggechang Date: Fri, 15 Aug 2025 14:36:32 +0800 Subject: [PATCH 015/124] window.orientation UT case modify Signed-off-by: fenggechang --- .../nweb_config_helper_test.cpp | 108 +++++++++++++++--- 1 file changed, 90 insertions(+), 18 deletions(-) diff --git a/test/unittest/nweb_config_helper_test/nweb_config_helper_test.cpp b/test/unittest/nweb_config_helper_test/nweb_config_helper_test.cpp index f4ace571c..e902bda4d 100644 --- a/test/unittest/nweb_config_helper_test/nweb_config_helper_test.cpp +++ b/test/unittest/nweb_config_helper_test/nweb_config_helper_test.cpp @@ -29,13 +29,24 @@ #include "nweb_config_helper.h" #include "nweb_helper.h" #include "nweb_init_params.h" +#include "application_context.h" using namespace testing; using namespace testing::ext; using namespace OHOS::NWeb; +using namespace OHOS::AbilityRuntime; namespace OHOS { + +namespace AbilityRuntime { +std::shared_ptr g_applicationContext = nullptr; +std::shared_ptr Context::GetApplicationContext() +{ + return g_applicationContext; +} +} // namespace AbilityRuntime + namespace NWebConfig { const auto XML_ATTR_NAME = "name"; @@ -52,6 +63,11 @@ public: std::shared_ptr initArgs)); }; +class ApplicationContextMock : public AbilityRuntime::ApplicationContext { +public: + MOCK_CONST_METHOD0(GetBundleName, std::string()); +}; + class NWebConfigHelperTest : public ::testing::Test { protected: std::shared_ptr initArgs = std::make_shared(); @@ -317,13 +333,32 @@ HWTEST_F(NWebConfigHelperTest, */ HWTEST_F(NWebConfigHelperTest, ParseWindowOrientationConfig_WhenBundleNameMatchesAndOrientationIsTure, TestSize.Level0) { - xmlNodePtr nodePtr = xmlNewNode(nullptr, BAD_CAST "testNode"); - EXPECT_NE(nodePtr, nullptr); - xmlNewProp(nodePtr, BAD_CAST(XML_BUNDLE_NAME), BAD_CAST("testBundleName")); - xmlNewProp(nodePtr, BAD_CAST(XML_ENABLE_WINDOW_ORIENTATION), BAD_CAST("true")); + xmlNodePtr rootNode = xmlNewNode(nullptr, BAD_CAST "root"); + xmlNodePtr configNode = xmlNewNode(nullptr, BAD_CAST "window_orientation"); + EXPECT_NE(rootNode, nullptr); + EXPECT_NE(configNode, nullptr); + xmlAddChild(rootNode, configNode); + xmlNewProp(configNode, BAD_CAST(XML_BUNDLE_NAME), BAD_CAST("testBundleName")); + xmlNewProp(configNode, BAD_CAST(XML_ENABLE_WINDOW_ORIENTATION), BAD_CAST("true")); + + g_applicationContext.reset(); + ApplicationContextMock* contextMock = new ApplicationContextMock(); + EXPECT_NE(contextMock, nullptr); + EXPECT_CALL(*contextMock, GetBundleName()).Times(1).WillRepeatedly(::testing::Return("testBundleName")); + EXPECT_EQ(g_applicationContext, nullptr); + g_applicationContext.reset(contextMock); + EXPECT_NE(g_applicationContext, nullptr); + std::shared_ptr initArgs = std::make_shared(); - NWebConfigHelper::Instance().ParseWindowOrientationConfig(nodePtr, initArgs); - EXPECT_EQ(initArgs->GetArgsToAdd().size(), 0); + NWebConfigHelper::Instance().ParseWindowOrientationConfig(rootNode, initArgs); + const auto& args = initArgs->GetArgsToAdd(); + EXPECT_EQ(args.size(), 1); + EXPECT_EQ(args.front(), "--enable-blink-features=OrientationEvent"); + + g_applicationContext.reset(); + EXPECT_EQ(g_applicationContext, nullptr); + xmlFreeNode(rootNode); + xmlFreeNode(configNode); } /** @@ -334,13 +369,32 @@ HWTEST_F(NWebConfigHelperTest, */ HWTEST_F(NWebConfigHelperTest, ParseWindowOrientationConfig_WhenBundleNameMatchesAndOrientationIsFalse, TestSize.Level0) { - xmlNodePtr nodePtr = xmlNewNode(nullptr, BAD_CAST "testNode"); - EXPECT_NE(nodePtr, nullptr); - xmlNewProp(nodePtr, BAD_CAST(XML_BUNDLE_NAME), BAD_CAST "testBundleName"); - xmlNewProp(nodePtr, BAD_CAST(XML_ENABLE_WINDOW_ORIENTATION), BAD_CAST("false")); + xmlNodePtr rootNode = xmlNewNode(nullptr, BAD_CAST "root"); + xmlNodePtr configNode = xmlNewNode(nullptr, BAD_CAST "window_orientation"); + EXPECT_NE(rootNode, nullptr); + EXPECT_NE(configNode, nullptr); + xmlAddChild(rootNode, configNode); + xmlNewProp(configNode, BAD_CAST(XML_BUNDLE_NAME), BAD_CAST("testBundleName")); + xmlNewProp(configNode, BAD_CAST(XML_ENABLE_WINDOW_ORIENTATION), BAD_CAST("false")); + + g_applicationContext.reset(); + ApplicationContextMock* contextMock = new ApplicationContextMock(); + EXPECT_NE(contextMock, nullptr); + EXPECT_CALL(*contextMock, GetBundleName()).Times(1).WillRepeatedly(::testing::Return("testBundleName")); + EXPECT_EQ(g_applicationContext, nullptr); + g_applicationContext.reset(contextMock); + EXPECT_NE(g_applicationContext, nullptr); + std::shared_ptr initArgs = std::make_shared(); - NWebConfigHelper::Instance().ParseWindowOrientationConfig(nodePtr, initArgs); - EXPECT_EQ(initArgs->GetArgsToAdd().size(), 0); + NWebConfigHelper::Instance().ParseWindowOrientationConfig(rootNode, initArgs); + const auto& args = initArgs->GetArgsToAdd(); + EXPECT_EQ(args.size(), 1); + EXPECT_EQ(args.front(), "--disable-blink-features=OrientationEvent"); + + g_applicationContext.reset(); + EXPECT_EQ(g_applicationContext, nullptr); + xmlFreeNode(rootNode); + xmlFreeNode(configNode); } /** @@ -351,13 +405,31 @@ HWTEST_F(NWebConfigHelperTest, */ HWTEST_F(NWebConfigHelperTest, ParseWindowOrientationConfig_WhenBundleNameMatchesAndOrientationIsInvalid, TestSize.Level0) { - xmlNodePtr nodePtr = xmlNewNode(nullptr, BAD_CAST "testNode"); - EXPECT_NE(nodePtr, nullptr); - xmlNewProp(nodePtr, BAD_CAST(XML_BUNDLE_NAME), BAD_CAST("testBundleName")); - xmlNewProp(nodePtr, BAD_CAST(XML_ENABLE_WINDOW_ORIENTATION), BAD_CAST("invalidValue")); + xmlNodePtr rootNode = xmlNewNode(nullptr, BAD_CAST "root"); + xmlNodePtr configNode = xmlNewNode(nullptr, BAD_CAST "window_orientation"); + EXPECT_NE(rootNode, nullptr); + EXPECT_NE(configNode, nullptr); + xmlAddChild(rootNode, configNode); + xmlNewProp(configNode, BAD_CAST(XML_BUNDLE_NAME), BAD_CAST("testBundleName")); + xmlNewProp(configNode, BAD_CAST(XML_ENABLE_WINDOW_ORIENTATION), BAD_CAST("invalidValue")); + + g_applicationContext.reset(); + ApplicationContextMock* contextMock = new ApplicationContextMock(); + EXPECT_NE(contextMock, nullptr); + EXPECT_CALL(*contextMock, GetBundleName()).Times(1).WillRepeatedly(::testing::Return("testBundleName")); + EXPECT_EQ(g_applicationContext, nullptr); + g_applicationContext.reset(contextMock); + EXPECT_NE(g_applicationContext, nullptr); + std::shared_ptr initArgs = std::make_shared(); - NWebConfigHelper::Instance().ParseWindowOrientationConfig(nodePtr, initArgs); - EXPECT_EQ(initArgs->GetArgsToAdd().size(), 0); + NWebConfigHelper::Instance().ParseWindowOrientationConfig(rootNode, initArgs); + const auto& args = initArgs->GetArgsToAdd(); + EXPECT_EQ(args.size(), 0); + + g_applicationContext.reset(); + EXPECT_EQ(g_applicationContext, nullptr); + xmlFreeNode(rootNode); + xmlFreeNode(configNode); } /** -- Gitee From 1336caacf3ef771fd69d12e0f9afdb5c8c5938cc Mon Sep 17 00:00:00 2001 From: minjiaqi1 Date: Mon, 18 Aug 2025 18:27:07 +0800 Subject: [PATCH 016/124] fix ut test display source mode Signed-off-by: minjiaqi1 --- .../display_manager_adapter_impl_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/display_manager_adapter_impl_test/display_manager_adapter_impl_test.cpp b/test/unittest/display_manager_adapter_impl_test/display_manager_adapter_impl_test.cpp index 908fd92ea..0691597ad 100644 --- a/test/unittest/display_manager_adapter_impl_test/display_manager_adapter_impl_test.cpp +++ b/test/unittest/display_manager_adapter_impl_test/display_manager_adapter_impl_test.cpp @@ -459,7 +459,7 @@ HWTEST_F(DisplayManagerAdapterImplTest, DisplayManagerAdapterImplTest_012, TestS EXPECT_GT(displayAdapterImpl->GetDensityDpi(), 0); EXPECT_GE(displayAdapterImpl->GetX(), 0); EXPECT_GE(displayAdapterImpl->GetY(), 0); - EXPECT_EQ(displayAdapterImpl->GetDisplaySourceMode(), DisplaySourceMode::NONE); + EXPECT_NE(displayAdapterImpl->GetDisplaySourceMode(), DisplaySourceMode::NONE); EXPECT_GE(displayAdapterImpl->GetPhysicalWidth(), 0); EXPECT_GE(displayAdapterImpl->GetPhysicalHeight(), 0); EXPECT_GT(displayAdapterImpl->GetDefaultVirtualPixelRatio(), 0); -- Gitee From 829e9992816037bedc2421fe6f3c3b992619b92f Mon Sep 17 00:00:00 2001 From: taoxueao Date: Mon, 18 Aug 2025 12:47:22 +0000 Subject: [PATCH 017/124] update ohos_adapter/system_properties_adapter/src/system_properties_adapter_impl.cpp. Signed-off-by: taoxueao --- .../src/system_properties_adapter_impl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 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 73e9970e2..9d9b6e0b2 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 @@ -189,8 +189,7 @@ std::string SystemPropertiesAdapterImpl::GetUserAgentOSName() std::string SystemPropertiesAdapterImpl::GetUserAgentOSVersion() { std::string apiname = OHOS::system::GetParameter("const.product.os.dist.apiname", ""); - std::string version = OHOS::system::GetParameter("const.product.os.dist.version", ""); - return apiname.empty() ? version : apiname; + return apiname.empty() ? OHOS::system::GetParameter("const.product.os.dist.version", "") : apiname; } std::string SystemPropertiesAdapterImpl::GetUserAgentBaseOSName() -- Gitee From e2742207f7e6e2f01dd4ace5ec323ba3b955cf81 Mon Sep 17 00:00:00 2001 From: lizeqiang Date: Mon, 18 Aug 2025 20:54:52 +0800 Subject: [PATCH 018/124] fix dual core predlopen error Signed-off-by: lizeqiang --- arkweb_utils/arkweb_utils.cpp | 4 ++-- arkweb_utils/arkweb_utils.h | 2 +- .../bridge/webview/ark_web_adapter_webview_bridge_helper.cpp | 2 +- .../bridge/webview/ark_web_nweb_webview_bridge_helper.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arkweb_utils/arkweb_utils.cpp b/arkweb_utils/arkweb_utils.cpp index ec54831f7..2e1c63fc1 100644 --- a/arkweb_utils/arkweb_utils.cpp +++ b/arkweb_utils/arkweb_utils.cpp @@ -390,7 +390,7 @@ void* ArkWebBridgeHelperLoadLibFile(int openMode, const std::string& libNsName, return libFileHandler; } -void* ArkWebBridgeHelperSharedInit(bool isPreDlopen, bool runMode) +void* ArkWebBridgeHelperSharedInit(bool runMode) { std::string libFileName = "libarkweb_engine.so"; @@ -411,7 +411,7 @@ void* ArkWebBridgeHelperSharedInit(bool isPreDlopen, bool runMode) libFileHandler = ArkWebBridgeHelperLoadLibFile(RTLD_NOW, libDirPath + "/" + libFileName) #endif - if (!isPreDlopen && libFileHandler != nullptr) { + if (libFileHandler != nullptr) { g_webEngineInitFlag = true; WVLOG_I("g_webEngineInitFlag set to true. setActiveWebEngineVersion will be ignored."); } diff --git a/arkweb_utils/arkweb_utils.h b/arkweb_utils/arkweb_utils.h index 79ccd0185..5038192f9 100644 --- a/arkweb_utils/arkweb_utils.h +++ b/arkweb_utils/arkweb_utils.h @@ -88,7 +88,7 @@ ARKWEB_EXPORT void PreloadArkWebLibForBrowser(); ARKWEB_EXPORT void LogForUnsupportedFunc(ArkWebEngineVersion version, const char* msg); -ARKWEB_EXPORT void* ArkWebBridgeHelperSharedInit(bool isPreDlopen, bool runMode = true); +ARKWEB_EXPORT void* ArkWebBridgeHelperSharedInit(bool runMode = true); } // namespace OHOS::ArkWeb #endif // WEB_WEBVIEW_ARKWEB_UTILS_ARKWEB_UTILS_H \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_web_adapter_webview_bridge_helper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_web_adapter_webview_bridge_helper.cpp index d4aa306d4..ea9b65b4a 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_web_adapter_webview_bridge_helper.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_web_adapter_webview_bridge_helper.cpp @@ -36,7 +36,7 @@ void ArkWebAdapterWebviewBridgeHelper::Init() return; } - void* libFileHandler = ArkWebBridgeHelperSharedInit(false); + void* libFileHandler = ArkWebBridgeHelperSharedInit(); if (!libFileHandler) { ARK_WEB_BRIDGE_ERROR_LOG("library resources loaded failed"); return; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.cpp index 79cd6cc9a..ff5872812 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.cpp @@ -34,7 +34,7 @@ bool ArkWebNWebWebviewBridgeHelper::Init(bool runMode, const std::string& bundle return true; } - void* libFileHandler = ArkWebBridgeHelperSharedInit(false, runMode); + void* libFileHandler = ArkWebBridgeHelperSharedInit(runMode); if (!libFileHandler) { ARK_WEB_BRIDGE_ERROR_LOG("library resources loaded failed"); return false; @@ -75,7 +75,7 @@ void ArkWebNWebWebviewBridgeHelper::PreDlopenLibFile(const std::string& bundlePa return; } - libFileHandler_ = ArkWebBridgeHelperSharedInit(true); + libFileHandler_ = ArkWebBridgeHelperSharedInit(); } } // namespace OHOS::ArkWeb -- Gitee From d0496aa80e3336315ee4470276468065fec04b15 Mon Sep 17 00:00:00 2001 From: liubo Date: Mon, 18 Aug 2025 14:44:07 +0800 Subject: [PATCH 019/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8DTDD=20Signed-off-by:?= =?UTF-8?q?=20liubo419=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unittest/arkweb_utils_test/arkweb_utils_test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp index f3f426a7f..dc6aea722 100644 --- a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp +++ b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp @@ -19,8 +19,6 @@ #include #include "arkweb_utils.h" -#include "nweb_config_helper.h" -#include "nweb_log.h" #include "parameters.h" #include "system_properties_adapter_impl.h" @@ -232,8 +230,9 @@ TEST(arkweb_utils_test, GetArkwebInstallPath001) { auto aclPath = GetArkwebInstallPath(); bool res = (aclPath == SANDBOX_LEGACY_HAP_PATH || aclPath == PRECONFIG_LEGACY_HAP_PATH); - NWeb::ProductDeviceType result = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetProductDeviceType(); - if (result == NWeb::ProductDeviceType::DEVICE_TYPE_UNKNOWN) { + // rk is default + std::string deviceType = OHOS::system::GetDeviceType(); + if (deviceType == "default") { EXPECT_FALSE(res); } else { EXPECT_TRUE(res); @@ -249,8 +248,9 @@ TEST(arkweb_utils_test, GetArkwebInstallPath002) { auto aclPath = GetArkwebInstallPath(); bool res = (aclPath == SANDBOX_EVERGREEN_HAP_PATH || aclPath == PRECONFIG_EVERGREEN_HAP_PATH); - NWeb::ProductDeviceType result = NWeb::SystemPropertiesAdapterImpl::GetInstance().GetProductDeviceType(); - if (result == NWeb::ProductDeviceType::DEVICE_TYPE_UNKNOWN) { + std::string deviceType = OHOS::system::GetDeviceType(); + // rk is default + if (deviceType == "default") { EXPECT_FALSE(res); } else { EXPECT_TRUE(res); -- Gitee From 762b1929ccf2ad1f347ff6f1f72b1975eb116d7b Mon Sep 17 00:00:00 2001 From: liuao Date: Tue, 19 Aug 2025 16:36:15 +0800 Subject: [PATCH 020/124] 0819 update ArkWebCore.hap to 6.0 Signed-off-by: liuao --- ohos_nweb/prebuilts/arm/ArkWebCore.hap | 4 ++-- ohos_nweb/prebuilts/arm64/ArkWebCore.hap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_nweb/prebuilts/arm/ArkWebCore.hap b/ohos_nweb/prebuilts/arm/ArkWebCore.hap index 9d6c7ea4c..24b9b7aa9 100644 --- a/ohos_nweb/prebuilts/arm/ArkWebCore.hap +++ b/ohos_nweb/prebuilts/arm/ArkWebCore.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5a2c746237e03bb072ae214e8e5d2a7115342b8e591cd6b768f162712cd94282 -size 116622817 +oid sha256:4e4e58c3feab41059f7994a25430fd265babbbd734943e1ec7a7ec79c572c249 +size 116631011 diff --git a/ohos_nweb/prebuilts/arm64/ArkWebCore.hap b/ohos_nweb/prebuilts/arm64/ArkWebCore.hap index d29aa0644..071f8db4a 100644 --- a/ohos_nweb/prebuilts/arm64/ArkWebCore.hap +++ b/ohos_nweb/prebuilts/arm64/ArkWebCore.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4354c793cc10a8763a10961320468a709ddae61aa9c838e956616289b7e8c1b8 -size 122459582 +oid sha256:6089e61d8b0a963406c475a80042f40566d280937768b8593eda2a9dfd9c34df +size 122455492 -- Gitee From 100a4539cf9899aa2351a4f3a63b2da4451f989f Mon Sep 17 00:00:00 2001 From: justwe <952806070@qq.com> Date: Tue, 19 Aug 2025 19:18:46 +0800 Subject: [PATCH 021/124] add blankless interface Signed-off-by: justwe <952806070@qq.com> --- ohos_interface/include/ohos_nweb/nweb.h | 8 ++++++++ ohos_interface/include/ohos_nweb/nweb_handler.h | 9 +++++++++ .../bridge/webcore/ark_web_handler_wrapper.cpp | 9 +++++++++ .../bridge/webcore/ark_web_handler_wrapper.h | 11 +++++++++++ .../ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp | 4 ++++ .../ohos_nweb/bridge/webcore/ark_web_nweb_impl.h | 7 +++++++ .../bridge/webview/ark_web_handler_impl.cpp | 7 +++++++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.h | 11 +++++++++++ .../bridge/webview/ark_web_nweb_wrapper.cpp | 5 +++++ .../ohos_nweb/bridge/webview/ark_web_nweb_wrapper.h | 6 ++++++ .../ohos_glue/ohos_nweb/include/ark_web_handler.h | 12 ++++++++++++ .../ohos_glue/ohos_nweb/include/ark_web_nweb.h | 8 ++++++++ 12 files changed, 97 insertions(+) diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 1c904e8f5..e2da22cd5 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -2061,6 +2061,14 @@ public: { return WebDestroyMode::NORMAL_MODE; } + + /** + * @brief Record the blankless frame size of the web. + * + * @param width The width of the blankless frame. + * @param height The height of the blankless frame. + */ + virtual void RecordBlanklessFrameSize(uint32_t width, uint32_t height) {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index 59832df9e..f9709da8a 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -1255,6 +1255,15 @@ public: virtual void OnPdfLoadEvent(int32_t result, const std::string& url) {} virtual void OnTakeFocus(std::shared_ptr event) {} + + /** + * @brief Notify the web client to insert blankless frame with size. + * + * @param pathToFrame The file used to insert frame. + * @param width The width of the blankless frame. + * @param height The height of the blankless frame. + */ + virtual void OnInsertBlanklessFrameWithSize(const std::string& pathToFrame, uint32_t width, uint32_t height) {} }; } // 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 93e4e225b..9a4505545 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 @@ -1262,4 +1262,13 @@ void ArkWebHandlerWrapper::OnTakeFocus(std::shared_ptr ark_web_handler_->OnTakeFocus(new ArkWebKeyEventImpl(event)); } + +void ArkWebHandlerWrapper::OnInsertBlanklessFrameWithSize(const std::string& pathToFrame, + uint32_t width, + uint32_t height) +{ + ArkWebString pathToFrame_ = ArkWebStringClassToStruct(pathToFrame); + ark_web_handler_->OnInsertBlanklessFrameWithSize(pathToFrame_, width, height); + ArkWebStringStructRelease(pathToFrame_); +} } // 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 b907f9690..e44db392d 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 @@ -734,6 +734,17 @@ public: void OnPdfLoadEvent(int32_t result, const std::string& url) override; void OnTakeFocus(std::shared_ptr event) override; + + /** + * @brief Notify the web client to insert blankless frame with size. + * + * @param pathToFrame The file used to insert frame. If empty, means remove frame. + * @param width The width of the blankless frame. + * @param height The height of the blankless frame. + */ + void OnInsertBlanklessFrameWithSize(const std::string& pathToFrame, + uint32_t width, + uint32_t height) override; private: ArkWebRefPtr ark_web_handler_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp index b1666ea9a..71807d2be 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 @@ -1548,4 +1548,8 @@ void ArkWebNWebImpl::FillAutofillDataV2(ArkWebRefPtr data) nweb_nweb_->FillAutofillDataV2(std::make_shared(data)); } +void ArkWebNWebImpl::RecordBlanklessFrameSize(uint32_t width, uint32_t height) +{ + nweb_nweb_->RecordBlanklessFrameSize(width, height); +} } // 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 c160b3e49..cacda4484 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 @@ -1758,6 +1758,13 @@ public: ArkWebRefPtr CreateWebPrintDocumentAdapterV2( const ArkWebString& job_name) override; + /** + * @brief Record the blankless frame size of the web. + * @param width The width of the blankless frame. + * @param height The height of the blankless frame. + */ + /*--ark web()--*/ + void RecordBlanklessFrameSize(uint32_t width, uint32_t height) override; private: std::shared_ptr nweb_nweb_; }; 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 e48c5c199..76518eeec 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 @@ -1100,4 +1100,11 @@ void ArkWebHandlerImpl::OnTakeFocus(ArkWebRefPtr event) nweb_handler_->OnTakeFocus(std::make_shared(event)); } + +void ArkWebHandlerImpl::OnInsertBlanklessFrameWithSize(const ArkWebString& pathToFrame, + uint32_t width, + uint32_t height) +{ + nweb_handler_->OnInsertBlanklessFrameWithSize(ArkWebStringStructToClass(pathToFrame), 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 bd471997b..7d75c5046 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 @@ -697,6 +697,17 @@ public: void OnPdfLoadEvent(int32_t result, const ArkWebString& url) override; void OnTakeFocus(ArkWebRefPtr event) override; + + /** + * @brief Notify the web client to do something for blankless. + * + * @param pathToFrame The file used to insert frame. + * @param width The width of the blankless frame. + * @param height The height of the blankless frame. + */ + void OnInsertBlanklessFrameWithSize(const ArkWebString& pathToFrame, + uint32_t width, + uint32_t height) override; private: std::shared_ptr nweb_handler_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp index bfdfecba3..cbb03fda0 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 @@ -1819,4 +1819,9 @@ void ArkWebNWebWrapper::FillAutofillDataV2(std::shared_ptrFillAutofillDataV2(new ArkWebRomValueImpl(data)); } + +void ArkWebNWebWrapper::RecordBlanklessFrameSize(uint32_t width, uint32_t height) +{ + ark_web_nweb_->RecordBlanklessFrameSize(width, height); +} } // 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 c5e593afc..1ea2eea68 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 @@ -1771,6 +1771,12 @@ public: std::unique_ptr CreateWebPrintDocumentAdapterV2( const std::string& job_name) override; + /** + * @brief Record the blankless frame size of the web. + * @param width The width of the blankless frame. + * @param height The height of the blankless frame. + */ + void RecordBlanklessFrameSize(uint32_t width, uint32_t height) override; private: ArkWebRefPtr ark_web_nweb_; }; 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 eb9199b79..6799938e2 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 @@ -1024,6 +1024,18 @@ public: /*--ark web()--*/ virtual void OnTakeFocus(ArkWebRefPtr event) = 0; + + /** + * @brief Notify the web client to insert blankless frame with size. + * + * @param pathToFrame The file used to insert frame. + * @param width The width of the blankless frame. + * @param height The height of the blankless frame. + */ + /*--ark web()--*/ + virtual void OnInsertBlanklessFrameWithSize(const ArkWebString& pathToFrame, + uint32_t width, + uint32_t height) = 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 f2d1123e6..fdfc2a2d3 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 @@ -1994,6 +1994,14 @@ public: /*--ark web()--*/ virtual ArkWebRefPtr CreateWebPrintDocumentAdapterV2( const ArkWebString& job_name) = 0; + + /** + * @brief Record the blankless frame size of the web. + * @param width The width of the blankless frame. + * @param height The height of the blankless frame. + */ + /*--ark web()--*/ + virtual void RecordBlanklessFrameSize(uint32_t width, uint32_t height) = 0; }; } // namespace OHOS::ArkWeb -- Gitee From 832076ac0eefe0a63d96729cf3d25315f71df641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B3=A2?= Date: Tue, 19 Aug 2025 11:40:56 +0000 Subject: [PATCH 022/124] update test/unittest/arkweb_utils_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘波 --- test/unittest/arkweb_utils_test/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/arkweb_utils_test/BUILD.gn b/test/unittest/arkweb_utils_test/BUILD.gn index f0f107a8e..c8764e4d8 100644 --- a/test/unittest/arkweb_utils_test/BUILD.gn +++ b/test/unittest/arkweb_utils_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_unittest("arkweb_utils_test") { "$webview_path/arkweb_utils:libarkweb_utils", "$webview_path/ohos_adapter:nweb_ohos_adapter" ] + external_deps = [ "ability_runtime:app_context", "ability_runtime:app_manager", -- Gitee From 8c570d4b723fb80a07b79a5e22fd55929db7e6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B3=A2?= Date: Tue, 19 Aug 2025 11:42:43 +0000 Subject: [PATCH 023/124] update test/unittest/arkweb_utils_test/arkweb_utils_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘波 --- test/unittest/arkweb_utils_test/arkweb_utils_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp index dc6aea722..63c071998 100644 --- a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp +++ b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp @@ -248,8 +248,8 @@ TEST(arkweb_utils_test, GetArkwebInstallPath002) { auto aclPath = GetArkwebInstallPath(); bool res = (aclPath == SANDBOX_EVERGREEN_HAP_PATH || aclPath == PRECONFIG_EVERGREEN_HAP_PATH); - std::string deviceType = OHOS::system::GetDeviceType(); // rk is default + std::string deviceType = OHOS::system::GetDeviceType(); if (deviceType == "default") { EXPECT_FALSE(res); } else { -- Gitee From fadc62613e68c621c9a43268143f627c6b613eb1 Mon Sep 17 00:00:00 2001 From: taoxueao Date: Tue, 19 Aug 2025 14:47:01 +0000 Subject: [PATCH 024/124] update ohos_nweb/src/nweb_helper.cpp. Signed-off-by: taoxueao --- ohos_nweb/src/nweb_helper.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index c879fb011..53805e0a9 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -707,7 +707,6 @@ bool NWebHelper::GetWebEngine(bool fromArk) bool NWebHelper::InitWebEngine() { if (initFlag_) { - WVLOG_I("web engine has been initialized"); return true; } -- Gitee From 7d0e9af2a627f64ac1767b0bedd62ea37a582746 Mon Sep 17 00:00:00 2001 From: slimshady999z Date: Mon, 18 Aug 2025 19:57:35 +0800 Subject: [PATCH 025/124] =?UTF-8?q?=E6=89=8B=E5=86=99=E7=AC=94=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: slim --- ohos_glue/BUILD.gn | 6 ++ ohos_interface/BUILD.gn | 6 ++ ohos_interface/include/ohos_nweb/nweb.h | 52 +++++++++++++ ohos_interface/ohos_glue/BUILD_webcore.gn | 6 ++ .../base/include/ark_web_bridge_types.h | 1 + .../bridge/webcore/ark_web_nweb_impl.cpp | 33 ++++++++ .../bridge/webcore/ark_web_nweb_impl.h | 24 ++++++ ...rk_web_stylus_touch_point_info_wrapper.cpp | 77 +++++++++++++++++++ .../ark_web_stylus_touch_point_info_wrapper.h | 51 ++++++++++++ .../bridge/webview/ark_web_nweb_wrapper.cpp | 37 +++++++++ .../bridge/webview/ark_web_nweb_wrapper.h | 25 ++++++ .../ark_web_stylus_touch_point_info_impl.cpp | 77 +++++++++++++++++++ .../ark_web_stylus_touch_point_info_impl.h | 48 ++++++++++++ ..._stylus_touch_point_info_vector_cpptoc.cpp | 56 ++++++++++++++ ...eb_stylus_touch_point_info_vector_cpptoc.h | 32 ++++++++ ..._stylus_touch_point_info_vector_ctocpp.cpp | 39 ++++++++++ ...eb_stylus_touch_point_info_vector_ctocpp.h | 30 ++++++++ .../ohos_nweb/include/ark_web_nweb.h | 32 ++++++++ .../include/ark_web_stylus_touch_point_info.h | 59 ++++++++++++++ .../ark_web_stylus_touch_point_info_vector.h | 35 +++++++++ .../ohos_glue/scripts/file_parser.py | 3 + 21 files changed, 729 insertions(+) create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/ctocpp/webcore/ark_web_stylus_touch_point_info_vector_ctocpp.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/ctocpp/webcore/ark_web_stylus_touch_point_info_vector_ctocpp.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info_vector.h diff --git a/ohos_glue/BUILD.gn b/ohos_glue/BUILD.gn index a0871a88c..1e59ca2de 100644 --- a/ohos_glue/BUILD.gn +++ b/ohos_glue/BUILD.gn @@ -227,6 +227,8 @@ action("ohos_glue_nweb_prepare") { "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_string_value_callback_impl.h", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_string_vector_value_callback_wrapper.cpp", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_string_vector_value_callback_wrapper.h", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_stylus_touch_point_info_impl.cpp", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_stylus_touch_point_info_impl.h", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_system_configuration_impl.cpp", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_system_configuration_impl.h", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_touch_handle_hot_zone_wrapper.cpp", @@ -323,6 +325,10 @@ action("ohos_glue_nweb_prepare") { "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_string_value_callback_cpptoc.h", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_system_configuration_cpptoc.cpp", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_system_configuration_cpptoc.h", + "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_stylus_touch_point_info_cpptoc.cpp", + "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_stylus_touch_point_info_cpptoc.h", + "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_stylus_touch_point_info_vector_cpptoc.cpp", + "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_stylus_touch_point_info_vector_cpptoc.h", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_touch_point_info_cpptoc.cpp", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_touch_point_info_cpptoc.h", "${glue_build_gen_dir}/ohos_nweb/cpptoc/ark_web_touch_point_info_vector_cpptoc.cpp", diff --git a/ohos_interface/BUILD.gn b/ohos_interface/BUILD.gn index da3ef3d51..e270cfb0e 100644 --- a/ohos_interface/BUILD.gn +++ b/ohos_interface/BUILD.gn @@ -209,6 +209,7 @@ action("webview_glue_nweb_prepare") { "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_media_player_bridge.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_media_player_handler.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_touch_point_info_vector.h", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info_vector.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_history_list.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_drag_event.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_url_resource_response.h", @@ -301,6 +302,7 @@ action("webview_glue_nweb_prepare") { "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_image_options.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_accessibility_node_info.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_controller_handler.h", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_media_player_handler_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_date_time_chooser_callback_wrapper.cpp", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_message_value_callback_impl.h", @@ -450,6 +452,8 @@ action("webview_glue_nweb_prepare") { "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_select_popup_menu_item_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_cookie_manager_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_drag_event_impl.cpp", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.cpp", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_custom_keyboard_handler_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_gesture_event_result_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_date_time_chooser_wrapper.cpp", @@ -492,6 +496,8 @@ action("webview_glue_nweb_prepare") { "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_drag_data_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_prefetch_args_impl.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_value_vector_cpptoc.h", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.h", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.cpp", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_touch_point_info_vector_cpptoc.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_js_proxy_callback_vector_cpptoc.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_js_proxy_callback_vector_cpptoc.cpp", diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 1c904e8f5..417df6c99 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -76,6 +76,20 @@ enum class ImageAlphaType { ALPHA_TYPE_POSTMULTIPLIED = 2, }; +enum class SourceTool : int32_t { + UNKNOWN = 0, + FINGER = 1, + PEN = 2, + RUBBER = 3, + BRUSH = 4, + PENCIL = 5, + AIRBRUSH = 6, + MOUSE = 7, + LENS = 8, + TOUCHPAD = 9, + JOYSTICK = 10, +}; + class OHOS_NWEB_EXPORT NWebEngineInitArgs { public: virtual ~NWebEngineInitArgs() = default; @@ -164,6 +178,18 @@ public: virtual double GetY() = 0; }; +class NWebStylusTouchPointInfo : public NWebTouchPointInfo { +public: + virtual ~NWebStylusTouchPointInfo() = default; + virtual float GetForce() = 0; + virtual float GetTiltX() = 0; + virtual float GetTiltY() = 0; + virtual float GetRollAngle() = 0; + virtual int32_t GetWidth() = 0; + virtual int32_t GetHeight() = 0; + virtual SourceTool GetSourceTool() = 0; +}; + enum class NestedScrollMode : int32_t { SELF_ONLY = 0, SELF_FIRST = 1, @@ -2061,6 +2087,32 @@ public: { return WebDestroyMode::NORMAL_MODE; } + + /** + * @brief Handle stylus touch press event. + * @param stylus_touch_point_info The stylus touch point information containing comprehensive parameters. + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + virtual void OnStylusTouchPress( + std::shared_ptr stylus_touch_point_info, bool from_overlay) = 0; + + /** + * @brief Handle stylus touch release event. + * @param stylus_touch_point_info The stylus touch point information containing comprehensive parameters. + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + virtual void OnStylusTouchRelease( + std::shared_ptr stylus_touch_point_info, bool from_overlay) = 0; + + /** + * @brief Handle batch stylus touch move events. + * @param stylus_touch_point_infos The vector containing multiple stylus touch points, + * each is a shared pointer to NWebStylusTouchPointInfo. + * @param from_overlay Indicates whether the events come from an overlay layer. + */ + virtual void OnStylusTouchMove( + const std::vector>& stylus_touch_point_infos, bool from_overlay) = 0; + }; } // namespace OHOS::NWeb diff --git a/ohos_interface/ohos_glue/BUILD_webcore.gn b/ohos_interface/ohos_glue/BUILD_webcore.gn index 050a7b8de..e0746d743 100644 --- a/ohos_interface/ohos_glue/BUILD_webcore.gn +++ b/ohos_interface/ohos_glue/BUILD_webcore.gn @@ -232,6 +232,8 @@ component("ohos_nweb_glue_source") { "ohos_nweb/bridge/ark_web_string_vector_value_callback_impl.h", "ohos_nweb/bridge/ark_web_system_configuration_wrapper.cpp", "ohos_nweb/bridge/ark_web_system_configuration_wrapper.h", + "ohos_nweb/bridge/ark_web_stylus_touch_point_info_wrapper.cpp", + "ohos_nweb/bridge/ark_web_stylus_touch_point_info_wrapper.h", "ohos_nweb/bridge/ark_web_touch_handle_hot_zone_impl.cpp", "ohos_nweb/bridge/ark_web_touch_handle_hot_zone_impl.h", "ohos_nweb/bridge/ark_web_touch_handle_state_impl.cpp", @@ -462,6 +464,10 @@ component("ohos_nweb_glue_source") { "ohos_nweb/ctocpp/ark_web_string_value_callback_ctocpp.h", "ohos_nweb/ctocpp/ark_web_system_configuration_ctocpp.cpp", "ohos_nweb/ctocpp/ark_web_system_configuration_ctocpp.h", + "ohos_nweb/ctocpp/ark_web_stylus_touch_point_info_ctocpp.cpp", + "ohos_nweb/ctocpp/ark_web_stylus_touch_point_info_ctocpp.h", + "ohos_nweb/ctocpp/ark_web_stylus_touch_point_info_vector_ctocpp.cpp", + "ohos_nweb/ctocpp/ark_web_stylus_touch_point_info_vector_ctocpp.h", "ohos_nweb/ctocpp/ark_web_touch_point_info_ctocpp.cpp", "ohos_nweb/ctocpp/ark_web_touch_point_info_ctocpp.h", "ohos_nweb/ctocpp/ark_web_touch_point_info_vector_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 8b3104f89..d3d18a233 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 @@ -123,6 +123,7 @@ enum ArkWebBridgeType { ARK_WEB_PRINT_ATTRIBUTES_ADAPTER = 100, ARK_WEB_PRINT_WRITE_RESULT_CALLBACK_ADAPTER = 101, ARK_WEB_PRINT_DOCUMENT_ADAPTER_ADAPTER = 102, + ARK_WEB_STYLUS_TOUCH_POINT_INFO = 104, /*Note: The end of nweb interface bridge type*/ ARK_WEB_NWEB_INTERFACE_BUTT, 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 b1666ea9a..453ee72c7 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 @@ -41,10 +41,12 @@ #include "ohos_nweb/bridge/ark_web_screen_lock_callback_wrapper.h" #include "ohos_nweb/bridge/ark_web_spanstring_convert_html_callback_wrapper.h" #include "ohos_nweb/bridge/ark_web_string_value_callback_wrapper.h" +#include "ohos_nweb/bridge/ark_web_stylus_touch_point_info_wrapper.h" #include "ohos_nweb/bridge/ark_web_system_configuration_wrapper.h" #include "ohos_nweb/bridge/ark_web_print_document_adapter_adapter_impl.h" #include "ohos_nweb/ctocpp/ark_web_js_proxy_callback_vector_ctocpp.h" #include "ohos_nweb/ctocpp/ark_web_rom_value_vector_ctocpp.h" +#include "ohos_nweb/ctocpp/ark_web_stylus_touch_point_info_vector_ctocpp.h" #include "ohos_nweb/ctocpp/ark_web_touch_point_info_vector_ctocpp.h" #include "ohos_nweb/ctocpp/ark_web_value_vector_ctocpp.h" @@ -1548,4 +1550,35 @@ void ArkWebNWebImpl::FillAutofillDataV2(ArkWebRefPtr data) nweb_nweb_->FillAutofillDataV2(std::make_shared(data)); } +void ArkWebNWebImpl::OnStylusTouchPress( + ArkWebRefPtr stylus_touch_point_info, bool from_overlay) +{ + if (CHECK_REF_PTR_IS_NULL(stylus_touch_point_info)) { + nweb_nweb_->OnStylusTouchPress(nullptr, from_overlay); + return; + } + + nweb_nweb_->OnStylusTouchPress( + std::make_shared(stylus_touch_point_info), from_overlay); +} + +void ArkWebNWebImpl::OnStylusTouchRelease( + ArkWebRefPtr stylus_touch_point_info, bool from_overlay) +{ + if (CHECK_REF_PTR_IS_NULL(stylus_touch_point_info)) { + nweb_nweb_->OnStylusTouchRelease(nullptr, from_overlay); + return; + } + + nweb_nweb_->OnStylusTouchRelease( + std::make_shared(stylus_touch_point_info), from_overlay); +} + +void ArkWebNWebImpl::OnStylusTouchMove( + const ArkWebStylusTouchPointInfoVector& stylus_touch_point_infos, bool from_overlay) +{ + nweb_nweb_->OnStylusTouchMove( + ArkWebStylusTouchPointInfoVectorStructToClass(stylus_touch_point_infos), from_overlay); +} + } // 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 c160b3e49..cc1b64431 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 @@ -1758,6 +1758,30 @@ public: ArkWebRefPtr CreateWebPrintDocumentAdapterV2( const ArkWebString& job_name) override; + /** + * @brief Handle stylus touch press event. + * @param stylus_touch_point_info The stylus touch point information containing detailed parameters. + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + void OnStylusTouchPress( + ArkWebRefPtr stylus_touch_point_info, bool from_overlay) override; + + /** + * @brief Handle stylus touch release event. + * @param stylus_touch_point_info The stylus touch point information containing detailed parameters. + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + void OnStylusTouchRelease( + ArkWebRefPtr stylus_touch_point_info, bool from_overlay) override; + + /** + * @brief Handle stylus touch move event. + * @param stylus_touch_point_infos The collection of stylus touch point information. + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + void OnStylusTouchMove( + const ArkWebStylusTouchPointInfoVector& stylus_touch_point_infos, bool from_overlay) override; + private: std::shared_ptr nweb_nweb_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.cpp new file mode 100644 index 000000000..14f1fc3da --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_stylus_touch_point_info_wrapper.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebStylusTouchPointInfoWrapper::ArkWebStylusTouchPointInfoWrapper( + ArkWebRefPtr ark_web_stylus_touch_point_info) + : ark_web_stylus_touch_point_info_(ark_web_stylus_touch_point_info) +{} + +int32_t ArkWebStylusTouchPointInfoWrapper::GetId() +{ + return ark_web_stylus_touch_point_info_->GetId(); +} + +double ArkWebStylusTouchPointInfoWrapper::GetX() +{ + return ark_web_stylus_touch_point_info_->GetX(); +} + +double ArkWebStylusTouchPointInfoWrapper::GetY() +{ + return ark_web_stylus_touch_point_info_->GetY(); +} + +float ArkWebStylusTouchPointInfoWrapper::GetForce() +{ + return ark_web_stylus_touch_point_info_->GetForce(); +} + +float ArkWebStylusTouchPointInfoWrapper::GetTiltX() +{ + return ark_web_stylus_touch_point_info_->GetTiltX(); +} + +float ArkWebStylusTouchPointInfoWrapper::GetTiltY() +{ + return ark_web_stylus_touch_point_info_->GetTiltY(); +} + +float ArkWebStylusTouchPointInfoWrapper::GetRollAngle() +{ + return ark_web_stylus_touch_point_info_->GetRollAngle(); +} + +int32_t ArkWebStylusTouchPointInfoWrapper::GetWidth() +{ + return ark_web_stylus_touch_point_info_->GetWidth(); +} + +int32_t ArkWebStylusTouchPointInfoWrapper::GetHeight() +{ + return ark_web_stylus_touch_point_info_->GetHeight(); +} + +SourceTool ArkWebStylusTouchPointInfoWrapper::GetSourceTool() +{ + return static_cast(ark_web_stylus_touch_point_info_->GetSourceTool()); +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.h new file mode 100644 index 000000000..b86ca4955 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_STYLUS_TOUCH_POINT_INFO_WRAPPER_H_ +#define ARK_WEB_STYLUS_TOUCH_POINT_INFO_WRAPPER_H_ +#pragma once + +#include "include/nweb.h" +#include "ohos_nweb/include/ark_web_stylus_touch_point_info.h" + +#include "base/include/ark_web_types.h" + +namespace OHOS::ArkWeb { + +using ArkWebSourceTool = OHOS::NWeb::SourceTool; + +class ArkWebStylusTouchPointInfoWrapper : public OHOS::NWeb::NWebStylusTouchPointInfo { +public: + ArkWebStylusTouchPointInfoWrapper(ArkWebRefPtr ark_web_stylus_touch_point_info); + ~ArkWebStylusTouchPointInfoWrapper() = default; + + int32_t GetId() override; + double GetX() override; + double GetY() override; + float GetForce() override; + float GetTiltX() override; + float GetTiltY() override; + float GetRollAngle() override; + int32_t GetWidth() override; + int32_t GetHeight() override; + ArkWebSourceTool GetSourceTool() override; + +private: + ArkWebRefPtr ark_web_stylus_touch_point_info_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_STYLUS_TOUCH_POINT_INFO_WRAPPER_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 bfdfecba3..0c2cce650 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 @@ -40,11 +40,13 @@ #include "ohos_nweb/bridge/ark_web_screen_lock_callback_impl.h" #include "ohos_nweb/bridge/ark_web_spanstring_convert_html_callback_impl.h" #include "ohos_nweb/bridge/ark_web_string_value_callback_impl.h" +#include "ohos_nweb/bridge/ark_web_stylus_touch_point_info_impl.h" #include "ohos_nweb/bridge/ark_web_system_configuration_impl.h" #include "ohos_nweb/bridge/ark_web_view_struct_utils.h" #include "ohos_nweb/bridge/ark_web_print_document_adapter_adapter_wrapper.h" #include "ohos_nweb/cpptoc/ark_web_js_proxy_callback_vector_cpptoc.h" #include "ohos_nweb/cpptoc/ark_web_rom_value_vector_cpptoc.h" +#include "ohos_nweb/cpptoc/ark_web_stylus_touch_point_info_vector_cpptoc.h" #include "ohos_nweb/cpptoc/ark_web_touch_point_info_vector_cpptoc.h" #include "ohos_nweb/cpptoc/ark_web_value_vector_cpptoc.h" @@ -1819,4 +1821,39 @@ void ArkWebNWebWrapper::FillAutofillDataV2(std::shared_ptrFillAutofillDataV2(new ArkWebRomValueImpl(data)); } + +void ArkWebNWebWrapper::OnStylusTouchPress( + std::shared_ptr stylus_touch_point_info, bool from_overlay) +{ + if (CHECK_SHARED_PTR_IS_NULL(stylus_touch_point_info)) { + ark_web_nweb_->OnStylusTouchPress(nullptr, from_overlay); + return; + } + + ark_web_nweb_->OnStylusTouchPress(new ArkWebStylusTouchPointInfoImpl(stylus_touch_point_info), from_overlay); +} + +void ArkWebNWebWrapper::OnStylusTouchRelease( + std::shared_ptr stylus_touch_point_info, bool from_overlay) +{ + if (CHECK_SHARED_PTR_IS_NULL(stylus_touch_point_info)) { + ark_web_nweb_->OnStylusTouchRelease(nullptr, from_overlay); + return; + } + + ark_web_nweb_->OnStylusTouchRelease(new ArkWebStylusTouchPointInfoImpl(stylus_touch_point_info), from_overlay); +} + +void ArkWebNWebWrapper::OnStylusTouchMove( + const std::vector>& stylus_touch_point_infos, + bool from_overlay) +{ + ArkWebStylusTouchPointInfoVector st_stylus_point_infos = + ArkWebStylusTouchPointInfoVectorClassToStruct(stylus_touch_point_infos); + + ark_web_nweb_->OnStylusTouchMove(st_stylus_point_infos, from_overlay); + + ArkWebStylusTouchPointInfoVectorStructRelease(st_stylus_point_infos); +} + } // 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 c5e593afc..d27e1891d 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 @@ -1771,6 +1771,31 @@ public: std::unique_ptr CreateWebPrintDocumentAdapterV2( const std::string& job_name) override; + /** + * @brief Handle stylus touch press event. + * @param stylus_touch_point_info The NWeb stylus touch point information object. + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + void OnStylusTouchPress( + std::shared_ptr stylus_touch_point_info, bool from_overlay) override; + + /** + * @brief Handle stylus touch release event. + * @param stylus_touch_point_info The NWeb stylus touch point information object. + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + void OnStylusTouchRelease( + std::shared_ptr stylus_touch_point_info, bool from_overlay) override; + + /** + * @brief Handle stylus touch move event. + * @param stylus_touch_point_infos The vector of NWeb stylus touch point information objects. + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + void OnStylusTouchMove( + const std::vector>& stylus_touch_point_infos, + bool from_overlay) override; + private: ArkWebRefPtr ark_web_nweb_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.cpp new file mode 100644 index 000000000..6d4e574e9 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_stylus_touch_point_info_impl.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebStylusTouchPointInfoImpl::ArkWebStylusTouchPointInfoImpl( + std::shared_ptr nweb_stylus_touch_point_info) + : nweb_stylus_touch_point_info_(nweb_stylus_touch_point_info) +{} + +int32_t ArkWebStylusTouchPointInfoImpl::GetId() +{ + return nweb_stylus_touch_point_info_->GetId(); +} + +double ArkWebStylusTouchPointInfoImpl::GetX() +{ + return nweb_stylus_touch_point_info_->GetX(); +} + +double ArkWebStylusTouchPointInfoImpl::GetY() +{ + return nweb_stylus_touch_point_info_->GetY(); +} + +float ArkWebStylusTouchPointInfoImpl::GetForce() +{ + return nweb_stylus_touch_point_info_->GetForce(); +} + +float ArkWebStylusTouchPointInfoImpl::GetTiltX() +{ + return nweb_stylus_touch_point_info_->GetTiltX(); +} + +float ArkWebStylusTouchPointInfoImpl::GetTiltY() +{ + return nweb_stylus_touch_point_info_->GetTiltY(); +} + +float ArkWebStylusTouchPointInfoImpl::GetRollAngle() +{ + return nweb_stylus_touch_point_info_->GetRollAngle(); +} + +int32_t ArkWebStylusTouchPointInfoImpl::GetWidth() +{ + return nweb_stylus_touch_point_info_->GetWidth(); +} + +int32_t ArkWebStylusTouchPointInfoImpl::GetHeight() +{ + return nweb_stylus_touch_point_info_->GetHeight(); +} + +int32_t ArkWebStylusTouchPointInfoImpl::GetSourceTool() +{ + return static_cast(nweb_stylus_touch_point_info_->GetSourceTool()); +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.h new file mode 100644 index 000000000..90854c7cb --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_stylus_touch_point_info_impl.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_STYLUS_TOUCH_POINT_INFO_IMPL_H_ +#define ARK_WEB_STYLUS_TOUCH_POINT_INFO_IMPL_H_ +#pragma once + +#include "include/nweb.h" +#include "ohos_nweb/include/ark_web_stylus_touch_point_info.h" + +namespace OHOS::ArkWeb { + +class ArkWebStylusTouchPointInfoImpl : public ArkWebStylusTouchPointInfo { + IMPLEMENT_REFCOUNTING(ArkWebStylusTouchPointInfoImpl); + +public: + ArkWebStylusTouchPointInfoImpl(std::shared_ptr nweb_stylus_touch_point_info); + ~ArkWebStylusTouchPointInfoImpl() = default; + + int32_t GetId() override; + double GetX() override; + double GetY() override; + float GetForce() override; + float GetTiltX() override; + float GetTiltY() override; + float GetRollAngle() override; + int32_t GetWidth() override; + int32_t GetHeight() override; + int32_t GetSourceTool() override; + +private: + std::shared_ptr nweb_stylus_touch_point_info_; +}; + +} // namespace OHOS::ArkWeb +#endif // ARK_WEB_STYLUS_TOUCH_POINT_INFO_IMPL_H_ diff --git a/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.cpp b/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.cpp new file mode 100644 index 000000000..c9f81a8d3 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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/cpptoc/ark_web_stylus_touch_point_info_vector_cpptoc.h" + +#include "ohos_nweb/bridge/ark_web_stylus_touch_point_info_impl.h" +#include "ohos_nweb/cpptoc/ark_web_stylus_touch_point_info_cpptoc.h" + +#include "base/include/ark_web_memory.h" + +namespace OHOS::ArkWeb { + +ArkWebStylusTouchPointInfoVector ArkWebStylusTouchPointInfoVectorClassToStruct( + const std::vector>& class_value) +{ + ArkWebStylusTouchPointInfoVector struct_value = { .size = static_cast(class_value.size()), + .ark_web_mem_free_func = ArkWebMemFree }; + if (struct_value.size > 0) { + struct_value.value = (ark_web_stylus_touch_point_info_t**)ArkWebMemMalloc( + sizeof(ark_web_stylus_touch_point_info_t*) * struct_value.size); + if (struct_value.value == nullptr) { + struct_value.size = 0; + return struct_value; + } + + int count = 0; + for (auto it = class_value.begin(); it != class_value.end(); it++) { + ArkWebRefPtr ark_web_stylus_point_info = + new ArkWebStylusTouchPointInfoImpl(*it); + struct_value.value[count] = ArkWebStylusTouchPointInfoCppToC::Invert(ark_web_stylus_point_info); + count++; + } + } + + return struct_value; +} + +ARK_WEB_NO_SANITIZE void ArkWebStylusTouchPointInfoVectorStructRelease(ArkWebStylusTouchPointInfoVector& struct_value) +{ + struct_value.size = 0; + SAFE_FREE(struct_value.value, struct_value.ark_web_mem_free_func); +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.h b/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.h new file mode 100644 index 000000000..797320fab --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webview/ark_web_stylus_touch_point_info_vector_cpptoc.h @@ -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. + */ + +#ifndef ARK_WEB_STYLUS_TOUCH_POINT_INFO_VECTOR_CPPTOC_H_ +#define ARK_WEB_STYLUS_TOUCH_POINT_INFO_VECTOR_CPPTOC_H_ +#pragma once + +#include "include/nweb.h" +#include "ohos_nweb/include/ark_web_stylus_touch_point_info_vector.h" + +namespace OHOS::ArkWeb { + +ArkWebStylusTouchPointInfoVector ArkWebStylusTouchPointInfoVectorClassToStruct( + const std::vector>& class_value); + +void ArkWebStylusTouchPointInfoVectorStructRelease(ArkWebStylusTouchPointInfoVector& struct_value); + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_STYLUS_TOUCH_POINT_INFO_VECTOR_CPPTOC_H_ diff --git a/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webcore/ark_web_stylus_touch_point_info_vector_ctocpp.cpp b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webcore/ark_web_stylus_touch_point_info_vector_ctocpp.cpp new file mode 100644 index 000000000..8beeed079 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webcore/ark_web_stylus_touch_point_info_vector_ctocpp.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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/ctocpp/ark_web_stylus_touch_point_info_vector_ctocpp.h" + +#include "ohos_nweb/bridge/ark_web_stylus_touch_point_info_wrapper.h" +#include "ohos_nweb/ctocpp/ark_web_stylus_touch_point_info_ctocpp.h" + +namespace OHOS::ArkWeb { + +std::vector> + ARK_WEB_CALLBACK ArkWebStylusTouchPointInfoVectorStructToClass(const ArkWebStylusTouchPointInfoVector& struct_value) +{ + std::vector> class_value; + if (struct_value.size > 0) { + for (int count = 0; count < struct_value.size; count++) { + std::shared_ptr nweb_stylus_point_info = + std::make_shared( + ArkWebStylusTouchPointInfoCToCpp::Invert(struct_value.value[count])); + class_value.push_back(nweb_stylus_point_info); + } + } + + return class_value; +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webcore/ark_web_stylus_touch_point_info_vector_ctocpp.h b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webcore/ark_web_stylus_touch_point_info_vector_ctocpp.h new file mode 100644 index 000000000..8a2fb36e8 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webcore/ark_web_stylus_touch_point_info_vector_ctocpp.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_STYLUS_TOUCH_POINT_INFO_VECTOR_CTOCPP_H_ +#define ARK_WEB_STYLUS_TOUCH_POINT_INFO_VECTOR_CTOCPP_H_ +#pragma once + +#include "include/nweb.h" +#include "ohos_nweb/include/ark_web_stylus_touch_point_info_vector.h" + +namespace OHOS::ArkWeb { + +std::vector> ARK_WEB_CALLBACK +ArkWebStylusTouchPointInfoVectorStructToClass(const ArkWebStylusTouchPointInfoVector& struct_value); + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_STYLUS_TOUCH_POINT_INFO_VECTOR_CTOCPP_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 f2d1123e6..7a85b1ec5 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 @@ -43,6 +43,8 @@ #include "ohos_nweb/include/ark_web_screen_lock_callback.h" #include "ohos_nweb/include/ark_web_spanstring_convert_html_callback.h" #include "ohos_nweb/include/ark_web_string_value_callback.h" +#include "ohos_nweb/include/ark_web_stylus_touch_point_info.h" +#include "ohos_nweb/include/ark_web_stylus_touch_point_info_vector.h" #include "ohos_nweb/include/ark_web_system_configuration.h" #include "ohos_nweb/include/ark_web_touch_point_info_vector.h" #include "ohos_nweb/include/ark_web_print_document_adapter_adapter.h" @@ -1994,6 +1996,36 @@ public: /*--ark web()--*/ virtual ArkWebRefPtr CreateWebPrintDocumentAdapterV2( const ArkWebString& job_name) = 0; + + /** + * @brief Handle stylus touch press event. + * @param stylus_touch_point_info The stylus touch point information object containing all necessary data + * (including id, coordinates, and stylus properties). + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + /*--ark web()--*/ + virtual void OnStylusTouchPress( + ArkWebRefPtr stylus_touch_point_info, bool from_overlay) = 0; + + /** + * @brief Handle stylus touch release event. + * @param stylus_touch_point_info The stylus touch point information object containing all necessary data + * (including id, coordinates, and stylus properties). + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + /*--ark web()--*/ + virtual void OnStylusTouchRelease( + ArkWebRefPtr stylus_touch_point_info, bool from_overlay) = 0; + + /** + * @brief Handle stylus touch move event. + * @param stylus_touch_point_infos The collection of stylus touch point information containing all necessary data + * (including multiple points with their ids, coordinates, and properties). + * @param from_overlay Indicates whether the event comes from an overlay layer. + */ + /*--ark web()--*/ + virtual void OnStylusTouchMove( + const ArkWebStylusTouchPointInfoVector& stylus_touch_point_infos, bool from_overlay) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info.h new file mode 100644 index 000000000..6fc0ecca6 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_STYLUS_TOUCH_POINT_INFO_H_ +#define ARK_WEB_STYLUS_TOUCH_POINT_INFO_H_ +#pragma once + +#include "base/include/ark_web_base_ref_counted.h" + +namespace OHOS::ArkWeb { + +/*--ark web(source=webview)--*/ +class ArkWebStylusTouchPointInfo : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual int32_t GetId() = 0; + + /*--ark web()--*/ + virtual double GetX() = 0; + + /*--ark web()--*/ + virtual double GetY() = 0; + + /*--ark web()--*/ + virtual int32_t GetSourceTool() = 0; + + /*--ark web()--*/ + virtual float GetForce() = 0; + + /*--ark web()--*/ + virtual float GetTiltX() = 0; + + /*--ark web()--*/ + virtual float GetTiltY() = 0; + + /*--ark web()--*/ + virtual float GetRollAngle() = 0; + + /*--ark web()--*/ + virtual int32_t GetWidth() = 0; + + /*--ark web()--*/ + virtual int32_t GetHeight() = 0; +}; + +} // namespace OHOS::ArkWeb +#endif // ARK_WEB_STYLUS_TOUCH_POINT_INFO_H_ diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info_vector.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info_vector.h new file mode 100644 index 000000000..23a93836d --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_stylus_touch_point_info_vector.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_STYLUS_TOUCH_POINT_INFO_VECTOR_H_ +#define ARK_WEB_STYLUS_TOUCH_POINT_INFO_VECTOR_H_ +#pragma once + +#include "ohos_nweb/capi/ark_web_stylus_touch_point_info_capi.h" + +#include "base/include/ark_web_memory.h" + +typedef struct { + int size; + ark_web_stylus_touch_point_info_t** value; + + ArkWebMemFreeFunc ark_web_mem_free_func; +} ArkWebStylusTouchPointInfoVector; + +const ArkWebStylusTouchPointInfoVector ark_web_stylus_touch_point_info_vector_default = { + 0, +}; + +#endif // ARK_WEB_STYLUS_TOUCH_POINT_INFO_VECTOR_H_ diff --git a/ohos_interface/ohos_glue/scripts/file_parser.py b/ohos_interface/ohos_glue/scripts/file_parser.py index fa99d1d44..a378c439a 100644 --- a/ohos_interface/ohos_glue/scripts/file_parser.py +++ b/ohos_interface/ohos_glue/scripts/file_parser.py @@ -438,6 +438,9 @@ _simpletypes = { 'CefWindowHandle': ['cef_window_handle_t', 'kNullWindowHandle'], 'WebSnapshotCallback':['WebSnapshotCallback', 'NULL'], 'ArkDisplayAdapterVector': ['ArkDisplayAdapterVector', '{0}'], + 'ArkWebStylusTouchPointInfoVector': [ + 'ArkWebStylusTouchPointInfoVector', 'ark_web_stylus_touch_point_info_vector_default' + ], } -- Gitee From 1b1fb1ceeeef0128a2e17f019d86cb3dc3234191 Mon Sep 17 00:00:00 2001 From: sunbin55 Date: Wed, 20 Aug 2025 11:35:06 +0800 Subject: [PATCH 026/124] =?UTF-8?q?IssueNo:#ICTT0N:[Bug]:=20=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5=E3=80=82=20Descri?= =?UTF-8?q?ption:=20=E6=B8=B2=E6=9F=93=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=20Sig:=20SIG=5FApplicationFramework=20Feature=20or=20Bugfix:?= =?UTF-8?q?=20(Bugfix)=20Binary=20Source:=20No=20=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=B6=89=E5=8F=8A=E9=9D=9E=E5=85=BC=E5=AE=B9=E5=8F=98=E6=9B=B4?= =?UTF-8?q?:=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20TDD=E8=87=AA=E9=AA=8C?= =?UTF-8?q?=E7=BB=93=E6=9E=9C(=E5=A6=82=E6=9C=89=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90=E4=BE=9B=E5=9F=BA=E7=BA=BF?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5):=20(=E4=B8=8D=E6=B6=89?= =?UTF-8?q?=E5=8F=8A)=20XTS=E8=87=AA=E9=AA=8C=E7=BB=93=E6=9E=9C(=E5=A6=82?= =?UTF-8?q?=E6=9C=89=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E5=9F=BA=E7=BA=BF=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5?= =?UTF-8?q?):=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20Signed-off-by:=20sunbin55?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ark_ohos_drawing_text_adapter_wrapper.h | 2 +- .../ark_web_custom_keyboard_handler_impl.cpp | 15 ++++++++----- .../ark_web_custom_keyboard_handler_impl.h | 22 +++++++++---------- .../ark_web_mouse_event_result_impl.cpp | 2 +- .../ark_web_native_embed_mouse_event_impl.cpp | 2 +- .../ark_web_native_embed_mouse_event_impl.h | 2 +- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.h index 3dd8294cf..2762656ba 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 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/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_custom_keyboard_handler_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_custom_keyboard_handler_impl.cpp index 8380fefa2..3cb3f63d2 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_custom_keyboard_handler_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_custom_keyboard_handler_impl.cpp @@ -17,23 +17,28 @@ #include "base/bridge/ark_web_bridge_macros.h" namespace OHOS::ArkWeb { -void ArkWebCustomKeyboardHandlerImpl::InsertText(const ArkWebString &text) { +void ArkWebCustomKeyboardHandlerImpl::InsertText(const ArkWebString &text) +{ nweb_custom_keyboard_handler_->InsertText(ArkWebStringStructToClass(text)); } -void ArkWebCustomKeyboardHandlerImpl::DeleteForward(int32_t length) { +void ArkWebCustomKeyboardHandlerImpl::DeleteForward(int32_t length) +{ nweb_custom_keyboard_handler_->DeleteForward(length); } -void ArkWebCustomKeyboardHandlerImpl::DeleteBackward(int32_t length) { +void ArkWebCustomKeyboardHandlerImpl::DeleteBackward(int32_t length) +{ nweb_custom_keyboard_handler_->DeleteBackward(length); } -void ArkWebCustomKeyboardHandlerImpl::SendFunctionKey(int32_t key) { +void ArkWebCustomKeyboardHandlerImpl::SendFunctionKey(int32_t key) +{ nweb_custom_keyboard_handler_->SendFunctionKey(key); } -void ArkWebCustomKeyboardHandlerImpl::Close() { +void ArkWebCustomKeyboardHandlerImpl::Close() +{ nweb_custom_keyboard_handler_->Close(); } diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_custom_keyboard_handler_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_custom_keyboard_handler_impl.h index d28d262c8..b3e319a55 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_custom_keyboard_handler_impl.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_custom_keyboard_handler_impl.h @@ -23,26 +23,26 @@ namespace OHOS::ArkWeb { class ArkWebCustomKeyboardHandlerImpl : public ArkWebCustomKeyboardHandler { - IMPLEMENT_REFCOUNTING(ArkWebCustomKeyboardHandlerImpl); + IMPLEMENT_REFCOUNTING(ArkWebCustomKeyboardHandlerImpl); public: - ArkWebCustomKeyboardHandlerImpl( - std::shared_ptr nweb_custom_keyboard_handler) : - nweb_custom_keyboard_handler_(nweb_custom_keyboard_handler) {} - ~ArkWebCustomKeyboardHandlerImpl() = default; + ArkWebCustomKeyboardHandlerImpl( + std::shared_ptr nweb_custom_keyboard_handler) + : nweb_custom_keyboard_handler_(nweb_custom_keyboard_handler) {} + ~ArkWebCustomKeyboardHandlerImpl() = default; - void InsertText(const ArkWebString &text) override; + void InsertText(const ArkWebString &text) override; - void DeleteForward(int32_t length) override; + void DeleteForward(int32_t length) override; - void DeleteBackward(int32_t length) override; + void DeleteBackward(int32_t length) override; - void SendFunctionKey(int32_t key) override; + void SendFunctionKey(int32_t key) override; - void Close() override; + void Close() override; private: - std::shared_ptr nweb_custom_keyboard_handler_; + std::shared_ptr nweb_custom_keyboard_handler_; }; } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp index 88f241f0d..da6604aa0 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.cpp index eb45c96e7..518135740 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 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/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.h index d0e587154..9ce0002de 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 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 bd0c6fc217afc8659926a47c7f9449d6e4bfbe94 Mon Sep 17 00:00:00 2001 From: sunbin55 Date: Wed, 20 Aug 2025 11:41:43 +0800 Subject: [PATCH 027/124] =?UTF-8?q?IssueNo:#ICTT0N:[Bug]:=20=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5=E3=80=82=20Descri?= =?UTF-8?q?ption:=20=E6=B8=B2=E6=9F=93=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=20Sig:=20SIG=5FApplicationFramework=20Feature=20or=20Bugfix:?= =?UTF-8?q?=20(Bugfix)=20Binary=20Source:=20No=20=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=B6=89=E5=8F=8A=E9=9D=9E=E5=85=BC=E5=AE=B9=E5=8F=98=E6=9B=B4?= =?UTF-8?q?:=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20TDD=E8=87=AA=E9=AA=8C?= =?UTF-8?q?=E7=BB=93=E6=9E=9C(=E5=A6=82=E6=9C=89=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90=E4=BE=9B=E5=9F=BA=E7=BA=BF?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5):=20(=E4=B8=8D=E6=B6=89?= =?UTF-8?q?=E5=8F=8A)=20XTS=E8=87=AA=E9=AA=8C=E7=BB=93=E6=9E=9C(=E5=A6=82?= =?UTF-8?q?=E6=9C=89=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E5=9F=BA=E7=BA=BF=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5?= =?UTF-8?q?):=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20Signed-off-by:=20sunbin55?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bridge/webcore/ark_web_mouse_event_result_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp index da6604aa0..96da7ef62 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 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 5b24f9d4707821bcfebbe4e11cb3fb65303fc8d9 Mon Sep 17 00:00:00 2001 From: Gao Lei Date: Tue, 12 Aug 2025 00:50:21 +0800 Subject: [PATCH 028/124] Update random IV generator. Signed-off-by: Gao Lei --- .../include/keystore_adapter_impl.h | 16 +- .../src/keystore_adapter_impl.cpp | 241 ++++++++---------- .../keystore_adapter_impl_test.cpp | 109 +++++--- 3 files changed, 184 insertions(+), 182 deletions(-) diff --git a/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h b/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h index a9c561126..b252b965c 100644 --- a/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h +++ b/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h @@ -16,10 +16,10 @@ #ifndef KEYSTORE_ADAPTER_IMPL_H #define KEYSTORE_ADAPTER_IMPL_H -#include "keystore_adapter.h" -#include "hks_param.h" #include "hks_api.h" +#include "hks_param.h" #include "hks_type.h" +#include "keystore_adapter.h" namespace OHOS::NWeb { @@ -31,10 +31,7 @@ public: std::string EncryptKey(const std::string alias, const std::string plainData) override; std::string DecryptKey(const std::string alias, const std::string encryptedData) override; - int32_t InitParamSet( - struct HksParamSet **paramSet, - const struct HksParam *params, - uint32_t paramCount); + int32_t InitParamSet(struct HksParamSet** paramSet, const struct HksParam* params, uint32_t paramCount); std::string AssetQuery(const std::string assetHandle) override; private: @@ -43,8 +40,11 @@ private: KeystoreAdapterImpl(const KeystoreAdapterImpl& other) = delete; KeystoreAdapterImpl& operator=(const KeystoreAdapterImpl&) = delete; + + bool PrepareHuksInternal(struct HksParamSet** genParamSet, const struct HksBlob* keyAlias, + struct HksParamSet** workParamSet, struct HksParam* workParams, size_t workParamCount); }; -} // namespace OHOS::NWeb +} // namespace OHOS::NWeb -#endif // KEYSTORE_ADAPTER_IMPL_H \ No newline at end of file +#endif // KEYSTORE_ADAPTER_IMPL_H \ No newline at end of file diff --git a/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp b/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp index c807daecf..440ae3a00 100644 --- a/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp +++ b/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "asset_api.h" #include "nweb_log.h" @@ -31,7 +32,28 @@ namespace { const uint32_t AES_COMMON_SIZE = 1024; static const uint32_t IV_SIZE = 16; static const uint8_t IV[IV_SIZE] = { 0 }; +const std::string V10 = "V10"; +const uint32_t V10_SIZE = 3; +const uint32_t CIPHER_TEXT_SIZE = 32; + +struct HksParam g_genEncDecParams[] = { { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_AES }, + { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_ENCRYPT | 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 } }; + +std::vector GetRandom(size_t size) +{ + std::vector result(size, 0); + struct HksBlob randBlob = { result.size(), result.data() }; + int ret = HksGenerateRandom(nullptr, &randBlob); + if (ret != HKS_SUCCESS) { + WVLOG_E("Failed to generate random bytes, hks error code: %{public}d", ret); + return {}; + } + return result; } +} // namespace namespace OHOS::NWeb { // static @@ -42,9 +64,7 @@ KeystoreAdapterImpl& KeystoreAdapterImpl::GetInstance() } int32_t KeystoreAdapterImpl::InitParamSet( - struct HksParamSet **paramSet, - const struct HksParam *params, - uint32_t paramCount) + struct HksParamSet** paramSet, const struct HksParam* params, uint32_t paramCount) { int32_t ret = HksInitParamSet(paramSet); if (ret != HKS_SUCCESS) { @@ -66,108 +86,60 @@ int32_t KeystoreAdapterImpl::InitParamSet( return ret; } -struct HksParam g_genEncDecParams[] = { - { - .tag = HKS_TAG_ALGORITHM, - .uint32Param = HKS_ALG_AES - }, { - .tag = HKS_TAG_PURPOSE, - .uint32Param = HKS_KEY_PURPOSE_ENCRYPT | 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 - } -}; - -struct HksParam g_encryptParams[] = { - { - .tag = HKS_TAG_ALGORITHM, - .uint32Param = HKS_ALG_AES - }, { - .tag = HKS_TAG_PURPOSE, - .uint32Param = HKS_KEY_PURPOSE_ENCRYPT - }, { - .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 - }, { - .tag = HKS_TAG_IV, - .blob = { - .size = IV_SIZE, - .data = (uint8_t *)IV - } - } -}; - -struct HksParam g_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 - }, { - .tag = HKS_TAG_IV, - .blob = { - .size = IV_SIZE, - .data = (uint8_t *)IV - } - } -}; +bool KeystoreAdapterImpl::PrepareHuksInternal(struct HksParamSet** genParamSet, const struct HksBlob* keyAlias, + struct HksParamSet** workParamSet, struct HksParam* workParams, size_t workParamCount) +{ + int32_t result = InitParamSet(genParamSet, g_genEncDecParams, sizeof(g_genEncDecParams) / sizeof(HksParam)); + if (result != HKS_SUCCESS) { + WVLOG_E("init gen param set failed, error code: %d", result); + HksFreeParamSet(genParamSet); + return false; + } + result = InitParamSet(workParamSet, workParams, workParamCount); + if (result != HKS_SUCCESS) { + WVLOG_E("init work param set failed, error code: %d", result); + HksFreeParamSet(genParamSet); + HksFreeParamSet(workParamSet); + return false; + } + result = HksKeyExist(keyAlias, *genParamSet); + if (result != HKS_SUCCESS) { + WVLOG_E("hks key is not exist, error code: %d", result); + HksFreeParamSet(genParamSet); + HksFreeParamSet(workParamSet); + return false; + } + return true; +} std::string KeystoreAdapterImpl::EncryptKey(const std::string alias, const std::string plainData) { - struct HksBlob keyAlias = { alias.length(), (uint8_t *)alias.c_str() }; - struct HksBlob inData = { plainData.length(), (uint8_t *)plainData.c_str() }; - struct HksParamSet *genParamSet = nullptr; - struct HksParamSet *encryptParamSet = nullptr; - uint8_t cipher[AES_COMMON_SIZE] = {0}; - struct HksBlob cipherText = {AES_COMMON_SIZE, cipher}; - int32_t ohResult = InitParamSet(&genParamSet, g_genEncDecParams, sizeof(g_genEncDecParams) / sizeof(HksParam)); - if (ohResult != HKS_SUCCESS) { - WVLOG_E("init gen param set failed, error code: %d", ohResult); - HksFreeParamSet(&genParamSet); + struct HksBlob keyAlias = { alias.length(), (uint8_t*)alias.c_str() }; + struct HksBlob inData = { plainData.length(), (uint8_t*)plainData.c_str() }; + struct HksParamSet* genParamSet = nullptr; + struct HksParamSet* encryptParamSet = nullptr; + uint8_t cipher[AES_COMMON_SIZE] = { 0 }; + struct HksBlob cipherText = { AES_COMMON_SIZE, cipher }; + + std::vector iv = GetRandom(IV_SIZE); + if (iv.empty()) { + WVLOG_E("Failed to get random IV"); return std::string(); } - ohResult = HksKeyExist(&keyAlias, genParamSet); - if (ohResult != HKS_SUCCESS) { - ohResult = HksGenerateKey(&keyAlias, genParamSet, nullptr); - if (ohResult != HKS_SUCCESS) { - WVLOG_E("generate key failed, error code: %d", ohResult); - HksFreeParamSet(&genParamSet); - return std::string(); - } - } - ohResult = InitParamSet(&encryptParamSet, g_encryptParams, sizeof(g_encryptParams) / sizeof(HksParam)); - if (ohResult != HKS_SUCCESS) { - WVLOG_E("init encrypt param set failed, error code: %d", ohResult); - HksFreeParamSet(&genParamSet); - HksFreeParamSet(&encryptParamSet); + struct HksParam encryptParams[] = { { .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_AES }, + { .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_ENCRYPT }, + { .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 }, + { .tag = HKS_TAG_IV, .blob = { .size = IV_SIZE, .data = iv.data() } } }; + if (!PrepareHuksInternal( + &genParamSet, &keyAlias, &encryptParamSet, encryptParams, sizeof(encryptParams) / sizeof(HksParam))) { return std::string(); } - uint8_t handleE[sizeof(uint64_t)] = {0}; - struct HksBlob handleEncrypt = {sizeof(uint64_t), handleE}; - ohResult = HksInit(&keyAlias, encryptParamSet, &handleEncrypt, nullptr); + + uint8_t handleE[sizeof(uint64_t)] = { 0 }; + struct HksBlob handleEncrypt = { sizeof(uint64_t), handleE }; + int32_t ohResult = HksInit(&keyAlias, encryptParamSet, &handleEncrypt, nullptr); if (ohResult != HKS_SUCCESS) { WVLOG_E("hks init invoke failed, error code: %d", ohResult); HksFreeParamSet(&genParamSet); @@ -175,49 +147,56 @@ std::string KeystoreAdapterImpl::EncryptKey(const std::string alias, const std:: return std::string(); } ohResult = HksFinish(&handleEncrypt, encryptParamSet, &inData, &cipherText); + HksFreeParamSet(&genParamSet); + HksFreeParamSet(&encryptParamSet); if (ohResult != HKS_SUCCESS) { WVLOG_E("hks finish invoke failed, error code: %d", ohResult); - HksFreeParamSet(&genParamSet); - HksFreeParamSet(&encryptParamSet); + return std::string(); + } + if (cipherText.size == 0) { + WVLOG_E("hks finish with empty cipher text"); return std::string(); } - HksFreeParamSet(&genParamSet); - HksFreeParamSet(&encryptParamSet); - return std::string(reinterpret_cast(cipherText.data), cipherText.size); + return V10 + std::string(reinterpret_cast(iv.data()), iv.size()) + + std::string(reinterpret_cast(cipherText.data), cipherText.size); } std::string KeystoreAdapterImpl::DecryptKey(const std::string alias, const std::string encryptedData) { - struct HksBlob keyAlias = { alias.length(), (uint8_t *)alias.c_str() }; - struct HksBlob cipherText = { encryptedData.length(), (uint8_t *)encryptedData.c_str() }; - struct HksParamSet *genParamSet = nullptr; - struct HksParamSet *decryptParamSet = nullptr; - uint8_t plain[AES_COMMON_SIZE] = {0}; - struct HksBlob plainText = {AES_COMMON_SIZE, plain}; - int32_t ohResult = InitParamSet(&genParamSet, g_genEncDecParams, sizeof(g_genEncDecParams) / sizeof(HksParam)); - if (ohResult != HKS_SUCCESS) { - HksFreeParamSet(&genParamSet); - WVLOG_E("init gen param set failed, error code: %d", ohResult); - return std::string(); - } - ohResult = InitParamSet(&decryptParamSet, g_decryptParams, sizeof(g_decryptParams) / sizeof(HksParam)); - if (ohResult != HKS_SUCCESS) { - WVLOG_E("init decrypt param set failed, error code: %d", ohResult); - HksFreeParamSet(&genParamSet); - HksFreeParamSet(&decryptParamSet); + struct HksBlob keyAlias = { alias.length(), (uint8_t*)alias.c_str() }; + struct HksParamSet* genParamSet = nullptr; + struct HksParamSet* decryptParamSet = nullptr; + uint8_t plain[AES_COMMON_SIZE] = { 0 }; + struct HksBlob plainText = { AES_COMMON_SIZE, plain }; + + std::string ivStr; + std::string cipherStr = encryptedData; + if (encryptedData.length() == V10_SIZE + IV_SIZE + CIPHER_TEXT_SIZE && + encryptedData.compare(0, V10_SIZE, V10) == 0) { + size_t prefix_size = V10_SIZE + IV_SIZE; + ivStr = encryptedData.substr(V10_SIZE, IV_SIZE); + cipherStr = encryptedData.substr(prefix_size, encryptedData.length() - prefix_size); + } else if (encryptedData.length() != CIPHER_TEXT_SIZE) { + WVLOG_W("Invalid cipher text length: %{public}zu", encryptedData.length()); return std::string(); } - ohResult = HksKeyExist(&keyAlias, genParamSet); - if (ohResult != HKS_SUCCESS) { - HksFreeParamSet(&genParamSet); - HksFreeParamSet(&decryptParamSet); - WVLOG_E("hks key is not exist, error code: %d", ohResult); + 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 }, + { .tag = HKS_TAG_IV, + .blob = { .size = IV_SIZE, .data = ivStr.empty() ? (uint8_t*)IV : (uint8_t*)ivStr.c_str() } } }; + struct HksBlob cipherText = { cipherStr.length(), (uint8_t*)cipherStr.c_str() }; + if (!PrepareHuksInternal( + &genParamSet, &keyAlias, &decryptParamSet, decryptParams, sizeof(decryptParams) / sizeof(HksParam))) { return std::string(); } - uint8_t handleD[sizeof(uint64_t)] = {0}; - struct HksBlob handleDecrypt = {sizeof(uint64_t), handleD}; - ohResult = HksInit(&keyAlias, decryptParamSet, &handleDecrypt, nullptr); + + uint8_t handleD[sizeof(uint64_t)] = { 0 }; + struct HksBlob handleDecrypt = { sizeof(uint64_t), handleD }; + int32_t ohResult = HksInit(&keyAlias, decryptParamSet, &handleDecrypt, nullptr); if (ohResult != HKS_SUCCESS) { HksFreeParamSet(&genParamSet); HksFreeParamSet(&decryptParamSet); @@ -225,14 +204,12 @@ std::string KeystoreAdapterImpl::DecryptKey(const std::string alias, const std:: return std::string(); } ohResult = HksFinish(&handleDecrypt, decryptParamSet, &cipherText, &plainText); + HksFreeParamSet(&genParamSet); + HksFreeParamSet(&decryptParamSet); if (ohResult != HKS_SUCCESS) { - HksFreeParamSet(&genParamSet); - HksFreeParamSet(&decryptParamSet); WVLOG_E("hks finish invoke failed, error code: %d", ohResult); return std::string(); } - HksFreeParamSet(&genParamSet); - HksFreeParamSet(&decryptParamSet); return std::string(reinterpret_cast(plainText.data), plainText.size); } diff --git a/test/unittest/ohos_adapter/keystore_adapter_impl_test/keystore_adapter_impl_test.cpp b/test/unittest/ohos_adapter/keystore_adapter_impl_test/keystore_adapter_impl_test.cpp index 07dbdd2d6..968161f95 100644 --- a/test/unittest/ohos_adapter/keystore_adapter_impl_test/keystore_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/keystore_adapter_impl_test/keystore_adapter_impl_test.cpp @@ -13,13 +13,11 @@ * limitations under the License. */ -#include #include +#include #include #include - -#define private public #include "keystore_adapter_impl.h" using namespace testing; @@ -28,9 +26,7 @@ using namespace testing::ext; namespace OHOS { namespace NWeb { -namespace { - -} +namespace {} class KeystoreAdapterImplTest : public testing::Test { public: @@ -40,17 +36,13 @@ public: void TearDown(); }; -void KeystoreAdapterImplTest::SetUpTestCase(void) -{} +void KeystoreAdapterImplTest::SetUpTestCase(void) {} -void KeystoreAdapterImplTest::TearDownTestCase(void) -{} +void KeystoreAdapterImplTest::TearDownTestCase(void) {} -void KeystoreAdapterImplTest::SetUp(void) -{} +void KeystoreAdapterImplTest::SetUp(void) {} -void KeystoreAdapterImplTest::TearDown(void) -{} +void KeystoreAdapterImplTest::TearDown(void) {} /** * @tc.name: KeystoreAdapterImplTest_InitParamSet_001 @@ -60,37 +52,24 @@ void KeystoreAdapterImplTest::TearDown(void) */ HWTEST_F(KeystoreAdapterImplTest, KeystoreAdapterImplTest_InitParamSet_001, TestSize.Level1) { - 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)); + 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)); EXPECT_NE(result, 0); result = KeystoreAdapterImpl::GetInstance().InitParamSet(nullptr, nullptr, sizeof(decryptParams) / sizeof(HksParam)); EXPECT_NE(result, 0); - result = KeystoreAdapterImpl::GetInstance().InitParamSet(¶mSet, nullptr, - sizeof(decryptParams) / sizeof(HksParam)); + result = + KeystoreAdapterImpl::GetInstance().InitParamSet(¶mSet, nullptr, sizeof(decryptParams) / sizeof(HksParam)); EXPECT_NE(result, 0); - result = KeystoreAdapterImpl::GetInstance().InitParamSet(¶mSet, decryptParams, - sizeof(decryptParams) / sizeof(HksParam)); + result = KeystoreAdapterImpl::GetInstance().InitParamSet( + ¶mSet, decryptParams, sizeof(decryptParams) / sizeof(HksParam)); EXPECT_EQ(result, 0); } @@ -125,6 +104,52 @@ HWTEST_F(KeystoreAdapterImplTest, KeystoreAdapterImplTest_EncryptKey_002, TestSi EXPECT_TRUE(nullEncrypt.empty()); nullDecrypt = KeystoreAdapterImpl::GetInstance().DecryptKey(long_str_alias, "test"); EXPECT_TRUE(DecryptString.empty()); + + std::string keyAlias(16, 'a'); + std::string keyPlain(32, 0x1c); + const int prefixSize = 3 + 16; // len("V10") + IV size + std::string result = KeystoreAdapterImpl::GetInstance().EncryptKey(keyAlias, keyPlain); + EXPECT_FALSE(result.empty()); + EXPECT_EQ(result.length(), keyPlain.length() + prefixSize); + std::string plainText = KeystoreAdapterImpl::GetInstance().DecryptKey(keyAlias, result); + EXPECT_EQ(keyPlain, plainText); +} + +/** + * @tc.name: KeystoreAdapterImplTest_DecryptKey_001 + * @tc.desc: Encrypt and Decrypt + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(KeystoreAdapterImplTest, KeystoreAdapterImplTest_DecryptKey_001, TestSize.Level1) +{ + const int prefixSize = 3 + 16; // len("V10") + IV size + std::string alias = "test"; + std::string encryptString = "fake_web_test"; + std::string plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(alias, encryptString); + EXPECT_TRUE(plainString.empty()); + + encryptString = "V10abcdefghijklmnopABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; + plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(alias, encryptString); + EXPECT_FALSE(plainString.empty()); + EXPECT_EQ(plainString.length(), encryptString.length() - prefixSize); + + std::string nullAlias = ""; + encryptString = ""; + plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(nullAlias, encryptString); + EXPECT_TRUE(plainString.empty()); + + std::string long_str_alias(2048, 'a'); + plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(long_str_alias, "test"); + EXPECT_TRUE(plainString.empty()); + + std::string keyAlias(16, 'a'); + std::string keyPlain(32, 'x'); + std::string result = KeystoreAdapterImpl::GetInstance().EncryptKey(keyAlias, keyPlain); + EXPECT_FALSE(result.empty()); + EXPECT_EQ(result.length(), keyPlain.length() + prefixSize); + plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(keyAlias, result); + EXPECT_EQ(keyPlain, plainString); } /** @@ -143,5 +168,5 @@ HWTEST_F(KeystoreAdapterImplTest, KeystoreAdapterImplTest_AssetQuery_003, TestSi std::string nullEncrypt = KeystoreAdapterImpl::GetInstance().AssetQuery(nullAlias); EXPECT_TRUE(nullEncrypt.empty()); } -} -} // namespace NWeb \ No newline at end of file +} // namespace NWeb +} // namespace OHOS \ No newline at end of file -- Gitee From 1be36c1cb5e891290b811e18749f81efe93eb35d Mon Sep 17 00:00:00 2001 From: m1n1ons <971254170@qq.com> Date: Wed, 20 Aug 2025 15:53:47 +0800 Subject: [PATCH 029/124] =?UTF-8?q?=E5=9B=9E=E9=80=80=20Signed-off-by:=20m?= =?UTF-8?q?1n1ons=20<971254170@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ohos_resource_adapter_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unittest/ohos_adapter/ohos_resource_adapter_test/ohos_resource_adapter_test.cpp b/test/unittest/ohos_adapter/ohos_resource_adapter_test/ohos_resource_adapter_test.cpp index fd128ea88..0ea7bb83e 100644 --- a/test/unittest/ohos_adapter/ohos_resource_adapter_test/ohos_resource_adapter_test.cpp +++ b/test/unittest/ohos_adapter/ohos_resource_adapter_test/ohos_resource_adapter_test.cpp @@ -186,7 +186,7 @@ HWTEST_F(OhosResourceAdapterTest, OhosResourceAdapterTest_OhosFileMapperImpl_003 EXPECT_NE(extractor, nullptr); std::shared_ptr fileReader = OHOS::AbilityBase::ZipFileReader::CreateZipFileReader(hapPath); - EXPECT_EQ(fileReader, nullptr); + EXPECT_NE(fileReader, nullptr); std::unique_ptr fileMap = std::make_unique(); EXPECT_NE(fileMap, nullptr); fileMap->CreateFileMapper(fileReader, hapPath, 0, hapPath.size(), true); @@ -196,13 +196,13 @@ HWTEST_F(OhosResourceAdapterTest, OhosResourceAdapterTest_OhosFileMapperImpl_003 result = apperImpl.GetOffset(); EXPECT_NE(result, -1); std::string fileNmae = apperImpl.GetFileName(); - EXPECT_EQ(fileNmae, ""); + EXPECT_NE(fileNmae, ""); bool isCompressed = apperImpl.IsCompressed(); - EXPECT_FALSE(isCompressed); + EXPECT_TRUE(isCompressed); void* data = apperImpl.GetDataPtr(); - EXPECT_EQ(data, nullptr); + EXPECT_NE(data, nullptr); size_t dataLen = apperImpl.GetDataLen(); - EXPECT_EQ(dataLen, 0); + EXPECT_NE(dataLen, 0); uint8_t* dest; isCompressed = apperImpl.UnzipData(&dest, dataLen); EXPECT_FALSE(isCompressed); -- Gitee From 3540acc83e99edd0db47d03fe724a2f1ac5c8597 Mon Sep 17 00:00:00 2001 From: dapaodexiaoyu2 Date: Wed, 20 Aug 2025 16:04:41 +0800 Subject: [PATCH 030/124] fix build warning Signed-off-by: dapaodexiaoyu2 Change-Id: I622c7812b179e2b9ae7564480946dc80398d9eb8 --- ohos_nweb/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/ohos_nweb/BUILD.gn b/ohos_nweb/BUILD.gn index 0ca315a0a..bded8353b 100644 --- a/ohos_nweb/BUILD.gn +++ b/ohos_nweb/BUILD.gn @@ -81,6 +81,7 @@ ohos_shared_library("web_configs") { "ipc:ipc_core", "libxml2:libxml2", "ability_runtime:ability_connect_callback_stub", + "samgr:samgr_proxy", ] part_name = "webview" -- Gitee From 03f1942eebac430f364807056f8d602755209d3f Mon Sep 17 00:00:00 2001 From: wanglei Date: Wed, 20 Aug 2025 08:05:16 +0000 Subject: [PATCH 031/124] send dlclose msg to appspawn when arkweb upgrade Signed-off-by: wanglei --- sa/src/app_fwk_update_service.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sa/src/app_fwk_update_service.cpp b/sa/src/app_fwk_update_service.cpp index 30715139a..82f1457cd 100644 --- a/sa/src/app_fwk_update_service.cpp +++ b/sa/src/app_fwk_update_service.cpp @@ -111,6 +111,12 @@ ErrCode AppFwkUpdateService::VerifyPackageInstall( return ERR_INVALID_VALUE; } int ret = 0; + ret = SendAppSpawnMessage(bundleName, MSG_UNLOAD_WEBLIB_IN_APPSPAWN); + if (ret != 0) { + WVLOG_I("SendAppSpawnMessage MSG_UNLOAD_WEBLIB_IN_APPSPAWN happened error: %{public}d", isSuccess); + return ERR_INVALID_VALUE; + } + isSuccess = 0; if (OHOS::system::GetParameter("persist.arkwebcore.install_path", "") == hapPath) { WVLOG_I("OnPackageChangedEvent install path not changed."); @@ -193,6 +199,7 @@ int AppFwkUpdateService::SendAppSpawnMessage(const std::string& bundleName, AppS int retryCount = 0; AppSpawnClientHandle clientHandle = nullptr; AppSpawnReqMsgHandle reqHandle = 0; + AppSpawnResult result = {}; do { ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); if (ret != 0) { @@ -204,10 +211,13 @@ int AppFwkUpdateService::SendAppSpawnMessage(const std::string& bundleName, AppS WVLOG_I("Failed to create req,retry count = %{public}d.", retryCount); continue; } - AppSpawnResult result = {}; ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); } while (++retryCount < RETRY_COUNT && ret != 0); AppSpawnClientDestroy(clientHandle); + if (result.result != 0) { + WVLOG_E("recv apsppawn result msg, result: %{public}d", result.result); + return result.result; + } WVLOG_I("Send appspawn message success."); return ret; } -- Gitee From 2f090401a95172b9c166e99e7438a1aa25d162c0 Mon Sep 17 00:00:00 2001 From: ohxianzhi Date: Wed, 20 Aug 2025 19:47:11 +0800 Subject: [PATCH 032/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=B6=85=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ohxianzhi --- .../src/display_manager_adapter_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/display_manager_adapter/src/display_manager_adapter_impl.cpp b/ohos_adapter/display_manager_adapter/src/display_manager_adapter_impl.cpp index 64d0d909a..01bbab4df 100644 --- a/ohos_adapter/display_manager_adapter/src/display_manager_adapter_impl.cpp +++ b/ohos_adapter/display_manager_adapter/src/display_manager_adapter_impl.cpp @@ -70,7 +70,7 @@ bool DisplayListenerAdapterImpl::CheckOnlyRefreshRateDecreased(DisplayId id) auto nwebDisplayInfo = ConvertDisplayInfo(*displayInfo); if (nwebDisplayInfo == cachedDisplayedInfo_ && nwebDisplayInfo.refreshRate_ != cachedDisplayedInfo_.refreshRate_) { - WVLOG_I("refresh rate change is intercepted, previous refresh rate: %{public}u, after: %{public}u", + WVLOG_D("refresh rate change is intercepted, previous refresh rate: %{public}u, after: %{public}u", cachedDisplayedInfo_.refreshRate_, nwebDisplayInfo.refreshRate_); cachedDisplayedInfo_ = nwebDisplayInfo; return true; -- Gitee From 2b72f6a4a231719f470b5f3950e1964261ed6a24 Mon Sep 17 00:00:00 2001 From: slim Date: Wed, 20 Aug 2025 20:56:51 +0800 Subject: [PATCH 033/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: slim --- .../webcore/ark_web_stylus_touch_point_info_wrapper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.cpp index 14f1fc3da..3b9e50629 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_stylus_touch_point_info_wrapper.cpp @@ -69,9 +69,9 @@ int32_t ArkWebStylusTouchPointInfoWrapper::GetHeight() return ark_web_stylus_touch_point_info_->GetHeight(); } -SourceTool ArkWebStylusTouchPointInfoWrapper::GetSourceTool() +ArkWebSourceTool ArkWebStylusTouchPointInfoWrapper::GetSourceTool() { - return static_cast(ark_web_stylus_touch_point_info_->GetSourceTool()); + return static_cast(ark_web_stylus_touch_point_info_->GetSourceTool()); } } // namespace OHOS::ArkWeb -- Gitee From d590eb4236233272fdf53022bd3e90c0bc723b94 Mon Sep 17 00:00:00 2001 From: li-kiao Date: Thu, 21 Aug 2025 04:07:55 +0000 Subject: [PATCH 034/124] =?UTF-8?q?blankless=E7=94=A8=E4=BE=8B=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-kiao Change-Id: Ieddfec7a731015458caef2c91a3104ec42540a24 --- .../interface_native_test/native_interface_arkweb_test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unittest/interface_native_test/native_interface_arkweb_test.cpp b/test/unittest/interface_native_test/native_interface_arkweb_test.cpp index 21c4930b2..966032f57 100644 --- a/test/unittest/interface_native_test/native_interface_arkweb_test.cpp +++ b/test/unittest/interface_native_test/native_interface_arkweb_test.cpp @@ -251,8 +251,9 @@ HWTEST_F(NativeInterfaceArkWebTest, OH_NativeArkWeb_SetBlanklessLoadingCacheCapa * @tc.desc : Test OH_NativeArkWeb_Blankless_Dual_Core */ HWTEST_F(NativeInterfaceArkWebTest, OH_NativeArkWeb_Blankless_Dual_Core_01, TestSize.Level1) { + bool defaultStatus = OHOS::system::GetBoolParameter("web.blankless.enabled", false); + OHOS::system::SetParameter("web.blankless.enabled", "true"); auto version = ArkWeb::getActiveWebEngineVersion(); - ArkWeb::setActiveWebEngineVersion(ArkWeb::ArkWebEngineVersion::M114); auto info = OH_NativeArkWeb_GetBlanklessInfoWithKey("", ""); EXPECT_EQ(info.errCode, ArkWeb_BlanklessErrorCode::ARKWEB_BLANKLESS_ERR_DEVICE_NOT_SUPPORT); @@ -270,6 +271,7 @@ HWTEST_F(NativeInterfaceArkWebTest, OH_NativeArkWeb_Blankless_Dual_Core_01, Test EXPECT_EQ(OH_NativeArkWeb_SetBlanklessLoadingCacheCapacity(20), 20); ArkWeb::setActiveWebEngineVersion(version); + OHOS::system::SetParameter("web.blankless.enabled", defaultStatus ? "true" : "false"); } /** -- Gitee From 155f8aeb865ec3ea2f51e621af760c03551bac18 Mon Sep 17 00:00:00 2001 From: yjw Date: Thu, 21 Aug 2025 07:21:43 +0000 Subject: [PATCH 035/124] update ohos_interface/include/ohos_adapter/drm_adapter.h. Signed-off-by: yjw --- ohos_interface/include/ohos_adapter/drm_adapter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_interface/include/ohos_adapter/drm_adapter.h b/ohos_interface/include/ohos_adapter/drm_adapter.h index 3dd0968a8..9b95cb898 100644 --- a/ohos_interface/include/ohos_adapter/drm_adapter.h +++ b/ohos_interface/include/ohos_adapter/drm_adapter.h @@ -59,7 +59,7 @@ public: virtual void OnStorageClearInfoForLoadFail(const std::string& sessionId) = 0; - virtual void OnMediaLicenseReady(bool success) {}; + virtual void OnMediaLicenseReady(bool success) {} }; class DrmAdapter { -- Gitee From 7148d0c71f5b0b17be26521f53d3ba263f2d9b11 Mon Sep 17 00:00:00 2001 From: yjw Date: Thu, 21 Aug 2025 09:00:47 +0000 Subject: [PATCH 036/124] update ohos_interface/include/ohos_adapter/drm_adapter.h. Signed-off-by: yjw --- ohos_interface/include/ohos_adapter/drm_adapter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ohos_interface/include/ohos_adapter/drm_adapter.h b/ohos_interface/include/ohos_adapter/drm_adapter.h index 9b95cb898..cc30d91cd 100644 --- a/ohos_interface/include/ohos_adapter/drm_adapter.h +++ b/ohos_interface/include/ohos_adapter/drm_adapter.h @@ -18,6 +18,7 @@ #include #include +#include namespace OHOS::NWeb { -- Gitee From 90fd210c25be943a24976777cd23099212b1e62d Mon Sep 17 00:00:00 2001 From: fuyongyuan Date: Wed, 20 Aug 2025 17:33:58 +0800 Subject: [PATCH 037/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=A9=E7=BD=91?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=AD=EF=BC=8Ccrashpad=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=9A=84so=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fuyongyuan --- config.gni | 3 ++- ohos_adapter/BUILD.gn | 5 +++++ ohos_nweb/BUILD.gn | 7 +++++++ ohos_nweb/src/nweb_crashpad_handler_main.cpp | 11 ++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config.gni b/config.gni index 14dbc04ac..3085542b6 100644 --- a/config.gni +++ b/config.gni @@ -105,4 +105,5 @@ webview_engine_so = "libarkweb_engine.so" webview_app_hap_path = "/system/app/ArkWeb/ArkWebCore.hap" webview_app_hap_path2 = "/system/app/${webview_package_name}/ArkWebCore.hap" -legacy_webview_sandbox_lib_path = "/data/storage/el1/bundle/arkweblegacy/libs/${target_cpu}" \ No newline at end of file +legacy_webview_sandbox_lib_path = "/data/storage/el1/bundle/arkweblegacy/libs/${target_cpu}" +asan_webview_sandbox_lib_path = "/data/storage/el1/bundle/arkwebcore_asan/libs/${target_cpu}" \ No newline at end of file diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 1901b59f4..f2bda40cf 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -59,6 +59,11 @@ ohos_shared_library("nweb_ohos_adapter") { "WEBVIEW_SANDBOX_PATH=\"${webview_sandbox_path}\"", ] + if (use_hwasan) { + defines += [ + "WEBVIEW_SANDBOX_LIB_PATH_ASAN=\"${asan_webview_sandbox_lib_path}\"", + ] + } sources = [ "aafwk_adapter/src/aafwk_app_mgr_client_adapter_impl.cpp", "aafwk_adapter/src/aafwk_browser_client_adapter_impl.cpp", diff --git a/ohos_nweb/BUILD.gn b/ohos_nweb/BUILD.gn index 0ca315a0a..1ccc21a3e 100644 --- a/ohos_nweb/BUILD.gn +++ b/ohos_nweb/BUILD.gn @@ -37,6 +37,13 @@ defines += [ "WEBVIEW_ENGINE_SO=\"${webview_engine_so}\"", ] +if (use_hwasan) { + defines += [ + "IS_ASAN", + "WEBVIEW_SANDBOX_LIB_PATH_ASAN=\"${asan_webview_sandbox_lib_path}\"", + ] +} + config("nweb_config") { include_dirs = [ "${target_gen_dir}/include" ] include_dirs += [ "include" ] diff --git a/ohos_nweb/src/nweb_crashpad_handler_main.cpp b/ohos_nweb/src/nweb_crashpad_handler_main.cpp index abd52ded0..c59254cde 100644 --- a/ohos_nweb/src/nweb_crashpad_handler_main.cpp +++ b/ohos_nweb/src/nweb_crashpad_handler_main.cpp @@ -48,17 +48,22 @@ std::optional GetEngineType(int argc, char* argv[]) { int main(int argc, char* argv[]) { std::string libCrashpadHandler; + std::string webPath = WEBVIEW_SANDBOX_LIB_PATH; +#if defined(IS_ASAN) && defined(webview_arm64) + if (access(std::string(WEBVIEW_SANDBOX_LIB_PATH_ASAN).c_str(), F_OK) == 0) { + webPath = WEBVIEW_SANDBOX_LIB_PATH_ASAN; + } +#endif if (auto engineType = GetEngineType(argc, argv); engineType.has_value() && engineType.value() == "LEGACY") { libCrashpadHandler = std::string(LEGACY_WEBVIEW_SANDBOX_LIB_PATH) + "/" + std::string(WEBVIEW_CRASHPAD_HANDLER_SO); } else { - libCrashpadHandler = std::string(WEBVIEW_SANDBOX_LIB_PATH) + "/" - + std::string(WEBVIEW_CRASHPAD_HANDLER_SO); + libCrashpadHandler = webPath + "/" + std::string(WEBVIEW_CRASHPAD_HANDLER_SO); } Dl_namespace dlns; dlns_init(&dlns, "nweb_ns"); - dlns_create(&dlns, std::string(WEBVIEW_SANDBOX_LIB_PATH).c_str()); + dlns_create(&dlns, webPath.c_str()); Dl_namespace ndkns; dlns_get("ndk", &ndkns); -- Gitee From 1dc72aebd1fd695c81041bc57e7f7158bb375ac4 Mon Sep 17 00:00:00 2001 From: Gao Lei Date: Thu, 21 Aug 2025 18:39:00 +0800 Subject: [PATCH 038/124] Generate key alias when absent. Signed-off-by: Gao Lei --- .../include/keystore_adapter_impl.h | 2 +- .../src/keystore_adapter_impl.cpp | 23 ++++++------- .../keystore_adapter_impl_test.cpp | 32 +++++++++++++++---- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h b/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h index b252b965c..2c956b928 100644 --- a/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h +++ b/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h @@ -42,7 +42,7 @@ private: KeystoreAdapterImpl& operator=(const KeystoreAdapterImpl&) = delete; bool PrepareHuksInternal(struct HksParamSet** genParamSet, const struct HksBlob* keyAlias, - struct HksParamSet** workParamSet, struct HksParam* workParams, size_t workParamCount); + struct HksParamSet** workParamSet, struct HksParam* workParams, size_t workParamCount, bool mayGenerateKey); }; } // namespace OHOS::NWeb diff --git a/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp b/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp index 4d8ba2489..2d51402a2 100644 --- a/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp +++ b/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp @@ -87,26 +87,27 @@ int32_t KeystoreAdapterImpl::InitParamSet( } bool KeystoreAdapterImpl::PrepareHuksInternal(struct HksParamSet** genParamSet, const struct HksBlob* keyAlias, - struct HksParamSet** workParamSet, struct HksParam* workParams, size_t workParamCount) + struct HksParamSet** workParamSet, struct HksParam* workParams, size_t workParamCount, bool mayGenerateKey) { int32_t result = InitParamSet(genParamSet, g_genEncDecParams, sizeof(g_genEncDecParams) / sizeof(HksParam)); if (result != HKS_SUCCESS) { WVLOG_E("init gen param set failed, error code: %d", result); - HksFreeParamSet(genParamSet); return false; } - result = InitParamSet(workParamSet, workParams, workParamCount); + result = HksKeyExist(keyAlias, *genParamSet); + if (result != HKS_SUCCESS && mayGenerateKey) { + result = HksGenerateKey(keyAlias, *genParamSet, nullptr); + WVLOG_I("key absent, generate key result: %{public}d", result); + } if (result != HKS_SUCCESS) { - WVLOG_E("init work param set failed, error code: %d", result); + WVLOG_E("hks key is not exist, error code: %d", result); HksFreeParamSet(genParamSet); - HksFreeParamSet(workParamSet); return false; } - result = HksKeyExist(keyAlias, *genParamSet); + result = InitParamSet(workParamSet, workParams, workParamCount); if (result != HKS_SUCCESS) { - WVLOG_E("hks key is not exist, error code: %d", result); + WVLOG_E("init work param set failed, error code: %d", result); HksFreeParamSet(genParamSet); - HksFreeParamSet(workParamSet); return false; } return true; @@ -133,7 +134,7 @@ std::string KeystoreAdapterImpl::EncryptKey(const std::string alias, const std:: { .tag = HKS_TAG_BLOCK_MODE, .uint32Param = HKS_MODE_CBC }, { .tag = HKS_TAG_IV, .blob = { .size = IV_SIZE, .data = iv.data() } } }; if (!PrepareHuksInternal( - &genParamSet, &keyAlias, &encryptParamSet, encryptParams, sizeof(encryptParams) / sizeof(HksParam))) { + &genParamSet, &keyAlias, &encryptParamSet, encryptParams, sizeof(encryptParams) / sizeof(HksParam), true)) { return std::string(); } @@ -189,8 +190,8 @@ std::string KeystoreAdapterImpl::DecryptKey(const std::string alias, const std:: { .tag = HKS_TAG_IV, .blob = { .size = IV_SIZE, .data = ivStr.empty() ? (uint8_t*)IV : (uint8_t*)ivStr.c_str() } } }; struct HksBlob cipherText = { cipherStr.length(), (uint8_t*)cipherStr.c_str() }; - if (!PrepareHuksInternal( - &genParamSet, &keyAlias, &decryptParamSet, decryptParams, sizeof(decryptParams) / sizeof(HksParam))) { + if (!PrepareHuksInternal(&genParamSet, &keyAlias, &decryptParamSet, decryptParams, + sizeof(decryptParams) / sizeof(HksParam), false)) { return std::string(); } diff --git a/test/unittest/ohos_adapter/keystore_adapter_impl_test/keystore_adapter_impl_test.cpp b/test/unittest/ohos_adapter/keystore_adapter_impl_test/keystore_adapter_impl_test.cpp index 968161f95..0d1c3bfa6 100644 --- a/test/unittest/ohos_adapter/keystore_adapter_impl_test/keystore_adapter_impl_test.cpp +++ b/test/unittest/ohos_adapter/keystore_adapter_impl_test/keystore_adapter_impl_test.cpp @@ -123,17 +123,35 @@ HWTEST_F(KeystoreAdapterImplTest, KeystoreAdapterImplTest_EncryptKey_002, TestSi */ HWTEST_F(KeystoreAdapterImplTest, KeystoreAdapterImplTest_DecryptKey_001, TestSize.Level1) { - const int prefixSize = 3 + 16; // len("V10") + IV size - std::string alias = "test"; - std::string encryptString = "fake_web_test"; - std::string plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(alias, encryptString); - EXPECT_TRUE(plainString.empty()); - + const int prefixSize = 3 + 16; // len("V10") + IV size + std::string absentKeyAlias = "absent_alias_test"; // Do not use absent key to encrypt anything! + std::string legacyAlias = "legacy_alias"; + + // Legacy mode testing. + std::string plainData = "legacy_key_test_16_bytes_aligned"; + std::string encryptString = KeystoreAdapterImpl::GetInstance().EncryptKey(legacyAlias, plainData); + EXPECT_FALSE(encryptString.empty()); + EXPECT_EQ(encryptString.length(), plainData.length() + prefixSize); + std::string plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(legacyAlias, encryptString); + EXPECT_FALSE(plainString.empty()); + EXPECT_EQ(plainString, plainData); + encryptString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; + plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(legacyAlias, encryptString); + EXPECT_FALSE(plainString.empty()); + EXPECT_EQ(plainString.length(), encryptString.length()); // in/out data was 16-bytes aligned encryptString = "V10abcdefghijklmnopABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; - plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(alias, encryptString); + plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(legacyAlias, encryptString); EXPECT_FALSE(plainString.empty()); EXPECT_EQ(plainString.length(), encryptString.length() - prefixSize); + // Absent key testing. + encryptString = "fake_web_test"; + plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(absentKeyAlias, encryptString); + EXPECT_TRUE(plainString.empty()); + encryptString = "V10abcdefghijklmnopABCDEFGHIJKLMNOPQRSTUVWXYZ123456"; + plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(absentKeyAlias, encryptString); + EXPECT_TRUE(plainString.empty()); + std::string nullAlias = ""; encryptString = ""; plainString = KeystoreAdapterImpl::GetInstance().DecryptKey(nullAlias, encryptString); -- Gitee From 9fca18fda58ea8a10d8d4323c128360584d712ca Mon Sep 17 00:00:00 2001 From: slim Date: Thu, 21 Aug 2025 23:28:24 +0800 Subject: [PATCH 039/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: slim --- ohos_interface/include/ohos_adapter/imf_adapter.h | 2 +- ohos_interface/include/ohos_nweb/nweb.h | 6 +++--- test/unittest/common/nweb_create_window.h | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ohos_interface/include/ohos_adapter/imf_adapter.h b/ohos_interface/include/ohos_adapter/imf_adapter.h index b8584b438..9f3adb4a3 100644 --- a/ohos_interface/include/ohos_adapter/imf_adapter.h +++ b/ohos_interface/include/ohos_adapter/imf_adapter.h @@ -173,7 +173,7 @@ public: virtual void AutoFillWithIMFEvent(bool isUsername, bool isOtherAccount, bool isNewPassword, const std::string& content) {} - virtual void KeyboardUpperRightCornerHide() {}; + virtual void KeyboardUpperRightCornerHide() {} }; class IMFAdapter { diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 417df6c99..55c41e026 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -2094,7 +2094,7 @@ public: * @param from_overlay Indicates whether the event comes from an overlay layer. */ virtual void OnStylusTouchPress( - std::shared_ptr stylus_touch_point_info, bool from_overlay) = 0; + std::shared_ptr stylus_touch_point_info, bool from_overlay) {} /** * @brief Handle stylus touch release event. @@ -2102,7 +2102,7 @@ public: * @param from_overlay Indicates whether the event comes from an overlay layer. */ virtual void OnStylusTouchRelease( - std::shared_ptr stylus_touch_point_info, bool from_overlay) = 0; + std::shared_ptr stylus_touch_point_info, bool from_overlay) {} /** * @brief Handle batch stylus touch move events. @@ -2111,7 +2111,7 @@ public: * @param from_overlay Indicates whether the events come from an overlay layer. */ virtual void OnStylusTouchMove( - const std::vector>& stylus_touch_point_infos, bool from_overlay) = 0; + const std::vector>& stylus_touch_point_infos, bool from_overlay) {} }; diff --git a/test/unittest/common/nweb_create_window.h b/test/unittest/common/nweb_create_window.h index 62d57190e..21318356e 100644 --- a/test/unittest/common/nweb_create_window.h +++ b/test/unittest/common/nweb_create_window.h @@ -52,6 +52,18 @@ public: {} void OnTouchCancel() override {} + void OnStylusTouchPress( + std::shared_ptr stylus_touch_point_info, + bool fromOverlay = false) override + {} + void OnStylusTouchRelease( + std::shared_ptr stylus_touch_point_info, + bool fromOverlay = false) override + {} + void OnStylusTouchMove( + const std::vector>& stylus_touch_point_infos, + bool fromOverlay = false) override + {} void OnNavigateBack() override {} bool SendKeyEvent(int32_t keyCode, int32_t keyAction) override -- Gitee From e0a2a6ec1e53d0e0abdcf84028dc180212586fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=83=B3?= Date: Thu, 21 Aug 2025 16:20:21 +0800 Subject: [PATCH 040/124] add web ImeShow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李想 --- .../src/imf_adapter_impl.cpp | 2 ++ ohos_interface/include/ohos_adapter/imf_adapter.h | 4 +++- ohos_interface/include/ohos_nweb/nweb_handler.h | 9 +++++++++ .../webcore/ark_imf_text_listener_adapter_impl.cpp | 5 +++++ .../webcore/ark_imf_text_listener_adapter_impl.h | 2 ++ .../webview/ark_imftext_listener_adapter_wrapper.cpp | 4 ++++ .../webview/ark_imftext_listener_adapter_wrapper.h | 1 + .../ohos_glue/ohos_adapter/include/ark_imf_adapter.h | 3 +++ .../bridge/webcore/ark_web_handler_wrapper.cpp | 5 +++++ .../ohos_nweb/bridge/webcore/ark_web_handler_wrapper.h | 9 +++++++++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.cpp | 5 +++++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.h | 9 +++++++++ .../ohos_glue/ohos_nweb/include/ark_web_handler.h | 10 ++++++++++ 13 files changed, 67 insertions(+), 1 deletion(-) diff --git a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp index acdcaf97a..86269cf7f 100644 --- a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp +++ b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp @@ -486,10 +486,12 @@ bool IMFAdapterImpl::AttachParamsCheck(std::shared_ptr l void IMFTextListenerAdapterImpl::NotifyPanelStatusInfo(const MiscServices::PanelStatusInfo& info) { + WVLOG_I("IMFTextListenerAdapterImpl::NotifyPanelStatusInfo, visible:%{public}d", info.visible); MiscServices::Trigger triggerFrom = info.trigger; if (listener_ && (triggerFrom == MiscServices::Trigger::IME_APP)) { WVLOG_I("IMFTextListenerAdapterImpl::NotifyPanelStatusInfo, info.IME_APP"); listener_->KeyboardUpperRightCornerHide(); } + listener_->WebSetImeShow(info.visible); } } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_adapter/imf_adapter.h b/ohos_interface/include/ohos_adapter/imf_adapter.h index b8584b438..110d825de 100644 --- a/ohos_interface/include/ohos_adapter/imf_adapter.h +++ b/ohos_interface/include/ohos_adapter/imf_adapter.h @@ -173,7 +173,9 @@ public: virtual void AutoFillWithIMFEvent(bool isUsername, bool isOtherAccount, bool isNewPassword, const std::string& content) {} - virtual void KeyboardUpperRightCornerHide() {}; + virtual void KeyboardUpperRightCornerHide() {} + + virtual void WebSetImeShow(bool visible) {} }; class IMFAdapter { diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index f9709da8a..298a891c2 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -1264,6 +1264,15 @@ public: * @param height The height of the blankless frame. */ virtual void OnInsertBlanklessFrameWithSize(const std::string& pathToFrame, uint32_t width, uint32_t height) {} + + /** + * @brief Notify the web client to set the soft keyboard panel status. + * + * @param visible the soft keyboard panel status. If true, it represents the keyboard display; + * If it is false, it indicates that the keyboard is hidden. + * + */ + virtual void SetImeShow(bool visible) {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_listener_adapter_impl.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_listener_adapter_impl.cpp index a1dede92f..7a25ddcb6 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_listener_adapter_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_listener_adapter_impl.cpp @@ -128,4 +128,9 @@ void ArkIMFTextListenerAdapterImpl::KeyboardUpperRightCornerHide() { real_->KeyboardUpperRightCornerHide(); } + +void ArkIMFTextListenerAdapterImpl::WebSetImeShow(bool visible) +{ + real_->WebSetImeShow(visible); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_listener_adapter_impl.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_listener_adapter_impl.h index ade0f6a6d..86d3eff97 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_listener_adapter_impl.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_imf_text_listener_adapter_impl.h @@ -65,6 +65,8 @@ public: void KeyboardUpperRightCornerHide() override; + void WebSetImeShow(bool visible) override; + private: std::shared_ptr real_; diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_listener_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_listener_adapter_wrapper.cpp index fc65ab140..bef1386e1 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_listener_adapter_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_listener_adapter_wrapper.cpp @@ -143,4 +143,8 @@ void ArkIMFTextListenerAdapterWrapper::KeyboardUpperRightCornerHide() ctocpp_->KeyboardUpperRightCornerHide(); } +void ArkIMFTextListenerAdapterWrapper::WebSetImeShow(bool visible) +{ + ctocpp_->WebSetImeShow(visible); +} } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_listener_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_listener_adapter_wrapper.h index cf15837de..69aeb19c0 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_listener_adapter_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_listener_adapter_wrapper.h @@ -65,6 +65,7 @@ public: void KeyboardUpperRightCornerHide() override; + void WebSetImeShow(bool visible) 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 150b5bf80..2badd92c9 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 @@ -147,6 +147,9 @@ public: /*--ark web()--*/ virtual void KeyboardUpperRightCornerHide() = 0; + + /*--ark web()--*/ + virtual void WebSetImeShow(bool visible) = 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 9a4505545..71902712c 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 @@ -1271,4 +1271,9 @@ void ArkWebHandlerWrapper::OnInsertBlanklessFrameWithSize(const std::string& pat ark_web_handler_->OnInsertBlanklessFrameWithSize(pathToFrame_, width, height); ArkWebStringStructRelease(pathToFrame_); } + +void ArkWebHandlerWrapper::SetImeShow(bool visible) +{ + ark_web_handler_->SetImeShow(visible); +} } // 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 e44db392d..cc3d5a30e 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 @@ -745,6 +745,15 @@ public: void OnInsertBlanklessFrameWithSize(const std::string& pathToFrame, uint32_t width, uint32_t height) override; + + /** + * @brief Notify the web client to set the soft keyboard panel status. + * + * @param visible the soft keyboard panel status. If true, it represents the keyboard display; + * If it is false, it indicates that the keyboard is hidden. + * + */ + void SetImeShow(bool visible) 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 76518eeec..ddc843da5 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 @@ -1107,4 +1107,9 @@ void ArkWebHandlerImpl::OnInsertBlanklessFrameWithSize(const ArkWebString& pathT { nweb_handler_->OnInsertBlanklessFrameWithSize(ArkWebStringStructToClass(pathToFrame), width, height); } + +void ArkWebHandlerImpl::SetImeShow(bool visible) +{ + nweb_handler_->SetImeShow(visible); +} } // 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 7d75c5046..c97cc8eb6 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 @@ -708,6 +708,15 @@ public: void OnInsertBlanklessFrameWithSize(const ArkWebString& pathToFrame, uint32_t width, uint32_t height) override; + + /** + * @brief Notify the web client to set the soft keyboard panel status. + * + * @param visible the soft keyboard panel status. If true, it represents the keyboard display; + * If it is false, it indicates that the keyboard is hidden. + * + */ + void SetImeShow(bool visible) 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 6799938e2..bf6c08bde 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 @@ -1036,6 +1036,16 @@ public: virtual void OnInsertBlanklessFrameWithSize(const ArkWebString& pathToFrame, uint32_t width, uint32_t height) = 0; + + /** + * @brief Notify the web client to set the soft keyboard panel status. + * + * @param visible the soft keyboard panel status. If true, it represents the keyboard display; + * If it is false, it indicates that the keyboard is hidden. + * + */ + /*--ark web()--*/ + virtual void SetImeShow(bool visible) = 0; }; } // namespace OHOS::ArkWeb -- Gitee From 6a301beb2ed112376dcc5ce89e68e56a30a7a788 Mon Sep 17 00:00:00 2001 From: wuyuechang Date: Fri, 22 Aug 2025 11:00:11 +0800 Subject: [PATCH 041/124] fix: clean code Signed-off-by: wuyuechang --- ohos_nweb/src/nweb_crashpad_handler_main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ohos_nweb/src/nweb_crashpad_handler_main.cpp b/ohos_nweb/src/nweb_crashpad_handler_main.cpp index c59254cde..66126e7dd 100644 --- a/ohos_nweb/src/nweb_crashpad_handler_main.cpp +++ b/ohos_nweb/src/nweb_crashpad_handler_main.cpp @@ -34,8 +34,9 @@ const std::string CRASHPAD_HANDLER_PATH = "unsupport"; const std::string LIB_CRASHPAD_HANDLER = "libchrome_crashpad_handler.so"; } -std::optional GetEngineType(int argc, char* argv[]) { - constexpr std::string_view prefix = "--engine-type"; +std::optional GetEngineType(int argc, char* argv[]) +{ + constexpr std::string_view prefix = "--engine-type="; for (int i = 0; i < argc; ++i) { std::string_view arg = argv[i]; if (arg.size() > prefix.size() && arg.substr(0, prefix.size()) == prefix) { @@ -55,9 +56,11 @@ int main(int argc, char* argv[]) } #endif if (auto engineType = GetEngineType(argc, argv); engineType.has_value() && engineType.value() == "LEGACY") { + WVLOG_I("crashpad handler start from legacy"); libCrashpadHandler = std::string(LEGACY_WEBVIEW_SANDBOX_LIB_PATH) + "/" + std::string(WEBVIEW_CRASHPAD_HANDLER_SO); } else { + WVLOG_I("crashpad handler start from default"); libCrashpadHandler = webPath + "/" + std::string(WEBVIEW_CRASHPAD_HANDLER_SO); } -- Gitee From dad32044ca3f00d73f662d2560969290bca33921 Mon Sep 17 00:00:00 2001 From: some-one-mmx Date: Fri, 22 Aug 2025 11:00:04 +0800 Subject: [PATCH 042/124] add decode api for blankless Signed-off-by: some-one-mmx --- .../include/ohos_image_decoder_adapter_impl.h | 1 + .../ohos_adapter/ohos_image_decoder_adapter.h | 3 +++ .../ohos_image_decoder_adapter_test.cpp | 13 +++++++++++++ 3 files changed, 17 insertions(+) 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 913fbed1a..62b9c23c3 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 @@ -52,6 +52,7 @@ public: void ReleasePixelMap() override; Media::PixelMap* GetPixelMap() { return pixelMap_.get(); } void* GetDecodeData() override; + bool DecodeByPath(const std::string& path, AllocatorType type) override { return false; }; private: Media::ImageInfo imageInfo_; diff --git a/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h b/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h index aa4e85aab..143f98a7e 100644 --- a/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h +++ b/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h @@ -64,6 +64,9 @@ public: bool useYuv) = 0; virtual void* GetDecodeData() = 0; + + // decode heic by path + virtual bool DecodeByPath(const std::string& path, AllocatorType type) = 0; }; } // namespace OHOS::NWeb 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 771fc00ee..073e959c9 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 @@ -537,5 +537,18 @@ HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_GetDecodeData_013, TestSize. imageDecoderAdapterImpl.ReleasePixelMap(); } +/** + * @tc.name: OhosImageAdapterTest_DecodeByPath_014 + * @tc.desc: DecodeByPath. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OhosImageAdapterTest, OhosImageAdapterTest_DecodeByPath_014, TestSize.Level1) +{ + OhosImageDecoderAdapterImpl imageDecoderAdapterImpl; + bool ret = imageDecoderAdapterImpl.DecodeByPath(IMAGE_FILE_PATH, AllocatorType::kDmaAlloc); + EXPECT_FALSE(ret); +} + } // namespace NWeb } // namespace OHOS -- Gitee From e495716a293b2eddac6033e8bafc0290e9ea1eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E4=BC=9F?= Date: Fri, 22 Aug 2025 06:02:23 +0000 Subject: [PATCH 043/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李志伟 --- .../webcore/ark_web_adsblock_manager_impl.cpp | 3 +- .../ark_web_adsblock_manager_wrapper.cpp | 62 ++++++------ .../ark_web_adsblock_manager_wrapper.h | 99 +++++++++---------- 3 files changed, 85 insertions(+), 79 deletions(-) diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_adsblock_manager_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_adsblock_manager_impl.cpp index 878866cba..f9558fb8c 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_adsblock_manager_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_adsblock_manager_impl.cpp @@ -53,7 +53,8 @@ void ArkWebAdsBlockManagerImpl::RemoveAdsBlockAllowedList(const ArkWebStringVect nweb_adsblock_manager_->RemoveAdsBlockAllowedList(ArkWebStringVectorStructToClass(domainSuffixes)); } -void ArkWebAdsBlockManagerImpl::ClearAdsBlockAllowedList() { +void ArkWebAdsBlockManagerImpl::ClearAdsBlockAllowedList() +{ nweb_adsblock_manager_->ClearAdsBlockAllowedList(); } diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_adsblock_manager_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_adsblock_manager_wrapper.cpp index 811b66301..d722020f9 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_adsblock_manager_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_adsblock_manager_wrapper.cpp @@ -19,57 +19,63 @@ namespace OHOS::ArkWeb { -ArkWebAdsBlockManagerWrapper::ArkWebAdsBlockManagerWrapper( - ArkWebRefPtr ark_web_adsblock_manager) - : ark_web_adsblock_manager_(ark_web_adsblock_manager) { -} +ArkWebAdsBlockManagerWrapper::ArkWebAdsBlockManagerWrapper(ArkWebRefPtr ark_web_adsblock_manager) + : ark_web_adsblock_manager_(ark_web_adsblock_manager) +{} -void ArkWebAdsBlockManagerWrapper::SetAdsBlockRules(const std::string &rulesFile, bool replace) { - ArkWebString stRulesFile = ArkWebStringClassToStruct(rulesFile); +void ArkWebAdsBlockManagerWrapper::SetAdsBlockRules(const std::string& rulesFile, bool replace) +{ + ArkWebString stRulesFile = ArkWebStringClassToStruct(rulesFile); - ark_web_adsblock_manager_->SetAdsBlockRules(stRulesFile, replace); + ark_web_adsblock_manager_->SetAdsBlockRules(stRulesFile, replace); - ArkWebStringStructRelease(stRulesFile); + ArkWebStringStructRelease(stRulesFile); } -void ArkWebAdsBlockManagerWrapper::AddAdsBlockDisallowedList(const std::vector &domainSuffixes) { - ArkWebStringVector stDomainSuffixes = ArkWebStringVectorClassToStruct(domainSuffixes); +void ArkWebAdsBlockManagerWrapper::AddAdsBlockDisallowedList(const std::vector& domainSuffixes) +{ + ArkWebStringVector stDomainSuffixes = ArkWebStringVectorClassToStruct(domainSuffixes); - ark_web_adsblock_manager_->AddAdsBlockDisallowedList(stDomainSuffixes); + ark_web_adsblock_manager_->AddAdsBlockDisallowedList(stDomainSuffixes); - ArkWebStringVectorStructRelease(stDomainSuffixes); + ArkWebStringVectorStructRelease(stDomainSuffixes); } -void ArkWebAdsBlockManagerWrapper::RemoveAdsBlockDisallowedList(const std::vector &domainSuffixes) { - ArkWebStringVector stDomainSuffixes = ArkWebStringVectorClassToStruct(domainSuffixes); +void ArkWebAdsBlockManagerWrapper::RemoveAdsBlockDisallowedList(const std::vector& domainSuffixes) +{ + ArkWebStringVector stDomainSuffixes = ArkWebStringVectorClassToStruct(domainSuffixes); - ark_web_adsblock_manager_->RemoveAdsBlockDisallowedList(stDomainSuffixes); + ark_web_adsblock_manager_->RemoveAdsBlockDisallowedList(stDomainSuffixes); - ArkWebStringVectorStructRelease(stDomainSuffixes); + ArkWebStringVectorStructRelease(stDomainSuffixes); } -void ArkWebAdsBlockManagerWrapper::ClearAdsBlockDisallowedList() { - ark_web_adsblock_manager_->ClearAdsBlockDisallowedList(); +void ArkWebAdsBlockManagerWrapper::ClearAdsBlockDisallowedList() +{ + ark_web_adsblock_manager_->ClearAdsBlockDisallowedList(); } -void ArkWebAdsBlockManagerWrapper::AddAdsBlockAllowedList(const std::vector &domainSuffixes) { - ArkWebStringVector stDomainSuffixes = ArkWebStringVectorClassToStruct(domainSuffixes); +void ArkWebAdsBlockManagerWrapper::AddAdsBlockAllowedList(const std::vector& domainSuffixes) +{ + ArkWebStringVector stDomainSuffixes = ArkWebStringVectorClassToStruct(domainSuffixes); - ark_web_adsblock_manager_->AddAdsBlockAllowedList(stDomainSuffixes); + ark_web_adsblock_manager_->AddAdsBlockAllowedList(stDomainSuffixes); - ArkWebStringVectorStructRelease(stDomainSuffixes); + ArkWebStringVectorStructRelease(stDomainSuffixes); } -void ArkWebAdsBlockManagerWrapper::RemoveAdsBlockAllowedList(const std::vector &domainSuffixes) { - ArkWebStringVector stDomainSuffixes = ArkWebStringVectorClassToStruct(domainSuffixes); +void ArkWebAdsBlockManagerWrapper::RemoveAdsBlockAllowedList(const std::vector& domainSuffixes) +{ + ArkWebStringVector stDomainSuffixes = ArkWebStringVectorClassToStruct(domainSuffixes); - ark_web_adsblock_manager_->RemoveAdsBlockAllowedList(stDomainSuffixes); + ark_web_adsblock_manager_->RemoveAdsBlockAllowedList(stDomainSuffixes); - ArkWebStringVectorStructRelease(stDomainSuffixes); + ArkWebStringVectorStructRelease(stDomainSuffixes); } -void ArkWebAdsBlockManagerWrapper::ClearAdsBlockAllowedList() { - ark_web_adsblock_manager_->ClearAdsBlockAllowedList(); +void ArkWebAdsBlockManagerWrapper::ClearAdsBlockAllowedList() +{ + ark_web_adsblock_manager_->ClearAdsBlockAllowedList(); } } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_adsblock_manager_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_adsblock_manager_wrapper.h index 99953b159..4c13b2197 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_adsblock_manager_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_adsblock_manager_wrapper.h @@ -24,65 +24,64 @@ namespace OHOS::ArkWeb { class ArkWebAdsBlockManagerWrapper : public OHOS::NWeb::NWebAdsBlockManager { public: - ArkWebAdsBlockManagerWrapper( - ArkWebRefPtr ark_web_adsblock_manager); - ~ArkWebAdsBlockManagerWrapper() = default; + ArkWebAdsBlockManagerWrapper(ArkWebRefPtr ark_web_adsblock_manager); + ~ArkWebAdsBlockManagerWrapper() = default; - /** - * @brief Set Ads Block ruleset file, containing easylist rules. - * - * @param rulesFile absolute easylist file path contains app customized ads block rules. - * @param replace replace internal rules or not; - */ - void SetAdsBlockRules(const std::string &rulesFile, bool replace) override; + /** + * @brief Set Ads Block ruleset file, containing easylist rules. + * + * @param rulesFile absolute easylist file path contains app customized ads block rules. + * @param replace replace internal rules or not; + */ + void SetAdsBlockRules(const std::string& rulesFile, bool replace) override; - /** - * @brief Add items to Ads Block Disallowed list. - * - * @param domainSuffix list of domains suffix. if web page url matches someone in the list, - * Ads Block will be disallowed for the web page. - */ - void AddAdsBlockDisallowedList(const std::vector &domainSuffixes) override; + /** + * @brief Add items to Ads Block Disallowed list. + * + * @param domainSuffix list of domains suffix. if web page url matches someone in the list, + * Ads Block will be disallowed for the web page. + */ + void AddAdsBlockDisallowedList(const std::vector& domainSuffixes) override; - /** - * @brief Remove items from Ads Block disallowed list. - * - * @param domainSuffix : list of domains suffix needed be removed from disallow list - */ - void RemoveAdsBlockDisallowedList(const std::vector &domainSuffixes) override; + /** + * @brief Remove items from Ads Block disallowed list. + * + * @param domainSuffix : list of domains suffix needed be removed from disallow list + */ + void RemoveAdsBlockDisallowedList(const std::vector& domainSuffixes) override; - /** - * @brief Clear Ads Block disallowed list. - * - */ - void ClearAdsBlockDisallowedList() override; + /** + * @brief Clear Ads Block disallowed list. + * + */ + void ClearAdsBlockDisallowedList() override; - /** - * @brief Add items to Ads Block Allowed list. - * By default, ads block is allowed for all pages unless they are added to the - * disallow list. The priority of allowlist is higher than the disallowlist. It is - * used to re-enable ads block on the page that matches disallow list. - * - * @param domainSuffix list of domains suffix, if web page url matches someone in the list, - * Ads Block will be allowed for the web page. - */ - void AddAdsBlockAllowedList(const std::vector &domainSuffixes) override; + /** + * @brief Add items to Ads Block Allowed list. + * By default, ads block is allowed for all pages unless they are added to the + * disallow list. The priority of allowlist is higher than the disallowlist. It is + * used to re-enable ads block on the page that matches disallow list. + * + * @param domainSuffix list of domains suffix, if web page url matches someone in the list, + * Ads Block will be allowed for the web page. + */ + void AddAdsBlockAllowedList(const std::vector& domainSuffixes) override; - /** - * @brief Remove items from Ads Block allowed list. - * - * @param domainSuffix : list of domains suffix needed be removed from allow list - */ - void RemoveAdsBlockAllowedList(const std::vector &domainSuffixes) override; + /** + * @brief Remove items from Ads Block allowed list. + * + * @param domainSuffix : list of domains suffix needed be removed from allow list + */ + void RemoveAdsBlockAllowedList(const std::vector& domainSuffixes) override; - /** - * @brief Clear Ads Block allow list. - * - */ - void ClearAdsBlockAllowedList() override; + /** + * @brief Clear Ads Block allow list. + * + */ + void ClearAdsBlockAllowedList() override; private: - ArkWebRefPtr ark_web_adsblock_manager_; + ArkWebRefPtr ark_web_adsblock_manager_; }; } // namespace OHOS::ArkWeb -- Gitee From c7c11781660aa5010e4107fc3e49bd89c4e4656d Mon Sep 17 00:00:00 2001 From: wuqiwen Date: Fri, 22 Aug 2025 07:00:27 +0000 Subject: [PATCH 044/124] update ohos_interface/include/ohos_adapter/screen_capture_adapter.h. Signed-off-by: wuqiwen --- .../include/ohos_adapter/screen_capture_adapter.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_interface/include/ohos_adapter/screen_capture_adapter.h b/ohos_interface/include/ohos_adapter/screen_capture_adapter.h index 271127c04..b8693af2a 100644 --- a/ohos_interface/include/ohos_adapter/screen_capture_adapter.h +++ b/ohos_interface/include/ohos_adapter/screen_capture_adapter.h @@ -105,11 +105,11 @@ enum class ContainerFormatTypeAdapter : int32_t { }; enum class ScreenCaptureStateCodeAdapter : int32_t { - /* Screen capture state INVLID */ + /* Screen capture state INVALID */ SCREEN_CAPTURE_STATE_INVLID = -1, - /* Screen capture state started by user */ + /* Screen capture started by user */ SCREEN_CAPTURE_STATE_STARTED = 0, - /* Screen capture state canceled by user */ + /* Screen capture canceled by user */ SCREEN_CAPTURE_STATE_CANCELED = 1, /* ScreenCapture stopped by user */ SCREEN_CAPTURE_STATE_STOPPED_BY_USER = 2, @@ -125,7 +125,7 @@ enum class ScreenCaptureStateCodeAdapter : int32_t { SCREEN_CAPTURE_STATE_MIC_UNMUTED_BY_USER = 7, /* Current captured screen has private window */ SCREEN_CAPTURE_STATE_ENTER_PRIVATE_SCENE = 8, - /* Private window disappeared on current captured screen */ + /* Private window disappeared on current captured screen*/ SCREEN_CAPTURE_STATE_EXIT_PRIVATE_SCENE = 9, }; -- Gitee From 04e2a330396691de43ceb92a984cc007c3d0d55a Mon Sep 17 00:00:00 2001 From: wuqiwen Date: Fri, 22 Aug 2025 07:08:47 +0000 Subject: [PATCH 045/124] update screen_capture_adapter_impl_test/screen_capture_adapter_impl_test.cpp. Signed-off-by: wuqiwen --- .../screen_capture_adapter_impl_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2cb4b9311..6c2d04fa1 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 @@ -62,8 +62,8 @@ public: MOCK_METHOD1(SetScreenCaptureCallback, int32_t(const std::shared_ptr&)); MOCK_METHOD1(ExcludeContent, int32_t(ScreenCaptureContentFilter&)); MOCK_METHOD0(SetPrivacyAuthorityEnabled, int32_t()); - MOCK_METHOD1(SetScreenCaptureStrategy, int32_t(ScreenCaptureStrategy)); MOCK_METHOD1(UpdateSurface, int32_t(sptr)); + MOCK_METHOD1(SetScreenCaptureStrategy, int32_t(ScreenCaptureStrategy)); MOCK_METHOD2(SetCaptureArea, int32_t(uint64_t, OHOS::Rect)); }; } // namespace Media -- Gitee From c547bf8bbb2da90e1cfc899c99342cb5dadc4dbf Mon Sep 17 00:00:00 2001 From: zhutianzi Date: Fri, 22 Aug 2025 07:14:28 +0000 Subject: [PATCH 046/124] =?UTF-8?q?=E7=99=BD=E7=9B=92=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhutianzi --- ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp b/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp index 4d8ba2489..5ddd4933a 100644 --- a/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp +++ b/ohos_adapter/keystore_adapter/src/keystore_adapter_impl.cpp @@ -215,7 +215,7 @@ std::string KeystoreAdapterImpl::DecryptKey(const std::string alias, const std:: std::string KeystoreAdapterImpl::AssetQuery(const std::string assetHandle) { - Asset_Blob alias = { (uint32_t)(assetHandle.length()), (uint8_t*)assetHandle.c_str() }; + Asset_Blob alias = { .size = (uint32_t)(assetHandle.length()), .data = (uint8_t*)assetHandle.c_str() }; Asset_Attr attr[] = { { .tag = ASSET_TAG_ALIAS, .value.blob = alias }, { .tag = ASSET_TAG_RETURN_TYPE, .value.u32 = ASSET_RETURN_ALL }, -- Gitee From 2500929ddbeb243213c94b50845f87f6760a3797 Mon Sep 17 00:00:00 2001 From: sylvieQaQ Date: Fri, 22 Aug 2025 16:11:54 +0800 Subject: [PATCH 047/124] fix_bug Signed-off-by: sylvieQaQ --- ohos_interface/include/ohos_adapter/event_handler_adapter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_interface/include/ohos_adapter/event_handler_adapter.h b/ohos_interface/include/ohos_adapter/event_handler_adapter.h index f6d77fadf..d275ef322 100644 --- a/ohos_interface/include/ohos_adapter/event_handler_adapter.h +++ b/ohos_interface/include/ohos_adapter/event_handler_adapter.h @@ -50,7 +50,7 @@ public: virtual void RemoveFileDescriptorListener(int32_t fileDescriptor) = 0; - virtual void PostTask(const std::shared_ptr callback) {}; + virtual void PostTask(const std::shared_ptr callback) {} // be consistent with // rom/base/notification/eventhandler/interfaces/inner_api/file_descriptor_listener.h -- Gitee From b23ee0bb54dd1f71df40161c5d58a0950136afb1 Mon Sep 17 00:00:00 2001 From: some-one-mmx Date: Fri, 22 Aug 2025 17:05:12 +0800 Subject: [PATCH 048/124] fix decode Signed-off-by: some-one-mmx --- .../include/ohos_image_decoder_adapter_impl.h | 1 - .../include/ohos_adapter/ohos_image_decoder_adapter.h | 2 +- 2 files changed, 1 insertion(+), 2 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 62b9c23c3..913fbed1a 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 @@ -52,7 +52,6 @@ public: void ReleasePixelMap() override; Media::PixelMap* GetPixelMap() { return pixelMap_.get(); } void* GetDecodeData() override; - bool DecodeByPath(const std::string& path, AllocatorType type) override { return false; }; private: Media::ImageInfo imageInfo_; diff --git a/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h b/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h index 143f98a7e..2b6e1577e 100644 --- a/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h +++ b/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h @@ -66,7 +66,7 @@ public: virtual void* GetDecodeData() = 0; // decode heic by path - virtual bool DecodeByPath(const std::string& path, AllocatorType type) = 0; + virtual bool DecodeByPath(const std::string& path, AllocatorType type) { return false; }; }; } // namespace OHOS::NWeb -- Gitee From c3c317547b73de7408241e1029402eee8a0d5397 Mon Sep 17 00:00:00 2001 From: hw_yang Date: Fri, 22 Aug 2025 11:26:23 +0800 Subject: [PATCH 049/124] code check fix Signed-off-by: hw_yang Change-Id: I95045d4ff17d5521e354361cf76f12bf949929cb --- .../interface_native_test/native_interface_arkweb_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unittest/interface_native_test/native_interface_arkweb_test.cpp b/test/unittest/interface_native_test/native_interface_arkweb_test.cpp index 966032f57..7bea1cf6e 100644 --- a/test/unittest/interface_native_test/native_interface_arkweb_test.cpp +++ b/test/unittest/interface_native_test/native_interface_arkweb_test.cpp @@ -170,13 +170,13 @@ HWTEST_F(NativeInterfaceArkWebTest, OH_NativeArkWeb_SetBlanklessLoadingWithKey_0 EXPECT_EQ(errCode1, ArkWeb_BlanklessErrorCode::ARKWEB_BLANKLESS_ERR_INVALID_ARGS); auto errCode2 = OH_NativeArkWeb_SetBlanklessLoadingWithKey("", "OH_NativeArkWeb_SetBlanklessLoadingWithKey", false); EXPECT_EQ(errCode2, ArkWeb_BlanklessErrorCode::ARKWEB_BLANKLESS_ERR_UNKNOWN); - + OHOS::system::SetParameter("web.blankless.enabled", "false"); auto errCode3 = OH_NativeArkWeb_SetBlanklessLoadingWithKey("", "", true); EXPECT_EQ(errCode3, ArkWeb_BlanklessErrorCode::ARKWEB_BLANKLESS_ERR_DEVICE_NOT_SUPPORT); auto errCode4 = OH_NativeArkWeb_SetBlanklessLoadingWithKey("", "OH_NativeArkWeb_SetBlanklessLoadingWithKey", false); EXPECT_EQ(errCode4, ArkWeb_BlanklessErrorCode::ARKWEB_BLANKLESS_ERR_DEVICE_NOT_SUPPORT); - + OHOS::system::SetParameter("web.blankless.enabled", enabled ? "true" : "false"); } @@ -210,7 +210,7 @@ HWTEST_F(NativeInterfaceArkWebTest, OH_NativeArkWeb_ClearBlanklessLoadingCache_0 OH_NativeArkWeb_ClearBlanklessLoadingCache(keys2, 3); const char* keys3[101]; - // Test for key length over MAX_KEY_COUNT, which is 100. + // Test for key size over MAX_KEY_COUNT, which is 100. for (uint32_t idx = 0; idx < 101; idx++) { keys3[idx] = "test"; } -- Gitee From acfa7aa6848c3a06bca376e7e2cee9d292ab048e Mon Sep 17 00:00:00 2001 From: liuao Date: Sat, 23 Aug 2025 17:52:28 +0800 Subject: [PATCH 050/124] 0823 update ArkWebCore.hap to 6.0 Signed-off-by: liuao --- ohos_nweb/prebuilts/arm/ArkWebCore.hap | 4 ++-- ohos_nweb/prebuilts/arm64/ArkWebCore.hap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_nweb/prebuilts/arm/ArkWebCore.hap b/ohos_nweb/prebuilts/arm/ArkWebCore.hap index 24b9b7aa9..8bd124ff1 100644 --- a/ohos_nweb/prebuilts/arm/ArkWebCore.hap +++ b/ohos_nweb/prebuilts/arm/ArkWebCore.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4e4e58c3feab41059f7994a25430fd265babbbd734943e1ec7a7ec79c572c249 -size 116631011 +oid sha256:0b088fe0dfb81c08c2b27e318416cc6c250fb9ab63b647d714ffbd65298a6904 +size 116626921 diff --git a/ohos_nweb/prebuilts/arm64/ArkWebCore.hap b/ohos_nweb/prebuilts/arm64/ArkWebCore.hap index 071f8db4a..0132578f6 100644 --- a/ohos_nweb/prebuilts/arm64/ArkWebCore.hap +++ b/ohos_nweb/prebuilts/arm64/ArkWebCore.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6089e61d8b0a963406c475a80042f40566d280937768b8593eda2a9dfd9c34df -size 122455492 +oid sha256:f50c7ea796bff684287a9d57388c4a12408408938e440c99960327f186aaf74b +size 122447302 -- Gitee From c87d030917189fd2dc340dad2204f738152a19c8 Mon Sep 17 00:00:00 2001 From: Jonah_xia Date: Sun, 24 Aug 2025 09:32:55 +0000 Subject: [PATCH 051/124] =?UTF-8?q?nweb=5Fconfig=5Fhelper=E8=93=9D?= =?UTF-8?q?=E9=BB=84=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonah_xia --- ohos_nweb/include/nweb_config_helper.h | 4 +++ ohos_nweb/src/nweb_config_helper.cpp | 42 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/ohos_nweb/include/nweb_config_helper.h b/ohos_nweb/include/nweb_config_helper.h index a85956844..e9edf354e 100644 --- a/ohos_nweb/include/nweb_config_helper.h +++ b/ohos_nweb/include/nweb_config_helper.h @@ -40,6 +40,7 @@ public: int safeGetPropAsInt(xmlNode* node, const xmlChar* propName, int defaultValue); std::string GetBundleName(); void SetBundleName(const std::string& bundleName); + bool GetNWebDvsyncSwitch(); bool IsWebPlayGroundEnable(); const std::string& GetWebPlayGroundInitArg(); const std::string& GetWebPlayGroundHapPath(); @@ -56,6 +57,8 @@ private: void ParseDeleteConfig(const xmlNodePtr &rootPtr, std::shared_ptr initArgs); void ParseNWebLTPOApp(xmlNodePtr nodePtr); void ParseNWebLTPOStrategy(xmlNodePtr nodePtr); + void ParseNWebDvsync(xmlNodePtr nodePtr); + void ParseNWebDvsyncSwitch(xmlNodePtr nodePtr); void ParseWindowOrientationConfig(xmlNodePtr nodePtr, std::shared_ptr initArgs); bool IsDeveloperModeEnabled(); bool IsPerfConfigEmpty(); @@ -65,6 +68,7 @@ private: std::set ltpoAllowedApps_ {}; int32_t ltpoStrategy_ {0}; std::string bundleName_; + bool dvsyncSwitch_; mutable std::mutex lock_; // add for web play ground diff --git a/ohos_nweb/src/nweb_config_helper.cpp b/ohos_nweb/src/nweb_config_helper.cpp index ff97c0fb5..639f019cd 100644 --- a/ohos_nweb/src/nweb_config_helper.cpp +++ b/ohos_nweb/src/nweb_config_helper.cpp @@ -43,6 +43,8 @@ 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 std::string WEB_LTPO_STRATEGY = "ltpo_strategy"; +const std::string WEB_DVSYNC_CONFIG = "dvsync_config"; +const std::string WEB_DVSYNC_SWITCH = "dvsync_switch"; const std::string WEB_WINDOW_ORIENTATION_CONFIG = "window_orientation_config"; const std::string WEB_ALL_BUNDLE_NAME = "*"; const auto XML_ATTR_NAME = "name"; @@ -184,6 +186,7 @@ NWebConfigHelper::NWebConfigHelper() } } web_play_ground_enabled_ = isDebugApp && hasPlayGround && isDeveloperMode; + dvsyncSwitch_ = false; if (web_play_ground_enabled_) { #define XPM_KICKER (0x6a6974) @@ -377,6 +380,13 @@ void NWebConfigHelper::ParseWebConfigXml(const std::string& configFilePath, } } + if (!dvsyncSwitch_) { + xmlNodePtr dvsyncConfigNodePtr = GetChildrenNode(rootPtr, WEB_DVSYNC_CONFIG); + if (dvsyncConfigNodePtr != nullptr) { + ParseNWebDvsync(dvsyncConfigNodePtr); + } + } + xmlNodePtr windowOrientationNodePtr = GetChildrenNode(rootPtr, WEB_WINDOW_ORIENTATION_CONFIG); if (windowOrientationNodePtr != nullptr) { WVLOG_D("read config from window orientation node"); @@ -464,6 +474,38 @@ int32_t NWebConfigHelper::GetLTPOStrategy() return ltpoStrategy_; } +void NWebConfigHelper::ParseNWebDvsync(xmlNodePtr nodePtr) +{ + for (xmlNodePtr curNodePtr = nodePtr->xmlChildrenNode; curNodePtr; curNodePtr = curNodePtr->next) { + if (curNodePtr->name == nullptr || curNodePtr->type == XML_COMMENT_NODE) { + WVLOG_E("invalid node!"); + continue; + } + char* namePtr = (char*)xmlGetProp(curNodePtr, BAD_CAST(XML_ATTR_NAME)); + if (!namePtr) { + WVLOG_E("invalid node!"); + continue; + } + std::string settingName(namePtr); + xmlFree(namePtr); + if (settingName == WEB_DVSYNC_SWITCH) { + ParseNWebDvsyncSwitch(curNodePtr); + continue; + } + } +} + +void NWebConfigHelper::ParseNWebDvsyncSwitch(xmlNodePtr nodePtr) +{ + dvsyncSwitch_ = atoi((char*)xmlNodeGetContent(NodePtr)) == 1; + WVLOG_D("dvsync switch is: %{public}d", dvsyncSwitch_); +} + +bool NWebConfigHelper::GetNWebDvsyncSwitch() +{ + return dvsyncSwitch_; +} + std::vector NWebConfigHelper::GetPerfConfig(const std::string& settingName) { if (ltpoConfig_.find(settingName) == ltpoConfig_.end()) { -- Gitee From be9695d05df5df6bf87e7093f4689eb3aad4484b Mon Sep 17 00:00:00 2001 From: PatrickFung Date: Fri, 15 Aug 2025 16:54:49 +0800 Subject: [PATCH 052/124] Code consistency synchronization Signed-off-by: PatrickFung --- .../src/system_properties_adapter_impl.cpp | 2 +- .../webcore/ark_web_preference_impl.cpp | 21 ++++++++++--------- ohos_nweb/etc/para/web.para | 2 +- ohos_nweb/etc/web_config.xml | 3 --- 4 files changed, 13 insertions(+), 15 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 7eb15da90..a5bce425a 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 @@ -252,7 +252,7 @@ int32_t SystemPropertiesAdapterImpl::GetInitialCongestionWindowSize() { std::string init_cwnd_str = NWebConfigHelper::Instance() .ParsePerfConfig("TCPConnectedSocketConfig", "initialCongestionWindowSize"); - if (init_cwnd_str.size() > 0 && init_cwnd_str.size() < INT_MAX_LEN - 1 ) { + if (init_cwnd_str.size() > 0 && init_cwnd_str.size() < INT_MAX_LEN) { for (char character : init_cwnd_str) { if (!std::isdigit(character, std::locale::classic())) { WVLOG_E("parse initialCongestionWindowSize failed: invalid argument"); diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_preference_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_preference_impl.cpp index 3b2a92338..fab9f9018 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_preference_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_preference_impl.cpp @@ -476,19 +476,20 @@ void ArkWebPreferenceImpl::SetNativeVideoPlayerConfig(bool enable, bool shouldOv } } -void ArkWebPreferenceImpl::PutOverlayScrollbarEnabled(bool flag) +ArkWebString ArkWebPreferenceImpl::GetSurfaceId() { - nweb_preference_->PutOverlayScrollbarEnabled(flag); + std::string surfaceId = nweb_preference_->GetSurfaceId(); + return ArkWebStringClassToStruct(surfaceId); } -ArkWebString ArkWebPreferenceImpl::GetSurfaceId() +void ArkWebPreferenceImpl::SetSurfaceId(const ArkWebString& surfaceId) { - return ArkWebStringClassToStruct(nweb_preference_->GetSurfaceId()); + nweb_preference_->SetSurfaceId(ArkWebStringStructToClass(surfaceId)); } -void ArkWebPreferenceImpl::SetSurfaceId(const ArkWebString& ua) +void ArkWebPreferenceImpl::PutOverlayScrollbarEnabled(bool enable) { - nweb_preference_->SetSurfaceId(ArkWebStringStructToClass(ua)); + nweb_preference_->PutOverlayScrollbarEnabled(enable); } void ArkWebPreferenceImpl::SetScrollable(bool enable, int32_t scrollType) @@ -501,14 +502,14 @@ void ArkWebPreferenceImpl::SetBlurOnKeyboardHideMode(int enable) nweb_preference_->SetBlurOnKeyboardHideMode(enable); } -void ArkWebPreferenceImpl::PutWebMediaAVSessionEnabled(bool enable) +void ArkWebPreferenceImpl::SetFontWeightScale(float size) { - nweb_preference_->PutWebMediaAVSessionEnabled(enable); + nweb_preference_->SetFontWeightScale(size); } -void ArkWebPreferenceImpl::SetFontWeightScale(float scale) +void ArkWebPreferenceImpl::PutWebMediaAVSessionEnabled(bool enable) { - nweb_preference_->SetFontWeightScale(scale); + nweb_preference_->PutWebMediaAVSessionEnabled(enable); } void ArkWebPreferenceImpl::SetIntrinsicSizeEnable(bool enable) diff --git a/ohos_nweb/etc/para/web.para b/ohos_nweb/etc/para/web.para index d83c8fdbe..b77bbf1e8 100644 --- a/ohos_nweb/etc/para/web.para +++ b/ohos_nweb/etc/para/web.para @@ -26,4 +26,4 @@ web.ohos.vulkan = None web.prppreload.mode = preload web.ohos.dvsync = false web.ohos.enableCWNDSetting = false -web.TCPConnectedSocket.initialCongestionWindowSize = 10 \ No newline at end of file +web.TCPConnectedSocket.initialCongestionWindowSize = -1 diff --git a/ohos_nweb/etc/web_config.xml b/ohos_nweb/etc/web_config.xml index f48a286cc..07b65549f 100644 --- a/ohos_nweb/etc/web_config.xml +++ b/ohos_nweb/etc/web_config.xml @@ -65,9 +65,6 @@ 0 - - 10 - -- Gitee From 795f62116381cb8976baf0ffad5db20eb24b20d9 Mon Sep 17 00:00:00 2001 From: Jonah_xia Date: Mon, 25 Aug 2025 06:40:52 +0000 Subject: [PATCH 053/124] update:nweb_config_helper.cpp Signed-off-by: Jonah_xia --- ohos_nweb/src/nweb_config_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_nweb/src/nweb_config_helper.cpp b/ohos_nweb/src/nweb_config_helper.cpp index 639f019cd..a5336cc30 100644 --- a/ohos_nweb/src/nweb_config_helper.cpp +++ b/ohos_nweb/src/nweb_config_helper.cpp @@ -497,7 +497,7 @@ void NWebConfigHelper::ParseNWebDvsync(xmlNodePtr nodePtr) void NWebConfigHelper::ParseNWebDvsyncSwitch(xmlNodePtr nodePtr) { - dvsyncSwitch_ = atoi((char*)xmlNodeGetContent(NodePtr)) == 1; + dvsyncSwitch_ = atoi((char*)xmlNodeGetContent(nodePtr)) == 1; WVLOG_D("dvsync switch is: %{public}d", dvsyncSwitch_); } -- Gitee From 46a4590fffc9189c445cb3608312e141a00094bb Mon Sep 17 00:00:00 2001 From: wangdantong Date: Mon, 25 Aug 2025 12:45:35 +0000 Subject: [PATCH 054/124] Remove false assertions Signed-off-by: wangdantong Change-Id: I7375e696454d0c342813b910b9b337cdf78eb2ec --- .../display_manager_adapter_impl_test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unittest/display_manager_adapter_impl_test/display_manager_adapter_impl_test.cpp b/test/unittest/display_manager_adapter_impl_test/display_manager_adapter_impl_test.cpp index 908fd92ea..4bc95661f 100644 --- a/test/unittest/display_manager_adapter_impl_test/display_manager_adapter_impl_test.cpp +++ b/test/unittest/display_manager_adapter_impl_test/display_manager_adapter_impl_test.cpp @@ -398,12 +398,10 @@ HWTEST_F(DisplayManagerAdapterImplTest, OnChange_001, TestSize.Level1) std::unique_ptr displayListenerAdapterImpl = std::make_unique(nullptr); EXPECT_FALSE(displayListenerAdapterImpl->CheckOnlyRefreshRateDecreased(static_cast(1))); - DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); auto displayPtr = DisplayManager::GetInstance().GetDefaultDisplay(); ASSERT_NE(displayPtr, nullptr); auto displayInfo = displayPtr->GetDisplayInfo(); ASSERT_NE(displayInfo, nullptr); - EXPECT_EQ(id, DisplayManager::GetInstance().GetDefaultDisplayId()); EXPECT_FALSE(displayListenerAdapterImpl->CheckOnlyRefreshRateDecreased( DisplayManager::GetInstance().GetDefaultDisplayId())); auto nwebDisplayInfo = displayListenerAdapterImpl->ConvertDisplayInfo(*displayInfo); -- Gitee From ebb7b3c0f292eda5b15d833706870f0fe9076815 Mon Sep 17 00:00:00 2001 From: Fiatiustitia Date: Tue, 26 Aug 2025 03:25:21 +0000 Subject: [PATCH 055/124] =?UTF-8?q?surfaceTmp=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E5=8A=A0=E5=85=A5surface=5Fmap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fiatiustitia --- ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp b/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp index 6bbea55d0..efca141b1 100644 --- a/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp +++ b/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp @@ -157,6 +157,10 @@ void AafwkBrowserHostImpl::PassSurface(sptr surface, int64_t surface_id WVLOG_E("get surfaceUtils failed."); return; } + if (!surfaceTmp) { + WVLOG_E("surface is nullptr"); + return; + } surface_map_.emplace(surface_id, surfaceTmp); utils->Add(surface_id, surfaceTmp); } -- Gitee From 03a28526945e52279f0aca8b826e2771c4112d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9C=89=E5=BA=B7?= Date: Tue, 26 Aug 2025 14:13:37 +0800 Subject: [PATCH 056/124] fix code warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张有康 --- ohos_interface/include/ohos_adapter/ohos_adapter_helper.h | 2 +- ohos_interface/include/ohos_nweb/nweb.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h b/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h index 1a91e18c0..dc382339a 100644 --- a/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h +++ b/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h @@ -169,7 +169,7 @@ public: virtual std::unique_ptr CreateScreenlockManagerAdapter() = 0; - virtual std::unique_ptr GetCertManagerAdapter() {return nullptr;}; + virtual std::unique_ptr GetCertManagerAdapter() {return nullptr;} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 98291b7e5..9325d5773 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -1956,7 +1956,7 @@ public: virtual std::unique_ptr CreateWebPrintDocumentAdapterV2( const std::string& jobName) { return nullptr; - }; + } /* * @brief Set unique key of current page for insert frame. -- Gitee From c96c24854b177aa2e63ae23bc28fd76053eb9019 Mon Sep 17 00:00:00 2001 From: Fiatiustitia Date: Tue, 26 Aug 2025 06:25:42 +0000 Subject: [PATCH 057/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMMIInputListenerAdapt?= =?UTF-8?q?erImpl::OnInputEvent=20keyEvent=E5=8F=AF=E8=83=BD=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?InputManager=20=E5=8F=AF=E8=83=BD=E4=B8=BA=E7=A9=BA=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fiatiustitia --- .../src/mmi_adapter_impl.cpp | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/ohos_adapter/multimodalinput_adapter/src/mmi_adapter_impl.cpp b/ohos_adapter/multimodalinput_adapter/src/mmi_adapter_impl.cpp index 7e9921be9..b3d0ff16e 100644 --- a/ohos_adapter/multimodalinput_adapter/src/mmi_adapter_impl.cpp +++ b/ohos_adapter/multimodalinput_adapter/src/mmi_adapter_impl.cpp @@ -54,7 +54,7 @@ MMIInputListenerAdapterImpl::~MMIInputListenerAdapterImpl() void MMIInputListenerAdapterImpl::OnInputEvent(std::shared_ptr keyEvent) const { - if (!listener_) { + if (!listener_ || !keyEvent) { return; } if (keyEvent->GetKeyAction() != MMI::KeyEvent::KEY_ACTION_DOWN && @@ -81,14 +81,24 @@ int32_t MMIAdapterImpl::RegisterMMIInputListener(std::shared_ptr(eventCallback); - int32_t id = InputManager::GetInstance()->AddMonitor(inputListener_); + auto manager = InputManager::GetInstance(); + if (!manager) { + WVLOG_E("InputManager::GetInstance failed"); + return -1; + } + int32_t id = manager->AddMonitor(inputListener_); WVLOG_D("RegisterMMIInputListener id = %{public}d", id); return id; }; void MMIAdapterImpl::UnregisterMMIInputListener(int32_t monitorId) { - InputManager::GetInstance()->RemoveMonitor(monitorId); + auto manager = InputManager::GetInstance(); + if (!manager) { + WVLOG_E("InputManager::GetInstance failed"); + return; + } + manager->RemoveMonitor(monitorId); }; int32_t MMIAdapterImpl::RegisterDevListener(std::string type, std::shared_ptr listener) @@ -98,24 +108,44 @@ int32_t MMIAdapterImpl::RegisterDevListener(std::string type, std::shared_ptr(listener); - return InputManager::GetInstance()->RegisterDevListener(type, devListener_); + auto manager = InputManager::GetInstance(); + if (!manager) { + WVLOG_E("InputManager::GetInstance failed"); + return -1; + } + return manager->RegisterDevListener(type, devListener_); }; int32_t MMIAdapterImpl::UnregisterDevListener(std::string type) { - return InputManager::GetInstance()->UnregisterDevListener(type, devListener_); + auto manager = InputManager::GetInstance(); + if (!manager) { + WVLOG_E("InputManager::GetInstance failed"); + return -1; + } + return manager->UnregisterDevListener(type, devListener_); }; int32_t MMIAdapterImpl::GetKeyboardType(int32_t deviceId, int32_t& type) { + auto manager = InputManager::GetInstance(); + if (!manager) { + WVLOG_E("InputManager::GetInstance failed"); + return -1; + } std::function callback = [&type](int32_t param) { type = param; }; - return InputManager::GetInstance()->GetKeyboardType(deviceId, callback); + return manager->GetKeyboardType(deviceId, callback); }; int32_t MMIAdapterImpl::GetDeviceIds(std::vector& ids) { + auto manager = InputManager::GetInstance(); + if (!manager) { + WVLOG_E("InputManager::GetInstance failed"); + return -1; + } std::function&)> callback = [&ids](std::vector& param) { ids = param; }; - return InputManager::GetInstance()->GetDeviceIds(callback); + return manager->GetDeviceIds(callback); }; int32_t MMIAdapterImpl::GetDeviceInfo(int32_t deviceId, std::shared_ptr info) @@ -139,8 +169,12 @@ int32_t MMIAdapterImpl::GetDeviceInfo(int32_t deviceId, std::shared_ptrSetUniq(device->GetUniq()); } }; - - int32_t ret = InputManager::GetInstance()->GetDevice( + auto manager = InputManager::GetInstance(); + if (!manager) { + WVLOG_E("InputManager::GetInstance failed"); + return -1; + } + int32_t ret = manager->GetDevice( deviceId, [&callback](std::shared_ptr device) { callback(device); }); if (ret != 0) { WVLOG_E("InputManager GetDevice failed, ret: %{public}d", ret); @@ -151,7 +185,12 @@ int32_t MMIAdapterImpl::GetDeviceInfo(int32_t deviceId, std::shared_ptrGetMaxMultiTouchPointNum(pointNum); + auto manager = MMI::InputManager::GetInstance(); + if (!manager) { + WVLOG_E("InputManager::GetInstance failed"); + return -1; + } + int32_t ret = manager->GetMaxMultiTouchPointNum(pointNum); WVLOG_D("MMIAdapterImpl::GetMaxTouchPoints, pointNum: %{public}d", pointNum); if (ret != 0) { WVLOG_E("InputManager GetMaxTouchPoints failed, ret: %{public}d", ret); -- Gitee From 9b257ff7841e03f06e69de0d881c55708785f533 Mon Sep 17 00:00:00 2001 From: hua-mengzheng Date: Tue, 26 Aug 2025 11:36:28 +0800 Subject: [PATCH 058/124] arkweb utils update Signed-off-by: hua-mengzheng --- arkweb_utils/arkweb_utils.cpp | 38 ++++++++-- arkweb_utils/arkweb_utils.h | 3 +- .../src/aafwk_app_mgr_client_adapter_impl.cpp | 2 +- .../arkweb_utils_test/arkweb_utils_test.cpp | 74 ++++++++----------- 4 files changed, 63 insertions(+), 54 deletions(-) diff --git a/arkweb_utils/arkweb_utils.cpp b/arkweb_utils/arkweb_utils.cpp index 2e1c63fc1..dea34ecd8 100644 --- a/arkweb_utils/arkweb_utils.cpp +++ b/arkweb_utils/arkweb_utils.cpp @@ -26,6 +26,8 @@ namespace OHOS::ArkWeb { static int g_appEngineVersion = static_cast(ArkWebEngineVersion::SYSTEM_DEFAULT); static bool g_webEngineInitFlag = false; +static ArkWebEngineVersion g_activeEngineVersion = ArkWebEngineVersion::SYSTEM_DEFAULT; +static std::string g_appBundleName = ""; #if defined(webview_arm64) const std::string ARK_WEB_CORE_MOCK_HAP_LIB_PATH = @@ -84,6 +86,9 @@ const std::string JSON_CONFIG_PATH = "/data/service/el1/public/update/param_service/install/system/etc/ArkWebSafeBrowsing/generic/ArkWebCoreCfg.json"; const std::string WEB_PARAM_PREFIX = "web.engine."; +// 前向声明 +static ArkWebEngineVersion CalculateActiveWebEngineVersion(); + static bool validateSpecialParams(const std::string& key, int value) { if (key == "web.engine.default") { @@ -157,6 +162,12 @@ static void updateCfgToSystemParam() processJsonConfig(root); } +void SelectWebcoreBeforeProcessRun(const std::string& appBundleName) +{ + g_appBundleName = appBundleName; + g_activeEngineVersion = CalculateActiveWebEngineVersion(); +} + void PreloadArkWebLibForBrowser() { updateCfgToSystemParam(); @@ -169,6 +180,7 @@ void PreloadArkWebLibForBrowser() static_cast(ArkWebEngineType::EVERGREEN)); } } + g_activeEngineVersion = CalculateActiveWebEngineVersion(); return; } @@ -187,24 +199,31 @@ void setActiveWebEngineVersion(ArkWebEngineVersion version) return; } g_appEngineVersion = static_cast(version); - WVLOG_I("set appEngineVersion: %{public}d", g_appEngineVersion); + WVLOG_I("app setActiveWebEngineVersion: %{public}d", g_appEngineVersion); + g_activeEngineVersion = CalculateActiveWebEngineVersion(); } -ArkWebEngineVersion getAppWebEngineVersion() +void SetActiveWebEngineVersionInner(ArkWebEngineVersion version) { - return static_cast(g_appEngineVersion); + g_activeEngineVersion = version; } ArkWebEngineVersion getActiveWebEngineVersion() +{ + WVLOG_I("getActiveWebEngineVersion: %{public}d", g_activeEngineVersion); + return g_activeEngineVersion; +} + +ArkWebEngineVersion CalculateActiveWebEngineVersion() { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); if (webEngineEnforce == static_cast(ArkWebEngineType::EVERGREEN)) { - WVLOG_I("WebEngineVersionResult, enforce EVERGREEN"); + WVLOG_I("CalculateActiveWebEngineVersion, enforce EVERGREEN"); return static_cast(ArkWebEngineType::EVERGREEN); } if (g_appEngineVersion != static_cast(ArkWebEngineVersion::SYSTEM_DEFAULT)) { - WVLOG_I("get appEngineVersion: %{public}d", g_appEngineVersion); + WVLOG_I("CalculateActiveWebEngineVersion appEngineVersion: %{public}d", g_appEngineVersion); if (g_appEngineVersion == static_cast(ArkWebEngineVersion::SYSTEM_EVERGREEN)) { return static_cast(ArkWebEngineType::EVERGREEN); } @@ -215,11 +234,16 @@ ArkWebEngineVersion getActiveWebEngineVersion() static_cast(ArkWebEngineType::EVERGREEN)); if (webEngineDefault != static_cast(ArkWebEngineType::LEGACY) && webEngineDefault != static_cast(ArkWebEngineType::EVERGREEN)) { - WVLOG_E("webEngineDefault is not EVERGREEN or LEGACY: %{public}d", webEngineDefault); + WVLOG_E("CalculateActiveWebEngineVersion, webEngineDefault error: %{public}d", webEngineDefault); + return static_cast(ArkWebEngineType::EVERGREEN); + } + + if (webEngineDefault == static_cast(ArkWebEngineVersion::M114) && + g_appBundleName == "com.example.app2") { return static_cast(ArkWebEngineType::EVERGREEN); } - WVLOG_I("get webEngineDefault: %{public}d", webEngineDefault); + WVLOG_I("CalculateActiveWebEngineVersion webEngineDefault: %{public}d", webEngineDefault); return static_cast(webEngineDefault); } diff --git a/arkweb_utils/arkweb_utils.h b/arkweb_utils/arkweb_utils.h index 5038192f9..9d7480473 100644 --- a/arkweb_utils/arkweb_utils.h +++ b/arkweb_utils/arkweb_utils.h @@ -76,8 +76,9 @@ enum class ArkWebEngineType { ARKWEB_EXPORT void setActiveWebEngineVersion(ArkWebEngineVersion version); ARKWEB_EXPORT ArkWebEngineVersion getActiveWebEngineVersion(); ARKWEB_EXPORT ArkWebEngineType getActiveWebEngineType(); -ARKWEB_EXPORT ArkWebEngineVersion getAppWebEngineVersion(); +ARKWEB_EXPORT void SetActiveWebEngineVersionInner(ArkWebEngineVersion version); ARKWEB_EXPORT bool IsActiveWebEngineEvergreen(); +ARKWEB_EXPORT void SelectWebcoreBeforeProcessRun(const std::string& appBundleName); ARKWEB_EXPORT std::string GetArkwebLibPath(); ARKWEB_EXPORT std::string GetArkwebNameSpace(); diff --git a/ohos_adapter/aafwk_adapter/src/aafwk_app_mgr_client_adapter_impl.cpp b/ohos_adapter/aafwk_adapter/src/aafwk_app_mgr_client_adapter_impl.cpp index 2a8fe27b2..4e5d6cfd0 100644 --- a/ohos_adapter/aafwk_adapter/src/aafwk_app_mgr_client_adapter_impl.cpp +++ b/ohos_adapter/aafwk_adapter/src/aafwk_app_mgr_client_adapter_impl.cpp @@ -128,7 +128,7 @@ int AafwkAppMgrClientAdapterImpl::StartChildProcess( int retryCnt = 0; int ret; do { - int appEngineVersion = static_cast(OHOS::ArkWeb::getAppWebEngineVersion()); + int appEngineVersion = static_cast(OHOS::ArkWeb::getActiveWebEngineVersion()); const std::string renderParamNew = renderParam + APP_ENGINE_VERSION_PREFIX + std::to_string(appEngineVersion); WVLOG_I("AafwkAppMgrClientAdapterImpl::StartChildProcess, renderParamNew = %{public}s, renderPid = %{public}d", diff --git a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp index 63c071998..96c993a54 100644 --- a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp +++ b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp @@ -72,58 +72,22 @@ const std::string SANDBOX_EVERGREEN_HAP_PATH = "/data/storage/el1/bundle/arkwebc const std::string JSON_CONFIG_PATH = "/data/service/el1/public/update/param_service/install/system/etc/ArkWebSafeBrowsing/generic/ArkWebCoreCfg.json"; -TEST(arkweb_utils_test, setActiveWebEngineVersion001) { - setActiveWebEngineVersion(ArkWebEngineVersion::SYSTEM_DEFAULT); - - EXPECT_EQ(getAppWebEngineVersion(), ArkWebEngineVersion::SYSTEM_DEFAULT); -} - -TEST(arkweb_utils_test, setActiveWebEngineVersion002) { - setActiveWebEngineVersion(ArkWebEngineVersion::M114); +TEST(arkweb_utils_test, SetActiveWebEngineVersionInner001) { + SetActiveWebEngineVersionInner(ArkWebEngineVersion::SYSTEM_DEFAULT); - EXPECT_EQ(getAppWebEngineVersion(), ArkWebEngineVersion::M114); + EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::SYSTEM_DEFAULT); } -TEST(arkweb_utils_test, setActiveWebEngineVersion003) { - setActiveWebEngineVersion(ArkWebEngineVersion::M132); +TEST(arkweb_utils_test, SetActiveWebEngineVersionInner002) { + SetActiveWebEngineVersionInner(ArkWebEngineVersion::M114); - EXPECT_EQ(getAppWebEngineVersion(), ArkWebEngineVersion::M132); + EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M114); } -TEST(arkweb_utils_test, setActiveWebEngineVersion004) { - setActiveWebEngineVersion(ArkWebEngineVersion::SYSTEM_DEFAULT); - setActiveWebEngineVersion(static_cast(3)); +TEST(arkweb_utils_test, SetActiveWebEngineVersionInner003) { + SetActiveWebEngineVersionInner(ArkWebEngineVersion::M132); - EXPECT_EQ(getAppWebEngineVersion(), ArkWebEngineVersion::SYSTEM_DEFAULT); -} - -TEST(arkweb_utils_test, getActiveWebEngineVersion001) { - int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); - OHOS::system::SetParameter("web.engine.enforce", std::to_string(1)); - - auto res = getActiveWebEngineVersion(); - EXPECT_EQ(res, ArkWebEngineVersion::M132); - OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); -} - -TEST(arkweb_utils_test, getActiveWebEngineVersion002) { - int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); - OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); - setActiveWebEngineVersion(ArkWebEngineVersion::SYSTEM_DEFAULT); - - auto res = getActiveWebEngineVersion(); - EXPECT_EQ(res, ArkWebEngineVersion::M132); - OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); -} - -TEST(arkweb_utils_test, getActiveWebEngineVersion003) { - int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); - OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); - setActiveWebEngineVersion(ArkWebEngineVersion::M114); - - auto res = getActiveWebEngineVersion(); - EXPECT_EQ(res, ArkWebEngineVersion::M114); - OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); + EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M132); } TEST(arkweb_utils_test, getActiveWebEngineType001) { @@ -258,4 +222,24 @@ TEST(arkweb_utils_test, GetArkwebInstallPath002) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } + +TEST(arkweb_utils_test, SelectWebcoreBeforeProcessRun001) { + std::string appBundleName = "com.example.app"; + int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); + OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); + + SelectWebcoreBeforeProcessRun(appBundleName); + EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M132); + OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); +} + +TEST(arkweb_utils_test, SelectWebcoreBeforeProcessRun002) { + std::string appBundleName = "com.example.app2"; + int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); + OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); + + SelectWebcoreBeforeProcessRun(appBundleName); + EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M132); + OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); +} } // namespace OHOS::NWeb \ No newline at end of file -- Gitee From ea3369e1ec6dc84cbaf6154e66e609f9fa773c08 Mon Sep 17 00:00:00 2001 From: Fiatiustitia Date: Tue, 26 Aug 2025 07:59:32 +0000 Subject: [PATCH 059/124] =?UTF-8?q?MiscServices::InputMethodController::Ge?= =?UTF-8?q?tInstance=20=E5=A4=96=E9=83=A8=E5=87=BD=E6=95=B0=E5=88=A4?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fiatiustitia --- .../src/imf_adapter_impl.cpp | 65 ++++++++++++++++--- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp index 86269cf7f..4694cc238 100644 --- a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp +++ b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp @@ -262,7 +262,12 @@ bool IMFAdapterImpl::Attach(std::shared_ptr listener, bo return false; } } - int32_t ret = MiscServices::InputMethodController::GetInstance()->Attach(textListener_, isShowKeyboard); + auto controller = MiscServices::InputMethodController::GetInstance(); + if (!controller) { + WVLOG_E("MiscServices::InputMethodController::GetInstance failed"); + return false; + } + int32_t ret = controller->Attach(textListener_, isShowKeyboard); if (ret != 0) { WVLOG_E("inputmethod attach failed, errcode=%{public}d", ret); return false; @@ -323,7 +328,12 @@ bool IMFAdapterImpl::Attach(std::shared_ptr listener, bo "web inputmethod attach, isShowKeyboard=%{public}d, textConfig=%{public}s", isShowKeyboard, textConfig.ToString().c_str()); - int32_t ret = MiscServices::InputMethodController::GetInstance()->Attach(textListener_, isShowKeyboard, textConfig); + auto controller = MiscServices::InputMethodController::GetInstance(); + if (!controller) { + WVLOG_E("MiscServices::InputMethodController::GetInstance failed"); + return false; + } + int32_t ret = controller->Attach(textListener_, isShowKeyboard, textConfig); if (ret != 0) { WVLOG_E("inputmethod attach failed, errcode=%{public}d", ret); ReportImfErrorEvent(ret, isShowKeyboard); @@ -362,7 +372,12 @@ bool IMFAdapterImpl::AttachWithRequestKeyboardReason(std::shared_ptrAttach(textListener_, attachOptions, textConfig); + auto controller = MiscServices::InputMethodController::GetInstance(); + if (!controller) { + WVLOG_E("MiscServices::InputMethodController::GetInstance failed"); + return false; + } + int32_t ret = controller->Attach(textListener_, attachOptions, textConfig); if (ret != 0) { WVLOG_E("inputmethod attach failed, errcode=%{public}d", ret); ReportImfErrorEvent(ret, isShowKeyboard); @@ -379,18 +394,33 @@ void IMFAdapterImpl::ShowCurrentInput(const IMFAdapterTextInputType& inputType) } else { config.SetTextInputType(MiscServices::TextInputType::TEXT); } - MiscServices::InputMethodController::GetInstance()->OnConfigurationChange(config); - MiscServices::InputMethodController::GetInstance()->ShowCurrentInput(); + auto controller = MiscServices::InputMethodController::GetInstance(); + if (!controller) { + WVLOG_E("MiscServices::InputMethodController::GetInstance failed"); + return; + } + controller->OnConfigurationChange(config); + controller->ShowCurrentInput(); } void IMFAdapterImpl::HideTextInput() { - MiscServices::InputMethodController::GetInstance()->HideTextInput(); + auto controller = MiscServices::InputMethodController::GetInstance(); + if (!controller) { + WVLOG_E("MiscServices::InputMethodController::GetInstance failed"); + return; + } + controller->HideTextInput(); } void IMFAdapterImpl::Close() { - MiscServices::InputMethodController::GetInstance()->Close(); + auto controller = MiscServices::InputMethodController::GetInstance(); + if (!controller) { + WVLOG_E("MiscServices::InputMethodController::GetInstance failed"); + return; + } + controller->Close(); } void IMFAdapterImpl::OnCursorUpdate(const std::shared_ptr cursorInfo) @@ -406,12 +436,22 @@ void IMFAdapterImpl::OnCursorUpdate(const std::shared_ptr .height = cursorInfo->GetHeight() }; WVLOG_D("imfInfo left = %{public}f, top = %{public}f, width = %{public}f, height = %{public}f", imfInfo.left, imfInfo.top, imfInfo.width, imfInfo.height); - MiscServices::InputMethodController::GetInstance()->OnCursorUpdate(imfInfo); + auto controller = MiscServices::InputMethodController::GetInstance(); + if (!controller) { + WVLOG_E("MiscServices::InputMethodController::GetInstance failed"); + return; + } + controller->OnCursorUpdate(imfInfo); } void IMFAdapterImpl::OnSelectionChange(std::u16string text, int start, int end) { - MiscServices::InputMethodController::GetInstance()->OnSelectionChange(text, start, end); + auto controller = MiscServices::InputMethodController::GetInstance(); + if (!controller) { + WVLOG_E("MiscServices::InputMethodController::GetInstance failed"); + return; + } + controller->OnSelectionChange(text, start, end); } bool IMFAdapterImpl::SendPrivateCommand(const std::string& commandKey, const std::string& commandValue) @@ -419,7 +459,12 @@ bool IMFAdapterImpl::SendPrivateCommand(const std::string& commandKey, const std if (commandKey == AUTO_FILL_CANCEL_PRIVATE_COMMAND) { std::unordered_map privateCommand; ParseFillContentJsonValue(commandValue, privateCommand); - int32_t ret = MiscServices::InputMethodController::GetInstance()->SendPrivateCommand(privateCommand); + auto controller = MiscServices::InputMethodController::GetInstance(); + if (!controller) { + WVLOG_E("MiscServices::InputMethodController::GetInstance failed"); + return false; + } + int32_t ret = controller->SendPrivateCommand(privateCommand); if (ret != 0) { WVLOG_E("inputmethod SendPrivateCommand failed, errcode=%{public}d", ret); return false; -- Gitee From 67b3d189aa761e029604f33652b1ab03290f5b29 Mon Sep 17 00:00:00 2001 From: xiongjun_gitee11 Date: Tue, 26 Aug 2025 14:07:49 +0800 Subject: [PATCH 060/124] add CM_ST_LONG_TAP Signed-off-by: xiongjun_gitee11 --- ohos_interface/include/ohos_nweb/nweb_context_menu_params.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ohos_interface/include/ohos_nweb/nweb_context_menu_params.h b/ohos_interface/include/ohos_nweb/nweb_context_menu_params.h index 0720b3caf..0e6807028 100644 --- a/ohos_interface/include/ohos_nweb/nweb_context_menu_params.h +++ b/ohos_interface/include/ohos_nweb/nweb_context_menu_params.h @@ -39,6 +39,7 @@ public: enum ContextMenuMediaType { CM_MT_NONE, CM_MT_IMAGE, + CM_MT_TEXT, }; enum ContextMenuEditStateFlags { @@ -62,6 +63,7 @@ public: CM_ST_NONE = 0, CM_ST_MOUSE = 1, CM_ST_LONG_PRESS = 2, + CM_ST_LONG_TAP = 3, }; virtual ~NWebContextMenuParams() = default; -- Gitee From c68daa2566cc5b60180fac3296ea28b4f032e9db Mon Sep 17 00:00:00 2001 From: liuzhijie2 Date: Tue, 26 Aug 2025 17:26:04 +0800 Subject: [PATCH 061/124] disable autopreconnect Signed-off-by: liuzhijie2 --- .../napi_webview_controller.cpp | 48 +++++++++++++++++++ .../napi_webview_controller.h | 2 + ohos_nweb/include/nweb_helper.h | 5 ++ ohos_nweb/src/nweb_helper.cpp | 16 +++++++ .../nweb_helper_test/nweb_helper_ex_test.cpp | 18 +++++++ 5 files changed, 89 insertions(+) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index a28c44de3..823241167 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -773,6 +773,8 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_FUNCTION("setActiveWebEngineVersion", NapiWebviewController::SetActiveWebEngineVersion), DECLARE_NAPI_STATIC_FUNCTION("getActiveWebEngineVersion", NapiWebviewController::GetActiveWebEngineVersion), DECLARE_NAPI_STATIC_FUNCTION("isActiveWebEngineEvergreen", NapiWebviewController::IsActiveWebEngineEvergreen), + DECLARE_NAPI_STATIC_FUNCTION("setAutoPreconnect", NapiWebviewController::SetAutoPreconnect), + DECLARE_NAPI_STATIC_FUNCTION("isAutoPreconnectEnabled", NapiWebviewController::IsAutoPreconnectEnabled), }; napi_value constructor = nullptr; napi_define_class(env, WEBVIEW_CONTROLLER_CLASS_NAME.c_str(), WEBVIEW_CONTROLLER_CLASS_NAME.length(), @@ -7739,5 +7741,51 @@ napi_value NapiWebviewController::IsActiveWebEngineEvergreen(napi_env env, napi_ NAPI_CALL(env, napi_get_boolean(env, isEvergreen, &result)); return result; } + +napi_value NapiWebviewController::SetAutoPreconnect(napi_env env, napi_callback_info info) +{ + if (IS_CALLING_FROM_M114()) { + WVLOG_W("SetAutoPreconnect unsupported engine version: M114"); + return nullptr; + } + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + + NAPI_CALL(env, 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; + } + + bool AutoPreconnectEnabled = true; + if (!NapiParseUtils::ParseBoolean(env, argv[0], AutoPreconnectEnabled)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "enable", "boolean")); + return result; + } + + NWebHelper::Instance().SetAutoPreconnect(AutoPreconnectEnabled); + return result; +} + +napi_value NapiWebviewController::IsAutoPreconnectEnabled(napi_env env, napi_callback_info info) +{ + bool AutoPreconnectEnabled = true; + napi_value result = nullptr; + + if (IS_CALLING_FROM_M114()) { + WVLOG_W("IsPrivateNetworkAccessEnabled unsupported engine version: M114"); + NAPI_CALL(env, napi_get_boolean(env, AutoPreconnectEnabled, &result)); + return result; + } + + AutoPreconnectEnabled = NWebHelper::Instance().IsAutoPreconnectEnabled(); + NAPI_CALL(env, napi_get_boolean(env, AutoPreconnectEnabled, &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 7bb2fa100..8407033ef 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -417,6 +417,8 @@ private: static napi_value SetActiveWebEngineVersion(napi_env env, napi_callback_info info); static napi_value GetActiveWebEngineVersion(napi_env env, napi_callback_info info); static napi_value IsActiveWebEngineEvergreen(napi_env env, napi_callback_info info); + static napi_value SetAutoPreconnect(napi_env env, napi_callback_info info); + static napi_value IsAutoPreconnectEnabled(napi_env env, napi_callback_info info); }; class ArkWebTransfer { diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index 31cdcacb8..df6c1e699 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -155,6 +155,10 @@ public: void SetWebDestroyMode(WebDestroyMode mode); + void SetAutoPreconnect(bool enable); + + bool IsAutoPreconnectEnabled(); + private: NWebHelper() = default; bool GetWebEngine(bool fromArk); @@ -163,6 +167,7 @@ private: private: int coreApiLevel_ = 0; bool initFlag_ = false; + bool autopreconnectenabled_ = true; std::string bundlePath_; std::string customSchemeCmdLine_; std::shared_ptr nwebEngine_ = nullptr; diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index 53805e0a9..e91cdc18e 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -759,6 +759,8 @@ bool NWebHelper::InitWebEngine() WVLOG_D("apiTargetVersion: %{public}s", apiVersion.c_str()); } + initArgs->AddArg(std::string("--auto-preconnect=").append(std::to_string(autopreconnectenabled_))); + nwebEngine_->InitializeWebEngine(initArgs); initFlag_ = true; @@ -1213,6 +1215,8 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(sptr surface, return nullptr; } initArgs->AddArg(NWebConfigHelper::Instance().GetWebPlayGroundInitArg()); + initArgs->AddArg( + std::string("--auto-preconnect=").append(std::to_string(NWebHelper::Instance().IsAutoPreconnectEnabled()))); auto createInfo = NWebSurfaceAdapter::Instance().GetCreateInfo(surface, initArgs, width, height, incognitoMode); NWebConfigHelper::Instance().ParseConfig(initArgs); @@ -1248,6 +1252,8 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(void* enhanceSurfaceInfo, return nullptr; } initArgs->AddArg(NWebConfigHelper::Instance().GetWebPlayGroundInitArg()); + initArgs->AddArg( + std::string("--auto-preconnect=").append(std::to_string(NWebHelper::Instance().IsAutoPreconnectEnabled()))); auto createInfo = NWebEnhanceSurfaceAdapter::Instance().GetCreateInfo(enhanceSurfaceInfo, initArgs, width, height, incognitoMode); auto nweb = NWebHelper::Instance().CreateNWeb(createInfo); @@ -1355,4 +1361,14 @@ void NWebHelper::SetWebDestroyMode(WebDestroyMode mode) nwebEngine_->SetWebDestroyMode(mode); } +void NWebHelper::SetAutoPreconnect(bool enable) +{ + autopreconnectenabled_ = enable; +} + +bool NWebHelper::IsAutoPreconnectEnabled() +{ + return autopreconnectenabled_; +} + } // namespace OHOS::NWeb diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index 3aa3dff01..2e848317f 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -293,6 +293,7 @@ HWTEST_F(NwebHelperTest, NWebHelper_GetConfigPath_005, TestSize.Level1) NWebHelper::Instance().EnableBackForwardCache(true, true); NWebHelper::Instance().SetCustomSchemeCmdLine("single-process"); NWebHelper::Instance().SetBundlePath(INSTALLATION_DIR); + NWebHelper::Instance().SetAutoPreconnect(true); bool result = NWebHelper::Instance().InitAndRun(false); EXPECT_FALSE(result); NWebHelper::Instance().SetConnectionTimeout(1); @@ -960,5 +961,22 @@ HWTEST_F(NwebHelperTest, NWebHelper_IsPrivateNetworkAccessEnabled_001, TestSize. NWebHelper::Instance().IsPrivateNetworkAccessEnabled(); EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); } + +/** + * @tc.name: NWebHelper_SetAutoPreconnect_001 + * @tc.desc: SetAutoPreconnect.. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_SetAutoPreconnect_001, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + EXPECT_EQ(nwebHelper, nullptr); + + NWebHelper::Instance().SetAutoPreconnect(true); + NWebHelper::Instance().SetAutoPreconnect(false); + EXPECT_EQ(NWebHelper::Instance().autopreconnectenabled_, false); +} } // namespace OHOS::NWeb } -- Gitee From 4667551c7100083e1e2a3f12c19d1dc011d03d8c Mon Sep 17 00:00:00 2001 From: liuzhijie2 Date: Tue, 26 Aug 2025 19:05:16 +0800 Subject: [PATCH 062/124] disable autopreconnect Signed-off-by: liuzhijie2 --- .../napi_webview_controller.cpp | 14 +++++++------- ohos_nweb/include/nweb_helper.h | 2 +- ohos_nweb/src/nweb_helper.cpp | 18 +++++++++++------- .../nweb_helper_test/nweb_helper_ex_test.cpp | 3 ++- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 823241167..08386a466 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -7761,30 +7761,30 @@ napi_value NapiWebviewController::SetAutoPreconnect(napi_env env, napi_callback_ return result; } - bool AutoPreconnectEnabled = true; - if (!NapiParseUtils::ParseBoolean(env, argv[0], AutoPreconnectEnabled)) { + bool autoPreconnectEnabled = true; + if (!NapiParseUtils::ParseBoolean(env, argv[0], autoPreconnectEnabled)) { BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "enable", "boolean")); return result; } - NWebHelper::Instance().SetAutoPreconnect(AutoPreconnectEnabled); + NWebHelper::Instance().SetAutoPreconnect(autoPreconnectEnabled); return result; } napi_value NapiWebviewController::IsAutoPreconnectEnabled(napi_env env, napi_callback_info info) { - bool AutoPreconnectEnabled = true; + bool autoPreconnectEnabled = true; napi_value result = nullptr; if (IS_CALLING_FROM_M114()) { WVLOG_W("IsPrivateNetworkAccessEnabled unsupported engine version: M114"); - NAPI_CALL(env, napi_get_boolean(env, AutoPreconnectEnabled, &result)); + NAPI_CALL(env, napi_get_boolean(env, autoPreconnectEnabled, &result)); return result; } - AutoPreconnectEnabled = NWebHelper::Instance().IsAutoPreconnectEnabled(); - NAPI_CALL(env, napi_get_boolean(env, AutoPreconnectEnabled, &result)); + autoPreconnectEnabled = NWebHelper::Instance().IsAutoPreconnectEnabled(); + NAPI_CALL(env, napi_get_boolean(env, autoPreconnectEnabled, &result)); return result; } } // namespace NWeb diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index df6c1e699..7c3b58fce 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -167,7 +167,7 @@ private: private: int coreApiLevel_ = 0; bool initFlag_ = false; - bool autopreconnectenabled_ = true; + bool autoPreconnectEnabled_ = true; std::string bundlePath_; std::string customSchemeCmdLine_; std::shared_ptr nwebEngine_ = nullptr; diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index e91cdc18e..0f337f232 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -759,7 +759,9 @@ bool NWebHelper::InitWebEngine() WVLOG_D("apiTargetVersion: %{public}s", apiVersion.c_str()); } - initArgs->AddArg(std::string("--auto-preconnect=").append(std::to_string(autopreconnectenabled_))); + if (!autoPreconnectEnabled_) { + initArgs->AddArg(std::string("--disable-auto-preconnect")); + } nwebEngine_->InitializeWebEngine(initArgs); initFlag_ = true; @@ -1215,8 +1217,9 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(sptr surface, return nullptr; } initArgs->AddArg(NWebConfigHelper::Instance().GetWebPlayGroundInitArg()); - initArgs->AddArg( - std::string("--auto-preconnect=").append(std::to_string(NWebHelper::Instance().IsAutoPreconnectEnabled()))); + if (!NWebHelper::Instance().IsAutoPreconnectEnabled()) { + initArgs->AddArg(std::string("--disable-auto-preconnect")); + } auto createInfo = NWebSurfaceAdapter::Instance().GetCreateInfo(surface, initArgs, width, height, incognitoMode); NWebConfigHelper::Instance().ParseConfig(initArgs); @@ -1252,8 +1255,9 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(void* enhanceSurfaceInfo, return nullptr; } initArgs->AddArg(NWebConfigHelper::Instance().GetWebPlayGroundInitArg()); - initArgs->AddArg( - std::string("--auto-preconnect=").append(std::to_string(NWebHelper::Instance().IsAutoPreconnectEnabled()))); + if (!NWebHelper::Instance().IsAutoPreconnectEnabled()) { + initArgs->AddArg(std::string("--disable-auto-preconnect")); + } auto createInfo = NWebEnhanceSurfaceAdapter::Instance().GetCreateInfo(enhanceSurfaceInfo, initArgs, width, height, incognitoMode); auto nweb = NWebHelper::Instance().CreateNWeb(createInfo); @@ -1363,12 +1367,12 @@ void NWebHelper::SetWebDestroyMode(WebDestroyMode mode) void NWebHelper::SetAutoPreconnect(bool enable) { - autopreconnectenabled_ = enable; + autoPreconnectEnabled_ = enable; } bool NWebHelper::IsAutoPreconnectEnabled() { - return autopreconnectenabled_; + return autoPreconnectEnabled_; } } // namespace OHOS::NWeb diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index 2e848317f..0c07ff303 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -975,8 +975,9 @@ HWTEST_F(NwebHelperTest, NWebHelper_SetAutoPreconnect_001, TestSize.Level1) EXPECT_EQ(nwebHelper, nullptr); NWebHelper::Instance().SetAutoPreconnect(true); + EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, true); NWebHelper::Instance().SetAutoPreconnect(false); - EXPECT_EQ(NWebHelper::Instance().autopreconnectenabled_, false); + EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, false); } } // namespace OHOS::NWeb } -- Gitee From dd37d176b4019b92b78df6e81e7848e1eb32281a Mon Sep 17 00:00:00 2001 From: diao-gaoyang Date: Tue, 26 Aug 2025 20:29:19 +0800 Subject: [PATCH 063/124] prefetchv2 Signed-off-by: diao-gaoyang --- interfaces/kits/napi/BUILD.gn | 2 + .../common/napi_webview_native_module.cpp | 2 + .../napi_prefetch_options.cpp | 58 +++++++++ .../webviewcontroller/napi_prefetch_options.h | 38 ++++++ .../napi_webview_controller.cpp | 118 ++++++++++++------ .../napi_webview_controller.h | 4 +- .../webviewcontroller/webview_controller.cpp | 13 ++ .../webviewcontroller/webview_controller.h | 3 + ohos_interface/include/ohos_nweb/nweb.h | 20 +++ .../bridge/webcore/ark_web_nweb_impl.cpp | 8 ++ .../bridge/webcore/ark_web_nweb_impl.h | 13 +- .../bridge/webview/ark_web_nweb_wrapper.cpp | 15 +++ .../bridge/webview/ark_web_nweb_wrapper.h | 14 ++- .../ohos_nweb/include/ark_web_nweb.h | 14 ++- ohos_nweb/include/nweb_init_params.h | 33 +++++ 15 files changed, 311 insertions(+), 44 deletions(-) create mode 100644 interfaces/kits/napi/webviewcontroller/napi_prefetch_options.cpp create mode 100644 interfaces/kits/napi/webviewcontroller/napi_prefetch_options.h diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index b313b485e..bf882224f 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -67,6 +67,8 @@ ohos_shared_library("webview_napi") { "webstorage/napi_web_storage.cpp", "webviewcontroller/napi_back_forward_cache_options.cpp", "webviewcontroller/napi_back_forward_cache_options.h", + "webviewcontroller/napi_prefetch_options.cpp", + "webviewcontroller/napi_prefetch_options.h", "webviewcontroller/napi_native_media_player.cpp", "webviewcontroller/napi_native_media_player.h", "webviewcontroller/napi_web_download_delegate.cpp", diff --git a/interfaces/kits/napi/common/napi_webview_native_module.cpp b/interfaces/kits/napi/common/napi_webview_native_module.cpp index 84f9f8aa9..983514fb6 100644 --- a/interfaces/kits/napi/common/napi_webview_native_module.cpp +++ b/interfaces/kits/napi/common/napi_webview_native_module.cpp @@ -31,6 +31,7 @@ #include "napi_web_download_delegate.h" #include "napi_web_scheme_handler_request.h" #include "napi_back_forward_cache_options.h" +#include "napi_prefetch_options.h" #include "napi_proxy_controller.h" #include "napi_proxy_config.h" @@ -57,6 +58,7 @@ static napi_value WebViewExport(napi_env env, napi_value exports) WebFunctionInit(env, exports); NapiNativeMediaPlayerHandler::Init(env, exports); NapiBackForwardCacheOptions::Init(env, exports); + NapiWebPrefetchOptions::Init(env, exports); NapiBackForwardCacheSupportedFeatures::Init(env, exports); NapiProxyController::Init(env, exports); NapiProxyConfig::Init(env, exports); diff --git a/interfaces/kits/napi/webviewcontroller/napi_prefetch_options.cpp b/interfaces/kits/napi/webviewcontroller/napi_prefetch_options.cpp new file mode 100644 index 000000000..38c6678ed --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/napi_prefetch_options.cpp @@ -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. + */ + +#include "napi_prefetch_options.h" + +#include +#include +#include +#include + +#include "business_error.h" +#include "nweb_log.h" +#include "napi_parse_utils.h" +#include "napi/native_node_api.h" +#include "web_errors.h" + +using namespace OHOS::NWebError; + +namespace OHOS { +namespace NWeb { + +const std::string PREFETCH_OPTIONS = "PrefetchOptions"; + +napi_value NapiWebPrefetchOptions::JS_Constructor(napi_env env, napi_callback_info info) +{ + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data); + + return thisVar; +} + +napi_value NapiWebPrefetchOptions::Init(napi_env env, napi_value exports) +{ + WVLOG_D("NapiBackForwardCacheOptions::Init"); + napi_value prefetchOptions = nullptr; + napi_define_class(env, PREFETCH_OPTIONS.c_str(), + PREFETCH_OPTIONS.length(), + JS_Constructor, nullptr, 0, nullptr, &prefetchOptions); + napi_set_named_property(env, exports, PREFETCH_OPTIONS.c_str(), + prefetchOptions); + return exports; +} + +} +} \ No newline at end of file diff --git a/interfaces/kits/napi/webviewcontroller/napi_prefetch_options.h b/interfaces/kits/napi/webviewcontroller/napi_prefetch_options.h new file mode 100644 index 000000000..d61ea5912 --- /dev/null +++ b/interfaces/kits/napi/webviewcontroller/napi_prefetch_options.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 NWEB_NAPI_PREFETCH_OPTIONS_H +#define NWEB_NAPI_PREFETCH_OPTIONS_H + +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" + +namespace OHOS { +namespace NWeb { + +class NapiWebPrefetchOptions { +public: + NapiWebPrefetchOptions() = default; + ~NapiWebPrefetchOptions() = default; + + static napi_value Init(napi_env env, napi_value exports); + static napi_value JS_Constructor(napi_env env, napi_callback_info info); +}; + +} +} + +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index a28c44de3..323bf05d2 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -492,6 +492,57 @@ bool ParseRegisterJavaScriptProxyParam(napi_env env, size_t argc, napi_value* ar return true; } +std::map GetPrefetchPageWithHttpHeaders(napi_env env, napi_value array) +{ + std::map additionalHttpHeaders; + uint32_t arrayLength = INTEGER_ZERO; + napi_get_array_length(env, array, &arrayLength); + for (uint32_t i = 0; i < arrayLength; ++i) { + std::string key; + std::string value; + napi_value obj = nullptr; + napi_value keyObj = nullptr; + napi_value valueObj = nullptr; + napi_get_element(env, array, i, &obj); + if (napi_get_named_property(env, obj, "headerKey", &keyObj) != napi_ok) { + continue; + } + if (napi_get_named_property(env, obj, "headerValue", &valueObj) != napi_ok) { + continue; + } + NapiParseUtils::ParseString(env, keyObj, key); + NapiParseUtils::ParseString(env, valueObj, value); + additionalHttpHeaders[key] = value; + } + + return additionalHttpHeaders; +} + +std::shared_ptr GetPrefetchOptions(napi_env env, napi_value Options) +{ + napi_value minTimeBetweenPrefetchesMsObj = nullptr; + int32_t minTimeBetweenPrefetchesMs = 500; + napi_get_named_property(env, Options, "minTimeBetweenPrefetchesMs", &minTimeBetweenPrefetchesMsObj); + if (!NapiParseUtils::ParseInt32(env, minTimeBetweenPrefetchesMsObj, minTimeBetweenPrefetchesMs)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "minTimeBetweenPrefetches", "number")); + return nullptr; + } + + napi_value ignoreCacheControlNoStoreObj = nullptr; + bool ignoreCacheControlNoStore = false; + napi_get_named_property(env, Options, "ignoreCacheControlNoStore", &ignoreCacheControlNoStoreObj); + if (!NapiParseUtils::ParseBoolean(env, ignoreCacheControlNoStoreObj, ignoreCacheControlNoStore)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "ignoreCacheControlNoStore", "number")); + return nullptr; + } + + std::shared_ptr prefetchOptions = std::make_shared( + minTimeBetweenPrefetchesMs, ignoreCacheControlNoStore); + return prefetchOptions; +} + napi_value RemoveDownloadDelegateRef(napi_env env, napi_value thisVar) { WebviewController *webviewController = nullptr; @@ -4862,12 +4913,12 @@ napi_value NapiWebviewController::PrefetchPage(napi_env env, napi_callback_info { napi_value thisVar = nullptr; napi_value result = nullptr; - size_t argc = INTEGER_TWO; - napi_value argv[INTEGER_TWO]; + size_t argc = INTEGER_THREE; + napi_value argv[INTEGER_THREE]; napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); WebviewController *webviewController = nullptr; napi_status status = napi_unwrap(env, thisVar, (void **)&webviewController); - if ((argc != INTEGER_ONE) && (argc != INTEGER_TWO)) { + if ((argc != INTEGER_ONE) && (argc != INTEGER_TWO) && (argc != INTEGER_THREE)) { BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); return nullptr; } @@ -4881,53 +4932,42 @@ napi_value NapiWebviewController::PrefetchPage(napi_env env, napi_callback_info return nullptr; } std::map additionalHttpHeaders; - if (argc == INTEGER_ONE) { - ErrCode ret = webviewController->PrefetchPage(url, additionalHttpHeaders); - if (ret != NO_ERROR) { - WVLOG_E("PrefetchPage failed, error code: %{public}d", ret); - BusinessError::ThrowErrorByErrcode(env, ret); - return nullptr; - } - NAPI_CALL(env, napi_get_undefined(env, &result)); - return result; + if (argc != INTEGER_ONE) { + return PrefetchPageWithHttpHeadersAndPrefetchOptions(env, url, + argc, argv, webviewController); } - return PrefetchPageWithHttpHeaders(env, info, url, argv, webviewController); + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; } -napi_value NapiWebviewController::PrefetchPageWithHttpHeaders(napi_env env, napi_callback_info info, std::string& url, - const napi_value* argv, WebviewController* webviewController) +napi_value NapiWebviewController::PrefetchPageWithHttpHeadersAndPrefetchOptions(napi_env env, std::string& url, + size_t argc, const napi_value* argv, WebviewController* webviewController) { - napi_value result = nullptr; std::map additionalHttpHeaders; + napi_value result = nullptr; + napi_value array = argv[INTEGER_ONE]; + napi_value Options = argv[INTEGER_ONE]; bool isArray = false; napi_is_array(env, array, &isArray); if (isArray) { - uint32_t arrayLength = INTEGER_ZERO; - napi_get_array_length(env, array, &arrayLength); - for (uint32_t i = 0; i < arrayLength; ++i) { - std::string key; - std::string value; - napi_value obj = nullptr; - napi_value keyObj = nullptr; - napi_value valueObj = nullptr; - napi_get_element(env, array, i, &obj); - if (napi_get_named_property(env, obj, "headerKey", &keyObj) != napi_ok) { - continue; - } - if (napi_get_named_property(env, obj, "headerValue", &valueObj) != napi_ok) { - continue; + additionalHttpHeaders = GetPrefetchPageWithHttpHeaders(env, array); + if(argc == INTEGER_THREE){ + Options = argv[INTEGER_TWO]; + }else { + ErrCode ret = webviewController->PrefetchPage(url, additionalHttpHeaders); + if (ret != NO_ERROR) { + WVLOG_E("PrefetchPage failed, error code: %{public}d", ret); + BusinessError::ThrowErrorByErrcode(env, ret); + return nullptr; } - NapiParseUtils::ParseString(env, keyObj, key); - NapiParseUtils::ParseString(env, valueObj, value); - additionalHttpHeaders[key] = value; + NAPI_CALL(env, napi_get_undefined(env, &result)); + return result; } - } else { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR); - return nullptr; - } - - ErrCode ret = webviewController->PrefetchPage(url, additionalHttpHeaders); + } + + std::shared_ptr prefetchOptions = GetPrefetchOptions(env, Options); + ErrCode ret = webviewController->PrefetchPage(url, additionalHttpHeaders, prefetchOptions); if (ret != NO_ERROR) { WVLOG_E("PrefetchPage failed, error code: %{public}d", ret); BusinessError::ThrowErrorByErrcode(env, ret); diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h index 7bb2fa100..83ed7206a 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -255,8 +255,8 @@ private: static napi_value PrefetchPage(napi_env env, napi_callback_info info); - static napi_value PrefetchPageWithHttpHeaders(napi_env env, napi_callback_info info, std::string& url, - const napi_value* argv, WebviewController* webviewController); + static napi_value PrefetchPageWithHttpHeadersAndPrefetchOptions(napi_env env, std::string& url, + size_t argc, const napi_value* argv, WebviewController* webviewController); static napi_value PrepareForPageLoad(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 fc9182510..2f10b9611 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp @@ -1390,6 +1390,19 @@ ErrCode WebviewController::PrefetchPage(std::string& url, std::map additionalHttpHeaders, + std::shared_ptr prefetchOptions) +{ + auto nweb_ptr = NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return NWebError::INIT_ERROR; + } + + nweb_ptr->PrefetchPageV2(url, additionalHttpHeaders, + prefetchOptions->GetminTimeBetweenPrefetchesMs(), prefetchOptions->GetignoreCacheControlNoStore()); + return NWebError::NO_ERROR; +} + bool WebPrintAttributes::GetBool(uint32_t attrId) { switch (attrId) { diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.h b/interfaces/kits/napi/webviewcontroller/webview_controller.h index 5a5579c85..58a76cb02 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.h @@ -322,6 +322,9 @@ public: ErrCode PrefetchPage(std::string& url, std::map additionalHttpHeaders); + ErrCode PrefetchPage(std::string& url, std::map additionalHttpHeaders, + std::shared_ptr prefetchOptions); + void* CreateWebPrintDocumentAdapter(const std::string &jobName, int32_t& useAdapterV2); ErrCode PostUrl(std::string& url, std::vector& postData); diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 9325d5773..4f475364e 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -223,6 +223,14 @@ public: virtual std::string GetFormData() = 0; }; +class OHOS_NWEB_EXPORT NWebPrefetchOptions { +public: + virtual ~NWebPrefetchOptions() = default; + + virtual int32_t GetminTimeBetweenPrefetchesMs() = 0; + virtual bool GetignoreCacheControlNoStore() = 0; +}; + class OHOS_NWEB_EXPORT NWebPDFConfigArgs { public: virtual ~NWebPDFConfigArgs() = default; @@ -2119,6 +2127,18 @@ public: * @param height The height of the blankless frame. */ virtual void RecordBlanklessFrameSize(uint32_t width, uint32_t height) {} + + /** + * @brief Prefetch the resources required by the page, but will not execute js or + * render the page. + * @param url: String: Which url to preresolve/preconnect. + * @param additional_http_headers: Additional HTTP request header of the URL. + * @param minTimeBetweenPrefetchesMs: djusting the throttling interval. + * @param ignoreCacheControlNoStore: true if ignoring Cache-Control: no-store. + */ + virtual void PrefetchPageV2( + const std::string& url, const std::map& additionalHttpHeaders, + int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) {} }; } // 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 0c8c7e663..415a7c6b8 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 @@ -1585,4 +1585,12 @@ void ArkWebNWebImpl::RecordBlanklessFrameSize(uint32_t width, uint32_t height) { nweb_nweb_->RecordBlanklessFrameSize(width, height); } + +void ArkWebNWebImpl::PrefetchPageV2(const ArkWebString& url, const ArkWebStringMap& additional_http_headers, + int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) +{ + nweb_nweb_->PrefetchPageV2(ArkWebStringStructToClass(url), ArkWebStringMapStructToClass(additional_http_headers), + minTimeBetweenPrefetchesMs, ignoreCacheControlNoStore); +} + } // 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 e35959a9c..3903688e3 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 @@ -1788,7 +1788,18 @@ public: * @param height The height of the blankless frame. */ /*--ark web()--*/ - void RecordBlanklessFrameSize(uint32_t width, uint32_t height) override; + void RecordBlanklessFrameSize(uint32_t width, uint32_t height) override; + + /** + * @brief Prefetch the resources required by the page, but will not execute js or + * render the page. + * @param url: String: Which url to preresolve/preconnect. + * @param additional_http_headers: Additional HTTP request header of the URL. + * @param minTimeBetweenPrefetchesMs: djusting the throttling interval. + * @param ignoreCacheControlNoStore: true if ignoring Cache-Control: no-store. + */ + void PrefetchPageV2(const ArkWebString& url, const ArkWebStringMap& additional_http_headers, + int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) 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 e518f7e58..3dc9ce31c 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 @@ -1860,4 +1860,19 @@ void ArkWebNWebWrapper::RecordBlanklessFrameSize(uint32_t width, uint32_t height { ark_web_nweb_->RecordBlanklessFrameSize(width, height); } + +void ArkWebNWebWrapper::PrefetchPageV2( + const std::string& url, const std::map& additional_http_headers, + int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) +{ + ArkWebString stUrl = ArkWebStringClassToStruct(url); + ArkWebStringMap stHeaders = ArkWebStringMapClassToStruct(additional_http_headers); + + ark_web_nweb_->PrefetchPageV2(stUrl, stHeaders, + minTimeBetweenPrefetchesMs, ignoreCacheControlNoStore); + + ArkWebStringStructRelease(stUrl); + ArkWebStringMapStructRelease(stHeaders); +} + } // 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 68fad1918..aa8e5c1cf 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 @@ -1801,7 +1801,19 @@ public: * @param width The width of the blankless frame. * @param height The height of the blankless frame. */ - void RecordBlanklessFrameSize(uint32_t width, uint32_t height) override; + void RecordBlanklessFrameSize(uint32_t width, uint32_t height) override; + + /** + * @brief Prefetch the resources required by the page, but will not execute js or + * render the page. + * @param url: String: Which url to preresolve/preconnect. + * @param additional_http_headers: Additional HTTP request header of the URL. + * @param minTimeBetweenPrefetchesMs: djusting the throttling interval. + * @param ignoreCacheControlNoStore: true if ignoring Cache-Control: no-store. + */ + void PrefetchPageV2( + const std::string& url, const std::map& additional_http_headers, + int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) 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 35526fda5..cf314c03d 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 @@ -2033,7 +2033,19 @@ public: * @param height The height of the blankless frame. */ /*--ark web()--*/ - virtual void RecordBlanklessFrameSize(uint32_t width, uint32_t height) = 0; + virtual void RecordBlanklessFrameSize(uint32_t width, uint32_t height) = 0; + + /** + * @brief Prefetch the resources required by the page, but will not execute js or + * render the page. + * @param url: String: Which url to preresolve/preconnect. + * @param additional_http_headers: Additional HTTP request header of the URL. + * @param minTimeBetweenPrefetchesMs: djusting the throttling interval. + * @param ignoreCacheControlNoStore: true if ignoring Cache-Control: no-store. + */ + /*--ark web()--*/ + virtual void PrefetchPageV2(const ArkWebString& url, const ArkWebStringMap& additional_http_headers, + int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_nweb/include/nweb_init_params.h b/ohos_nweb/include/nweb_init_params.h index 4e8501562..a9d9ecd1c 100644 --- a/ohos_nweb/include/nweb_init_params.h +++ b/ohos_nweb/include/nweb_init_params.h @@ -275,6 +275,39 @@ private: std::string form_data_; }; +class NWebPrefetchOptionsImpl : public NWebPrefetchOptions { +public: + NWebPrefetchOptionsImpl(int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) + : minTimeBetweenPrefetchesMs_(minTimeBetweenPrefetchesMs), ignoreCacheControlNoStore_(ignoreCacheControlNoStore) + {} + + ~NWebPrefetchOptionsImpl() = default; + + void SetminTimeBetweenPrefetchesMs(int32_t minTimeBetweenPrefetchesMs) + { + minTimeBetweenPrefetchesMs_ = minTimeBetweenPrefetchesMs; + } + + int32_t GetminTimeBetweenPrefetchesMs() override + { + return minTimeBetweenPrefetchesMs_; + } + + void SetignoreCacheControlNoStore(bool ignoreCacheControlNoStore) + { + ignoreCacheControlNoStore_ = ignoreCacheControlNoStore; + } + + bool GetignoreCacheControlNoStore() override + { + return ignoreCacheControlNoStore_; + } + +private: + int32_t minTimeBetweenPrefetchesMs_ = 500; + bool ignoreCacheControlNoStore_ = false; +}; + class NWebPDFConfigArgsImpl : public NWebPDFConfigArgs { public: NWebPDFConfigArgsImpl(const double width, const double height, const double scale, const double marginTop, -- Gitee From 2c740b9c640a9fabf3b640ee20a3a49d4807bf65 Mon Sep 17 00:00:00 2001 From: diao-gaoyang Date: Tue, 26 Aug 2025 20:35:52 +0800 Subject: [PATCH 064/124] =?UTF-8?q?prefetchpage=E8=BF=BD=E5=8A=A0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: diao-gaoyang --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 323bf05d2..59c8acbef 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -4936,6 +4936,12 @@ napi_value NapiWebviewController::PrefetchPage(napi_env env, napi_callback_info return PrefetchPageWithHttpHeadersAndPrefetchOptions(env, url, argc, argv, webviewController); } + ErrCode ret = webviewController->PrefetchPage(url, additionalHttpHeaders); + if (ret != NO_ERROR) { + WVLOG_E("PrefetchPage failed, error code: %{public}d", ret); + BusinessError::ThrowErrorByErrcode(env, ret); + return nullptr; + } NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } -- Gitee From f7b06eb9f865b9cca1bfeb07924ce3df8ef6086c Mon Sep 17 00:00:00 2001 From: diao-gaoyang Date: Tue, 26 Aug 2025 22:12:15 +0800 Subject: [PATCH 065/124] =?UTF-8?q?prefetch=E5=A2=9E=E5=8A=A0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: diao-gaoyang --- .../napi/webviewcontroller/napi_webview_controller.cpp | 8 ++++---- .../ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 59c8acbef..be6bbf099 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -4951,16 +4951,16 @@ napi_value NapiWebviewController::PrefetchPageWithHttpHeadersAndPrefetchOptions( { std::map additionalHttpHeaders; napi_value result = nullptr; - napi_value array = argv[INTEGER_ONE]; napi_value Options = argv[INTEGER_ONE]; bool isArray = false; napi_is_array(env, array, &isArray); + if (isArray) { additionalHttpHeaders = GetPrefetchPageWithHttpHeaders(env, array); - if(argc == INTEGER_THREE){ + if (argc == INTEGER_THREE && !IS_CALLING_FROM_M114()) { Options = argv[INTEGER_TWO]; - }else { + } else { ErrCode ret = webviewController->PrefetchPage(url, additionalHttpHeaders); if (ret != NO_ERROR) { WVLOG_E("PrefetchPage failed, error code: %{public}d", ret); @@ -4970,7 +4970,7 @@ napi_value NapiWebviewController::PrefetchPageWithHttpHeadersAndPrefetchOptions( NAPI_CALL(env, napi_get_undefined(env, &result)); return result; } - } + } std::shared_ptr prefetchOptions = GetPrefetchOptions(env, Options); ErrCode ret = webviewController->PrefetchPage(url, additionalHttpHeaders, prefetchOptions); 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 3dc9ce31c..6d12edf9b 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 @@ -1868,8 +1868,12 @@ void ArkWebNWebWrapper::PrefetchPageV2( ArkWebString stUrl = ArkWebStringClassToStruct(url); ArkWebStringMap stHeaders = ArkWebStringMapClassToStruct(additional_http_headers); - ark_web_nweb_->PrefetchPageV2(stUrl, stHeaders, + ark_web_nweb_->PrefetchPageV2(stUrl, stHeaders, minTimeBetweenPrefetchesMs, ignoreCacheControlNoStore); + + if (ArkWebGetErrno() != RESULT_OK) { + ark_web_nweb_->PrefetchPage(stUrl, stHeaders); + } ArkWebStringStructRelease(stUrl); ArkWebStringMapStructRelease(stHeaders); -- Gitee From 40bc2da07717e63950bcb50f426e3bfe5bc59730 Mon Sep 17 00:00:00 2001 From: diao-gaoyang Date: Wed, 27 Aug 2025 09:42:46 +0800 Subject: [PATCH 066/124] =?UTF-8?q?prefetch=E8=BF=BD=E5=8A=A0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: diao-gaoyang --- .../ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp | 1 + 1 file changed, 1 insertion(+) 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 6d12edf9b..8aadd5e60 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 @@ -51,6 +51,7 @@ #include "ohos_nweb/cpptoc/ark_web_value_vector_cpptoc.h" #include "base/bridge/ark_web_bridge_macros.h" +#include "../../base/include/ark_web_errno.h" namespace OHOS::ArkWeb { -- Gitee From 96c3beb451e2f27d8b763eb8bf2efbab500ba6dc Mon Sep 17 00:00:00 2001 From: lizeqiang Date: Tue, 26 Aug 2025 22:13:54 +0800 Subject: [PATCH 067/124] fix dual core memberCheckFunc_ error Signed-off-by: lizeqiang --- .../ark_web_nweb_webview_bridge_helper.cpp | 11 +------ .../ark_web_nweb_webview_bridge_helper.h | 1 - ohos_nweb/include/nweb_helper.h | 1 - ohos_nweb/src/nweb_helper.cpp | 10 ------- .../nweb_helper_test/nweb_helper_ex_test.cpp | 19 ------------ .../nweb_helper_test/nweb_helper_test.cpp | 29 ------------------- 6 files changed, 1 insertion(+), 70 deletions(-) diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.cpp index ff5872812..80154b81b 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.cpp @@ -29,6 +29,7 @@ ArkWebNWebWebviewBridgeHelper::ArkWebNWebWebviewBridgeHelper() bool ArkWebNWebWebviewBridgeHelper::Init(bool runMode, const std::string& bundlePath) { + ARK_WEB_BRIDGE_INFO_LOG("init load resources bundle path %{public}s", bundlePath.c_str()); if (libFileHandler_) { ARK_WEB_BRIDGE_INFO_LOG("library resources have been loaded"); return true; @@ -68,16 +69,6 @@ void ArkWebNWebWebviewBridgeHelper::PreloadLibFile(bool runMode, const std::stri ArkWebBridgeHelper::PrereadLibFile(libFilePath); } -void ArkWebNWebWebviewBridgeHelper::PreDlopenLibFile(const std::string& bundlePath) -{ - if (libFileHandler_) { - ARK_WEB_BRIDGE_INFO_LOG("library resources have been loaded"); - return; - } - - libFileHandler_ = ArkWebBridgeHelperSharedInit(); -} - } // namespace OHOS::ArkWeb #ifdef __cplusplus diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.h index 39571cec0..3a316dad4 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.h @@ -31,7 +31,6 @@ public: static void PreloadLibFile(bool runMode, const std::string& bundlePath); - void PreDlopenLibFile(const std::string& bundlePath); private: ArkWebNWebWebviewBridgeHelper(); }; diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index df6c1e699..2ca7f1dd4 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -72,7 +72,6 @@ public: bool InitAndRun(bool from_ark = true); bool LoadWebEngine(bool fromArk, bool runFlag); void* LoadFuncSymbol(const char* funcName); - static void TryPreReadLib(bool isFirstTimeStartUpWeb, const std::string& bundlePath); std::shared_ptr CreateNWeb(std::shared_ptr create_info); std::shared_ptr GetCookieManager(); diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index e91cdc18e..4b61b279d 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -601,16 +601,6 @@ NWebHelper& NWebHelper::Instance() return helper; } -void NWebHelper::TryPreReadLib(bool isFirstTimeStartUpWeb, const std::string& bundlePath) -{ - if (isFirstTimeStartUpWeb) { - WVLOG_D("first time startup, need to wait until the nweb init stage"); - return; - } - - ArkWeb::ArkWebNWebWebviewBridgeHelper::GetInstance().PreDlopenLibFile(bundlePath); -} - bool NWebHelper::Init(bool from_ark) { return LoadWebEngine(from_ark, false); diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index 2e848317f..3ac96dc63 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -253,25 +253,6 @@ HWTEST_F(NwebHelperTest, NWebHelper_GetDataBase_003, TestSize.Level1) EXPECT_EQ(NWebHelper::Instance().GetDataBase(), nullptr); } -/** - * @tc.name: NWebHelper_TryPreReadLib_004 - * @tc.desc: TryPreReadLib. - * @tc.type: FUNC - * @tc.require: AR000GGHJ8 - */ -HWTEST_F(NwebHelperTest, NWebHelper_TryPreReadLib_004, TestSize.Level1) -{ - std::string hapPath = ""; - if (access(INSTALLATION_DIR.c_str(), F_OK) == 0) { - hapPath = INSTALLATION_DIR; - } - NWebHelper::Instance().TryPreReadLib(false, hapPath); - NWebHelper::Instance().TryPreReadLib(true, hapPath); - NWebHelper::Instance().SetBundlePath(INSTALLATION_DIR); - bool result = NWebAdapterHelper::Instance().Init(false); - EXPECT_FALSE(result); -} - /** * @tc.name: NWebHelper_GetConfigPath_005 * @tc.desc: GetConfigPath. diff --git a/test/unittest/nweb_helper_test/nweb_helper_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_test.cpp index 409cf0267..32e9f454f 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_test.cpp @@ -299,35 +299,6 @@ HWTEST_F(NwebHelperTest, NWebHelper_GetDataBase_003, TestSize.Level1) EXPECT_EQ(nweb, nullptr); } -/** - * @tc.name: NWebHelper_TryPreReadLib_004 - * @tc.desc: TryPreReadLib. - * @tc.type: FUNC - * @tc.require: AR000GGHJ8 - */ -HWTEST_F(NwebHelperTest, NWebHelper_TryPreReadLib_004, TestSize.Level1) -{ - std::string hapPath = ""; - if (access(MOCK_NWEB_INSTALLATION_DIR.c_str(), F_OK) == 0) { - hapPath = MOCK_NWEB_INSTALLATION_DIR; - } - NWebHelper::Instance().TryPreReadLib(false, hapPath); - NWebHelper::Instance().TryPreReadLib(true, hapPath); - bool result = NWebHelper::Instance().Init(false); - EXPECT_TRUE(result); - sptr surface = nullptr; - std::shared_ptr nweb = - NWebAdapterHelper::Instance().CreateNWeb(surface, GetInitArgs(), - DEFAULT_WIDTH, DEFAULT_HEIGHT); - EXPECT_EQ(nweb, nullptr); - nweb = NWebAdapterHelper::Instance().CreateNWeb(g_surface, GetInitArgs(), - DEFAULT_WIDTH, NWEB_MAX_WIDTH); - EXPECT_EQ(nweb, nullptr); - nweb = NWebAdapterHelper::Instance().CreateNWeb(g_surface, GetInitArgs(), - NWEB_MAX_WIDTH, DEFAULT_HEIGHT); - EXPECT_EQ(nweb, nullptr); -} - /** * @tc.name: NWebHelper_GetConfigPath_005 * @tc.desc: GetConfigPath. -- Gitee From 376189c294d9f18640edf55fe67af17b282b565a Mon Sep 17 00:00:00 2001 From: Fiatiustitia Date: Wed, 27 Aug 2025 15:19:23 +0800 Subject: [PATCH 068/124] =?UTF-8?q?=E5=87=8F=E5=B0=91=E5=86=97=E4=BD=99?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fiatiustitia --- .../src/imf_adapter_impl.cpp | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp index 4694cc238..0f2e9186e 100644 --- a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp +++ b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp @@ -286,30 +286,10 @@ void ReportImfErrorEvent(int32_t ret, bool isShowKeyboard) bool IMFAdapterImpl::Attach(std::shared_ptr listener, bool isShowKeyboard, const std::shared_ptr config, bool isResetListener) { - if (!listener) { - WVLOG_E("the listener is nullptr"); - ReportImfErrorEvent(IMF_LISTENER_NULL_POINT, isShowKeyboard); - return false; - } - if (!config || !(config->GetInputAttribute()) || !(config->GetCursorInfo())) { - WVLOG_E("the config is nullptr"); - ReportImfErrorEvent(IMF_TEXT_CONFIG_NULL_POINT, isShowKeyboard); + if (!AttachParamsCheck(listener, isShowKeyboard, config, isResetListener)) { return false; } - - if ((textListener_ != nullptr) && isResetListener) { - textListener_ = nullptr; - WVLOG_I("attach node is changed, need reset listener"); - } - - if (!textListener_) { - textListener_ = new (std::nothrow) IMFTextListenerAdapterImpl(listener); - if (!textListener_) { - WVLOG_E("new textListener failed"); - ReportImfErrorEvent(IMF_LISTENER_NULL_POINT, isShowKeyboard); - return false; - } - } + MiscServices::InputAttribute inputAttribute = { .inputPattern = config->GetInputAttribute()->GetInputPattern(), .enterKeyType = config->GetInputAttribute()->GetEnterKeyType(), .isTextPreviewSupported = true }; -- Gitee From 63a7a2843b63b31660224e00436ef3eaf8eb1ff6 Mon Sep 17 00:00:00 2001 From: Fiatiustitia Date: Wed, 27 Aug 2025 15:23:22 +0800 Subject: [PATCH 069/124] =?UTF-8?q?=E8=A7=84=E8=8C=83=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fiatiustitia --- ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp b/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp index efca141b1..dbdfb275c 100644 --- a/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp +++ b/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp @@ -158,7 +158,7 @@ void AafwkBrowserHostImpl::PassSurface(sptr surface, int64_t surface_id return; } if (!surfaceTmp) { - WVLOG_E("surface is nullptr"); + WVLOG_E("passSurface failed"); return; } surface_map_.emplace(surface_id, surfaceTmp); -- Gitee From 76a8fecfe0ce48da9d61e25bf61a91c14335976d Mon Sep 17 00:00:00 2001 From: pan-liujun Date: Tue, 26 Aug 2025 15:57:20 +0800 Subject: [PATCH 070/124] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E7=BC=A9=E6=94=BE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pan-liujun --- ohos_interface/include/ohos_nweb/nweb.h | 6 ++++++ .../ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp | 6 ++++++ .../ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.h | 6 ++++++ .../ohos_nweb/bridge/webview/ark_web_nweb_wrapper.cpp | 5 +++++ .../ohos_nweb/bridge/webview/ark_web_nweb_wrapper.h | 5 +++++ ohos_interface/ohos_glue/ohos_nweb/include/ark_web_nweb.h | 6 ++++++ 6 files changed, 34 insertions(+) diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 4f475364e..63a3f19f8 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -2139,6 +2139,12 @@ public: virtual void PrefetchPageV2( const std::string& url, const std::map& additionalHttpHeaders, int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) {} + + /** + * @brief Set web should ignore zoom limit. + */ + /*--ark web()--*/ + virtual void SetForceEnableZoom(bool forceEnableZoom) const {} }; } // 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 415a7c6b8..62180b83e 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 @@ -1593,4 +1593,10 @@ void ArkWebNWebImpl::PrefetchPageV2(const ArkWebString& url, const ArkWebStringM minTimeBetweenPrefetchesMs, ignoreCacheControlNoStore); } +void ArkWebNWebImpl::SetForceEnableZoom(bool forceEnableZoom) +{ + WVLOG_E("forceEnableZoom = %{public}d", forceEnableZoom); + nweb_nweb_->SetForceEnableZoom(forceEnableZoom); +} + } // 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 3903688e3..313f99ee5 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 @@ -1800,6 +1800,12 @@ public: */ void PrefetchPageV2(const ArkWebString& url, const ArkWebStringMap& additional_http_headers, int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) override; + + /** + * @brief Set web should ignore zoom limit. + */ + /*--ark web()--*/ + void SetForceEnableZoom(bool forceEnableZoom) 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 8aadd5e60..18e95b4b7 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 @@ -1880,4 +1880,9 @@ void ArkWebNWebWrapper::PrefetchPageV2( ArkWebStringMapStructRelease(stHeaders); } +void ArkWebNWebWrapper::SetForceEnableZoom(bool forceEnableZoom) const +{ + WVLOG_E("forceEnableZoom = %{public}d", forceEnableZoom); + ark_web_nweb_->SetForceEnableZoom(forceEnableZoom); +} } // 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 aa8e5c1cf..f73a70690 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 @@ -1814,6 +1814,11 @@ public: void PrefetchPageV2( const std::string& url, const std::map& additional_http_headers, int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) override; + + /** + * @brief Set web should ignore zoom limit. + */ + void SetForceEnableZoom(bool forceEnableZoom) const 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 cf314c03d..b57dbd943 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 @@ -2046,6 +2046,12 @@ public: /*--ark web()--*/ virtual void PrefetchPageV2(const ArkWebString& url, const ArkWebStringMap& additional_http_headers, int32_t minTimeBetweenPrefetchesMs, bool ignoreCacheControlNoStore) = 0; + + /** + * @brief Set web should ignore zoom limit. + */ + /*--ark web()--*/ + virtual void SetForceEnableZoom(bool forceEnableZoom) {} }; } // namespace OHOS::ArkWeb -- Gitee From 723f7377553ddee333cc26a459b4dc23405b24aa Mon Sep 17 00:00:00 2001 From: liuzhijie2 Date: Tue, 26 Aug 2025 19:05:16 +0800 Subject: [PATCH 071/124] disable autopreconnect Signed-off-by: liuzhijie2 --- .../napi_webview_controller.cpp | 16 ++++++++-------- ohos_nweb/include/nweb_helper.h | 2 +- ohos_nweb/src/nweb_helper.cpp | 18 +++++++++++------- .../nweb_helper_test/nweb_helper_ex_test.cpp | 3 ++- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 823241167..ee3b8ce24 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -7761,30 +7761,30 @@ napi_value NapiWebviewController::SetAutoPreconnect(napi_env env, napi_callback_ return result; } - bool AutoPreconnectEnabled = true; - if (!NapiParseUtils::ParseBoolean(env, argv[0], AutoPreconnectEnabled)) { + bool autoPreconnectEnabled = true; + if (!NapiParseUtils::ParseBoolean(env, argv[0], autoPreconnectEnabled)) { BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "enable", "boolean")); return result; } - NWebHelper::Instance().SetAutoPreconnect(AutoPreconnectEnabled); + NWebHelper::Instance().SetAutoPreconnect(autoPreconnectEnabled); return result; } napi_value NapiWebviewController::IsAutoPreconnectEnabled(napi_env env, napi_callback_info info) { - bool AutoPreconnectEnabled = true; + bool autoPreconnectEnabled = true; napi_value result = nullptr; if (IS_CALLING_FROM_M114()) { - WVLOG_W("IsPrivateNetworkAccessEnabled unsupported engine version: M114"); - NAPI_CALL(env, napi_get_boolean(env, AutoPreconnectEnabled, &result)); + WVLOG_W("IsAutoPreconnectEnabled unsupported engine version: M114"); + NAPI_CALL(env, napi_get_boolean(env, autoPreconnectEnabled, &result)); return result; } - AutoPreconnectEnabled = NWebHelper::Instance().IsAutoPreconnectEnabled(); - NAPI_CALL(env, napi_get_boolean(env, AutoPreconnectEnabled, &result)); + autoPreconnectEnabled = NWebHelper::Instance().IsAutoPreconnectEnabled(); + NAPI_CALL(env, napi_get_boolean(env, autoPreconnectEnabled, &result)); return result; } } // namespace NWeb diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index df6c1e699..7c3b58fce 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -167,7 +167,7 @@ private: private: int coreApiLevel_ = 0; bool initFlag_ = false; - bool autopreconnectenabled_ = true; + bool autoPreconnectEnabled_ = true; std::string bundlePath_; std::string customSchemeCmdLine_; std::shared_ptr nwebEngine_ = nullptr; diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index e91cdc18e..0f337f232 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -759,7 +759,9 @@ bool NWebHelper::InitWebEngine() WVLOG_D("apiTargetVersion: %{public}s", apiVersion.c_str()); } - initArgs->AddArg(std::string("--auto-preconnect=").append(std::to_string(autopreconnectenabled_))); + if (!autoPreconnectEnabled_) { + initArgs->AddArg(std::string("--disable-auto-preconnect")); + } nwebEngine_->InitializeWebEngine(initArgs); initFlag_ = true; @@ -1215,8 +1217,9 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(sptr surface, return nullptr; } initArgs->AddArg(NWebConfigHelper::Instance().GetWebPlayGroundInitArg()); - initArgs->AddArg( - std::string("--auto-preconnect=").append(std::to_string(NWebHelper::Instance().IsAutoPreconnectEnabled()))); + if (!NWebHelper::Instance().IsAutoPreconnectEnabled()) { + initArgs->AddArg(std::string("--disable-auto-preconnect")); + } auto createInfo = NWebSurfaceAdapter::Instance().GetCreateInfo(surface, initArgs, width, height, incognitoMode); NWebConfigHelper::Instance().ParseConfig(initArgs); @@ -1252,8 +1255,9 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(void* enhanceSurfaceInfo, return nullptr; } initArgs->AddArg(NWebConfigHelper::Instance().GetWebPlayGroundInitArg()); - initArgs->AddArg( - std::string("--auto-preconnect=").append(std::to_string(NWebHelper::Instance().IsAutoPreconnectEnabled()))); + if (!NWebHelper::Instance().IsAutoPreconnectEnabled()) { + initArgs->AddArg(std::string("--disable-auto-preconnect")); + } auto createInfo = NWebEnhanceSurfaceAdapter::Instance().GetCreateInfo(enhanceSurfaceInfo, initArgs, width, height, incognitoMode); auto nweb = NWebHelper::Instance().CreateNWeb(createInfo); @@ -1363,12 +1367,12 @@ void NWebHelper::SetWebDestroyMode(WebDestroyMode mode) void NWebHelper::SetAutoPreconnect(bool enable) { - autopreconnectenabled_ = enable; + autoPreconnectEnabled_ = enable; } bool NWebHelper::IsAutoPreconnectEnabled() { - return autopreconnectenabled_; + return autoPreconnectEnabled_; } } // namespace OHOS::NWeb diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index 2e848317f..0c07ff303 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -975,8 +975,9 @@ HWTEST_F(NwebHelperTest, NWebHelper_SetAutoPreconnect_001, TestSize.Level1) EXPECT_EQ(nwebHelper, nullptr); NWebHelper::Instance().SetAutoPreconnect(true); + EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, true); NWebHelper::Instance().SetAutoPreconnect(false); - EXPECT_EQ(NWebHelper::Instance().autopreconnectenabled_, false); + EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, false); } } // namespace OHOS::NWeb } -- Gitee From 5f810d1a174c29014eb04c4ea459cdbee8e5e2a3 Mon Sep 17 00:00:00 2001 From: sunbin55 Date: Thu, 28 Aug 2025 10:41:16 +0800 Subject: [PATCH 072/124] =?UTF-8?q?IssueNo:#ICV63C:[Bug]:=20=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E6=94=AF=E8=A6=86=E7=9B=96=E7=8E=87?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E3=80=82=20Description:=20=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=88=86=E6=94=AF=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90?= =?UTF-8?q?=E5=8D=87=20Sig:=20SIG=5FApplicationFramework=20Feature=20or=20?= =?UTF-8?q?Bugfix:=20(Bugfix)=20Binary=20Source:=20No=20=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=B6=89=E5=8F=8A=E9=9D=9E=E5=85=BC=E5=AE=B9=E5=8F=98=E6=9B=B4?= =?UTF-8?q?:=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20TDD=E8=87=AA=E9=AA=8C?= =?UTF-8?q?=E7=BB=93=E6=9E=9C(=E5=A6=82=E6=9C=89=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90=E4=BE=9B=E5=9F=BA=E7=BA=BF?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5):=20(=E4=B8=8D=E6=B6=89?= =?UTF-8?q?=E5=8F=8A)=20XTS=E8=87=AA=E9=AA=8C=E7=BB=93=E6=9E=9C(=E5=A6=82?= =?UTF-8?q?=E6=9C=89=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E5=9F=BA=E7=BA=BF=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5?= =?UTF-8?q?):=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20Signed-off-by:=20sunbin55?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drawing_text_adapter_test.cpp | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/test/unittest/ohos_adapter/drawing_text_adapter_test/drawing_text_adapter_test.cpp b/test/unittest/ohos_adapter/drawing_text_adapter_test/drawing_text_adapter_test.cpp index 545c3ed74..99b52e718 100644 --- a/test/unittest/ohos_adapter/drawing_text_adapter_test/drawing_text_adapter_test.cpp +++ b/test/unittest/ohos_adapter/drawing_text_adapter_test/drawing_text_adapter_test.cpp @@ -257,5 +257,78 @@ HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_011, TestSize.Le auto& instance2 = drawingTextFontAdapter->GetInstance(); EXPECT_EQ(&instance1, &instance2); } + +/** +* @tc.name : DrawingTextAdapterImplTest_012 +* @tc.number: Test GetSystemFontFullNamesByType function when drawingArray is nullptr +* @tc.desc : FUNC +*/ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_012, TestSize.Level1) +{ + std::shared_ptr drawingTextFontAdapter = + std::make_shared(); + ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; + void** drawingArray = nullptr; + int32_t errorCode = drawingTextFontAdapter->GetSystemFontFullNamesByType( + systemFontType, drawingArray); + EXPECT_EQ(errorCode, NWEB_ERROR); +} + +/** + * @tc.name: DrawingTextAdapterImplTest_013. + * @tc.desc: test GetFontDescriptorByFullName when drawingFontDescriptor is nullptr + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_013, TestSize.Level1) +{ + std::shared_ptr drawingTextFontAdapter = + std::make_shared(); + EXPECT_TRUE(drawingTextFontAdapter != nullptr); + + void* drawingString = nullptr; + ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; + void** drawingFontDescriptor = nullptr; + int32_t errorCode = drawingTextFontAdapter->GetFontDescriptorByFullName( + drawingString, systemFontType, drawingFontDescriptor); + EXPECT_EQ(errorCode, NWEB_ERROR); +} + +/* + * @tc.name: DrawingTextAdapterImplTest_014. + * @tc.desc: test GetSystemFontFullNameByIndex when drawingString is nullptr + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_014, TestSize.Level1) +{ + std::shared_ptr drawingTextFontAdapter = + std::make_shared(); + + void* drawingArray = nullptr; + int32_t indexOfFullName = 0; + const void** drawingString = nullptr; + int32_t errorCode = drawingTextFontAdapter->GetSystemFontFullNameByIndex( + drawingArray, indexOfFullName, drawingString); + EXPECT_EQ(errorCode, NWEB_ERROR); +} + +/** + * @tc.name: DrawingTextAdapterImplTest_015. + * @tc.desc: test GetSystemFontConfigInfo when fontConfigInfo is nullptr. + * @tc.type: FUNC. + * @tc.require: + */ +HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_015, TestSize.Level1) +{ + std::shared_ptr drawingTextTypographyAdapter = + std::make_shared(); + + void* fontConfigInfoErrorCode = nullptr; + void** fontConfigInfo = nullptr; + int32_t errorCode = drawingTextTypographyAdapter->GetSystemFontConfigInfo( + fontConfigInfoErrorCode,fontConfigInfo); + EXPECT_EQ(errorCode, NWEB_ERROR); +} } // namespace NWeb } // namespace OHOS \ No newline at end of file -- Gitee From 61e56275ed8f36f695d68fde59957830d43f875e Mon Sep 17 00:00:00 2001 From: duanshaofei Date: Thu, 28 Aug 2025 10:37:52 +0800 Subject: [PATCH 073/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E6=A0=B8?= =?UTF-8?q?=E6=89=8B=E6=9F=84=E7=83=AD=E5=8C=BA=E5=92=8CArkUI=E7=83=AD?= =?UTF-8?q?=E5=8C=BA=E6=89=8B=E6=9F=84=E5=B7=AE=E5=BC=82=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: duanshaofei --- ohos_interface/include/ohos_nweb/nweb_handler.h | 5 +++++ .../ohos_nweb/bridge/webcore/ark_web_handler_wrapper.cpp | 5 +++++ .../ohos_nweb/bridge/webcore/ark_web_handler_wrapper.h | 5 +++++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.cpp | 5 +++++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.h | 5 +++++ .../ohos_glue/ohos_nweb/include/ark_web_handler.h | 6 ++++++ 6 files changed, 31 insertions(+) diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index 298a891c2..3c73e0496 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -1273,6 +1273,11 @@ public: * */ virtual void SetImeShow(bool visible) {} + + /** + * @brief Called when you click on caret. + */ + virtual bool IsShowHandle() { return false; } }; } // 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 71902712c..328c4a512 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 @@ -1276,4 +1276,9 @@ void ArkWebHandlerWrapper::SetImeShow(bool visible) { ark_web_handler_->SetImeShow(visible); } + +bool ArkWebHandlerWrapper::IsShowHandle() +{ + return ark_web_handler_->IsShowHandle(); +} } // 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 cc3d5a30e..fce768ece 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 @@ -754,6 +754,11 @@ public: * */ void SetImeShow(bool visible) override; + + /** + * @brief Called when you click on caret. + */ + virtual bool IsShowHandle() 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 ddc843da5..f16438bb3 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 @@ -1112,4 +1112,9 @@ void ArkWebHandlerImpl::SetImeShow(bool visible) { nweb_handler_->SetImeShow(visible); } + +bool ArkWebHandlerImpl::IsShowHandle() +{ + return nweb_handler_->IsShowHandle(); +} } // 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 c97cc8eb6..be1c1fbfd 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 @@ -717,6 +717,11 @@ public: * */ void SetImeShow(bool visible) override; + + /** + * @brief Called when you click on caret. + */ + virtual bool IsShowHandle() 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 bf6c08bde..847557c6a 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 @@ -1046,6 +1046,12 @@ public: */ /*--ark web()--*/ virtual void SetImeShow(bool visible) = 0; + + /** + * @brief Called when you click on caret. + */ + /*--ark web()--*/ + virtual bool IsShowHandle() { return false; } }; } // namespace OHOS::ArkWeb -- Gitee From eb51e88056d6ccaeb076e7cbd699dc55ba3f55d8 Mon Sep 17 00:00:00 2001 From: lijiancheng21 Date: Thu, 28 Aug 2025 16:29:40 +0800 Subject: [PATCH 074/124] add webview ut for initialCongestionWindowSize Signed-off-by: lijiancheng21 --- .../system_properties_adapter_test.cpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/unittest/ohos_adapter/system_properties_adapter/system_properties_adapter_test.cpp b/test/unittest/ohos_adapter/system_properties_adapter/system_properties_adapter_test.cpp index ef2bb00f9..40d5340fd 100644 --- a/test/unittest/ohos_adapter/system_properties_adapter/system_properties_adapter_test.cpp +++ b/test/unittest/ohos_adapter/system_properties_adapter/system_properties_adapter_test.cpp @@ -260,4 +260,38 @@ HWTEST_F(SystemPropertiesAdapterTest, SystemPropertiesAdapterTest_GetPRPPreloadM value = SystemPropertiesAdapterImpl::GetInstance().GetPRPPreloadMode(); EXPECT_EQ(value, "preload"); } + +/** + * @tc.name: SystemPropertiesAdapterTest_GetInitialCongestionWindowSize_001 + * @tc.desc: GetInstance unittest. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SystemPropertiesAdapterTest, SystemPropertiesAdapterTest_GetInitialCongestionWindowSize_001, TestSize.Level1) +{ + NWebConfigHelper::Instance().perfConfig_.emplace("TCPConnectedSocketConfig/initialCongestionWindowSize", "invalid"); + auto value = SystemPropertiesAdapterImpl::GetInstance().GetInitialCongestionWindowSize(); + EXPECT_EQ(value, -1); + NWebConfigHelper::Instance().perfConfig_.clear(); + + NWebConfigHelper::Instance().perfConfig_.emplace("TCPConnectedSocketConfig/initialCongestionWindowSize", ""); + value = SystemPropertiesAdapterImpl::GetInstance().GetInitialCongestionWindowSize(); + EXPECT_EQ(value, -1); + NWebConfigHelper::Instance().perfConfig_.clear(); + + NWebConfigHelper::Instance().perfConfig_.emplace("TCPConnectedSocketConfig/initialCongestionWindowSize", "-1"); + value = SystemPropertiesAdapterImpl::GetInstance().GetInitialCongestionWindowSize(); + EXPECT_EQ(value, -1); + NWebConfigHelper::Instance().perfConfig_.clear(); + + NWebConfigHelper::Instance().perfConfig_.emplace("TCPConnectedSocketConfig/initialCongestionWindowSize", "0"); + value = SystemPropertiesAdapterImpl::GetInstance().GetInitialCongestionWindowSize(); + EXPECT_EQ(value, 0); + NWebConfigHelper::Instance().perfConfig_.clear(); + + NWebConfigHelper::Instance().perfConfig_.emplace("TCPConnectedSocketConfig/initialCongestionWindowSize", "150"); + value = SystemPropertiesAdapterImpl::GetInstance().GetInitialCongestionWindowSize(); + EXPECT_EQ(value, 150); + NWebConfigHelper::Instance().perfConfig_.clear(); +} } // namespace OHOS -- Gitee From c80c7f58e09d2d360ab356ad0982455f7a857c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=83=B3?= Date: Thu, 28 Aug 2025 20:17:10 +0800 Subject: [PATCH 075/124] supply for imeshow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李想 --- .../src/imf_adapter_impl.cpp | 10 ++++++---- .../imf_adapter_test/imf_adapter_impl_test.cpp | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp index 0f2e9186e..5362d46c3 100644 --- a/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp +++ b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp @@ -513,10 +513,12 @@ void IMFTextListenerAdapterImpl::NotifyPanelStatusInfo(const MiscServices::Panel { WVLOG_I("IMFTextListenerAdapterImpl::NotifyPanelStatusInfo, visible:%{public}d", info.visible); MiscServices::Trigger triggerFrom = info.trigger; - if (listener_ && (triggerFrom == MiscServices::Trigger::IME_APP)) { - WVLOG_I("IMFTextListenerAdapterImpl::NotifyPanelStatusInfo, info.IME_APP"); - listener_->KeyboardUpperRightCornerHide(); + if (listener_) { + listener_->WebSetImeShow(info.visible); + if (triggerFrom == MiscServices::Trigger::IME_APP) { + WVLOG_I("IMFTextListenerAdapterImpl::NotifyPanelStatusInfo, info.IME_APP"); + listener_->KeyboardUpperRightCornerHide(); + } } - listener_->WebSetImeShow(info.visible); } } // 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 759408ff1..33e2c4e4c 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 @@ -239,13 +239,18 @@ public: WVLOG_I("test KeyboardUpperRightCornerHide"); isKeyboardUpperRightCornerHide_ = true; } + void WebSetImeShow(bool visible) override + { + WVLOG_I("test WebSetImeShow"); + isWebSetImeShow_ = true; + } bool VerifyAllSuccess() { return isInsertText_ && isDeleteForward_ && isDeleteBackward_ && isSendKeyEventFromInputMethod_ && isSendKeyboardStatus_ && isSendFunctionKey_ && isSetKeyboardStatus_ && isMoveCursor_ && isHandleSetSelection_ && isHandleExtendAction_ && isHandleSelect_ && isGetTextIndexAtCursor_ && isGetLeftTextOfCursor_ && isGetRightTextOfCursor_ && isSetPreviewText_ && isFinishTextPreview_ && - isSetNeedUnderLine_ && isKeyboardUpperRightCornerHide_; + isSetNeedUnderLine_ && isKeyboardUpperRightCornerHide_ && isWebSetImeShow_; } bool VerifyFunctionKeySuccess() { @@ -270,6 +275,7 @@ private: bool isFinishTextPreview_ = false; bool isSetNeedUnderLine_ = false; bool isKeyboardUpperRightCornerHide_ = false; + bool isWebSetImeShow_ = false; }; void NWebIMFAdapterTest::SetUpTestCase(void) -- Gitee From 4aab2c35e0011343a7f8ab233ba90bbcec0a9a54 Mon Sep 17 00:00:00 2001 From: liuao Date: Sat, 30 Aug 2025 12:39:31 +0800 Subject: [PATCH 076/124] 0830 update ArkWebCore.hap to 6.0 Signed-off-by: liuao --- ohos_nweb/prebuilts/arm/ArkWebCore.hap | 4 ++-- ohos_nweb/prebuilts/arm64/ArkWebCore.hap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_nweb/prebuilts/arm/ArkWebCore.hap b/ohos_nweb/prebuilts/arm/ArkWebCore.hap index 8bd124ff1..136f74a3e 100644 --- a/ohos_nweb/prebuilts/arm/ArkWebCore.hap +++ b/ohos_nweb/prebuilts/arm/ArkWebCore.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0b088fe0dfb81c08c2b27e318416cc6c250fb9ab63b647d714ffbd65298a6904 -size 116626921 +oid sha256:7a2c94d016bffbcca431a73355ac74decb536d39347b39ab4a050aec326e9faf +size 116692452 diff --git a/ohos_nweb/prebuilts/arm64/ArkWebCore.hap b/ohos_nweb/prebuilts/arm64/ArkWebCore.hap index 0132578f6..c4ad995fc 100644 --- a/ohos_nweb/prebuilts/arm64/ArkWebCore.hap +++ b/ohos_nweb/prebuilts/arm64/ArkWebCore.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f50c7ea796bff684287a9d57388c4a12408408938e440c99960327f186aaf74b -size 122447302 +oid sha256:c826657314ac97b1268c206bc5c9626fac4f7e1f0bbcef95e5f276bd50273f91 +size 122521025 -- Gitee From 5885513a310f76df30d1cff5f528f7d026c4c1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=89=E4=B8=9C?= Date: Mon, 1 Sep 2025 03:34:10 +0000 Subject: [PATCH 077/124] =?UTF-8?q?=E5=A4=9A=E7=BA=BF=E7=A8=8B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=AB=9E=E4=BA=89=E9=A3=8E=E9=99=A9=E3=80=81=E7=A9=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张吉东 --- .../include/location_proxy_adapter_impl.h | 2 ++ .../src/location_callback_adapter_impl.cpp | 6 +++++- .../src/location_proxy_adapter_impl.cpp | 17 +++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h b/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h index 34d22518a..12ae57156 100755 --- a/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h +++ b/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h @@ -17,6 +17,7 @@ #define LOCATION_PROXY_ADAPTER_IMPL_H #include +#include #if defined(NWEB_LOCATION_ENABLE) #include "i_locator_callback.h" @@ -100,6 +101,7 @@ private: static StartLocatingFuncType startLocatingFunc_; static StopLocatingFuncType stopLocatingFunc_; LocatorCallbackMap reg_; + std::mutex count_mutex_; #endif }; } diff --git a/ohos_adapter/location_adapter/src/location_callback_adapter_impl.cpp b/ohos_adapter/location_adapter/src/location_callback_adapter_impl.cpp index c30c042ce..8c5d112f7 100755 --- a/ohos_adapter/location_adapter/src/location_callback_adapter_impl.cpp +++ b/ohos_adapter/location_adapter/src/location_callback_adapter_impl.cpp @@ -55,7 +55,7 @@ int LocationCallbackImpl::OnRemoteRequest(uint32_t code, } default: { WVLOG_E("locationCallback receive error code:%{public}u", code); - break; + return -1; } } return 0; @@ -64,6 +64,10 @@ int LocationCallbackImpl::OnRemoteRequest(uint32_t code, void LocationCallbackImpl::OnLocationReport( const std::unique_ptr& location) { + if (location == nullptr) { + WVLOG_E("OnLocationReport location is nullptr"); + return; + } std::unique_ptr tempLocation = std::make_unique(*location); std::shared_ptr locationInfo = diff --git a/ohos_adapter/location_adapter/src/location_proxy_adapter_impl.cpp b/ohos_adapter/location_adapter/src/location_proxy_adapter_impl.cpp index a7ee1fe93..cedb9284d 100755 --- a/ohos_adapter/location_adapter/src/location_proxy_adapter_impl.cpp +++ b/ohos_adapter/location_adapter/src/location_proxy_adapter_impl.cpp @@ -25,7 +25,7 @@ using namespace OHOS::Location; namespace { -#if defined (__aarch64__) || defined(__x86_64__) +#if defined (__aarch64__) || defined (__x86_64__) const std::string NWEB_WRAPPER_SO_PATH = "/system/lib64/libnweb_ohos_wrapper.z.so"; const std::string ARKWEB_WRAPPER_SO_PATH = "/system/lib64/libarkweb_os_wrapper.z.so"; #else @@ -34,7 +34,7 @@ const std::string ARKWEB_WRAPPER_SO_PATH = "/system/lib/libarkweb_os_wrapper.z.s #endif int32_t ConvertScenario(int32_t scenario) { - int32_t ret = OHOS::NWeb::LocationRequestConfig::Scenario::UNSET; + int32_t ret = OHOS::Location::SCENE_UNSET; switch (scenario) { case OHOS::NWeb::LocationRequestConfig::Scenario::UNSET: ret = OHOS::Location::SCENE_UNSET; @@ -55,6 +55,7 @@ int32_t ConvertScenario(int32_t scenario) ret = OHOS::Location::SCENE_NO_POWER; break; default: + ret = OHOS::Location::SCENE_UNSET; break; } return ret; @@ -62,7 +63,7 @@ int32_t ConvertScenario(int32_t scenario) int32_t ConvertPriority(int32_t priority) { - int32_t ret = OHOS::NWeb::LocationRequestConfig::Priority::PRIORITY_UNSET; + int32_t ret = OHOS::Location::PRIORITY_UNSET; switch (priority) { case OHOS::NWeb::LocationRequestConfig::Priority::PRIORITY_UNSET: ret = OHOS::Location::PRIORITY_UNSET; @@ -77,6 +78,7 @@ int32_t ConvertPriority(int32_t priority) ret = OHOS::Location::PRIORITY_FAST_FIRST_FIX; break; default: + ret = OHOS::Location::PRIORITY_UNSET; break; } return ret; @@ -277,9 +279,12 @@ int32_t LocationProxyAdapterImpl::StartLocating( return id; } - id = count++; - if (count < 0) { - count = 0; + { + std::lock_guard lock(count_mutex_); + id = count++; + if (count < 0) { + count = 0; + } } reg_.emplace(std::make_pair(id, iCallback)); return id; -- Gitee From 6385aa575eb36122d93d99285464871d69f6e0a5 Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Mon, 1 Sep 2025 18:24:44 +0800 Subject: [PATCH 078/124] site isolation Signed-off-by: quyue00807312 --- .../napi_webview_controller.cpp | 79 +++++++++++++++++++ .../napi_webview_controller.h | 5 ++ ohos_interface/include/ohos_nweb/nweb.h | 5 ++ .../include/ohos_nweb/nweb_engine.h | 4 + .../bridge/webcore/ark_web_engine_impl.cpp | 12 +++ .../bridge/webcore/ark_web_engine_impl.h | 4 + .../bridge/webview/ark_web_engine_wrapper.cpp | 11 +++ .../bridge/webview/ark_web_engine_wrapper.h | 6 ++ .../ohos_nweb/include/ark_web_engine.h | 6 ++ ohos_nweb/include/nweb_helper.h | 4 + ohos_nweb/src/nweb_helper.cpp | 20 +++++ 11 files changed, 156 insertions(+) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index c0430ec1d..a346fe385 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -775,6 +775,8 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_FUNCTION("clearPrefetchedResource", NapiWebviewController::ClearPrefetchedResource), DECLARE_NAPI_STATIC_FUNCTION("setRenderProcessMode", NapiWebviewController::SetRenderProcessMode), DECLARE_NAPI_STATIC_FUNCTION("getRenderProcessMode", NapiWebviewController::GetRenderProcessMode), + DECLARE_NAPI_STATIC_FUNCTION("setSiteIsolationMode", NapiWebviewController::SetSiteIsolationMode), + DECLARE_NAPI_STATIC_FUNCTION("getSiteIsolationMode", NapiWebviewController::GetSiteIsolationMode), DECLARE_NAPI_FUNCTION("precompileJavaScript", NapiWebviewController::PrecompileJavaScript), DECLARE_NAPI_FUNCTION("injectOfflineResources", NapiWebviewController::InjectOfflineResources), DECLARE_NAPI_STATIC_FUNCTION("setHostIP", NapiWebviewController::SetHostIP), @@ -1092,6 +1094,18 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) &webDestroyModeEnum); napi_set_named_property(env, exports, WEB_DESTROY_MODE_ENUM_NAME.c_str(), webDestroyModeEnum); + napi_value siteIsolationModeEnum = nullptr; + napi_property_descriptor siteIsolationModeProperties[] = { + DECLARE_NAPI_STATIC_PROPERTY("PARTIAL", NapiParseUtils::ToInt32Value(env, + static_cast(SiteIsolationMode::PARTIAL))), + DECLARE_NAPI_STATIC_PROPERTY("STRICT", NapiParseUtils::ToInt32Value(env, + static_cast(SiteIsolationMode::STRICT))), + }; + napi_define_class(env, WEB_SITE_ISOLATION_MODE_ENUM_NAME.c_str(), WEB_SITE_ISOLATION_MODE_ENUM_NAME.length(), + NapiParseUtils::CreateEnumConstructor, nullptr, sizeof(siteIsolationModeProperties) / + sizeof(siteIsolationModeProperties[0]), siteIsolationModeProperties, &siteIsolationModeEnum); + napi_set_named_property(env, exports, WEB_SITE_ISOLATION_MODE_ENUM_NAME.c_str(), siteIsolationModeEnum); + WebviewJavaScriptExecuteCallback::InitJSExcute(env, exports); WebviewCreatePDFExecuteCallback::InitJSExcute(env, exports); return exports; @@ -7833,5 +7847,70 @@ napi_value NapiWebviewController::IsAutoPreconnectEnabled(napi_env env, napi_cal NAPI_CALL(env, napi_get_boolean(env, autoPreconnectEnabled, &result)); return result; } + +napi_value NapiWebviewController::SetSiteIsolationMode( + napi_env env, napi_callback_info info) +{ + WVLOG_I("set site isolation mode."); + + napi_value result = nullptr; + napi_value thisVar = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + + NAPI_CALL(env, 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, + "BusinessError 401: Parameter error. The number of params must be one."); + return result; + } + + int32_t mode = 0; + if (!NapiParseUtils::ParseInt32(env, argv[INTEGER_ZERO], mode)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + "BusinessError 401: Parameter error. The type of 'mode' must be int."); + return result; + } + WVLOG_I("NapiWebviewController::SetSiteIsolationMode: %{public}d", mode); + + if (mode < static_cast(SiteIsolationMode::PARTIAL) || + mode > static_cast(SiteIsolationMode::STRICT)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYPE_INVALID, "mode")); + return result; + } + + int32_t res = NWebHelper::Instance().SetSiteIsolationMode( + static_cast(mode)); + + WVLOG_I("NapiWebviewController::SetSiteIsolationMode res: %{public}d", res); + if (res == 4) { + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, + "InitError 17100001: Site Isolation mode already set by developer"); + return result; + } + + if (res == 2) { + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, + "InitError 17100001: cannot change (AdvancedSecurityMode active)"); + return result; + } + + return result; +} + +napi_value NapiWebviewController::GetSiteIsolationMode( + napi_env env, napi_callback_info info) +{ + WVLOG_I("get site isolation mode."); + napi_value result = nullptr; + + int32_t mode = static_cast(NWebHelper::Instance().GetSiteIsolationMode()); + NAPI_CALL(env, napi_create_int32(env, mode, &result)); + WVLOG_I("NapiWebviewController::GetSiteIsolationMode result: %{public}d", mode); + 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 c8dfc3c5d..a30b42c7f 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -46,6 +46,7 @@ const std::string WEB_PRESSURE_LEVEL_ENUM_NAME = "PressureLevel"; const std::string WEB_CONTROLLER_ATTACHSTATE_ENUM_NAME = "ControllerAttachState"; const std::string WEB_BLANKLESS_ERROR_CODE_ENUM_NAME = "WebBlanklessErrorCode"; const std::string WEB_DESTROY_MODE_ENUM_NAME = "WebDestroyMode"; +const std::string WEB_SITE_ISOLATION_MODE_ENUM_NAME = "SiteIsolationMode"; constexpr double TEN_MILLIMETER_TO_INCH = 0.39; struct Scheme { @@ -337,6 +338,10 @@ private: static napi_value GetRenderProcessMode(napi_env env, napi_callback_info info); + static napi_value SetSiteIsolationMode(napi_env env, napi_callback_info info); + + static napi_value GetSiteIsolationMode(napi_env env, napi_callback_info info); + static napi_value PrecompileJavaScript(napi_env env, napi_callback_info info); static napi_value InjectOfflineResources(napi_env env, napi_callback_info info); diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 63a3f19f8..cac2ae80f 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -169,6 +169,11 @@ enum class RenderProcessMode : int32_t { MULTIPLE_MODE = 1, }; +enum class SiteIsolationMode { + PARTIAL, + STRICT, +}; + class NWebTouchPointInfo { public: virtual ~NWebTouchPointInfo() = default; diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 039873fb9..4b6d5a570 100644 --- a/ohos_interface/include/ohos_nweb/nweb_engine.h +++ b/ohos_interface/include/ohos_nweb/nweb_engine.h @@ -72,6 +72,10 @@ public: virtual RenderProcessMode GetRenderProcessMode() = 0; + virtual int32_t SetSiteIsolationMode(SiteIsolationMode mode) { return 0; } + + virtual SiteIsolationMode GetSiteIsolationMode() { return SiteIsolationMode::PARTIAL; } + virtual void ClearPrefetchedResource(const std::vector& cache_key_list) = 0; virtual void WarmupServiceWorker(const std::string& url) = 0; 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 9e2ff2191..862c9f594 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 @@ -31,6 +31,8 @@ namespace OHOS::ArkWeb { using ArkWebRenderProcessMode = OHOS::NWeb::RenderProcessMode; +using ArkWebSiteIsolationMode = OHOS::NWeb::SiteIsolationMode; + ArkWebEngineImpl::ArkWebEngineImpl(std::shared_ptr nweb_engine) : nweb_engine_(nweb_engine) {} ArkWebRefPtr ArkWebEngine::GetInstance() @@ -315,4 +317,14 @@ void ArkWebEngineImpl::SetWebDestroyMode(int32_t mode) nweb_engine_->SetWebDestroyMode(static_cast(mode)); } +int32_t ArkWebEngineImpl::SetSiteIsolationMode(int32_t mode) +{ + return static_cast(nweb_engine_->SetSiteIsolationMode(static_cast(mode))); +} + +int32_t ArkWebEngineImpl::GetSiteIsolationMode() +{ + return static_cast(nweb_engine_->GetSiteIsolationMode()); +} + } // 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 061c3bc61..f55d6500e 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 @@ -120,6 +120,10 @@ public: void SetWebDestroyMode(int32_t mode) override; + int32_t SetSiteIsolationMode(int32_t mode) override; + + int32_t GetSiteIsolationMode() 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 de32186f1..097bd7eea 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 @@ -372,4 +372,15 @@ void ArkWebEngineWrapper::SetWebDestroyMode(OHOS::NWeb::WebDestroyMode mode) ark_web_engine_->SetWebDestroyMode(static_cast(mode)); } +int32_t ArkWebEngineWrapper::SetSiteIsolationMode(ArkWebSiteIsolationMode mode) +{ + return static_cast(ark_web_engine_->SetSiteIsolationMode(static_cast(mode))); +} + +ArkWebSiteIsolationMode ArkWebEngineWrapper::GetSiteIsolationMode() +{ + int32_t res = ark_web_engine_->GetSiteIsolationMode(); + return static_cast(res); +} + } // 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 ae3301b38..8c95d2044 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 @@ -24,6 +24,8 @@ namespace OHOS::ArkWeb { using ArkWebRenderProcessMode = OHOS::NWeb::RenderProcessMode; +using ArkWebSiteIsolationMode = OHOS::NWeb::SiteIsolationMode; + class ArkWebEngineWrapper : public OHOS::NWeb::NWebEngine { public: ArkWebEngineWrapper(ArkWebRefPtr ark_web_engine); @@ -119,6 +121,10 @@ public: void SetWebDestroyMode(OHOS::NWeb::WebDestroyMode mode) override; + int32_t SetSiteIsolationMode(ArkWebSiteIsolationMode mode) override; + + ArkWebSiteIsolationMode GetSiteIsolationMode() 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 b3d800637..f58a4db2b 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 @@ -194,6 +194,12 @@ public: /*--ark web()--*/ virtual void SetWebDestroyMode(int32_t mode) = 0; + + /*--ark web()--*/ + virtual int32_t SetSiteIsolationMode(int32_t mode) = 0; + + /*--ark web()--*/ + virtual int32_t GetSiteIsolationMode() = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index da0787c08..b43b03b51 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -158,6 +158,10 @@ public: bool IsAutoPreconnectEnabled(); + int32_t SetSiteIsolationMode(SiteIsolationMode mode); + + SiteIsolationMode GetSiteIsolationMode() override; + private: NWebHelper() = default; bool GetWebEngine(bool fromArk); diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index 85bd5372d..e21fa37dd 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -1018,6 +1018,26 @@ RenderProcessMode NWebHelper::GetRenderProcessMode() return nwebEngine_->GetRenderProcessMode(); } +int32_t NWebHelper::SetSiteIsolationMode(SiteIsolationMode mode) +{ + if (nwebEngine_ == nullptr) { + WVLOG_E("web engine is nullptr"); + return -1; + } + + return nwebEngine_->SetSiteIsolationMode(mode); +} + +SiteIsolationMode NWebHelper::GetSiteIsolationMode() +{ + if (nwebEngine_ == nullptr) { + WVLOG_E("web engine is nullptr"); + return SiteIsolationMode::PARTIAL; + } + + return nwebEngine_->GetSiteIsolationMode(); +} + void NWebHelper::SetHostIP(const std::string& hostName, const std::string& address, int32_t aliveTime) { if (nwebEngine_ == nullptr) { -- Gitee From 7686c8c5dde39b624b667dac63e5494f0319bcf0 Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Mon, 1 Sep 2025 19:07:02 +0800 Subject: [PATCH 079/124] site isolation Signed-off-by: quyue00807312 --- ohos_nweb/include/nweb_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index b43b03b51..30a1d52ab 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -160,7 +160,7 @@ public: int32_t SetSiteIsolationMode(SiteIsolationMode mode); - SiteIsolationMode GetSiteIsolationMode() override; + SiteIsolationMode GetSiteIsolationMode(); private: NWebHelper() = default; -- Gitee From bd1cefbf800747f23bd329378d2484f1f74dbd3b Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Mon, 1 Sep 2025 20:02:26 +0800 Subject: [PATCH 080/124] site isolation Signed-off-by: quyue00807312 --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index a346fe385..497821606 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -7886,13 +7886,13 @@ napi_value NapiWebviewController::SetSiteIsolationMode( static_cast(mode)); WVLOG_I("NapiWebviewController::SetSiteIsolationMode res: %{public}d", res); - if (res == 4) { + if (res == INTEGER_FOUR) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: Site Isolation mode already set by developer"); return result; } - if (res == 2) { + if (res == INTEGER_TWO) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: cannot change (AdvancedSecurityMode active)"); return result; -- Gitee From 7215f1b47a33a14eeff512729735a84c967034ea Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Tue, 2 Sep 2025 10:29:13 +0800 Subject: [PATCH 081/124] site isolation Signed-off-by: quyue00807312 --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 497821606..0b954b1d3 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -7892,6 +7892,12 @@ napi_value NapiWebviewController::SetSiteIsolationMode( return result; } + if (res == INTEGER_THREE) { + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, + "InitError 17100001: Site Isolation mode cannot be strict when single render"); + return result; + } + if (res == INTEGER_TWO) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: cannot change (AdvancedSecurityMode active)"); -- Gitee From 28feb6afc45faae9fa7f87b03af99d9056d9d0d0 Mon Sep 17 00:00:00 2001 From: DDDDD Date: Tue, 2 Sep 2025 15:02:54 +0800 Subject: [PATCH 082/124] =?UTF-8?q?=E5=90=8C=E5=B1=82=E6=B8=B2=E6=9F=93obj?= =?UTF-8?q?ect=E6=A0=87=E7=AD=BE=E6=94=AF=E6=8C=81=E4=BC=A0=E9=80=92param?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DDDDD --- ohos_glue/BUILD.gn | 10 ++++ .../include/ohos_nweb/nweb_handler.h | 38 ++++++++++++ ohos_interface/ohos_glue/BUILD_webcore.gn | 10 ++++ .../base/include/ark_web_bridge_types.h | 2 + .../webcore/ark_web_handler_wrapper.cpp | 12 ++++ .../bridge/webcore/ark_web_handler_wrapper.h | 9 +++ ..._web_native_embed_param_data_info_impl.cpp | 46 ++++++++++++++ ...rk_web_native_embed_param_data_info_impl.h | 45 ++++++++++++++ .../ark_web_native_embed_param_item_impl.cpp | 47 +++++++++++++++ .../ark_web_native_embed_param_item_impl.h | 47 +++++++++++++++ .../bridge/webview/ark_web_handler_impl.cpp | 11 ++++ .../bridge/webview/ark_web_handler_impl.h | 8 +++ ...b_native_embed_param_data_info_wrapper.cpp | 60 +++++++++++++++++++ ...web_native_embed_param_data_info_wrapper.h | 43 +++++++++++++ ...rk_web_native_embed_param_item_wrapper.cpp | 59 ++++++++++++++++++ .../ark_web_native_embed_param_item_wrapper.h | 47 +++++++++++++++ ..._native_embed_param_item_vector_cpptoc.cpp | 49 +++++++++++++++ ...eb_native_embed_param_item_vector_cpptoc.h | 30 ++++++++++ ..._native_embed_param_item_vector_ctocpp.cpp | 44 ++++++++++++++ ...eb_native_embed_param_item_vector_ctocpp.h | 32 ++++++++++ .../ohos_nweb/include/ark_web_handler.h | 10 ++++ .../ark_web_native_embed_param_data_info.h | 41 +++++++++++++ .../include/ark_web_native_embed_param_item.h | 43 +++++++++++++ .../ark_web_native_embed_param_item_vector.h | 35 +++++++++++ .../ohos_glue/scripts/file_parser.py | 3 + 25 files changed, 781 insertions(+) create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_data_info_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_data_info_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_item_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_item_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_data_info_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_data_info_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_item_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_item_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/cpptoc/webcore/ark_web_native_embed_param_item_vector_cpptoc.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/cpptoc/webcore/ark_web_native_embed_param_item_vector_cpptoc.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_data_info.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_item.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_item_vector.h diff --git a/ohos_glue/BUILD.gn b/ohos_glue/BUILD.gn index 1e59ca2de..e1523c518 100644 --- a/ohos_glue/BUILD.gn +++ b/ohos_glue/BUILD.gn @@ -179,6 +179,10 @@ action("ohos_glue_nweb_prepare") { "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_embed_info_wrapper.h", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_embed_mouse_event_wrapper.cpp", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_embed_mouse_event_wrapper.h", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_embed_param_data_info_wrapper.cpp", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_embed_param_data_info_wrapper.h", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_embed_param_item_wrapper.cpp", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_embed_param_item_wrapper.h", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_embed_touch_event_wrapper.cpp", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_embed_touch_event_wrapper.h", "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_media_player_bridge_impl.cpp", @@ -433,6 +437,12 @@ action("ohos_glue_nweb_prepare") { "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_embed_touch_event_ctocpp.h", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_embed_mouse_event_ctocpp.cpp", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_embed_mouse_event_ctocpp.h", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_embed_param_data_info_ctocpp.cpp", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_embed_param_data_info_ctocpp.h", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_embed_param_item_ctocpp.cpp", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_embed_param_item_ctocpp.h", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_embed_param_item_vector_ctocpp.cpp", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_embed_param_item_vector_ctocpp.h", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_media_player_handler_ctocpp.cpp", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_media_player_handler_ctocpp.h", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_media_player_surface_info_ctocpp.cpp", diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index 3c73e0496..e31f121b0 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -355,6 +355,36 @@ public: virtual std::shared_ptr GetResult() = 0; }; +enum class NativeEmbedParamStatus { + ADD, + UPDATE, + DELETE, +}; + +class NWebNativeEmbedParamItem { +public: + virtual ~NWebNativeEmbedParamItem() = default; + + virtual NativeEmbedParamStatus GetStatus() = 0; + + virtual std::string GetId() = 0; + + virtual std::string GetName() = 0; + + virtual std::string GetValue() = 0; +}; + +class NWebNativeEmbedParamDataInfo { +public: + virtual ~NWebNativeEmbedParamDataInfo() = default; + + virtual std::string GetEmbedId() = 0; + + virtual std::string GetObjectAttributeId() = 0; + + virtual std::vector> GetParamItems() = 0; +}; + class OHOS_NWEB_EXPORT NWebHandler { public: NWebHandler() = default; @@ -1278,6 +1308,14 @@ public: * @brief Called when you click on caret. */ virtual bool IsShowHandle() { return false; } + + /** + * @brief Called when params of the native object are changed. + * + * @param paramDataInfo The information containing the set of all changed params for the native object. + * + */ + virtual void OnNativeEmbedObjectParamChange(std::shared_ptr paramDataInfo) {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/ohos_glue/BUILD_webcore.gn b/ohos_interface/ohos_glue/BUILD_webcore.gn index e0746d743..ab130591a 100644 --- a/ohos_interface/ohos_glue/BUILD_webcore.gn +++ b/ohos_interface/ohos_glue/BUILD_webcore.gn @@ -174,6 +174,10 @@ component("ohos_nweb_glue_source") { "ohos_nweb/bridge/ark_web_native_embed_data_info_impl.h", "ohos_nweb/bridge/ark_web_native_embed_info_impl.cpp", "ohos_nweb/bridge/ark_web_native_embed_info_impl.h", + "ohos_nweb/bridge/ark_web_native_embed_param_data_info_impl.cpp", + "ohos_nweb/bridge/ark_web_native_embed_param_data_info_impl.h", + "ohos_nweb/bridge/ark_web_native_embed_param_item_impl.cpp", + "ohos_nweb/bridge/ark_web_native_embed_param_item_impl.h", "ohos_nweb/bridge/ark_web_native_embed_touch_event_impl.cpp", "ohos_nweb/bridge/ark_web_native_embed_touch_event_impl.h", "ohos_nweb/bridge/ark_web_native_media_player_bridge_wrapper.cpp", @@ -348,6 +352,12 @@ component("ohos_nweb_glue_source") { "ohos_nweb/cpptoc/ark_web_native_embed_touch_event_cpptoc.h", "ohos_nweb/cpptoc/ark_web_native_embed_mouse_event_cpptoc.cpp", "ohos_nweb/cpptoc/ark_web_native_embed_mouse_event_cpptoc.h", + "ohos_nweb/cpptoc/ark_web_native_embed_param_data_info_cpptoc.cpp", + "ohos_nweb/cpptoc/ark_web_native_embed_param_data_info_cpptoc.h", + "ohos_nweb/cpptoc/ark_web_native_embed_param_item_cpptoc.cpp", + "ohos_nweb/cpptoc/ark_web_native_embed_param_item_cpptoc.h", + "ohos_nweb/cpptoc/ark_web_native_embed_param_item_vector_cpptoc.cpp", + "ohos_nweb/cpptoc/ark_web_native_embed_param_item_vector_cpptoc.h", "ohos_nweb/cpptoc/ark_web_native_media_player_handler_cpptoc.cpp", "ohos_nweb/cpptoc/ark_web_native_media_player_handler_cpptoc.h", "ohos_nweb/cpptoc/ark_web_native_media_player_surface_info_cpptoc.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 d3d18a233..0ff6e070c 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 @@ -124,6 +124,8 @@ enum ArkWebBridgeType { ARK_WEB_PRINT_WRITE_RESULT_CALLBACK_ADAPTER = 101, ARK_WEB_PRINT_DOCUMENT_ADAPTER_ADAPTER = 102, ARK_WEB_STYLUS_TOUCH_POINT_INFO = 104, + ARK_WEB_NATIVE_EMBED_PARAM_DATA_INFO = 105, + ARK_WEB_NATIVE_EMBED_PARAM_ITEM = 106, /*Note: The end of nweb interface bridge type*/ ARK_WEB_NWEB_INTERFACE_BUTT, 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 328c4a512..0a391fa3a 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 @@ -43,6 +43,7 @@ #include "ohos_nweb/bridge/ark_web_native_embed_data_info_impl.h" #include "ohos_nweb/bridge/ark_web_native_embed_touch_event_impl.h" #include "ohos_nweb/bridge/ark_web_native_embed_mouse_event_impl.h" +#include "ohos_nweb/bridge/ark_web_native_embed_param_data_info_impl.h" #include "ohos_nweb/bridge/ark_web_nweb_impl.h" #include "ohos_nweb/bridge/ark_web_quick_menu_callback_impl.h" #include "ohos_nweb/bridge/ark_web_quick_menu_params_impl.h" @@ -1281,4 +1282,15 @@ bool ArkWebHandlerWrapper::IsShowHandle() { return ark_web_handler_->IsShowHandle(); } + +void ArkWebHandlerWrapper::OnNativeEmbedObjectParamChange( + std::shared_ptr paramDataInfo) +{ + if (CHECK_SHARED_PTR_IS_NULL(paramDataInfo)) { + ark_web_handler_->OnNativeEmbedObjectParamChange(nullptr); + return; + } + + ark_web_handler_->OnNativeEmbedObjectParamChange(new ArkWebNativeEmbedParamDataInfoImpl(paramDataInfo)); +} } // 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 fce768ece..cfe5ec8bb 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 @@ -759,6 +759,15 @@ public: * @brief Called when you click on caret. */ virtual bool IsShowHandle() override; + + /** + * @brief Called when params of the native object are changed. + * + * @param paramDataInfo The information containing the set of all changed params for the native object. + * + */ + void OnNativeEmbedObjectParamChange( + std::shared_ptr paramDataInfo) override; private: ArkWebRefPtr ark_web_handler_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_data_info_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_data_info_impl.cpp new file mode 100644 index 000000000..ce6d10bca --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_data_info_impl.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_native_embed_param_data_info_impl.h" + +#include "ohos_nweb/cpptoc/ark_web_native_embed_param_item_vector_cpptoc.h" + +#include "ohos_nweb/bridge/ark_web_native_embed_param_item_impl.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebNativeEmbedParamDataInfoImpl::ArkWebNativeEmbedParamDataInfoImpl( + std::shared_ptr nweb_native_embed_param_data_info) + : nweb_native_embed_param_data_info_(nweb_native_embed_param_data_info) +{} + +ArkWebString ArkWebNativeEmbedParamDataInfoImpl::GetEmbedId() +{ + return ArkWebStringClassToStruct(nweb_native_embed_param_data_info_->GetEmbedId()); +} + +ArkWebString ArkWebNativeEmbedParamDataInfoImpl::GetObjectAttributeId() +{ + return ArkWebStringClassToStruct(nweb_native_embed_param_data_info_->GetObjectAttributeId()); +} + +ArkWebNativeEmbedParamItemVector ArkWebNativeEmbedParamDataInfoImpl::GetParamItems() +{ + return ArkWebNativeEmbedParamItemVectorClassToStruct(nweb_native_embed_param_data_info_->GetParamItems()); +} + +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_data_info_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_data_info_impl.h new file mode 100644 index 000000000..017cc8c20 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_data_info_impl.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_EMBED_PARAM_DATA_INFO_IMPL_H_ +#define ARK_WEB_NATIVE_EMBED_PARAM_DATA_INFO_IMPL_H_ +#pragma once + +#include "include/nweb_handler.h" +#include "ohos_nweb/include/ark_web_native_embed_param_data_info.h" + +namespace OHOS::ArkWeb { + +class ArkWebNativeEmbedParamDataInfoImpl : public ArkWebNativeEmbedParamDataInfo { + IMPLEMENT_REFCOUNTING(ArkWebNativeEmbedParamDataInfoImpl); + +public: + ArkWebNativeEmbedParamDataInfoImpl( + std::shared_ptr nweb_native_embed_param_data_info); + ~ArkWebNativeEmbedParamDataInfoImpl() = default; + + ArkWebString GetEmbedId() override; + + ArkWebString GetObjectAttributeId() override; + + ArkWebNativeEmbedParamItemVector GetParamItems() override; + +private: + std::shared_ptr nweb_native_embed_param_data_info_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_EMBED_PARAM_DATA_INFO_IMPL_H_ \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_item_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_item_impl.cpp new file mode 100644 index 000000000..e3d61c61a --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_item_impl.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_native_embed_param_item_impl.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebNativeEmbedParamItemImpl::ArkWebNativeEmbedParamItemImpl( + std::shared_ptr nweb_native_embed_param_item) + : nweb_native_embed_param_item_(nweb_native_embed_param_item) +{} + +int ArkWebNativeEmbedParamItemImpl::GetStatus() +{ + return static_cast(nweb_native_embed_param_item_->GetStatus()); +} + +ArkWebString ArkWebNativeEmbedParamItemImpl::GetId() +{ + return ArkWebStringClassToStruct(nweb_native_embed_param_item_->GetId()); +} + +ArkWebString ArkWebNativeEmbedParamItemImpl::GetName() +{ + return ArkWebStringClassToStruct(nweb_native_embed_param_item_->GetName()); +} + +ArkWebString ArkWebNativeEmbedParamItemImpl::GetValue() +{ + return ArkWebStringClassToStruct(nweb_native_embed_param_item_->GetValue()); +} + +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_item_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_item_impl.h new file mode 100644 index 000000000..fa6b942e2 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_param_item_impl.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_EMBED_PARAM_ITEM_IMPL_H_ +#define ARK_WEB_NATIVE_EMBED_PARAM_ITEM_IMPL_H_ +#pragma once + +#include "include/nweb_handler.h" +#include "ohos_nweb/include/ark_web_native_embed_param_item.h" + +namespace OHOS::ArkWeb { + +class ArkWebNativeEmbedParamItemImpl : public ArkWebNativeEmbedParamItem { + IMPLEMENT_REFCOUNTING(ArkWebNativeEmbedParamItemImpl); + +public: + ArkWebNativeEmbedParamItemImpl( + std::shared_ptr nweb_native_embed_param_item); + ~ArkWebNativeEmbedParamItemImpl() = default; + + int GetStatus() override; + + ArkWebString GetId() override; + + ArkWebString GetName() override; + + ArkWebString GetValue() override; + +private: + std::shared_ptr nweb_native_embed_param_item_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_EMBED_PARAM_ITEM_IMPL_H_ \ No newline at end of file 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 f16438bb3..394fb9daa 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 @@ -43,6 +43,7 @@ #include "ohos_nweb/bridge/ark_web_native_embed_data_info_wrapper.h" #include "ohos_nweb/bridge/ark_web_native_embed_touch_event_wrapper.h" #include "ohos_nweb/bridge/ark_web_native_embed_mouse_event_wrapper.h" +#include "ohos_nweb/bridge/ark_web_native_embed_param_data_info_wrapper.h" #include "ohos_nweb/bridge/ark_web_nweb_wrapper.h" #include "ohos_nweb/bridge/ark_web_quick_menu_callback_wrapper.h" #include "ohos_nweb/bridge/ark_web_quick_menu_params_wrapper.h" @@ -1117,4 +1118,14 @@ bool ArkWebHandlerImpl::IsShowHandle() { return nweb_handler_->IsShowHandle(); } + +void ArkWebHandlerImpl::OnNativeEmbedObjectParamChange(ArkWebRefPtr data_info) +{ + if (CHECK_REF_PTR_IS_NULL(data_info)) { + nweb_handler_->OnNativeEmbedObjectParamChange(nullptr); + return; + } + + nweb_handler_->OnNativeEmbedObjectParamChange(std::make_shared(data_info)); +} } // 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 be1c1fbfd..43a042f80 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 @@ -722,6 +722,14 @@ public: * @brief Called when you click on caret. */ virtual bool IsShowHandle() override; + + /** + * @brief Called when params of the native object are changed. + * + * @param data_info The information containing the set of all changed params for the native object. + * + */ + void OnNativeEmbedObjectParamChange(ArkWebRefPtr data_info) override; private: std::shared_ptr nweb_handler_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_data_info_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_data_info_wrapper.cpp new file mode 100644 index 000000000..ec07f8406 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_data_info_wrapper.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_native_embed_param_data_info_wrapper.h" + +#include "ohos_nweb/bridge/ark_web_native_embed_param_item_wrapper.h" +#include "ohos_nweb/ctocpp/ark_web_native_embed_param_item_vector_ctocpp.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebNativeEmbedParamDataInfoWrapper::ArkWebNativeEmbedParamDataInfoWrapper( + ArkWebRefPtr ark_web_native_embed_param_data_info) + : ark_web_native_embed_param_data_info_(ark_web_native_embed_param_data_info) +{} + +std::string ArkWebNativeEmbedParamDataInfoWrapper::GetEmbedId() +{ + ArkWebString stEmbedId = ark_web_native_embed_param_data_info_->GetEmbedId(); + + std::string objEmbedId = ArkWebStringStructToClass(stEmbedId); + ArkWebStringStructRelease(stEmbedId); + return objEmbedId; +} + +std::string ArkWebNativeEmbedParamDataInfoWrapper::GetObjectAttributeId() +{ + ArkWebString stObjectAttributeId = ark_web_native_embed_param_data_info_->GetObjectAttributeId(); + + std::string objObjectAttributeId = ArkWebStringStructToClass(stObjectAttributeId); + ArkWebStringStructRelease(stObjectAttributeId); + return objObjectAttributeId; +} + +std::vector> + ArkWebNativeEmbedParamDataInfoWrapper::GetParamItems() +{ + ArkWebNativeEmbedParamItemVector stNativeEmbedParamItemVector = + ark_web_native_embed_param_data_info_->GetParamItems(); + + std::vector> objNativeEmbedParamItemVector = + ArkWebNativeEmbedParamItemVectorStructToClass(stNativeEmbedParamItemVector); + ArkWebNativeEmbedParamItemVectorStructRelease(stNativeEmbedParamItemVector); + return objNativeEmbedParamItemVector; +} + +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_data_info_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_data_info_wrapper.h new file mode 100644 index 000000000..1b3f7589c --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_data_info_wrapper.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_EMBED_PARAM_DATA_INFO_WRAPPER_H_ +#define ARK_WEB_NATIVE_EMBED_PARAM_DATA_INFO_WRAPPER_H_ +#pragma once + +#include "include/nweb_handler.h" +#include "ohos_nweb/include/ark_web_native_embed_param_data_info.h" + +namespace OHOS::ArkWeb { + +class ArkWebNativeEmbedParamDataInfoWrapper : public OHOS::NWeb::NWebNativeEmbedParamDataInfo { +public: + ArkWebNativeEmbedParamDataInfoWrapper( + ArkWebRefPtr ark_web_native_embed_param_data_info); + ~ArkWebNativeEmbedParamDataInfoWrapper() = default; + + std::string GetEmbedId() override; + + std::string GetObjectAttributeId() override; + + std::vector> GetParamItems() override; + +private: + ArkWebRefPtr ark_web_native_embed_param_data_info_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_EMBED_PARAM_DATA_INFO_WRAPPER_H_ \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_item_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_item_wrapper.cpp new file mode 100644 index 000000000..6362bcbd8 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_item_wrapper.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_native_embed_param_item_wrapper.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebNativeEmbedParamItemWrapper::ArkWebNativeEmbedParamItemWrapper( + ArkWebRefPtr ark_web_native_embed_param_item) + : ark_web_native_embed_param_item_(ark_web_native_embed_param_item) +{} + +ArkWebNativeEmbedParamStatus ArkWebNativeEmbedParamItemWrapper::GetStatus() +{ + return static_cast(ark_web_native_embed_param_item_->GetStatus()); +} + +std::string ArkWebNativeEmbedParamItemWrapper::GetId() +{ + ArkWebString stId = ark_web_native_embed_param_item_->GetId(); + + std::string objId = ArkWebStringStructToClass(stId); + ArkWebStringStructRelease(stId); + return objId; +} + +std::string ArkWebNativeEmbedParamItemWrapper::GetName() +{ + ArkWebString stName = ark_web_native_embed_param_item_->GetName(); + + std::string objName = ArkWebStringStructToClass(stName); + ArkWebStringStructRelease(stName); + return objName; +} + +std::string ArkWebNativeEmbedParamItemWrapper::GetValue() +{ + ArkWebString stValue = ark_web_native_embed_param_item_->GetValue(); + + std::string objValue = ArkWebStringStructToClass(stValue); + ArkWebStringStructRelease(stValue); + return objValue; +} + +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_item_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_item_wrapper.h new file mode 100644 index 000000000..364c768ef --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_embed_param_item_wrapper.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_EMBED_PARAM_ITEM_WRAPPER_H_ +#define ARK_WEB_NATIVE_EMBED_PARAM_ITEM_WRAPPER_H_ +#pragma once + +#include "include/nweb_handler.h" +#include "ohos_nweb/include/ark_web_native_embed_param_item.h" + +namespace OHOS::ArkWeb { + +using ArkWebNativeEmbedParamStatus = OHOS::NWeb::NativeEmbedParamStatus; + +class ArkWebNativeEmbedParamItemWrapper : public OHOS::NWeb::NWebNativeEmbedParamItem { +public: + ArkWebNativeEmbedParamItemWrapper( + ArkWebRefPtr ark_web_native_embed_param_item); + ~ArkWebNativeEmbedParamItemWrapper() = default; + + ArkWebNativeEmbedParamStatus GetStatus() override; + + std::string GetId() override; + + std::string GetName() override; + + std::string GetValue() override; + +private: + ArkWebRefPtr ark_web_native_embed_param_item_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_EMBED_PARAM_ITEM_WRAPPER_H_ \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webcore/ark_web_native_embed_param_item_vector_cpptoc.cpp b/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webcore/ark_web_native_embed_param_item_vector_cpptoc.cpp new file mode 100644 index 000000000..9d2f10498 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webcore/ark_web_native_embed_param_item_vector_cpptoc.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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/cpptoc/ark_web_native_embed_param_item_vector_cpptoc.h" + +#include "ohos_nweb/bridge/ark_web_native_embed_param_item_impl.h" + +#include "ohos_nweb/cpptoc/ark_web_native_embed_param_item_cpptoc.h" + +namespace OHOS::ArkWeb { + +ArkWebNativeEmbedParamItemVector ArkWebNativeEmbedParamItemVectorClassToStruct( + const std::vector>& class_value) +{ + ArkWebNativeEmbedParamItemVector struct_value = { .size = class_value.size(), + .ark_web_mem_free_func = ArkWebMemFree }; + if (struct_value.size > 0) { + struct_value.value = (ark_web_native_embed_param_item_t**)ArkWebMemMalloc( + sizeof(ark_web_native_embed_param_item_t*) * struct_value.size); + if (struct_value.value == nullptr) { + struct_value.size = 0; + return struct_value; + } + + int count = 0; + for (auto it = class_value.begin(); it != class_value.end(); it++) { + ArkWebRefPtr ark_web_native_embed_param_item = + new ArkWebNativeEmbedParamItemImpl(*it); + struct_value.value[count] = ArkWebNativeEmbedParamItemCppToC::Invert(ark_web_native_embed_param_item); + count++; + } + } + + return struct_value; +} + +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webcore/ark_web_native_embed_param_item_vector_cpptoc.h b/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webcore/ark_web_native_embed_param_item_vector_cpptoc.h new file mode 100644 index 000000000..d7aeea77a --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/cpptoc/webcore/ark_web_native_embed_param_item_vector_cpptoc.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_EMBED_PARAM_ITEM_VECTOR_CPPTOC_H_ +#define ARK_WEB_NATIVE_EMBED_PARAM_ITEM_VECTOR_CPPTOC_H_ +#pragma once + +#include "include/nweb_handler.h" +#include "ohos_nweb/include/ark_web_native_embed_param_item_vector.h" + +namespace OHOS::ArkWeb { + +ArkWebNativeEmbedParamItemVector ArkWebNativeEmbedParamItemVectorClassToStruct( + const std::vector>& class_value); + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_EMBED_PARAM_ITEM_VECTOR_CPPTOC_H_ \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.cpp b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.cpp new file mode 100644 index 000000000..18e79b0bd --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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/ctocpp/ark_web_native_embed_param_item_vector_ctocpp.h" +#include "ohos_nweb/bridge/ark_web_native_embed_param_item_wrapper.h" +#include "ohos_nweb/ctocpp/ark_web_native_embed_param_item_ctocpp.h" + +namespace OHOS::ArkWeb { + +std::vector> ArkWebNativeEmbedParamItemVectorStructToClass( + const ArkWebNativeEmbedParamItemVector& struct_value) +{ + std::vector> class_value; + if (struct_value.size > 0) { + for (int count = 0; count < struct_value.size; count++) { + std::shared_ptr nweb_native_embed_param_item = + std::make_shared( + ArkWebNativeEmbedParamItemCToCpp::Invert(struct_value.value[count])); + class_value.push_back(nweb_native_embed_param_item); + } + } + + return class_value; +} + +void ArkWebNativeEmbedParamItemVectorStructRelease(ArkWebNativeEmbedParamItemVector& struct_value) +{ + struct_value.size = 0; + SAFE_FREE(struct_value.value, struct_value.ark_web_mem_free_func); +} + +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.h b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.h new file mode 100644 index 000000000..b535f69c1 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_EMBED_PARAM_ITEM_VECTOR_CTOCPP_H_ +#define ARK_WEB_NATIVE_EMBED_PARAM_ITEM_VECTOR_CTOCPP_H_ +#pragma once + +#include "include/nweb_handler.h" +#include "ohos_nweb/include/ark_web_native_embed_param_item_vector.h" + +namespace OHOS::ArkWeb { + +std::vector> ArkWebNativeEmbedParamItemVectorStructToClass( + const ArkWebNativeEmbedParamItemVector& struct_value); + +void ArkWebNativeEmbedParamItemVectorStructRelease(ArkWebNativeEmbedParamItemVector& struct_value); + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_EMBED_PARAM_ITEM_VECTOR_CTOCPP_H_ 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 847557c6a..83ddff6e7 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 @@ -45,6 +45,7 @@ #include "ohos_nweb/include/ark_web_native_embed_data_info.h" #include "ohos_nweb/include/ark_web_native_embed_touch_event.h" #include "ohos_nweb/include/ark_web_native_embed_mouse_event.h" +#include "ohos_nweb/include/ark_web_native_embed_param_data_info.h" #include "ohos_nweb/include/ark_web_nweb.h" #include "ohos_nweb/include/ark_web_quick_menu_callback.h" #include "ohos_nweb/include/ark_web_quick_menu_params.h" @@ -1052,6 +1053,15 @@ public: */ /*--ark web()--*/ virtual bool IsShowHandle() { return false; } + + /** + * @brief Called when params of the native object are changed. + * + * @param data_info The information containing the set of all changed params for the native object. + * + */ + /*--ark web()--*/ + virtual void OnNativeEmbedObjectParamChange(ArkWebRefPtr data_info) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_data_info.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_data_info.h new file mode 100644 index 000000000..d44a9154e --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_data_info.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_EMBED_PARAM_DATA_INFO_H_ +#define ARK_WEB_NATIVE_EMBED_PARAM_DATA_INFO_H_ +#pragma once + +#include "base/include/ark_web_base_ref_counted.h" +#include "ohos_nweb/include/ark_web_native_embed_param_item.h" +#include "ohos_nweb/include/ark_web_native_embed_param_item_vector.h" + +namespace OHOS::ArkWeb { + +/*--ark web(source=webcore)--*/ +class ArkWebNativeEmbedParamDataInfo : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual ArkWebString GetEmbedId() = 0; + + /*--ark web()--*/ + virtual ArkWebString GetObjectAttributeId() = 0; + + /*--ark web()--*/ + virtual ArkWebNativeEmbedParamItemVector GetParamItems() = 0; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_EMBED_PARAM_DATA_INFO_H_ \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_item.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_item.h new file mode 100644 index 000000000..6f39ae254 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_item.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_EMBED_PARAM_ITEM_H_ +#define ARK_WEB_NATIVE_EMBED_PARAM_ITEM_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 ArkWebNativeEmbedParamItem : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual int GetStatus() = 0; + + /*--ark web()--*/ + virtual ArkWebString GetId() = 0; + + /*--ark web()--*/ + virtual ArkWebString GetName() = 0; + + /*--ark web()--*/ + virtual ArkWebString GetValue() = 0; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_EMBED_PARAM_ITEM_H_ diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_item_vector.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_item_vector.h new file mode 100644 index 000000000..d9b600e14 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_embed_param_item_vector.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_EMBED_PARAM_ITEM_VECTOR_H_ +#define ARK_WEB_NATIVE_EMBED_PARAM_ITEM_VECTOR_H_ +#pragma once + +#include "ohos_nweb/capi/ark_web_native_embed_param_item_capi.h" + +#include "base/include/ark_web_memory.h" + +typedef struct { + int size; + ark_web_native_embed_param_item_t** value; + + ArkWebMemFreeFunc ark_web_mem_free_func; +} ArkWebNativeEmbedParamItemVector; + +const ArkWebNativeEmbedParamItemVector ark_web_native_embed_param_item_vector_default = { + 0, +}; + +#endif // ARK_WEB_NATIVE_EMBED_PARAM_ITEM_VECTOR_H_ \ No newline at end of file diff --git a/ohos_interface/ohos_glue/scripts/file_parser.py b/ohos_interface/ohos_glue/scripts/file_parser.py index a378c439a..3ca322783 100644 --- a/ohos_interface/ohos_glue/scripts/file_parser.py +++ b/ohos_interface/ohos_glue/scripts/file_parser.py @@ -441,6 +441,9 @@ _simpletypes = { 'ArkWebStylusTouchPointInfoVector': [ 'ArkWebStylusTouchPointInfoVector', 'ark_web_stylus_touch_point_info_vector_default' ], + 'ArkWebNativeEmbedParamItemVector': [ + 'ArkWebNativeEmbedParamItemVector', 'ark_web_native_embed_param_item_vector_default' + ], } -- Gitee From 9dd7da5a1fee657ca150ba67069966af2c45e071 Mon Sep 17 00:00:00 2001 From: liubo Date: Tue, 2 Sep 2025 15:08:45 +0800 Subject: [PATCH 083/124] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B3=84=E9=9C=B2?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Signed-off-by:=20liubo419=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../media_adapter/src/audio_codec_decoder_adapter_impl.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ohos_adapter/media_adapter/src/audio_codec_decoder_adapter_impl.cpp b/ohos_adapter/media_adapter/src/audio_codec_decoder_adapter_impl.cpp index bf44630b0..7429e61f5 100644 --- a/ohos_adapter/media_adapter/src/audio_codec_decoder_adapter_impl.cpp +++ b/ohos_adapter/media_adapter/src/audio_codec_decoder_adapter_impl.cpp @@ -662,13 +662,10 @@ AudioDecoderAdapterCode AudioCodecDecoderAdapterImpl::GetOutputFormatDec( return AudioDecoderAdapterCode::DECODER_ERROR; } AudioDecoderAdapterCode ret = GetParamFromAVFormat(avFormat, format); - if (ret != AudioDecoderAdapterCode::DECODER_OK) { - return ret; - } OH_AVFormat_Destroy(avFormat); avFormat = nullptr; - return AudioDecoderAdapterCode::DECODER_OK; + return ret; } AudioDecoderAdapterCode AudioCodecDecoderAdapterImpl::ReleaseOutputBufferDec(uint32_t index) -- Gitee From 019d904e986c9c8e367a2cceea735e1b800bb6d9 Mon Sep 17 00:00:00 2001 From: yjw Date: Tue, 2 Sep 2025 07:20:12 +0000 Subject: [PATCH 084/124] change fuzz Signed-off-by: yjw --- .../acquireaudiobuffer_fuzzer/BUILD.gn | 7 ++++--- .../screencaptureadapterimpl_fuzzer/init_fuzzer/BUILD.gn | 7 ++++--- .../releaseaudiobuffer_fuzzer/BUILD.gn | 7 ++++--- .../onaudiobufferavailable_fuzzer/BUILD.gn | 7 ++++--- .../screencapturecallback_fuzzer/onerror_fuzzer/BUILD.gn | 7 ++++--- .../onstatechange_fuzzer/BUILD.gn | 7 ++++--- .../onvideobufferavailable_fuzzer/BUILD.gn | 7 ++++--- .../setcapturecallback_fuzzer/BUILD.gn | 7 ++++--- 8 files changed, 32 insertions(+), 24 deletions(-) diff --git a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/acquireaudiobuffer_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/acquireaudiobuffer_fuzzer/BUILD.gn index 97d65a5a7..696f04487 100644 --- a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/acquireaudiobuffer_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/acquireaudiobuffer_fuzzer/BUILD.gn @@ -56,8 +56,9 @@ ohos_fuzztest("AcquireAudioBufferFuzzTest") { group("fuzztest") { testonly = true deps = [] - if (webview_camera_enable) { - deps += [ ":AcquireAudioBufferFuzzTest" ] - } + deps += [ + # deps file + ":AcquireAudioBufferFuzzTest", + ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/init_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/init_fuzzer/BUILD.gn index b5614b3bd..d5c34e21e 100644 --- a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/init_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/init_fuzzer/BUILD.gn @@ -56,8 +56,9 @@ ohos_fuzztest("InitFuzzTest") { group("fuzztest") { testonly = true deps = [] - if (webview_camera_enable) { - deps += [ ":InitFuzzTest" ] - } + deps += [ + # deps file + ":InitFuzzTest", + ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/releaseaudiobuffer_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/releaseaudiobuffer_fuzzer/BUILD.gn index 14b9c4adb..fa4228b29 100644 --- a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/releaseaudiobuffer_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/releaseaudiobuffer_fuzzer/BUILD.gn @@ -56,8 +56,9 @@ ohos_fuzztest("ReleaseAudioBufferFuzzTest") { group("fuzztest") { testonly = true deps = [] - if (webview_camera_enable) { - deps += [ ":ReleaseAudioBufferFuzzTest" ] - } + deps += [ + # deps file + ":ReleaseAudioBufferFuzzTest", + ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onaudiobufferavailable_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onaudiobufferavailable_fuzzer/BUILD.gn index b618cf467..82f660daa 100644 --- a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onaudiobufferavailable_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onaudiobufferavailable_fuzzer/BUILD.gn @@ -56,8 +56,9 @@ ohos_fuzztest("OnAudioBufferAvailableFuzzTest") { group("fuzztest") { testonly = true deps = [] - if (webview_camera_enable) { - deps += [ ":OnAudioBufferAvailableFuzzTest" ] - } + deps += [ + # deps file + ":OnAudioBufferAvailableFuzzTest", + ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onerror_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onerror_fuzzer/BUILD.gn index 56e353f82..41ed6dad8 100644 --- a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onerror_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onerror_fuzzer/BUILD.gn @@ -56,8 +56,9 @@ ohos_fuzztest("OnErrorFuzzTest") { group("fuzztest") { testonly = true deps = [] - if (webview_camera_enable) { - deps += [ ":OnErrorFuzzTest" ] - } + deps += [ + # deps file + ":OnErrorFuzzTest", + ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onstatechange_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onstatechange_fuzzer/BUILD.gn index 56ceed30f..76edd6944 100644 --- a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onstatechange_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onstatechange_fuzzer/BUILD.gn @@ -56,8 +56,9 @@ ohos_fuzztest("OnStateChangeFuzzTest") { group("fuzztest") { testonly = true deps = [] - if (webview_camera_enable) { - deps += [ ":OnStateChangeFuzzTest" ] - } + deps += [ + # deps file + ":OnStateChangeFuzzTest", + ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onvideobufferavailable_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onvideobufferavailable_fuzzer/BUILD.gn index 1a697bde8..36f30ae3d 100644 --- a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onvideobufferavailable_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/screencapturecallback_fuzzer/onvideobufferavailable_fuzzer/BUILD.gn @@ -56,8 +56,9 @@ ohos_fuzztest("OnVideoBufferAvailableFuzzTest") { group("fuzztest") { testonly = true deps = [] - if (webview_camera_enable) { - deps += [ ":OnVideoBufferAvailableFuzzTest" ] - } + deps += [ + # deps file + ":OnVideoBufferAvailableFuzzTest", + ] } ############################################################################### diff --git a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/setcapturecallback_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/setcapturecallback_fuzzer/BUILD.gn index 54003318a..6d920ee87 100644 --- a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/setcapturecallback_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/setcapturecallback_fuzzer/BUILD.gn @@ -56,8 +56,9 @@ ohos_fuzztest("SetCaptureCallbackFuzzTest") { group("fuzztest") { testonly = true deps = [] - if (webview_camera_enable) { - deps += [ ":SetCaptureCallbackFuzzTest" ] - } + deps += [ + # deps file + ":OnVideoBufferAvailableFuzzTest", + ] } ############################################################################### -- Gitee From e6c0cc09284496a18044694bcf2c7584ed7505e8 Mon Sep 17 00:00:00 2001 From: yjw Date: Tue, 2 Sep 2025 08:18:29 +0000 Subject: [PATCH 085/124] update /setcapturecallback_fuzzer/BUILD.gn. add code Signed-off-by: yjw --- .../setcapturecallback_fuzzer/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/setcapturecallback_fuzzer/BUILD.gn b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/setcapturecallback_fuzzer/BUILD.gn index 6d920ee87..e44004f88 100644 --- a/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/setcapturecallback_fuzzer/BUILD.gn +++ b/test/fuzztest/ohos_adapter/screencaptureadapterimpl_fuzzer/setcapturecallback_fuzzer/BUILD.gn @@ -58,7 +58,7 @@ group("fuzztest") { deps = [] deps += [ # deps file - ":OnVideoBufferAvailableFuzzTest", + ":SetCaptureCallbackFuzzTest", ] } ############################################################################### -- Gitee From a9de00941eafff3d92fe19ec9ff9c2e17d16e28e Mon Sep 17 00:00:00 2001 From: sunbin55 Date: Wed, 3 Sep 2025 10:51:44 +0800 Subject: [PATCH 086/124] =?UTF-8?q?IssueNo:#ICW3JB:[Bug]:=20=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5=E3=80=82=20Descri?= =?UTF-8?q?ption:=20=E6=B8=B2=E6=9F=93=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=20Sig:=20SIG=5FApplicationFramework=20Feature=20or=20Bugfix:?= =?UTF-8?q?=20(Bugfix)=20Binary=20Source:=20No=20=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=B6=89=E5=8F=8A=E9=9D=9E=E5=85=BC=E5=AE=B9=E5=8F=98=E6=9B=B4?= =?UTF-8?q?:=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20TDD=E8=87=AA=E9=AA=8C?= =?UTF-8?q?=E7=BB=93=E6=9E=9C(=E5=A6=82=E6=9C=89=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90=E4=BE=9B=E5=9F=BA=E7=BA=BF?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5):=20(=E4=B8=8D=E6=B6=89?= =?UTF-8?q?=E5=8F=8A)=20XTS=E8=87=AA=E9=AA=8C=E7=BB=93=E6=9E=9C(=E5=A6=82?= =?UTF-8?q?=E6=9C=89=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E5=9F=BA=E7=BA=BF=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5?= =?UTF-8?q?):=20(=E4=B8=8D=E6=B6=89=E5=8F=8A)=20Signed-off-by:=20sunbin55?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.h | 2 +- .../bridge/webcore/ark_web_mouse_event_result_impl.cpp | 2 +- .../bridge/webcore/ark_web_native_embed_mouse_event_impl.cpp | 2 +- .../bridge/webcore/ark_web_native_embed_mouse_event_impl.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.h b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.h index 2762656ba..3dd8294cf 100644 --- a/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_adapter/bridge/webcore/ark_ohos_drawing_text_adapter_wrapper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp index 96da7ef62..88f241f0d 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_mouse_event_result_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.cpp index 518135740..eb45c96e7 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.h index 9ce0002de..d0e587154 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_embed_mouse_event_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.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 afe06676e2e9376c8106ccf909613a402b2d7f1a Mon Sep 17 00:00:00 2001 From: DDDDD Date: Wed, 3 Sep 2025 16:31:43 +0800 Subject: [PATCH 087/124] =?UTF-8?q?=E8=A1=A5=E5=85=85CFI=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DDDDD --- .../webview/ark_web_native_embed_param_item_vector_ctocpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.cpp b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.cpp index 18e79b0bd..4fac008ea 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/ctocpp/webview/ark_web_native_embed_param_item_vector_ctocpp.cpp @@ -35,7 +35,7 @@ std::vector> ArkWebNativeE return class_value; } -void ArkWebNativeEmbedParamItemVectorStructRelease(ArkWebNativeEmbedParamItemVector& struct_value) +ARK_WEB_NO_SANITIZE void ArkWebNativeEmbedParamItemVectorStructRelease(ArkWebNativeEmbedParamItemVector& struct_value) { struct_value.size = 0; SAFE_FREE(struct_value.value, struct_value.ark_web_mem_free_func); -- Gitee From 22b94e1d5a06c0d7b695661c8748e7d85248cf26 Mon Sep 17 00:00:00 2001 From: xiongjun_gitee11 Date: Wed, 3 Sep 2025 19:15:49 +0800 Subject: [PATCH 088/124] Changing the log level Signed-off-by: xiongjun_gitee11 --- interfaces/native/arkweb_interface.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/native/arkweb_interface.cpp b/interfaces/native/arkweb_interface.cpp index 9aa5e6bb3..53f1481c1 100644 --- a/interfaces/native/arkweb_interface.cpp +++ b/interfaces/native/arkweb_interface.cpp @@ -102,7 +102,7 @@ static void LoadFunction(const char* functionName, Fn* fnOut) static bool LoadComponentAPI() { if (g_ComponentImpl) { - WVLOG_I("NativeArkWeb component api already loaded"); + WVLOG_D("NativeArkWeb component api already loaded"); return true; } g_ComponentImpl = new (std::nothrow) ArkWeb_ComponentAPI(); @@ -126,7 +126,7 @@ static bool LoadComponentAPI() static bool LoadComponentGlobalAPI() { if (g_ComponentGlobalImpl) { - WVLOG_I("NativeArkWeb component api already loaded"); + WVLOG_D("NativeArkWeb component api already loaded"); return true; } @@ -152,7 +152,7 @@ static bool LoadComponentGlobalAPI() static bool LoadControllerAPI() { if (g_ControllerImpl) { - WVLOG_I("NativeArkWeb controller api already loaded"); + WVLOG_D("NativeArkWeb controller api already loaded"); return true; } g_ControllerImpl = new (std::nothrow) ArkWeb_ControllerAPI(); -- Gitee From 88c6df394e39d947c5cc9e97a9d4748ed8eeb15e Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Wed, 3 Sep 2025 21:31:23 +0800 Subject: [PATCH 089/124] site isolation Signed-off-by: quyue00807312 --- .../napi/webviewcontroller/napi_webview_controller.cpp | 10 ++++++++++ ohos_nweb/src/nweb_helper.cpp | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 0b954b1d3..6bd42a4fc 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -7852,6 +7852,12 @@ napi_value NapiWebviewController::SetSiteIsolationMode( napi_env env, napi_callback_info info) { WVLOG_I("set site isolation mode."); + if(IS_CALLING_FROM_M114()){ + WVLOG_W("SetSiteIsolationMode unsupported engine version: M114"); + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, + "InitError 17100001: function SetSiteIsolationMode isn't existing"); + return nullptr; + } napi_value result = nullptr; napi_value thisVar = nullptr; @@ -7911,6 +7917,10 @@ napi_value NapiWebviewController::GetSiteIsolationMode( napi_env env, napi_callback_info info) { WVLOG_I("get site isolation mode."); + if(IS_CALLING_FROM_M114()){ + WVLOG_W("GetSiteIsolationMode unsupported engine version: M114"); + return nullptr; + } napi_value result = nullptr; int32_t mode = static_cast(NWebHelper::Instance().GetSiteIsolationMode()); diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index e21fa37dd..b57beaf28 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -1022,7 +1022,7 @@ int32_t NWebHelper::SetSiteIsolationMode(SiteIsolationMode mode) { if (nwebEngine_ == nullptr) { WVLOG_E("web engine is nullptr"); - return -1; + return 0; } return nwebEngine_->SetSiteIsolationMode(mode); -- Gitee From d36559460971af9250e4185a607a7f03814b2adf Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Thu, 4 Sep 2025 09:45:05 +0800 Subject: [PATCH 090/124] site isolation Signed-off-by: quyue00807312 --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 6bd42a4fc..abfe62469 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -7852,7 +7852,7 @@ napi_value NapiWebviewController::SetSiteIsolationMode( napi_env env, napi_callback_info info) { WVLOG_I("set site isolation mode."); - if(IS_CALLING_FROM_M114()){ + if(IS_CALLING_FROM_M114()) { WVLOG_W("SetSiteIsolationMode unsupported engine version: M114"); BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: function SetSiteIsolationMode isn't existing"); @@ -7879,7 +7879,6 @@ napi_value NapiWebviewController::SetSiteIsolationMode( "BusinessError 401: Parameter error. The type of 'mode' must be int."); return result; } - WVLOG_I("NapiWebviewController::SetSiteIsolationMode: %{public}d", mode); if (mode < static_cast(SiteIsolationMode::PARTIAL) || mode > static_cast(SiteIsolationMode::STRICT)) { @@ -7895,19 +7894,16 @@ napi_value NapiWebviewController::SetSiteIsolationMode( if (res == INTEGER_FOUR) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: Site Isolation mode already set by developer"); - return result; } if (res == INTEGER_THREE) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: Site Isolation mode cannot be strict when single render"); - return result; } if (res == INTEGER_TWO) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: cannot change (AdvancedSecurityMode active)"); - return result; } return result; -- Gitee From 98435db259679160fa72327626b44077825db2a3 Mon Sep 17 00:00:00 2001 From: ahjxliubao Date: Thu, 4 Sep 2025 20:15:03 +0800 Subject: [PATCH 091/124] =?UTF-8?q?SystemPropertiesAdapterTest=E8=93=9D?= =?UTF-8?q?=E9=BB=84=E5=B7=AE=E5=BC=82=20IssueNo:#ICWG0N=20Description:=20?= =?UTF-8?q?Sig:=20SIG=5FApplicationFramework=20Feature=20or=20Bugfix:=20Fe?= =?UTF-8?q?ature=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuliubao --- .../system_properties_adapter_test.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/unittest/ohos_adapter/system_properties_adapter/system_properties_adapter_test.cpp b/test/unittest/ohos_adapter/system_properties_adapter/system_properties_adapter_test.cpp index 40d5340fd..7fea5393e 100644 --- a/test/unittest/ohos_adapter/system_properties_adapter/system_properties_adapter_test.cpp +++ b/test/unittest/ohos_adapter/system_properties_adapter/system_properties_adapter_test.cpp @@ -54,20 +54,20 @@ class SystemPropertiesObserverTest : public SystemPropertiesObserver { void PropertiesUpdate(const char* value) override { if (strcmp(value, "true") == 0) { - update_value_ = true; + updateValue = true; } else if (strcmp(value, "false") == 0) { - update_value_ = false; + updateValue = false; } else { WVLOG_E("SystemPropertiesObserverTest return value is invalid"); } } - bool UpdateValue() - { - return update_value_; - } + bool UpdateValue() + { + return updateValue; + } private: - bool update_value_ = false; + bool updateValue = false; }; /** @@ -115,17 +115,17 @@ HWTEST_F(SystemPropertiesAdapterTest, SystemPropertiesAdapterTest_OptSystemPrope auto observer = std::make_shared(); system_properties_adapter.AttachSysPropObserver(PropertiesKey::PROP_RENDER_DUMP, observer.get()); system("param set web.render.dump true"); - bool result_first = observer->UpdateValue(); - EXPECT_TRUE(result_first); + bool resultFirst = observer->UpdateValue(); + EXPECT_TRUE(resultFirst); system("param set web.render.dump false"); - bool result_second = observer->UpdateValue(); - EXPECT_FALSE(result_second); + bool resultSecond = observer->UpdateValue(); + EXPECT_FALSE(resultSecond); system_properties_adapter.DetachSysPropObserver(PropertiesKey::PROP_RENDER_DUMP, nullptr); system_properties_adapter.DetachSysPropObserver(PropertiesKey::PROP_RENDER_DUMP, observer.get()); system("param set web.render.dump true"); - bool result_third = observer->UpdateValue(); - EXPECT_FALSE(result_third); + bool resultThird = observer->UpdateValue(); + EXPECT_FALSE(resultThird); } /** -- Gitee From ad24fe66e7fcca2e53c998d272d1aab57543dda7 Mon Sep 17 00:00:00 2001 From: yueyang Date: Thu, 4 Sep 2025 13:43:27 +0000 Subject: [PATCH 092/124] =?UTF-8?q?=E8=B6=85=E9=87=8F=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yueyang --- interfaces/native/arkweb_interface.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/native/arkweb_interface.cpp b/interfaces/native/arkweb_interface.cpp index 53f1481c1..60b922f4b 100644 --- a/interfaces/native/arkweb_interface.cpp +++ b/interfaces/native/arkweb_interface.cpp @@ -152,7 +152,6 @@ static bool LoadComponentGlobalAPI() static bool LoadControllerAPI() { if (g_ControllerImpl) { - WVLOG_D("NativeArkWeb controller api already loaded"); return true; } g_ControllerImpl = new (std::nothrow) ArkWeb_ControllerAPI(); -- Gitee From 9b901fe6bfabcb3cff5d77261bbca109ab5d1d0b Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Thu, 4 Sep 2025 21:56:02 +0800 Subject: [PATCH 093/124] site isolation Signed-off-by: quyue00807312 --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 6 +++--- ohos_interface/include/ohos_nweb/nweb.h | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index abfe62469..f689982f0 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -7891,17 +7891,17 @@ napi_value NapiWebviewController::SetSiteIsolationMode( static_cast(mode)); WVLOG_I("NapiWebviewController::SetSiteIsolationMode res: %{public}d", res); - if (res == INTEGER_FOUR) { + if (res == static_cast(SetSiteIsolationModeErr::ALREADY_SET_ERR)) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: Site Isolation mode already set by developer"); } - if (res == INTEGER_THREE) { + if (res == static_cast(SetSiteIsolationModeErr::SINGLE_RENDER_SET_STRICT_ERR)) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: Site Isolation mode cannot be strict when single render"); } - if (res == INTEGER_TWO) { + if (res == static_cast(SetSiteIsolationModeErr::ADVANCED_SECURITY_SET_ERR)) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: cannot change (AdvancedSecurityMode active)"); } diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index cac2ae80f..5b303a9e4 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -174,6 +174,12 @@ enum class SiteIsolationMode { STRICT, }; +enum class SetSiteIsolationModeErr : int32_t { + ALREADY_SET_ERR = 4, + SINGLE_RENDER_SET_STRICT_ERR = 3, + ADVANCED_SECURITY_SET_ERR = 2, +}; + class NWebTouchPointInfo { public: virtual ~NWebTouchPointInfo() = default; -- Gitee From 156ac73d946a21c136813de6106e7f6eccb9012b Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Thu, 4 Sep 2025 22:07:04 +0800 Subject: [PATCH 094/124] site isolation Signed-off-by: quyue00807312 --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index f689982f0..e564f316f 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -7891,17 +7891,17 @@ napi_value NapiWebviewController::SetSiteIsolationMode( static_cast(mode)); WVLOG_I("NapiWebviewController::SetSiteIsolationMode res: %{public}d", res); - if (res == static_cast(SetSiteIsolationModeErr::ALREADY_SET_ERR)) { + if (res == static_cast(SetSiteIsolationModeErr::ALREADY_SET_ERR)) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: Site Isolation mode already set by developer"); } - if (res == static_cast(SetSiteIsolationModeErr::SINGLE_RENDER_SET_STRICT_ERR)) { + if (res == static_cast(SetSiteIsolationModeErr::SINGLE_RENDER_SET_STRICT_ERR)) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: Site Isolation mode cannot be strict when single render"); } - if (res == static_cast(SetSiteIsolationModeErr::ADVANCED_SECURITY_SET_ERR)) { + if (res == static_cast(SetSiteIsolationModeErr::ADVANCED_SECURITY_SET_ERR)) { BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, "InitError 17100001: cannot change (AdvancedSecurityMode active)"); } -- Gitee From 9b808bc6dc3de5ace5e9251d4aabee8d7dcf75dd Mon Sep 17 00:00:00 2001 From: wanglei Date: Fri, 5 Sep 2025 06:28:24 +0000 Subject: [PATCH 095/124] arkweb preload Signed-off-by: wanglei --- arkweb_utils/BUILD.gn | 6 ++ arkweb_utils/arkweb_preload.cpp | 27 +++++++ arkweb_utils/arkweb_preload.h | 34 +++++++++ arkweb_utils/arkweb_utils.cpp | 71 +++++++++++++++++++ arkweb_utils/arkweb_utils.h | 4 ++ .../arkweb_utils_test/arkweb_utils_test.cpp | 7 ++ 6 files changed, 149 insertions(+) create mode 100644 arkweb_utils/arkweb_preload.cpp create mode 100644 arkweb_utils/arkweb_preload.h diff --git a/arkweb_utils/BUILD.gn b/arkweb_utils/BUILD.gn index fd4cdf5b6..4f227a9ba 100644 --- a/arkweb_utils/BUILD.gn +++ b/arkweb_utils/BUILD.gn @@ -25,6 +25,7 @@ ohos_shared_library("libarkweb_utils") { sources = [ "arkweb_utils.cpp", + "arkweb_preload.cpp", ] cflags = [ @@ -46,10 +47,15 @@ ohos_shared_library("libarkweb_utils") { defines += [ "webview_x86_64" ] } + if (asan_detector || is_asan) { + defines += [ "ASAN_DETECTOR" ] + } + external_deps = [ "init:libbegetutil", "hilog:libhilog", "jsoncpp:jsoncpp", + "ace_engine:ace_forward_compatibility", ] include_dirs = [ diff --git a/arkweb_utils/arkweb_preload.cpp b/arkweb_utils/arkweb_preload.cpp new file mode 100644 index 000000000..024539b3c --- /dev/null +++ b/arkweb_utils/arkweb_preload.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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 "arkweb_preload.h" +#include "arkweb_utils.h" + +extern "C" void ProcessSpawnDlopenMsg() +{ + OHOS::ArkWeb::DlopenArkWebLib(); +} + +extern "C" int ProcessSpawnDlcloseMsg() +{ + return OHOS::ArkWeb::DlcloseArkWebLib(); +} \ No newline at end of file diff --git a/arkweb_utils/arkweb_preload.h b/arkweb_utils/arkweb_preload.h new file mode 100644 index 000000000..434251b9d --- /dev/null +++ b/arkweb_utils/arkweb_preload.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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 WEB_WEBVIEW_ARKWEB_UTILS_ARKWEB_PRELOAD_H +#define WEB_WEBVIEW_ARKWEB_UTILS_ARKWEB_PRELOAD_H + +#ifndef ARKWEB_EXPORT +#define ARKWEB_EXPORT __attribute__((visibility("default"))) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +ARKWEB_EXPORT void ProcessSpawnDlopenMsg(); + +ARKWEB_EXPORT int ProcessSpawnDlcloseMsg(); + +#ifdef __cplusplus +} +#endif + +#endif // WEB_WEBVIEW_ARKWEB_UTILS_ARKWEB_PRELOAD_H \ No newline at end of file diff --git a/arkweb_utils/arkweb_utils.cpp b/arkweb_utils/arkweb_utils.cpp index dea34ecd8..d4fdc9d62 100644 --- a/arkweb_utils/arkweb_utils.cpp +++ b/arkweb_utils/arkweb_utils.cpp @@ -22,6 +22,10 @@ #include #include +#if (defined(webview_arm64) && !defined(ASAN_DETECTOR)) +#include "ace_forward_compatibility.h" +#endif + namespace OHOS::ArkWeb { static int g_appEngineVersion = static_cast(ArkWebEngineVersion::SYSTEM_DEFAULT); @@ -86,6 +90,13 @@ const std::string JSON_CONFIG_PATH = "/data/service/el1/public/update/param_service/install/system/etc/ArkWebSafeBrowsing/generic/ArkWebCoreCfg.json"; const std::string WEB_PARAM_PREFIX = "web.engine."; +#if (defined(webview_arm64) && !defined(ASAN_DETECTOR)) +const int MAX_DLCLOSE_COUNT = 10; +const std::string LIB_ARKWEB_ENGINE = "libarkweb_engine.so"; +const std::string PERSIST_ARKWEBCORE_PACKAGE_NAME = "persist.arkwebcore.package_name"; +const std::string EL1_BUNDLE_PUBLIC = "/data/app/el1/bundle/public/"; +#endif + // 前向声明 static ArkWebEngineVersion CalculateActiveWebEngineVersion(); @@ -442,4 +453,64 @@ void* ArkWebBridgeHelperSharedInit(bool runMode) return libFileHandler; } + +void DlopenArkWebLib() +{ +#if (defined(webview_arm64) && !defined(ASAN_DETECTOR)) + const std::string bundleName = OHOS::system::GetParameter(PERSIST_ARKWEBCORE_PACKAGE_NAME, ""); + const std::string arkwebLibPath = EL1_BUNDLE_PUBLIC + bundleName + "/" + ARK_WEB_CORE_PATH_FOR_MOCK + + ":" + ARK_WEB_CORE_HAP_LIB_PATH; + WVLOG_I("DlopenArkWebLib arkwebLibPath: %{public}s", arkwebLibPath.c_str()); + void* libFileHandler = ArkWebBridgeHelperLoadLibFile( + RTLD_NOW | RTLD_GLOBAL, + "nweb_ns", + arkwebLibPath.c_str(), + LIB_ARKWEB_ENGINE.c_str() + ); + if (libFileHandler != nullptr) { + WVLOG_I("DlopenArkWebLib Start reclaim file cache"); + OHOS::Ace::AceForwardCompatibility::ReclaimFileCache(getpid()); + } +#endif +} + +#if (defined(webview_arm64) && !defined(ASAN_DETECTOR)) +static bool IsNWebLibLoaded(Dl_namespace dlns) +{ + void* handler = dlopen_ns(&dlns, LIB_ARKWEB_ENGINE.c_str(), RTLD_NOW | RTLD_NOLOAD); + if (handler) { + dlclose(handler); + return true; + } + return false; +} +#endif + +int DlcloseArkWebLib() +{ +#if (defined(webview_arm64) && !defined(ASAN_DETECTOR)) + Dl_namespace dlns; + if (dlns_get("nweb_ns", &dlns) != 0) { + WVLOG_I("Failed to get nweb_ns"); + return 0; + } + + void* webEngineHandle = dlopen_ns(&dlns, LIB_ARKWEB_ENGINE.c_str(), RTLD_NOW | RTLD_NOLOAD); + if (!webEngineHandle) { + WVLOG_E("FAILED to find %{public}s", LIB_ARKWEB_ENGINE.c_str(), dlerror()); + return 0; + } + + int cnt = MAX_DLCLOSE_COUNT; + do { + cnt--; + dlclose(webEngineHandle); + } while (cnt > 0 && IsNWebLibLoaded(dlns)); + + if (cnt == 0 && IsNWebLibLoaded(dlns)) { + return -1; + } +#endif + return 0; +} } \ No newline at end of file diff --git a/arkweb_utils/arkweb_utils.h b/arkweb_utils/arkweb_utils.h index 9d7480473..d34a3296d 100644 --- a/arkweb_utils/arkweb_utils.h +++ b/arkweb_utils/arkweb_utils.h @@ -90,6 +90,10 @@ ARKWEB_EXPORT void PreloadArkWebLibForBrowser(); ARKWEB_EXPORT void LogForUnsupportedFunc(ArkWebEngineVersion version, const char* msg); ARKWEB_EXPORT void* ArkWebBridgeHelperSharedInit(bool runMode = true); + +ARKWEB_EXPORT void DlopenArkWebLib(); +ARKWEB_EXPORT int DlcloseArkWebLib(); + } // namespace OHOS::ArkWeb #endif // WEB_WEBVIEW_ARKWEB_UTILS_ARKWEB_UTILS_H \ No newline at end of file diff --git a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp index 96c993a54..5ac4465c8 100644 --- a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp +++ b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp @@ -242,4 +242,11 @@ TEST(arkweb_utils_test, SelectWebcoreBeforeProcessRun002) { EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M132); OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } + +#if (defined(webview_arm64) && !defined(ASAN_DETECTOR)) +TEST(arkweb_utils_test, DlcloseArkWebLib001) { + int ret = DlcloseArkWebLib(); + EXPECT_EQ(ret, 0); +} +#endif } // namespace OHOS::NWeb \ No newline at end of file -- Gitee From 381b376f3718d0a9f73157b82b0e87935a37144b Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Fri, 5 Sep 2025 16:34:55 +0800 Subject: [PATCH 096/124] site isolation Signed-off-by: quyue00807312 --- ohos_interface/include/ohos_nweb/nweb.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 5b303a9e4..b7d43181a 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -175,9 +175,9 @@ enum class SiteIsolationMode { }; enum class SetSiteIsolationModeErr : int32_t { - ALREADY_SET_ERR = 4, - SINGLE_RENDER_SET_STRICT_ERR = 3, ADVANCED_SECURITY_SET_ERR = 2, + SINGLE_RENDER_SET_STRICT_ERR = 3, + ALREADY_SET_ERR = 4, }; class NWebTouchPointInfo { -- Gitee From b8cb360ecced37bf9f18e3c42cbe4caa7f3ccd5f Mon Sep 17 00:00:00 2001 From: liuao Date: Sat, 6 Sep 2025 08:17:56 +0800 Subject: [PATCH 097/124] 0906 update ArkWebCore.hap to 6.0 Signed-off-by: liuao --- ohos_nweb/prebuilts/arm/ArkWebCore.hap | 4 ++-- ohos_nweb/prebuilts/arm64/ArkWebCore.hap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ohos_nweb/prebuilts/arm/ArkWebCore.hap b/ohos_nweb/prebuilts/arm/ArkWebCore.hap index 136f74a3e..fa80f88a2 100644 --- a/ohos_nweb/prebuilts/arm/ArkWebCore.hap +++ b/ohos_nweb/prebuilts/arm/ArkWebCore.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7a2c94d016bffbcca431a73355ac74decb536d39347b39ab4a050aec326e9faf -size 116692452 +oid sha256:b43c7f2c8e2b0f4d6ad7fac936a0286ba08d9af2afd0bfcabee473568801ee4d +size 116737507 diff --git a/ohos_nweb/prebuilts/arm64/ArkWebCore.hap b/ohos_nweb/prebuilts/arm64/ArkWebCore.hap index c4ad995fc..b63ead6f7 100644 --- a/ohos_nweb/prebuilts/arm64/ArkWebCore.hap +++ b/ohos_nweb/prebuilts/arm64/ArkWebCore.hap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c826657314ac97b1268c206bc5c9626fac4f7e1f0bbcef95e5f276bd50273f91 -size 122521025 +oid sha256:1756edd2b829394cdf999e6232cc0e94767382148378bb7faeeecb8eb8e976e7 +size 122574271 -- Gitee From 230f14f26c1e5aa80ee50b1a94e73610944e08b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=9E=E5=AE=87=E6=88=90?= Date: Sat, 6 Sep 2025 11:21:15 +0800 Subject: [PATCH 098/124] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 庞宇成 --- interfaces/native/arkweb_scheme_handler.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/native/arkweb_scheme_handler.cpp b/interfaces/native/arkweb_scheme_handler.cpp index 3cf38891f..73c573d7c 100644 --- a/interfaces/native/arkweb_scheme_handler.cpp +++ b/interfaces/native/arkweb_scheme_handler.cpp @@ -124,7 +124,6 @@ void LoadSchemeHandlerApi(SchemeHandlerApi* api) bool EnsureSdkLoaded() { if (g_SchemeHandlerApi) { - WVLOG_I("SchemeHandlerApi had loaded."); return true; } -- Gitee From f3ca3d5da352516ee4aaa36dec96682cb9928f3e Mon Sep 17 00:00:00 2001 From: lizeqiang Date: Sat, 6 Sep 2025 19:30:23 +0800 Subject: [PATCH 099/124] delete arkweb_utils log Signed-off-by: lizeqiang --- arkweb_utils/arkweb_utils.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/arkweb_utils/arkweb_utils.cpp b/arkweb_utils/arkweb_utils.cpp index dea34ecd8..300fcc04f 100644 --- a/arkweb_utils/arkweb_utils.cpp +++ b/arkweb_utils/arkweb_utils.cpp @@ -210,7 +210,6 @@ void SetActiveWebEngineVersionInner(ArkWebEngineVersion version) ArkWebEngineVersion getActiveWebEngineVersion() { - WVLOG_I("getActiveWebEngineVersion: %{public}d", g_activeEngineVersion); return g_activeEngineVersion; } @@ -243,7 +242,6 @@ ArkWebEngineVersion CalculateActiveWebEngineVersion() return static_cast(ArkWebEngineType::EVERGREEN); } - WVLOG_I("CalculateActiveWebEngineVersion webEngineDefault: %{public}d", webEngineDefault); return static_cast(webEngineDefault); } @@ -352,7 +350,6 @@ std::string GetArkwebInstallPath() if (installPath == "") { WVLOG_E("failed to find hap path"); } - WVLOG_I("get arkweb install path: %{public}s", installPath.c_str()); return installPath; } -- Gitee From 9716f0083f915ce5ac5038636c8167eb8dd164e0 Mon Sep 17 00:00:00 2001 From: diao-gaoyang Date: Mon, 8 Sep 2025 11:08:21 +0800 Subject: [PATCH 100/124] add OnSafeBrowsingCheckFinish Signed-off-by: diao-gaoyang --- ohos_interface/include/ohos_nweb/nweb_handler.h | 6 ++++++ .../ohos_nweb/bridge/webcore/ark_web_handler_wrapper.cpp | 5 +++++ .../ohos_nweb/bridge/webcore/ark_web_handler_wrapper.h | 7 +++++++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.cpp | 5 +++++ .../ohos_nweb/bridge/webview/ark_web_handler_impl.h | 7 +++++++ .../ohos_glue/ohos_nweb/include/ark_web_handler.h | 8 ++++++++ 6 files changed, 38 insertions(+) diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index e31f121b0..9237e3c0c 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -1316,6 +1316,12 @@ public: * */ virtual void OnNativeEmbedObjectParamChange(std::shared_ptr paramDataInfo) {} + + /** + * @brief Called when received website security risk check finish. + * @param threat_type The threat type of website. + */ + virtual void OnSafeBrowsingCheckFinish(int threat_type) {} }; } // 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 0a391fa3a..4ad9974ce 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 @@ -1293,4 +1293,9 @@ void ArkWebHandlerWrapper::OnNativeEmbedObjectParamChange( ark_web_handler_->OnNativeEmbedObjectParamChange(new ArkWebNativeEmbedParamDataInfoImpl(paramDataInfo)); } + +void ArkWebHandlerWrapper::OnSafeBrowsingCheckFinish(int threat_type) +{ + ark_web_handler_->OnSafeBrowsingCheckFinish(threat_type); +} } // 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 cfe5ec8bb..9d009dee2 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 @@ -768,6 +768,13 @@ public: */ void OnNativeEmbedObjectParamChange( std::shared_ptr paramDataInfo) override; + + /** + * @brief Called when received website security risk check finish. + * + * @param threat_type The threat type of website. + */ + void OnSafeBrowsingCheckFinish(int threat_type) 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 394fb9daa..7588354f7 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 @@ -1128,4 +1128,9 @@ void ArkWebHandlerImpl::OnNativeEmbedObjectParamChange(ArkWebRefPtrOnNativeEmbedObjectParamChange(std::make_shared(data_info)); } + +void ArkWebHandlerImpl::OnSafeBrowsingCheckFinish(int threat_type) +{ + nweb_handler_->OnSafeBrowsingCheckFinish(threat_type); +} } // 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 43a042f80..7e5f5ab12 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 @@ -730,6 +730,13 @@ public: * */ void OnNativeEmbedObjectParamChange(ArkWebRefPtr data_info) override; + + /** + * @brief Called when received website security risk check finish. + * + * @param threat_type The threat type of website. + */ + void OnSafeBrowsingCheckFinish(int threat_type) 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 83ddff6e7..4d1018b68 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 @@ -1062,6 +1062,14 @@ public: */ /*--ark web()--*/ virtual void OnNativeEmbedObjectParamChange(ArkWebRefPtr data_info) = 0; + + /** + * @brief Called when received website security risk check finish. + * + * @param threat_type The threat type of website. + */ + /*--ark web()--*/ + virtual void OnSafeBrowsingCheckFinish(int threat_type) = 0; }; } // namespace OHOS::ArkWeb -- Gitee From e038e1f2375244bee7878d67902cfb28e42fc61d Mon Sep 17 00:00:00 2001 From: yueyang Date: Mon, 8 Sep 2025 03:16:15 +0000 Subject: [PATCH 101/124] =?UTF-8?q?=E8=93=9D=E9=BB=84=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7=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/native/arkweb_interface.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/native/arkweb_interface.cpp b/interfaces/native/arkweb_interface.cpp index 60b922f4b..53f1481c1 100644 --- a/interfaces/native/arkweb_interface.cpp +++ b/interfaces/native/arkweb_interface.cpp @@ -152,6 +152,7 @@ static bool LoadComponentGlobalAPI() static bool LoadControllerAPI() { if (g_ControllerImpl) { + WVLOG_D("NativeArkWeb controller api already loaded"); return true; } g_ControllerImpl = new (std::nothrow) ArkWeb_ControllerAPI(); -- Gitee From 039605b94769db162ea29c4c364ed48e0c88437c Mon Sep 17 00:00:00 2001 From: yjw Date: Mon, 8 Sep 2025 06:55:13 +0000 Subject: [PATCH 102/124] update ohos_adapter/media_adapter/src/media_codec_decoder_adapter_impl.cpp. Signed-off-by: yjw --- .../media_adapter/src/media_codec_decoder_adapter_impl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ohos_adapter/media_adapter/src/media_codec_decoder_adapter_impl.cpp b/ohos_adapter/media_adapter/src/media_codec_decoder_adapter_impl.cpp index a49f1877d..4257152aa 100644 --- a/ohos_adapter/media_adapter/src/media_codec_decoder_adapter_impl.cpp +++ b/ohos_adapter/media_adapter/src/media_codec_decoder_adapter_impl.cpp @@ -400,8 +400,7 @@ DecoderAdapterCode MediaCodecDecoderAdapterImpl::ReleaseOutputBufferDec(uint32_t WVLOG_E("MediaCodecDecoder release buffer[%{public}u] fail.", index); return DecoderAdapterCode::DECODER_ERROR; } - std::unique_lock lock(bufferMutex_); - bufferMap_.erase(index); + return DecoderAdapterCode::DECODER_OK; } -- Gitee From b123bb46dbdf6daf397434bf7732c4b7526b92ca Mon Sep 17 00:00:00 2001 From: yjw Date: Mon, 8 Sep 2025 06:59:04 +0000 Subject: [PATCH 103/124] update ohos_adapter/media_adapter/include/media_codec_decoder_adapter_impl.h. Signed-off-by: yjw --- .../media_adapter/include/media_codec_decoder_adapter_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/media_adapter/include/media_codec_decoder_adapter_impl.h b/ohos_adapter/media_adapter/include/media_codec_decoder_adapter_impl.h index 8f4650c10..91ec55111 100644 --- a/ohos_adapter/media_adapter/include/media_codec_decoder_adapter_impl.h +++ b/ohos_adapter/media_adapter/include/media_codec_decoder_adapter_impl.h @@ -90,7 +90,7 @@ public: private: OH_AVCodec* decoder_ = nullptr; std::shared_ptr callback_ = nullptr; - std::map bufferMap_; + std::map bufferMap_; // To manage the input buffer. std::mutex bufferMutex_; bool isHardwareDecode_ = true; bool isSecure_ = false; -- Gitee From d2a298443c264a8bdac946826e98e575f6163dfa Mon Sep 17 00:00:00 2001 From: wanglei Date: Mon, 8 Sep 2025 08:43:37 +0000 Subject: [PATCH 104/124] modify dlclose error log Signed-off-by: wanglei --- arkweb_utils/arkweb_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arkweb_utils/arkweb_utils.cpp b/arkweb_utils/arkweb_utils.cpp index 60a69ccc9..66e1a05fe 100644 --- a/arkweb_utils/arkweb_utils.cpp +++ b/arkweb_utils/arkweb_utils.cpp @@ -494,7 +494,7 @@ int DlcloseArkWebLib() void* webEngineHandle = dlopen_ns(&dlns, LIB_ARKWEB_ENGINE.c_str(), RTLD_NOW | RTLD_NOLOAD); if (!webEngineHandle) { - WVLOG_E("FAILED to find %{public}s", LIB_ARKWEB_ENGINE.c_str(), dlerror()); + WVLOG_E("FAILED to find %{public}s, error: %{public}s", LIB_ARKWEB_ENGINE.c_str(), dlerror()); return 0; } -- Gitee From 45d78bd0de482ab0b19a04a4b7b5e746e7e95bc8 Mon Sep 17 00:00:00 2001 From: liuzhijie2 Date: Mon, 8 Sep 2025 16:55:12 +0800 Subject: [PATCH 105/124] set socket idle timeout Signed-off-by: liuzhijie2 --- .../ani/webview/ets/@ohos.web.webview.ets | 1 + .../ani_webview_controller.cpp | 16 ++++ .../napi_webview_controller.cpp | 38 +++++++++- .../napi_webview_controller.h | 1 + .../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 | 5 ++ ohos_nweb/src/nweb_helper.cpp | 22 ++++++ .../nweb_helper_test/nweb_helper_ex_test.cpp | 73 ++++++++++++++++++- 13 files changed, 173 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets b/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets index 214d0b8ae..bf339388a 100644 --- a/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets +++ b/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets @@ -189,6 +189,7 @@ export default namespace webview { native clearHistory(): void; native clearWebSchemeHandler(): void; native innerCompleteWindowNew(parentNwebId:int): void; + native setSocketIdleTimeout(timeout: int): void; innerGetThisVar(): long { return this.nativePtr; } diff --git a/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp b/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp index 3052438aa..e304a6449 100644 --- a/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp +++ b/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp @@ -68,6 +68,9 @@ namespace NWeb { using namespace NWebError; using NWebError::NO_ERROR; namespace { +constexpr int32_t MIN_SOCKET_IDLE_TIMEOUT = 30; +constexpr int32_t MAX_SOCKET_IDLE_TIMEOUT = 300; + bool ParseResourceRawfileUrl(ani_env *env, const ani_object& object, std::string& fileName) { ani_ref paramsRef; @@ -1379,6 +1382,18 @@ static void InnerCompleteWindowNew(ani_env* env, ani_object object, ani_int pare controller->InnerCompleteWindowNew(parentNWebId); } +static void SetSocketIdleTimeout(ani_env* env, ani_object object, ani_int timeout) +{ + if (env == nullptr) { + WVLOG_E("env is nullptr"); + return; + } + + int32_t socketIdleTimeout = + std::clamp(static_cast(timeout), MIN_SOCKET_IDLE_TIMEOUT, MAX_SOCKET_IDLE_TIMEOUT); + NWebHelper::Instance().SetSocketIdleTimeout(socketIdleTimeout); +} + ani_status StsWebviewControllerInit(ani_env *env) { if (env == nullptr) { @@ -1436,6 +1451,7 @@ ani_status StsWebviewControllerInit(ani_env *env) ani_native_function { "clearHistory", nullptr, reinterpret_cast(ClearHistory) }, ani_native_function { "clearWebSchemeHandler", nullptr, reinterpret_cast(ClearWebSchemeHandler) }, ani_native_function { "innerCompleteWindowNew", nullptr, reinterpret_cast(InnerCompleteWindowNew) }, + ani_native_function { "setSocketIdleTimeout", nullptr, reinterpret_cast(SetSocketIdleTimeout) }, }; status = env->Class_BindNativeMethods(webviewControllerCls, controllerMethods.data(), controllerMethods.size()); diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index e564f316f..fd8f413fe 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -81,6 +81,8 @@ constexpr double SCALE_MAX = 2.0; constexpr double HALF = 2.0; constexpr double TEN_MILLIMETER_TO_INCH = 0.39; constexpr const char* EVENT_ATTACH_STATE_CHANGE = "controllerAttachStateChange"; +constexpr int32_t MIN_SOCKET_IDLE_TIMEOUT = 30; +constexpr int32_t MAX_SOCKET_IDLE_TIMEOUT = 300; using WebPrintWriteResultCallback = std::function; bool ParsePrepareUrl(napi_env env, napi_value urlObj, std::string& url) @@ -828,6 +830,7 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_FUNCTION("isActiveWebEngineEvergreen", NapiWebviewController::IsActiveWebEngineEvergreen), DECLARE_NAPI_STATIC_FUNCTION("setAutoPreconnect", NapiWebviewController::SetAutoPreconnect), DECLARE_NAPI_STATIC_FUNCTION("isAutoPreconnectEnabled", NapiWebviewController::IsAutoPreconnectEnabled), + DECLARE_NAPI_STATIC_FUNCTION("setSocketIdleTimeout", NapiWebviewController::SetSocketIdleTimeout), }; napi_value constructor = nullptr; napi_define_class(env, WEBVIEW_CONTROLLER_CLASS_NAME.c_str(), WEBVIEW_CONTROLLER_CLASS_NAME.length(), @@ -7808,13 +7811,14 @@ napi_value NapiWebviewController::SetAutoPreconnect(napi_env env, napi_callback_ WVLOG_W("SetAutoPreconnect unsupported engine version: M114"); return nullptr; } + napi_value thisVar = nullptr; napi_value result = nullptr; size_t argc = INTEGER_ONE; napi_value argv[INTEGER_ONE] = { 0 }; - NAPI_CALL(env, 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")); @@ -7924,5 +7928,37 @@ napi_value NapiWebviewController::GetSiteIsolationMode( WVLOG_I("NapiWebviewController::GetSiteIsolationMode result: %{public}d", mode); return result; } + +napi_value NapiWebviewController::SetSocketIdleTimeout(napi_env env, napi_callback_info info) +{ + if (IS_CALLING_FROM_M114()) { + WVLOG_W("SetSocketIdleTimeout unsupported engine version: M114"); + return nullptr; + } + + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + NAPI_CALL(env, 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; + } + + int32_t socketIdleTimeout = 0; + if (!NapiParseUtils::ParseInt32(env, argv[0], socketIdleTimeout)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "socketIdleTimeout", "number")); + return result; + } + + socketIdleTimeout = std::clamp(socketIdleTimeout, MIN_SOCKET_IDLE_TIMEOUT, MAX_SOCKET_IDLE_TIMEOUT); + NWebHelper::Instance().SetSocketIdleTimeout(socketIdleTimeout); + 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 a30b42c7f..d34fd7227 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -424,6 +424,7 @@ private: static napi_value IsActiveWebEngineEvergreen(napi_env env, napi_callback_info info); static napi_value SetAutoPreconnect(napi_env env, napi_callback_info info); static napi_value IsAutoPreconnectEnabled(napi_env env, napi_callback_info info); + static napi_value SetSocketIdleTimeout(napi_env env, napi_callback_info info); }; class ArkWebTransfer { diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 4b6d5a570..5b23cc06b 100644 --- a/ohos_interface/include/ohos_nweb/nweb_engine.h +++ b/ohos_interface/include/ohos_nweb/nweb_engine.h @@ -137,6 +137,8 @@ public: } virtual void SetWebDestroyMode(WebDestroyMode mode) {} + + virtual void SetSocketIdleTimeout(int32_t timeout) {} }; } // 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 862c9f594..a7abe5dd8 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 @@ -327,4 +327,9 @@ int32_t ArkWebEngineImpl::GetSiteIsolationMode() return static_cast(nweb_engine_->GetSiteIsolationMode()); } +void ArkWebEngineImpl::SetSocketIdleTimeout(int32_t timeout) +{ + nweb_engine_->SetSocketIdleTimeout(timeout); +} + } // 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 f55d6500e..0db19f26e 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 @@ -124,6 +124,8 @@ public: int32_t GetSiteIsolationMode() override; + void SetSocketIdleTimeout(int32_t timeout) 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 097bd7eea..3951a4e9c 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 @@ -383,4 +383,9 @@ ArkWebSiteIsolationMode ArkWebEngineWrapper::GetSiteIsolationMode() return static_cast(res); } +void ArkWebEngineWrapper::SetSocketIdleTimeout(int32_t timeout) +{ + ark_web_engine_->SetSocketIdleTimeout(timeout); +} + } // 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 8c95d2044..926124fa4 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 @@ -125,6 +125,8 @@ public: ArkWebSiteIsolationMode GetSiteIsolationMode() override; + void SetSocketIdleTimeout(int32_t timeout) 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 f58a4db2b..b8b84ea1c 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 @@ -200,6 +200,9 @@ public: /*--ark web()--*/ virtual int32_t GetSiteIsolationMode() = 0; + + /*--ark web()--*/ + virtual void SetSocketIdleTimeout(int32_t timeout) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index 30a1d52ab..8219dd7a7 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -162,6 +162,10 @@ public: SiteIsolationMode GetSiteIsolationMode(); + void SetSocketIdleTimeout(int32_t timeout); + + int32_t GetSocketIdleTimeout(); + private: NWebHelper() = default; bool GetWebEngine(bool fromArk); @@ -169,6 +173,7 @@ private: private: int coreApiLevel_ = 0; + int32_t socketIdleTimeout_ = 300; bool initFlag_ = false; bool autoPreconnectEnabled_ = true; std::string bundlePath_; diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index b57beaf28..d4c1716df 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -753,6 +753,8 @@ bool NWebHelper::InitWebEngine() initArgs->AddArg(std::string("--disable-auto-preconnect")); } + initArgs->AddArg(std::string("--socket-idle-timeout=").append(std::to_string(socketIdleTimeout_))); + nwebEngine_->InitializeWebEngine(initArgs); initFlag_ = true; @@ -1230,6 +1232,8 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(sptr surface, if (!NWebHelper::Instance().IsAutoPreconnectEnabled()) { initArgs->AddArg(std::string("--disable-auto-preconnect")); } + std::string socketIdleTimeout = std::to_string(NWebHelper::Instance().GetSocketIdleTimeout()); + initArgs->AddArg(std::string("--socket-idle-timeout=").append(socketIdleTimeout)); auto createInfo = NWebSurfaceAdapter::Instance().GetCreateInfo(surface, initArgs, width, height, incognitoMode); NWebConfigHelper::Instance().ParseConfig(initArgs); @@ -1268,6 +1272,8 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(void* enhanceSurfaceInfo, if (!NWebHelper::Instance().IsAutoPreconnectEnabled()) { initArgs->AddArg(std::string("--disable-auto-preconnect")); } + std::string socketIdleTimeout = std::to_string(NWebHelper::Instance().GetSocketIdleTimeout()); + initArgs->AddArg(std::string("--socket-idle-timeout=").append(socketIdleTimeout)); auto createInfo = NWebEnhanceSurfaceAdapter::Instance().GetCreateInfo(enhanceSurfaceInfo, initArgs, width, height, incognitoMode); auto nweb = NWebHelper::Instance().CreateNWeb(createInfo); @@ -1385,4 +1391,20 @@ bool NWebHelper::IsAutoPreconnectEnabled() return autoPreconnectEnabled_; } +void NWebHelper::SetSocketIdleTimeout(int32_t timeout) +{ + if (nwebEngine_ == nullptr) { + WVLOG_E("web engine is nullptr"); + socketIdleTimeout_ = timeout; + return; + } + + nwebEngine_->SetSocketIdleTimeout(timeout); +} + +int32_t NWebHelper::GetSocketIdleTimeout() +{ + return socketIdleTimeout_; +} + } // namespace OHOS::NWeb diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index dfd0d7378..f1f674896 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -167,6 +167,8 @@ public: return false; } + void SetSocketIdleTimeout(int32_t timeout) {} + MOCK_METHOD(void, SetWebDebuggingAccessAndPort, (bool isEnableDebug, int32_t port), (override)); @@ -945,7 +947,7 @@ HWTEST_F(NwebHelperTest, NWebHelper_IsPrivateNetworkAccessEnabled_001, TestSize. /** * @tc.name: NWebHelper_SetAutoPreconnect_001 - * @tc.desc: SetAutoPreconnect.. + * @tc.desc: SetAutoPreconnect. * @tc.type: FUNC * @tc.require: */ @@ -960,5 +962,74 @@ HWTEST_F(NwebHelperTest, NWebHelper_SetAutoPreconnect_001, TestSize.Level1) NWebHelper::Instance().SetAutoPreconnect(false); EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, false); } + +/** + * @tc.name: NWebHelper_IsAutoPreconnectEnabled_001 + * @tc.desc: IsAutoPreconnectEnabled. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_IsAutoPreconnectEnabled_001, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + EXPECT_EQ(nwebHelper, nullptr); + + NWebHelper::Instance().autoPreconnectEnabled_ = true; + EXPECT_EQ(NWebHelper::Instance().IsAutoPreconnectEnabled(), true); + NWebHelper::Instance().autoPreconnectEnabled_ = false; + EXPECT_EQ(NWebHelper::Instance().IsAutoPreconnectEnabled(), false); +} + +/** + * @tc.name: NWebHelper_SetSocketIdleTimeout_001 + * @tc.desc: SetSocketIdleTimeout. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_SetSocketIdleTimeout_001, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + NWebHelper::Instance().nwebEngine_ = nullptr; + EXPECT_EQ(NWebHelper::Instance().nwebEngine_, nullptr); + + NWebHelper::Instance().SetSocketIdleTimeout(100); + EXPECT_EQ(NWebHelper::Instance().socketIdleTimeout_, 100); +} + +/** + * @tc.name: NWebHelper_SetSocketIdleTimeout_002 + * @tc.desc: SetSocketIdleTimeout. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_SetSocketIdleTimeout_002, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + auto nwebEngineMock = std::make_shared(); + NWebHelper::Instance().nwebEngine_ = nwebEngineMock; + EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); + + NWebHelper::Instance().SetSocketIdleTimeout(100); + EXPECT_EQ(NWebHelper::Instance().socketIdleTimeout_, 300); +} + +/** + * @tc.name: NWebHelper_GetSocketIdleTimeout_001 + * @tc.desc: GetSocketIdleTimeout. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_GetSocketIdleTimeout_001, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + EXPECT_EQ(nwebHelper, nullptr); + + NWebHelper::Instance().SetSocketIdleTimeout(100); + EXPECT_EQ(NWebHelper::Instance().GetSocketIdleTimeout(), 100); +} } // namespace OHOS::NWeb } -- Gitee From f11810d9c1346085816329444d35628617862ee4 Mon Sep 17 00:00:00 2001 From: liuxiao_310 Date: Sun, 7 Sep 2025 10:29:06 +0800 Subject: [PATCH 106/124] runtime native message callback and disconnect Signed-off-by: liuxiao_310 --- interfaces/kits/napi/js/webview_export.js | 86 +++++++++++++++++++ ohos_glue/BUILD.gn | 9 ++ ohos_interface/BUILD.gn | 8 ++ .../include/ohos_nweb/nweb_handler.h | 22 +++++ .../ohos_nweb/nweb_native_message_callback.h | 33 +++++++ .../ohos_nweb/nweb_runtime_connect_info.h | 34 ++++++++ ohos_interface/ohos_glue/BUILD_webcore.gn | 8 ++ .../base/include/ark_web_bridge_types.h | 2 + .../webcore/ark_web_handler_wrapper.cpp | 27 ++++++ .../bridge/webcore/ark_web_handler_wrapper.h | 18 ++++ .../ark_web_native_message_callback_impl.cpp | 49 +++++++++++ .../ark_web_native_message_callback_impl.h | 42 +++++++++ .../ark_web_runtime_connect_info_impl.cpp | 46 ++++++++++ .../ark_web_runtime_connect_info_impl.h | 66 ++++++++++++++ .../bridge/webview/ark_web_handler_impl.cpp | 22 ++++- .../bridge/webview/ark_web_handler_impl.h | 17 ++++ ...rk_web_native_message_callback_wrapper.cpp | 42 +++++++++ .../ark_web_native_message_callback_wrapper.h | 42 +++++++++ .../ark_web_runtime_connect_info_wrapper.cpp | 51 +++++++++++ .../ark_web_runtime_connect_info_wrapper.h | 41 +++++++++ .../ohos_nweb/include/ark_web_handler.h | 20 +++++ .../include/ark_web_native_message_callback.h | 40 +++++++++ .../include/ark_web_runtime_connect_info.h | 60 +++++++++++++ 23 files changed, 784 insertions(+), 1 deletion(-) create mode 100644 ohos_interface/include/ohos_nweb/nweb_native_message_callback.h create mode 100644 ohos_interface/include/ohos_nweb/nweb_runtime_connect_info.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_message_callback_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_message_callback_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_runtime_connect_info_impl.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_runtime_connect_info_impl.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.cpp create mode 100644 ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_message_callback.h create mode 100644 ohos_interface/ohos_glue/ohos_nweb/include/ark_web_runtime_connect_info.h diff --git a/interfaces/kits/napi/js/webview_export.js b/interfaces/kits/napi/js/webview_export.js index b943813e3..ea6460473 100644 --- a/interfaces/kits/napi/js/webview_export.js +++ b/interfaces/kits/napi/js/webview_export.js @@ -24,6 +24,9 @@ let camera = requireNapi('multimedia.camera'); let accessControl = requireNapi('abilityAccessCtrl'); let deviceinfo = requireInternal('deviceInfo'); let promptAction = requireNapi('promptAction'); +let dataShare = requireNapi('data.dataShare'); +let webNativeMessagingExtensionManager = requireNapi('web.webnativemessagingextensionmanager_napi'); + const PARAM_CHECK_ERROR = 401; const ERROR_MSG_INVALID_PARAM = 'Invalid input parameter'; @@ -438,6 +441,29 @@ function selectPicture(param, selectResult) { } } +function getManifestData(bundleName, callback) { + + dataShare.createDataProxyHandle().then((dsProxyHelper) => { + const urisToGet = + [`datashareproxy://${bundleName}/browserNativeMessagingHosts`]; + const config = { + type: dataShare.DataProxyType.SHARED_CONFIG, + }; + dsProxyHelper.get(urisToGet, config).then((results) => { + results.forEach((result) => { + callback(result.value); + }); + }).catch((error) => { + callback(undefined); + console.error('getManifestData, error getting config:', JSON.stringify(error)); + }); + }).catch((error) => { + callback(undefined); + console.error('getManifestData, error creating DataProxyHandle:', JSON.stringify(error)); + }); +} + + Object.defineProperty(webview.WebviewController.prototype, 'getCertificate', { value: function (callback) { if (arguments.length !== 0 && arguments.length !== 1) { @@ -553,4 +579,64 @@ Object.defineProperty(webview.WebviewController.prototype, 'openAppLink', { } }); +Object.defineProperty(webview.WebviewController.prototype, 'innerWebNativeMessageManager', { + value: function (callback) { + console.info('Web deal native messaging '); + try { + getManifestData(callback.bundleName, (result) => { + if (!result) { + callback.result.onFailed(4001); + return; + } + const infoByJson = JSON.parse(result); + if (!infoByJson || !infoByJson.allowed_origins) { + callback.result.onFailed(infoByJson ? 4002 : 4101); + return; + } + if (!infoByJson.allowed_origins.includes(callback.extensionOrigin)) { + callback.result.onFailed(4003); + return; + } + const pathByJson = JSON.parse(infoByJson.path); + if (!pathByJson) { + callback.result.onFailed(4102); + return; + } + let wantInfo = { + bundleName: pathByJson.bundleName, + abilityName: pathByJson.abilityName, + parameters: { + 'ohos.arkweb.messageReadPipe': { 'type': 'FD', 'value': callback.readPipe }, + 'ohos.arkweb.messageWritePipe': { 'type': 'FD', 'value': callback.writePipe }, + 'ohos.arkweb.extensionOrigin': callback.extensionOrigin + }, + }; + let options = { + onConnect(connection) { + callback.result.onConnect(connection.connectionId); + }, + onDisconnect(connection) { + callback.result.onDisconnect(connection.connectionId); + }, + onFailed(code) { + console.error(`messaging onFailed callback, code: ${code}`); + callback.result.onFailed(code); + } + }; + webNativeMessagingExtensionManager.connectNative(getContext(this), wantInfo, options); + }); + } catch (err) { + console.log(`messaging error : ${JSON.stringify(err)}`); + } + } +}); + +Object.defineProperty(webview.WebviewController.prototype, 'innerNativeMessageDisconnect', { + value: function (callback) { + let connectId = callback.connectId; + console.log(`Messaging disconnect connectId= ${connectId}`); + webNativeMessagingExtensionManager.disconnectNative(connectId); + } +}); + export default webview; diff --git a/ohos_glue/BUILD.gn b/ohos_glue/BUILD.gn index e1523c518..0e6c60dc9 100644 --- a/ohos_glue/BUILD.gn +++ b/ohos_glue/BUILD.gn @@ -491,6 +491,14 @@ action("ohos_glue_nweb_prepare") { "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_web_storage_origin_vector_ctocpp.h", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_ads_block_manager_ctocpp.cpp", "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_ads_block_manager_ctocpp.h", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_message_callback_ctocpp.cpp", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_native_message_callback_ctocpp.h", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_runtime_connect_info_ctocpp.cpp", + "${glue_build_gen_dir}/ohos_nweb/ctocpp/ark_web_runtime_connect_info_ctocpp.h", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_message_callback_wrapper.cpp", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_native_message_callback_wrapper.h", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_runtime_connect_info_wrapper.cpp", + "${glue_build_gen_dir}/ohos_nweb/bridge/ark_web_runtime_connect_info_wrapper.h", ] deps = [ @@ -1103,6 +1111,7 @@ action("ohos_glue_adapter_prepare") { "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_video_info_adapter_ctocpp.h", "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_vpn_listener_ctocpp.cpp", "${glue_build_gen_dir}/ohos_adapter/ctocpp/ark_vpn_listener_ctocpp.h", + ] deps = [ diff --git a/ohos_interface/BUILD.gn b/ohos_interface/BUILD.gn index e270cfb0e..d89a058ea 100644 --- a/ohos_interface/BUILD.gn +++ b/ohos_interface/BUILD.gn @@ -57,6 +57,8 @@ action("webview_interface_prepare") { "//base/web/webview/ohos_interface/include/ohos_nweb/nweb_data_resubmission_callback.h", "//base/web/webview/ohos_interface/include/ohos_nweb/nweb_javascript_result_callback.h", "//base/web/webview/ohos_interface/include/ohos_nweb/nweb_app_link_callback.h", + "//base/web/webview/ohos_interface/include/ohos_nweb/nweb_native_message_callback.h", + "//base/web/webview/ohos_interface/include/ohos_nweb/nweb_runtime_connect_info.h", "//base/web/webview/ohos_interface/include/ohos_nweb/nweb_custom_keyboard_handler.h", "//base/web/webview/ohos_interface/include/ohos_nweb/nweb_date_time_chooser.h", "//base/web/webview/ohos_interface/include/ohos_nweb/nweb_export.h", @@ -213,6 +215,8 @@ action("webview_glue_nweb_prepare") { "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_history_list.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_drag_event.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_url_resource_response.h", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_message_callback.h", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_runtime_connect_info.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_date_time_suggestion.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_message_value_callback.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_select_popup_menu_callback.h", @@ -354,6 +358,8 @@ action("webview_glue_nweb_prepare") { "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_js_proxy_method_impl.cpp", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_keyboard_event_impl.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_app_link_callback_wrapper.h", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.h", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_history_item_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_console_log_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_bool_value_callback_impl.cpp", @@ -433,6 +439,8 @@ action("webview_glue_nweb_prepare") { "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_js_ssl_error_result_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_touch_handle_hot_zone_wrapper.h", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_app_link_callback_wrapper.cpp", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.cpp", + "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.cpp", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_cursor_info_wrapper.cpp", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_spanstring_convert_html_callback_impl.cpp", "//base/web/webview/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_screen_capture_config_impl.h", diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index e31f121b0..1a2dc4c8c 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -48,6 +48,8 @@ #include "nweb_url_resource_error.h" #include "nweb_url_resource_request.h" #include "nweb_url_resource_response.h" +#include "nweb_native_message_callback.h" +#include "nweb_runtime_connect_info.h" namespace OHOS::NWeb { @@ -1316,6 +1318,26 @@ public: * */ virtual void OnNativeEmbedObjectParamChange(std::shared_ptr paramDataInfo) {} + + /** + * @brief Triggered when the webExtensions-native host connection terminates. + * + * @param connectId The id of the connection. + */ + virtual void OnExtensionDisconnect(int32_t connectId) {} + + /** + * @brief Initiates webExtensions-native messaging requests and handles corresponding callbacks + * + * @param info The runtime's message connect info. + * @param callback Response handler for processing asynchronous replies from native host. + * @return Returns connection status. + */ + virtual std::string OnWebNativeMessage( + std::shared_ptr info, std::shared_ptr callback) + { + return ""; + } }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_native_message_callback.h b/ohos_interface/include/ohos_nweb/nweb_native_message_callback.h new file mode 100644 index 000000000..4a0743a70 --- /dev/null +++ b/ohos_interface/include/ohos_nweb/nweb_native_message_callback.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_MESSAGE_CALLBACK_H +#define NWEB_NATIVE_MESSAGE_CALLBACK_H + +#include "nweb_export.h" +#include +namespace OHOS::NWeb { +class OHOS_NWEB_EXPORT NWebNativeMessageCallback { +public: + virtual ~NWebNativeMessageCallback() = default; + + virtual void OnConnect(int nativeInfo) = 0; + virtual void OnDisconnect(int nativeInfo) = 0; + virtual void OnFailed(int code) = 0; +}; + +} // namespace OHOS::NWeb + +#endif // NWEB_NATIVE_MESSAGE_CALLBACK_H diff --git a/ohos_interface/include/ohos_nweb/nweb_runtime_connect_info.h b/ohos_interface/include/ohos_nweb/nweb_runtime_connect_info.h new file mode 100644 index 000000000..59cdbe670 --- /dev/null +++ b/ohos_interface/include/ohos_nweb/nweb_runtime_connect_info.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_RUNTIME_CONNECT_INFO_H +#define NWEB_RUNTIME_CONNECT_INFO_H + +#include + +#include "nweb_export.h" +namespace OHOS::NWeb { +class OHOS_NWEB_EXPORT NWebRuntimeConnectInfo { +public: + virtual ~NWebRuntimeConnectInfo() = default; + + virtual std::string GetBundleName() = 0; + virtual std::string GetExtensionOrigin() = 0; + virtual int GetMessageReadPipe() = 0; + virtual int GetMessageWritePipe() = 0; +}; +} // namespace OHOS::NWeb + +#endif // NWEB_RUNTIME_CONNECT_INFO_H diff --git a/ohos_interface/ohos_glue/BUILD_webcore.gn b/ohos_interface/ohos_glue/BUILD_webcore.gn index ab130591a..71683566a 100644 --- a/ohos_interface/ohos_glue/BUILD_webcore.gn +++ b/ohos_interface/ohos_glue/BUILD_webcore.gn @@ -488,6 +488,14 @@ component("ohos_nweb_glue_source") { "ohos_nweb/ctocpp/ark_web_web_storage_origin_vector_value_callback_ctocpp.h", "ohos_nweb/ctocpp/ark_web_proxy_changed_callback_ctocpp.h", "ohos_nweb/ctocpp/ark_web_proxy_changed_callback_ctocpp.cpp", + "ohos_nweb/cpptoc/ark_web_native_message_callback_cpptoc.cpp", + "ohos_nweb/cpptoc/ark_web_native_message_callback_cpptoc.h", + "ohos_nweb/cpptoc/ark_web_runtime_connect_info_cpptoc.cpp", + "ohos_nweb/cpptoc/ark_web_runtime_connect_info_cpptoc.h", + "ohos_nweb/bridge/ark_web_native_message_callback_impl.cpp", + "ohos_nweb/bridge/ark_web_native_message_callback_impl.h", + "ohos_nweb/bridge/ark_web_runtime_connect_info_impl.cpp", + "ohos_nweb/bridge/ark_web_runtime_connect_info_impl.h", ] deps = [ "//ohos_glue:ohos_base_glue_source" ] 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 0ff6e070c..16d0663d7 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 @@ -126,6 +126,8 @@ enum ArkWebBridgeType { ARK_WEB_STYLUS_TOUCH_POINT_INFO = 104, ARK_WEB_NATIVE_EMBED_PARAM_DATA_INFO = 105, ARK_WEB_NATIVE_EMBED_PARAM_ITEM = 106, + ARK_WEB_NATIVE_MESSAGE_CALLBACK = 107, + ARK_WEB_RUNTIME_CONNECT_INFO = 108, /*Note: The end of nweb interface bridge type*/ ARK_WEB_NWEB_INTERFACE_BUTT, 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 0a391fa3a..5ff6ea926 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 @@ -57,6 +57,8 @@ #include "ohos_nweb/bridge/ark_web_url_resource_request_impl.h" #include "ohos_nweb/bridge/ark_web_url_resource_response_impl.h" #include "ohos_nweb/cpptoc/ark_web_date_time_suggestion_vector_cpptoc.h" +#include "ohos_nweb/bridge/ark_web_native_message_callback_impl.h" +#include "ohos_nweb/bridge/ark_web_runtime_connect_info_impl.h" #include "base/bridge/ark_web_bridge_macros.h" @@ -1293,4 +1295,29 @@ void ArkWebHandlerWrapper::OnNativeEmbedObjectParamChange( ark_web_handler_->OnNativeEmbedObjectParamChange(new ArkWebNativeEmbedParamDataInfoImpl(paramDataInfo)); } + +void ArkWebHandlerWrapper::OnExtensionDisconnect(int32_t connectId) +{ + ark_web_handler_->OnExtensionDisconnect(connectId); +} + +std::string ArkWebHandlerWrapper::OnWebNativeMessage(std::shared_ptr info, + std::shared_ptr callback) +{ + ArkWebRefPtr nweb_connect_info = nullptr; + if (!CHECK_SHARED_PTR_IS_NULL(info)) { + nweb_connect_info = new ArkWebRuntimeConnectInfoImpl(info); + } + + if (CHECK_SHARED_PTR_IS_NULL(callback)) { + ark_web_handler_->OnWebNativeMessage(nweb_connect_info, nullptr); + return ""; + } + + ArkWebString result = + ark_web_handler_->OnWebNativeMessage(nweb_connect_info, new ArkWebNativeMessageCallbackImpl(callback)); + std::string connectInfo = ArkWebStringStructToClass(result); + ArkWebStringStructRelease(result); + return connectInfo; +} } // 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 cfe5ec8bb..4347da25f 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 @@ -768,6 +768,24 @@ public: */ void OnNativeEmbedObjectParamChange( std::shared_ptr paramDataInfo) override; + + /** + * @brief Triggered when the webExtensions-native host connection terminates. + * + * @param connectId The id of the connection. + */ + void OnExtensionDisconnect(int32_t connectId) override; + + /** + * @brief Initiates webExtensions-native messaging requests and handles corresponding callbacks + * + * @param info The runtime's message connect info. + * @param callback Response handler for processing asynchronous replies from native host. + * @return Returns connection status. + */ + std::string OnWebNativeMessage(std::shared_ptr info, + std::shared_ptr callback) override; + private: ArkWebRefPtr ark_web_handler_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_message_callback_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_message_callback_impl.cpp new file mode 100644 index 000000000..adde60690 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_message_callback_impl.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_native_message_callback_impl.h" + +#include "include/nweb_native_message_callback.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebNativeMessageCallbackImpl::ArkWebNativeMessageCallbackImpl( + std::shared_ptr callback) + : callback_(callback) +{} + +void ArkWebNativeMessageCallbackImpl::OnConnect(const int connection) +{ + if (callback_) { + callback_->OnConnect(connection); + } +} + +void ArkWebNativeMessageCallbackImpl::OnDisconnect(const int connection) +{ + if (callback_) { + callback_->OnDisconnect(connection); + } +} + +void ArkWebNativeMessageCallbackImpl::OnFailed(const int code) +{ + if (callback_) { + callback_->OnFailed(code); + } +} +} // namespace OHOS::ArkWeb \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_message_callback_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_message_callback_impl.h new file mode 100644 index 000000000..f7a5df3c4 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_native_message_callback_impl.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_MESSAGE_CALLBACK_IMPL_H_ +#define ARK_WEB_NATIVE_MESSAGE_CALLBACK_IMPL_H_ +#pragma once + +#include "include/nweb_native_message_callback.h" +#include "ohos_nweb/include/ark_web_native_message_callback.h" + +namespace OHOS::ArkWeb { + +class ArkWebNativeMessageCallbackImpl : public ArkWebNativeMessageCallback { + IMPLEMENT_REFCOUNTING(ArkWebNativeMessageCallbackImpl); + +public: + ArkWebNativeMessageCallbackImpl(std::shared_ptr callback); + ~ArkWebNativeMessageCallbackImpl() = default; + + void OnConnect(const int connection) override; + void OnDisconnect(const int connection) override; + void OnFailed(const int code) override; + +private: + std::shared_ptr callback_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_MESSAGE_CALLBACK_IMPL_H_ \ No newline at end of file diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_runtime_connect_info_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_runtime_connect_info_impl.cpp new file mode 100644 index 000000000..ebcaaefb8 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_runtime_connect_info_impl.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_runtime_connect_info_impl.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebRuntimeConnectInfoImpl::ArkWebRuntimeConnectInfoImpl( + std::shared_ptr nweb_runtime_connect_info) + : nweb_runtime_connect_info_(nweb_runtime_connect_info) +{} + +ArkWebString ArkWebRuntimeConnectInfoImpl::GetBundleName() +{ + return ArkWebStringClassToStruct(nweb_runtime_connect_info_->GetBundleName()); +} + +ArkWebString ArkWebRuntimeConnectInfoImpl::GetExtensionOrigin() +{ + return ArkWebStringClassToStruct(nweb_runtime_connect_info_->GetExtensionOrigin()); +} + +int ArkWebRuntimeConnectInfoImpl::GetMessageReadPipe() +{ + return nweb_runtime_connect_info_->GetMessageReadPipe(); +} + +int ArkWebRuntimeConnectInfoImpl::GetMessageWritePipe() +{ + return nweb_runtime_connect_info_->GetMessageWritePipe(); +} +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_runtime_connect_info_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_runtime_connect_info_impl.h new file mode 100644 index 000000000..5404e4de6 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_runtime_connect_info_impl.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_RUNTIME_CONNECT_INFO_IMPL_H_ +#define ARK_WEB_RUNTIME_CONNECT_INFO_IMPL_H_ +#pragma once + +#include "include/nweb_runtime_connect_info.h" +#include "ohos_nweb/include/ark_web_runtime_connect_info.h" + +namespace OHOS::ArkWeb { + +class ArkWebRuntimeConnectInfoImpl : public ArkWebRuntimeConnectInfo { + IMPLEMENT_REFCOUNTING(ArkWebRuntimeConnectInfoImpl); + +public: + ArkWebRuntimeConnectInfoImpl(std::shared_ptr nweb_runtime_connect_info); + ~ArkWebRuntimeConnectInfoImpl() = default; + + /** + * @brief Retrieves application bundle identifier. + * + * @return bundleName + */ + ArkWebString GetBundleName() override; + + /** + * @brief Gets the origin of the extension. + * + * @return extensionOrigin + */ + ArkWebString GetExtensionOrigin() override; + + /** + * @brief Gets the read end of the message pipe. + * + * @return messageReadPipe + */ + int GetMessageReadPipe() override; + + /** + * @brief Gets the write end of the message pipe. + * + * @return messageWritePipe + */ + int GetMessageWritePipe() override; + +private: + std::shared_ptr nweb_runtime_connect_info_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_RUNTIME_CONNECT_INFO_IMPL_H_ 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 394fb9daa..f95a05618 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 @@ -58,7 +58,8 @@ #include "ohos_nweb/bridge/ark_web_url_resource_response_wrapper.h" #include "ohos_nweb/bridge/ark_web_view_struct_utils.h" #include "ohos_nweb/ctocpp/ark_web_date_time_suggestion_vector_ctocpp.h" - +#include "ohos_nweb/bridge/ark_web_native_message_callback_wrapper.h" +#include "ohos_nweb/bridge/ark_web_runtime_connect_info_wrapper.h" #include "base/bridge/ark_web_bridge_macros.h" namespace OHOS::ArkWeb { @@ -1128,4 +1129,23 @@ void ArkWebHandlerImpl::OnNativeEmbedObjectParamChange(ArkWebRefPtrOnNativeEmbedObjectParamChange(std::make_shared(data_info)); } + +void ArkWebHandlerImpl::OnExtensionDisconnect(int32_t connectId) +{ + nweb_handler_->OnExtensionDisconnect(connectId); +} + +ArkWebString ArkWebHandlerImpl::OnWebNativeMessage( + ArkWebRefPtr info, ArkWebRefPtr callback) +{ + std::shared_ptr nweb_connect_info = nullptr; + if (!CHECK_REF_PTR_IS_NULL(info)) { + nweb_connect_info = std::make_shared(info); + } + if (CHECK_REF_PTR_IS_NULL(callback)) { + return ArkWebStringClassToStruct(nweb_handler_->OnWebNativeMessage(nweb_connect_info, nullptr)); + } + return ArkWebStringClassToStruct(nweb_handler_->OnWebNativeMessage( + nweb_connect_info, std::make_shared(callback))); +} } // 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 43a042f80..71f45f2c8 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 @@ -730,6 +730,23 @@ public: * */ void OnNativeEmbedObjectParamChange(ArkWebRefPtr data_info) override; + + /** + * @brief Triggered when the webExtensions-native host connection terminates. + * + * @param connectId The id of the connection. + */ + void OnExtensionDisconnect(int32_t connectId) override; + /** + * @brief Initiates webExtensions-native messaging requests and handles corresponding callbacks + * + * @param info The runtime's message connect info. + * @param callback Response handler for processing asynchronous replies from native host. + * @return Returns connection status. + */ + ArkWebString OnWebNativeMessage( + ArkWebRefPtr info, ArkWebRefPtr callback) override; + private: std::shared_ptr nweb_handler_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.cpp new file mode 100644 index 000000000..9a164528e --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_native_message_callback_wrapper.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebNativeMessageCallbackWrapper::ArkWebNativeMessageCallbackWrapper( + ArkWebRefPtr ark_web_native_message_callback) + : ark_web_native_message_callback_(ark_web_native_message_callback) +{} + +void ArkWebNativeMessageCallbackWrapper::OnDisconnect(int nativeInfo) +{ + ark_web_native_message_callback_->OnDisconnect(nativeInfo); +} + +void ArkWebNativeMessageCallbackWrapper::OnConnect(int nativeInfo) +{ + ark_web_native_message_callback_->OnConnect(nativeInfo); +} + +void ArkWebNativeMessageCallbackWrapper::OnFailed(int nativeInfo) +{ + ark_web_native_message_callback_->OnFailed(nativeInfo); +} + +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.h new file mode 100644 index 000000000..19a3f1a94 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_native_message_callback_wrapper.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_MESSAGE_CALLBACK_WRAPPER_H_ +#define ARK_WEB_NATIVE_MESSAGE_CALLBACK_WRAPPER_H_ +#pragma once + +#include "include/nweb_native_message_callback.h" +#include "ohos_nweb/include/ark_web_native_message_callback.h" + +#include "base/include/ark_web_types.h" + +namespace OHOS::ArkWeb { + +class ArkWebNativeMessageCallbackWrapper : public OHOS::NWeb::NWebNativeMessageCallback { +public: + ArkWebNativeMessageCallbackWrapper(ArkWebRefPtr ark_web_native_message_callback); + ~ArkWebNativeMessageCallbackWrapper() = default; + + virtual void OnConnect(int nativeInfo) override; + virtual void OnDisconnect(int nativeInfo) override; + virtual void OnFailed(int code) override; + +private: + ArkWebRefPtr ark_web_native_message_callback_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_MESSAGE_CALLBACK_WRAPPER_H_ diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.cpp new file mode 100644 index 000000000..08b93ec29 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_runtime_connect_info_wrapper.h" + +#include "base/bridge/ark_web_bridge_macros.h" + +namespace OHOS::ArkWeb { + +ArkWebRuntimeConnectInfoWrapper::ArkWebRuntimeConnectInfoWrapper( + ArkWebRefPtr ark_web_runtime_connect_info) + : ark_web_runtime_connect_info_(ark_web_runtime_connect_info) +{} +std::string ArkWebRuntimeConnectInfoWrapper::GetBundleName() +{ + ArkWebString bundleName = ark_web_runtime_connect_info_->GetBundleName(); + + std::string strBundleName = ArkWebStringStructToClass(bundleName); + ArkWebStringStructRelease(bundleName); + return strBundleName; +} +std::string ArkWebRuntimeConnectInfoWrapper::GetExtensionOrigin() +{ + ArkWebString extensionOrigin = ark_web_runtime_connect_info_->GetExtensionOrigin(); + + std::string strExtensionOrigin = ArkWebStringStructToClass(extensionOrigin); + ArkWebStringStructRelease(extensionOrigin); + return strExtensionOrigin; +} + +int ArkWebRuntimeConnectInfoWrapper::GetMessageReadPipe() +{ + return ark_web_runtime_connect_info_->GetMessageReadPipe(); +} +int ArkWebRuntimeConnectInfoWrapper::GetMessageWritePipe() +{ + return ark_web_runtime_connect_info_->GetMessageWritePipe(); +} +} // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.h new file mode 100644 index 000000000..9998a99e9 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_runtime_connect_info_wrapper.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_RUNTIME_CONNECT_INFO_WRAPPER_H_ +#define ARK_WEB_RUNTIME_CONNECT_INFO_WRAPPER_H_ +#pragma once + +#include "include/nweb_runtime_connect_info.h" +#include "ohos_nweb/include/ark_web_runtime_connect_info.h" + +namespace OHOS::ArkWeb { + +class ArkWebRuntimeConnectInfoWrapper : public OHOS::NWeb::NWebRuntimeConnectInfo { +public: + ArkWebRuntimeConnectInfoWrapper(ArkWebRefPtr ark_web_runtime_connect_info); + ~ArkWebRuntimeConnectInfoWrapper() = default; + + std::string GetBundleName() override; + std::string GetExtensionOrigin() override; + int GetMessageReadPipe() override; + int GetMessageWritePipe() override; + +private: + ArkWebRefPtr ark_web_runtime_connect_info_; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_RUNTIME_CONNECTION_INFO_WRAPPER_H_ 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 83ddff6e7..e69ecaf19 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 @@ -58,6 +58,8 @@ #include "ohos_nweb/include/ark_web_url_resource_error.h" #include "ohos_nweb/include/ark_web_url_resource_request.h" #include "ohos_nweb/include/ark_web_url_resource_response.h" +#include "ohos_nweb/include/ark_web_native_message_callback.h" +#include "ohos_nweb/include/ark_web_runtime_connect_info.h" namespace OHOS::ArkWeb { @@ -1062,6 +1064,24 @@ public: */ /*--ark web()--*/ virtual void OnNativeEmbedObjectParamChange(ArkWebRefPtr data_info) = 0; + + /** + * @brief Triggered when the webExtensions-native host connection terminates. + * + * @param connectId The id of the connection. + */ + /*--ark web()--*/ + virtual void OnExtensionDisconnect(int32_t connectId) = 0; + /** + * @brief Initiates webExtensions-native messaging requests and handles corresponding callbacks + * + * @param info The runtime's message connect info. + * @param callback Response handler for processing asynchronous replies from native host. + * @return Returns connection status. + */ + /*--ark web()--*/ + virtual ArkWebString OnWebNativeMessage( + ArkWebRefPtr info, ArkWebRefPtr callback) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_message_callback.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_message_callback.h new file mode 100644 index 000000000..b4a7bcd6f --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_native_message_callback.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_NATIVE_MESSAGE_CALLBACK_H_ +#define ARK_WEB_NATIVE_MESSAGE_CALLBACK_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 ArkWebNativeMessageCallback : public virtual ArkWebBaseRefCounted { +public: + /*--ark web()--*/ + virtual void OnConnect(int nativeInfo) = 0; + + /*--ark web()--*/ + virtual void OnDisconnect(int nativeInfo) = 0; + + /*--ark web()--*/ + virtual void OnFailed(int code) = 0; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_NATIVE_MESSAGE_CALLBACK_H_ diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_runtime_connect_info.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_runtime_connect_info.h new file mode 100644 index 000000000..bb43710a5 --- /dev/null +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_runtime_connect_info.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to 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_RUNTIME_CONNECTINFO_H_ +#define ARK_WEB_RUNTIME_CONNECTINFO_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 ArkWebRuntimeConnectInfo : public virtual ArkWebBaseRefCounted { +public: + /** + * @brief Retrieves application bundle identifier. + * + * @return bundleName + */ + /*--ark web()--*/ + virtual ArkWebString GetBundleName() = 0; + /** + * @brief Gets the origin of the extension. + * + * @return extensionOrigin + */ + /*--ark web()--*/ + virtual ArkWebString GetExtensionOrigin() = 0; + /** + * @brief Gets the read end of the message pipe. + * + * @return messageReadPipe + */ + /*--ark web()--*/ + virtual int GetMessageReadPipe() = 0; + /** + * @brief Gets the write end of the message pipe. + * + * @return messageWritePipe + */ + /*--ark web()--*/ + virtual int GetMessageWritePipe() = 0; +}; + +} // namespace OHOS::ArkWeb + +#endif // ARK_WEB_RUNTIME_CONNECTINFO_H_ -- Gitee From c26771443977d94469214345973347b89fbbd81f Mon Sep 17 00:00:00 2001 From: liuzhijie2 Date: Mon, 8 Sep 2025 16:55:12 +0800 Subject: [PATCH 107/124] set socket idle timeout Signed-off-by: liuzhijie2 --- .../ani/webview/ets/@ohos.web.webview.ets | 1 + .../ani_webview_controller.cpp | 16 ++++ .../napi_webview_controller.cpp | 38 +++++++++- .../napi_webview_controller.h | 1 + .../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 | 5 ++ ohos_nweb/src/nweb_helper.cpp | 22 ++++++ .../nweb_helper_test/nweb_helper_ex_test.cpp | 73 ++++++++++++++++++- 13 files changed, 173 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets b/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets index 214d0b8ae..bf339388a 100644 --- a/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets +++ b/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets @@ -189,6 +189,7 @@ export default namespace webview { native clearHistory(): void; native clearWebSchemeHandler(): void; native innerCompleteWindowNew(parentNwebId:int): void; + native setSocketIdleTimeout(timeout: int): void; innerGetThisVar(): long { return this.nativePtr; } diff --git a/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp b/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp index 3052438aa..e304a6449 100644 --- a/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp +++ b/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp @@ -68,6 +68,9 @@ namespace NWeb { using namespace NWebError; using NWebError::NO_ERROR; namespace { +constexpr int32_t MIN_SOCKET_IDLE_TIMEOUT = 30; +constexpr int32_t MAX_SOCKET_IDLE_TIMEOUT = 300; + bool ParseResourceRawfileUrl(ani_env *env, const ani_object& object, std::string& fileName) { ani_ref paramsRef; @@ -1379,6 +1382,18 @@ static void InnerCompleteWindowNew(ani_env* env, ani_object object, ani_int pare controller->InnerCompleteWindowNew(parentNWebId); } +static void SetSocketIdleTimeout(ani_env* env, ani_object object, ani_int timeout) +{ + if (env == nullptr) { + WVLOG_E("env is nullptr"); + return; + } + + int32_t socketIdleTimeout = + std::clamp(static_cast(timeout), MIN_SOCKET_IDLE_TIMEOUT, MAX_SOCKET_IDLE_TIMEOUT); + NWebHelper::Instance().SetSocketIdleTimeout(socketIdleTimeout); +} + ani_status StsWebviewControllerInit(ani_env *env) { if (env == nullptr) { @@ -1436,6 +1451,7 @@ ani_status StsWebviewControllerInit(ani_env *env) ani_native_function { "clearHistory", nullptr, reinterpret_cast(ClearHistory) }, ani_native_function { "clearWebSchemeHandler", nullptr, reinterpret_cast(ClearWebSchemeHandler) }, ani_native_function { "innerCompleteWindowNew", nullptr, reinterpret_cast(InnerCompleteWindowNew) }, + ani_native_function { "setSocketIdleTimeout", nullptr, reinterpret_cast(SetSocketIdleTimeout) }, }; status = env->Class_BindNativeMethods(webviewControllerCls, controllerMethods.data(), controllerMethods.size()); diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index e564f316f..fd8f413fe 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -81,6 +81,8 @@ constexpr double SCALE_MAX = 2.0; constexpr double HALF = 2.0; constexpr double TEN_MILLIMETER_TO_INCH = 0.39; constexpr const char* EVENT_ATTACH_STATE_CHANGE = "controllerAttachStateChange"; +constexpr int32_t MIN_SOCKET_IDLE_TIMEOUT = 30; +constexpr int32_t MAX_SOCKET_IDLE_TIMEOUT = 300; using WebPrintWriteResultCallback = std::function; bool ParsePrepareUrl(napi_env env, napi_value urlObj, std::string& url) @@ -828,6 +830,7 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_FUNCTION("isActiveWebEngineEvergreen", NapiWebviewController::IsActiveWebEngineEvergreen), DECLARE_NAPI_STATIC_FUNCTION("setAutoPreconnect", NapiWebviewController::SetAutoPreconnect), DECLARE_NAPI_STATIC_FUNCTION("isAutoPreconnectEnabled", NapiWebviewController::IsAutoPreconnectEnabled), + DECLARE_NAPI_STATIC_FUNCTION("setSocketIdleTimeout", NapiWebviewController::SetSocketIdleTimeout), }; napi_value constructor = nullptr; napi_define_class(env, WEBVIEW_CONTROLLER_CLASS_NAME.c_str(), WEBVIEW_CONTROLLER_CLASS_NAME.length(), @@ -7808,13 +7811,14 @@ napi_value NapiWebviewController::SetAutoPreconnect(napi_env env, napi_callback_ WVLOG_W("SetAutoPreconnect unsupported engine version: M114"); return nullptr; } + napi_value thisVar = nullptr; napi_value result = nullptr; size_t argc = INTEGER_ONE; napi_value argv[INTEGER_ONE] = { 0 }; - NAPI_CALL(env, 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")); @@ -7924,5 +7928,37 @@ napi_value NapiWebviewController::GetSiteIsolationMode( WVLOG_I("NapiWebviewController::GetSiteIsolationMode result: %{public}d", mode); return result; } + +napi_value NapiWebviewController::SetSocketIdleTimeout(napi_env env, napi_callback_info info) +{ + if (IS_CALLING_FROM_M114()) { + WVLOG_W("SetSocketIdleTimeout unsupported engine version: M114"); + return nullptr; + } + + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + NAPI_CALL(env, 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; + } + + int32_t socketIdleTimeout = 0; + if (!NapiParseUtils::ParseInt32(env, argv[0], socketIdleTimeout)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "socketIdleTimeout", "number")); + return result; + } + + socketIdleTimeout = std::clamp(socketIdleTimeout, MIN_SOCKET_IDLE_TIMEOUT, MAX_SOCKET_IDLE_TIMEOUT); + NWebHelper::Instance().SetSocketIdleTimeout(socketIdleTimeout); + 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 a30b42c7f..d34fd7227 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -424,6 +424,7 @@ private: static napi_value IsActiveWebEngineEvergreen(napi_env env, napi_callback_info info); static napi_value SetAutoPreconnect(napi_env env, napi_callback_info info); static napi_value IsAutoPreconnectEnabled(napi_env env, napi_callback_info info); + static napi_value SetSocketIdleTimeout(napi_env env, napi_callback_info info); }; class ArkWebTransfer { diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 4b6d5a570..5b23cc06b 100644 --- a/ohos_interface/include/ohos_nweb/nweb_engine.h +++ b/ohos_interface/include/ohos_nweb/nweb_engine.h @@ -137,6 +137,8 @@ public: } virtual void SetWebDestroyMode(WebDestroyMode mode) {} + + virtual void SetSocketIdleTimeout(int32_t timeout) {} }; } // 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 862c9f594..a7abe5dd8 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 @@ -327,4 +327,9 @@ int32_t ArkWebEngineImpl::GetSiteIsolationMode() return static_cast(nweb_engine_->GetSiteIsolationMode()); } +void ArkWebEngineImpl::SetSocketIdleTimeout(int32_t timeout) +{ + nweb_engine_->SetSocketIdleTimeout(timeout); +} + } // 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 f55d6500e..0db19f26e 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 @@ -124,6 +124,8 @@ public: int32_t GetSiteIsolationMode() override; + void SetSocketIdleTimeout(int32_t timeout) 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 097bd7eea..3951a4e9c 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 @@ -383,4 +383,9 @@ ArkWebSiteIsolationMode ArkWebEngineWrapper::GetSiteIsolationMode() return static_cast(res); } +void ArkWebEngineWrapper::SetSocketIdleTimeout(int32_t timeout) +{ + ark_web_engine_->SetSocketIdleTimeout(timeout); +} + } // 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 8c95d2044..926124fa4 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 @@ -125,6 +125,8 @@ public: ArkWebSiteIsolationMode GetSiteIsolationMode() override; + void SetSocketIdleTimeout(int32_t timeout) 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 f58a4db2b..b8b84ea1c 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 @@ -200,6 +200,9 @@ public: /*--ark web()--*/ virtual int32_t GetSiteIsolationMode() = 0; + + /*--ark web()--*/ + virtual void SetSocketIdleTimeout(int32_t timeout) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index 30a1d52ab..8219dd7a7 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -162,6 +162,10 @@ public: SiteIsolationMode GetSiteIsolationMode(); + void SetSocketIdleTimeout(int32_t timeout); + + int32_t GetSocketIdleTimeout(); + private: NWebHelper() = default; bool GetWebEngine(bool fromArk); @@ -169,6 +173,7 @@ private: private: int coreApiLevel_ = 0; + int32_t socketIdleTimeout_ = 300; bool initFlag_ = false; bool autoPreconnectEnabled_ = true; std::string bundlePath_; diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index b57beaf28..d4c1716df 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -753,6 +753,8 @@ bool NWebHelper::InitWebEngine() initArgs->AddArg(std::string("--disable-auto-preconnect")); } + initArgs->AddArg(std::string("--socket-idle-timeout=").append(std::to_string(socketIdleTimeout_))); + nwebEngine_->InitializeWebEngine(initArgs); initFlag_ = true; @@ -1230,6 +1232,8 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(sptr surface, if (!NWebHelper::Instance().IsAutoPreconnectEnabled()) { initArgs->AddArg(std::string("--disable-auto-preconnect")); } + std::string socketIdleTimeout = std::to_string(NWebHelper::Instance().GetSocketIdleTimeout()); + initArgs->AddArg(std::string("--socket-idle-timeout=").append(socketIdleTimeout)); auto createInfo = NWebSurfaceAdapter::Instance().GetCreateInfo(surface, initArgs, width, height, incognitoMode); NWebConfigHelper::Instance().ParseConfig(initArgs); @@ -1268,6 +1272,8 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(void* enhanceSurfaceInfo, if (!NWebHelper::Instance().IsAutoPreconnectEnabled()) { initArgs->AddArg(std::string("--disable-auto-preconnect")); } + std::string socketIdleTimeout = std::to_string(NWebHelper::Instance().GetSocketIdleTimeout()); + initArgs->AddArg(std::string("--socket-idle-timeout=").append(socketIdleTimeout)); auto createInfo = NWebEnhanceSurfaceAdapter::Instance().GetCreateInfo(enhanceSurfaceInfo, initArgs, width, height, incognitoMode); auto nweb = NWebHelper::Instance().CreateNWeb(createInfo); @@ -1385,4 +1391,20 @@ bool NWebHelper::IsAutoPreconnectEnabled() return autoPreconnectEnabled_; } +void NWebHelper::SetSocketIdleTimeout(int32_t timeout) +{ + if (nwebEngine_ == nullptr) { + WVLOG_E("web engine is nullptr"); + socketIdleTimeout_ = timeout; + return; + } + + nwebEngine_->SetSocketIdleTimeout(timeout); +} + +int32_t NWebHelper::GetSocketIdleTimeout() +{ + return socketIdleTimeout_; +} + } // namespace OHOS::NWeb diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index dfd0d7378..f7249288e 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -167,6 +167,8 @@ public: return false; } + void SetSocketIdleTimeout(int32_t timeout) {} + MOCK_METHOD(void, SetWebDebuggingAccessAndPort, (bool isEnableDebug, int32_t port), (override)); @@ -945,7 +947,7 @@ HWTEST_F(NwebHelperTest, NWebHelper_IsPrivateNetworkAccessEnabled_001, TestSize. /** * @tc.name: NWebHelper_SetAutoPreconnect_001 - * @tc.desc: SetAutoPreconnect.. + * @tc.desc: SetAutoPreconnect. * @tc.type: FUNC * @tc.require: */ @@ -960,5 +962,74 @@ HWTEST_F(NwebHelperTest, NWebHelper_SetAutoPreconnect_001, TestSize.Level1) NWebHelper::Instance().SetAutoPreconnect(false); EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, false); } + +/** + * @tc.name: NWebHelper_IsAutoPreconnectEnabled_001 + * @tc.desc: IsAutoPreconnectEnabled. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_IsAutoPreconnectEnabled_001, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + EXPECT_EQ(nwebHelper, nullptr); + + NWebHelper::Instance().autoPreconnectEnabled_ = true; + EXPECT_EQ(NWebHelper::Instance().IsAutoPreconnectEnabled(), true); + NWebHelper::Instance().autoPreconnectEnabled_ = false; + EXPECT_EQ(NWebHelper::Instance().IsAutoPreconnectEnabled(), false); +} + +/** + * @tc.name: NWebHelper_SetSocketIdleTimeout_001 + * @tc.desc: SetSocketIdleTimeout. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_SetSocketIdleTimeout_001, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + NWebHelper::Instance().nwebEngine_ = nullptr; + EXPECT_EQ(NWebHelper::Instance().nwebEngine_, nullptr); + + NWebHelper::Instance().SetSocketIdleTimeout(100); + EXPECT_EQ(NWebHelper::Instance().socketIdleTimeout_, 100); +} + +/** + * @tc.name: NWebHelper_SetSocketIdleTimeout_002 + * @tc.desc: SetSocketIdleTimeout. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_SetSocketIdleTimeout_002, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + auto nwebengineMock = std::make_shared(); + NWebHelper::Instance().nwebEngine_ = nwebEngineMock; + EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); + + NWebHelper::Instance().SetSocketIdleTimeout(100); + EXPECT_EQ(NWebHelper::Instance().socketIdleTimeout_, 300); +} + +/** + * @tc.name: NWebHelper_GetSocketIdleTimeout_001 + * @tc.desc: GetSocketIdleTimeout. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_GetSocketIdleTimeout_001, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + EXPECT_EQ(nwebHelper, nullptr); + + NWebHelper::Instance().SetSocketIdleTimeout(100); + EXPECT_EQ(NWebHelper::Instance().GetSocketIdleTimeout(), 100); +} } // namespace OHOS::NWeb } -- Gitee From f5f3165f0f8a94cba49c86529ce77f730cc1b40a Mon Sep 17 00:00:00 2001 From: s30043564 Date: Mon, 8 Sep 2025 17:33:44 +0800 Subject: [PATCH 108/124] =?UTF-8?q?web=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30043564 --- .../include/ohos_adapter/ohos_image_decoder_adapter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h b/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h index 2b6e1577e..d58e8f7aa 100644 --- a/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h +++ b/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h @@ -66,7 +66,7 @@ public: virtual void* GetDecodeData() = 0; // decode heic by path - virtual bool DecodeByPath(const std::string& path, AllocatorType type) { return false; }; + virtual bool DecodeByPath(const std::string& path, AllocatorType type) { return false; } }; } // namespace OHOS::NWeb -- Gitee From 25760555f40772aec89f2555de0dfdd4c32fd330 Mon Sep 17 00:00:00 2001 From: SprucEovo Date: Mon, 8 Sep 2025 19:15:47 +0800 Subject: [PATCH 109/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=BC=B9=E6=A1=86=E5=9C=A8=E6=9E=81=E5=B0=8F?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E4=B8=8B=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=85=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SprucEovo --- interfaces/kits/napi/js/webview_export.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/napi/js/webview_export.js b/interfaces/kits/napi/js/webview_export.js index b943813e3..5c3001c85 100644 --- a/interfaces/kits/napi/js/webview_export.js +++ b/interfaces/kits/napi/js/webview_export.js @@ -283,7 +283,9 @@ function fileSelectorListItem(callback, sysResource, text, func) { right: 16 }); Row.create(); - Row.width(deviceinfo.deviceType.toLowerCase() === '2in1' ? 312 : 240); + Row.margin({ + right: 36 + }); Row.border({ width: { bottom: 0.5 }, color: '#33000000' }); Text.create(text); Text.fontSize(16); @@ -293,6 +295,7 @@ function fileSelectorListItem(callback, sysResource, text, func) { top: 13, bottom: 13 }); + Text.width('100%'); Text.pop(); Row.pop(); Row.pop(); @@ -328,7 +331,6 @@ function fileSelectorDialog(callback) { function fileSelectorDialogForPC(callback) { Column.create(); Column.height(272); - Column.width(400); fileSelectorDialog(callback); Row.create(); Row.onClick(() => { @@ -343,7 +345,7 @@ function fileSelectorDialogForPC(callback) { console.error(`closeCustomDialog error code is ${code}, message is ${message}`); } }); - Row.width(368); + Row.width('92%'); Row.height(40); Row.margin(16); Row.borderRadius(5); -- Gitee From 62aa8c17c85da6cd50d9561c2794bf953cccd8d7 Mon Sep 17 00:00:00 2001 From: SprucEovo Date: Tue, 9 Sep 2025 10:04:09 +0800 Subject: [PATCH 110/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9codeCheck=E6=84=8F?= =?UTF-8?q?=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SprucEovo --- interfaces/kits/napi/js/webview_export.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interfaces/kits/napi/js/webview_export.js b/interfaces/kits/napi/js/webview_export.js index 5c3001c85..f739d597d 100644 --- a/interfaces/kits/napi/js/webview_export.js +++ b/interfaces/kits/napi/js/webview_export.js @@ -283,9 +283,7 @@ function fileSelectorListItem(callback, sysResource, text, func) { right: 16 }); Row.create(); - Row.margin({ - right: 36 - }); + Row.margin({ right: 36 }); Row.border({ width: { bottom: 0.5 }, color: '#33000000' }); Text.create(text); Text.fontSize(16); -- Gitee From 5bc78edb88e4cb61938f512b284f008299a3285e Mon Sep 17 00:00:00 2001 From: wuxinzao Date: Tue, 9 Sep 2025 13:57:26 +0800 Subject: [PATCH 111/124] =?UTF-8?q?CustomizeSchemes=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuxinzao --- .../napi/webviewcontroller/napi_webview_controller.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index fd8f413fe..bbcaeca76 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -4597,13 +4597,9 @@ int32_t CustomizeSchemesArrayDataHandler(napi_env env, napi_value array) } int32_t registerResult; for (auto it = schemeVector.begin(); it != schemeVector.end(); ++it) { - if (OHOS::NWeb::NWebHelper::Instance().HasLoadWebEngine() == false) { - OHOS::NWeb::NWebHelper::Instance().SaveSchemeVector(it->name.c_str(), it->option); - } else { - registerResult = OH_ArkWeb_RegisterCustomSchemes(it->name.c_str(), it->option); - if (registerResult != NO_ERROR) { - return registerResult; - } + registerResult = OH_ArkWeb_RegisterCustomSchemes(it->name.c_str(), it->option); + if (registerResult != NO_ERROR) { + return registerResult; } } return NO_ERROR; -- Gitee From c21c0debd2a16c8c557d11e69cbb9b94d24fd662 Mon Sep 17 00:00:00 2001 From: cpeng1101 Date: Wed, 27 Aug 2025 16:47:23 +0800 Subject: [PATCH 112/124] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3url=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cpeng1101 --- .../kits/napi/webviewcontroller/napi_webview_controller.cpp | 2 +- interfaces/kits/napi/webviewcontroller/webview_controller.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index 88e78614a..111ed4da7 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -60,7 +60,7 @@ using namespace NWebError; using NWebError::NO_ERROR; namespace { -constexpr uint32_t URL_MAXIMUM = 2048; +constexpr uint32_t URL_MAXIMUM = 2 * 1024 * 1024; constexpr int32_t MAX_WAIT_FOR_ATTACH_TIMEOUT = 300000; constexpr uint32_t SOCKET_MAXIMUM = 6; constexpr char URL_REGEXPR[] = "^http(s)?:\\/\\/.+"; diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp index 2f10b9611..bdcca246e 100644 --- a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp @@ -59,7 +59,7 @@ const std::string MODULE_NAME_PREFIX = "moduleName:"; namespace OHOS { namespace NWeb { namespace { -constexpr uint32_t URL_MAXIMUM = 2048; +constexpr uint32_t URL_MAXIMUM = 2 * 1024 * 1024; const std::string EVENT_CONTROLLER_ATTACH_STATE_CHANGE = "controllerAttachStateChange"; const std::string EVENT_WAIT_FOR_ATTACH = "waitForAttach"; -- Gitee From a860b8db0a2bc43d8efa188b7abbb37da7d7b1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9C=89=E5=BA=B7?= Date: Tue, 9 Sep 2025 13:47:21 +0800 Subject: [PATCH 113/124] add UT for nweb_helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张有康 --- .../nweb_helper_test/nweb_helper_ex_test.cpp | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index 37483f0be..30d53c06a 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -18,6 +18,7 @@ #include #include #include +#include "hilog/log.h" #define private public #include "nweb.h" @@ -46,6 +47,15 @@ const std::string INSTALLATION_DIR = "/data/app/el1/bundle/public/com.ohos.arkwe std::shared_ptr g_applicationContext = nullptr; } // namespace +namespace { + std::string g_errlog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag, + const char* msg) + { + g_errlog += msg; + } +} + namespace AbilityRuntime { std::shared_ptr Context::GetApplicationContext() { @@ -920,11 +930,18 @@ HWTEST_F(NwebHelperTest, NWebHelper_EnablePrivateNetworkAccess_001, TestSize.Lev auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); EXPECT_EQ(nwebHelper, nullptr); + g_errlog.clear(); + LOG_SetCallback(MyLogCallback); + NWebHelper::Instance().nwebEngine_ = nullptr; + NWebHelper::Instance().EnablePrivateNetworkAccess(true); + EXPECT_TRUE(g_errlog.find("web engine is nullptr") != std::string::npos); + auto nwebengineMock = std::make_shared(); NWebHelper::Instance().nwebEngine_ = nwebengineMock; NWebHelper::Instance().EnablePrivateNetworkAccess(true); NWebHelper::Instance().EnablePrivateNetworkAccess(false); EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); + LOG_SetCallback(nullptr); } /** @@ -939,10 +956,17 @@ HWTEST_F(NwebHelperTest, NWebHelper_IsPrivateNetworkAccessEnabled_001, TestSize. auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); EXPECT_EQ(nwebHelper, nullptr); + g_errlog.clear(); + LOG_SetCallback(MyLogCallback); + NWebHelper::Instance().nwebEngine_ = nullptr; + NWebHelper::Instance().IsPrivateNetworkAccessEnabled(); + EXPECT_TRUE(g_errlog.find("web engine is nullptr") != std::string::npos); + auto nwebengineMock = std::make_shared(); NWebHelper::Instance().nwebEngine_ = nwebengineMock; NWebHelper::Instance().IsPrivateNetworkAccessEnabled(); EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); + LOG_SetCallback(nullptr); } /** @@ -1031,5 +1055,59 @@ HWTEST_F(NwebHelperTest, NWebHelper_GetSocketIdleTimeout_001, TestSize.Level1) NWebHelper::Instance().SetSocketIdleTimeout(100); EXPECT_EQ(NWebHelper::Instance().GetSocketIdleTimeout(), 100); } + +/** + * @tc.name: NWebHelper_CreateNWeb + * @tc.desc: CreateNWeb + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_CreateNWeb, TestSize.Level1) +{ + g_errlog.clear(); + LOG_SetCallback(MyLogCallback); + RSSurfaceNodeConfig config; + config.SurfaceNodeName = "webTestSurfaceName"; + auto surfaceNode = RSSurfaceNode::Create(config, false); + ASSERT_NE(surfaceNode, nullptr); + sptr surPtr = surfaceNode->GetSurface(); + ASSERT_NE(surPtr, nullptr); + ASSERT_NE(GetInitArgs(), nullptr); + uint32_t width = 7880; + uint32_t height = 7880; + std::shared_ptr nweb = + NWebAdapterHelper::Instance().CreateNWeb(surPtr, GetInitArgs(), width, height); + EXPECT_TRUE(g_errlog.find("is invalid") != std::string::npos); + EXPECT_EQ(nweb, nullptr); + + g_errlog.clear(); + width = 780; + nweb = NWebAdapterHelper::Instance().CreateNWeb(surPtr, GetInitArgs(), width, height); + EXPECT_TRUE(g_errlog.find("is invalid") != std::string::npos); + EXPECT_EQ(nweb, nullptr); + + g_errlog.clear(); + width = 7880; + height = 780; + nweb = NWebAdapterHelper::Instance().CreateNWeb(surPtr, GetInitArgs(), width, height); + EXPECT_TRUE(g_errlog.find("is invalid") != std::string::npos); + EXPECT_EQ(nweb, nullptr); + + g_errlog.clear(); + bool ret = NWebHelper::Instance().autoPreconnectEnabled_; + width = 780; + height = 780; + NWebHelper::Instance().autoPreconnectEnabled_ = false; + nweb = NWebAdapterHelper::Instance().CreateNWeb(surPtr, GetInitArgs(), width, height); + EXPECT_FALSE(g_errlog.find("is invalid") != std::string::npos); + + g_errlog.clear(); + NWebHelper::Instance().autoPreconnectEnabled_ = true; + nweb = NWebAdapterHelper::Instance().CreateNWeb(surPtr, GetInitArgs(), width, height); + EXPECT_FALSE(g_errlog.find("is invalid") != std::string::npos); + + NWebHelper::Instance().autoPreconnectEnabled_ = ret; + LOG_SetCallback(nullptr); +} } // namespace OHOS::NWeb } -- Gitee From d356bec3bf761ff06087d598f3d688172b9ee09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=9E=E5=AE=87=E6=88=90?= Date: Tue, 9 Sep 2025 17:00:49 +0800 Subject: [PATCH 114/124] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E7=BB=B4?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 庞宇成 --- interfaces/native/arkweb_scheme_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/native/arkweb_scheme_handler.cpp b/interfaces/native/arkweb_scheme_handler.cpp index 73c573d7c..39bbf3549 100644 --- a/interfaces/native/arkweb_scheme_handler.cpp +++ b/interfaces/native/arkweb_scheme_handler.cpp @@ -126,7 +126,6 @@ bool EnsureSdkLoaded() if (g_SchemeHandlerApi) { return true; } - auto* schemeHandlerApi = new (std::nothrow) SchemeHandlerApi(); if (schemeHandlerApi == nullptr) { WVLOG_I("schemeHandlerApi is nullptr."); @@ -134,6 +133,7 @@ bool EnsureSdkLoaded() } LoadSchemeHandlerApi(schemeHandlerApi); g_SchemeHandlerApi = schemeHandlerApi; + WVLOG_I("SchemeHandlerApi had loaded."); return true; } #undef FOR_EACH_API_FN -- Gitee From d4899d21417934544c172c6763f1899ada3c97cc Mon Sep 17 00:00:00 2001 From: cpeng1101 Date: Fri, 5 Sep 2025 14:11:50 +0800 Subject: [PATCH 115/124] =?UTF-8?q?OnRefreshAccessedHistoryEvent=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=8F=AF=E9=80=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cpeng1101 --- .../include/ohos_nweb/nweb_handler.h | 15 +++++++++++++++ .../bridge/webcore/ark_web_handler_wrapper.cpp | 14 ++++++++++++++ .../bridge/webcore/ark_web_handler_wrapper.h | 16 ++++++++++++++++ .../bridge/webview/ark_web_handler_impl.cpp | 10 ++++++++++ .../bridge/webview/ark_web_handler_impl.h | 16 ++++++++++++++++ .../ohos_nweb/include/ark_web_handler.h | 18 ++++++++++++++++++ 6 files changed, 89 insertions(+) diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index e31f121b0..fafca8c27 100644 --- a/ohos_interface/include/ohos_nweb/nweb_handler.h +++ b/ohos_interface/include/ohos_nweb/nweb_handler.h @@ -1316,6 +1316,21 @@ public: * */ virtual void OnNativeEmbedObjectParamChange(std::shared_ptr paramDataInfo) {} + + /** + * @brief Called when received website security risk check finish. + * @param threat_type The threat type of website. + */ + virtual void OnSafeBrowsingCheckFinish(int threat_type) {} + + /** + * @brief inform application to update its visited links database. + * + * @param url the url being visited. + * @param isReload true if the url is being reload. + * @param isMainFrame true if the request is for the main frame. + */ + virtual void OnRefreshAccessedHistoryV2(const std::string& url, bool isReload, bool isMainFrame) {} }; } // 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 0a391fa3a..3746d8592 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 @@ -1293,4 +1293,18 @@ void ArkWebHandlerWrapper::OnNativeEmbedObjectParamChange( ark_web_handler_->OnNativeEmbedObjectParamChange(new ArkWebNativeEmbedParamDataInfoImpl(paramDataInfo)); } + +void ArkWebHandlerWrapper::OnSafeBrowsingCheckFinish(int threat_type) +{ + ark_web_handler_->OnSafeBrowsingCheckFinish(threat_type); +} + +void ArkWebHandlerWrapper::OnRefreshAccessedHistoryV2(const std::string& url, bool is_reload, bool isMainFrame) +{ + ArkWebString stUrl = ArkWebStringClassToStruct(url); + + ark_web_handler_->OnRefreshAccessedHistoryV2(stUrl, is_reload, isMainFrame); + + ArkWebStringStructRelease(stUrl); +} } // 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 cfe5ec8bb..c6d8f2e42 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 @@ -768,6 +768,22 @@ public: */ void OnNativeEmbedObjectParamChange( std::shared_ptr paramDataInfo) override; + + /** + * @brief Called when received website security risk check finish. + * + * @param threat_type The threat type of website. + */ + void OnSafeBrowsingCheckFinish(int threat_type) override; + + /** + * @brief inform application to update its visited links database. + * + * @param url the url being visited. + * @param isReload true if the url is being reload. + * @param isMainFrame true if the request is for the main frame. + */ + void OnRefreshAccessedHistoryV2(const std::string& url, bool isReload, bool isMainFrame) 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 394fb9daa..e808b9ee6 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 @@ -1128,4 +1128,14 @@ void ArkWebHandlerImpl::OnNativeEmbedObjectParamChange(ArkWebRefPtrOnNativeEmbedObjectParamChange(std::make_shared(data_info)); } + +void ArkWebHandlerImpl::OnSafeBrowsingCheckFinish(int threat_type) +{ + nweb_handler_->OnSafeBrowsingCheckFinish(threat_type); +} + +void ArkWebHandlerImpl::OnRefreshAccessedHistoryV2(const ArkWebString& url, bool isReload, bool isMainFrame) +{ + nweb_handler_->OnRefreshAccessedHistoryV2(ArkWebStringStructToClass(url), isReload, isMainFrame); +} } // 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 43a042f80..cd702574f 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 @@ -730,6 +730,22 @@ public: * */ void OnNativeEmbedObjectParamChange(ArkWebRefPtr data_info) override; + + /** + * @brief Called when received website security risk check finish. + * + * @param threat_type The threat type of website. + */ + void OnSafeBrowsingCheckFinish(int threat_type) override; + + /** + * @brief inform application to update its visited links database. + * + * @param url the url being visited. + * @param isReload true if the url is being reload. + * @param isMainFrame true if the request is for the main frame. + */ + void OnRefreshAccessedHistoryV2(const ArkWebString& url, bool isReload, bool isMainFrame) 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 83ddff6e7..f732d1d03 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 @@ -1062,6 +1062,24 @@ public: */ /*--ark web()--*/ virtual void OnNativeEmbedObjectParamChange(ArkWebRefPtr data_info) = 0; + + /** + * @brief Called when received website security risk check finish. + * + * @param threat_type The threat type of website. + */ + /*--ark web()--*/ + virtual void OnSafeBrowsingCheckFinish(int threat_type) = 0; + + /** + * @brief inform application to update its visited links database. + * + * @param url the url being visited. + * @param isReload true if the url is being reload. + * @param isMainFrame true if the request is for the main frame. + */ + /*--ark web()--*/ + virtual void OnRefreshAccessedHistoryV2(const ArkWebString& url, bool isReload, bool isMainFrame) = 0; }; } // namespace OHOS::ArkWeb -- Gitee From eaef52af6240eb812d8f2182bde5e9d0e82e9172 Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Wed, 10 Sep 2025 11:29:34 +0800 Subject: [PATCH 116/124] site isolation ut Signed-off-by: quyue00807312 --- test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp | 4 ++++ test/unittest/nweb_helper_test/nweb_helper_test.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index dfd0d7378..9ff6f86ea 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -436,6 +436,8 @@ HWTEST_F(NwebHelperTest, NWebHelper_LoadWebEngine_008, TestSize.Level1) NWebHelper::Instance().PauseAllTimers(); NWebHelper::Instance().ResumeAllTimers(); NWebHelper::Instance().SetWebDestroyMode(WebDestroyMode::NORMAL_MODE); + NWebHelper::Instance().SetSiteIsolationMode(SiteIsolationMode::PARTIAL); + NWebHelper::Instance().GetSiteIsolationMode(); auto nwebEngineMock = std::make_shared(); NWebHelper::Instance().nwebEngine_ = nwebEngineMock; @@ -453,6 +455,8 @@ HWTEST_F(NwebHelperTest, NWebHelper_LoadWebEngine_008, TestSize.Level1) NWebHelper::Instance().PauseAllTimers(); NWebHelper::Instance().ResumeAllTimers(); NWebHelper::Instance().SetWebDestroyMode(WebDestroyMode::NORMAL_MODE); + NWebHelper::Instance().SetSiteIsolationMode(SiteIsolationMode::PARTIAL); + NWebHelper::Instance().GetSiteIsolationMode(); EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); NWebHelper::Instance().LoadWebEngine(true, false); bool result = NWebHelper::Instance().GetWebEngine(true); diff --git a/test/unittest/nweb_helper_test/nweb_helper_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_test.cpp index 32e9f454f..75f913e2b 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_test.cpp @@ -488,6 +488,8 @@ HWTEST_F(NwebHelperTest, NWebHelper_LoadWebEngine_008, TestSize.Level1) NWebHelper::Instance().PauseAllTimers(); NWebHelper::Instance().ResumeAllTimers(); NWebHelper::Instance().SetWebDestroyMode(WebDestroyMode::NORMAL_MODE); + NWebHelper::Instance().SetSiteIsolationMode(SiteIsolationMode::PARTIAL); + NWebHelper::Instance().GetSiteIsolationMode(); EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); NWebHelper::Instance().LoadWebEngine(true, false); bool result = NWebHelper::Instance().GetWebEngine(true); @@ -510,6 +512,8 @@ HWTEST_F(NwebHelperTest, NWebHelper_LoadWebEngine_008, TestSize.Level1) NWebHelper::Instance().PauseAllTimers(); NWebHelper::Instance().ResumeAllTimers(); NWebHelper::Instance().SetWebDestroyMode(WebDestroyMode::NORMAL_MODE); + NWebHelper::Instance().SetSiteIsolationMode(SiteIsolationMode::PARTIAL); + NWebHelper::Instance().GetSiteIsolationMode(); NWebHelper::Instance().SetWebDebuggingAccess(true); NWebHelper::Instance().SetWebDebuggingAccessAndPort(true, 80); NWebHelper::Instance().SaveSchemeVector("web_test", 8080); -- Gitee From 57e1a634bbc816cb4650f2730948f87e4bba5d6b Mon Sep 17 00:00:00 2001 From: liuxiao_310 Date: Wed, 10 Sep 2025 14:33:10 +0800 Subject: [PATCH 117/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=83=B6=E6=B0=B4?= =?UTF-8?q?=E5=B1=82=E8=A7=A3=E5=86=B2=E7=AA=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuxiao_310 --- .../bridge/webcore/ark_web_handler_wrapper.h | 17 ----------------- 1 file changed, 17 deletions(-) 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 190667f75..fcf2d1b78 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 @@ -769,23 +769,6 @@ public: void OnNativeEmbedObjectParamChange( std::shared_ptr paramDataInfo) override; - /** - * @brief Triggered when the webExtensions-native host connection terminates. - * - * @param connectId The id of the connection. - */ - void OnExtensionDisconnect(int32_t connectId) override; - - /** - * @brief Initiates webExtensions-native messaging requests and handles corresponding callbacks - * - * @param info The runtime's message connect info. - * @param callback Response handler for processing asynchronous replies from native host. - * @return Returns connection status. - */ - std::string OnWebNativeMessage(std::shared_ptr info, - std::shared_ptr callback) override; - /** * @brief Called when received website security risk check finish. * -- Gitee From 0363eaf19760b7fb6565c689226e7c426702fe39 Mon Sep 17 00:00:00 2001 From: coldrabbit Date: Wed, 10 Sep 2025 07:17:39 +0000 Subject: [PATCH 118/124] update ohos_adapter/flowbuffer_adapter/src/flowbuffer_adapter_impl.cpp. Signed-off-by: coldrabbit --- ohos_adapter/flowbuffer_adapter/src/flowbuffer_adapter_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/flowbuffer_adapter/src/flowbuffer_adapter_impl.cpp b/ohos_adapter/flowbuffer_adapter/src/flowbuffer_adapter_impl.cpp index 11b46303f..de047b724 100644 --- a/ohos_adapter/flowbuffer_adapter/src/flowbuffer_adapter_impl.cpp +++ b/ohos_adapter/flowbuffer_adapter/src/flowbuffer_adapter_impl.cpp @@ -65,7 +65,7 @@ void FlowbufferAdapterImpl::StartPerformanceBoost() void* FlowbufferAdapterImpl::CreateAshmem(size_t size, int mapType, int& fd) { - fd = AshmemCreate(nullptr, size); + fd = AshmemCreate("WebFlowBuffer", size); if (fd < 0) { WVLOG_E("Create ashmem failed, fd: %{public}d", fd); return nullptr; -- Gitee From 71a5d9cf697c9892b96255fb44d95237695f388f Mon Sep 17 00:00:00 2001 From: LGH W Date: Wed, 10 Sep 2025 16:33:13 +0800 Subject: [PATCH 119/124] Dual-core app whitelist solution Signed-off-by: LGH W --- arkweb_utils/arkweb_utils.cpp | 151 ++++++++---- .../arkweb_utils_test/arkweb_utils_test.cpp | 231 ++++++++++++++---- 2 files changed, 289 insertions(+), 93 deletions(-) diff --git a/arkweb_utils/arkweb_utils.cpp b/arkweb_utils/arkweb_utils.cpp index 66e1a05fe..0e454d2f4 100644 --- a/arkweb_utils/arkweb_utils.cpp +++ b/arkweb_utils/arkweb_utils.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #if (defined(webview_arm64) && !defined(ASAN_DETECTOR)) #include "ace_forward_compatibility.h" @@ -32,6 +33,8 @@ static int g_appEngineVersion = static_cast(ArkWebEngineVersion::SYSTEM_DEF static bool g_webEngineInitFlag = false; static ArkWebEngineVersion g_activeEngineVersion = ArkWebEngineVersion::SYSTEM_DEFAULT; static std::string g_appBundleName = ""; +static int g_cloudEnableAppVersion = static_cast(ArkWebEngineVersion::SYSTEM_DEFAULT); +static std::unique_ptr> g_legacyApp = nullptr; #if defined(webview_arm64) const std::string ARK_WEB_CORE_MOCK_HAP_LIB_PATH = @@ -100,63 +103,114 @@ const std::string EL1_BUNDLE_PUBLIC = "/data/app/el1/bundle/public/"; // 前向声明 static ArkWebEngineVersion CalculateActiveWebEngineVersion(); -static bool validateSpecialParams(const std::string& key, int value) +static void SetIntParameter(const std::string& key, const int& intValue) { - if (key == "web.engine.default") { - if (value != static_cast(ArkWebEngineType::EVERGREEN) && - value != static_cast(ArkWebEngineType::LEGACY)) { - WVLOG_E("Invalid value for %{public}s: %{public}d, must be EVERGREEN or LEGACY", - key.c_str(), value); - return false; - } - } - else if (key == "web.engine.enforce") { - if (value != static_cast(ArkWebEngineType::EVERGREEN)) { - WVLOG_E("Invalid value for %{public}s: %{public}d, must be EVERGREEN", - key.c_str(), value); - return false; + std::string valueStr = std::to_string(intValue); + if (OHOS::system::SetParameter(key, valueStr)) { + WVLOG_I("Successfully set integer param %{public}s with %{public}s", key.c_str(), valueStr.c_str()); + } else { + WVLOG_E("Failed to set integer param %{public}s with %{public}s", key.c_str(), valueStr.c_str()); + } +} + +static void ProcessDefaultParam(const Json::Value& value) +{ + if (!value.isInt()) { + WVLOG_E("Unsupported type for param web.engine.default, must be integer"); + return; + } + + int intValue = value.asInt(); + if (intValue != static_cast(ArkWebEngineType::LEGACY) && + intValue != static_cast(ArkWebEngineType::EVERGREEN)) { + WVLOG_E("Invalid value for web.engine.default: %{public}d, " + "must be LEGACY(%{public}d) or EVERGREEN(%{public}d)", + intValue, + static_cast(ArkWebEngineType::LEGACY), + static_cast(ArkWebEngineType::EVERGREEN)); + return; + } + + SetIntParameter("web.engine.default", intValue); +} + +static void ProcessEnforceParam(const Json::Value& value) +{ + if (!value.isInt()) { + WVLOG_E("Unsupported type for param web.engine.enforce, must be integer"); + return; + } + + int intValue = value.asInt(); + if (intValue != static_cast(ArkWebEngineType::EVERGREEN)) { + WVLOG_E("Invalid value for web.engine.enforce: %{public}d, " + "must be LEGACY(%{public}d) or EVERGREEN(%{public}d)", + intValue, + static_cast(ArkWebEngineType::LEGACY), + static_cast(ArkWebEngineType::EVERGREEN)); + return; + } + + SetIntParameter("web.engine.enforce", intValue); +} + +static void ProcessLegacyAppParam(const Json::Value& value) +{ + if (!value.isArray()) { + WVLOG_E("Unsupported type for param web.engine.legacyApp, must be array"); + return; + } + + auto appSet = std::make_unique>(); + for (const auto& item : value) { + if (item.isString()) { + appSet->insert(item.asString()); + } else { + WVLOG_E("Non-string item found in array for web.engine.legacyApp, skipping."); } } - return true; + + g_legacyApp = std::move(appSet); + WVLOG_I("Successfully stored legacyApp in heap memory using smart pointer."); +} + +static void ProcessParamItem(const std::string& key, const Json::Value& value) +{ + if (key.find(WEB_PARAM_PREFIX) != 0) { + WVLOG_E("Skipping param with incorrect prefix %{public}s", key.c_str()); + return; + } + + if (key == "web.engine.default") { + ProcessDefaultParam(value); + } else if (key == "web.engine.enforce") { + ProcessEnforceParam(value); + } else if (key == "web.engine.legacyApp") { + ProcessLegacyAppParam(value); + } else { + WVLOG_E("Unsupported key for param %{public}s", key.c_str()); + } } -static void processJsonConfig(const Json::Value& root) +static void ProcessJsonConfig(const Json::Value& root) { if (!root.isObject()) { - WVLOG_E("Not a JSON object"); + WVLOG_E("Root element is not a JSON object"); return; } Json::Value::Members keys = root.getMemberNames(); for (const auto& key : keys) { const Json::Value& value = root[key]; - if (!value.isInt() || key.rfind(WEB_PARAM_PREFIX, 0) != 0) { - WVLOG_E("Invalid param %{public}s", key.c_str()); - continue; - } - - int intValue = value.asInt(); - - // 验证特殊参数 - if (!validateSpecialParams(key, intValue)) { - continue; // 跳过非法值 - } - - // 设置有效参数 - std::string valueStr = std::to_string(intValue); - if (OHOS::system::SetParameter(key, valueStr)) { - WVLOG_I("Set param %{public}s with %{public}s", key.c_str(), valueStr.c_str()); - } else { - WVLOG_E("Set param %{public}s with %{public}s failed", key.c_str(), valueStr.c_str()); - } + ProcessParamItem(key, value); } } -static void updateCfgToSystemParam() +static void ParseCloudCfg() { std::ifstream jsonFile(JSON_CONFIG_PATH.c_str()); if (!jsonFile.is_open()) { - WVLOG_E("Failed to open file reason: %{public}s", strerror(errno)); + WVLOG_E("Failed to open file %{public}s, reason: %{public}s", JSON_CONFIG_PATH.c_str(), strerror(errno)); return; } @@ -164,24 +218,31 @@ static void updateCfgToSystemParam() Json::CharReaderBuilder readerBuilder; std::string parseErrors; bool parsingSuccessful = Json::parseFromStream(readerBuilder, jsonFile, &root, &parseErrors); - if (!parsingSuccessful) { - WVLOG_E("JSON parse failed, parseErrors:%{public}s", parseErrors.c_str()); + WVLOG_E("JSON parse failed, parseErrors: %{public}s", parseErrors.c_str()); return; } - processJsonConfig(root); + ProcessJsonConfig(root); } void SelectWebcoreBeforeProcessRun(const std::string& appBundleName) { + WVLOG_I("Calculate CloudEnableAppVersion for app %{public}s.", appBundleName.c_str()); g_appBundleName = appBundleName; + + if (g_legacyApp && g_legacyApp->find(appBundleName) != g_legacyApp->end()) { + g_cloudEnableAppVersion = static_cast(ArkWebEngineType::LEGACY); + } + g_activeEngineVersion = CalculateActiveWebEngineVersion(); + + g_legacyApp.reset(); } void PreloadArkWebLibForBrowser() { - updateCfgToSystemParam(); + ParseCloudCfg(); if (!(access(PRECONFIG_LEGACY_HAP_PATH.c_str(), F_OK) == 0)) { if (OHOS::system::SetParameter("web.engine.enforce", std::to_string(static_cast(ArkWebEngineType::EVERGREEN)))) { @@ -239,6 +300,12 @@ ArkWebEngineVersion CalculateActiveWebEngineVersion() } return static_cast(g_appEngineVersion); } + + if (g_cloudEnableAppVersion == static_cast(ArkWebEngineType::LEGACY) || + g_cloudEnableAppVersion == static_cast(ArkWebEngineType::EVERGREEN)) { + WVLOG_I("CalculateActiveWebEngineVersion CloudEnableAppVersion: %{public}d", g_cloudEnableAppVersion); + return static_cast(g_cloudEnableAppVersion); + } int webEngineDefault = OHOS::system::GetIntParameter("web.engine.default", static_cast(ArkWebEngineType::EVERGREEN)); diff --git a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp index 5ac4465c8..337505d2a 100644 --- a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp +++ b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp @@ -18,39 +18,13 @@ #include #include -#include "arkweb_utils.h" +#include "arkweb_utils.cpp" #include "parameters.h" #include "system_properties_adapter_impl.h" using namespace testing::ext; namespace OHOS::ArkWeb { -#if defined(webview_arm64) -const std::string ARK_WEB_CORE_HAP_LIB_PATH = - "/data/storage/el1/bundle/arkwebcore/libs/arm64"; -const std::string ARK_WEB_CORE_LEGACY_HAP_LIB_PATH = - "/data/storage/el1/bundle/arkwebcorelegacy/libs/arm64"; -const std::string ARK_WEB_CORE_PATH_FOR_MOCK = "libs/arm64"; -const std::string ARK_WEB_CORE_PATH_FOR_BUNDLE = "arkwebcore/libs/arm64"; -const std::string ARK_WEB_CORE_LEGACY_PATH_FOR_BUNDLE = "arkwebcorelegacy/libs/arm64"; -#elif defined(webview_x86_64) -const std::string ARK_WEB_CORE_HAP_LIB_PATH = - "/data/storage/el1/bundle/arkwebcore/libs/x86_64"; -const std::string ARK_WEB_CORE_LEGACY_HAP_LIB_PATH = - "/data/storage/el1/bundle/arkwebcorelegacy/libs/x86_64"; -const std::string ARK_WEB_CORE_PATH_FOR_MOCK = "libs/x86_64"; -const std::string ARK_WEB_CORE_PATH_FOR_BUNDLE = "arkwebcore/libs/x86_64"; -const std::string ARK_WEB_CORE_LEGACY_PATH_FOR_BUNDLE = "arkwebcorelegacy/libs/x86_64"; -#else -const std::string ARK_WEB_CORE_HAP_LIB_PATH = - "/data/storage/el1/bundle/arkwebcore/libs/arm"; -const std::string ARK_WEB_CORE_LEGACY_HAP_LIB_PATH = - "/data/storage/el1/bundle/arkwebcorelegacy/libs/arm"; -const std::string ARK_WEB_CORE_PATH_FOR_MOCK = "libs/arm"; -const std::string ARK_WEB_CORE_PATH_FOR_BUNDLE = "arkwebcore/libs/arm"; -const std::string ARK_WEB_CORE_LEGACY_PATH_FOR_BUNDLE = "arkwebcorelegacy/libs/arm"; -#endif - #if defined(IS_ASAN) #if defined(webview_arm64) const std::string ARK_WEB_CORE_ASAN_PATH_FOR_BUNDLE = "arkwebcore_asan/libs/arm64"; @@ -63,34 +37,45 @@ const std::string ARK_WEB_CORE_ASAN_PATH_FOR_BUNDLE = "arkwebcore_asan/libs/arm" #endif #endif -const std::string PRECONFIG_LEGACY_HAP_PATH = "/system/app/ArkWebCoreLegacy/ArkWebCoreLegacy.hap"; -const std::string PRECONFIG_EVERGREEN_HAP_PATH = - "/system/app/ArkWebCore/ArkWebCore.hap"; -const std::string SANDBOX_LEGACY_HAP_PATH = "/data/storage/el1/bundle/arkwebcorelegacy/entry.hap"; -const std::string SANDBOX_EVERGREEN_HAP_PATH = "/data/storage/el1/bundle/arkwebcore/entry.hap"; +class ArkWebUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ArkWebUtilsTest::SetUpTestCase(void) +{} -const std::string JSON_CONFIG_PATH = - "/data/service/el1/public/update/param_service/install/system/etc/ArkWebSafeBrowsing/generic/ArkWebCoreCfg.json"; +void ArkWebUtilsTest::TearDownTestCase(void) +{} -TEST(arkweb_utils_test, SetActiveWebEngineVersionInner001) { +void ArkWebUtilsTest::SetUp(void) +{} + +void ArkWebUtilsTest::TearDown(void) +{} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_SetActiveWebEngineVersionInner_001, TestSize.Level1) { SetActiveWebEngineVersionInner(ArkWebEngineVersion::SYSTEM_DEFAULT); EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::SYSTEM_DEFAULT); } -TEST(arkweb_utils_test, SetActiveWebEngineVersionInner002) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_SetActiveWebEngineVersionInner_002, TestSize.Level1) { SetActiveWebEngineVersionInner(ArkWebEngineVersion::M114); EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M114); } -TEST(arkweb_utils_test, SetActiveWebEngineVersionInner003) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_SetActiveWebEngineVersionInner_003, TestSize.Level1) { SetActiveWebEngineVersionInner(ArkWebEngineVersion::M132); EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M132); } -TEST(arkweb_utils_test, getActiveWebEngineType001) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_getActiveWebEngineType_001, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(2)); @@ -99,7 +84,7 @@ TEST(arkweb_utils_test, getActiveWebEngineType001) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, getActiveWebEngineType002) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_getActiveWebEngineType_002, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::SYSTEM_DEFAULT); @@ -109,7 +94,7 @@ TEST(arkweb_utils_test, getActiveWebEngineType002) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, getActiveWebEngineType003) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_getActiveWebEngineType_003, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::M114); @@ -119,7 +104,7 @@ TEST(arkweb_utils_test, getActiveWebEngineType003) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, GetArkwebLibPath001) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_GetArkwebLibPath_001, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::M114); @@ -129,7 +114,7 @@ TEST(arkweb_utils_test, GetArkwebLibPath001) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, GetArkwebLibPath002) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_GetArkwebLibPath_002, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::SYSTEM_DEFAULT); @@ -139,7 +124,7 @@ TEST(arkweb_utils_test, GetArkwebLibPath002) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, GetArkwebNameSpace001) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_GetArkwebNameSpace_001, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::M114); @@ -149,7 +134,7 @@ TEST(arkweb_utils_test, GetArkwebNameSpace001) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, GetArkwebNameSpace002) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_GetArkwebNameSpace_002, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::SYSTEM_DEFAULT); @@ -159,7 +144,7 @@ TEST(arkweb_utils_test, GetArkwebNameSpace002) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, GetArkwebRelativePathForBundle001) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_GetArkwebRelativePathForBundle_001, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::M114); @@ -173,7 +158,7 @@ TEST(arkweb_utils_test, GetArkwebRelativePathForBundle001) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, GetArkwebRelativePathForBundle002) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_GetArkwebRelativePathForBundle_002, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::SYSTEM_DEFAULT); @@ -187,7 +172,7 @@ TEST(arkweb_utils_test, GetArkwebRelativePathForBundle002) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, GetArkwebInstallPath001) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_GetArkwebInstallPath_001, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::M114); @@ -205,7 +190,7 @@ TEST(arkweb_utils_test, GetArkwebInstallPath001) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, GetArkwebInstallPath002) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_GetArkwebInstallPath_002, TestSize.Level1) { int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); setActiveWebEngineVersion(ArkWebEngineVersion::SYSTEM_DEFAULT); @@ -223,7 +208,7 @@ TEST(arkweb_utils_test, GetArkwebInstallPath002) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, SelectWebcoreBeforeProcessRun001) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_SelectWebcoreBeforeProcessRun_001, TestSize.Level1) { std::string appBundleName = "com.example.app"; int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); @@ -233,7 +218,7 @@ TEST(arkweb_utils_test, SelectWebcoreBeforeProcessRun001) { OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } -TEST(arkweb_utils_test, SelectWebcoreBeforeProcessRun002) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_SelectWebcoreBeforeProcessRun_002, TestSize.Level1) { std::string appBundleName = "com.example.app2"; int webEngineEnforce = OHOS::system::GetIntParameter("web.engine.enforce", 0); OHOS::system::SetParameter("web.engine.enforce", std::to_string(0)); @@ -244,9 +229,153 @@ TEST(arkweb_utils_test, SelectWebcoreBeforeProcessRun002) { } #if (defined(webview_arm64) && !defined(ASAN_DETECTOR)) -TEST(arkweb_utils_test, DlcloseArkWebLib001) { +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_DlcloseArkWebLib_001, TestSize.Level1) { int ret = DlcloseArkWebLib(); EXPECT_EQ(ret, 0); } #endif + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessDefaultParam_001, TestSize.Level1) +{ + std::string key = "web.engine.default"; + Json::Value value = 1000; + ProcessDefaultParam(value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 0); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessDefaultParam_002, TestSize.Level1) +{ + std::string key = "web.engine.default"; + Json::Value value = std::to_string(static_cast(ArkWebEngineType::LEGACY)); + ProcessDefaultParam(value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 0); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessDefaultParam_003, TestSize.Level1) +{ + std::string key = "web.engine.default"; + Json::Value value = static_cast(ArkWebEngineType::LEGACY); + ProcessDefaultParam(value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 1); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessDefaultParam_004, TestSize.Level1) +{ + std::string key = "web.engine.default"; + Json::Value value = static_cast(ArkWebEngineType::EVERGREEN); + ProcessDefaultParam(value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 2); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessEnforceParam_001, TestSize.Level1) +{ + std::string key = "web.engine.enforce"; + Json::Value value = 1000; + ProcessEnforceParam(value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 0); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessEnforceParam_002, TestSize.Level1) +{ + std::string key = "web.engine.enforce"; + Json::Value value = std::to_string(static_cast(ArkWebEngineType::LEGACY)); + ProcessEnforceParam(value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 0); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessEnforceParam_003, TestSize.Level1) +{ + std::string key = "web.engine.enforce"; + Json::Value value = static_cast(ArkWebEngineType::LEGACY); + ProcessEnforceParam(value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 0); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessEnforceParam_004, TestSize.Level1) +{ + std::string key = "web.engine.enforce"; + Json::Value value = static_cast(ArkWebEngineType::EVERGREEN); + ProcessEnforceParam(value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 2); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessLegacyAppParam_001, TestSize.Level1) +{ + Json::Value value = "com.example.myapplication"; + ProcessLegacyAppParam(value); + EXPECT_EQ(g_legacyApp, nullptr); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessLegacyAppParam_002, TestSize.Level1) +{ + std::string appBundleName = "com.example.myapplication"; + Json::Value value(Json::arrayValue); + ProcessLegacyAppParam(value); + EXPECT_NE(g_legacyApp, nullptr); + EXPECT_EQ(g_legacyApp->find(appBundleName) != g_legacyApp->end(), false); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessLegacyAppParam_003, TestSize.Level1) +{ + std::string appBundleName = "com.example.myapplication"; + Json::Value value(Json::arrayValue); + value.append(2); + value.append("test"); + ProcessLegacyAppParam(value); + EXPECT_NE(g_legacyApp, nullptr); + EXPECT_EQ(g_legacyApp->find(appBundleName) != g_legacyApp->end(), false); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessLegacyAppParam_004, TestSize.Level1) +{ + std::string appBundleName = "com.example.myapplication"; + Json::Value value(Json::arrayValue); + value.append(appBundleName); + ProcessLegacyAppParam(value); + EXPECT_NE(g_legacyApp, nullptr); + EXPECT_EQ(g_legacyApp->find(appBundleName) != g_legacyApp->end(), true); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessParamItem_001, TestSize.Level1) +{ + std::string key = "Arkweb.engine.default"; + Json::Value value = static_cast(ArkWebEngineType::EVERGREEN); + ProcessParamItem(key, value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 0); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessParamItem_002, TestSize.Level1) +{ + std::string key = "web.engine.test"; + Json::Value value = static_cast(ArkWebEngineType::EVERGREEN); + ProcessParamItem(key, value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 0); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessParamItem_003, TestSize.Level1) +{ + std::string key = "web.engine.default"; + Json::Value value = static_cast(ArkWebEngineType::EVERGREEN); + ProcessParamItem(key, value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 2); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessParamItem_004, TestSize.Level1) +{ + std::string key = "web.engine.enforce"; + Json::Value value = static_cast(ArkWebEngineType::EVERGREEN); + ProcessParamItem(key, value); + EXPECT_EQ(OHOS::system::GetIntParameter(key, 0), 2); +} + +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_ProcessParamItem_005, TestSize.Level1) +{ + std::string key = "web.engine.legacyApp"; + std::string appBundleName = "com.example.myapplication"; + Json::Value value(Json::arrayValue); + value.append(appBundleName); + ProcessParamItem(key, value); + EXPECT_NE(g_legacyApp, nullptr); + EXPECT_EQ(g_legacyApp->find(appBundleName) != g_legacyApp->end(), true); +} } // namespace OHOS::NWeb \ No newline at end of file -- Gitee From 87adf323b16720750d1a59a2fc795d1e1e2a11fe Mon Sep 17 00:00:00 2001 From: LGH W Date: Wed, 10 Sep 2025 20:04:56 +0800 Subject: [PATCH 120/124] fix log hint and bug Signed-off-by: LGH W --- arkweb_utils/arkweb_utils.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arkweb_utils/arkweb_utils.cpp b/arkweb_utils/arkweb_utils.cpp index 0e454d2f4..815da6aef 100644 --- a/arkweb_utils/arkweb_utils.cpp +++ b/arkweb_utils/arkweb_utils.cpp @@ -144,9 +144,8 @@ static void ProcessEnforceParam(const Json::Value& value) int intValue = value.asInt(); if (intValue != static_cast(ArkWebEngineType::EVERGREEN)) { WVLOG_E("Invalid value for web.engine.enforce: %{public}d, " - "must be LEGACY(%{public}d) or EVERGREEN(%{public}d)", + "must be EVERGREEN(%{public}d)", intValue, - static_cast(ArkWebEngineType::LEGACY), static_cast(ArkWebEngineType::EVERGREEN)); return; } @@ -228,7 +227,7 @@ static void ParseCloudCfg() void SelectWebcoreBeforeProcessRun(const std::string& appBundleName) { - WVLOG_I("Calculate CloudEnableAppVersion for app %{public}s.", appBundleName.c_str()); + WVLOG_I("SelectWebcoreBeforeProcessRun for app %{public}s.", appBundleName.c_str()); g_appBundleName = appBundleName; if (g_legacyApp && g_legacyApp->find(appBundleName) != g_legacyApp->end()) { @@ -301,8 +300,7 @@ ArkWebEngineVersion CalculateActiveWebEngineVersion() return static_cast(g_appEngineVersion); } - if (g_cloudEnableAppVersion == static_cast(ArkWebEngineType::LEGACY) || - g_cloudEnableAppVersion == static_cast(ArkWebEngineType::EVERGREEN)) { + if (g_cloudEnableAppVersion == static_cast(ArkWebEngineType::LEGACY)) { WVLOG_I("CalculateActiveWebEngineVersion CloudEnableAppVersion: %{public}d", g_cloudEnableAppVersion); return static_cast(g_cloudEnableAppVersion); } -- Gitee From 3975e10f369d471105248a09bee624e96276b96d Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Wed, 10 Sep 2025 20:11:39 +0800 Subject: [PATCH 121/124] site isolation ut Signed-off-by: quyue00807312 --- .../nweb_helper_test/nweb_helper_ex_test.cpp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index 9ff6f86ea..9acd54bb2 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -499,6 +499,30 @@ HWTEST_F(NwebHelperTest, NWebHelper_ParseNWebLTPOConfig_001, TestSize.Level1) EXPECT_TRUE(NWebConfigHelper::Instance().ltpoConfig_.empty()); } +/** + * @tc.name: NWebHelper_GetSiteIsolationMode_001 + * @tc.desc: GetSiteIsolationMode. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_GetSiteIsolationMode_001, TestSize.Level1) +{ + NWebHelper::Instance().nwebEngine_ = nullptr; + NWebHelper::Instance().bundlePath_ = ""; + 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().GetSiteIsolationMode(); + EXPECT_EQ(manager, nullptr); + auto nwebengineMock = std::make_shared(); + NWebHelper::Instance().nwebEngine_ = nwebengineMock; + auto manager1 = NWebHelper::Instance().GetSiteIsolationMode(); + EXPECT_EQ(manager1, nullptr); + NWebHelper::Instance().nwebEngine_ = nullptr; +} + /** * @tc.name: NWebHelper_SetHostIP_001 * @tc.desc: SetHostIP. @@ -947,6 +971,24 @@ HWTEST_F(NwebHelperTest, NWebHelper_IsPrivateNetworkAccessEnabled_001, TestSize. EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); } +/** + * @tc.name: NWebHelper_SetAutoPreconnect_001 + * @tc.desc: SetAutoPreconnect.. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NwebHelperTest, NWebHelper_SetAutoPreconnect_001, TestSize.Level1) +{ + int32_t nweb_id = 1; + auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); + EXPECT_EQ(nwebHelper, nullptr); + + NWebHelper::Instance().SetAutoPreconnect(true); + EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, true); + NWebHelper::Instance().SetAutoPreconnect(false); + EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, false); +} + /** * @tc.name: NWebHelper_SetAutoPreconnect_001 * @tc.desc: SetAutoPreconnect.. -- Gitee From a228ecea09ecc6da6ef5b58426ec03e5a966c43f Mon Sep 17 00:00:00 2001 From: quyue00807312 Date: Wed, 10 Sep 2025 20:21:46 +0800 Subject: [PATCH 122/124] site isolation ut Signed-off-by: quyue00807312 --- .../nweb_helper_test/nweb_helper_ex_test.cpp | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index 9acd54bb2..9ff6f86ea 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -499,30 +499,6 @@ HWTEST_F(NwebHelperTest, NWebHelper_ParseNWebLTPOConfig_001, TestSize.Level1) EXPECT_TRUE(NWebConfigHelper::Instance().ltpoConfig_.empty()); } -/** - * @tc.name: NWebHelper_GetSiteIsolationMode_001 - * @tc.desc: GetSiteIsolationMode. - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(NwebHelperTest, NWebHelper_GetSiteIsolationMode_001, TestSize.Level1) -{ - NWebHelper::Instance().nwebEngine_ = nullptr; - NWebHelper::Instance().bundlePath_ = ""; - 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().GetSiteIsolationMode(); - EXPECT_EQ(manager, nullptr); - auto nwebengineMock = std::make_shared(); - NWebHelper::Instance().nwebEngine_ = nwebengineMock; - auto manager1 = NWebHelper::Instance().GetSiteIsolationMode(); - EXPECT_EQ(manager1, nullptr); - NWebHelper::Instance().nwebEngine_ = nullptr; -} - /** * @tc.name: NWebHelper_SetHostIP_001 * @tc.desc: SetHostIP. @@ -971,24 +947,6 @@ HWTEST_F(NwebHelperTest, NWebHelper_IsPrivateNetworkAccessEnabled_001, TestSize. EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); } -/** - * @tc.name: NWebHelper_SetAutoPreconnect_001 - * @tc.desc: SetAutoPreconnect.. - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(NwebHelperTest, NWebHelper_SetAutoPreconnect_001, TestSize.Level1) -{ - int32_t nweb_id = 1; - auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id); - EXPECT_EQ(nwebHelper, nullptr); - - NWebHelper::Instance().SetAutoPreconnect(true); - EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, true); - NWebHelper::Instance().SetAutoPreconnect(false); - EXPECT_EQ(NWebHelper::Instance().autoPreconnectEnabled_, false); -} - /** * @tc.name: NWebHelper_SetAutoPreconnect_001 * @tc.desc: SetAutoPreconnect.. -- Gitee From 57ef657819457b5f34cc8887ec061e81a9d68cfd Mon Sep 17 00:00:00 2001 From: wangdantong Date: Thu, 11 Sep 2025 11:42:19 +0000 Subject: [PATCH 123/124] fix fuzztest timeout when running Signed-off-by: wangdantong Change-Id: I235c151649d849ed4a499835f29db1e17abc1909 --- .../nativebufferadapter_fuzzer.cpp | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/test/fuzztest/nativebufferadapter_fuzzer/nativebufferadapter_fuzzer.cpp b/test/fuzztest/nativebufferadapter_fuzzer/nativebufferadapter_fuzzer.cpp index bbfffbbee..dd0b2cf37 100644 --- a/test/fuzztest/nativebufferadapter_fuzzer/nativebufferadapter_fuzzer.cpp +++ b/test/fuzztest/nativebufferadapter_fuzzer/nativebufferadapter_fuzzer.cpp @@ -22,23 +22,6 @@ using namespace OHOS::NWeb; namespace OHOS { -void TestAllocate(void** outBuffer) -{ - OH_NativeBuffer_Config config = { - .width = 10, - .height = 10, - .format = OH_NativeBuffer_Format::NATIVEBUFFER_PIXEL_FMT_RGBA_8888, - .usage = 1, - }; - - OH_NativeBuffer* buffer = OH_NativeBuffer_Alloc(&config); - if (buffer != nullptr) { - *outBuffer = buffer; - } else { - *outBuffer = nullptr; - } -} - constexpr int MAX_SET_NUMBER = 1000; bool NativeBufferAdapterFuzzTest(const uint8_t* data, size_t size) @@ -47,8 +30,6 @@ bool NativeBufferAdapterFuzzTest(const uint8_t* data, size_t size) return false; } FuzzedDataProvider dataProvider(data, size); - uint32_t width = dataProvider.ConsumeIntegralInRange(1, MAX_SET_NUMBER); - uint32_t height = dataProvider.ConsumeIntegralInRange(1, MAX_SET_NUMBER); uint64_t usage = dataProvider.ConsumeIntegralInRange(1, MAX_SET_NUMBER); int32_t fence = dataProvider.ConsumeIntegralInRange(1, MAX_SET_NUMBER); int socketFd = dataProvider.ConsumeIntegralInRange(1, MAX_SET_NUMBER); @@ -70,22 +51,6 @@ bool NativeBufferAdapterFuzzTest(const uint8_t* data, size_t size) adapter.NativeBufferFromNativeWindowBuffer(nativeWindowBuffer, &nativeBuffer); void* address = nullptr; adapter.Lock(buffer, usage, fence, &address); - adapter.FreeNativeBuffer(buffer); - - TestAllocate(&nativeBuffer); - adapter.AcquireBuffer(nativeBuffer); - adapter.Release(nativeBuffer); - adapter.GetSeqNum(nativeBuffer); - adapter.GetEGLBuffer(nativeBuffer, &eglBuffer); - adapter.FreeEGLBuffer(eglBuffer); - OH_NativeBuffer_Config config = { - .width = width, - .height = height, - .format = OH_NativeBuffer_Format::NATIVEBUFFER_PIXEL_FMT_RGBA_8888, - .usage = OH_NativeBuffer_Usage::NATIVEBUFFER_USAGE_HW_RENDER, - }; - buffer = OH_NativeBuffer_Alloc(&config); - adapter.Lock(buffer, usage, fence, &address); adapter.Unlock(buffer, &fence); adapter.FreeNativeBuffer(buffer); return true; -- Gitee From 40da82b4653ae0349d796a9e075a7c5f5c013b1e Mon Sep 17 00:00:00 2001 From: fuyongyuan Date: Wed, 20 Aug 2025 17:33:58 +0800 Subject: [PATCH 124/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=A9=E7=BD=91?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=AD=EF=BC=8Ccrashpad=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=9A=84so=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.gni | 3 ++- ohos_adapter/BUILD.gn | 5 +++++ ohos_nweb/BUILD.gn | 7 +++++++ ohos_nweb/src/nweb_crashpad_handler_main.cpp | 11 ++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config.gni b/config.gni index 14dbc04ac..3085542b6 100644 --- a/config.gni +++ b/config.gni @@ -105,4 +105,5 @@ webview_engine_so = "libarkweb_engine.so" webview_app_hap_path = "/system/app/ArkWeb/ArkWebCore.hap" webview_app_hap_path2 = "/system/app/${webview_package_name}/ArkWebCore.hap" -legacy_webview_sandbox_lib_path = "/data/storage/el1/bundle/arkweblegacy/libs/${target_cpu}" \ No newline at end of file +legacy_webview_sandbox_lib_path = "/data/storage/el1/bundle/arkweblegacy/libs/${target_cpu}" +asan_webview_sandbox_lib_path = "/data/storage/el1/bundle/arkwebcore_asan/libs/${target_cpu}" \ No newline at end of file diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 1901b59f4..f2bda40cf 100644 --- a/ohos_adapter/BUILD.gn +++ b/ohos_adapter/BUILD.gn @@ -59,6 +59,11 @@ ohos_shared_library("nweb_ohos_adapter") { "WEBVIEW_SANDBOX_PATH=\"${webview_sandbox_path}\"", ] + if (use_hwasan) { + defines += [ + "WEBVIEW_SANDBOX_LIB_PATH_ASAN=\"${asan_webview_sandbox_lib_path}\"", + ] + } sources = [ "aafwk_adapter/src/aafwk_app_mgr_client_adapter_impl.cpp", "aafwk_adapter/src/aafwk_browser_client_adapter_impl.cpp", diff --git a/ohos_nweb/BUILD.gn b/ohos_nweb/BUILD.gn index 0ca315a0a..1ccc21a3e 100644 --- a/ohos_nweb/BUILD.gn +++ b/ohos_nweb/BUILD.gn @@ -37,6 +37,13 @@ defines += [ "WEBVIEW_ENGINE_SO=\"${webview_engine_so}\"", ] +if (use_hwasan) { + defines += [ + "IS_ASAN", + "WEBVIEW_SANDBOX_LIB_PATH_ASAN=\"${asan_webview_sandbox_lib_path}\"", + ] +} + config("nweb_config") { include_dirs = [ "${target_gen_dir}/include" ] include_dirs += [ "include" ] diff --git a/ohos_nweb/src/nweb_crashpad_handler_main.cpp b/ohos_nweb/src/nweb_crashpad_handler_main.cpp index abd52ded0..c59254cde 100644 --- a/ohos_nweb/src/nweb_crashpad_handler_main.cpp +++ b/ohos_nweb/src/nweb_crashpad_handler_main.cpp @@ -48,17 +48,22 @@ std::optional GetEngineType(int argc, char* argv[]) { int main(int argc, char* argv[]) { std::string libCrashpadHandler; + std::string webPath = WEBVIEW_SANDBOX_LIB_PATH; +#if defined(IS_ASAN) && defined(webview_arm64) + if (access(std::string(WEBVIEW_SANDBOX_LIB_PATH_ASAN).c_str(), F_OK) == 0) { + webPath = WEBVIEW_SANDBOX_LIB_PATH_ASAN; + } +#endif if (auto engineType = GetEngineType(argc, argv); engineType.has_value() && engineType.value() == "LEGACY") { libCrashpadHandler = std::string(LEGACY_WEBVIEW_SANDBOX_LIB_PATH) + "/" + std::string(WEBVIEW_CRASHPAD_HANDLER_SO); } else { - libCrashpadHandler = std::string(WEBVIEW_SANDBOX_LIB_PATH) + "/" - + std::string(WEBVIEW_CRASHPAD_HANDLER_SO); + libCrashpadHandler = webPath + "/" + std::string(WEBVIEW_CRASHPAD_HANDLER_SO); } Dl_namespace dlns; dlns_init(&dlns, "nweb_ns"); - dlns_create(&dlns, std::string(WEBVIEW_SANDBOX_LIB_PATH).c_str()); + dlns_create(&dlns, webPath.c_str()); Dl_namespace ndkns; dlns_get("ndk", &ndkns); -- Gitee