diff --git a/ArkWebKit/ManageWebPageFileIO/README.md b/ArkWebKit/ManageWebPageFileIO/README.md index 97977a08a919bea45dcd5adf479396bf64cd36ce..aa6b07807f4c84806e584283a46f0cc45fe730ed 100755 --- a/ArkWebKit/ManageWebPageFileIO/README.md +++ b/ArkWebKit/ManageWebPageFileIO/README.md @@ -113,7 +113,7 @@ entry/src/main/ ### 约束与限制 1. 本示例仅支持标准系统上运行,支持设备:RK3568。 -2. 本示例支持API14版本SDK,SDK版本号(API Version 14 Release)。 +2. 本示例支持API18版本SDK,SDK版本号(API Version 18 Release)。 3. 本示例需要使用DevEco Studio 版本号(5.0.1Release)才可编译运行。 ### 下载 diff --git a/ArkWebKit/ManageWebPageFileIO/build-profile.json5 b/ArkWebKit/ManageWebPageFileIO/build-profile.json5 index a72104fccf0572b5b409526942b4770d4a56d0db..06d60f1b912af43d1d050ff927d04650f685099e 100755 --- a/ArkWebKit/ManageWebPageFileIO/build-profile.json5 +++ b/ArkWebKit/ManageWebPageFileIO/build-profile.json5 @@ -20,8 +20,8 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.2(14)", - "targetSdkVersion": "5.0.2(14)", + "compatibleSdkVersion": "5.1.0(18)", + "targetSdkVersion": "5.1.0(18)", "runtimeOS": "HarmonyOS", } ], diff --git a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets index 0c104b48a2ba0e7c08c630b861c30a083d4bef52..d0aa82121dfa8540a6a4320f3df8e41dc6089da9 100755 --- a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets +++ b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets @@ -17,10 +17,6 @@ import { webview } from '@kit.ArkWeb'; import { BusinessError } from '@kit.BasicServicesKit'; -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - @Entry @Component struct WebComponent { @@ -35,18 +31,19 @@ struct WebComponent { .onClick(() => { try { this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { - console.log('will start a download.'); + console.info('will start a download.'); // 传入一个下载路径,并开始下载。 + // 如果传入一个不存在的路径,则会下载到默认/data/storage/el2/base/cache/web/目录。 webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); }) this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { - console.log('download update guid: ' + webDownloadItem.getGuid()); + console.info('download update guid: ' + webDownloadItem.getGuid()); }) this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { - console.log('download failed guid: ' + webDownloadItem.getGuid()); + console.error('download failed guid: ' + webDownloadItem.getGuid()); }) this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { - console.log('download finish guid: ' + webDownloadItem.getGuid()); + console.info('download finish guid: ' + webDownloadItem.getGuid()); this.myText = 'download finish'; }) this.controller.setDownloadDelegate(this.delegate); @@ -60,7 +57,7 @@ struct WebComponent { try { // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 // 开发者需要替换为自己想要下载的内容的地址。 - this.controller.startDownload(resourceToString($r('app.string.web_path'))); + this.controller.startDownload('https://www.example.com/'); } catch (error) { console.error( `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); diff --git a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets index 733a26d4b9600db7f50a41cc0b338561f1584951..592ddf49c02ee8f1405752bdf1649ae8f6dd2411 100755 --- a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets +++ b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets @@ -31,27 +31,26 @@ struct WebComponent { .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/. + console.info('will start a download.'); + // 传入一个下载路径,并开始下载。 + // 如果传入一个不存在的路径,则会下载到默认/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()); + // 下载任务的唯一标识。 + console.info('download update guid: ' + webDownloadItem.getGuid()); + // 下载的进度。 + console.info('download update percent complete: ' + webDownloadItem.getPercentComplete()); + // 当前的下载速度。 + console.info('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()); + console.error('download failed guid: ' + webDownloadItem.getGuid()); + // 下载任务失败的错误码。 + console.error('download failed last error code: ' + webDownloadItem.getLastErrorCode()); }) this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { - console.log('download finish guid: ' + webDownloadItem.getGuid()); + console.info('download finish guid: ' + webDownloadItem.getGuid()); this.myText = 'download finish'; }) this.controller.setDownloadDelegate(this.delegate); diff --git a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets index b2c4f7002135a74ccd926353c21365c0dd4abebb..d7bfe0aaf07e36efdad743a89239e289986913c7 100755 --- a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets +++ b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets @@ -18,10 +18,6 @@ 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 { @@ -31,27 +27,32 @@ struct WebComponent { // 用于记录失败的下载任务。 failedData: Uint8Array = new Uint8Array(); + aboutToAppear(): void { + DownloadUtil.init(this.getUIContext()); + } + build() { Column() { Button('setDownloadDelegate') .onClick(() => { try { this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { - console.log('will start a download.'); + console.info('will start a download.'); // 传入一个下载路径,并开始下载。 + // 如果传入一个不存在的路径,则会下载到默认/data/storage/el2/base/cache/web/目录。 webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); }) this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { - console.log('download update percent complete: ' + webDownloadItem.getPercentComplete()); + console.info('download update percent complete: ' + webDownloadItem.getPercentComplete()); this.download = webDownloadItem; }) this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { - console.log('download failed guid: ' + webDownloadItem.getGuid()); + console.error('download failed guid: ' + webDownloadItem.getGuid()); // 序列化失败的下载任务到一个字节数组。 this.failedData = webDownloadItem.serialize(); }) this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { - console.log('download finish guid: ' + webDownloadItem.getGuid()); + console.info('download finish guid: ' + webDownloadItem.getGuid()); }) this.controller.setDownloadDelegate(this.delegate); webview.WebDownloadManager.setDownloadDelegate(this.delegate); @@ -65,7 +66,7 @@ struct WebComponent { try { // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 // 开发者需要替换为自己想要下载的内容的地址。 - this.controller.startDownload(resourceToString($r('app.string.web_path'))); + this.controller.startDownload('https://www.example.com/'); } catch (error) { console.error( `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); diff --git a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets index e8f00e6dde1f97904255e39bb919a11b8bc5c605..f5e26614ec7193c00bd97c8ca7aca9b5d14d66b1 100755 --- a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets +++ b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets @@ -27,7 +27,7 @@ struct WebComponent { Column() { Web({ src: $rawfile('local.html'), controller: this.controller }) .onShowFileSelector((event) => { - console.info('MyFileUploader onShowFileSelector invoked'); + console.log('MyFileUploader onShowFileSelector invoked'); const documentSelectOptions = new picker.DocumentSelectOptions(); let uri: string | null = null; const documentViewPicker = new picker.DocumentViewPicker(); diff --git a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets index f00bbab9c0e8316aad81218c0b74d66ec93d7f06..55182d19156eae2dc770e01202879f332bd6a255 100755 --- a/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets +++ b/ArkWebKit/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets @@ -19,9 +19,13 @@ import fileStream from '@ohos.file.fs'; const helper = new util.Base64Helper(); -export const filePath = getContext().filesDir; +export let filePath : string; export const fileName = 'demoFile.txt'; export namespace DownloadUtil { + + export function init(context: UIContext): void { + filePath = context.getHostContext()!.filesDir; + } export function uint8ArrayToStr(uint8Array: Uint8Array): string { return helper.encodeToStringSync(uint8Array); diff --git a/ArkWebKit/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html b/ArkWebKit/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html index 006195d7f7e4558ccf102fbf1d1259b4ab30d172..2c5cdf6ac50dd7d8e8fe51137b31024b9078ac96 100755 --- a/ArkWebKit/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html +++ b/ArkWebKit/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html @@ -16,6 +16,11 @@ +// 点击视频右下方菜单的下载按钮会触发下载任务。 + Download diff --git a/ArkWebKit/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html b/ArkWebKit/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html index 6bc2ba391d0239e9e168e4819078fb5b6db44552..d7bb4919a5ce7d64f8c92975b6494b0d92f163fa 100755 --- a/ArkWebKit/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html +++ b/ArkWebKit/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html @@ -16,13 +16,13 @@ - - + Document -
+
+ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/.gitignore b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/.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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/app.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..9e9d3da1dc5c49dfd8ad61c60a6788ceaf10c4d5 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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.acceleratepageaccess", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..44391627e85411e07d75892e68bc02ca1ebf4c9b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AcceleratePageAccess" + } + ] +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/media/app_icon.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/README.md b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/README.md new file mode 100755 index 0000000000000000000000000000000000000000..4ab535f566d22acd2a14f701e227e4fb52915158 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/README.md @@ -0,0 +1,249 @@ +# 加速Web页面的访问 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-predictor.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### Entry: + +#### PrepareForPageLoad_one + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,可以通过prepareForPageLoad()来预解析或者预连接将要加载的页面。 + +##### 效果预览 + +| 主页 | loadDate | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 在Web组件的onAppear中对要加载的页面进行预连接。 +1. 点击超链接跳转下一界面。 +1. 点击loadData按钮返回上个界面。 + +### Entry1: + +#### PrepareForPageLoad_two + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,可以通过initializeBrowserEngine()来提前初始化内核,然后在初始化内核后调用 prepareForPageLoad()对即将要加载的页面进行预解析、预连接。 +##### 效果预览 + +| 主页 | loadDate | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. Ability的onCreate中提前初始化Web内核并对首页进行预连接。 + +### Entry2: + +#### Prefetching + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,如果能够预测到Web组件将要加载的页面或者即将要跳转的页面,可以通过prefetchPage()来预加载即将要加载页面。 + +##### 效果预览 + +| 主页 | +| -------------------------------------------------------- | +| | + +使用说明 + +1. 在onPageEnd的时候触发下一个要访问的页面的预加载。 + +#### PrefetchingAPOSTRequest_one + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,通过prefetchResource()预获取将要加载页面中的post请求。在页面加载结束时,可以通过clearPrefetchedResource()清除后续不再使用的预获取资源缓存。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 对要加载页面中的post请求进行预获取。在onPageEnd中,可以清除预获取的post请求缓存。 + +#### PrefetchingAPOSTRequest_two + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,如果能够预测到Web组件将要加载页面或者即将要跳转页面中的post请求。可以通过prefetchResource()预获取即将要加载页面的post请求。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 在onPageEnd中,触发预获取一个要访问页面的post请求。 + +#### PrefetchingAPOSTRequest_three + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,通过initializeBrowserEngine()提前初始化内核,然后在初始化内核后调用prefetchResource()预获取将要加载页面中的post请求。这种方式适合提前预获取首页的post请求。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 在Ability的onCreate中,提前初始化Web内核并预获取首页的post请求。 + +### Entry3: + +#### PrecompForCompCache + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,通过precompileJavaScript()在页面加载前提前生成脚本文件的编译缓存。 + +##### 效果预览 + +| 主页 | 加载页面 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 应用启动时EntryAbility将UIContext存到localstorage,初始化预编译Web组件生成编译缓存。 +2. 点击加载页面按钮,创建businessNode,加载业务用Web组件展示business.html页面,此时会使用之前生成的编译缓存。 + +### Entry4: + +#### InjOffResNoInt + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,可以通过injectOfflineResources()在页面加载前提前将图片、样式表或脚本资源注入到应用的内存缓存中。 + +##### 效果预览 + +| 主页 | 加载页面 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 进入Index.ets页面自动触发aboutToAppear方法。 +2. 点击加载页面按钮创建businessNode,加载业务用Web组件,展示business.html页面。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry1/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry2/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---Prefetching.ets +|---|---|---PrefetchingAPOSTRequest_one.ets +|---|---|---PrefetchingAPOSTRequest_three.ets +|---|---|---PrefetchingAPOSTRequest_two.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry3/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---BusinessWebview.ets +|---|---|---DynamicComponent.ets +|---|---|---Index.ets // 首页 +|---|---|---PrecompileConfig.ets +|---|---|---Precompile Webview.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry4/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---BusinessWebview.ets +|---|---|---DynamicComponent.ets +|---|---|---Index.ets // 首页 +|---|---|---Inject Webview.ets +|---|---|---Resource.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. 本示例仅支持标准系统上运行,支持设备:RK3568。 +2. 本示例支持API18版本SDK,SDK版本号(API Version 18 Release)。 +3. 本示例需要使用DevEco Studio 版本号(5.0.1Release)才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/build-profile.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..bd0ba62c698303281793f8f26c1257cc913fea8b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/build-profile.json5 @@ -0,0 +1,99 @@ +/* + * 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.1.0(18)", + "targetSdkVersion": "5.1.0(18)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry1", + "srcPath": "./entry1", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry3", + "srcPath": "./entry3", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry4", + "srcPath": "./entry4", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/code-linter.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/.gitignore b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/build-profile.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4d65d490ef6cbe22d933b9231555210f1555786 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/hvigorfile.ts b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/obfuscation-rules.txt b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/oh-package.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..b865efd626c466d6a334efc1e8111c6e88807a82 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..7aaec79f5a28d765725aede370d8344f3839638c --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/pages/Index.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..6bf0e4fed027a57256e805bbbeb305052bb0b4be --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/pages/Index.ets @@ -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. + */ + +import { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadData') + .onClick(() => { + if (this.webviewController.accessBackward()) { + this.webviewController.backward(); + } + }) + Web({ src: resourceToString($r('app.string.web_path_one')), controller: this.webviewController }) + .onAppear(() => { + // 指定第二个参数为true,代表要进行预连接,如果为false该接口只会对网址进行dns预解析 + // 第三个参数为要预连接socket的个数。最多允许6个。 + webview.WebviewController.prepareForPageLoad(resourceToString($r('app.string.web_path_one')), true, 2); + }) + } + } +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/module.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/color.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/string.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..65e6e287e05d404b31a376c49615635f654367cf --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AcceleratePageAccess" + }, + { + "name": "web_path", + "value": "https://www.example.com/" + }, + { + "name": "web_path_one", + "value": "https://www.example.com" + } + ] +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/background.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/foreground.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/layered_image.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/startIcon.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/main_pages.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/en_US/element/string.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/en_US/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..0838a23893a22a87feea786664077715b79cf52e --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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": "AcceleratePageAccess" + } + ] +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/zh_CN/element/string.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/zh_CN/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..5fd56f1eb0b9b271fbe3be4dc307c05d954eee7b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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": "AcceleratePageAccess" + } + ] +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/mock/mock-config.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..4387b1d1e8e1e4e55c8e53794278b34203de2801 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,78 @@ +/* + * 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. + }) + + /* + * 打开应用 + * 预解析或者预连接将要加载的页面 + */ + 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(3000); + + const clickText = await driver.findComponent(ON.type('link')); + await clickText.click(); + await driver.delayMs(3000); + + const button = await driver.findComponent(ON.type('Button')); + await button.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/List.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/module.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..9983b2ba4e55e31a172f0328c82c9a75bfa00ded --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/List.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/LocalUnit.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/.gitignore b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/build-profile.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4d65d490ef6cbe22d933b9231555210f1555786 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/hvigorfile.ts b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/obfuscation-rules.txt b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/oh-package.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..4628f905e04f04e452fa5f8f9a43e8d641e3e7e8 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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": "entry1", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.ets new file mode 100755 index 0000000000000000000000000000000000000000..4676b2677a780743b8039bb87e41fa62ae796ded --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.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 initialize_kernel_in_onCreate_and_pre_connect_to_homepage] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; + +export default class Entry1Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + console.info('EntryAbility onCreate'); + webview.WebviewController.initializeWebEngine(); + // 预连接时,需要將'https://www.example.com'替换成真实要访问的网站地址。 + + webview.WebviewController.prepareForPageLoad('https://www.example.com/', true, 2); + AppStorage.setOrCreate('abilityWant', want); + console.info('EntryAbility onCreate done'); + } + + // [StartExclude initialize_kernel_in_onCreate_and_pre_connect_to_homepage] + 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'); + } + // [EndExclude initialize_kernel_in_onCreate_and_pre_connect_to_homepage] +} +// [End initialize_kernel_in_onCreate_and_pre_connect_to_homepage] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/pages/Index.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..0c3fff9863df2bb9ab29ddb58e4b1e1a06765aee --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/pages/Index.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 previously_connect_in_onAppear_to_pages_being_loaded] +import { webview } from '@kit.ArkWeb'; +// [StartExclude previously_connect_in_onAppear_to_pages_being_loaded] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude previously_connect_in_onAppear_to_pages_being_loaded] + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadData') + .onClick(() => { + if (this.webviewController.accessBackward()) { + this.webviewController.backward(); + } + }) + Web({ src: 'https://www.example.com/', controller: this.webviewController }) + .onAppear(() => { + // 指定第二个参数为true,代表要进行预连接,如果为false该接口只会对网址进行dns预解析 + // 第三个参数为要预连接socket的个数。最多允许6个。 + webview.WebviewController.prepareForPageLoad('https://www.example.com/', true, 2); + }) + } + } +} +//[End previously_connect_in_onAppear_to_pages_being_loaded] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..465872d2309126fd7bbf697c9395c155c717a4bf --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 @@ -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. + */ + +{ + "module": { + "name": "entry1", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry1Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry1Ability", + "srcEntry": "./ets/entry1ability/Entry1Ability.ets", + "description": "$string:Entry1Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry1Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/color.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/string.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..76a37f8e3d89782b8d1c1215279ecf96c008d58e --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry1Ability_desc", + "value": "description" + }, + { + "name": "Entry1Ability_label", + "value": "AcceleratePageAccess" + }, + { + "name": "web_path", + "value": "https://www.example.com/" + }, + { + "name": "web_path_one", + "value": "https://www.example.com" + } + ] +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/background.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/background.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/foreground.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/foreground.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/layered_image.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/startIcon.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/profile/main_pages.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/mock/mock-config.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/Ability.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..92f3212a1bf7d5c1936e398fec3c79bdf642d910 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,78 @@ +/* + * 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. + }) + + /* + * 打开应用 + * 对即将要加载的页面进行预解析、预连接 + */ + it('TestUiExample', 0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'Entry1Ability' + } + 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('Entry1Ability'); + await driver.delayMs(3000); + + const clickText = await driver.findComponent(ON.type('link')); + await clickText.click(); + await driver.delayMs(5000); + + const button = await driver.findComponent(ON.type('Button')); + await button.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/List.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/module.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b463f808d133416ec65c5c4ef3f4d1dd9528e592 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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": "entry1_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/List.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/LocalUnit.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/.gitignore b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/build-profile.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4d65d490ef6cbe22d933b9231555210f1555786 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/hvigorfile.ts b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/obfuscation-rules.txt b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/oh-package.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..bcb70ff878510fb523d011c47eb563dc4edbd9ea --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100755 index 0000000000000000000000000000000000000000..cf7edaa3ca7fb433ec4145438a5c4a3791e13c31 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/entry2ability/Entry2Ability.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 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'); + } + + 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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Index.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..e330ef4623eab184383297cf399532844448f58c --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/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('Prefetching') + .onClick(() => { + router.pushUrl({ url: 'pages/Prefetching' }); + }) + Button('PrefetchingAPOSTRequest_one') + .onClick(() => { + router.pushUrl({ url: 'pages/PrefetchingAPOSTRequest_one' }); + }) + Button('PrefetchingAPOSTRequest_two') + .onClick(() => { + router.pushUrl({ url: 'pages/PrefetchingAPOSTRequest_two' }); + }) + Button('PrefetchingAPOSTRequest_three') + .onClick(() => { + router.pushUrl({ url: 'pages/PrefetchingAPOSTRequest_three' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Prefetching.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Prefetching.ets new file mode 100755 index 0000000000000000000000000000000000000000..3f6dce6a2377300913c95307bcc0db740121154d --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Prefetching.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 on_page_end_triggers_preload_of_next_page] +import { webview } from '@kit.ArkWeb'; +// [StartExclude on_page_end_triggers_preload_of_next_page] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude on_page_end_triggers_preload_of_next_page] +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: 'https://www.example.com/', controller: this.webviewController }) + .onPageEnd(() => { + // 预加载https://www.iana.org/help/example-domains。 + this.webviewController.prefetchPage('https://www.iana.org/help/example-domains'); + }) + } + } +} +// [End on_page_end_triggers_preload_of_next_page] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.ets new file mode 100755 index 0000000000000000000000000000000000000000..cae04fda9a2627df9c5ceb3f5762a8878c2f1800 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.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. + */ +//[Start prefetch_post_request_on_page_end_clear_cache] +import { webview } from '@kit.ArkWeb'; +// [StartExclude prefetch_post_request_on_page_end_clear_cache] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude prefetch_post_request_on_page_end_clear_cache] +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: 'https://www.example.com/', controller: this.webviewController }) + .onAppear(() => { + // 预获取时,需要将'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 + webview.WebviewController.prefetchResource( + { + url: 'https://www.example1.com/post?e=f&g=h', + method: 'POST', + formData: 'a=x&b=y', + }, + [{ + headerKey: 'c', + headerValue: 'z', + },], + 'KeyX', 500); + }) + .onPageEnd(() => { + // 清除后续不再使用的预获取资源缓存。 + webview.WebviewController.clearPrefetchedResource(['KeyX',]); + }) + } + } +} +//[End prefetch_post_request_on_page_end_clear_cache] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.ets new file mode 100755 index 0000000000000000000000000000000000000000..667625bc8636f1e49f5379dc9b37e6e72a386b6c --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.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 on_page_end_trigger_prefetch_post_request_access_page] +import { webview } from '@kit.ArkWeb'; +// [StartExclude on_page_end_trigger_prefetch_post_request_access_page] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude on_page_end_trigger_prefetch_post_request_access_page] +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: 'https://www.example.com/', controller: this.webviewController }) + .onPageEnd(() => { + // 预获取时,需要将'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 + webview.WebviewController.prefetchResource( + { + url: 'https://www.example1.com/post?e=f&g=h', + method: 'POST', + formData: 'a=x&b=y', + }, + [{ + headerKey: 'c', + headerValue: 'z', + },], + 'KeyX', 500); + }) + } + } +} +//[End on_page_end_trigger_prefetch_post_request_access_page] diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.ets new file mode 100755 index 0000000000000000000000000000000000000000..57f29f3c803732f6671524be801cbc1f3e055e33 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.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 initialize_kernel_in_onCreate_and_pre_fetch_post_request] +import { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.webviewController}) + .onPageEnd(() => { + // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 + webview.WebviewController.prefetchResource( + { + url: 'https://www.example1.com/post?e=f&g=h', + method: 'POST', + formData: 'a=x&b=y', + }, + [{ + headerKey: 'c', + headerValue: 'z', + },], + 'KeyX', 500); + }) + } + } +} +// [End initialize_kernel_in_onCreate_and_pre_fetch_post_request] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..fc96afe421ecc484ebbbeae15a26566355c8d18d --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 @@ -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. + */ + +{ + "module": { + "name": "entry2", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "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 + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/color.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/string.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..b363550515903b8badcdcbf12d372a6791349190 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry2Ability_desc", + "value": "description" + }, + { + "name": "Entry2Ability_label", + "value": "AcceleratePageAccess" + }, + { + "name": "web_path", + "value": "https://www.example.com/" + }, + { + "name": "domains_path", + "value": "https://www.iana.org/help/example-domains" + }, + { + "name": "post_path", + "value": "https://www.example1.com/post?e=f&g=h" + } + ] +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/background.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/background.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/foreground.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/foreground.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/layered_image.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/startIcon.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/profile/main_pages.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1c4e7fcde829651559470084dc4c22f2f3c88b58 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,9 @@ +{ + "src": [ + "pages/Index", + "pages/Prefetching", + "pages/PrefetchingAPOSTRequest_one", + "pages/PrefetchingAPOSTRequest_two", + "pages/PrefetchingAPOSTRequest_three" + ] +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/mock/mock-config.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/Ability.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..4ad971c822e74f7fa1ac058671ad091bc5bf2497 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,141 @@ +/* + * 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. + }) + + /* + * 打开应用,点击 Prefetching 按钮 + * 通过 prefetchPage 来预加载即将要加载页面 + */ + it('Prefetching', 0, async (done: Function) => { + console.info('uitest: Prefetching 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(3000); + + const button1 = await driver.findComponent(ON.text('Prefetching')); + await button1.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: Prefetching end'); + done(); + }); + + /* + * 点击 PrefetchingAPOSTRequest_one 按钮 + * 预获取将要加载页面中的post请求 + * 在页面加载结束时,清除后续不再使用的预获取资源缓存 + */ + it('PrefetchingAPOSTRequest_one', 0, async (done: Function) => { + console.info('uitest: PrefetchingAPOSTRequest_one begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('PrefetchingAPOSTRequest_one')); + await button1.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: PrefetchingAPOSTRequest_one end'); + done(); + }); + + /* + * 点击 PrefetchingAPOSTRequest_two 按钮 + * 通过 prefetchResource 预获取即将要加载页面的post请求 + */ + it('PrefetchingAPOSTRequest_two', 0, async (done: Function) => { + console.info('uitest: PrefetchingAPOSTRequest_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('PrefetchingAPOSTRequest_two')); + await button1.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: PrefetchingAPOSTRequest_two end'); + done(); + }); + + /* + * 点击 PrefetchingAPOSTRequest_three 按钮 + * 在初始化内核后调用 prefetchResource 预获取将要加载页面中的post请求 + */ + it('PrefetchingAPOSTRequest_three', 0, async (done: Function) => { + console.info('uitest: PrefetchingAPOSTRequest_three begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('PrefetchingAPOSTRequest_three')); + await button1.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: PrefetchingAPOSTRequest_three end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/List.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/module.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..87a1b504873368e9fba4674048215376b52ec579 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/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": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/List.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/LocalUnit.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/.gitignore b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/build-profile.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4d65d490ef6cbe22d933b9231555210f1555786 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/hvigorfile.ts b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/obfuscation-rules.txt b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/oh-package.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..401ea2ff2de9d5a85b272557fd72f6d8e2d9440d --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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": "entry3", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.ets new file mode 100755 index 0000000000000000000000000000000000000000..70e9ac6dedcc24d251a2b79c3925b3ea0215881c --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.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 save_the_uiContext_to_localstorage_in_entry_ability] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +// [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] +import { hilog } from '@kit.PerformanceAnalysisKit'; +// [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + +const localStorage: LocalStorage = new LocalStorage('uiContext'); + +export default class Entry3Ability extends UIAbility { + public storage: LocalStorage = localStorage; + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('pages/Index', this.storage, (err, data) => { + if (err.code) { + return; + } + + this.storage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); + }); + } + + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] +} +// [End save_the_uiContext_to_localstorage_in_entry_ability] diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.ets new file mode 100755 index 0000000000000000000000000000000000000000..b48330fdcae7fd4dbb82e646a3bbba77a1ca76c0 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.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. + */ + +// [Start write_code_for_business_components] +import { BuilderData } from './DynamicComponent'; + +@Builder +function webBuilder(data: BuilderData) { + // 此处组件可根据业务需要自行扩展 + Web({ src: data.url, controller: data.controller }) + .cacheMode(CacheMode.Default) +} + +export const businessWebview = wrapBuilder(webBuilder); +// [End write_code_for_business_components] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets new file mode 100755 index 0000000000000000000000000000000000000000..53cbadacae15b399a77832dd2835537a08a6ccae --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets @@ -0,0 +1,62 @@ +/* + * 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 underlying_code_required_for_dynamic_components] +import { NodeController, BuilderNode, FrameNode, UIContext } from '@kit.ArkUI'; + +export interface BuilderData { + url: string; + controller: WebviewController; + context: UIContext; +} + +let storage : LocalStorage | undefined = undefined; + +export class NodeControllerImpl extends NodeController { + private rootNode: BuilderNode | null = null; + private wrappedBuilder: WrappedBuilder | null = null; + + constructor(wrappedBuilder: WrappedBuilder, context: UIContext) { + storage = context.getSharedLocalStorage(); + super(); + this.wrappedBuilder = wrappedBuilder; + } + + makeNode(): FrameNode | null { + if (this.rootNode != null) { + return this.rootNode.getFrameNode(); + } + return null; + } + + initWeb(url: string, controller: WebviewController) { + if(this.rootNode != null) { + return; + } + + const uiContext: UIContext = storage!.get('uiContext') as UIContext; + if (!uiContext) { + return; + } + this.rootNode = new BuilderNode(uiContext); + this.rootNode.build(this.wrappedBuilder, { url: url, controller: controller }); + } +} + +export const createNode = (wrappedBuilder: WrappedBuilder, data: BuilderData) => { + const baseNode = new NodeControllerImpl(wrappedBuilder, data.context); + baseNode.initWeb(data.url, data.controller); + return baseNode; +} +// [End underlying_code_required_for_dynamic_components] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/Index.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..f5ee74f5333fc40a8cb6de5e7d9b88ad584525dd --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/Index.ets @@ -0,0 +1,54 @@ +/* + * 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 dynamic_webview_component_loading] +import { webview } from '@kit.ArkWeb'; +import { NodeController } from '@kit.ArkUI'; +import { createNode } from './DynamicComponent'; +import { precompileWebview } from './PrecompileWebview'; +import { businessWebview } from './BusinessWebview'; + +@Entry +@Component +struct Index { + @State precompileNode: NodeController | undefined = undefined; + precompileController: webview.WebviewController = new webview.WebviewController(); + + @State businessNode: NodeController | undefined = undefined; + businessController: webview.WebviewController = new webview.WebviewController(); + + aboutToAppear(): void { + // 初始化用于注入本地资源的Web组件 + this.precompileNode = createNode(precompileWebview, + { url: 'https://www.example.com/empty.html', controller: this.precompileController, context: this.getUIContext()}); + } + + build() { + Column() { + // 在适当的时机加载业务用Web组件,本例以Button点击触发为例 + Button('加载页面') + .onClick(() => { + this.businessNode = createNode(businessWebview, { + url: 'https://www.example.com/business.html', + controller: this.businessController, + context: this.getUIContext() + }); + }) + // 用于业务的Web组件 + NodeContainer(this.businessNode); + } + } +} +// [End dynamic_webview_component_loading] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.ets new file mode 100755 index 0000000000000000000000000000000000000000..cb63d60226a389a790b4ac11621abb67992c0571 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.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 compile_resource_allocation_information] +import { webview } from '@kit.ArkWeb' + +export interface Config { + url: string, + localPath: string, // 本地资源路径 + options: webview.CacheOptions +} + +export let configs: Config[] = [ + { + url: 'https://www.example.com/example.js', + localPath: 'example.js', + options: { + responseHeaders: [ + { headerKey: 'E-Tag', headerValue: 'aWO42N9P9dG/5xqYQCxsx+vDOoU='}, + { headerKey: 'Last-Modified', headerValue: 'Wed, 21 Mar 2025 10:38:41 GMT'} + ] + } + } +] +// [End compile_resource_allocation_information] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.ets new file mode 100755 index 0000000000000000000000000000000000000000..2e6f107ecc95d1e749457c31c0bfc563bf5b8acc --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.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. + */ + +// [Start read_local_js_resource_from_rawfile_dir_via_file_api] +import { BuilderData } from './DynamicComponent'; +import { Config, configs } from './PrecompileConfig'; + +@Builder +function webBuilder(data: BuilderData) { + Web({ src: data.url, controller: data.controller }) + .onControllerAttached(() => { + precompile(data.controller, configs, data.context); + }) + .fileAccess(true) +} + +export const precompileWebview = wrapBuilder(webBuilder); + +export const precompile = async (controller: WebviewController, configs: Array, context: UIContext) => { + for (const config of configs) { + let content = await readRawFile(config.localPath, context); + + try { + controller.precompileJavaScript(config.url, content, config.options) + .then(errCode => { + console.error('precompile successfully! ' + errCode); + }).catch((errCode: number) => { + console.error('precompile failed. ' + errCode); + }); + } catch (err) { + console.error('precompile failed. ' + err.code + ' ' + err.message); + } + } +} + +async function readRawFile(path: string, context: UIContext) { + try { + return await context.getHostContext()!.resourceManager.getRawFileContent(path); + } catch (err) { + return new Uint8Array(0); + } +} +// [End read_local_js_resource_from_rawfile_dir_via_file_api] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..db35d4bff47b7647ddc86c9ab2e4c31ae43e90e2 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 @@ -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. + */ + +{ + "module": { + "name": "entry3", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry3Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry3Ability", + "srcEntry": "./ets/entry3ability/Entry3Ability.ets", + "description": "$string:Entry3Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry3Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/color.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/string.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..6894c74192e3a04b77939f14374213985e80eedb --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry3Ability_desc", + "value": "description" + }, + { + "name": "Entry3Ability_label", + "value": "AcceleratePageAccess" + }, + { + "name": "web_path", + "value": "https://www.example.com/example.js" + }, + { + "name": "web_path_one", + "value": "https://www.example.com/" + } + ] +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/background.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/background.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/foreground.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/foreground.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/layered_image.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/startIcon.png b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/profile/main_pages.json b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/mock/mock-config.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/Ability.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..7216209578b1a72626a3341d0f398fcd2b454688 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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. + }) + + /* + * 打开应用 + * 通过 precompileJavaScript 在页面加载前提前生成脚本文件的编译缓存 + */ + it('testUiExample',0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'Entry3Ability' + }; + 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('Entry3Ability'); + await driver.delayMs(3000); + + const button = await driver.findComponent(ON.type('Button')); + await button.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/List.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/module.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..9fec93324fb8655cf1fac5683305c468a26c135e --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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": "entry3_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/List.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/LocalUnit.test.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/.gitignore b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/build-profile.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4d65d490ef6cbe22d933b9231555210f1555786 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/hvigorfile.ts b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/obfuscation-rules.txt b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/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/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/oh-package.json5 b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..0291d967fe2ab60ebdbcd4dbd691320edf31e5bf --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/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": "entry4", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.ets new file mode 100755 index 0000000000000000000000000000000000000000..24119194e26614a56f5ebdaf5863c49908c5f0fe --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.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 save_uiContext_to_localstorage_in_entry_ability] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +// [StartExclude save_uiContext_to_localstorage_in_entry_ability] +import { hilog } from '@kit.PerformanceAnalysisKit'; +// [EndExclude save_uiContext_to_localstorage_in_entry_ability] + +const localStorage: LocalStorage = new LocalStorage('uiContext'); + +export default class Entry4Ability extends UIAbility { + public storage: LocalStorage = localStorage; + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] + + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('pages/Index', this.storage, (err, data) => { + if (err.code) { + return; + } + + this.storage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); + }); + } + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] +} +// [End save_uiContext_to_localstorage_in_entry_ability] diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets new file mode 100755 index 0000000000000000000000000000000000000000..9bc8a28fae23f53fab0433556e56798f7b54b0b8 --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets @@ -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. + */ +// [Start write_code_for_business_components] +import { BuilderData } from './DynamicComponent'; + +@Builder +function webBuilder(data: BuilderData) { + // 此处组件可根据业务需要自行扩展 + Web({ src: data.url, controller: data.controller }) + .cacheMode(CacheMode.Default) +} + +export const businessWebview = wrapBuilder(webBuilder); +// [End write_code_for_business_components] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets new file mode 100755 index 0000000000000000000000000000000000000000..932907eb0be1e28c2ec0c7366c6219ab7affa99e --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets @@ -0,0 +1,62 @@ +/* + * 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 underlying_code_required_for_dynamic_components] +import { NodeController, BuilderNode, FrameNode, UIContext } from '@kit.ArkUI'; + +export interface BuilderData { + url: string; + controller: WebviewController; + context: UIContext; +} + +let storage : LocalStorage | undefined = undefined; + +export class NodeControllerImpl extends NodeController { + private rootNode: BuilderNode | null = null; + private wrappedBuilder: WrappedBuilder | null = null; + + constructor(wrappedBuilder: WrappedBuilder, context: UIContext) { + storage = context.getSharedLocalStorage(); + super(); + this.wrappedBuilder = wrappedBuilder; + } + + makeNode(): FrameNode | null { + if (this.rootNode != null) { + return this.rootNode.getFrameNode(); + } + return null; + } + + initWeb(url: string, controller: WebviewController) { + if(this.rootNode != null) { + return; + } + + const uiContext: UIContext = storage!.get('uiContext') as UIContext; + if (!uiContext) { + return; + } + this.rootNode = new BuilderNode(uiContext); + this.rootNode.build(this.wrappedBuilder, { url: url, controller: controller }); + } +} + +export const createNode = (wrappedBuilder: WrappedBuilder, data: BuilderData) => { + const baseNode = new NodeControllerImpl(wrappedBuilder, data.context); + baseNode.initWeb(data.url, data.controller); + return baseNode; +} +// [End underlying_code_required_for_dynamic_components] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Index.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..497100cfec217e2c1df651e1560e2abd258bdcbd --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Index.ets @@ -0,0 +1,54 @@ +/* + * 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 dynamic_webview_component_loading] +import { webview } from '@kit.ArkWeb'; +import { NodeController } from '@kit.ArkUI'; +import { createNode } from './DynamicComponent'; +import { injectWebview } from './InjectWebview'; +import { businessWebview } from './BusinessWebview'; + +@Entry +@Component +struct Index { + @State injectNode: NodeController | undefined = undefined; + injectController: webview.WebviewController = new webview.WebviewController(); + + @State businessNode: NodeController | undefined = undefined; + businessController: webview.WebviewController = new webview.WebviewController(); + + aboutToAppear(): void { + // 初始化用于注入本地资源的Web组件, 提供一个空的html页面作为url即可 + this.injectNode = createNode(injectWebview, + { url: 'https://www.example.com/empty.html', controller: this.injectController, context: this.getUIContext()}); + } + + build() { + Column() { + // 在适当的时机加载业务用Web组件,本例以Button点击触发为例 + Button('加载页面') + .onClick(() => { + this.businessNode = createNode(businessWebview, { + url: 'https://www.example.com/business.html', + controller: this.businessController, + context: this.getUIContext() + }); + }) + // 用于业务的Web组件 + NodeContainer(this.businessNode); + } + } +} +// [End dynamic_webview_component_loading] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.ets new file mode 100755 index 0000000000000000000000000000000000000000..7591e3cc0c123d4270f34d52ba88108ad42cd17a --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.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 local_resources_content_read_from_rawfile_directory_by_file_operation] +import { webview } from '@kit.ArkWeb'; +import { resourceConfigs } from './Resource'; +import { BuilderData } from './DynamicComponent'; + +@Builder +function webBuilder(data: BuilderData) { + Web({ src: data.url, controller: data.controller }) + .onControllerAttached(async () => { + try { + data.controller.injectOfflineResources(await getData (data.context)); + } catch (err) { + console.error('error: ' + err.code + ' ' + err.message); + } + }) + .fileAccess(true) +} + +export const injectWebview = wrapBuilder(webBuilder); + +export async function getData(context: UIContext) { + const resourceMapArr: webview.OfflineResourceMap[] = []; + + // 读取配置,从rawfile目录中读取文件内容 + for (let config of resourceConfigs) { + let buf: Uint8Array = new Uint8Array(0); + if (config.localPath) { + buf = await readRawFile(config.localPath, context); + } + + resourceMapArr.push({ + urlList: config.urlList, + resource: buf, + responseHeaders: config.responseHeaders, + type: config.type, + }) + } + + return resourceMapArr; +} + +export async function readRawFile(url: string, context: UIContext) { + try { + return await context.getHostContext()!.resourceManager.getRawFileContent(url); + } catch (err) { + return new Uint8Array(0); + } +} +// [End local_resources_content_read_from_rawfile_directory_by_file_operation] \ No newline at end of file diff --git a/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.ets b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.ets new file mode 100755 index 0000000000000000000000000000000000000000..d413840bd18c9e36964c9d2bd4db7bcd777e64ff --- /dev/null +++ b/ArkWebKit/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.ets @@ -0,0 +1,52 @@ +/* + * 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 compile_resource_allocation_information] +import { webview } from '@kit.ArkWeb'; + +export interface ResourceConfig { + urlList: Array, + type: webview.OfflineResourceType, + responseHeaders: Array
, + localPath: string, // 本地资源存放在rawfile目录下的路径 +} + +export const resourceConfigs: ResourceConfig[] = [ + { + localPath: 'example.png', + urlList: [ + 'https://www.example.com/', + 'https://www.example.com/path1/example.png', + 'https://www.example.com/path2/example.png', + ], + type: webview.OfflineResourceType.IMAGE, + responseHeaders: [ + { headerKey: 'Cache-Control', headerValue: 'max-age=1000' }, + { headerKey: 'Content-Type', headerValue: 'image/png' }, + ] + }, + { + localPath: 'example.js', + urlList: [ // 仅提供一个url,这个url既作为资源的源,也作为资源的网络请求地址 + 'https://www.example.com/example.js', + ], + type: webview.OfflineResourceType.CLASSIC_JS, + responseHeaders: [ + // 以