diff --git a/arkweb_utils/BUILD.gn b/arkweb_utils/BUILD.gn index fd4cdf5b64cc7ceefd6207d49b8614e338453b64..4f227a9ba1a32757cced28453b1ec56b823d8bfa 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 0000000000000000000000000000000000000000..024539b3c5166e45b9459f84a2bf0bdd3989cb83 --- /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 0000000000000000000000000000000000000000..434251b9d846a80c8ac110b69540505de146abfa --- /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 ec54831f7c5f2e72e9c91ad2ad2a8784a00a37ee..815da6aef7137360d21f4adf9337501c50579240 100644 --- a/arkweb_utils/arkweb_utils.cpp +++ b/arkweb_utils/arkweb_utils.cpp @@ -21,11 +21,20 @@ #include #include #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); 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 = @@ -84,63 +93,123 @@ 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 bool validateSpecialParams(const std::string& key, int value) +#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(); + +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 EVERGREEN(%{public}d)", + intValue, + 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; } @@ -148,18 +217,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("SelectWebcoreBeforeProcessRun 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)))) { @@ -169,6 +251,7 @@ void PreloadArkWebLibForBrowser() static_cast(ArkWebEngineType::EVERGREEN)); } } + g_activeEngineVersion = CalculateActiveWebEngineVersion(); return; } @@ -187,39 +270,54 @@ 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() +{ + 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); } return static_cast(g_appEngineVersion); } + + if (g_cloudEnableAppVersion == static_cast(ArkWebEngineType::LEGACY)) { + 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)); 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); return static_cast(webEngineDefault); } @@ -328,7 +426,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; } @@ -390,7 +487,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,11 +508,71 @@ 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."); } 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, error: %{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 79ccd01855571bace6181a8ab44cc4b026d52694..d34a3296d64d91104a066ba7178be2731e474da3 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(); @@ -88,7 +89,11 @@ 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); + +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/config.gni b/config.gni index 14dbc04ac00c309c27ea8e7e170d2c7425b2a768..3085542b6840249d02480bda73fc0c2029a3931b 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/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets b/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets index 214d0b8ae933eb4ff93b79cddfcdfb611199431d..bf339388ac45db238911bf81e58d00c4ce04ec90 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 3052438aa214fd0ba7b1db725612ff5aaf594cdd..e304a6449922fdabfc09736141916cebbac737ae 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/cj/include/web_scheme_handler_request.h b/interfaces/kits/cj/include/web_scheme_handler_request.h index 68169f3501ab5944a09cd704112c9498a129c27c..ef69c421d9d0640916d495cd1f9e995817fbcb5b 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/BUILD.gn b/interfaces/kits/napi/BUILD.gn index b313b485e08438d7a462488419b648946f0883e9..bf882224fc6f69de71b0b40ec705f3494c9d25ee 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 84f9f8aa95699e66a8d16f57dc64edc6c019e6d5..983514fb6016c425c6183cebb87c9319c28e4bfb 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/js/webview_export.js b/interfaces/kits/napi/js/webview_export.js index 29518b169862a13ab08d0ab345582326765b499e..4185ecb727c306292636762f679cf071d1a4aa0a 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'; @@ -79,9 +82,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 +119,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) => { @@ -133,10 +136,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 +148,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)); @@ -283,7 +286,7 @@ 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 +296,7 @@ function fileSelectorListItem(callback, sysResource, text, func) { top: 13, bottom: 13 }); + Text.width('100%'); Text.pop(); Row.pop(); Row.pop(); @@ -328,7 +332,6 @@ function fileSelectorDialog(callback) { function fileSelectorDialogForPC(callback) { Column.create(); Column.height(272); - Column.width(400); fileSelectorDialog(callback); Row.create(); Row.onClick(() => { @@ -343,7 +346,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); @@ -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) { @@ -496,7 +522,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 { @@ -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/interfaces/kits/napi/webviewcontroller/napi_prefetch_options.cpp b/interfaces/kits/napi/webviewcontroller/napi_prefetch_options.cpp new file mode 100644 index 0000000000000000000000000000000000000000..38c6678edba900b8d623ee0d862c07a0fd6d3bfb --- /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 0000000000000000000000000000000000000000..d61ea5912dba71b5556e09cc6bd5f60c2cd801ba --- /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 0028344f26bd5f253b0c36dcf1119228e117ab0a..e93803932cd4a5b770f2c9ed284bf46c038cc365 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)?:\\/\\/.+"; @@ -72,15 +72,17 @@ 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"; +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) @@ -492,6 +494,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; @@ -630,7 +683,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 +707,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), @@ -723,6 +777,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), @@ -743,13 +799,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), @@ -773,6 +828,9 @@ 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), + 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(), @@ -972,6 +1030,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 +1052,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, @@ -1039,6 +1097,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; @@ -1207,7 +1277,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; } @@ -2919,7 +2990,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; } @@ -4524,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; @@ -4617,6 +4686,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 +4738,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 { @@ -4857,12 +4928,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; } @@ -4876,53 +4947,48 @@ 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); + } + 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; } - 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 && !IS_CALLING_FROM_M114()) { + 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); @@ -5041,92 +5107,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 +5172,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,25 +5546,110 @@ napi_value NapiWebPrintDocument::JsConstructor(napi_env env, napi_callback_info return thisVar; } -napi_value NapiWebviewController::SetPrintBackground(napi_env env, napi_callback_info info) +napi_value NapiWebviewController::SetDownloadDelegate(napi_env env, napi_callback_info info) { - napi_value result = nullptr; + WVLOG_D("WebDownloader::JS_SetDownloadDelegate"); + NWebHelper::Instance().LoadNWebSDK(); + + size_t argc = 1; + napi_value argv[1] = {0}; napi_value thisVar = nullptr; - size_t argc = INTEGER_ONE; - napi_value argv[INTEGER_ONE] = { 0 }; + void* data = nullptr; + napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - 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; + 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_); - bool printBackgroundEnabled = false; - if (!NapiParseUtils::ParseBoolean(env, argv[0], printBackgroundEnabled)) { - BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "enable", "boolean")); + 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; + 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, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "one")); + return result; + } + + bool printBackgroundEnabled = false; + if (!NapiParseUtils::ParseBoolean(env, argv[0], printBackgroundEnabled)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "enable", "boolean")); return result; } @@ -5746,6 +5813,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 +5835,7 @@ napi_value NapiWebviewController::IsIntelligentTrackingPreventionEnabled( WebviewController *webviewController = GetWebviewController(env, info); if (!webviewController) { + WVLOG_E("IsIntelligentTrackingPreventionEnabled failed for webviewController failed"); return result; } @@ -6184,7 +6253,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; } @@ -6214,7 +6284,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; } @@ -6248,29 +6319,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,6 +6497,42 @@ napi_value NapiWebviewController::ClearHostIP(napi_env env, napi_callback_info i 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::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) { @@ -6535,97 +6619,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,28 +6810,106 @@ napi_value NapiWebviewController::WebPageSnapshot(napi_env env, napi_callback_in return result; } -napi_value NapiWebviewController::SetPathAllowingUniversalAccess( - napi_env env, napi_callback_info info) +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_CALL(env, napi_get_undefined(env, &result)); napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); - WebviewController *webviewController = GetWebviewController(env, info); - if (!webviewController) { - WVLOG_E("SetPathAllowingUniversalAccess init webview controller error."); + if (argc != INTEGER_ONE) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "one")); return result; } - bool isArray = false; - NAPI_CALL(env, napi_is_array(env, argv[INTEGER_ZERO], &isArray)); - if (!isArray) { + + std::string urlTrustList; + if (!NapiParseUtils::ParseString(env, argv[0], urlTrustList)) { BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, - NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "pathList", "Array")); + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "urlTrustList", "string")); return result; } - std::vector pathList; + 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) +{ + 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); + WebviewController *webviewController = GetWebviewController(env, info); + if (!webviewController) { + WVLOG_E("SetPathAllowingUniversalAccess init webview controller error."); + return result; + } + bool isArray = false; + NAPI_CALL(env, napi_is_array(env, argv[INTEGER_ZERO], &isArray)); + if (!isArray) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "pathList", "Array")); + return result; + } + std::vector pathList; uint32_t pathCount = 0; NAPI_CALL(env, napi_get_array_length(env, argv[INTEGER_ZERO], &pathCount)); for (uint32_t i = 0 ; i < pathCount ; i++) { @@ -6867,33 +6938,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 +6984,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); @@ -6923,6 +7000,10 @@ napi_value NapiWebviewController::GetScrollOffset(napi_env env, napi_value NapiWebviewController::GetPageOffset(napi_env env, napi_callback_info info) { + if (IS_CALLING_FROM_M114()) { + BusinessError::ThrowErrorByErrcode(env, CAPABILITY_NOT_SUPPORTED_ERROR); + return nullptr; + } napi_value result = nullptr; napi_value horizontal; napi_value vertical; @@ -6932,9 +7013,7 @@ napi_value NapiWebviewController::GetPageOffset(napi_env env, if (!webviewController) { return nullptr; } - if (ArkWeb::getActiveWebEngineVersion() >= ArkWeb::ArkWebEngineVersion::M132) { - webviewController->GetPageOffset(&offsetX, &offsetY); - } + 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); @@ -6943,42 +7022,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) @@ -7370,6 +7440,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; @@ -7412,7 +7483,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; } @@ -7454,7 +7526,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; } @@ -7604,6 +7677,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; } @@ -7612,7 +7686,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) { @@ -7620,23 +7694,24 @@ 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; 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; } @@ -7725,5 +7800,161 @@ 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("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)); + return result; +} + +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; + 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; + } + + 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 == 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)) { + 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)) { + BusinessError::ThrowErrorByErrcode(env, INIT_ERROR, + "InitError 17100001: cannot change (AdvancedSecurityMode active)"); + } + + return result; +} + +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()); + NAPI_CALL(env, napi_create_int32(env, mode, &result)); + 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 7bb2fa100828642e31833f06f265ef8affcf865d..d34fd72274b129cce0905c77b3923fa039439b51 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 { @@ -255,8 +256,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); @@ -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); @@ -417,6 +422,9 @@ 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); + static napi_value SetSocketIdleTimeout(napi_env env, napi_callback_info info); }; class ArkWebTransfer { diff --git a/interfaces/kits/napi/webviewcontroller/web_scheme_handler_request.cpp b/interfaces/kits/napi/webviewcontroller/web_scheme_handler_request.cpp index 12f390273b942ca54dc594665439c7541553ebc5..f30ebba9a6055eb65171dbbe3e329acc9781ed5c 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; } diff --git a/interfaces/kits/napi/webviewcontroller/webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/webview_controller.cpp index fc9182510029b31edc982ffe87e93c9a96ba1c69..bdcca246e8f9010b2c02c531d700bdef5511f2e1 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"; @@ -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 5a5579c85ffc83e38cadfff0cbf11153441da04f..58a76cb02229b0941dd0d1f68fd736cea7cf7b2c 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/interfaces/native/arkweb_interface.cpp b/interfaces/native/arkweb_interface.cpp index 9aa5e6bb369e5b5cb43d26b6454dfa818c75c7b5..53f1481c179f3caaf0b96ac6f6e6729ce69104d1 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(); diff --git a/interfaces/native/arkweb_scheme_handler.cpp b/interfaces/native/arkweb_scheme_handler.cpp index 3cf38891f2fbd1cd5a980f2241bebcad581ecf59..39bbf3549b4f397a4ac6b951fdbef7c0eb7025be 100644 --- a/interfaces/native/arkweb_scheme_handler.cpp +++ b/interfaces/native/arkweb_scheme_handler.cpp @@ -124,10 +124,8 @@ void LoadSchemeHandlerApi(SchemeHandlerApi* api) bool EnsureSdkLoaded() { if (g_SchemeHandlerApi) { - WVLOG_I("SchemeHandlerApi had loaded."); return true; } - auto* schemeHandlerApi = new (std::nothrow) SchemeHandlerApi(); if (schemeHandlerApi == nullptr) { WVLOG_I("schemeHandlerApi is nullptr."); @@ -135,6 +133,7 @@ bool EnsureSdkLoaded() } LoadSchemeHandlerApi(schemeHandlerApi); g_SchemeHandlerApi = schemeHandlerApi; + WVLOG_I("SchemeHandlerApi had loaded."); return true; } #undef FOR_EACH_API_FN diff --git a/ohos_adapter/BUILD.gn b/ohos_adapter/BUILD.gn index 1901b59f46649001ab76bfba11c5e1db9381e948..22236bb879d1e6e4867be03751d71e222834ffd8 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 @@ -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", @@ -165,6 +170,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", 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 2a8fe27b2eafac2a9249b2ce5339425745005635..4e5d6cfd0de8755b617412363ee15841daf1339b 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/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp b/ohos_adapter/aafwk_adapter/src/aafwk_browser_host_impl.cpp index 6bbea55d04ec0a21fafca55eb9dd34c2d155c52f..dbdfb275c93f9b2fa96a8687b1430028d25bc30a 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("passSurface failed"); + return; + } surface_map_.emplace(surface_id, surfaceTmp); utils->Add(surface_id, surfaceTmp); } 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 64d0d909a638d40645bf8cdff38787171aa3ee90..01bbab4df32ada3cf4c12783dbe5b494adeb6898 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; diff --git a/ohos_adapter/flowbuffer_adapter/src/flowbuffer_adapter_impl.cpp b/ohos_adapter/flowbuffer_adapter/src/flowbuffer_adapter_impl.cpp index 11b46303f7b83d32f489623271e52163f35183fa..de047b724c79dea1dc235581315979761cb21bd7 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; diff --git a/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h b/ohos_adapter/graphic_adapter/include/vsync_adapter_impl.h index ee5ad1b0c6e0e99f9175f2fc4d6971cc860a8608..b29b2267d72ed1e0d29f80fe6441de72eb6854d6 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 5db1fdac0745abef355df6a40b62744ee1d2f208..b7659644c4cbe12958774247f706f79004c05e23 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/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp b/ohos_adapter/inputmethodframework_adapter/src/imf_adapter_impl.cpp index acdcaf97afffe1ad86afb00481d346c5c55beff8..5362d46c334ec0a68508eff250934bd58961472a 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; @@ -281,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 }; @@ -323,7 +308,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 +352,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 +374,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 +416,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 +439,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; @@ -486,10 +511,14 @@ 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(); + if (listener_) { + listener_->WebSetImeShow(info.visible); + if (triggerFrom == MiscServices::Trigger::IME_APP) { + WVLOG_I("IMFTextListenerAdapterImpl::NotifyPanelStatusInfo, info.IME_APP"); + listener_->KeyboardUpperRightCornerHide(); + } } } } // namespace OHOS::NWeb diff --git a/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h b/ohos_adapter/keystore_adapter/include/keystore_adapter_impl.h index a9c5611263737e52a357d6d64515e9c4ff234397..2c956b9283df6cf82263bc94a2e14a0d293047d2 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, bool mayGenerateKey); }; -} // 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 d3a8f16f688aecfbec4ba8d44fc990096f93c72c..4a3c7b074a1e162ebec4f125dcf4f39992ac7695 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,61 @@ 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, 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); + return false; + } + 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("hks key is not exist, 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); + 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), true)) { 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 +148,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), false)) { 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,20 +205,18 @@ 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); } 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 }, 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 34d22518a5f037a037a3c6c10c73cc4fb172cdac..12ae5715628a4608778713fc347848bed407fa10 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 c30c042cef7831f147e6f96ba9e54b0361c6b8f6..8c5d112f7558748fa1b912345e8efe05ae6132ac 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 a7ee1fe937f9c11178a5cd3ed65eb9ebd758bffb..cedb9284dfe69e13c37af5c71b32a61c3051014c 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; 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 8f4650c10207346321bfd64d564c84f9c13bb965..91ec55111855244d6600119a7bef66dc8c8e7f3a 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; 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 bf44630b0d2088ca67c7e4cdd4ce19441667de95..7429e61f5e230f58e75ca38f457a19d90b1099cf 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) 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 a49f1877d3aa826a058eddb24d7b283e2796dc5b..4257152aa78ae8d2d1a7f18d9218067b72fb0008 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; } diff --git a/ohos_adapter/multimodalinput_adapter/src/mmi_adapter_impl.cpp b/ohos_adapter/multimodalinput_adapter/src/mmi_adapter_impl.cpp index 7e9921be9334a496e2f1d7e249b526dc08c50b3e..b3d0ff16e251e76f57f86e0c83aea90d541a7e9c 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); 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 0dacb3af0cb82ef019ec8552b99d090ea503b207..46174ee7984481524073fe1470ba1ff65348777d 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 ""; } 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 7eb15da90490fddbe8fc9da79acf0f23fdd7f587..374b29d68d896ac903d13f0f25176cf6a7fdc271 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,8 @@ 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", ""); + return apiname.empty() ? OHOS::system::GetParameter("const.product.os.dist.version", "") : apiname; } std::string SystemPropertiesAdapterImpl::GetUserAgentBaseOSName() @@ -252,7 +251,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_glue/BUILD.gn b/ohos_glue/BUILD.gn index a0871a88c29b1a391de4781f83304c24eeea1dc7..0e6c60dc94ee74f787bcec54209e951e96adc87d 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", @@ -227,6 +231,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 +329,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", @@ -427,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", @@ -475,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 = [ @@ -1087,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 da3ef3d5145922d2fcaf6ca4d920c303aada0a43..d89a058eae0911ecfb49e69f2b5396d4de9178bf 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", @@ -209,9 +211,12 @@ 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", + "//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", @@ -301,6 +306,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", @@ -352,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", @@ -431,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", @@ -450,6 +460,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 +504,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_adapter/drm_adapter.h b/ohos_interface/include/ohos_adapter/drm_adapter.h index 3dd0968a8e3cc41b01067d53b82d556a8adb0706..cc30d91cd46bf795bafaaffaba1263c90411a374 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 { @@ -59,7 +60,7 @@ public: virtual void OnStorageClearInfoForLoadFail(const std::string& sessionId) = 0; - virtual void OnMediaLicenseReady(bool success) {}; + virtual void OnMediaLicenseReady(bool success) {} }; class DrmAdapter { diff --git a/ohos_interface/include/ohos_adapter/event_handler_adapter.h b/ohos_interface/include/ohos_adapter/event_handler_adapter.h index f6d77fadf911d0798ee822c012faccf3177ada0b..d275ef3221a1bdd735d2a8c505b98d4374b9e276 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 diff --git a/ohos_interface/include/ohos_adapter/imf_adapter.h b/ohos_interface/include/ohos_adapter/imf_adapter.h index b8584b438352806230ddc9d821522c9486c2d1ad..110d825ded80bd8f41585a58f7f6e0605c6c4c07 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_adapter/ohos_adapter_helper.h b/ohos_interface/include/ohos_adapter/ohos_adapter_helper.h index 1a91e18c027a92daa0c2464b066e342052b7542e..dc382339a83b685ed21aae95d58c70ebeb387494 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_adapter/ohos_image_decoder_adapter.h b/ohos_interface/include/ohos_adapter/ohos_image_decoder_adapter.h index aa4e85aabbdfc9e3b5458dd6041cf391f14c3349..d58e8f7aadcd02e2393eeebd17e02066fff5416a 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) { return false; } }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_adapter/screen_capture_adapter.h b/ohos_interface/include/ohos_adapter/screen_capture_adapter.h index 271127c04839bdefc930951b3db259cd883f86f4..b8693af2ae6294400eb0621844c6c693812029cb 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, }; diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 1c904e8f5a4e317456c379ea1c035cf5f13042f9..b7d43181a545c2979e6a31e6e3c3e2a59e49c598 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; @@ -155,6 +169,17 @@ enum class RenderProcessMode : int32_t { MULTIPLE_MODE = 1, }; +enum class SiteIsolationMode { + PARTIAL, + STRICT, +}; + +enum class SetSiteIsolationModeErr : int32_t { + ADVANCED_SECURITY_SET_ERR = 2, + SINGLE_RENDER_SET_STRICT_ERR = 3, + ALREADY_SET_ERR = 4, +}; + class NWebTouchPointInfo { public: virtual ~NWebTouchPointInfo() = default; @@ -164,6 +189,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, @@ -197,6 +234,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; @@ -1930,7 +1975,7 @@ public: virtual std::unique_ptr CreateWebPrintDocumentAdapterV2( const std::string& jobName) { return nullptr; - }; + } /* * @brief Set unique key of current page for insert frame. @@ -2061,6 +2106,56 @@ 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) {} + + /** + * @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) {} + + /** + * @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) {} + + /** + * @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) {} + + /** + * @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) {} + + /** + * @brief Set web should ignore zoom limit. + */ + /*--ark web()--*/ + virtual void SetForceEnableZoom(bool forceEnableZoom) const {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_autofill.h b/ohos_interface/include/ohos_nweb/nweb_autofill.h index e3eb979fa50489944bc463a207a36ad4fd6439cb..7fc117e619fbdf008b75fdb7722015da6f7fb6de 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/include/ohos_nweb/nweb_context_menu_params.h b/ohos_interface/include/ohos_nweb/nweb_context_menu_params.h index 0720b3caf9044f1ca6dc9dab4304f75c7429a4c3..0e680702817162b9c4e8a9e637f54ea9b5f3b84b 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; diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 039873fb9f6691265d64222bd785474caee2cef7..5b23cc06bcbc799024241778a202665673a17d6d 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; @@ -133,6 +137,8 @@ public: } virtual void SetWebDestroyMode(WebDestroyMode mode) {} + + virtual void SetSocketIdleTimeout(int32_t timeout) {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/include/ohos_nweb/nweb_handler.h b/ohos_interface/include/ohos_nweb/nweb_handler.h index 59832df9e12b6aa30f7c09f737ca46d03f3ecd04..72c5f908cdbbe3237c605d1e75d3ccc92a1c9d68 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 { @@ -355,6 +357,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; @@ -1255,6 +1287,72 @@ 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) {} + + /** + * @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) {} + + /** + * @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) {} + + /** + * @brief Called when received website security risk check finish. + * @param threat_type The threat type of website. + */ + virtual void OnSafeBrowsingCheckFinish(int threat_type) {} + + /** + * @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 ""; + } + + /** + * @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/include/ohos_nweb/nweb_native_message_callback.h b/ohos_interface/include/ohos_nweb/nweb_native_message_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..4a0743a70f7034d0cc4d3cc37770ef76f487f089 --- /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 0000000000000000000000000000000000000000..59cdbe670f7ea582c6e53f527100919e7ca7a59a --- /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 050a7b8de1af7a03774492ed8b4ca0b32f9d21fc..71683566ade08fdbcc7ae8f8a6c22a6b0fc93b68 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", @@ -232,6 +236,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", @@ -346,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", @@ -462,6 +474,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", @@ -472,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 8b3104f89a9fc189b4f2990d044be4128f38dcc9..16d0663d7810e40991ebe8c4adb5a16c6913bf9a 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,11 @@ 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, + 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_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 a1dede92f043c21538d24dd0ee5addce94313509..7a25ddcb618afe0d9feed7c404d42d371cf666a6 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 ade0f6a6d037244b8f6974d77434ef889fd0fe9e..86d3eff97c92053ef473c38f099f54ff953af0ba 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/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 4a095186aa98cd373300949e9c984b556526371a..573935e130d2dffd909bd3cd7a0c59165ac131f5 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_imftext_listener_adapter_wrapper.cpp b/ohos_interface/ohos_glue/ohos_adapter/bridge/webview/ark_imftext_listener_adapter_wrapper.cpp index fc65ab140a319afe0e67fe70b2aa3316727a0951..bef1386e1ec6dcd25245f4c0d4a3f5171b613cfd 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 cf15837de2963e731578a178ad06bfeca11e20e4..69aeb19c08aae02a2fe7f99b9aafdb3224c03875 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/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 1be2fbbc81a490f0b8e1527b83e1af3559cff038..7a1833b07b21feb2fbe2f693662ef6957f655b6f 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 8f3cb05428c7ca50694970434ac827dbee77393a..95ecb9fc42b2462532697ec8e0235065035af79e 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/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 d4aa306d4445cb5905f231780699edffa6d72e09..ea9b65b4a6a93e57dec0696521ad21a8d1149c1e 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_adapter/include/ark_imf_adapter.h b/ohos_interface/ohos_glue/ohos_adapter/include/ark_imf_adapter.h index 150b5bf80b6b1c29be97324f4028607a01fb4a6e..2badd92c9c47990f14bac862953f4995b1edd9d1 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_accessibility_node_info_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_accessibility_node_info_impl.cpp index be7881b6dc2d776a0fcbe831b3877f79f26e1c59..3f5741f08bd5b0bfc40490d8513e6c739d1364b4 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 be2a3d62834e166950c11f9622650f0bc773a4bf..924f689f276c081fc1998ca138ed9fe3a1e5dd7c 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_; }; 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 878866cbacf7a9354c42340a6da89faa1b48da92..f9558fb8c5b986ea84a12075303d1128b62f3c50 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/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 8380fefa2a2781a4b32425bda862b439e8bde798..3cb3f63d2ddabc697a4eeebfabb3cec3957e0f43 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 d28d262c87b858ff06b2e2bc94aecb905109f5d4..b3e319a55847d122e422fe88a9741206dfdd9a55 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_engine_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.cpp index 9e2ff21918afc138a7987c3a63cc459a31aeac37..a7abe5dd8ef120664de09ac5176dec7ac7772884 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,19 @@ 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()); +} + +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 061c3bc6161594f262e7fe46676c8227c805f052..0db19f26ed45f24657748f23c6ac2a057486619a 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,12 @@ public: void SetWebDestroyMode(int32_t mode) override; + int32_t SetSiteIsolationMode(int32_t mode) override; + + 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/webcore/ark_web_handler_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_handler_wrapper.cpp index 93e4e225b734962d4426c9c57593264a08c0c96f..aac710daf7e38d531a420afd9282782fe3815e07 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" @@ -56,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" @@ -1262,4 +1265,73 @@ 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_); +} + +void ArkWebHandlerWrapper::SetImeShow(bool visible) +{ + ark_web_handler_->SetImeShow(visible); +} + +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)); +} + +void ArkWebHandlerWrapper::OnSafeBrowsingCheckFinish(int threat_type) +{ + ark_web_handler_->OnSafeBrowsingCheckFinish(threat_type); +} + +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; +} + +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 b907f9690674a88770ea3046f5362eb76c6ee1aa..9251648d645cb1e643be8cd1795996ef073ce24e 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,73 @@ 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; + + /** + * @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; + + /** + * @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; + + /** + * @brief Called when received website security risk check finish. + * + * @param threat_type The threat type of website. + */ + void OnSafeBrowsingCheckFinish(int threat_type) 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 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/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 0000000000000000000000000000000000000000..ce6d10bcabaeba8d359d4b4a58994d5cf9ddfcab --- /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 0000000000000000000000000000000000000000..017cc8c209ed9e5a40f4de8d33de0753207b1d84 --- /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 0000000000000000000000000000000000000000..e3d61c61a426ca409138dcf3536715286c51161d --- /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 0000000000000000000000000000000000000000..fa6b942e2c7640015711922630f489a060274c83 --- /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/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 0000000000000000000000000000000000000000..adde606904451a997ba7a39ba3fa18a8ef57cb3e --- /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 0000000000000000000000000000000000000000..f7a5df3c49b59b2f5fc862aff76ba4ad6a3af84f --- /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_nweb_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_nweb_impl.cpp index b1666ea9a9def9a512af6e3586a5f9f22919cc48..62180b83eb09546b7ba03045f036b00ac614b991 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,53 @@ 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); +} + +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); +} + +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 c160b3e496cbd785789a942aff242fb7ea4ede16..313f99ee51270829765e68eb9e70a9ca0a9404f2 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,54 @@ 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; + + /** + * @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; + + /** + * @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; + + /** + * @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/webcore/ark_web_preference_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_preference_impl.cpp index 3b2a923385d9fcaf7b64e2ec8a2fca373d4dc98b..fab9f901845683c481dfc9f67e940d1cfa2357d6 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_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 0000000000000000000000000000000000000000..ebcaaefb8355009f6c6e48c7abb05257623d1a74 --- /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 0000000000000000000000000000000000000000..5404e4de6fc2035438d12c67c35d133e0229f311 --- /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/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 0000000000000000000000000000000000000000..3b9e506297c7a4de260879146dfcdf2e2eae5bb3 --- /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(); +} + +ArkWebSourceTool 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 0000000000000000000000000000000000000000..b86ca49555128ec6580dd14633c8f59ebd5ec164 --- /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_adsblock_manager_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_adsblock_manager_wrapper.cpp index 811b663019c7a4c6cff6275b3a903a0345207671..d722020f9fc3129db689dfbe831ea56f94db07e8 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 99953b1597d9306d45fc20bdc783c80ad5a42ed5..4c13b21976172821e1acc6714931c620eaf6d927 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 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 de32186f123e1d1b1d7a4320fcd60056ac18f222..3951a4e9c9fe4dd105140ba92db8096e0f420700 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,20 @@ 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); +} + +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 ae3301b3817c6471c0894b2abcce99c3f7c69c9c..926124fa4347f5328919ace609ce8df9d9b002c0 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,12 @@ public: void SetWebDestroyMode(OHOS::NWeb::WebDestroyMode mode) override; + int32_t SetSiteIsolationMode(ArkWebSiteIsolationMode mode) override; + + ArkWebSiteIsolationMode GetSiteIsolationMode() override; + + void SetSocketIdleTimeout(int32_t timeout) override; + private: ArkWebRefPtr ark_web_engine_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_handler_impl.cpp index e48c5c199d9837e59bbfdb1c03e6b5c7d2b51314..dac01339dad3a9c27b733ab3ea6da8168f225a78 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" @@ -57,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 { @@ -1100,4 +1102,60 @@ 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); +} + +void ArkWebHandlerImpl::SetImeShow(bool visible) +{ + nweb_handler_->SetImeShow(visible); +} + +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)); +} + +void ArkWebHandlerImpl::OnSafeBrowsingCheckFinish(int threat_type) +{ + nweb_handler_->OnSafeBrowsingCheckFinish(threat_type); +} + +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))); +} + +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 bd471997bcbe22ea79d6c5579497d490ea31562e..12c2cd5d4927196a820764f1b8b7923f0b20c452 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,72 @@ 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; + + /** + * @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; + + /** + * @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; + + /** + * @brief Called when received website security risk check finish. + * + * @param threat_type The threat type of website. + */ + void OnSafeBrowsingCheckFinish(int threat_type) 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; + + /** + * @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/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 0000000000000000000000000000000000000000..ec07f8406a6f29b6d6e4d4cb82272144b65f9af2 --- /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 0000000000000000000000000000000000000000..1b3f7589c547807f6e7eabff56e1fb67dcca9663 --- /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 0000000000000000000000000000000000000000..6362bcbd89ecaed9b8d2725d156a9fe30531e3e0 --- /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 0000000000000000000000000000000000000000..364c768ef6e73f3877194c93de483d408791daaf --- /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/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 0000000000000000000000000000000000000000..9a164528e5def019b90382a2fb4e68d3b22654cf --- /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 0000000000000000000000000000000000000000..19a3f1a94414edc26f64bc53e99a4bc5988658d2 --- /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_nweb_webview_bridge_helper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_nweb_webview_bridge_helper.cpp index 79cd6cc9aebaf16464e51fc0698fe4727a60b447..80154b81b65154f2d098c55728fb8d3a3997bb04 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,12 +29,13 @@ 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; } - void* libFileHandler = ArkWebBridgeHelperSharedInit(false, runMode); + void* libFileHandler = ArkWebBridgeHelperSharedInit(runMode); if (!libFileHandler) { ARK_WEB_BRIDGE_ERROR_LOG("library resources loaded failed"); return false; @@ -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(true); -} - } // 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 39571cec04306a69f0f53db8a0b3ca9f43f5554d..3a316dad4cfaed9a6c81294b317430ecf2c8aa39 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_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 bfdfecba317c4700168c868bad57af851e6b656f..18e95b4b77c08dc7ebc4346ca9bc3b57d6c87b27 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,15 +40,18 @@ #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" #include "base/bridge/ark_web_bridge_macros.h" +#include "../../base/include/ark_web_errno.h" namespace OHOS::ArkWeb { @@ -1819,4 +1822,67 @@ 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); +} + +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); + + if (ArkWebGetErrno() != RESULT_OK) { + ark_web_nweb_->PrefetchPage(stUrl, stHeaders); + } + + ArkWebStringStructRelease(stUrl); + 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 c5e593afc6d819c282ef08b40e811ef4cdb0adaf..f73a7069085b66de6d68a6f7c7e1ddb694fdce00 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,54 @@ 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; + + /** + * @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; + + /** + * @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; + + /** + * @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/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 0000000000000000000000000000000000000000..08b93ec29b6f5c6bbe26cfbec97d6ab86aaddc87 --- /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 0000000000000000000000000000000000000000..9998a99e98a61a8c5f8a7a9e33c45c13dd1e4c67 --- /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/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 0000000000000000000000000000000000000000..6d4e574e942a6f365bf65a25a582460c96aace74 --- /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 0000000000000000000000000000000000000000..90854c7cb9b3d8741d6180d0a076233547798ea7 --- /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/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 0000000000000000000000000000000000000000..9d2f104980cae9ba0760a19e313cf8da84144d36 --- /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 0000000000000000000000000000000000000000..d7aeea77ae3bf24c3c03a474289db70d8f3f1926 --- /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/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 0000000000000000000000000000000000000000..c9f81a8d30c7f785c622afbb954e7dd62a2c8cad --- /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 0000000000000000000000000000000000000000..797320fabe5e99ad77ffa6fdeebaea1907137cbb --- /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 0000000000000000000000000000000000000000..8beeed0799f8b7bec50b256164d735ddaee093e8 --- /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 0000000000000000000000000000000000000000..8a2fb36e853ca4f31607b1f9cd8ec505518e62a0 --- /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/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 0000000000000000000000000000000000000000..4fac008ea6ec0e5ea8c735b884c338dddc30a799 --- /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; +} + +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); +} + +} // 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 0000000000000000000000000000000000000000..b535f69c15fb3825c8dbc2f959aea07f302f3987 --- /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_engine.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h index b3d800637e3d4e1e37a012a10d2b002c1acb37e2..b8b84ea1cce373a5112e5b0ac329a380ad3c1401 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,15 @@ 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; + + /*--ark web()--*/ + virtual void SetSocketIdleTimeout(int32_t timeout) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_handler.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_handler.h index eb9199b79432f5a91871b878b7ddb9475d23f797..7ed308d50130b87ee6f34593e68fdf90bf347205 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" @@ -57,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 { @@ -1024,6 +1027,80 @@ 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; + + /** + * @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; + + /** + * @brief Called when you click on caret. + */ + /*--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; + + /** + * @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 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; + + /** + * @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 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 0000000000000000000000000000000000000000..d44a9154eda274abd78e5b36d31494d2c6957488 --- /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 0000000000000000000000000000000000000000..6f39ae254521ab1593735b48870fd2fee570e3c9 --- /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 0000000000000000000000000000000000000000..d9b600e1421752f236ab2e8471312b9224245541 --- /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/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 0000000000000000000000000000000000000000..b4a7bcd6fe2cab6c9b2d9eb5c659b41f6804dc0a --- /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_nweb.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_nweb.h index f2d1123e60b62466757b0b55fbda941e382136ec..b57dbd943ff049bac96e025aa1c288baa5719fd7 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,62 @@ 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; + + /** + * @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; + + /** + * @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; + + /** + * @brief Set web should ignore zoom limit. + */ + /*--ark web()--*/ + virtual void SetForceEnableZoom(bool forceEnableZoom) {} }; } // namespace OHOS::ArkWeb 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 0000000000000000000000000000000000000000..bb43710a55e0de43a6559677b6bdfce08cde9b45 --- /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_ 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 0000000000000000000000000000000000000000..6fc0ecca699b89621890eb1a63f654da03a4dfa3 --- /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 0000000000000000000000000000000000000000..23a93836d456372194c7e2258a8594c2311a2250 --- /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 fa99d1d446ea40dd07c45d8e8a877721c7dfc3a7..3ca322783241f1ffa6a40ab4f36c02b90c96e467 100644 --- a/ohos_interface/ohos_glue/scripts/file_parser.py +++ b/ohos_interface/ohos_glue/scripts/file_parser.py @@ -438,6 +438,12 @@ _simpletypes = { 'CefWindowHandle': ['cef_window_handle_t', 'kNullWindowHandle'], 'WebSnapshotCallback':['WebSnapshotCallback', 'NULL'], 'ArkDisplayAdapterVector': ['ArkDisplayAdapterVector', '{0}'], + 'ArkWebStylusTouchPointInfoVector': [ + 'ArkWebStylusTouchPointInfoVector', 'ark_web_stylus_touch_point_info_vector_default' + ], + 'ArkWebNativeEmbedParamItemVector': [ + 'ArkWebNativeEmbedParamItemVector', 'ark_web_native_embed_param_item_vector_default' + ], } diff --git a/ohos_nweb/BUILD.gn b/ohos_nweb/BUILD.gn index 0ca315a0a8b65ed24cfc0a8cb1ba12346e565154..9f1dc9a5855eaa864ec3b24509667f5ea1b065c3 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" ] @@ -81,6 +88,7 @@ ohos_shared_library("web_configs") { "ipc:ipc_core", "libxml2:libxml2", "ability_runtime:ability_connect_callback_stub", + "samgr:samgr_proxy", ] part_name = "webview" diff --git a/ohos_nweb/etc/para/web.para b/ohos_nweb/etc/para/web.para index d83c8fdbe83cd2946f6be241943919268e425e02..b77bbf1e88433dd9a522218a1bd8ca80ae0b01ef 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 f48a286ccae64a65928d856280c7f205b2269f8a..07b65549f51998050b71059ac553722958ec7d48 100644 --- a/ohos_nweb/etc/web_config.xml +++ b/ohos_nweb/etc/web_config.xml @@ -65,9 +65,6 @@ 0 - - 10 - diff --git a/ohos_nweb/include/nweb_config_helper.h b/ohos_nweb/include/nweb_config_helper.h index a859568446883e5e7e19ea7bb8d3c85800a0b438..e9edf354e98a419d0d80ee91ac94b98085519333 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/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index 31cdcacb89c842a410481adabf693f9dbbd0d7bf..8219dd7a7d3aa78ee3c9d065502960a7659cfe03 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(); @@ -155,6 +154,18 @@ public: void SetWebDestroyMode(WebDestroyMode mode); + void SetAutoPreconnect(bool enable); + + bool IsAutoPreconnectEnabled(); + + int32_t SetSiteIsolationMode(SiteIsolationMode mode); + + SiteIsolationMode GetSiteIsolationMode(); + + void SetSocketIdleTimeout(int32_t timeout); + + int32_t GetSocketIdleTimeout(); + private: NWebHelper() = default; bool GetWebEngine(bool fromArk); @@ -162,7 +173,9 @@ private: private: int coreApiLevel_ = 0; + int32_t socketIdleTimeout_ = 300; bool initFlag_ = false; + bool autoPreconnectEnabled_ = true; std::string bundlePath_; std::string customSchemeCmdLine_; std::shared_ptr nwebEngine_ = nullptr; diff --git a/ohos_nweb/include/nweb_init_params.h b/ohos_nweb/include/nweb_init_params.h index 4e8501562015e0383c9d88fd1593db3a36a709b2..a9d9ecd1cf201434f3d45ea4f2324025768a3b8a 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, diff --git a/ohos_nweb/prebuilts/arm/ArkWebCore.hap b/ohos_nweb/prebuilts/arm/ArkWebCore.hap index 9d6c7ea4c7370ddc4cc4990beb1b820e994ac9c2..fa80f88a23c3a22436044d0e6512da958fe615ec 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:b43c7f2c8e2b0f4d6ad7fac936a0286ba08d9af2afd0bfcabee473568801ee4d +size 116737507 diff --git a/ohos_nweb/prebuilts/arm64/ArkWebCore.hap b/ohos_nweb/prebuilts/arm64/ArkWebCore.hap index d29aa064454fa263d3283e9b14be320e3cc72322..b63ead6f717ea61b7fb8422fe2c4d5a32ea5f7cb 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:1756edd2b829394cdf999e6232cc0e94767382148378bb7faeeecb8eb8e976e7 +size 122574271 diff --git a/ohos_nweb/src/nweb_config_helper.cpp b/ohos_nweb/src/nweb_config_helper.cpp index 6b1a91e4c4c74808179bb089701f3c73c7d1f479..a5336cc305b894e2ea33595dd4a4b873d1207f37 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()) { @@ -575,12 +617,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); diff --git a/ohos_nweb/src/nweb_crashpad_handler_main.cpp b/ohos_nweb/src/nweb_crashpad_handler_main.cpp index abd52ded0da4fc33d2264e2ac432cdc182684d5c..66126e7dda9a075c9707aab8c3a5069a878c1835 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) { @@ -48,17 +49,24 @@ 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") { + WVLOG_I("crashpad handler start from 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); + WVLOG_I("crashpad handler start from default"); + 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); diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index c879fb0116f7905dce136175c41e84f5eff27695..d4c1716df4fc011d3474a4f3130000d01fed318b 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); @@ -707,7 +697,6 @@ bool NWebHelper::GetWebEngine(bool fromArk) bool NWebHelper::InitWebEngine() { if (initFlag_) { - WVLOG_I("web engine has been initialized"); return true; } @@ -760,6 +749,12 @@ bool NWebHelper::InitWebEngine() WVLOG_D("apiTargetVersion: %{public}s", apiVersion.c_str()); } + if (!autoPreconnectEnabled_) { + initArgs->AddArg(std::string("--disable-auto-preconnect")); + } + + initArgs->AddArg(std::string("--socket-idle-timeout=").append(std::to_string(socketIdleTimeout_))); + nwebEngine_->InitializeWebEngine(initArgs); initFlag_ = true; @@ -1025,6 +1020,26 @@ RenderProcessMode NWebHelper::GetRenderProcessMode() return nwebEngine_->GetRenderProcessMode(); } +int32_t NWebHelper::SetSiteIsolationMode(SiteIsolationMode mode) +{ + if (nwebEngine_ == nullptr) { + WVLOG_E("web engine is nullptr"); + return 0; + } + + 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) { @@ -1214,6 +1229,11 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(sptr surface, return nullptr; } initArgs->AddArg(NWebConfigHelper::Instance().GetWebPlayGroundInitArg()); + 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); @@ -1249,6 +1269,11 @@ std::shared_ptr NWebAdapterHelper::CreateNWeb(void* enhanceSurfaceInfo, return nullptr; } initArgs->AddArg(NWebConfigHelper::Instance().GetWebPlayGroundInitArg()); + 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); @@ -1356,4 +1381,30 @@ void NWebHelper::SetWebDestroyMode(WebDestroyMode mode) nwebEngine_->SetWebDestroyMode(mode); } +void NWebHelper::SetAutoPreconnect(bool enable) +{ + autoPreconnectEnabled_ = enable; +} + +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/sa/src/app_fwk_update_service.cpp b/sa/src/app_fwk_update_service.cpp index 30715139ad284c61e9e7943a3f88806f4461ae91..82f1457cdfbcd0d1d586c4615cd1ca2cacf5f13c 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; } diff --git a/test/fuzztest/nativebufferadapter_fuzzer/nativebufferadapter_fuzzer.cpp b/test/fuzztest/nativebufferadapter_fuzzer/nativebufferadapter_fuzzer.cpp index bbfffbbee12383020692eda461ff28c626747650..dd0b2cf374102f8ca01b86831b84e103cde2c956 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; 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 97d65a5a7163bcc50e9fc3aa23a6b70b7bacd194..696f044876df02816aa25e8ed4ddf17908ff441f 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 b5614b3bdcc3ddef5d8dbf4cd28126205ec48ea0..d5c34e21e32f51e617afe283b86521c0d1921a14 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 14b9c4adb772b9f95c72f293dffcfa7839426f2d..fa4228b299f33d97bb0e4063ca91e4455c61c847 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 b618cf467aafe4fef41cfa931f3a73bc919ca25f..82f660daaeed83884e91d3204742bd5a3cffdea4 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 56e353f82c5f7458c3a0c5314dba6c676f6cc879..41ed6dad8324b37a2372ff62920e87623b9fa4a5 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 56ceed30faf2ee52d6e1dafeb09d37eaa888eb4e..76edd6944dc08ff1d4aac0feb807cb06763b6c6a 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 1a697bde87cc839242b227b61cac2cae72a607ab..36f30ae3d36da663e1398ec48f8cef7b03df1352 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 54003318ab7f7f185b323d3448592865e97646ec..e44004f882ca932ee7e2f8c8f3de2b8083d61c2d 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 + ":SetCaptureCallbackFuzzTest", + ] } ############################################################################### diff --git a/test/unittest/arkweb_utils_test/BUILD.gn b/test/unittest/arkweb_utils_test/BUILD.gn index 0d32168d471d5e63cbc93ed606b041f681eac73a..c8764e4d876e970f244857f923e996cd95a434b6 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,7 +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", diff --git a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp index 4f217e38113f1eade527d06ceee08e7b1510d1d6..337505d2aae89e40d212ded5343d6ebe2b4d857a 100644 --- a/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp +++ b/test/unittest/arkweb_utils_test/arkweb_utils_test.cpp @@ -18,38 +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"; @@ -62,70 +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"; - -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); -} +class ArkWebUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; -TEST(arkweb_utils_test, setActiveWebEngineVersion002) { - setActiveWebEngineVersion(ArkWebEngineVersion::M114); +void ArkWebUtilsTest::SetUpTestCase(void) +{} - EXPECT_EQ(getAppWebEngineVersion(), ArkWebEngineVersion::M114); -} +void ArkWebUtilsTest::TearDownTestCase(void) +{} -TEST(arkweb_utils_test, setActiveWebEngineVersion003) { - setActiveWebEngineVersion(ArkWebEngineVersion::M132); +void ArkWebUtilsTest::SetUp(void) +{} - EXPECT_EQ(getAppWebEngineVersion(), ArkWebEngineVersion::M132); -} +void ArkWebUtilsTest::TearDown(void) +{} -TEST(arkweb_utils_test, setActiveWebEngineVersion004) { - setActiveWebEngineVersion(ArkWebEngineVersion::SYSTEM_DEFAULT); - setActiveWebEngineVersion(static_cast(3)); +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_SetActiveWebEngineVersionInner_001, TestSize.Level1) { + SetActiveWebEngineVersionInner(ArkWebEngineVersion::SYSTEM_DEFAULT); - EXPECT_EQ(getAppWebEngineVersion(), ArkWebEngineVersion::SYSTEM_DEFAULT); + EXPECT_EQ(getActiveWebEngineVersion(), 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)); +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_SetActiveWebEngineVersionInner_002, TestSize.Level1) { + SetActiveWebEngineVersionInner(ArkWebEngineVersion::M114); - auto res = getActiveWebEngineVersion(); - EXPECT_EQ(res, ArkWebEngineVersion::M132); - OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); + EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M114); } -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); +HWTEST_F(ArkWebUtilsTest, ArkWebUtilsTest_SetActiveWebEngineVersionInner_003, TestSize.Level1) { + SetActiveWebEngineVersionInner(ArkWebEngineVersion::M132); - auto res = getActiveWebEngineVersion(); - EXPECT_EQ(res, ArkWebEngineVersion::M132); - OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); + EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M132); } -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)); -} - -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)); @@ -134,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); @@ -144,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); @@ -154,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); @@ -164,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); @@ -174,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); @@ -184,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); @@ -194,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); @@ -208,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); @@ -222,25 +172,210 @@ 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); auto aclPath = GetArkwebInstallPath(); bool res = (aclPath == SANDBOX_LEGACY_HAP_PATH || aclPath == PRECONFIG_LEGACY_HAP_PATH); - EXPECT_TRUE(res); + // rk is default + std::string deviceType = OHOS::system::GetDeviceType(); + if (deviceType == "default") { + EXPECT_FALSE(res); + } else { + EXPECT_TRUE(res); + } + 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); auto aclPath = GetArkwebInstallPath(); bool res = (aclPath == SANDBOX_EVERGREEN_HAP_PATH || aclPath == PRECONFIG_EVERGREEN_HAP_PATH); - EXPECT_TRUE(res); + // rk is default + std::string deviceType = OHOS::system::GetDeviceType(); + if (deviceType == "default") { + EXPECT_FALSE(res); + } else { + EXPECT_TRUE(res); + } + + OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); +} + +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)); + + SelectWebcoreBeforeProcessRun(appBundleName); + EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M132); + OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); +} + +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)); + + SelectWebcoreBeforeProcessRun(appBundleName); + EXPECT_EQ(getActiveWebEngineVersion(), ArkWebEngineVersion::M132); OHOS::system::SetParameter("web.engine.enforce", std::to_string(webEngineEnforce)); } + +#if (defined(webview_arm64) && !defined(ASAN_DETECTOR)) +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 diff --git a/test/unittest/common/nweb_create_window.h b/test/unittest/common/nweb_create_window.h index 62d57190e015356ec3de014590d25b5c0533130b..21318356e939f09335fcd2610dc44765ebd77a34 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 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 908fd92eaca648b836137b8ba673d524a94c1a01..9f0b968a5a549291e1d2a0331f3bfecea662168a 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); @@ -459,7 +457,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); 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 21c4930b205df5e47bd868962fff923ad0a55898..7bea1cf6e93f29355e0b92a665952220846a5779 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"; } @@ -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"); } /** 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 f4ace571c113e5b565a430409de21bab38a9a91b..e902bda4da292ddd26299f9028744968d0766d00 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); } /** 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 3aa3dff0153c91ef820e79778592e2e2f9c825c4..0a4898c3bfcea1768fd39ec18b08a3f5603d0066 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() { @@ -167,6 +177,8 @@ public: return false; } + void SetSocketIdleTimeout(int32_t timeout) {} + MOCK_METHOD(void, SetWebDebuggingAccessAndPort, (bool isEnableDebug, int32_t port), (override)); @@ -253,25 +265,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. @@ -293,6 +286,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); @@ -454,6 +448,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; @@ -471,6 +467,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); @@ -936,11 +934,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); } /** @@ -955,10 +960,158 @@ 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); +} + +/** + * @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_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); +} + +/** + * @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 } diff --git a/test/unittest/nweb_helper_test/nweb_helper_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_test.cpp index 409cf02673c5f4baa03adcf0564b15b4f4b98c0c..75f913e2ba52e958a76c237e53991790dbb04af3 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. @@ -517,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); @@ -539,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); 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 cdb972515ac2633311160459cd40420f2f9b0ea6..99b52e718538ec2b1ea8db44088c00006e45220f 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,78 @@ 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 + +/** +* @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 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 00830b86324475bf8d616609a48d086ca15d73fc..a56728b65c266cd7890f6c4847008da2485e0fac 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); 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 759408ff1cac605dc4d92809c1d012dcd861dcc9..33e2c4e4cd17b7708b9920b26beaf9d40d19eb7e 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) 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 07dbdd2d699ce052f92356a27a7dc6b01ecbe7ff..0d1c3bfa6830b02321fe130c6c7884c11ed6d377 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,70 @@ 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 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(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); + 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 +186,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 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 771fc00eef6939bbbd2fad95db16c00c02dd5521..073e959c9c127feb0c4f51e4b8211a7153da32c5 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 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 fd128ea88ee92e7d114ca11989f48bd4d99f1757..0ea7bb83ee9d39ff1e38f948ed643cfa67c04532 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); 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 2cb4b9311457059c95cee1ec1803e561dc2117a6..6c2d04fa18df323a5b2ef2e8b523fd731e2ab9de 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 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 ef2bb00f94f2a9905355df8be253b7943022f056..7fea5393ec7636e01d7ac3488db0ba6f89bb06c7 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); } /** @@ -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