@react-native-ohos/react-native-webview 13.10.5-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/harmony/rn_webview/BuildProfile.ets +41 -0
  4. package/harmony/rn_webview/LICENSE +21 -0
  5. package/harmony/rn_webview/NOTICE +33 -0
  6. package/harmony/rn_webview/OAT.xml +45 -0
  7. package/harmony/rn_webview/README.OpenSource +11 -0
  8. package/harmony/rn_webview/build-profile.json5 +28 -0
  9. package/harmony/rn_webview/consumer-rules.txt +0 -0
  10. package/harmony/rn_webview/hvigorfile.ts +1 -0
  11. package/harmony/rn_webview/index.ets +34 -0
  12. package/harmony/rn_webview/obfuscation-rules.txt +18 -0
  13. package/harmony/rn_webview/oh-package.json5 +13 -0
  14. package/harmony/rn_webview/src/main/cpp/CMakeLists.txt +9 -0
  15. package/harmony/rn_webview/src/main/cpp/WebViewPackage.h +37 -0
  16. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/BaseReactNativeWebviewPackage.h +95 -0
  17. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/components/RNCWebViewJSIBinder.h +126 -0
  18. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebView.cpp +20 -0
  19. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebView.h +16 -0
  20. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebViewModule.cpp +19 -0
  21. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebViewModule.h +16 -0
  22. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ComponentDescriptors.h +22 -0
  23. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/EventEmitters.cpp +240 -0
  24. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/EventEmitters.h +285 -0
  25. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/Props.cpp +151 -0
  26. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/Props.h +337 -0
  27. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ShadowNodes.cpp +19 -0
  28. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ShadowNodes.h +34 -0
  29. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/States.cpp +16 -0
  30. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/States.h +20 -0
  31. package/harmony/rn_webview/src/main/ets/CutomReference.ts +50 -0
  32. package/harmony/rn_webview/src/main/ets/Logger.ts +64 -0
  33. package/harmony/rn_webview/src/main/ets/Magic.ets +205 -0
  34. package/harmony/rn_webview/src/main/ets/RNCWebView.ets +607 -0
  35. package/harmony/rn_webview/src/main/ets/RNCWebViewPackage.ets +66 -0
  36. package/harmony/rn_webview/src/main/ets/ShouldRequestUrl.ts +68 -0
  37. package/harmony/rn_webview/src/main/ets/WebViewBaseOperate.ets +463 -0
  38. package/harmony/rn_webview/src/main/ets/WebViewTurboModule.ets +78 -0
  39. package/harmony/rn_webview/src/main/ets/generated/components/RNCWebView.ts +509 -0
  40. package/harmony/rn_webview/src/main/ets/generated/components/ts.ts +5 -0
  41. package/harmony/rn_webview/src/main/ets/generated/index.ets +5 -0
  42. package/harmony/rn_webview/src/main/ets/generated/ts.ts +6 -0
  43. package/harmony/rn_webview/src/main/ets/generated/turboModules/RNCWebView.ts +18 -0
  44. package/harmony/rn_webview/src/main/ets/generated/turboModules/RNCWebViewModule.ts +16 -0
  45. package/harmony/rn_webview/src/main/ets/generated/turboModules/ts.ts +6 -0
  46. package/harmony/rn_webview/src/main/module.json5 +11 -0
  47. package/harmony/rn_webview/src/main/resources/base/element/string.json +40 -0
  48. package/harmony/rn_webview/src/main/resources/en_US/element/string.json +40 -0
  49. package/harmony/rn_webview/src/main/resources/zh_CN/element/string.json +40 -0
  50. package/harmony/rn_webview/src/test/List.test.ets +5 -0
  51. package/harmony/rn_webview/src/test/LocalUnit.test.ets +33 -0
  52. package/harmony/rn_webview/ts.ets +29 -0
  53. package/harmony/rn_webview.har +0 -0
  54. package/package.json +107 -0
  55. package/src/NativeRNCWebView.ts +16 -0
  56. package/src/NativeRNCWebViewModule.ts +17 -0
  57. package/src/RNCWebViewNativeComponent.ts +286 -0
  58. package/src/WebView.harmony.tsx +330 -0
  59. package/src/WebView.tsx +4 -0
  60. package/src/codegenUtils.ts +9 -0
  61. package/src/index.ts +4 -0
