diff --git a/ArkWeb/ArkWebSchemeHandler/.gitignore b/ArkWeb/ArkWebSchemeHandler/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/AppScope/app.json5 b/ArkWeb/ArkWebSchemeHandler/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..380216c4148a89ebb8eecf3cb191120fd624ceab --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* +* 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. +*/ + +{ + "app": { + "bundleName": "com.samples.arkwebschemehandler", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/element/string.json b/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..42a06f64bb1731e07c5b6a7aa98ea811ec09d3e9 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ArkWebSchemeHandler" + } + ] +} diff --git a/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/media/background.png b/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/media/background.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/media/foreground.png b/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/media/foreground.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/media/layered_image.json b/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/README.md b/ArkWeb/ArkWebSchemeHandler/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a2f141f80a3c7ac2a42ba09841533ecf137015f3 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/README.md @@ -0,0 +1,192 @@ +# 拦截Web组件发起的网络请求 + +### 介绍 + +1. 本示例通过使用arkweb_scheme_handler.h相关API实现对Web组件发出的请求进行拦截,并为被拦截的请求提供自定义的响应头以及响应体。 +2. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-scheme-handler.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### 主页 + +1. 本示例通过使用arkweb_scheme_handler.h相关API实现对Web组件发出的请求进行拦截,并为被拦截的请求提供自定义的响应头以及响应体。 + +#### 效果预览 + +| 主页 | +|:----------------------:| +| | + +#### 使用说明 + +1. 打开DEMO进入首页,展示html。 +2. 点击各链接进入不同属性的拦截结果页面或读取结果页面。 + +### 拦截视频资源 + +#### 介绍 + +1. 此处模块主要介绍通过Web组件,拦截视频资源请求,读取本地mp4文件。 + +#### 效果预览 + +| 拦截视频资源 | +| ------------------------------------------------------------ | +| | + +#### 使用说明 + +1. 通过点击主页的“拦截视频资源请求,读取本地mp4文件”链接,拦截页面请求并跳转到此页面并展示本地的mp4文件。 + +### 忽略csp检查并拦截 + +#### 介绍 + +1. 此处模块主要介绍通过Web组件,测试三方协议忽略csp检查,并成功拦截。 + +#### 效果预览 + +| 忽略csp检查并拦截 | +| ------------------------------------------------------------ | +| | + +#### 使用说明 + +1. 通过点击主页的“测试三方协议忽略csp检查,并成功拦截”链接,展示被拦截的自定义scheme请求,该scheme需要遵循标准的scheme规则,允许忽略CSP检查。 +2. 如果要拦截自定义scheme的请求,需要提前将自定义scheme注册到Web内核。需要在Web组件初始化之前进行注册,Web组件初始化后再注册会失败。 + +### 拦截ISOLATED属性 + +#### 介绍 + +1. 此处模块主要介绍通过Web组件,测试拦截设置ISOLATED属性的三方协议。 + +#### 效果预览 + +| 拦截ISOLATED属性 | +| ------------------------------------------------------------ | +| | + +#### 使用说明 + +1. 通过点击主页的“测试拦截设置ISOLATED属性的三方协议”链接,展示被拦截的带有ISOLATED属性的自定义scheme请求,该scheme的请求必须从相同scheme加载的网页中发起。 +2. 如果要拦截自定义scheme的请求,需要提前将自定义scheme注册到Web内核。需要在Web组件初始化之前进行注册,Web组件初始化后再注册会失败。 + +### 拦截LOCAL属性 + +#### 介绍 + +1. 此处模块主要介绍通过Web组件,测试拦截设置LOCAL属性的三方协议。 + +#### 效果预览 + +| 拦截LOCAL属性 | +| ------------------------------------------------------------ | +| | + +#### 使用说明 + +1. 通过点击主页的“测试拦截设置LOCAL属性的三方协议”链接,展示被拦截的带有LOCAL属性的自定义scheme请求,该scheme需要遵循与“file” scheme一样的规则。 +2. 如果要拦截自定义scheme的请求,需要提前将自定义scheme注册到Web内核。需要在Web组件初始化之前进行注册,Web组件初始化后再注册会失败。 + +### 拦截service worker + +#### 介绍 + +1. 此处模块主要介绍通过Web组件,测试拦截service worker触发的请求。 + +#### 效果预览 + +| 拦截service worker | +| ------------------------------------------------------------ | +| | + +#### 使用说明 + +1. 通过点击主页的“测试拦截service worker触发的请求”链接,展示被拦截的Web组件发出的scheme为“custom”的请求。 +2. 如果要拦截自定义scheme的请求,需要提前将自定义scheme注册到Web内核。需要在Web组件初始化之前进行注册,Web组件初始化后再注册会失败。 + +### 测试读取blob类型http body stream + +#### 介绍 + +1. 此处模块主要介绍通过Web组件,测试读取blob类型http body stream。 + +#### 效果预览 + +| 测试读取blob类型http body stream | +| ------------------------------------------------------------ | +| | + +#### 使用说明 + +1. 通过点击主页的“测试读取blob类型http body stream”链接,跳转至post_data.html,通过"test xhr post"或"test xhr put"按键,创建blob类型的对应请求,并发送至服务端,在设备日志中可查看发送结果。 + +### 测试读取chunked类型http body stream + +#### 介绍 + +1. 此处模块主要介绍通过Web组件,测试读取chunked类型http body stream。 + +#### 效果预览 + +| 测试读取chunked类型http body stream | +| ------------------------------------------------------------ | +| | + +#### 使用说明 + +1. 通过点击主页的“测试读取chunked类型http body stream”链接,跳转至pchunked_post_stream.html,通过"test post chunked http body"按键,创建chunked类型的请求,并以POST方式发送至服务端,在设备日志中可查看发送结果。 + +### 工程目录 + + +``` +├── entry +│ └── src +│ └── main +│ ├── cpp // C++代码区 +│ │ ├── CMakeLists.txt // CMAKE配置文件 +│ │ ├── hello.cpp // Native业务代码实现 +│ │ ├── rawfile_request.cpp // RawfileRequest实现 +│ │ ├── rawfile_request.h // RawfileRequest类 +│ │ └── types +│ │ └── libentry // C++接口导出 +│ │ ├── Index.d.ts +│ │ └── oh-package.json5 +│ ├── ets // ArkTS代码区 +│ │ ├── entryability +│ │ │ └── EntryAbility.ets // 入口类 +│ │ ├── entrybackupability +│ │ │ └── EntryBackupAbility.ets // 备份恢复框架 +│ │ └── pages +│ │ └── Index.ets // 主页 +│ └── resources // 应用资源文件 +``` +### 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/ArkWebSchemeHandler > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/build-profile.json5 b/ArkWeb/ArkWebSchemeHandler/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..023caeeb56c41dc1ce697cbf21433d4fd6ee6543 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/build-profile.json5 @@ -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. + */ + + { + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/ArkWeb/ArkWebSchemeHandler/code-linter.json5 b/ArkWeb/ArkWebSchemeHandler/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/code-linter.json5 @@ -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. + */ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/build-profile.json5 b/ArkWeb/ArkWebSchemeHandler/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fea31f4580540c7c560b62bf531292c471c410f1 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/build-profile.json5 @@ -0,0 +1,55 @@ +/* + * 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/hvigorfile.ts b/ArkWeb/ArkWebSchemeHandler/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ArkWebSchemeHandler/entry/obfuscation-rules.txt b/ArkWeb/ArkWebSchemeHandler/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/oh-package.json5 b/ArkWeb/ArkWebSchemeHandler/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/CMakeLists.txt b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..27bc12820c74e082ddcb3dbdb80db75951d72222 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,19 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(schemehandler) + + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + + +if(DEFINED PACKAGE_INFO_FILE) + include(${PACKAGE_INFO_FILE}) +endif() + + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + + +add_library(entry SHARED rawfile_request.cpp hello.cpp) +target_link_libraries(entry PUBLIC librawfile.z.so libace_napi.z.so libohweb.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/hello.cpp b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5ec9335a06ff09c025923a959cc8cb7e1c24ff2 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/hello.cpp @@ -0,0 +1,137 @@ +#include "hilog/log.h" +#include "napi/native_api.h" +#include "rawfile_request.h" +#include "rawfile/raw_file_manager.h" +#include "web/arkweb_scheme_handler.h" +#include "web/arkweb_net_error_list.h" + +#undef LOG_TAG +#define LOG_TAG "ss-handler" + +ArkWeb_SchemeHandler *g_schemeHandler; +ArkWeb_SchemeHandler *g_schemeHandlerForSW; +NativeResourceManager *g_resourceManager; + +// 注册三方协议的配置,需要在Web内核初始化之前调用,否则会注册失败。 +static napi_value RegisterCustomSchemes(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "register custom schemes"); + OH_ArkWeb_RegisterCustomSchemes("custom", ARKWEB_SCHEME_OPTION_STANDARD | ARKWEB_SCHEME_OPTION_CORS_ENABLED); + OH_ArkWeb_RegisterCustomSchemes("custom-local", ARKWEB_SCHEME_OPTION_LOCAL); + OH_ArkWeb_RegisterCustomSchemes("custom-csp-bypassing", ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD); + OH_ArkWeb_RegisterCustomSchemes("custom-isolated", ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED); + return nullptr; +} + +// 请求开始的回调,在该函数中我们创建一个RawfileRequest来实现对Web内核请求的拦截。 +void OnURLRequestStart(const ArkWeb_SchemeHandler *schemeHandler, + ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + bool *intercept) +{ + *intercept = true; + RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); + OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); + request->Start(); +} + +// 请求结束的回调,在该函数中我们需要标记RawfileRequest已经结束了,内部不应该再使用ResourceHandler。 +void OnURLRequestStop(const ArkWeb_SchemeHandler *schemeHandler, + const ArkWeb_ResourceRequest *request) +{ + if (!request) { + OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); + return; + } + + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); + if (rawfileRequest) { + rawfileRequest->Stop(); + } +} + +void OnURLRequestStartForSW(const ArkWeb_SchemeHandler *schemeHandler, + ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + bool *intercept) +{ + *intercept = true; + RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); + OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); + request->Start(); +} + +void OnURLRequestStopForSW(const ArkWeb_SchemeHandler *schemeHandler, + const ArkWeb_ResourceRequest *request) +{ + if (!request) { + OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); + return; + } + + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); + if (rawfileRequest) { + rawfileRequest->Stop(); + } +} + +// 设置SchemeHandler。 +static napi_value SetSchemeHandler(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "set scheme handler"); + OH_ArkWeb_CreateSchemeHandler(&g_schemeHandler); + OH_ArkWeb_CreateSchemeHandler(&g_schemeHandlerForSW); + + OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandler, OnURLRequestStart); + OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandler, OnURLRequestStop); + + OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandlerForSW, OnURLRequestStart); + OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandlerForSW, OnURLRequestStop); + + OH_ArkWeb_SetSchemeHandler("custom", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-csp-bypassing", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-isolated", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-local", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("https", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("http", "scheme-handler", g_schemeHandler); + + OH_ArkWebServiceWorker_SetSchemeHandler("https", g_schemeHandlerForSW); + return nullptr; +} + +static napi_value InitResourceManager(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + g_resourceManager = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"setSchemeHandler", nullptr, SetSchemeHandler, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"initResourceManager", nullptr, InitResourceManager, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"registerCustomSchemes", nullptr, RegisterCustomSchemes, nullptr, nullptr, nullptr, napi_default, nullptr} + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/rawfile_request.cpp b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/rawfile_request.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a35e9066b403cac1b56ba0d0960a0a25fe21329a --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/rawfile_request.cpp @@ -0,0 +1,257 @@ +#include "rawfile_request.h" + + +#include "threads.h" + + +#include "hilog/log.h" +#include "rawfile/raw_file.h" +#include "rawfile/raw_file_manager.h" + + +#undef LOG_TAG +#define LOG_TAG "ss-handler" + + +namespace { + + +uint8_t buffer[1024]; +cnd_t http_body_cnd; +mtx_t http_body_mtx; + + +// HttpBodyStream的读回调。 +void ReadCallback(const ArkWeb_HttpBodyStream *httpBodyStream, uint8_t* buffer, int bytesRead) +{ + OH_LOG_INFO(LOG_APP, "read http body back."); + bool isEof = OH_ArkWebHttpBodyStream_IsEof(httpBodyStream); + if (!isEof && bytesRead != 0) { + memset(buffer, 0, 1000); + OH_ArkWebHttpBodyStream_Read(httpBodyStream, buffer, 1000); + } else { + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebHttpBodyStream_GetUserData(httpBodyStream); + if (rawfileRequest) { + rawfileRequest->ReadRawfileDataOnWorkerThread(); + cnd_signal(&http_body_cnd); + } + } +} + + +int ReadHttpBodyOnWorkerThread(void* userData) +{ + memset(buffer, 0, 1000); + ArkWeb_HttpBodyStream *httpBodyStream = (ArkWeb_HttpBodyStream *)userData; + OH_ArkWebHttpBodyStream_Read(httpBodyStream, buffer, 1000); + cnd_init(&http_body_cnd); + mtx_init(&http_body_mtx, mtx_plain); + cnd_wait(&http_body_cnd, &http_body_mtx); + return 0; +} + + +int ReadRawfileOnWorkerThread(void* userData) +{ + RawfileRequest * rawfileRequest = (RawfileRequest *)userData; + if (rawfileRequest) { + rawfileRequest->ReadRawfileDataOnWorkerThread(); + } + return 0; +} + + +// ArkWeb_HttpBodyStream的初始化回调。 +void InitCallback(const ArkWeb_HttpBodyStream *httpBodyStream, ArkWeb_NetError result) +{ + OH_LOG_INFO(LOG_APP, "init http body stream done %{public}d.", result); + bool isChunked = OH_ArkWebHttpBodyStream_IsChunked(httpBodyStream); + OH_LOG_INFO(LOG_APP, "http body stream is chunked %{public}d.", isChunked); + thrd_t th; + if (thrd_create(&th, ReadHttpBodyOnWorkerThread, (void *)httpBodyStream) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "create thread failed."); + return; + } + + + if (thrd_detach(th) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "detach thread failed."); + } +} + + +const int blockSize = 1024 * 8; + + +} // namespace + + +RawfileRequest::RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + const NativeResourceManager* resourceManager) + : resourceRequest_(resourceRequest), + resourceHandler_(resourceHandler), + resourceManager_(resourceManager) {} + + +RawfileRequest::~RawfileRequest() {} + + +void RawfileRequest::Start() +{ + OH_LOG_INFO(LOG_APP, "start a rawfile request."); + char* url; + OH_ArkWebResourceRequest_GetUrl(resourceRequest_, &url); + std::string urlStr(url); + std::size_t position = urlStr.rfind('/'); + if (position != std::string::npos) { + rawfilePath_ = urlStr.substr(position + 1); + } + OH_ArkWeb_ReleaseString(url); + + + OH_ArkWeb_CreateResponse(&response_); + OH_ArkWebResourceRequest_GetHttpBodyStream(resourceRequest(), &stream_); + if (stream_) { + OH_LOG_ERROR(LOG_APP, "have http body stream"); + OH_ArkWebHttpBodyStream_SetUserData(stream_, this); + OH_ArkWebHttpBodyStream_SetReadCallback(stream_, ReadCallback); + OH_ArkWebHttpBodyStream_Init(stream_, InitCallback); + } else { + thrd_t th; + if (thrd_create(&th, ReadRawfileOnWorkerThread, (void *)this) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "create thread failed."); + return; + } + + + if (thrd_detach(th) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "detach thread failed."); + } + } +} + + +// 在worker线程中读取rawfile,并通过ResourceHandler返回给Web内核。 +void RawfileRequest::ReadRawfileDataOnWorkerThread() +{ + OH_LOG_INFO(LOG_APP, "read rawfile in worker thread."); + const struct UrlInfo { + std::string resource; + std::string mimeType; + } urlInfos[] = { + {"test.html", "text/html"}, + {"video.html", "text/html"}, + {"isolated.html", "text/html"}, + {"csp_bypassing.html", "text/html"}, + {"post_data.html", "text/html"}, + {"chunked_post_stream.html", "text/html"}, + {"local.html", "text/html"}, + {"service_worker.html", "text/html"}, + {"csp_script.js", "text/javascript"}, + {"sw.js", "text/javascript"}, + {"isolated_script.js", "text/javascript"}, + {"local_script.js", "text/javascript"}, + {"test.mp4", "video/mp4"}, + {"xhr", "application/json"} + }; + + + if (!resourceManager()) { + OH_LOG_ERROR(LOG_APP, "read rawfile error, resource manager is nullptr."); + return; + } + + + RawFile *rawfile = OH_ResourceManager_OpenRawFile(resourceManager(), rawfilePath().c_str()); + if (!rawfile) { + OH_ArkWebResponse_SetStatus(response(), 404); + } else { + OH_ArkWebResponse_SetStatus(response(), 200); + } + + + for (auto &urlInfo : urlInfos) { + if (urlInfo.resource == rawfilePath()) { + OH_ArkWebResponse_SetMimeType(response(), urlInfo.mimeType.c_str()); + break; + } + } + OH_ArkWebResponse_SetCharset(response(), "UTF-8"); + + + long len = OH_ResourceManager_GetRawFileSize(rawfile); + OH_ArkWebResponse_SetHeaderByName(response(), "content-length", std::to_string(len).c_str(), false); + DidReceiveResponse(); + + + long consumed = 0; + uint8_t buffer[blockSize]; + while (true) { + int ret = OH_ResourceManager_ReadRawFile(rawfile, buffer, blockSize); + OH_LOG_INFO(LOG_APP, "read rawfile %{public}d bytes.", ret); + if (ret == 0) { + break; + } + consumed += ret; + OH_ResourceManager_SeekRawFile(rawfile, consumed, 0); + DidReceiveData(buffer, ret); + memset(buffer, 0, blockSize); + } + + + OH_ResourceManager_CloseRawFile(rawfile); + DidFinish(); +} + + +void RawfileRequest::Stop() +{ + OH_LOG_INFO(LOG_APP, "stop the rawfile request."); + std::lock_guard guard(mutex_); + stopped_ = true; + if (response_) { + OH_ArkWeb_DestroyResponse(response_); + } + OH_ArkWebResourceRequest_Destroy(resourceRequest_); + OH_ArkWebResourceHandler_Destroy(resourceHandler_); +} + + +void RawfileRequest::DidReceiveResponse() +{ + OH_LOG_INFO(LOG_APP, "did receive response."); + std::lock_guard guard(mutex_); + if (!stopped_) { + OH_ArkWebResourceHandler_DidReceiveResponse(resourceHandler_, response_); + } +} + + +void RawfileRequest::DidReceiveData(const uint8_t *buffer, int64_t bufLen) +{ + OH_LOG_INFO(LOG_APP, "did receive data."); + std::lock_guard guard(mutex_); + if (!stopped_) { + OH_ArkWebResourceHandler_DidReceiveData(resourceHandler_, buffer, bufLen); + } +} + + +void RawfileRequest::DidFinish() +{ + OH_LOG_INFO(LOG_APP, "did finish."); + std::lock_guard guard(mutex_); + if (!stopped_) { + OH_ArkWebResourceHandler_DidFinish(resourceHandler_); + } +} + + +void RawfileRequest::DidFailWithError(ArkWeb_NetError errorCode) +{ + OH_LOG_INFO(LOG_APP, "did finish with error %{public}d.", errorCode); + if (!stopped_) { + OH_ArkWebResourceHandler_DidFailWithError(resourceHandler_, errorCode); + } +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/rawfile_request.h b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/rawfile_request.h new file mode 100644 index 0000000000000000000000000000000000000000..ce72bce77ab7fea89a360b6ab025c88c9b240b38 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/rawfile_request.h @@ -0,0 +1,53 @@ +#ifndef RAWFILE_REQUEST_H +#define RAWFILE_REQUEST_H + + +#include +#include + + +#include +#include "web/arkweb_scheme_handler.h" +#include "web/arkweb_net_error_list.h" + + +class RawfileRequest { +public: + RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + const NativeResourceManager* resourceManager); + ~RawfileRequest(); + + + void Start(); + void Stop(); + void ReadRawfileDataOnWorkerThread(); + + + const ArkWeb_ResourceHandler *resourceHandler() { return resourceHandler_; } + const ArkWeb_ResourceRequest *resourceRequest() { return resourceRequest_; } + const NativeResourceManager *resourceManager() { return resourceManager_; } + ArkWeb_Response *response() { return response_; } + ArkWeb_HttpBodyStream *stream() { return stream_; } + const std::string rawfilePath() { return rawfilePath_; } + + + void DidReceiveResponse(); + void DidReceiveData(const uint8_t *buffer, int64_t bufLen); + void DidFinish(); + void DidFailWithError(ArkWeb_NetError errorCode); + + +private: + const ArkWeb_ResourceRequest *resourceRequest_{nullptr}; + const ArkWeb_ResourceHandler *resourceHandler_{nullptr}; + const NativeResourceManager *resourceManager_{nullptr}; + ArkWeb_Response *response_; + bool stopped_{false}; + std::string rawfilePath_; + ArkWeb_HttpBodyStream *stream_{nullptr}; + std::mutex mutex_; +}; + + +#endif // RAWFILE_REQUEST_H \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f34c7c5744d67baf13ba4e26d3cd786025f08b90 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,3 @@ +export const registerCustomSchemes: () => void; +export const setSchemeHandler: () => void; +export const initResourceManager: (resmgr: resourceManager.ResourceManager) => void; \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/types/libentry/oh-package.json5 b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ea410725a8826704d061021d98cf02aa76cd8016 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/ArkWebSchemeHandler/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..ecc7a5eb82402045f42ecd578d0b7335ba963a53 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,55 @@ +/* +* 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. +*/ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import testNapi from 'libentry.so'; +import { webview } from '@kit.ArkWeb'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 注册三方协议的配置。 + testNapi.registerCustomSchemes(); + // 初始化Web组件内核,该操作会初始化Browser进程以及创建BrowserContext。 + webview.WebviewController.initializeWebEngine(); + // 设置SchemeHandler。 + testNapi.setSchemeHandler(); + } + + onDestroy(): void { + + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } + + onWindowStageDestroy(): void { + + } + + onForeground(): void { + + } + + onBackground(): void { + + } +}; \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/ArkWebSchemeHandler/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..48fcfc36922b540f93f6de56c15880c8db6bb2a5 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* +* 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. +*/ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/ets/pages/Index.ets b/ArkWeb/ArkWebSchemeHandler/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..30cb9f3a7999fbb248a669f6b91d82d8dae00dcc --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/ets/pages/Index.ets @@ -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. +*/ + +import testNapi from 'libentry.so'; +import { webview } from '@kit.ArkWeb'; +import { resourceManager } from '@kit.LocalizationKit'; + + +@Entry +@Component +struct Index { + mycontroller: webview.WebviewController = new webview.WebviewController("scheme-handler"); + + + build() { + Row() { + Column() { + Button($r('app.string.go_back')).onClick( event => { + this.mycontroller.backward(); + }) + + + Web({ src: $rawfile("test.html"), controller: this.mycontroller}) + .javaScriptAccess(true) + .width('100%') + .height('100%') + .databaseAccess(true) + .fileAccess(false) + .domStorageAccess(true) + .cacheMode(CacheMode.Default) + .onPageBegin( event => { + testNapi.initResourceManager(getContext().resourceManager); + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/module.json5 b/ArkWeb/ArkWebSchemeHandler/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b2331c8946c4bc01c590af2e9304a18691020511 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/module.json5 @@ -0,0 +1,70 @@ +/* + * 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. + */ + { + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ], + "requestPermissions":[ + { + "name" : "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/element/color.json b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/element/float.json b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/element/string.json b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f87c1e22bcded55626fbf8b4ebeace8f575a5d24 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ArkWebSchemeHandler" + }, + { + "name": "go_back", + "value": "go back" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/background.png b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/foreground.png b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/dark/element/color.json b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/cat.svg b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/cat.svg new file mode 100644 index 0000000000000000000000000000000000000000..e2abac4d22da57f6217cda27e2087d3863bb3fe2 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/cat.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/chunked_post_stream.html b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/chunked_post_stream.html new file mode 100644 index 0000000000000000000000000000000000000000..a4f7a11242619ba582c56c90bf0298a480da106d --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/chunked_post_stream.html @@ -0,0 +1,43 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/csp_bypassing.html b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/csp_bypassing.html new file mode 100644 index 0000000000000000000000000000000000000000..616b8e984716579bfd189e96f2522ba9238e2c1d --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/csp_bypassing.html @@ -0,0 +1,26 @@ + + + + + + + + +

scheme: custom-csp-bypassing

+

options: ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD

+ + + \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/csp_script.js b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/csp_script.js new file mode 100644 index 0000000000000000000000000000000000000000..07a301212fc48d7bc73d81f7e441c9aba461f07f --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/csp_script.js @@ -0,0 +1,19 @@ +/* +* 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. +*/ + +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'csp_script.js bypass the csp rules'; +body.appendChild(element); \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/isolated.html b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/isolated.html new file mode 100644 index 0000000000000000000000000000000000000000..0ef20f02ff5c3ce6ca5094d78fd54cddabb476b5 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/isolated.html @@ -0,0 +1,26 @@ + + + + + + + +

scheme: custom-isolated

+

options: ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED

+
isolated_script.js 被拦截
+ + + \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/isolated_script.js b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/isolated_script.js new file mode 100644 index 0000000000000000000000000000000000000000..e97a5f9602d358e549e099823560af002bd8c066 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/isolated_script.js @@ -0,0 +1,17 @@ +/* +* 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. +*/ + +const element = document.getElementById('isolated_test'); +element.textContent = 'isolated_script.js not blocked'; \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/local.html b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/local.html new file mode 100644 index 0000000000000000000000000000000000000000..5a90787ee61f981663b7111383db01908e5c68af --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/local.html @@ -0,0 +1,26 @@ + + + + + + + +

scheme: custom-local

+

options: ARKWEB_SCHEME_OPTION_LOCAL

+
local_script.js 被拦截
+ + + \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/local_script.js b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/local_script.js new file mode 100644 index 0000000000000000000000000000000000000000..94bcdac42f7805f45ee9266943f600a14dee71af --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/local_script.js @@ -0,0 +1,17 @@ +/* +* 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. +*/ + +const element = document.getElementById('local_test'); +element.textContent = 'local_script.js not blocked.'; \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/post_data.html b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/post_data.html new file mode 100644 index 0000000000000000000000000000000000000000..fa62fceb7e45e2c134121a866944686c47f4dbfc --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/post_data.html @@ -0,0 +1,48 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/service_worker.html b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/service_worker.html new file mode 100644 index 0000000000000000000000000000000000000000..c9f84b397596073642f4d33c29731bdcdc766de0 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/service_worker.html @@ -0,0 +1,33 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/sw.js b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/sw.js new file mode 100644 index 0000000000000000000000000000000000000000..d1f18a5f0df928d07406d30bb45da0f23519a0cb --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/sw.js @@ -0,0 +1,26 @@ +/* +* 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. +*/ + +self.addEventListener('install', event => { + console.log('v1 installing'); + event.waitUntil( + caches.open('static-v1').then(cache => cache.add('/cat.svg')) + ); +}); + + +self.addEventListener('activate', event => { + console.log("v1 now redy to handle fetches."); +}); \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/test.html b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/test.html new file mode 100644 index 0000000000000000000000000000000000000000..430349d6993788f8f9b3110d9b07334b4bc60c5c --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/test.html @@ -0,0 +1,32 @@ + + + + + + + + + +

网络拦截测试demo

+拦截视频资源请求,读取本地mp4文件
+测试三方协议忽略csp检查,并成功拦截
+测试拦截设置ISOLATED属性的三方协议
+测试拦截设置LOCAL属性的三方协议
+测试拦截service worker触发的请求
+测试读取blob类型http body stream
+测试读取chunked类型http body stream + + \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/test.mp4 b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/test.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9b0cc327db31d79a3fee73803deebe0762afe156 Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/test.mp4 differ diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/video.html b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/video.html new file mode 100644 index 0000000000000000000000000000000000000000..d036984efd0b1633a80a5ca92808fbf6e5e201e9 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/video.html @@ -0,0 +1,25 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/xhr b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/xhr new file mode 100644 index 0000000000000000000000000000000000000000..9e26dfeeb6e641a33dae4961196235bdb965b21b --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/main/resources/rawfile/xhr @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/mock/mock-config.json5 b/ArkWeb/ArkWebSchemeHandler/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..82c3ede8034d34fb9326e71fb6d2a0610ce2aa35 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,72 @@ +/* + * 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 测试三方协议忽略csp检查,并成功拦截 按钮 + * 拦截自定义的忽略了csp属性的scheme请求。 + */ + it('loadTestHtml', 0, async (done: Function) => { + console.info('uitest: loadTestHtml begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('test.html'); + + await driver.pressBack(); + await driver.delayMs(1000); + console.info('uitest: loadTestHtml end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/module.json5 b/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/module.json5 @@ -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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/test/List.test.ets b/ArkWeb/ArkWebSchemeHandler/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/entry/src/test/LocalUnit.test.ets b/ArkWeb/ArkWebSchemeHandler/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/entry/src/test/LocalUnit.test.ets @@ -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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/ArkWebSchemeHandler/hvigor/hvigor-config.json5 b/ArkWeb/ArkWebSchemeHandler/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..65dd6e421ed1979c8ab9b0f138616e0cd46889d9 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* +* 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. +*/ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/ArkWebSchemeHandler/hvigorfile.ts b/ArkWeb/ArkWebSchemeHandler/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ArkWebSchemeHandler/oh-package.json5 b/ArkWeb/ArkWebSchemeHandler/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..14655ea1c07e1b7b8b8eb3d9f6813577b90f6a0f --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/ArkWebSchemeHandler/ohosTest.md b/ArkWeb/ArkWebSchemeHandler/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..38a2a207a1844b6e2566fefab73fa4412874fe23 --- /dev/null +++ b/ArkWeb/ArkWebSchemeHandler/ohosTest.md @@ -0,0 +1,4 @@ +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ------------ | ---------------- | -------- | -------- | +| Web组件的加载html | 设备运转正常 | 应用启动成功 | 加载首页html成功 | Yes | Pass | + diff --git a/ArkWeb/ArkWebSchemeHandler/screenshots/ISOLATED.png b/ArkWeb/ArkWebSchemeHandler/screenshots/ISOLATED.png new file mode 100644 index 0000000000000000000000000000000000000000..10d394603912fa37f1dd3ce0275522f9ca17288c Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/screenshots/ISOLATED.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/screenshots/LOCAL.png b/ArkWeb/ArkWebSchemeHandler/screenshots/LOCAL.png new file mode 100644 index 0000000000000000000000000000000000000000..25fae824d4bac60d69fe8a08ee0f7ed98922a3bc Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/screenshots/LOCAL.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/screenshots/blob.png b/ArkWeb/ArkWebSchemeHandler/screenshots/blob.png new file mode 100644 index 0000000000000000000000000000000000000000..ac0859746d2abfb5dfd1035f40c6524236bf13db Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/screenshots/blob.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/screenshots/chunked.png b/ArkWeb/ArkWebSchemeHandler/screenshots/chunked.png new file mode 100644 index 0000000000000000000000000000000000000000..49d7fe3ddbaa43a6ca2c0669460a7c8d82470623 Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/screenshots/chunked.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/screenshots/csp.png b/ArkWeb/ArkWebSchemeHandler/screenshots/csp.png new file mode 100644 index 0000000000000000000000000000000000000000..b6fb15b8f0f2f09392d9c002f514c8327ed03448 Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/screenshots/csp.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/screenshots/home.png b/ArkWeb/ArkWebSchemeHandler/screenshots/home.png new file mode 100644 index 0000000000000000000000000000000000000000..4547549ea37b6a939048c312a67bb46ff5e3d082 Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/screenshots/home.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/screenshots/mp4.png b/ArkWeb/ArkWebSchemeHandler/screenshots/mp4.png new file mode 100644 index 0000000000000000000000000000000000000000..f3fe7b90f038b140ab2a71e61b60d2119bab4d8b Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/screenshots/mp4.png differ diff --git a/ArkWeb/ArkWebSchemeHandler/screenshots/service_worker.png b/ArkWeb/ArkWebSchemeHandler/screenshots/service_worker.png new file mode 100644 index 0000000000000000000000000000000000000000..88d73100decc1b314f63d78680464fa9d297cbea Binary files /dev/null and b/ArkWeb/ArkWebSchemeHandler/screenshots/service_worker.png differ diff --git a/ArkWeb/LifecycleWebComp/.gitignore b/ArkWeb/LifecycleWebComp/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWeb/LifecycleWebComp/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/AppScope/app.json5 b/ArkWeb/LifecycleWebComp/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c280ad8998ec933a13d5f497a6d439143c5eb8c2 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "com.samples.lifecyclewebcomp", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json b/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..db726d0837ef849bc208a86e9467181653f73010 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "LifecycleWebComp" + } + ] +} diff --git a/ArkWeb/LifecycleWebComp/AppScope/resources/base/media/app_icon.png b/ArkWeb/LifecycleWebComp/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWeb/LifecycleWebComp/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWeb/LifecycleWebComp/README.md b/ArkWeb/LifecycleWebComp/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c8caed8379995582f26d7079e73b882badb0a5ea --- /dev/null +++ b/ArkWeb/LifecycleWebComp/README.md @@ -0,0 +1,62 @@ +# Web组件的生命周期 + +### 介绍 + +本工程主要实现了对以下指南文档中 https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/web/web-event-sequence.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### 效果预览 + +| 日志效果 | +| --------------------------------------- | +| ![](./screenshots/LifecycleWebComp.png) | + +使用说明 + +1. 此 Web 组件无页面展示,运行时通过系统日志输出相关信息。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +### 相关权限 + +无。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/LifecycleWebComp > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/build-profile.json5 b/ArkWeb/LifecycleWebComp/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d8f458efb875310bfaca49b33a5a8fc651e1ebd7 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/build-profile.json5 @@ -0,0 +1,51 @@ +/* + * 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/code-linter.json5 b/ArkWeb/LifecycleWebComp/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..eff2dbc9b8a447e5a99b0aab08ca2b766d786bf6 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/.gitignore b/ArkWeb/LifecycleWebComp/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/build-profile.json5 b/ArkWeb/LifecycleWebComp/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31bf2f4c4df15f0403582b255ebdff1354312357 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/hvigorfile.ts b/ArkWeb/LifecycleWebComp/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/LifecycleWebComp/entry/obfuscation-rules.txt b/ArkWeb/LifecycleWebComp/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/oh-package.json5 b/ArkWeb/LifecycleWebComp/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4e54d14e1b444a338b2c922f94a4fe4deed5be45 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..217744d8eb6d893e1138cd660209ce4d0441ac4f --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b744d7eaa66e51e79fc4e0896e251292ee767c5 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/ets/pages/Index.ets b/ArkWeb/LifecycleWebComp/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5e904676c4acbaa978d796dc71ce3ca78d084010 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,131 @@ +/* + * 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. + */ +// [Start the_status_of_web_component_web_page_loading] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { promptAction } from '@kit.ArkUI'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + responseWeb: WebResourceResponse = new WebResourceResponse(); + heads: Header[] = new Array(); + @State webData: string = '\n' + + '\n' + + '\n' + + 'intercept test\n' + + '\n' + + '\n' + + '

intercept test

\n' + + '\n' + + ''; + + aboutToAppear(): void { + try { + webview.WebviewController.setWebDebuggingAccess(true); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + } + + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onControllerAttached(() => { + // 推荐在此loadUrl、设置自定义用户代理、注入JS对象等 + console.log('onControllerAttached execute'); + }) + .onLoadIntercept((event) => { + if (event) { + console.log('onLoadIntercept url:' + event.data.getRequestUrl()); + console.log('url:' + event.data.getRequestUrl()); + console.log('isMainFrame:' + event.data.isMainFrame()); + console.log('isRedirect:' + event.data.isRedirect()); + console.log('isRequestGesture:' + event.data.isRequestGesture()); + } + // 返回true表示阻止此次加载,否则允许此次加载 + return true; + }) + .onOverrideUrlLoading((webResourceRequest: WebResourceRequest) => { + if (webResourceRequest && webResourceRequest.getRequestUrl() == 'about:blank') { + return true; + } + return false; + }) + .onInterceptRequest((event) => { + if (event) { + console.log('url:' + event.request.getRequestUrl()); + } + let head1: Header = { + headerKey: 'Connection', + headerValue: 'keep-alive' + } + let head2: Header = { + headerKey: 'Cache-Control', + headerValue: 'no-cache' + } + let length = this.heads.push(head1); + length = this.heads.push(head2); + this.responseWeb.setResponseHeader(this.heads); + this.responseWeb.setResponseData(this.webData); + this.responseWeb.setResponseEncoding('utf-8'); + this.responseWeb.setResponseMimeType('text/html'); + this.responseWeb.setResponseCode(200); + this.responseWeb.setReasonMessage('OK'); + // 返回响应数据则按照响应数据加载,无响应数据则返回null表示按照原来的方式加载 + return this.responseWeb; + }) + .onPageBegin((event) => { + if (event) { + console.log('onPageBegin url:' + event.url); + } + }) + .onFirstContentfulPaint(event => { + if (event) { + console.log('onFirstContentfulPaint:' + '[navigationStartTick]:' + + event.navigationStartTick + ', [firstContentfulPaintMs]:' + + event.firstContentfulPaintMs); + } + }) + .onProgressChange((event) => { + if (event) { + console.log('newProgress:' + event.newProgress); + } + }) + .onPageEnd((event) => { + // 推荐在此事件中执行JavaScript脚本 + if (event) { + console.log('onPageEnd url:' + event.url); + } + }) + .onPageVisible((event) => { + console.log('onPageVisible url:' + event.url); + }) + .onRenderExited((event) => { + if (event) { + console.log('onRenderExited reason:' + event.renderExitReason); + } + }) + .onDisAppear(() => { + promptAction.showToast({ + message: 'The web is hidden', + duration: 2000 + }); + }) + } + } +} +// [End the_status_of_web_component_web_page_loading] \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/module.json5 b/ArkWeb/LifecycleWebComp/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cb5df2316a385286bf09b1aab230f0bf56d8b993 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/color.json b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/string.json b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..38f261172dc69d5f1652c4a07e5197966e5d449f --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "LifecycleWebComp" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/background.png b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/en_US/element/string.json b/ArkWeb/LifecycleWebComp/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..38f261172dc69d5f1652c4a07e5197966e5d449f --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "LifecycleWebComp" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html b/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..844921321627bd854c9219a879ff5c656da188e9 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,9 @@ + + + + + + +

Hello, ArkWeb

+ + diff --git a/ArkWeb/LifecycleWebComp/entry/src/main/resources/zh_CN/element/string.json b/ArkWeb/LifecycleWebComp/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..00df20570eb1892ed5e7d19b125c9f65988634c4 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "LifecycleWebComp" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/mock/mock-config.json5 b/ArkWeb/LifecycleWebComp/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..26ed9f53bc46192a07ad5ab16ea24e7ce9a79328 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..72a538fe044d7e7dbbac4010a47249c3eeabeeb7 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('testUiExample',0, async (done: Function) => { + console.info("uitest: TestUiExample begin"); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('index.html'); + + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e909c66ab67746c53f694cc12a0a604748a8b661 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/ohosTest/module.json5 b/ArkWeb/LifecycleWebComp/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5f63462032245655b8df990c83c5d7312015c089 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/LifecycleWebComp/entry/src/test/List.test.ets b/ArkWeb/LifecycleWebComp/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab6445db05608a5b7f851a85add24f32b890b0f8 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/entry/src/test/LocalUnit.test.ets b/ArkWeb/LifecycleWebComp/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b7b4eb2ff9627c7184e386fe88c2ba1b507f905 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/LifecycleWebComp/hvigor/hvigor-config.json5 b/ArkWeb/LifecycleWebComp/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..76e3231223076011f7f4400f54fa73a5ab0141d4 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/LifecycleWebComp/hvigorfile.ts b/ArkWeb/LifecycleWebComp/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/LifecycleWebComp/oh-package.json5 b/ArkWeb/LifecycleWebComp/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d7622199b7ba60be5983122081f71ae9ebef0c4b --- /dev/null +++ b/ArkWeb/LifecycleWebComp/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/LifecycleWebComp/ohosTest.md b/ArkWeb/LifecycleWebComp/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..cbf90fb29998b1baec6a0ea45fdd2c6ff8633012 --- /dev/null +++ b/ArkWeb/LifecycleWebComp/ohosTest.md @@ -0,0 +1,4 @@ +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ------------ | ---------------- | -------- | -------- | +| Web组件的生命周期 | 设备运转正常 | 应用启动成功 | 日志输出相关信息 | Yes | Pass | + diff --git a/ArkWeb/LifecycleWebComp/screenshots/LifecycleWebComp.png b/ArkWeb/LifecycleWebComp/screenshots/LifecycleWebComp.png new file mode 100644 index 0000000000000000000000000000000000000000..879273b457515acee4cc9752e74440204b7ac63c Binary files /dev/null and b/ArkWeb/LifecycleWebComp/screenshots/LifecycleWebComp.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/.gitignore b/ArkWeb/ManageWebCompSecPriv/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/AppScope/app.json5 b/ArkWeb/ManageWebCompSecPriv/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f3bfcf54902f2bda4cd2cee4b827b89e2ba7ee37 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "com.samples.managewebcompsecpriv", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/element/string.json b/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8e172ff2061de12c25e977effcf18d7629db4cd7 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManageWebCompSecPriv" + } + ] +} diff --git a/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/media/app_icon.png b/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/README.md b/ArkWeb/ManageWebCompSecPriv/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5a91822c8adb3714ad2d1d50fcad808aa8ef0b4d --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/README.md @@ -0,0 +1,270 @@ +## 解决Web组件本地资源跨域问题 + +### 介绍 + +1. 本示例主要介绍解决Web组件本地资源跨域问题,利用Web组件的onInterceptRequest方法,对本地资源进行拦截和相应的替换。 +2. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-cross-origin.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### LocCrossOriginResAccSol_one + +##### 介绍 + +1. 本示例主要介绍解决Web组件本地资源跨域问题,利用Web组件的onInterceptRequest方法,对本地资源进行拦截和相应的替换。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 针对本地index.html,使用http或者https协议代替file协议或者resource协议,构造一个属于自己的域名。 + +#### LocCrossOriginResAccSol_two + +##### 介绍 + +1. 本示例主要介绍解决Web组件本地资源跨域问题,通过setPathAllowingUniversalAccess设置一个路径列表。当使用file协议访问该列表中的资源时,允许进行跨域访问本地文件。 + +##### 效果预览 + +| 主页 | 跨域访问 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 通过setPathAllowingUniversalAccess设置一个路径列表。当使用file协议访问该列表中的资源时,允许进行跨域访问本地文件。 +1. index.html页面加载完成后,页面上显示一个按钮stealFile,点击stealFile按钮触发getFile函数跨域访问本地resfile/js/script.js文件。 + +## 使用智能防跟踪功能 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-intelligent-tracking-prevention.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +#### AddIntTrackPreventByPassList + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,调用addIntelligentTrackingPreventionBypassingList接口设置需要绕过智能防跟踪功能的域名列表。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击addIntelligentTrackingPreventionBypassingList按钮设置需要绕过智能防跟踪功能的域名。 + +#### ClearIntTrackPreventByPassList + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,通过调用clearIntelligentTrackingPreventionBypassingList接口清除通过addIntelligentTrackingPreventionBypassingList接口设置的所有域名。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击clearIntelligentTrackingPreventionBypassingList按钮清除通过addIntelligentTrackingPreventionBypassingList接口设置的所有域名。 + +#### EnableIntTrackPrevent + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,调用enableIntelligentTrackingPrevention接口使能或者关闭相应Web组件的智能防跟踪功能。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击enableIntelligentTrackingPrevention按钮使能相应Web组件的智能防跟踪功能。 + +#### IsIntTrackPreventEnabled + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,通过调用isIntelligentTrackingPreventionEnabled接口判断当前Web组件是否开启了智能防跟踪功能。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击isIntelligentTrackingPreventionEnabled按钮判断当前Web组件是否开启了智能防跟踪功能。 + +#### OnIntTrackPreventResult + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,通过调用onIntelligentTrackingPreventionResult接口,以回调的方式异步获取拦截的跟踪型网站的域名和访问的网站域名信息。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击onIntelligentTrackingPreventionResult按钮,获取拦截的跟踪型网站的域名和访问的网站域名信息。 + +#### RemoveIntTrackPreventByPassList + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,通过调用removeIntelligentTrackingPreventionBypassingList接口移除通过addIntelligentTrackingPreventionBypassingList接口设置的部分域名列表。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击removeIntelligentTrackingPreventionBypassingList按钮,移除通过addIntelligentTrackingPreventionBypassingList接口设置的部分域名列表。 + +## 使用Web组件的广告过滤功能 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-adsblock.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +#### EnablingAdsBlocking + +##### 介绍 + +1. 本示例主要介绍使用Web组件的广告过滤功能,应用可以通过AdsBlockManager提供的setAdsBlockRules()接口设置自定义的easylist过滤规则,并通过Web组件的enableAdsBlock()接口使能广告过滤特性。 + +##### 效果预览 + +| 主页 | 文件选择器 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| /> | | + +使用说明 + +1. 点击setAdsBlockRules按钮,通过文件选择器设置自定义的easylist过滤规则。 + +#### DisAdsBlockSpecDomPages_one + +##### 介绍 + +1. 本示例主要介绍使用Web组件的广告过滤功能,在Web组件的广告过滤开关开启后,应用有时候会期望关闭一些特定页面的广告过滤功能,AdsBlockManager提供了addAdsBlockDisallowedList()接口完成此功能。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击addAdsBlockDisallowedList按钮关闭特定域名页面的广告过滤。 + +#### DisAdsBlockSpecDomPages_two + +##### 介绍 + +1. 本示例主要介绍使用Web组件的广告过滤功能,使用addAdsBlockDisallowedList()接口添加域名。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击addAdsBlockDisallowedList按钮添加域名。 + +#### CollectingAdsBlockingInformation + +##### 介绍 + +1. 本示例主要介绍使用Web组件的广告过滤功能,在Web组件的广告过滤开关开启后,访问的网页如果发生了广告过滤,会通过Web组件的onAdsBlocked()回调接口通知到应用,应用可根据需要进行过滤信息的收集和统计。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 使用onAdsBlocked接口收集广告过滤的信息。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---CollectingAdsBlockingInformation +|---|---|---DisAdsBlockSpecDomPages_one +|---|---|---DisAdsBlockSpecDomPages_two +|---|---|---LocCrossOriginResAccSol_one +|---|---|---LocCrossOriginResAccSol_two +|---|---|---AddIntTrackPreventByPassList +|---|---|---ClearIntTrackPreventByPassList +|---|---|---EnableIntTrackPrevent +|---|---|---IsIntTrackPreventEnabled +|---|---|---OnIntTrackPreventResult +|---|---|---RemoveIntTrackPreventByPassList +|---|---|---EnablingAdsBlocking +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +### 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/ManageWebCompSecPriv > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` diff --git a/ArkWeb/ManageWebCompSecPriv/build-profile.json5 b/ArkWeb/ManageWebCompSecPriv/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..edcfa0a0b72fb77e6fa0828177e088eec84f61eb --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/build-profile.json5 @@ -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. + */ + + { + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/code-linter.json5 b/ArkWeb/ManageWebCompSecPriv/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/code-linter.json5 @@ -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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/.gitignore b/ArkWeb/ManageWebCompSecPriv/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/build-profile.json5 b/ArkWeb/ManageWebCompSecPriv/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/hvigorfile.ts b/ArkWeb/ManageWebCompSecPriv/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ManageWebCompSecPriv/entry/obfuscation-rules.txt b/ArkWeb/ManageWebCompSecPriv/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/oh-package.json5 b/ArkWeb/ManageWebCompSecPriv/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entryability/EntryAbility.ets @@ -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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/AddIntTrackPreventByPassList.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/AddIntTrackPreventByPassList.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa1655f7bbde61df1c1a081b565110487297ab79 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/AddIntTrackPreventByPassList.ets @@ -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. + */ +// [Start set_domains_to_bypass_intelligent_tracking] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('addIntelligentTrackingPreventionBypassingList') + .onClick(() => { + try { + let hostList = ['www.test1.com', 'www.test2.com', 'www.test3.com']; + webview.WebviewController.addIntelligentTrackingPreventionBypassingList(hostList); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }); + } + } +} +// [End set_domains_to_bypass_intelligent_tracking] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets new file mode 100644 index 0000000000000000000000000000000000000000..49754ae2a245269f8aaec2dbcd2934e959e8bcb4 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets @@ -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. + */ +// [Start clear_all_intelligent_tracking_prevention_bypasses] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('clearIntelligentTrackingPreventionBypassingList') + .onClick(() => { + webview.WebviewController.clearIntelligentTrackingPreventionBypassingList(); + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }) + } + } +} +// [End clear_all_intelligent_tracking_prevention_bypasses] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d271fae7990654324db8a7e4aeb8b3b363caec9 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.ets @@ -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. + */ + +// [Start collect_information_about_ad_filtering] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + @State totalAdsBlockCounts: number = 0; + // [StartExclude collect_information_about_ad_filtering] + @State myString: string = 'onAdsBlocked'; + // [EndExclude collect_information_about_ad_filtering] + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.controller }) + .onAdsBlocked((details: AdsBlockedDetails) => { + if (details) { + console.log(' Blocked ' + details.adsBlocked.length + ' in ' + details.url); + let adList: string[] = Array.from(new Set(details.adsBlocked)); + this.totalAdsBlockCounts += adList.length; + console.log('Total blocked counts :' + this.totalAdsBlockCounts); + } + }) + } + } +} +// [End collect_information_about_ad_filtering] diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7649e9937a547b1fc4a4034afce0a877e524fc5 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets @@ -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. + */ +// [Start turn_off_ad_filtering_for_specific_domain_pages] +import { webview } from '@kit.ArkWeb'; + +// [StartExclude turn_off_ad_filtering_for_specific_domain_pages] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude turn_off_ad_filtering_for_specific_domain_pages] +@Entry +@Component +struct WebComponent { + mainUrl: string = resourceToString($r('app.string.web_path')); + textInputController: TextInputController = new TextInputController(); + controller: webview.WebviewController = new webview.WebviewController(); + + @State inputText: string = resourceToString($r('app.string.web_path')); + + build() { + Column() { + Row() { + Flex() { + TextInput({ text: this.inputText, placeholder: this.mainUrl, controller: this.textInputController}) + .id('input_url') + .height(40) + .margin(5) + .borderColor(Color.Blue) + .onChange((value: string) => { + this.inputText = value; + }) + + Button({type: ButtonType.Capsule}) { Text('Go') } + .onClick(() => { + this.controller.loadUrl(this.inputText); + }) + + Button({type: ButtonType.Capsule}) { Text('addAdsBlockDisallowedList') } + .onClick(() => { + let arrDomainSuffixes: string[] = []; + arrDomainSuffixes.push('example.com'); + arrDomainSuffixes.push('abcdefg.cn'); + webview.AdsBlockManager.addAdsBlockDisallowedList(arrDomainSuffixes); + }) + } + } + Web({ src: this.mainUrl, controller: this.controller }) + .onControllerAttached(()=>{ + this.controller.enableAdsBlock(true); + }) + } + } +} +// [End turn_off_ad_filtering_for_specific_domain_pages] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..c407061e161f5f86af1b1272e265f1d59262e821 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets @@ -0,0 +1,67 @@ +/* + * 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. + */ +// [Start set_up_page_level_ad_filtering_switch] +import { webview } from '@kit.ArkWeb'; + +// [StartExclude set_up_page_level_ad_filtering_switch] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude set_up_page_level_ad_filtering_switch] +@Entry +@Component +struct WebComponent { + mainUrl: string = resourceToString($r('app.string.web_path')); + textInputController: TextInputController = new TextInputController(); + controller: webview.WebviewController = new webview.WebviewController(); + + @State inputText: string = resourceToString($r('app.string.web_path')); + + build() { + Column() { + Row() { + Flex() { + TextInput({ text: this.inputText, placeholder: this.mainUrl, controller: this.textInputController}) + .id('input_url') + .height(40) + .margin(5) + .borderColor(Color.Blue) + .onChange((value: string) => { + this.inputText = value; + }) + + Button({type: ButtonType.Capsule}) { Text('Go'); } + .onClick(() => { + this.controller.loadUrl(this.inputText); + }) + + Button({type: ButtonType.Capsule}) { Text('addAdsBlockAllowedList'); } + .onClick(() => { + let arrDisallowDomainSuffixes = ['example.com']; + webview.AdsBlockManager.addAdsBlockDisallowedList(arrDisallowDomainSuffixes); + + let arrAllowedDomainSuffixes = ['news.example.com', 'sport.example.com']; + webview.AdsBlockManager.addAdsBlockAllowedList(arrAllowedDomainSuffixes); + }) + } + } + Web({ src: this.mainUrl, controller: this.controller }) + .onControllerAttached(()=>{ + this.controller.enableAdsBlock(true); + }) + } + } +} +// [End set_up_page_level_ad_filtering_switch] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab7767a6c6bb65d34e0c320e9d6b126039a8e77d --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.ets @@ -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. + */ + +// [Start enable_or_disable_web_component_anti_tracking] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('enableIntelligentTrackingPrevention') + .onClick(() => { + try { + this.controller.enableIntelligentTrackingPrevention(true); + console.log('enableIntelligentTrackingPrevention: true'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }); + } + } +} +// [End enable_or_disable_web_component_anti_tracking] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnablingAdsBlocking.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnablingAdsBlocking.ets new file mode 100644 index 0000000000000000000000000000000000000000..8eb4a81e2d203fc04af163a09aaf5601ef77c7c7 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnablingAdsBlocking.ets @@ -0,0 +1,64 @@ +/* + * 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. + */ + +// [Start app_select_list_rule_file_for_ad_filter] +import { webview } from '@kit.ArkWeb'; +import { picker, fileUri } from '@kit.CoreFileKit'; + +// [StartExclude app_select_list_rule_file_for_ad_filter] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude app_select_list_rule_file_for_ad_filter] +@Entry +@Component +struct WebComponent { + mainUrl: string = resourceToString($r('app.string.web_path')); + controller: webview.WebviewController = new webview.WebviewController(); + + @State inputText: string = resourceToString($r('app.string.web_path')); + + build() { + Column() { + Row() { + Flex() { + Button({type: ButtonType.Capsule}) { + Text('setAdsBlockRules'); + } + .onClick(() => { + try { + let documentSelectionOptions: picker.DocumentSelectOptions = new picker.DocumentSelectOptions(); + let documentPicker: picker.DocumentViewPicker = new picker.DocumentViewPicker(); + documentPicker.select(documentSelectionOptions).then((documentSelectResult: string[]) => { + if (documentSelectResult && documentSelectResult.length > 0) { + let fileRealPath = new fileUri.FileUri(documentSelectResult[0]); + console.info('DocumentViewPicker.select successfully, uri: ' + fileRealPath); + webview.AdsBlockManager.setAdsBlockRules(fileRealPath.path, true); + } + }) + } catch (err) { + console.error('DocumentViewPicker.select failed with err:' + err); + } + }) + } + } + Web({ src: this.mainUrl, controller: this.controller }) + .onControllerAttached(()=>{ + this.controller.enableAdsBlock(true); + }) + } + } +} +// [End app_select_list_rule_file_for_ad_filter] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb5f033b5edc90ee98d926d2590e6c02294df4b6 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,74 @@ +/* + * 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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('LocCrossOriginResAccSol_one') + .onClick(() => { + router.pushUrl({ url: 'pages/LocCrossOriginResAccSol_one' }); + }) + Button('LocCrossOriginResAccSol_two') + .onClick(() => { + router.pushUrl({ url: 'pages/LocCrossOriginResAccSol_two' }); + }) + Button('AddIntTrackPreventByPassList') + .onClick(() => { + router.pushUrl({ url: 'pages/AddIntTrackPreventByPassList' }); + }) + Button('ClearIntTrackPreventByPassList') + .onClick(() => { + router.pushUrl({ url: 'pages/ClearIntTrackPreventByPassList' }); + }) + Button('EnableIntTrackPrevent') + .onClick(() => { + router.pushUrl({ url: 'pages/EnableIntTrackPrevent' }); + }) + Button('IsIntTrackPreventEnabled') + .onClick(() => { + router.pushUrl({ url: 'pages/IsIntTrackPreventEnabled' }); + }) + Button('OnIntTrackPreventResult') + .onClick(() => { + router.pushUrl({ url: 'pages/OnIntTrackPreventResult' }); + }) + Button('RemoveIntTrackPreventByPassList') + .onClick(() => { + router.pushUrl({ url: 'pages/RemoveIntTrackPreventByPassList' }); + }) + Button('EnablingAdsBlocking') + .onClick(() => { + router.pushUrl({ url: 'pages/EnablingAdsBlocking' }); + }) + Button('DisAdsBlockSpecDomPages_one') + .onClick(() => { + router.pushUrl({ url: 'pages/DisAdsBlockSpecDomPages_one' }); + }) + Button('DisAdsBlockSpecDomPages_two') + .onClick(() => { + router.pushUrl({ url: 'pages/DisAdsBlockSpecDomPages_two' }); + }) + Button('CollectingAdsBlockingInformation') + .onClick(() => { + router.pushUrl({ url: 'pages/CollectingAdsBlockingInformation' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.ets new file mode 100644 index 0000000000000000000000000000000000000000..b33603d2c083d817a71949d8e8c4ac533582e4fc --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.ets @@ -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. + */ + +// [Start check_if_web_component_anti_tracking_on] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('isIntelligentTrackingPreventionEnabled') + .onClick(() => { + try { + let result = this.controller.isIntelligentTrackingPreventionEnabled(); + console.log('result: ' + result); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }); + } + } +} +// [End check_if_web_component_anti_tracking_on] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_one.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..89333b69cb353cc31ca718d0175cae53d6bd1de7 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_one.ets @@ -0,0 +1,79 @@ +/* + * 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. + */ + +// [Start cors_loccross_one] +import { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + webviewController: webview.WebviewController = new webview.WebviewController(); + // 构造域名和本地文件的映射表 + schemeMap = new Map([ + [resourceToString($r('app.string.web_path')) + '/index.html', 'index.html'], + [resourceToString($r('app.string.web_path')) + '/js/script.js', 'js/script.js'], + ]); + // 构造本地文件和构造返回的格式mimeType + mimeTypeMap = new Map([ + ['index.html', 'text/html'], + ['js/script.js', 'text/javascript'] + ]); + + build() { + Row() { + Column() { + // 针对本地index1.html,使用http或者https协议代替file协议或者resource协议,并且构造一个属于自己的域名。 + // 本例中构造www.example.com为例。 + Web({ src: resourceToString($r('app.string.web_path')) + '/index.html', controller: this.webviewController }) + .javaScriptAccess(true) + .fileAccess(true) + .domStorageAccess(true) + .geolocationAccess(true) + .width('100%') + .height('100%') + .onInterceptRequest((event) => { + if (!event) { + return; + } + // 此处匹配自己想要加载的本地离线资源,进行资源拦截替换,绕过跨域 + if (this.schemeMap.has(event.request.getRequestUrl())) { + let rawfileName: string = this.schemeMap.get(event.request.getRequestUrl())!; + let mimeType = this.mimeTypeMap.get(rawfileName); + if (typeof mimeType === 'string') { + let response = new WebResourceResponse(); + // 构造响应数据,如果本地文件在rawfile下,可以通过如下方式设置 + response.setResponseData($rawfile(rawfileName)); + response.setResponseEncoding('utf-8'); + response.setResponseMimeType(mimeType); + response.setResponseCode(200); + response.setReasonMessage('OK'); + response.setResponseIsReady(true); + return response; + } + } + return null; + }) + } + .width('100%') + } + .height('100%') + } +} +// [End cors_loccross_one] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_two.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..aae56aaced7fd6f3c2611a7080e2c823b87ea13d --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_two.ets @@ -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. + */ + +// [Start cors_loccross_two] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: WebviewController = new webview.WebviewController(); + + build() { + Row() { + Web({ src: '', controller: this.controller }) + .onControllerAttached(() => { + try { + // 设置允许可以跨域访问的路径列表 + this.controller.setPathAllowingUniversalAccess([ + getContext().resourceDir, + getContext().filesDir + '/example' + ]); + this.controller.loadUrl('file://' + getContext().resourceDir + '/index.html'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + .javaScriptAccess(true) + .fileAccess(true) + .domStorageAccess(true) + } + } +} +// [End cors_loccross_two] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets new file mode 100644 index 0000000000000000000000000000000000000000..23fdec43f07cb906691e0505bdc65cd5306e1e36 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets @@ -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. + */ + +// [Start retrieve_blocked_and_visited_domain_names] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + // 需要打开智能防跟踪功能,才会触发onIntelligentTrackingPreventionResult回调 + Button('enableIntelligentTrackingPrevention') + .onClick(() => { + try { + this.controller.enableIntelligentTrackingPrevention(true); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }) + .onIntelligentTrackingPreventionResult((details) => { + console.log('onIntelligentTrackingPreventionResult: [websiteHost]= ' + details.host + + ', [trackerHost]=' + details.trackerHost); + }) + } + } +} +// [End retrieve_blocked_and_visited_domain_names] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.ets new file mode 100644 index 0000000000000000000000000000000000000000..ed8c741879f229405e43b14fbc72650b4df53ec9 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.ets @@ -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. + */ +// [Start partial_domain_name_list] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('removeIntelligentTrackingPreventionBypassingList') + .onClick(() => { + try { + let hostList = [ 'www.test1.com', 'www.test2.com' ]; + webview.WebviewController.removeIntelligentTrackingPreventionBypassingList(hostList); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +// [End partial_domain_name_list] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/module.json5 b/ArkWeb/ManageWebCompSecPriv/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/module.json5 @@ -0,0 +1,71 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/color.json b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/string.json b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..68f2a3f7cd4e6b25d5f6224c60837ba99c25ec76 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageWebCompSecPriv" + }, + { + "name": "web_path", + "value": "https://www.example.com" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/background.png b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/foreground.png b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..8a72c3b7803a5e5cd787f8239bc1a60b9f60391c --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,17 @@ +{ + "src": [ + "pages/Index", + "pages/LocCrossOriginResAccSol_one", + "pages/LocCrossOriginResAccSol_two", + "pages/AddIntTrackPreventByPassList", + "pages/ClearIntTrackPreventByPassList", + "pages/EnableIntTrackPrevent", + "pages/IsIntTrackPreventEnabled", + "pages/OnIntTrackPreventResult", + "pages/RemoveIntTrackPreventByPassList", + "pages/EnablingAdsBlocking", + "pages/DisAdsBlockSpecDomPages_one", + "pages/DisAdsBlockSpecDomPages_two", + "pages/CollectingAdsBlockingInformation" + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/en_US/element/string.json b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6aba54ea1bb3ac12f412cb39a46e76081f6fcc31 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageWebCompSecPriv" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..01ba29a16a4306f3ed6bd10c2c7a9cdb84e5285e --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,23 @@ + + + + + + + + + + diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js new file mode 100644 index 0000000000000000000000000000000000000000..dfd1c0b8cb035c61be2f521a59d66908d4b4c023 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js @@ -0,0 +1,21 @@ +/* + * 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. + */ + +// [Start cors_script_raw] +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'success'; +body.appendChild(element); +// [End cors_script_raw] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..e8aa15081537f3f522e4ed361345524ca955f8f3 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html @@ -0,0 +1,56 @@ + + + + + + + + Demo + + + + + +
+ +
+
+ + + diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js new file mode 100644 index 0000000000000000000000000000000000000000..9853f099a5d5f45d51460a9c53fd067ed68eb240 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js @@ -0,0 +1,21 @@ +/* + * 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. + */ + +// [Start cors_script] +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'success'; +body.appendChild(element); +// [End cors_script] \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/zh_CN/element/string.json b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fa45cf3851f9f2519e27031ca337ffd4bd784ce5 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageWebCompSecPriv" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/mock/mock-config.json5 b/ArkWeb/ManageWebCompSecPriv/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f1d36678d8f270241ce6d2f73e6654664986586 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,369 @@ +/* + * 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /** + * 打开应用,点击 LocCrossOriginResAccSol_one 按钮 + * 对本地资源进行拦截和相应的替换 + */ + it('LocCrossOriginResAccSol_one', 0, async (done: Function) => { + console.info('uitest: LocCrossOriginResAccSol_one begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('LocCrossOriginResAccSol_one')); + await button1.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('index.html'); + + await driver.pressBack(); + console.info('uitest: LocCrossOriginResAccSol_one end'); + done(); + }); + + /** + * 点击 LocCrossOriginResAccSol_two 按钮,跨域访问本地文件 + */ + it('LocCrossOriginResAccSol_two', 0, async (done: Function) => { + console.info('uitest: LocCrossOriginResAccSol_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('LocCrossOriginResAccSol_two')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('button')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.type('button')); + await button3.click(); + + const web1 = await driver.findComponent(ON.type('Web')); + let src = await web1.getText(); + expect(src).assertContain(''); + + await driver.pressBack(); + console.info('uitest: LocCrossOriginResAccSol_two end'); + done(); + }); + + /** + * 点击 AddIntTrackPreventByPassList 按钮 + * 设置需要绕过智能防跟踪功能的域名列表 + */ + it('AddIntTrackPreventByPassList',0, async (done: Function) => { + console.info('uitest: AddIntTrackPreventByPassList begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('AddIntTrackPreventByPassList')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: AddIntTrackPreventByPassList end'); + done(); + }); + + /** + * 点击 ClearIntTrackPreventByPassList 按钮 + * 清除通过 addIntelligentTrackingPreventionBypassingList 接口设置的所有域名 + */ + it('ClearIntTrackPreventByPassList',0, async (done: Function) => { + console.info('uitest: ClearIntTrackPreventByPassList begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ClearIntTrackPreventByPassList')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: ClearIntTrackPreventByPassList end'); + done(); + }); + + /** + * 点击 EnableIntTrackPrevent 按钮 + * 使能或者关闭相应Web组件的智能防跟踪功能 + */ + it('EnableIntTrackPrevent',0, async (done: Function) => { + console.info('uitest: EnableIntTrackPrevent begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('EnableIntTrackPrevent')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: EnableIntTrackPrevent end'); + done(); + }); + + /** + * 点击 IsIntTrackPreventEnabled 按钮 + * 判断当前Web组件是否开启了智能防跟踪功能 + */ + it('IsIntTrackPreventEnabled',0, async (done: Function) => { + console.info('uitest: IsIntTrackPreventEnabled begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('IsIntTrackPreventEnabled')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: IsIntTrackPreventEnabled end'); + done(); + }); + + /** + * 点击 OnIntTrackPreventResult 按钮 + * 异步获取拦截的跟踪型网站的域名和访问的网站域名信息 + */ + it('OnIntTrackPreventResult',0, async (done: Function) => { + console.info('uitest: OnIntTrackPreventResult begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('OnIntTrackPreventResult')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: OnIntTrackPreventResult end'); + done(); + }); + + /** + * 点击 RemoveIntTrackPreventByPassList 按钮 + * 移除通过 addIntelligentTrackingPreventionBypassingList 接口设置的部分域名列表 + */ + it('RemoveIntTrackPreventByPassList',0, async (done: Function) => { + console.info('uitest: RemoveIntTrackPreventByPassList begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('RemoveIntTrackPreventByPassList')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: RemoveIntTrackPreventByPassList end'); + done(); + }); + + /** + * 点击 EnablingAdsBlocking 按钮 + * 设置自定义的easylist过滤规则并使能广告过滤特性 + */ + it('EnablingAdsBlocking',0, async (done: Function) => { + console.info('uitest: EnablingAdsBlocking begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('EnablingAdsBlocking')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + await driver.pressBack(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: EnablingAdsBlocking end'); + done(); + }); + + /** + * 点击 DisAdsBlockSpecDomPages_one 按钮 + * 关闭一些特定页面的广告过滤功能 + */ + it('DisAdsBlockSpecDomPages_one',0, async (done: Function) => { + console.info('uitest: DisAdsBlockSpecDomPages_one begin'); + const driver = Driver.create(); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('DisAdsBlockSpecDomPages_one')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('Go')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('addAdsBlockDisallowedList')); + await button3.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: DisAdsBlockSpecDomPages_one end'); + done(); + }); + + /** + * 点击 DisAdsBlockSpecDomPages_two 按钮 + * 使用 addAdsBlockDisallowedList 接口添加域名 + */ + it('DisAdsBlockSpecDomPages_two',0, async (done: Function) => { + console.info('uitest: DisAdsBlockSpecDomPages_two begin'); + const driver = Driver.create(); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('DisAdsBlockSpecDomPages_two')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('Go')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('addAdsBlockAllowedList')); + await button3.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: DisAdsBlockSpecDomPages_two end'); + done(); + }); + + /** + * 点击 CollectingAdsBlockingInformation 按钮 + * 触发发生了广告过滤后过滤信息的收集和统计 + */ + it('CollectingAdsBlockingInformation',0, async (done: Function) => { + console.info('uitest: CollectingAdsBlockingInformation begin'); + const driver = Driver.create(); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('CollectingAdsBlockingInformation')); + await button1.click(); + await driver.delayMs(1000); + + const type1 = await driver.findComponent(ON.type('Web')); + let text: string = await type1.getText(); + expect(text).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: CollectingAdsBlockingInformation end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/module.json5 b/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/module.json5 @@ -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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/test/List.test.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/entry/src/test/LocalUnit.test.ets b/ArkWeb/ManageWebCompSecPriv/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/entry/src/test/LocalUnit.test.ets @@ -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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebCompSecPriv/hvigor/hvigor-config.json5 b/ArkWeb/ManageWebCompSecPriv/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/ManageWebCompSecPriv/hvigorfile.ts b/ArkWeb/ManageWebCompSecPriv/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* 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. +*/ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ManageWebCompSecPriv/oh-package.json5 b/ArkWeb/ManageWebCompSecPriv/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/ManageWebCompSecPriv/ohosTest.md b/ArkWeb/ManageWebCompSecPriv/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..a63576a348152f48f2d0a0658a723c18c0b87e15 --- /dev/null +++ b/ArkWeb/ManageWebCompSecPriv/ohosTest.md @@ -0,0 +1,71 @@ +### LocCrossOriginResAccSol_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------- | ------------ | ------------ | ------------------ | -------- | -------- | +| 解决Web组件本地资源跨域问题 | 设备运转正常 | 应用启动成功 | 加载index.html页面 | Yes | Pass | + +### LocCrossOriginResAccSol_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------- | ------------------------------------ | ------------------------------- | ------------------------------------ | -------- | -------- | +| 解决Web组件本地资源跨域问题 | 设备运转正常,index.html页面加载完成 | 应用启动成功,点击stealFile按钮 | 跨域访问本地resfile/js/script.js文件 | Yes | Pass | + +### AddIntTrackPreventByPassList + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------------------------------------------------------ | -------------------------------- | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击addIntelligentTrackingPreventionBypassingList按钮 | 设置需要绕过智能防跟踪功能的域名 | Yes | Pass | + +### ClearIntTrackPreventByPassList + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击clearIntelligentTrackingPreventionBypassingList按钮 | 清除通过addIntelligentTrackingPreventionBypassingList接口设置的所有域名 | Yes | Pass | + +### EnableIntTrackPrevent + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | --------------------------------------------------------- | ------------------------------- | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击enableIntelligentTrackingPrevention按钮 | 使能相应Web组件的智能防跟踪功能 | Yes | Pass | + +### IsIntTrackPreventEnabled + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------------------------------------------------------ | --------------------------------------- | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击isIntelligentTrackingPreventionEnabled按钮 | 判断当前Web组件是否开启了智能防跟踪功能 | Yes | Pass | + +### OnIntTrackPreventResult + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ----------------------------------------------------------- | ------------------------------------------------ | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击onIntelligentTrackingPreventionResult按钮 | 获取拦截的跟踪型网站的域名和访问的网站域名信息。 | Yes | Pass | + +### RemoveIntTrackPreventByPassList + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击removeIntelligentTrackingPreventionBypassingList按钮 | 移除通过addIntelligentTrackingPreventionBypassingList接口设置的部分域名列表 | Yes | Pass | + +### EnablingAdsBlocking + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | -------------------------------------- | -------------- | -------- | -------- | +| 使用Web组件的广告过滤功能 | 设备运转正常 | 应用启动成功,点击setAdsBlockRules按钮 | 打开文件选择器 | Yes | Pass | + +### DisAdsBlockSpecDomPages_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ----------------------------------------------- | -------------------------- | -------- | -------- | +| 使用Web组件的广告过滤功能 | 设备运转正常 | 应用启动成功,点击addAdsBlockDisallowedList按钮 | 关闭特定域名页面的广告过滤 | Yes | Pass | + +### DisAdsBlockSpecDomPages_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ----------------------------------------------- | -------- | -------- | -------- | +| 使用Web组件的广告过滤功能 | 设备运转正常 | 应用启动成功,点击addAdsBlockDisallowedList按钮 | 添加域名 | Yes | Pass | + +### CollectingAdsBlockingInformation + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ------------ | ------------------ | -------- | -------- | +| 使用Web组件的广告过滤功能 | 设备运转正常 | 应用启动成功 | 收集广告过滤的信息 | Yes | Pass | diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/AddIntTrackPreventByPassList.png b/ArkWeb/ManageWebCompSecPriv/screenshots/AddIntTrackPreventByPassList.png new file mode 100644 index 0000000000000000000000000000000000000000..ccbe69798a139432a565a9c74bef18fe5bc6f1e1 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/AddIntTrackPreventByPassList.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/ClearIntTrackPreventByPassList.png b/ArkWeb/ManageWebCompSecPriv/screenshots/ClearIntTrackPreventByPassList.png new file mode 100644 index 0000000000000000000000000000000000000000..c0438ba8b3ce0f30d8a340873cb43aef719de170 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/ClearIntTrackPreventByPassList.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/CollectingAdsBlockingInformation.png b/ArkWeb/ManageWebCompSecPriv/screenshots/CollectingAdsBlockingInformation.png new file mode 100644 index 0000000000000000000000000000000000000000..5e3d62abefcb00d148eeaf9cfa91c255b8344a1c Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/CollectingAdsBlockingInformation.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_one.png b/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_one.png new file mode 100644 index 0000000000000000000000000000000000000000..7e75e856cddf583d86e17f86a68f0c689836f298 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_one.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_two.png b/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_two.png new file mode 100644 index 0000000000000000000000000000000000000000..5f334f78a76bedca13310e917768027abaa16789 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_two.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/EnableIntTrackPrevent.png b/ArkWeb/ManageWebCompSecPriv/screenshots/EnableIntTrackPrevent.png new file mode 100644 index 0000000000000000000000000000000000000000..3b2c90131beb736c785746ec54c922640cc906da Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/EnableIntTrackPrevent.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_1.png b/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_1.png new file mode 100644 index 0000000000000000000000000000000000000000..6d6d41b49abab13406bdf04923b905d00081d7b6 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_1.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_2.png b/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_2.png new file mode 100644 index 0000000000000000000000000000000000000000..e327def8ac32a67e40b0f1319fc5ea6359dc5fe2 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_2.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/IsIntTrackPreventEnabled.png b/ArkWeb/ManageWebCompSecPriv/screenshots/IsIntTrackPreventEnabled.png new file mode 100644 index 0000000000000000000000000000000000000000..31f7613ec78b6a724259d2b80cd3f7d41170241a Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/IsIntTrackPreventEnabled.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_one.png b/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_one.png new file mode 100644 index 0000000000000000000000000000000000000000..a7cfbd1b813c8eacd6962fdc9552954f5b19f2a5 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_one.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_1.png b/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_1.png new file mode 100644 index 0000000000000000000000000000000000000000..816ee5693ab636c82957c6c524f5e7f10bea78a3 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_1.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_2.png b/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_2.png new file mode 100644 index 0000000000000000000000000000000000000000..8eb796240d9933f65ff4681d59075b93479d0809 Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_2.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/OnIntTrackPreventResult.png b/ArkWeb/ManageWebCompSecPriv/screenshots/OnIntTrackPreventResult.png new file mode 100644 index 0000000000000000000000000000000000000000..bc6f50d9eaeaedf1a0fe0f907f00e6ad44f369df Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/OnIntTrackPreventResult.png differ diff --git a/ArkWeb/ManageWebCompSecPriv/screenshots/RemoveIntTrackPreventByPassList.png b/ArkWeb/ManageWebCompSecPriv/screenshots/RemoveIntTrackPreventByPassList.png new file mode 100644 index 0000000000000000000000000000000000000000..47389d196eca6812e5ed0fd941798d677785836a Binary files /dev/null and b/ArkWeb/ManageWebCompSecPriv/screenshots/RemoveIntTrackPreventByPassList.png differ diff --git a/ArkWeb/ManageWebPageFileIO/.gitignore b/ArkWeb/ManageWebPageFileIO/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/AppScope/app.json5 b/ArkWeb/ManageWebPageFileIO/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c81be320936ad21787cdb02b4d04f1015bfae2ea --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "com.samples.managewebpagefileio", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/element/string.json b/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..651c9e36903ecf6afe4187bce123a1a3ab00c38d --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManageWebPageFileIO" + } + ] +} diff --git a/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/media/app_icon.png b/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWeb/ManageWebPageFileIO/README.md b/ArkWeb/ManageWebPageFileIO/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b0d6d3de9ee2f6d867d63d18dd7c1ddf55f19eea --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/README.md @@ -0,0 +1,133 @@ +## 上传文件 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-file-upload.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### UploadFiles + +#### 介绍 + +1. 本示例主要介绍Web组件上传文件功能,Web组件支持前端页面选择文件上传功能,应用开发者可以使用onShowvfileSelector)接口来处理前端页面文件上传的请求,如果应用开发者不做任何处理,Web会提供默认行为来处理前端页面文件上传的请求。 + +#### 效果预览 + +| 主页 | | +| ---------------------------------------------------------- | ---------------------------------------------------------- | +| | | + +使用方法 + +1. 在主页点击选择文件按钮触发onShowFileSelector事件创建DocumentSelectOptions和DocumentViewPicker,用于打开文件选择器,弹出文件选择器,用户可选择一个文件。 + +## 使用Web组件的下载能力 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-download.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### ListenForPageDown + +#### 介绍 + +1. 本示例主要介绍使用Web组件监听页面触发的下载功能,通过setDownloadDelegate()向Web组件注册一个DownloadDelegate来监听页面触发的下载任务。资源由Web组件来下载,Web组件会通过DownloadDelegate将下载的进度通知给应用。 + +#### 效果预览 + +| 主页 | 下载 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击setDownloadDelegate按钮,定义下载委托回调。 +2. 点击下载download.html链接,触发下载任务。 + +### InitiatingADownloadTask + +#### 介绍 + +1. 本示例主要介绍使用Web组件的下载能力。在Web组件启动时,可通过resumeDownload()接口恢复未完成的下载任务。 + + +#### 效果预览 + +| 主页 | 下载 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击setDownloadDelegate按钮,定义下载委托回调。 +1. 使用startDownload()接口发起一个下载。 + +### ResumeDownload + +#### 介绍 + +1. 本示例主要介绍使用Web组件的下载能力。使用startDownload()接口发起一个下载,Web组件发起的下载会根据当前显示的url以及Web组件默认的Referrer Policy来计算referrer。 + + +#### 效果预览 + +| 主页 | +| ----------------------------------------------------------- | +| | + +使用说明 + +1. 点击setDownloadDelegate按钮,定义下载委托回调。 +1. 使用startDownload()接口发起一个下载。 +1. 通过record按钮将当前下载任务保存至持久化文件中,记录下载任务信息。 +1. 点击recovery按钮恢复下载任务。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---UploadFiles.ets +|---|---|---downloadUtil.ets +|---|---|---Index.ets // 首页 +|---|---|---InitiatingADownloadTask.ets +|---|---|---ListenForPageDown.ets +|---|---|---ResumeDownload.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + +### 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/ManageWebPageFileIO > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/build-profile.json5 b/ArkWeb/ManageWebPageFileIO/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/build-profile.json5 @@ -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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/code-linter.json5 b/ArkWeb/ManageWebPageFileIO/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/code-linter.json5 @@ -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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/.gitignore b/ArkWeb/ManageWebPageFileIO/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/build-profile.json5 b/ArkWeb/ManageWebPageFileIO/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/hvigorfile.ts b/ArkWeb/ManageWebPageFileIO/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ManageWebPageFileIO/entry/obfuscation-rules.txt b/ArkWeb/ManageWebPageFileIO/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/oh-package.json5 b/ArkWeb/ManageWebPageFileIO/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entryability/EntryAbility.ets @@ -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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/Index.ets b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..80e8214f747914b9b3b64331d9eb37fd1619a007 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/Index.ets @@ -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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('UploadFiles') + .onClick(() => { + router.pushUrl({ url: 'pages/UploadFiles' }); + }) + Button('ListenForPageDown') + .onClick(() => { + router.pushUrl({ url: 'pages/ListenForPageDown' }); + }) + Button('InitiatingADownloadTask') + .onClick(() => { + router.pushUrl({ url: 'pages/InitiatingADownloadTask' }); + }) + Button('ResumeDownload') + .onClick(() => { + router.pushUrl({ url: 'pages/ResumeDownload' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b876e5f292321bcd2a884cd16a2f360516b7f02 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets @@ -0,0 +1,73 @@ +/* + * 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. + */ + +// [Start init_download_task] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); + @State myText: string = 'download'; + + build() { + Column() { + Text(this.myText) + Button('setDownloadDelegate') + .onClick(() => { + try { + this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { + console.log('will start a download.'); + // 传入一个下载路径,并开始下载。 + webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); + }) + this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { + console.log('download update guid: ' + webDownloadItem.getGuid()); + }) + this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { + console.log('download failed guid: ' + webDownloadItem.getGuid()); + }) + this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { + console.log('download finish guid: ' + webDownloadItem.getGuid()); + this.myText = 'download finish'; + }) + this.controller.setDownloadDelegate(this.delegate); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('startDownload') + .onClick(() => { + try { + // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 + // 开发者需要替换为自己想要下载的内容的地址。 + this.controller.startDownload(resourceToString($r('app.string.web_path'))); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +// [End init_download_task] diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets new file mode 100644 index 0000000000000000000000000000000000000000..733a26d4b9600db7f50a41cc0b338561f1584951 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets @@ -0,0 +1,67 @@ +/* + * 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. + */ + +// [Start download_delegate] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); + @State myText: string = 'download'; + + build() { + Column() { + Text(this.myText) + Button('setDownloadDelegate') + .onClick(() => { + try { + this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { + console.log('will start a download.'); + // Pass in a download path and start the download. + // If the path is invalid, the file will be downloaded to the + // default directory at /data/storage/el2/base/cache/web/. + webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); + }) + this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { + // Unique ID of a download task. + console.log('download update guid: ' + webDownloadItem.getGuid()); + // Download progress. + console.log('download update guid: ' + webDownloadItem.getPercentComplete()); + // Current download speed. + console.log('download update speed: ' + webDownloadItem.getCurrentSpeed()); + }) + this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { + console.log('download failed guid: ' + webDownloadItem.getGuid()); + // Error code of a download task failure. + console.log('download failed guid: ' + webDownloadItem.getLastErrorCode()); + }) + this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { + console.log('download finish guid: ' + webDownloadItem.getGuid()); + this.myText = 'download finish'; + }) + this.controller.setDownloadDelegate(this.delegate); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index.html'), controller: this.controller }) + } + } +} +// [End download_delegate] diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets new file mode 100644 index 0000000000000000000000000000000000000000..c0d230cdc7916565a9760fad159c3f84b950243c --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets @@ -0,0 +1,106 @@ +/* + * 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. + */ + +// [Start recovery_download_task] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { DownloadUtil, fileName, filePath } from './downloadUtil'; // downloadUtil.ets 见下文 + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); + download: webview.WebDownloadItem = new webview.WebDownloadItem(); + // 用于记录失败的下载任务。 + failedData: Uint8Array = new Uint8Array(); + + build() { + Column() { + Button('setDownloadDelegate') + .onClick(() => { + try { + this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { + console.log('will start a download.'); + // 传入一个下载路径,并开始下载。 + webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); + }) + this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { + console.log('download update percent complete: ' + webDownloadItem.getPercentComplete()); + this.download = webDownloadItem; + }) + this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { + console.log('download failed guid: ' + webDownloadItem.getGuid()); + // 序列化失败的下载任务到一个字节数组。 + this.failedData = webDownloadItem.serialize(); + }) + this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { + console.log('download finish guid: ' + webDownloadItem.getGuid()); + }) + this.controller.setDownloadDelegate(this.delegate); + webview.WebDownloadManager.setDownloadDelegate(this.delegate); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('startDownload') + .onClick(() => { + try { + // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 + // 开发者需要替换为自己想要下载的内容的地址。 + this.controller.startDownload(resourceToString($r('app.string.web_path'))); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 将当前的下载任务信息序列化保存,用于后续恢复下载任务。 + // 当前用例仅展示下载一个任务的场景,多任务场景请按需扩展。 + Button('record') + .onClick(() => { + try { + // 保存当前下载数据到持久化文档中。 + DownloadUtil.saveDownloadInfo(DownloadUtil.uint8ArrayToStr(this.download.serialize())); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 从序列化的下载任务信息中,恢复下载任务。 + // 按钮触发时必须保证WebDownloadManager.setDownloadDelegate设置完成。 + Button('recovery') + .onClick(() => { + try { + // 当前默认持久化文件存在,用户根据实际情况增加判断。 + let webDownloadItem = + webview.WebDownloadItem.deserialize( + DownloadUtil.strToUint8Array(DownloadUtil.readFileSync(filePath, fileName))); + webview.WebDownloadManager.resumeDownload(webDownloadItem); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +// [End recovery_download_task] \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets new file mode 100644 index 0000000000000000000000000000000000000000..f5e26614ec7193c00bd97c8ca7aca9b5d14d66b1 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets @@ -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. + */ + +// [Start web_file_upload] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { picker } from '@kit.CoreFileKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $rawfile('local.html'), controller: this.controller }) + .onShowFileSelector((event) => { + console.log('MyFileUploader onShowFileSelector invoked'); + const documentSelectOptions = new picker.DocumentSelectOptions(); + let uri: string | null = null; + const documentViewPicker = new picker.DocumentViewPicker(); + documentViewPicker.select(documentSelectOptions).then((documentSelectResult) => { + uri = documentSelectResult[0]; + console.info('documentViewPicker.select to file succeed and uri is:' + uri); + if (event) { + event.result.handleFileList([uri]); + } + }).catch((err: BusinessError) => { + console.error(`Invoke documentViewPicker.select failed, code is ${err.code}, message is ${err.message}`); + }) + return true; + }) + } + } +} +// [End web_file_upload] diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..be9907e29f5341089f5e24a75fbefb6b08917e44 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets @@ -0,0 +1,68 @@ +/* + * 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. + */ + +// [Start task_info_persistence_util] +import { util } from '@kit.ArkTS'; +import fileStream from '@ohos.file.fs'; + +const helper = new util.Base64Helper(); + +export const filePath = getContext().filesDir; +export const fileName = 'demoFile.txt'; +export namespace DownloadUtil { + + export function uint8ArrayToStr(uint8Array: Uint8Array): string { + return helper.encodeToStringSync(uint8Array); + } + + export function strToUint8Array(str: string): Uint8Array { + return helper.decodeSync(str); + } + + export function saveDownloadInfo(downloadInfo: string): void { + if (!fileExists(filePath)) { + mkDirectorySync(filePath); + } + + writeToFileSync(filePath, fileName, downloadInfo); + } + + export function fileExists(filePath: string): boolean { + try { + return fileStream.accessSync(filePath); + } catch (error) { + return false; + } + } + + export function mkDirectorySync(directoryPath: string, recursion?: boolean): void { + try { + fileStream.mkdirSync(directoryPath, recursion ?? false); + } catch (error) { + console.error(`mk dir error. err message: ${error.message}, err code: ${error.code}`); + } + } + + export function writeToFileSync(dir: string, fileName: string, msg: string): void { + let file = fileStream.openSync(dir + '/' + fileName, fileStream.OpenMode.WRITE_ONLY | fileStream.OpenMode.CREATE); + fileStream.writeSync(file.fd, msg); + } + + export function readFileSync(dir: string, fileName: string): string { + return fileStream.readTextSync(dir + '/' + fileName); + } + +} +// [End task_info_persistence_util] \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/module.json5 b/ArkWeb/ManageWebPageFileIO/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/module.json5 @@ -0,0 +1,71 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/color.json b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/string.json b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..883cf5800d2f788f5b396cc9fbe250677c524829 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageWebPageFileIO" + }, + { + "name": "web_path", + "value": "https://www.example.com/" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/background.png b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/foreground.png b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c163d886b69f969ad6975c6ac9fc06556384d468 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,9 @@ +{ + "src": [ + "pages/Index", + "pages/UploadFiles", + "pages/ListenForPageDown", + "pages/InitiatingADownloadTask", + "pages/ResumeDownload" + ] +} diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/en_US/element/string.json b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b22824ad2f373eba1f5d72ee7ae6cddd9f82a8f --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageWebPageFileIO" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html new file mode 100644 index 0000000000000000000000000000000000000000..79e8cc88be2c00e1a49303cd9ddffeb2e55b6c25 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html @@ -0,0 +1,21 @@ + + + + + +

download test

+ + \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..3dab642cbf493c630cec7194e2ea9c24d9dfadc8 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,21 @@ + + + + + +Download + + diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html new file mode 100644 index 0000000000000000000000000000000000000000..a02fa4eb2b9854bcea11238cd13e25bafc9e9156 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html @@ -0,0 +1,28 @@ + + + + + + + Document + + + + +
+ + + diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/zh_CN/element/string.json b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..24c323f82206183076757243cbd869c488fd30f1 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageWebPageFileIO" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/mock/mock-config.json5 b/ArkWeb/ManageWebPageFileIO/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb7966dc1b673cb46d7ead5c41419c25af4522ae --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,184 @@ +/* + * 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 UploadFiles 按钮 + * 处理前端页面文件上传的请求 + */ + it('UploadFiles', 0, async (done: Function) => { + console.info('uitest: UploadFiles begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UploadFiles')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.clickable(true).enabled(true)); + await button2.click(); + await driver.delayMs(3000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('local.html'); + + await driver.pressBack(); + await driver.delayMs(1000); + await driver.pressBack(); + await driver.delayMs(1000); + console.info('uitest: UploadFiles end'); + done(); + }); + + /* + * 点击 ListenForPageDown 按钮 + * 使用Web组件监听页面触发的下载 + */ + it('ListenForPageDown', 0, async (done: Function) => { + console.info('uitest: ListenForPageDown begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ListenForPageDown')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('setDownloadDelegate')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Download')); + await button3.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index.html'); + + const type1 = await driver.findComponent(ON.type('Text')); + let text1: string = await type1.getText(); + expect(text1).assertEqual('download finish'); + + await driver.pressBack(); + console.info('uitest: ListenForPageDown end'); + done(); + }); + + /* + * 点击 InitiatingADownloadTask 按钮 + * 使用Web组件的下载能力 + */ + it('InitiatingADownloadTask',0, async (done: Function) => { + console.info('uitest: InitiatingADownloadTask begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('InitiatingADownloadTask')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('setDownloadDelegate')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('startDownload')); + await button3.click(); + await driver.delayMs(4000); + + const type1 = await driver.findComponent(ON.type('Text')); + let text1: string = await type1.getText(); + expect(text1).assertEqual('download finish'); + + await driver.pressBack(); + console.info('uitest: InitiatingADownloadTask end'); + done(); + }); + + /* + * 点击 ResumeDownload 按钮 + * 发起一个下载,Web组件发起的下载会根据当前显示的url以及Web组件默认的Referrer Policy来计算referrer + */ + it('ResumeDownload',0, async (done: Function) => { + console.info('uitest: ResumeDownload begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ResumeDownload')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('setDownloadDelegate')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('startDownload')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('record')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.text('recovery')); + await button5.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: ResumeDownload end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/module.json5 b/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/module.json5 @@ -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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/test/List.test.ets b/ArkWeb/ManageWebPageFileIO/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/entry/src/test/LocalUnit.test.ets b/ArkWeb/ManageWebPageFileIO/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/entry/src/test/LocalUnit.test.ets @@ -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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageFileIO/hvigor/hvigor-config.json5 b/ArkWeb/ManageWebPageFileIO/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/ManageWebPageFileIO/hvigorfile.ts b/ArkWeb/ManageWebPageFileIO/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* 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. +*/ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ManageWebPageFileIO/oh-package.json5 b/ArkWeb/ManageWebPageFileIO/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/ManageWebPageFileIO/ohosTest.md b/ArkWeb/ManageWebPageFileIO/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..09391f96fdc12e8ac2491af0cc7af217d206c44b --- /dev/null +++ b/ArkWeb/ManageWebPageFileIO/ohosTest.md @@ -0,0 +1,28 @@ +#### UploadFiles + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ------------ | ------------------------------------ | -------------- | -------- | -------- | +| 上传文件 | 设备运转正常 | 应用启动成功,在主页点击选择文件按钮 | 弹出文件选择器 | Yes | Pass | + +#### ListenForPageDown + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ---------------- | ----------------------------------------- | ---------------------------- | -------- | -------- | +| 使用Web组件的下载能力 | 设备运转正常 | 应用启动成功,点击setDownloadDelegate按钮 | 定义下载委托回调 | Yes | Pass | +| download | 定义下载委托回调 | 点击下载download.html链接 | 触发下载任务,为Text组件更名 | Yes | Pass | + +#### InitiatingADownloadTask + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ---------------- | ----------------------------------------- | ---------------------------- | -------- | -------- | +| 使用Web组件的下载能力 | 设备运转正常 | 应用启动成功,点击setDownloadDelegate按钮 | 定义下载委托回调 | Yes | Pass | +| startDownload() | 定义下载委托回调 | 使用startDownload按钮 | 发起一个下载,为Text组件更名 | Yes | Pass | + +#### ResumeDownload + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ---------------- | ----------------------------------------- | -------------------------------- | -------- | -------- | +| 使用Web组件的下载能力 | 设备运转正常 | 应用启动成功,点击setDownloadDelegate按钮 | 定义下载委托回调 | Yes | Pass | +| startDownload() | 定义下载委托回调 | 使用startDownload按钮 | 发起一个下载,为Text组件更名 | Yes | Pass | +| 记录下载任务信息 | 发起一个下载 | 点击record按钮 | 将当前下载任务保存至持久化文件中 | Yes | Pass | +| 恢复下载任务 | 记录下载任务信息 | 点击recovery按钮 | 恢复下载任务 | Yes | Pass | diff --git a/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_1.png b/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_1.png new file mode 100644 index 0000000000000000000000000000000000000000..638d816041eeaa5df04c9ea8d9faed0a43c074a5 Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_1.png differ diff --git a/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_2.png b/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_2.png new file mode 100644 index 0000000000000000000000000000000000000000..1126c64170901e237ae6a5c3189b61577afea4bc Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_2.png differ diff --git a/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_1.png b/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_1.png new file mode 100644 index 0000000000000000000000000000000000000000..da6c2b942cf47810384d06a6e68975a7e32c4ccf Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_1.png differ diff --git a/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_2.png b/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_2.png new file mode 100644 index 0000000000000000000000000000000000000000..474253d8840f12efe2c581698a4a34878d3e5e03 Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_2.png differ diff --git a/ArkWeb/ManageWebPageFileIO/screenshots/ResumeDownload.png b/ArkWeb/ManageWebPageFileIO/screenshots/ResumeDownload.png new file mode 100644 index 0000000000000000000000000000000000000000..84aa81093ac4cbd3c800d30633ae81f8e96587aa Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/screenshots/ResumeDownload.png differ diff --git a/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_1.png b/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_1.png new file mode 100644 index 0000000000000000000000000000000000000000..83e3761eb2482a0bd2822c7624d49ed19e090809 Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_1.png differ diff --git a/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_2.png b/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_2.png new file mode 100644 index 0000000000000000000000000000000000000000..1fa35a07316427ee7d43b791e721d0b634d985e9 Binary files /dev/null and b/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_2.png differ diff --git a/ArkWeb/ManageWebPageInteracts/.gitignore b/ArkWeb/ManageWebPageInteracts/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/AppScope/app.json5 b/ArkWeb/ManageWebPageInteracts/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce3d05eda7baad507acf0e8de81df905cdf32d67 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "app": { + "bundleName": "com.samples.managewebpageinteracts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/element/string.json b/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..be8d935f6276f0e2833fde78d0f8320e6447b4f7 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManageWebPageInteracts" + } + ] +} diff --git a/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/media/app_icon.png b/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWeb/ManageWebPageInteracts/README.md b/ArkWeb/ManageWebPageInteracts/README.md new file mode 100644 index 0000000000000000000000000000000000000000..51b37423fe34e8e97f944b7023e4e8cd23aa1e41 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/README.md @@ -0,0 +1,151 @@ +# entry: + +## Web组件嵌套滚动 + +### 介绍 + +#### ImpNestedScroll + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-nested-scrolling.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +##### 效果预览 + +| 主页 | +| ---------------------------------------------------------- | +| | + +##### 使用说明 + +1. 设置滚动模式(前) + - 在 切换前滚动模式 区域,点击 SELF_ONLY、SELF_FIRST、PARENT_FIRST、PARALLEL 按钮,可分别将 NestedScrollModeF 设置为相应的滚动模式,此模式用于控制 Web 视图向前滚动(scrollForward)时与父组件的交互方式。 +2. 设置滚动模式(后) + - 在 切换后滚动模式 区域,同样点击上述按钮,可设置NestedScrollModeB,用于控制 Web 视图向后滚动(scrollBackward)时的交互模式。 + +## Web组件对接软键盘 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-docking-softkeyboard.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +#### SetSKBMode_one + +##### 介绍 + +1. 本示例主要介绍Web组件对接软键盘,在UIContext的键盘避让模式为Offset模式情况下,通过WebKeyboardAvoidMode()设置ArkWeb组件的键盘避让模式。 + +##### 效果预览 + +| 主页 | 软键盘 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击输入框拉起软键盘。 + +#### OnIntKbdAttachSysCustIn + +##### 介绍 + +1. 本示例主要介绍拦截系统软键盘与自定义软键盘输入,调用onInterceptKeyboardAttach来拦截系统软键盘的弹出。 + + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击未设置特殊属性的输入框,将默认使用系统默认键盘。 +2. 点击设置了keyboard-return属性的输入框,根据属性值获取对应的enterKeyType,以改变系统键盘回车键的行为。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---OnIntKbdAttachSysCustIn.ets +|---|---|---SetSKBMode_one.ets +|---|---|---ImpNestedScroll.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +### 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +## entry2: + +### SetSKBMode_two + +#### 介绍 + +1. 本示例主要介绍Web组件对接软键盘,设置UIContext的软键盘避让模式setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE),应用窗口高度可缩小避开软键盘,ArkWeb组件跟随ArkUI重新布局。 + +#### 效果预览 + +| 主页 | 软键盘 | +| ----------------------------------------------------------- | ----------------------------------------------------------- | +| | | + +使用说明 + +1. 点击输入框拉起软键盘。 + +### 工程目录 + +``` +entry2/src/main/ +|---ets +|---|---entry2ability +|---|---|---Entry2Ability.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +### 相关权限 + +无。 + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/ManageWebPageInteracts > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/build-profile.json5 b/ArkWeb/ManageWebPageInteracts/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c00db5abef42d324e414e34ba929de407db76b8a --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/build-profile.json5 @@ -0,0 +1,63 @@ +/* +* 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. +*/ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/code-linter.json5 b/ArkWeb/ManageWebPageInteracts/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/code-linter.json5 @@ -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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/.gitignore b/ArkWeb/ManageWebPageInteracts/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/build-profile.json5 b/ArkWeb/ManageWebPageInteracts/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/hvigorfile.ts b/ArkWeb/ManageWebPageInteracts/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* 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. +*/ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ManageWebPageInteracts/entry/obfuscation-rules.txt b/ArkWeb/ManageWebPageInteracts/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/oh-package.json5 b/ArkWeb/ManageWebPageInteracts/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entryability/EntryAbility.ets @@ -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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/ImpNestedScroll.ets b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/ImpNestedScroll.ets new file mode 100644 index 0000000000000000000000000000000000000000..502a4cc8780ad87d5ceff274637b369f27c1af63 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/ImpNestedScroll.ets @@ -0,0 +1,139 @@ +/* + * 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. + */ + +// [Start nested_scrolling] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct NestedScroll { + private scrollerForScroll: Scroller = new Scroller(); + controller: webview.WebviewController = new webview.WebviewController(); + controller2: webview.WebviewController = new webview.WebviewController(); + // NestedScrollMode设置成SELF_ONLY时,Web网页滚动到页面边缘后,不与父组件联动,父组件仍无法滚动。 + @State nestedScrollMode0: NestedScrollMode = NestedScrollMode.SELF_ONLY; + // NestedScrollMode设置成SELF_FIRST时,Web网页滚动到页面边缘后,父组件继续滚动。 + @State nestedScrollMode1: NestedScrollMode = NestedScrollMode.SELF_FIRST; + // NestedScrollMode设置为PARENT_FIRST时,父组件先滚动,滚动至边缘后通知Web继续滚动。 + @State nestedScrollMode2: NestedScrollMode = NestedScrollMode.PARENT_FIRST; + // NestedScrollMode设置为PARALLEL时,父组件与Web同时滚动。 + @State nestedScrollMode3: NestedScrollMode = NestedScrollMode.PARALLEL; + @State nestedScrollModeF: NestedScrollMode = NestedScrollMode.SELF_FIRST; + @State nestedScrollModeB: NestedScrollMode = NestedScrollMode.SELF_FIRST; + // scroll竖向的滚动 + @State scrollDirection: ScrollDirection = ScrollDirection.Vertical; + + build() { + Flex() { + Scroll(this.scrollerForScroll) { + Column({ space: 5 }) { + Row({}) { + Text('切换前滚动模式').fontSize(5) + Button('SELF_ONLY').onClick((event: ClickEvent) => { + this.nestedScrollModeF = this.nestedScrollMode0 + }).fontSize(5) + Button('SELF_FIRST').onClick((event: ClickEvent) => { + this.nestedScrollModeF = this.nestedScrollMode1 + }).fontSize(5) + Button('PARENT_FIRST').onClick((event: ClickEvent) => { + this.nestedScrollModeF = this.nestedScrollMode2 + }).fontSize(5) + Button('PARALLEL').onClick((event: ClickEvent) => { + this.nestedScrollModeF = this.nestedScrollMode3 + }).fontSize(5) + } + + Row({}) { + Text('切换后滚动模式').fontSize(5) + Button('SELF_ONLY').onClick((event: ClickEvent) => { + this.nestedScrollModeB = this.nestedScrollMode0 + }).fontSize(5) + Button('SELF_FIRST').onClick((event: ClickEvent) => { + this.nestedScrollModeB = this.nestedScrollMode1 + }).fontSize(5) + Button('PARENT_FIRST').onClick((event: ClickEvent) => { + this.nestedScrollModeB = this.nestedScrollMode2 + }).fontSize(5) + Button('PARALLEL').onClick((event: ClickEvent) => { + this.nestedScrollModeB = this.nestedScrollMode3 + }).fontSize(5) + } + + Text('当前内嵌前滚动模式 scrollForward ---' + `${this.nestedScrollModeF}`).fontSize(10) + Text('当前内嵌后滚动模式 scrollBackward ---' + `${this.nestedScrollModeB}`).fontSize(10) + + Text('Scroll Area') + .width('100%') + .height('10%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + Text('Scroll Area') + .width('100%') + .height('10%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + Text('Scroll Area') + .width('100%') + .height('10%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + + Web({ src: 'www.example.com', controller: this.controller }) + .nestedScroll({ + scrollForward: this.nestedScrollModeF, + scrollBackward: this.nestedScrollModeB, + }) + .height('40%') + .width('100%') + + Text('Scroll Area') + .width('100%') + .height('20%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + + Text('Scroll Area') + .width('100%') + .height('20%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + + Web({ src: 'www.example.com', controller: this.controller2 }) + .nestedScroll({ + scrollForward: this.nestedScrollModeF, + scrollBackward: this.nestedScrollModeB, + }) + .height('40%') + .width('90%') + + Text('Scroll Area') + .width('100%') + .height('20%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + + }.width('95%').border({ width: 5 }) + } + .width('100%').height('120%').border({ width: 5 }).scrollable(this.scrollDirection) + }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding(20) + } +} +// [End nested_scrolling] \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/Index.ets b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9b6f41e802970502c50ee0ea64b70bc455da97a --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,38 @@ +/* + * 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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('ImpNestedScroll') + .onClick(() => { + router.pushUrl({ url: 'pages/ImpNestedScroll' }); + }) + Button('OnIntKbdAttachSysCustIn') + .onClick(() => { + router.pushUrl({ url: 'pages/OnIntKbdAttachSysCustIn' }); + }) + Button('SetSKBMode_one') + .onClick(() => { + router.pushUrl({ url: 'pages/SetSKBMode_one' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets new file mode 100644 index 0000000000000000000000000000000000000000..ed6dd8f9d0e1e447a3f91400877713906f6e9d57 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets @@ -0,0 +1,122 @@ +/* + * 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. + */ + +// [Start soft_keyboard_web] +import { webview } from '@kit.ArkWeb'; +import { inputMethodEngine } from '@kit.IMEKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + webKeyboardController: WebKeyboardController = new WebKeyboardController(); + inputAttributeMap: Map = new Map([ + ['UNSPECIFIED', inputMethodEngine.ENTER_KEY_TYPE_UNSPECIFIED], + ['GO', inputMethodEngine.ENTER_KEY_TYPE_GO], + ['SEARCH', inputMethodEngine.ENTER_KEY_TYPE_SEARCH], + ['SEND', inputMethodEngine.ENTER_KEY_TYPE_SEND], + ['NEXT', inputMethodEngine.ENTER_KEY_TYPE_NEXT], + ['DONE', inputMethodEngine.ENTER_KEY_TYPE_DONE], + ['PREVIOUS', inputMethodEngine.ENTER_KEY_TYPE_PREVIOUS] + ]); + + /** + * 自定义键盘组件Builder + */ + @Builder + customKeyboardBuilder() { + // 这里实现自定义键盘组件,对接WebKeyboardController实现输入、删除、关闭等操作。 + Row() { + Text('finish') + .fontSize(20) + .fontColor(Color.Blue) + .onClick(() => { + this.webKeyboardController.close(); + }) + // 插入字符。 + Button('insertText').onClick(() => { + this.webKeyboardController.insertText('insert '); + }).margin({ + bottom: 200, + }); + // 从后往前删除length参数指定长度的字符。 + Button('deleteForward').onClick(() => { + this.webKeyboardController.deleteForward(1); + }).margin({ + bottom: 200, + }); + // 从前往后删除length参数指定长度的字符。 + Button('deleteBackward').onClick(() => { + this.webKeyboardController.deleteBackward(1); + }).margin({ + left: -220, + }); + // 插入功能按键。 + Button('sendFunctionKey').onClick(() => { + this.webKeyboardController.sendFunctionKey(6); + }) + } + } + + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onInterceptKeyboardAttach((keyBoardCallBackInfo) => { + // option初始化,默认使用系统默认键盘 + let option: WebKeyboardOptions = { + useSystemKeyboard: true, + }; + if (!keyBoardCallBackInfo) { + return option; + } + + // 保存WebKeyboardController,使用自定义键盘时候,需要使用该handler控制输入、删除、软键盘关闭等行为 + this.webKeyboardController = keyBoardCallBackInfo.controller; + let attributes: Record = keyBoardCallBackInfo.attributes; + // 遍历attributes + let attributeKeys = Object.keys(attributes); + for (let i = 0; i < attributeKeys.length; i++) { + console.log('WebCustomKeyboard key = ' + attributeKeys[i] + ', value = ' + attributes[attributeKeys[i]]); + } + + if (attributes) { + if (attributes['data-keyboard'] == 'customKeyboard') { + // 根据html可编辑元素的属性,判断使用不同的软键盘,例如这里如果属性包含有data-keyboard,且值为customKeyboard,则使用自定义键盘 + console.log('WebCustomKeyboard use custom keyboard'); + option.useSystemKeyboard = false; + // 设置自定义键盘builder + option.customKeyboard = () => { + this.customKeyboardBuilder(); + } + return option; + } + + if (attributes['keyboard-return'] != undefined) { + // 根据html可编辑元素的属性,判断使用不同的软键盘,例如这里如果属性包含有keyboard-return,使用系统键盘,并且指定系统软键盘enterKey类型 + option.useSystemKeyboard = true; + let enterKeyType: number | undefined = this.inputAttributeMap.get(attributes['keyboard-return']); + if (enterKeyType != undefined) { + option.enterKeyType = enterKeyType; + } + return option; + } + } + + return option; + }) + } + } +} +// [End soft_keyboard_web] \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/SetSKBMode_one.ets b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/SetSKBMode_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d04e9146f1c3eaa821bebc51a94f07561961b2c --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/SetSKBMode_one.ets @@ -0,0 +1,37 @@ +/* + * 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. + */ + +// [Start soft_keyboard_setmode] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct KeyboardAvoidExample { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Row().height('50%').width('100%').backgroundColor(Color.Gray) + Web({ src: $rawfile('SetSKBModeIndex.html'), controller: this.controller }) + .keyboardAvoidMode(WebKeyboardAvoidMode.OVERLAYS_CONTENT) //此时ArkWeb组件不会调整任何视口的大小大小 + Text('I can see the bottom of the page') + .width('100%') + .textAlign(TextAlign.Center) + .backgroundColor(Color.Pink) + .layoutWeight(1) + }.width('100%').height('100%') + } +} +// [End soft_keyboard_setmode] \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/module.json5 b/ArkWeb/ManageWebPageInteracts/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/module.json5 @@ -0,0 +1,71 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/color.json b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/string.json b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a660c237c2319d4f72e68f5c1caafb9fb065b72c --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageWebPageInteracts" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/background.png b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/foreground.png b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..08d6cd1a732e2be0fea3683042318567db9eb26f --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/ImpNestedScroll", + "pages/OnIntKbdAttachSysCustIn", + "pages/SetSKBMode_one" + ] +} diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/en_US/element/string.json b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a660c237c2319d4f72e68f5c1caafb9fb065b72c --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageWebPageInteracts" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html new file mode 100644 index 0000000000000000000000000000000000000000..61538c5f011d7b79e613fa0ff14c35ff008e246a --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html @@ -0,0 +1,25 @@ + + + + + + 测试网页 + + +

DEMO

+ + + diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..126ebbb351a2ec7d26f2c3024eb907935eb13a11 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,63 @@ + + + + + + + + + + + + +

input标签,原有默认行为:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key UNSPECIFIED:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key GO:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key SEARCH:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key SEND:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key NEXT:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key DONE:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key PREVIOUS:

+
+
+ +

input标签,应用自定义键盘:

+
+ + + + diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/zh_CN/element/string.json b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..dce1868b4c1a653b60d10f637996503b2b90d241 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageWebPageInteracts" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/mock/mock-config.json5 b/ArkWeb/ManageWebPageInteracts/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..89cfee09caf5b351f7709a00a4b92931e68ed55d --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,144 @@ +/* + * 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 ImpNestedScroll 按钮 + * 设置滚动模式 + */ + it('ImpNestedScroll', 0, async (done: Function) => { + console.info('uitest: ImpNestedScroll begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ImpNestedScroll')); + await button1.click(); + await driver.delayMs(500); + + const button2 = await driver.findComponent(ON.text('SELF_ONLY')); + await button2.click(); + await driver.delayMs(500); + + const button3 = await driver.findComponent(ON.text('SELF_FIRST')); + await button3.click(); + await driver.delayMs(500); + + const button4 = await driver.findComponent(ON.text('PARENT_FIRST')); + await button4.click(); + await driver.delayMs(500); + + const button5 = await driver.findComponent(ON.text('PARALLEL')); + await button5.click(); + await driver.delayMs(500); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: ImpNestedScroll end'); + done(); + }); + + /* + * 打开应用,点击 OnIntKbdAttachSysCustIn 按钮 + * 调用onInterceptKeyboardAttach来拦截系统软键盘的弹出 + */ + it('OnIntKbdAttachSysCustIn', 0, async (done: Function) => { + console.info('uitest: OnIntKbdAttachSysCustIn begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('OnIntKbdAttachSysCustIn')); + await button1.click(); + await driver.delayMs(1000); + + const input1 = await driver.findComponent(ON.clickable(true).enabled(true)); + await input1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index.html'); + + await driver.pressBack(); + await driver.pressBack(); + console.info('uitest: OnIntKbdAttachSysCustIn end'); + done(); + }); + + /* + * 打开应用,点击 SetSKBMode_one 按钮 + * 设置ArkWeb组件的键盘避让模式 + */ + it('SetSKBMode_one', 0, async (done: Function) => { + console.info('uitest: SetSKBMode_one begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('SetSKBMode_one')); + await button1.click(); + await driver.delayMs(2000); + + const input1 = await driver.findComponent(ON.clickable(true).enabled(true)); + await input1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('SetSKBModeIndex.html'); + + await driver.pressBack(); + console.info('uitest: SetSKBMode_one end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/module.json5 b/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/module.json5 @@ -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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/test/List.test.ets b/ArkWeb/ManageWebPageInteracts/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry/src/test/LocalUnit.test.ets b/ArkWeb/ManageWebPageInteracts/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry/src/test/LocalUnit.test.ets @@ -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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/.gitignore b/ArkWeb/ManageWebPageInteracts/entry2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/build-profile.json5 b/ArkWeb/ManageWebPageInteracts/entry2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9edfdf8c4a72db3313433e7366df25b6beb1c3a7 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/build-profile.json5 @@ -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. +*/ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/hvigorfile.ts b/ArkWeb/ManageWebPageInteracts/entry2/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* 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. +*/ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ManageWebPageInteracts/entry2/obfuscation-rules.txt b/ArkWeb/ManageWebPageInteracts/entry2/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/oh-package.json5 b/ArkWeb/ManageWebPageInteracts/entry2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2944307304532e967f4956384cc91447f2c9bf8c --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/oh-package.json5 @@ -0,0 +1,25 @@ +/* +* 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. +*/ + +{ + "name": "entry2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7cf84b7a4732e1e1512ce7602c303c116cd4fc6 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -0,0 +1,61 @@ +/* + * 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window, KeyboardAvoidMode } from '@kit.ArkUI'; + +export default class Entry2Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + // [Start soft_keyboard_entryability] + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + let keyboardAvoidMode = windowStage.getMainWindowSync().getUIContext().getKeyboardAvoidMode(); + // 设置虚拟键盘抬起时压缩页面大小为减去键盘的高度 + windowStage.getMainWindowSync().getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE); + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + // [End soft_keyboard_entryability] + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9a6b459004e1f1d0aefe9350f2c2ee907f66ff3 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets @@ -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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class Entry2BackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/pages/Index.ets b/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ac257ec08718a4fe4c8f383f07aa413a1bb8e6c3 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/pages/Index.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +// [Start soft_keyboard_index] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct KeyboardAvoidExample { + controller: webview.WebviewController = new webview.WebviewController(); + build() { + Column() { + Row().height('50%').width('100%').backgroundColor(Color.Gray) + Web({ src: $rawfile('index.html'),controller: this.controller}) + Text('I can see the bottom of the page').width('100%').textAlign(TextAlign.Center).backgroundColor(Color.Pink).layoutWeight(1) + }.width('100%').height('100%') + } +} +// [End soft_keyboard_index] \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/module.json5 b/ArkWeb/ManageWebPageInteracts/entry2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7ef3d746a37c973a35599267383dee3b96d7eddb --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/module.json5 @@ -0,0 +1,65 @@ +/* +* 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. +*/ + +{ + "module": { + "name": "entry2", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry2Ability", + "srcEntry": "./ets/entry2ability/Entry2Ability.ets", + "description": "$string:Entry2Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry2Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "Entry2BackupAbility", + "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/color.json b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/string.json b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2098765bde8417c3acfa9fd16eecdbdf37cba011 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry2Ability_desc", + "value": "description" + }, + { + "name": "Entry2Ability_label", + "value": "ManageWebPageInteracts" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/background.png b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/foreground.png b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/layered_image.json b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/startIcon.png b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/main_pages.json b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..4699c0c00f733ad2b5675eaf7e9898c61d3e0700 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html @@ -0,0 +1,25 @@ + + + + + + 测试网页 + + +

DEMO

+ + + \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/mock/mock-config.json5 b/ArkWeb/ManageWebPageInteracts/entry2/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2417dae33e86618dcf41b9c0c0f2835b30e47b34 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* +* 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. +*/ + +{ +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2fe0b328f2c2ffec62bdd561344aa5ef4911dae0 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,74 @@ +/* + * 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 UploadFiles 按钮 + * 设置UIContext的软键盘避让模式 + */ + it('TestUiExample',0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'Entry2Ability' + } + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('Entry2Ability'); + await driver.delayMs(5000); + + const input1 = await driver.findComponent(ON.clickable(true).enabled(true)); + await input1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index.html'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/List.test.ets b/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 b/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..58f59ef1464c44befe0c3035c92ad225804b072f --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* +* 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. +*/ + +{ + "module": { + "name": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/test/List.test.ets b/ArkWeb/ManageWebPageInteracts/entry2/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/entry2/src/test/LocalUnit.test.ets b/ArkWeb/ManageWebPageInteracts/entry2/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/entry2/src/test/LocalUnit.test.ets @@ -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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/ManageWebPageInteracts/hvigor/hvigor-config.json5 b/ArkWeb/ManageWebPageInteracts/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/ManageWebPageInteracts/hvigorfile.ts b/ArkWeb/ManageWebPageInteracts/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* 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. +*/ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ManageWebPageInteracts/oh-package.json5 b/ArkWeb/ManageWebPageInteracts/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/ManageWebPageInteracts/ohosTest.md b/ArkWeb/ManageWebPageInteracts/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..5e7e391d23ad1648fb318f86edf186312263fb1b --- /dev/null +++ b/ArkWeb/ManageWebPageInteracts/ohosTest.md @@ -0,0 +1,31 @@ +## entry: + +### ImpNestedScroll + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ---------------------------------------- | ------------------------------- | ------------------------------------------------------------ | -------- | -------- | +| Web组件嵌套滚动 | 设备运转正常,example.com 页面可正常访问 | 应用启动成功,点击SELF_ONLY按钮 | 当前内嵌前滚动模式 scrollForward ---NestedScrollMode.SELF_ONLY | Yes | Pass | +| 设置滚动模式(前) | 设备运转正常,example.com 页面可正常访问 | 点击SELF_FIRST按钮 | 当前内嵌前滚动模式 scrollForward ---NestedScrollMode.SELF_FIRST | Yes | Pass | +| 设置滚动模式(前) | 设备运转正常,example.com 页面可正常访问 | 点击PARENT_FIRST按钮 | 当前内嵌前滚动模式 scrollForward ---NestedScrollMode.PARENT_FIRST | Yes | Pass | +| 设置滚动模式(前) | 设备运转正常,example.com 页面可正常访问 | 点击PARALLEL 按钮 | 当前内嵌前滚动模式 scrollForward ---NestedScrollMode.PARALLEL | Yes | Pass | + +### OnIntKbdAttachSysCustIn + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------- | ------------ | ------------------------ | -------- | -------- | -------- | +| 拦截系统软键盘与自定义软键盘输入 | 设备运转正常 | 应用启动成功,点击输入框 | 弹出键盘 | Yes | Pass | + +### SetSKBMode_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ---------------------------------- | -------------------------- | -------- | -------- | +| Web组件对接软键盘 | 设备运转正常 | 应用启动成功,点击输入框拉起软键盘 | 应用窗口高度缩小避开软键盘 | Yes | Pass | + +## entry2: + +### SetSKBMode_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ---------------------------------- | -------------------------- | -------- | -------- | +| Web组件对接软键盘 | 设备运转正常 | 应用启动成功,点击输入框拉起软键盘 | 应用窗口高度缩小避开软键盘 | Yes | Pass | + diff --git a/ArkWeb/ManageWebPageInteracts/screenshots/ImpNestedScroll.png b/ArkWeb/ManageWebPageInteracts/screenshots/ImpNestedScroll.png new file mode 100644 index 0000000000000000000000000000000000000000..bfb841ff5c9ef3f4b33df5f9bf8c2fef6c20dd60 Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/screenshots/ImpNestedScroll.png differ diff --git a/ArkWeb/ManageWebPageInteracts/screenshots/OnIntKbdAttachSysCustIn.png b/ArkWeb/ManageWebPageInteracts/screenshots/OnIntKbdAttachSysCustIn.png new file mode 100644 index 0000000000000000000000000000000000000000..0bdd2dc4c67bcee1b60eb0f6d98c2ab19c74bcdb Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/screenshots/OnIntKbdAttachSysCustIn.png differ diff --git a/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_1.png b/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_1.png new file mode 100644 index 0000000000000000000000000000000000000000..435149dcebea920a056e829852f1c9906f142aa0 Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_1.png differ diff --git a/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_2.png b/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_2.png new file mode 100644 index 0000000000000000000000000000000000000000..a4056bf1dc11cc4b1fc8972ad486b0b770d2334a Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_2.png differ diff --git a/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_1.png b/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_1.png new file mode 100644 index 0000000000000000000000000000000000000000..7e7edaa392c118a336f7ecc67550a9071a640000 Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_1.png differ diff --git a/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_2.png b/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_2.png new file mode 100644 index 0000000000000000000000000000000000000000..78452f56bd471af2e1b138629e31f3f82156287a Binary files /dev/null and b/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_2.png differ