From 66f214f1a018352bdbd0745c8be371cf1b9e7366 Mon Sep 17 00:00:00 2001 From: sfchu Date: Fri, 28 Mar 2025 14:23:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/WebPage.ets | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/entry/src/main/ets/pages/WebPage.ets b/entry/src/main/ets/pages/WebPage.ets index 45af523..44e230b 100644 --- a/entry/src/main/ets/pages/WebPage.ets +++ b/entry/src/main/ets/pages/WebPage.ets @@ -13,33 +13,32 @@ * limitations under the License. */ -import { webview } from '@kit.ArkWeb'; import { UIContext, NodeController, BuilderNode, FrameNode } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; +import { webview } from '@kit.ArkWeb'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; class Data { public url: string = ResourceUtil.getRawFileStringByKey(getContext(this) as common.UIAbilityContext, ConfigMapKey.GALLERY_URL); public controller: WebviewController = new webview.WebviewController(); - - constructor() { - try { - // Set the whitelist to allow access to only the trust web page. - this.controller.setUrlTrustList(ConfigMapKey.GALLERY_URL); - } catch (error) { - hilog.info(0x0000, 'WebviewController', '%{public}s', - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - } } @Builder function webBuilder(data: Data) { Column() { Web({ src: data.url, controller: data.controller }) + .onControllerAttached(()=>{ + try { + // Set the whitelist to allow access to only the trust web page. + data.controller.setUrlTrustList('https://developer.huawei.com/consumer/cn/next'); + } catch (error) { + hilog.info(0x0000, 'WebviewController', '%{public}s', + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) .width($r('app.string.full_height_width')) .height($r('app.string.full_height_width')) .domStorageAccess(true) -- Gitee From c898d4cc59ea987e59ddfcb4bcfd861ab5fd028b Mon Sep 17 00:00:00 2001 From: sfchu Date: Fri, 28 Mar 2025 14:58:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E5=9F=BA=E4=BA=8E=E9=A2=84?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E6=8A=80=E6=9C=AF=E5=AE=9E=E7=8E=B0Web?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9E=AC=E5=BC=80=E6=95=88=E6=9E=9C=E3=80=91?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/common/Constants.ets | 6 ++++++ entry/src/main/ets/pages/WebPage.ets | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/common/Constants.ets b/entry/src/main/ets/common/Constants.ets index 8b29a77..093e1e2 100644 --- a/entry/src/main/ets/common/Constants.ets +++ b/entry/src/main/ets/common/Constants.ets @@ -48,4 +48,10 @@ export class Constants { * Index page padding bottom size. */ public static readonly PADDING_BOTTOM_INDEX: number = 16; + + /** + * Set the url whitelist of the current web + */ + public static readonly URL_TRUST: string = + '{\"UrlPermissionList\": [{\"scheme\": \"https\",\"host\": \"developer.huawei.com/consumer/cn/next\"}]}'; } \ No newline at end of file diff --git a/entry/src/main/ets/pages/WebPage.ets b/entry/src/main/ets/pages/WebPage.ets index 44e230b..3cb000d 100644 --- a/entry/src/main/ets/pages/WebPage.ets +++ b/entry/src/main/ets/pages/WebPage.ets @@ -19,6 +19,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; import { webview } from '@kit.ArkWeb'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; +import { Constants } from '../common/Constants'; class Data { public url: string = @@ -33,7 +34,7 @@ function webBuilder(data: Data) { .onControllerAttached(()=>{ try { // Set the whitelist to allow access to only the trust web page. - data.controller.setUrlTrustList('https://developer.huawei.com/consumer/cn/next'); + data.controller.setUrlTrustList(Constants.URL_TRUST); } catch (error) { hilog.info(0x0000, 'WebviewController', '%{public}s', `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); -- Gitee