@@ -0,0 +1,68 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { CustomReference } from './CutomReference';
26
+ import HashMap from '@ohos.util.HashMap';
27
+
28
+ export enum CallbackState {
29
+ UNDECIDED,
30
+ SHOULD_OVERRIDE,
31
+ DO_NOT_OVERRIDE,
32
+ }
33
+
34
+ export class ShouldRequestUrl {
35
+ private constructor() {
36
+ }
37
+
38
+ static nextLockIdentifier: number = 1;
39
+ static ShouldRequestUrlLocks: HashMap<string, CustomReference> = new HashMap();
40
+ static callBack: Function;
41
+
42
+ static setCallBack(lockIdentifier: string, callBack: Function): void {
43
+ let data: CustomReference = ShouldRequestUrl.ShouldRequestUrlLocks.get(lockIdentifier);
44
+ data.setCallBack(callBack)
45
+ }
46
+
47
+ public static getNewData(): string {
48
+ let lockIdentifier = ShouldRequestUrl.nextLockIdentifier++ + ''
49
+ let custom = new CustomReference(CallbackState.UNDECIDED)
50
+ ShouldRequestUrl.ShouldRequestUrlLocks.set(lockIdentifier, custom)
51
+ return lockIdentifier
52
+ }
53
+
54
+ public static setValue(lockIdentifier: number, stateParam: CallbackState): void {
55
+ let lock: string = lockIdentifier + '';
56
+ if (ShouldRequestUrl.ShouldRequestUrlLocks.hasKey(lock)) {
57
+ let data: CustomReference = ShouldRequestUrl.ShouldRequestUrlLocks.get(lock)
58
+ data.setValue(stateParam)
59
+ }
60
+ }
61
+
62
+ public static getValue(lockIdentifier: string): CallbackState {
63
+ return ShouldRequestUrl.ShouldRequestUrlLocks.get(lockIdentifier).getValue()
64
+ }
65
+ public static removeData(lockIdentifier: string): void {
66
+ ShouldRequestUrl.ShouldRequestUrlLocks.remove(lockIdentifier)
67
+ }
68
+ }
@@ -0,0 +1,463 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { RNC } from './generated/ts'
26
+ import { webview } from '@kit.ArkWeb'
27
+ import { CACHE_MODE, COMMAND_NAME, ONE_HUNDRED, WebViewEventParams } from './Magic';
28
+ import Logger from './Logger';
29
+ import { common, ConfigurationConstant } from '@kit.AbilityKit';
30
+
31
+ export const TAG = "WebView"
32
+
33
+
34
+ interface ProgressInterface {
35
+ progress: number;
36
+ }
37
+
38
+ interface CreateWebViewEventInterface {
39
+ type: string;
40
+ progress: number;
41
+ }
42
+
43
+ export class BaseOperate {
44
+ private static LOCK_IDENTIFIER = 0
45
+ private eventEmitter: RNC.RNCWebView.EventEmitter
46
+ private controller: webview.WebviewController
47
+ private lockIdentifier: number = 0
48
+
49
+ constructor(eventEmitter: RNC.RNCWebView.EventEmitter, controller: webview.WebviewController) {
50
+ this.eventEmitter = eventEmitter
51
+ this.controller = controller
52
+ this.lockIdentifier = BaseOperate.generateLockIdentifier()
53
+ }
54
+
55
+ static setThirdPartyCookiesEnabled(status: boolean) {
56
+ try {
57
+ webview.WebCookieManager.putAcceptThirdPartyCookieEnabled(status);
58
+ } catch (error) {
59
+ Logger.error(TAG, `[RNOH] setThirdPartyCookiesEnabled Errorcode: ${error.code}`);
60
+ }
61
+ }
62
+
63
+ static getColorMode(context: common.UIAbilityContext, forceDarkOn: boolean): WebDarkMode {
64
+ try {
65
+ return ((context.config.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK) && forceDarkOn) ?
66
+ WebDarkMode.On : WebDarkMode.Off
67
+ } catch (error) {
68
+ Logger.error(TAG, `[RNOH] getColorMode Errorcode: ${error.code}`);
69
+ return WebDarkMode.Off
70
+ }
71
+ }
72
+
73
+ static generateLockIdentifier(): number {
74
+ BaseOperate.LOCK_IDENTIFIER = BaseOperate.LOCK_IDENTIFIER + 1
75
+ return BaseOperate.LOCK_IDENTIFIER
76
+ }
77
+
78
+ getLockIdentifier():number {
79
+ return this.lockIdentifier
80
+ }
81
+
82
+ setLockIdentifier(lockIdentifier: number) {
83
+ this.lockIdentifier = lockIdentifier
84
+ }
85
+
86
+ emitProgressChange(params: ProgressInterface) {
87
+ try {
88
+ this.eventEmitter!.emit('loadingProgress', {
89
+ url: this.controller.getUrl(),
90
+ loading: params.progress != ONE_HUNDRED,
91
+ title: this.controller.getTitle(),
92
+ canGoBack: this.controller.accessBackward(),
93
+ canGoForward: this.controller.accessForward(),
94
+ lockIdentifier: this.lockIdentifier,
95
+ progress: params.progress / ONE_HUNDRED
96
+ })
97
+ } catch (error) {
98
+ Logger.error(TAG, `[RNOH] emitProgressChange Errorcode: ${error.code}`);
99
+ }
100
+ }
101
+
102
+ emitLoadingStart(params: ProgressInterface) {
103
+ try {
104
+ this.eventEmitter!.emit('loadingStart', {
105
+ url: this.controller.getUrl(),
106
+ loading: params.progress != ONE_HUNDRED,
107
+ title: this.controller.getTitle(),
108
+ canGoBack: this.controller.accessBackward(),
109
+ canGoForward: this.controller.accessForward(),
110
+ lockIdentifier: this.lockIdentifier,
111
+ navigationType: "other",
112
+ mainDocumentURL: ""
113
+ })
114
+ } catch (error) {
115
+ Logger.error(TAG, `[RNOH] emitLoadingStart Errorcode: ${error.code}`);
116
+ }
117
+ }
118
+
119
+ emitLoadingFinish(params: ProgressInterface) {
120
+ try {
121
+ this.eventEmitter!.emit('loadingFinish', {
122
+ url: this.controller.getUrl(),
123
+ loading: params.progress != ONE_HUNDRED,
124
+ title: this.controller.getTitle(),
125
+ canGoBack: this.controller.accessBackward(),
126
+ canGoForward: this.controller.accessForward(),
127
+ lockIdentifier: this.lockIdentifier,
128
+ navigationType: "other",
129
+ mainDocumentURL: ""
130
+ })
131
+ } catch (error) {
132
+ Logger.error(TAG, `[RNOH] emitLoadingFinish Errorcode: ${error.code}`);
133
+ }
134
+ }
135
+
136
+ emitLoadingError(event: OnErrorReceiveEvent) {
137
+ try {
138
+ if (!event.request.isMainFrame()) {
139
+ Logger.debug(TAG, "[RNOH] Not Main Frame Error");
140
+ return;
141
+ }
142
+ this.eventEmitter!.emit('loadingError', {
143
+ url: this.controller.getUrl(),
144
+ loading: false,
145
+ title: this.controller.getTitle(),
146
+ canGoBack: this.controller.accessBackward(),
147
+ canGoForward: this.controller.accessForward(),
148
+ lockIdentifier: this.lockIdentifier,
149
+ domain: "",
150
+ code: event.error.getErrorCode(),
151
+ description: event.error.getErrorInfo()
152
+ })
153
+ } catch (error) {
154
+ Logger.error(TAG, `[RNOH] emitLoadingError Errorcode: ${error.code}`);
155
+ }
156
+ }
157
+
158
+ emitHttpError(event: OnHttpErrorReceiveEvent) {
159
+ try {
160
+ this.eventEmitter!.emit('httpError', {
161
+ url: this.controller.getUrl(),
162
+ loading: false,
163
+ title: this.controller.getTitle(),
164
+ canGoBack: this.controller.accessBackward(),
165
+ canGoForward: this.controller.accessForward(),
166
+ lockIdentifier: this.lockIdentifier,
167
+ description: event.response.getResponseData(),
168
+ statusCode: event.response.getResponseCode()
169
+ })
170
+ } catch (error) {
171
+ Logger.error(TAG, `[RNOH] emitHttpError Errorcode: ${error.code}`);
172
+ }
173
+ }
174
+
175
+ emitScroll(event: OnScrollEvent) {
176
+ try {
177
+ this.eventEmitter!.emit('scroll', {
178
+ contentInset: {
179
+ bottom: 0,
180
+ left: 0,
181
+ right: 0,
182
+ top: 0
183
+ },
184
+ contentOffset: { y: event.yOffset, x: event.xOffset },
185
+ contentSize: { height: 0, width: 0 },
186
+ layoutMeasurement: { height: 0, width: 0 }
187
+ })
188
+ } catch (error) {
189
+ Logger.error(TAG, `[RNOH] emitScroll Errorcode: ${error.code}`);
190
+ }
191
+ }
192
+
193
+ emitShouldStartLoadWithRequest(event: OnLoadInterceptEvent) {
194
+ try {
195
+ this.eventEmitter!.emit('shouldStartLoadWithRequest', {
196
+ url: event.data.getRequestUrl(),
197
+ loading: false,
198
+ title: this.controller.getTitle(),
199
+ canGoBack: this.controller.accessBackward(),
200
+ canGoForward: this.controller.accessForward(),
201
+ lockIdentifier: this.lockIdentifier,
202
+ navigationType: "other",
203
+ mainDocumentURL: "",
204
+ isTopFrame: false
205
+ })
206
+ } catch (error) {
207
+ Logger.error(TAG, `[RNOH] emitShouldStartLoadWithRequest Errorcode: ${error.code}`);
208
+ }
209
+ }
210
+
211
+ emitShouldStartLoadWithRequestOverrideUrlLoading(event: WebResourceRequest) {
212
+ try {
213
+ this.eventEmitter!.emit('shouldStartLoadWithRequest', {
214
+ url: event.getRequestUrl(),
215
+ loading: false,
216
+ title: this.controller.getTitle(),
217
+ canGoBack: this.controller.accessBackward(),
218
+ canGoForward: this.controller.accessForward(),
219
+ lockIdentifier: this.lockIdentifier,
220
+ navigationType: "other",
221
+ mainDocumentURL: "",
222
+ isTopFrame: false
223
+ })
224
+ } catch (error) {
225
+ Logger.error(TAG, `[RNOH] emitShouldStartLoadWithRequest Errorcode: ${error.code}`);
226
+ }
227
+ }
228
+
229
+ transCacheMode(cacheMode: CACHE_MODE): CacheMode {
230
+ let mode = CacheMode.Default
231
+ switch (cacheMode) {
232
+ case CACHE_MODE.LOAD_DEFAULT:
233
+ mode = CacheMode.Default
234
+ break;
235
+ case CACHE_MODE.LOAD_CACHE_ELSE_NETWORK:
236
+ mode = CacheMode.None
237
+ break;
238
+ case CACHE_MODE.LOAD_NO_CACHE:
239
+ mode = CacheMode.Online
240
+ break;
241
+ case CACHE_MODE.LOAD_CACHE_ONLY:
242
+ mode = CacheMode.Only
243
+ break;
244
+ default:
245
+ break;
246
+ }
247
+ return mode
248
+ }
249
+
250
+ createWebViewEvent(param: CreateWebViewEventInterface): WebViewEventParams {
251
+ let result: WebViewEventParams = new WebViewEventParams(param.type);
252
+ result.loading = param.progress != ONE_HUNDRED
253
+ try {
254
+ result.url = this.controller.getUrl();
255
+ result.title = this.controller.getTitle();
256
+ result.canGoBack = this.controller.accessBackward();
257
+ result.canGoForward = this.controller.accessForward();
258
+ } catch (error) {
259
+ result.url = "";
260
+ result.title = "";
261
+ result.canGoBack = false;
262
+ result.canGoForward = false;
263
+ }
264
+ return result;
265
+ }
266
+
267
+ // 与OS web同事 对齐 默认false 是取消静音
268
+ ignoreSilentHardwareSwitchMethods(ignoreSilentHardwareSwitch: boolean) {
269
+ this.controller.setAudioMuted(!ignoreSilentHardwareSwitch)
270
+ }
271
+
272
+ setCustomUserAgent(customUserAgent?: string, applicationNameForUserAgent?: string): void {
273
+ try {
274
+ if (customUserAgent) {
275
+ let userAgent: string = customUserAgent;
276
+ this.controller.setCustomUserAgent(userAgent);
277
+ }
278
+ if (applicationNameForUserAgent) {
279
+ this.controller.setCustomUserAgent(`${this.controller.getUserAgent()}${applicationNameForUserAgent}`);
280
+ }
281
+ } catch (error) {
282
+ Logger.debug(TAG,
283
+ `[RNOH] setCustomUserAgent ErrorCode: ${error.code}, userAgent: ${customUserAgent}`);
284
+ }
285
+ }
286
+
287
+ injectJavaScript(args: string[]) {
288
+ try {
289
+ this.controller.runJavaScript(args[0])
290
+ } catch (error) {
291
+ Logger.error(TAG, `[RNOH] injectJavaScript Errorcode: ${error.code}`);
292
+ }
293
+ }
294
+
295
+ postMessage(args: string[]) {
296
+ let data = JSON.stringify({ data: args[0] })
297
+ let result: string = "(function () {" +
298
+ "var event;" +
299
+ "var data = " + data.toString() + ";" +
300
+ "try {" +
301
+ "event = new MessageEvent('message', data);" +
302
+ "} catch (e) {" +
303
+ "event = document.createEvent('MessageEvent');" +
304
+ "event.initMessageEvent('message', true, true, data.data, data.origin, data.lastEventId, data.source);" +
305
+ "}" +
306
+ "document.dispatchEvent(event);" +
307
+ "})();"
308
+ try {
309
+ this.controller.runJavaScript(result)
310
+ } catch (error) {
311
+ Logger.error(TAG, `[RNOH] postMessage Errorcode: ${error.code}`);
312
+ }
313
+ }
314
+
315
+ reload() {
316
+ try {
317
+ this.controller.refresh();
318
+ } catch (error) {
319
+ Logger.error(TAG, `[RNOH] reload Errorcode: ${error.code}`);
320
+ }
321
+ }
322
+
323
+ goBack() {
324
+ try {
325
+ this.controller.backward();
326
+ } catch (error) {
327
+ Logger.error(TAG, `[RNOH] goBack Errorcode: ${error.code}`);
328
+ }
329
+ }
330
+
331
+ goForward() {
332
+ try {
333
+ this.controller.forward();
334
+ } catch (error) {
335
+ Logger.error(TAG, `[RNOH] goForward Errorcode: ${error.code}`);
336
+ }
337
+ }
338
+
339
+ requestFocus() {
340
+ try {
341
+ this.controller.requestFocus();
342
+ } catch (error) {
343
+ Logger.error(TAG, `[RNOH] requestFocus Errorcode: ${error.code}`);
344
+ }
345
+ }
346
+
347
+ clearCache(args: string[]) {
348
+ try {
349
+ const removeFlag = !!args[0] === true;
350
+ this.controller.removeCache(removeFlag);
351
+ } catch (error) {
352
+ Logger.error(TAG, `[RNOH] clearCache Errorcode: ${error.code}`);
353
+ }
354
+ }
355
+
356
+ clearHistory() {
357
+ try {
358
+ this.controller.clearHistory();
359
+ } catch (error) {
360
+ Logger.error(TAG, `[RNOH] clearHistory Errorcode: ${error.code}`);
361
+ }
362
+ }
363
+
364
+ stopLoading() {
365
+ try {
366
+ this.controller.stop();
367
+ } catch (error) {
368
+ Logger.error(TAG, `[RNOH] stopLoading Errorcode: ${error.code}`);
369
+ }
370
+ }
371
+
372
+ loadUrl(args: string[]) {
373
+ try {
374
+ this.controller.loadUrl(args[0]);
375
+ } catch (error) {
376
+ Logger.error(TAG, `[RNOH] loadUrl Errorcode: ${error.code}`);
377
+ }
378
+ }
379
+
380
+ registerCommandCallback(commandName: COMMAND_NAME, args: string[]) {
381
+ switch (commandName) {
382
+ case COMMAND_NAME.INJECTJAVASCRIPT:
383
+ this.injectJavaScript(args)
384
+ break
385
+ case COMMAND_NAME.POSTMESSAGE:
386
+ this.postMessage(args)
387
+ break
388
+ case COMMAND_NAME.RELOAD:
389
+ this.reload()
390
+ break
391
+ case COMMAND_NAME.GOBACK:
392
+ this.goBack()
393
+ break
394
+ case COMMAND_NAME.GOFORWARD:
395
+ this.goForward()
396
+ break
397
+ case COMMAND_NAME.REQUESTFOCUS:
398
+ this.requestFocus()
399
+ case COMMAND_NAME.CLEARCACHE:
400
+ this.clearCache(args)
401
+ case COMMAND_NAME.CLEARHISTORY:
402
+ this.clearHistory()
403
+ break
404
+ case COMMAND_NAME.STOPLOADING:
405
+ this.stopLoading()
406
+ break
407
+ case COMMAND_NAME.LOADURL:
408
+ this.loadUrl(args)
409
+ break
410
+ default:
411
+ break
412
+ }
413
+ }
414
+
415
+ setOriginWhitelist(uris: string) {
416
+ try {
417
+ this.controller.setUrlTrustList(uris);
418
+ } catch (error) {
419
+ Logger.error(TAG, `[RNOH] setOriginWhitelist Errorcode: ${error.code}`);
420
+ }
421
+ }
422
+
423
+ setIncognito() {
424
+ this.controller.clearHistory()
425
+ webview.WebCookieManager.clearAllCookiesSync(true);
426
+ webview.WebCookieManager.clearSessionCookieSync()
427
+ webview.WebStorage.deleteAllData();
428
+ }
429
+
430
+ setFraudulentWebsiteWarningEnabled(status: boolean) {
431
+ try {
432
+ this.controller.enableSafeBrowsing(status);
433
+ } catch (error) {
434
+ Logger.error(TAG, `[RNOH] setFraudulentWebsiteWarningEnabled Errorcode: ${error.code}`);
435
+ }
436
+ }
437
+
438
+ onDownloadStart(event: OnDownloadStartEvent) {
439
+ try {
440
+ this.eventEmitter!.emit('fileDownload', {
441
+ downloadUrl: event.url
442
+ })
443
+ } catch (error) {
444
+ Logger.error(TAG, `[RNOH] onDownloadStart Errorcode: ${error.code}`);
445
+ }
446
+ }
447
+
448
+ onRenderExited(event: OnRenderExitedEvent) {
449
+ try {
450
+
451
+ } catch (error) {
452
+ Logger.error(TAG, `[RNOH] onRenderExited Errorcode: ${error.code}`);
453
+ }
454
+ }
455
+
456
+ onTitleReceive(event: OnTitleReceiveEvent) {
457
+ try {
458
+
459
+ } catch (error) {
460
+ Logger.error(TAG, `[RNOH] onTitleReceive Errorcode: ${error.code}`);
461
+ }
462
+ }
463
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { TM } from './generated/ts';
26
+ import { AnyThreadTurboModule } from '@rnoh/react-native-openharmony/ts';
27
+ import Logger from './Logger';
28
+
29
+ const TAG = "WebViewTurboModule"
30
+
31
+ export class WebViewTurboModule extends AnyThreadTurboModule implements TM.RNCWebViewModule.Spec {
32
+ private shouldStartParamsMap : Map<number,ShouldStartParams> = new Map();
33
+
34
+ isFileUploadSupported(): Promise<boolean> {
35
+ return Promise.resolve(true)
36
+ }
37
+
38
+ shouldStartLoadWithLockIdentifier(shouldStart: boolean, lockIdentifier: number): void {
39
+ Logger.debug("shouldStartLoadWithLockIdentifier:" + shouldStart + " lockIdentifier:" + lockIdentifier)
40
+ let shouldStartParams = this.shouldStartParamsMap.get(lockIdentifier)
41
+ Logger.debug("shouldStartLoadWithLockIdentifier setShouldStartParams:" + JSON.stringify(shouldStartParams))
42
+ if (shouldStartParams) {
43
+ shouldStartParams.shouldStart = shouldStart
44
+ shouldStartParams.lockState = shouldStart ? ShouldOverrideCallbackState.ALLOW_LOADING : ShouldOverrideCallbackState.SHOULD_OVERRIDE;
45
+ }
46
+ this.shouldStartParamsMap.set(lockIdentifier,shouldStartParams || new ShouldStartParams())
47
+ }
48
+
49
+
50
+ setShouldStartParams(params: ShouldStartParams){
51
+ Logger.debug("setShouldStartParams:" + JSON.stringify(params))
52
+ this.shouldStartParamsMap.set(params.lockIdentifier,params)
53
+ }
54
+ }
55
+
56
+ // 锁状态
57
+ export enum ShouldOverrideCallbackState {
58
+ /**
59
+ * 初始状态
60
+ */
61
+ UNDECIDED,
62
+ /**
63
+ * 阻止加载
64
+ */
65
+ SHOULD_OVERRIDE,
66
+ /**
67
+ * 允许加载
68
+ */
69
+ ALLOW_LOADING,
70
+ }
71
+
72
+ @Sendable
73
+ export class ShouldStartParams {
74
+ shouldStart: boolean = true
75
+ lockIdentifier: number = -1
76
+ // 对应ShouldOverrideCallbackState
77
+ lockState: number = 0
78
+ }