@react-native-ohos/react-native-webview 13.15.1-rc.1 → 13.15.1-rc.4
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.
- package/LICENSE +20 -20
- package/README.OpenSource +10 -10
- package/README.md +12 -12
- package/harmony/rn_webview/OAT.xml +44 -44
- package/harmony/rn_webview/build-profile.json5 +28 -28
- package/harmony/rn_webview/index.ets +12 -12
- package/harmony/rn_webview/oh-package.json5 +13 -13
- package/harmony/rn_webview/src/main/cpp/CMakeLists.txt +9 -9
- package/harmony/rn_webview/src/main/cpp/WebViewPackage.h +16 -16
- package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/BaseReactNativeWebviewPackage.h +95 -95
- package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/components/RNCWebViewJSIBinder.h +119 -119
- package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebView.cpp +18 -18
- package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebView.h +16 -16
- package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebViewModule.cpp +17 -17
- package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebViewModule.h +16 -16
- package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ComponentDescriptors.h +24 -24
- package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/EventEmitters.cpp +241 -241
- package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/EventEmitters.h +263 -263
- package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/Props.cpp +103 -103
- package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/Props.h +509 -509
- package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ShadowNodes.cpp +17 -17
- package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ShadowNodes.h +32 -32
- package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/States.cpp +16 -16
- package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/States.h +28 -28
- package/harmony/rn_webview/src/main/ets/CutomReference.ts +29 -29
- package/harmony/rn_webview/src/main/ets/Logger.ts +43 -43
- package/harmony/rn_webview/src/main/ets/Magic.ets +184 -184
- package/harmony/rn_webview/src/main/ets/RNCWebView.ets +645 -570
- package/harmony/rn_webview/src/main/ets/RNCWebViewPackage.ets +37 -37
- package/harmony/rn_webview/src/main/ets/ShouldRequestUrl.ts +47 -47
- package/harmony/rn_webview/src/main/ets/WebViewBaseOperate.ets +457 -443
- package/harmony/rn_webview/src/main/ets/WebViewTurboModule.ets +57 -57
- package/harmony/rn_webview/src/main/ets/generated/components/RNCWebView.ts +524 -524
- package/harmony/rn_webview/src/main/ets/generated/components/ts.ts +5 -5
- package/harmony/rn_webview/src/main/ets/generated/index.ets +5 -5
- package/harmony/rn_webview/src/main/ets/generated/ts.ts +6 -6
- package/harmony/rn_webview/src/main/ets/generated/turboModules/RNCWebView.ts +18 -18
- package/harmony/rn_webview/src/main/ets/generated/turboModules/RNCWebViewModule.ts +16 -16
- package/harmony/rn_webview/src/main/ets/generated/turboModules/ts.ts +6 -6
- package/harmony/rn_webview/src/main/module.json5 +10 -10
- package/harmony/rn_webview/src/main/resources/base/element/string.json +39 -39
- package/harmony/rn_webview/src/main/resources/en_US/element/string.json +39 -39
- package/harmony/rn_webview/src/main/resources/zh_CN/element/string.json +39 -39
- package/harmony/rn_webview/src/test/List.test.ets +4 -4
- package/harmony/rn_webview/src/test/LocalUnit.test.ets +32 -32
- package/harmony/rn_webview/ts.ets +8 -8
- package/harmony/rn_webview.har +0 -0
- package/package.json +99 -99
- package/src/NativeRNCWebView.ts +21 -21
- package/src/NativeRNCWebViewModule.ts +19 -19
- package/src/RNCWebViewNativeComponent.ts +354 -354
- package/src/WebView.harmony.tsx +342 -342
- package/src/WebView.tsx +10 -10
- package/src/codegenUtils.ts +10 -10
- package/src/index.ts +10 -10
- package/harmony/rn_webview/BuildProfile.ets +0 -17
|
@@ -1,443 +1,457 @@
|
|
|
1
|
-
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
-
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
-
// found in the LICENSE file.
|
|
4
|
-
|
|
5
|
-
import { RNC } from './generated/ts'
|
|
6
|
-
import { webview } from '@kit.ArkWeb'
|
|
7
|
-
import { CACHE_MODE, COMMAND_NAME, ONE_HUNDRED, WebViewEventParams } from './Magic';
|
|
8
|
-
import Logger from './Logger';
|
|
9
|
-
import { common, ConfigurationConstant } from '@kit.AbilityKit';
|
|
10
|
-
|
|
11
|
-
export const TAG = "WebView"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
interface ProgressInterface {
|
|
15
|
-
progress: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface CreateWebViewEventInterface {
|
|
19
|
-
type: string;
|
|
20
|
-
progress: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class BaseOperate {
|
|
24
|
-
private static LOCK_IDENTIFIER = 0
|
|
25
|
-
private eventEmitter: RNC.RNCWebView.EventEmitter
|
|
26
|
-
private controller: webview.WebviewController
|
|
27
|
-
private lockIdentifier: number = 0
|
|
28
|
-
|
|
29
|
-
constructor(eventEmitter: RNC.RNCWebView.EventEmitter, controller: webview.WebviewController) {
|
|
30
|
-
this.eventEmitter = eventEmitter
|
|
31
|
-
this.controller = controller
|
|
32
|
-
this.lockIdentifier = BaseOperate.generateLockIdentifier()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static setThirdPartyCookiesEnabled(status: boolean) {
|
|
36
|
-
try {
|
|
37
|
-
webview.WebCookieManager.putAcceptThirdPartyCookieEnabled(status);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
Logger.error(TAG, `[RNOH] setThirdPartyCookiesEnabled Errorcode: ${error.code}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static getColorMode(context: common.UIAbilityContext, forceDarkOn: boolean): WebDarkMode {
|
|
44
|
-
try {
|
|
45
|
-
return ((context.config.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK) && forceDarkOn) ?
|
|
46
|
-
WebDarkMode.On : WebDarkMode.Off
|
|
47
|
-
} catch (error) {
|
|
48
|
-
Logger.error(TAG, `[RNOH] getColorMode Errorcode: ${error.code}`);
|
|
49
|
-
return WebDarkMode.Off
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static generateLockIdentifier(): number {
|
|
54
|
-
BaseOperate.LOCK_IDENTIFIER = BaseOperate.LOCK_IDENTIFIER + 1
|
|
55
|
-
return BaseOperate.LOCK_IDENTIFIER
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
getLockIdentifier():number {
|
|
59
|
-
return this.lockIdentifier
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
setLockIdentifier(lockIdentifier: number) {
|
|
63
|
-
this.lockIdentifier = lockIdentifier
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
emitProgressChange(params: ProgressInterface) {
|
|
67
|
-
try {
|
|
68
|
-
this.eventEmitter!.emit('loadingProgress', {
|
|
69
|
-
url: this.controller.getUrl(),
|
|
70
|
-
loading: params.progress != ONE_HUNDRED,
|
|
71
|
-
title: this.controller.getTitle(),
|
|
72
|
-
canGoBack: this.controller.accessBackward(),
|
|
73
|
-
canGoForward: this.controller.accessForward(),
|
|
74
|
-
lockIdentifier: this.lockIdentifier,
|
|
75
|
-
progress: params.progress / ONE_HUNDRED
|
|
76
|
-
})
|
|
77
|
-
} catch (error) {
|
|
78
|
-
Logger.error(TAG, `[RNOH] emitProgressChange Errorcode: ${error.code}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
emitLoadingStart(params: ProgressInterface) {
|
|
83
|
-
try {
|
|
84
|
-
this.eventEmitter!.emit('loadingStart', {
|
|
85
|
-
url: this.controller.getUrl(),
|
|
86
|
-
loading: params.progress != ONE_HUNDRED,
|
|
87
|
-
title: this.controller.getTitle(),
|
|
88
|
-
canGoBack: this.controller.accessBackward(),
|
|
89
|
-
canGoForward: this.controller.accessForward(),
|
|
90
|
-
lockIdentifier: this.lockIdentifier,
|
|
91
|
-
navigationType: "other",
|
|
92
|
-
mainDocumentURL: ""
|
|
93
|
-
})
|
|
94
|
-
} catch (error) {
|
|
95
|
-
Logger.error(TAG, `[RNOH] emitLoadingStart Errorcode: ${error.code}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
emitLoadingFinish(params: ProgressInterface) {
|
|
100
|
-
try {
|
|
101
|
-
this.eventEmitter!.emit('loadingFinish', {
|
|
102
|
-
url: this.controller.getUrl(),
|
|
103
|
-
loading: params.progress != ONE_HUNDRED,
|
|
104
|
-
title: this.controller.getTitle(),
|
|
105
|
-
canGoBack: this.controller.accessBackward(),
|
|
106
|
-
canGoForward: this.controller.accessForward(),
|
|
107
|
-
lockIdentifier: this.lockIdentifier,
|
|
108
|
-
navigationType: "other",
|
|
109
|
-
mainDocumentURL: ""
|
|
110
|
-
})
|
|
111
|
-
} catch (error) {
|
|
112
|
-
Logger.error(TAG, `[RNOH] emitLoadingFinish Errorcode: ${error.code}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
emitLoadingError(event: OnErrorReceiveEvent) {
|
|
117
|
-
try {
|
|
118
|
-
if (!event.request.isMainFrame()) {
|
|
119
|
-
Logger.debug(TAG, "[RNOH] Not Main Frame Error");
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
this.eventEmitter!.emit('loadingError', {
|
|
123
|
-
url: this.controller.getUrl(),
|
|
124
|
-
loading: false,
|
|
125
|
-
title: this.controller.getTitle(),
|
|
126
|
-
canGoBack: this.controller.accessBackward(),
|
|
127
|
-
canGoForward: this.controller.accessForward(),
|
|
128
|
-
lockIdentifier: this.lockIdentifier,
|
|
129
|
-
domain: "",
|
|
130
|
-
code: event.error.getErrorCode(),
|
|
131
|
-
description: event.error.getErrorInfo()
|
|
132
|
-
})
|
|
133
|
-
} catch (error) {
|
|
134
|
-
Logger.error(TAG, `[RNOH] emitLoadingError Errorcode: ${error.code}`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
emitHttpError(event: OnHttpErrorReceiveEvent) {
|
|
139
|
-
try {
|
|
140
|
-
this.eventEmitter!.emit('httpError', {
|
|
141
|
-
url: this.controller.getUrl(),
|
|
142
|
-
loading: false,
|
|
143
|
-
title: this.controller.getTitle(),
|
|
144
|
-
canGoBack: this.controller.accessBackward(),
|
|
145
|
-
canGoForward: this.controller.accessForward(),
|
|
146
|
-
lockIdentifier: this.lockIdentifier,
|
|
147
|
-
description: event.response.getResponseData(),
|
|
148
|
-
statusCode: event.response.getResponseCode()
|
|
149
|
-
})
|
|
150
|
-
} catch (error) {
|
|
151
|
-
Logger.error(TAG, `[RNOH] emitHttpError Errorcode: ${error.code}`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
emitScroll(event: OnScrollEvent) {
|
|
156
|
-
try {
|
|
157
|
-
this.eventEmitter!.emit('scroll', {
|
|
158
|
-
contentInset: {
|
|
159
|
-
bottom: 0,
|
|
160
|
-
left: 0,
|
|
161
|
-
right: 0,
|
|
162
|
-
top: 0
|
|
163
|
-
},
|
|
164
|
-
contentOffset: { y: event.yOffset, x: event.xOffset },
|
|
165
|
-
contentSize: { height: 0, width: 0 },
|
|
166
|
-
layoutMeasurement: { height: 0, width: 0 }
|
|
167
|
-
})
|
|
168
|
-
} catch (error) {
|
|
169
|
-
Logger.error(TAG, `[RNOH] emitScroll Errorcode: ${error.code}`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
case COMMAND_NAME.
|
|
380
|
-
this.
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import { RNC } from './generated/ts'
|
|
6
|
+
import { webview } from '@kit.ArkWeb'
|
|
7
|
+
import { CACHE_MODE, COMMAND_NAME, ONE_HUNDRED, WebViewEventParams } from './Magic';
|
|
8
|
+
import Logger from './Logger';
|
|
9
|
+
import { common, ConfigurationConstant } from '@kit.AbilityKit';
|
|
10
|
+
|
|
11
|
+
export const TAG = "WebView"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
interface ProgressInterface {
|
|
15
|
+
progress: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface CreateWebViewEventInterface {
|
|
19
|
+
type: string;
|
|
20
|
+
progress: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class BaseOperate {
|
|
24
|
+
private static LOCK_IDENTIFIER = 0
|
|
25
|
+
private eventEmitter: RNC.RNCWebView.EventEmitter
|
|
26
|
+
private controller: webview.WebviewController
|
|
27
|
+
private lockIdentifier: number = 0
|
|
28
|
+
|
|
29
|
+
constructor(eventEmitter: RNC.RNCWebView.EventEmitter, controller: webview.WebviewController) {
|
|
30
|
+
this.eventEmitter = eventEmitter
|
|
31
|
+
this.controller = controller
|
|
32
|
+
this.lockIdentifier = BaseOperate.generateLockIdentifier()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static setThirdPartyCookiesEnabled(status: boolean) {
|
|
36
|
+
try {
|
|
37
|
+
webview.WebCookieManager.putAcceptThirdPartyCookieEnabled(status);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
Logger.error(TAG, `[RNOH] setThirdPartyCookiesEnabled Errorcode: ${error.code}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static getColorMode(context: common.UIAbilityContext, forceDarkOn: boolean): WebDarkMode {
|
|
44
|
+
try {
|
|
45
|
+
return ((context.config.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK) && forceDarkOn) ?
|
|
46
|
+
WebDarkMode.On : WebDarkMode.Off
|
|
47
|
+
} catch (error) {
|
|
48
|
+
Logger.error(TAG, `[RNOH] getColorMode Errorcode: ${error.code}`);
|
|
49
|
+
return WebDarkMode.Off
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static generateLockIdentifier(): number {
|
|
54
|
+
BaseOperate.LOCK_IDENTIFIER = BaseOperate.LOCK_IDENTIFIER + 1
|
|
55
|
+
return BaseOperate.LOCK_IDENTIFIER
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getLockIdentifier():number {
|
|
59
|
+
return this.lockIdentifier
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setLockIdentifier(lockIdentifier: number) {
|
|
63
|
+
this.lockIdentifier = lockIdentifier
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
emitProgressChange(params: ProgressInterface) {
|
|
67
|
+
try {
|
|
68
|
+
this.eventEmitter!.emit('loadingProgress', {
|
|
69
|
+
url: this.controller.getUrl(),
|
|
70
|
+
loading: params.progress != ONE_HUNDRED,
|
|
71
|
+
title: this.controller.getTitle(),
|
|
72
|
+
canGoBack: this.controller.accessBackward(),
|
|
73
|
+
canGoForward: this.controller.accessForward(),
|
|
74
|
+
lockIdentifier: this.lockIdentifier,
|
|
75
|
+
progress: params.progress / ONE_HUNDRED
|
|
76
|
+
})
|
|
77
|
+
} catch (error) {
|
|
78
|
+
Logger.error(TAG, `[RNOH] emitProgressChange Errorcode: ${error.code}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
emitLoadingStart(params: ProgressInterface) {
|
|
83
|
+
try {
|
|
84
|
+
this.eventEmitter!.emit('loadingStart', {
|
|
85
|
+
url: this.controller.getUrl(),
|
|
86
|
+
loading: params.progress != ONE_HUNDRED,
|
|
87
|
+
title: this.controller.getTitle(),
|
|
88
|
+
canGoBack: this.controller.accessBackward(),
|
|
89
|
+
canGoForward: this.controller.accessForward(),
|
|
90
|
+
lockIdentifier: this.lockIdentifier,
|
|
91
|
+
navigationType: "other",
|
|
92
|
+
mainDocumentURL: ""
|
|
93
|
+
})
|
|
94
|
+
} catch (error) {
|
|
95
|
+
Logger.error(TAG, `[RNOH] emitLoadingStart Errorcode: ${error.code}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
emitLoadingFinish(params: ProgressInterface) {
|
|
100
|
+
try {
|
|
101
|
+
this.eventEmitter!.emit('loadingFinish', {
|
|
102
|
+
url: this.controller.getUrl(),
|
|
103
|
+
loading: params.progress != ONE_HUNDRED,
|
|
104
|
+
title: this.controller.getTitle(),
|
|
105
|
+
canGoBack: this.controller.accessBackward(),
|
|
106
|
+
canGoForward: this.controller.accessForward(),
|
|
107
|
+
lockIdentifier: this.lockIdentifier,
|
|
108
|
+
navigationType: "other",
|
|
109
|
+
mainDocumentURL: ""
|
|
110
|
+
})
|
|
111
|
+
} catch (error) {
|
|
112
|
+
Logger.error(TAG, `[RNOH] emitLoadingFinish Errorcode: ${error.code}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
emitLoadingError(event: OnErrorReceiveEvent) {
|
|
117
|
+
try {
|
|
118
|
+
if (!event.request.isMainFrame()) {
|
|
119
|
+
Logger.debug(TAG, "[RNOH] Not Main Frame Error");
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this.eventEmitter!.emit('loadingError', {
|
|
123
|
+
url: this.controller.getUrl(),
|
|
124
|
+
loading: false,
|
|
125
|
+
title: this.controller.getTitle(),
|
|
126
|
+
canGoBack: this.controller.accessBackward(),
|
|
127
|
+
canGoForward: this.controller.accessForward(),
|
|
128
|
+
lockIdentifier: this.lockIdentifier,
|
|
129
|
+
domain: "",
|
|
130
|
+
code: event.error.getErrorCode(),
|
|
131
|
+
description: event.error.getErrorInfo()
|
|
132
|
+
})
|
|
133
|
+
} catch (error) {
|
|
134
|
+
Logger.error(TAG, `[RNOH] emitLoadingError Errorcode: ${error.code}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
emitHttpError(event: OnHttpErrorReceiveEvent) {
|
|
139
|
+
try {
|
|
140
|
+
this.eventEmitter!.emit('httpError', {
|
|
141
|
+
url: this.controller.getUrl(),
|
|
142
|
+
loading: false,
|
|
143
|
+
title: this.controller.getTitle(),
|
|
144
|
+
canGoBack: this.controller.accessBackward(),
|
|
145
|
+
canGoForward: this.controller.accessForward(),
|
|
146
|
+
lockIdentifier: this.lockIdentifier,
|
|
147
|
+
description: event.response.getResponseData(),
|
|
148
|
+
statusCode: event.response.getResponseCode()
|
|
149
|
+
})
|
|
150
|
+
} catch (error) {
|
|
151
|
+
Logger.error(TAG, `[RNOH] emitHttpError Errorcode: ${error.code}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
emitScroll(event: OnScrollEvent) {
|
|
156
|
+
try {
|
|
157
|
+
this.eventEmitter!.emit('scroll', {
|
|
158
|
+
contentInset: {
|
|
159
|
+
bottom: 0,
|
|
160
|
+
left: 0,
|
|
161
|
+
right: 0,
|
|
162
|
+
top: 0
|
|
163
|
+
},
|
|
164
|
+
contentOffset: { y: event.yOffset, x: event.xOffset },
|
|
165
|
+
contentSize: { height: 0, width: 0 },
|
|
166
|
+
layoutMeasurement: { height: 0, width: 0 }
|
|
167
|
+
})
|
|
168
|
+
} catch (error) {
|
|
169
|
+
Logger.error(TAG, `[RNOH] emitScroll Errorcode: ${error.code}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
verifyURLFormat(url: string, html: string | undefined, baseUrl: string | undefined) {
|
|
174
|
+
const dataUrlPattern = /^data:text\/html;/;
|
|
175
|
+
if (dataUrlPattern.test(url)){
|
|
176
|
+
if (html != undefined && html != "") {
|
|
177
|
+
if (baseUrl != undefined && baseUrl != "") {
|
|
178
|
+
url = baseUrl.toLowerCase();
|
|
179
|
+
} else {
|
|
180
|
+
url = 'about:blank';
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return url;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
emitShouldStartLoadWithRequest(event: OnLoadInterceptEvent, html: string | undefined, baseUrl: string | undefined) {
|
|
188
|
+
try {
|
|
189
|
+
this.eventEmitter!.emit('shouldStartLoadWithRequest', {
|
|
190
|
+
url: this.verifyURLFormat(event.data.getRequestUrl(), html, baseUrl),
|
|
191
|
+
loading: false,
|
|
192
|
+
title: this.controller.getTitle(),
|
|
193
|
+
canGoBack: this.controller.accessBackward(),
|
|
194
|
+
canGoForward: this.controller.accessForward(),
|
|
195
|
+
lockIdentifier: this.lockIdentifier,
|
|
196
|
+
navigationType: "other",
|
|
197
|
+
mainDocumentURL: "",
|
|
198
|
+
isTopFrame: false
|
|
199
|
+
})
|
|
200
|
+
} catch (error) {
|
|
201
|
+
Logger.error(TAG, `[RNOH] emitShouldStartLoadWithRequest Errorcode: ${error.code}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
emitShouldStartLoadWithRequestOverrideUrlLoading(event: WebResourceRequest) {
|
|
206
|
+
try {
|
|
207
|
+
this.eventEmitter!.emit('shouldStartLoadWithRequest', {
|
|
208
|
+
url: event.getRequestUrl(),
|
|
209
|
+
loading: false,
|
|
210
|
+
title: this.controller.getTitle(),
|
|
211
|
+
canGoBack: this.controller.accessBackward(),
|
|
212
|
+
canGoForward: this.controller.accessForward(),
|
|
213
|
+
lockIdentifier: this.lockIdentifier,
|
|
214
|
+
navigationType: "other",
|
|
215
|
+
mainDocumentURL: "",
|
|
216
|
+
isTopFrame: false
|
|
217
|
+
})
|
|
218
|
+
} catch (error) {
|
|
219
|
+
Logger.error(TAG, `[RNOH] emitShouldStartLoadWithRequest Errorcode: ${error.code}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
transCacheMode(cacheMode: CACHE_MODE): CacheMode {
|
|
224
|
+
let mode = CacheMode.Default
|
|
225
|
+
switch (cacheMode) {
|
|
226
|
+
case CACHE_MODE.LOAD_DEFAULT:
|
|
227
|
+
mode = CacheMode.Default
|
|
228
|
+
break;
|
|
229
|
+
case CACHE_MODE.LOAD_CACHE_ELSE_NETWORK:
|
|
230
|
+
mode = CacheMode.None
|
|
231
|
+
break;
|
|
232
|
+
case CACHE_MODE.LOAD_NO_CACHE:
|
|
233
|
+
mode = CacheMode.Online
|
|
234
|
+
break;
|
|
235
|
+
case CACHE_MODE.LOAD_CACHE_ONLY:
|
|
236
|
+
mode = CacheMode.Only
|
|
237
|
+
break;
|
|
238
|
+
default:
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
return mode
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
createWebViewEvent(param: CreateWebViewEventInterface): WebViewEventParams {
|
|
245
|
+
let result: WebViewEventParams = new WebViewEventParams(param.type);
|
|
246
|
+
result.loading = param.progress != ONE_HUNDRED
|
|
247
|
+
try {
|
|
248
|
+
result.url = this.controller.getUrl();
|
|
249
|
+
result.title = this.controller.getTitle();
|
|
250
|
+
result.canGoBack = this.controller.accessBackward();
|
|
251
|
+
result.canGoForward = this.controller.accessForward();
|
|
252
|
+
} catch (error) {
|
|
253
|
+
result.url = "";
|
|
254
|
+
result.title = "";
|
|
255
|
+
result.canGoBack = false;
|
|
256
|
+
result.canGoForward = false;
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// 与OS web同事 对齐 默认false 是取消静音
|
|
262
|
+
ignoreSilentHardwareSwitchMethods(ignoreSilentHardwareSwitch: boolean) {
|
|
263
|
+
this.controller.setAudioMuted(!ignoreSilentHardwareSwitch)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
setCustomUserAgent(customUserAgent?: string, applicationNameForUserAgent?: string): void {
|
|
267
|
+
try {
|
|
268
|
+
if (customUserAgent) {
|
|
269
|
+
let userAgent: string = customUserAgent;
|
|
270
|
+
this.controller.setCustomUserAgent(userAgent);
|
|
271
|
+
}
|
|
272
|
+
if (applicationNameForUserAgent) {
|
|
273
|
+
this.controller.setCustomUserAgent(`${this.controller.getUserAgent()}${applicationNameForUserAgent}`);
|
|
274
|
+
}
|
|
275
|
+
} catch (error) {
|
|
276
|
+
Logger.debug(TAG,
|
|
277
|
+
`[RNOH] setCustomUserAgent ErrorCode: ${error.code}, userAgent: ${customUserAgent}`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
injectJavaScript(args: string[]) {
|
|
282
|
+
try {
|
|
283
|
+
this.controller.runJavaScript(args[0])
|
|
284
|
+
} catch (error) {
|
|
285
|
+
Logger.error(TAG, `[RNOH] injectJavaScript Errorcode: ${error.code}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
postMessage(args: string[]) {
|
|
290
|
+
let data = JSON.stringify({ data: args[0] })
|
|
291
|
+
let result: string = "(function () {" +
|
|
292
|
+
"var event;" +
|
|
293
|
+
"var data = " + data.toString() + ";" +
|
|
294
|
+
"try {" +
|
|
295
|
+
"event = new MessageEvent('message', data);" +
|
|
296
|
+
"} catch (e) {" +
|
|
297
|
+
"event = document.createEvent('MessageEvent');" +
|
|
298
|
+
"event.initMessageEvent('message', true, true, data.data, data.origin, data.lastEventId, data.source);" +
|
|
299
|
+
"}" +
|
|
300
|
+
"document.dispatchEvent(event);" +
|
|
301
|
+
"})();"
|
|
302
|
+
try {
|
|
303
|
+
this.controller.runJavaScript(result)
|
|
304
|
+
} catch (error) {
|
|
305
|
+
Logger.error(TAG, `[RNOH] postMessage Errorcode: ${error.code}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
reload() {
|
|
310
|
+
try {
|
|
311
|
+
this.controller.refresh();
|
|
312
|
+
} catch (error) {
|
|
313
|
+
Logger.error(TAG, `[RNOH] reload Errorcode: ${error.code}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
goBack() {
|
|
318
|
+
try {
|
|
319
|
+
this.controller.backward();
|
|
320
|
+
} catch (error) {
|
|
321
|
+
Logger.error(TAG, `[RNOH] goBack Errorcode: ${error.code}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
goForward() {
|
|
326
|
+
try {
|
|
327
|
+
this.controller.forward();
|
|
328
|
+
} catch (error) {
|
|
329
|
+
Logger.error(TAG, `[RNOH] goForward Errorcode: ${error.code}`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
requestFocus() {
|
|
334
|
+
try {
|
|
335
|
+
this.controller.requestFocus();
|
|
336
|
+
} catch (error) {
|
|
337
|
+
Logger.error(TAG, `[RNOH] requestFocus Errorcode: ${error.code}`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
clearCache(args: string[]) {
|
|
342
|
+
try {
|
|
343
|
+
const removeFlag = !!args[0] === true;
|
|
344
|
+
this.controller.removeCache(removeFlag);
|
|
345
|
+
} catch (error) {
|
|
346
|
+
Logger.error(TAG, `[RNOH] clearCache Errorcode: ${error.code}`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
clearHistory() {
|
|
351
|
+
try {
|
|
352
|
+
this.controller.clearHistory();
|
|
353
|
+
} catch (error) {
|
|
354
|
+
Logger.error(TAG, `[RNOH] clearHistory Errorcode: ${error.code}`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
stopLoading() {
|
|
359
|
+
try {
|
|
360
|
+
this.controller.stop();
|
|
361
|
+
} catch (error) {
|
|
362
|
+
Logger.error(TAG, `[RNOH] stopLoading Errorcode: ${error.code}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
loadUrl(args: string[]) {
|
|
367
|
+
try {
|
|
368
|
+
this.controller.loadUrl(args[0]);
|
|
369
|
+
} catch (error) {
|
|
370
|
+
Logger.error(TAG, `[RNOH] loadUrl Errorcode: ${error.code}`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
registerCommandCallback(commandName: COMMAND_NAME, args: string[]) {
|
|
375
|
+
switch (commandName) {
|
|
376
|
+
case COMMAND_NAME.INJECTJAVASCRIPT:
|
|
377
|
+
this.injectJavaScript(args)
|
|
378
|
+
break
|
|
379
|
+
case COMMAND_NAME.POSTMESSAGE:
|
|
380
|
+
this.postMessage(args)
|
|
381
|
+
break
|
|
382
|
+
case COMMAND_NAME.RELOAD:
|
|
383
|
+
this.reload()
|
|
384
|
+
break
|
|
385
|
+
case COMMAND_NAME.GOBACK:
|
|
386
|
+
this.goBack()
|
|
387
|
+
break
|
|
388
|
+
case COMMAND_NAME.GOFORWARD:
|
|
389
|
+
this.goForward()
|
|
390
|
+
break
|
|
391
|
+
case COMMAND_NAME.REQUESTFOCUS:
|
|
392
|
+
this.requestFocus()
|
|
393
|
+
case COMMAND_NAME.CLEARCACHE:
|
|
394
|
+
this.clearCache(args)
|
|
395
|
+
case COMMAND_NAME.CLEARHISTORY:
|
|
396
|
+
this.clearHistory()
|
|
397
|
+
break
|
|
398
|
+
case COMMAND_NAME.STOPLOADING:
|
|
399
|
+
this.stopLoading()
|
|
400
|
+
break
|
|
401
|
+
case COMMAND_NAME.LOADURL:
|
|
402
|
+
this.loadUrl(args)
|
|
403
|
+
break
|
|
404
|
+
default:
|
|
405
|
+
break
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
setOriginWhitelist(uris: string) {
|
|
410
|
+
try {
|
|
411
|
+
this.controller.setUrlTrustList(uris);
|
|
412
|
+
} catch (error) {
|
|
413
|
+
Logger.error(TAG, `[RNOH] setOriginWhitelist Errorcode: ${error.code}`);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
setIncognito() {
|
|
418
|
+
this.controller.clearHistory()
|
|
419
|
+
webview.WebCookieManager.clearAllCookiesSync(true);
|
|
420
|
+
webview.WebCookieManager.clearSessionCookieSync()
|
|
421
|
+
webview.WebStorage.deleteAllData();
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
setFraudulentWebsiteWarningEnabled(status: boolean) {
|
|
425
|
+
try {
|
|
426
|
+
this.controller.enableSafeBrowsing(status);
|
|
427
|
+
} catch (error) {
|
|
428
|
+
Logger.error(TAG, `[RNOH] setFraudulentWebsiteWarningEnabled Errorcode: ${error.code}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
onDownloadStart(event: OnDownloadStartEvent) {
|
|
433
|
+
try {
|
|
434
|
+
this.eventEmitter!.emit('fileDownload', {
|
|
435
|
+
downloadUrl: event.url
|
|
436
|
+
})
|
|
437
|
+
} catch (error) {
|
|
438
|
+
Logger.error(TAG, `[RNOH] onDownloadStart Errorcode: ${error.code}`);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
onRenderExited(event: OnRenderExitedEvent) {
|
|
443
|
+
try {
|
|
444
|
+
|
|
445
|
+
} catch (error) {
|
|
446
|
+
Logger.error(TAG, `[RNOH] onRenderExited Errorcode: ${error.code}`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
onTitleReceive(event: OnTitleReceiveEvent) {
|
|
451
|
+
try {
|
|
452
|
+
|
|
453
|
+
} catch (error) {
|
|
454
|
+
Logger.error(TAG, `[RNOH] onTitleReceive Errorcode: ${error.code}`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|