@react-native-ohos/react-native-webview 13.10.5-rc.1 → 13.10.5-rc.2
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.
|
@@ -309,6 +309,10 @@ export struct RNCWebView {
|
|
|
309
309
|
})
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
if (!this.hasRegisterJavaScriptProxy && this.descriptorWrapper.rawProps.messagingEnabled) {
|
|
313
|
+
this.registerJavaScriptProxyOnly()
|
|
314
|
+
}
|
|
315
|
+
|
|
312
316
|
let baseUrl = this.source.baseUrl
|
|
313
317
|
let uri = this.source.uri
|
|
314
318
|
if (this.source.html != undefined && this.source.html != "") {
|
|
@@ -398,7 +402,7 @@ export struct RNCWebView {
|
|
|
398
402
|
const params = new ShouldStartParams();
|
|
399
403
|
params.lockIdentifier = this.webViewBaseOperate?.getLockIdentifier() || -1
|
|
400
404
|
this.ctx.runOnWorkerThread(new WorkerRunnable(), params);
|
|
401
|
-
this.webViewBaseOperate?.emitShouldStartLoadWithRequest(event)
|
|
405
|
+
this.webViewBaseOperate?.emitShouldStartLoadWithRequest(event, this.source.html, this.source.baseUrl)
|
|
402
406
|
const startTime = Date.now();
|
|
403
407
|
// 当lockState没变化并且小于超时时间,阻塞进程
|
|
404
408
|
while (params.lockState === ShouldOverrideCallbackState.UNDECIDED &&
|
|
@@ -579,12 +583,41 @@ export struct RNCWebView {
|
|
|
579
583
|
}
|
|
580
584
|
}
|
|
581
585
|
|
|
586
|
+
private registerJavaScriptProxyOnly() {
|
|
587
|
+
if (this.messagingEnabled == this.descriptorWrapper.rawProps.messagingEnabled && this.hasRegisterJavaScriptProxy) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
this.messagingEnabled = this.descriptorWrapper.rawProps.messagingEnabled;
|
|
591
|
+
if (this.messagingEnabled) {
|
|
592
|
+
let bridge: RNCWebViewBridge = {
|
|
593
|
+
postMessage: (data: string) => {
|
|
594
|
+
Logger.debug(TAG, `[RNOH] bridge postMessage, ${JSON.stringify(data)}`);
|
|
595
|
+
if (this.controller != null) {
|
|
596
|
+
let result: WebViewEventParams = this.createWebViewEvent("onMessage")
|
|
597
|
+
if (result) {
|
|
598
|
+
result.data = data.toString()
|
|
599
|
+
result.lockIdentifier = this.webViewBaseOperate?.getLockIdentifier()
|
|
600
|
+
this.eventEmitter!.emit("message", result as ResultType);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
this.controller.registerJavaScriptProxy(bridge, JAVASCRIPT_INTERFACE, ["postMessage"])
|
|
606
|
+
this.hasRegisterJavaScriptProxy = true
|
|
607
|
+
Logger.debug(TAG, "[RNOH] JavaScript Proxy registered without reloading page")
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
582
611
|
private registerPostMessage() {
|
|
583
612
|
if (this.messagingEnabled == this.descriptorWrapper.rawProps.messagingEnabled) {
|
|
584
613
|
return;
|
|
585
614
|
}
|
|
586
615
|
this.messagingEnabled = this.descriptorWrapper.rawProps.messagingEnabled;
|
|
587
616
|
if (this.messagingEnabled) {
|
|
617
|
+
if (this.hasRegisterJavaScriptProxy) {
|
|
618
|
+
Logger.debug(TAG, "[RNOH] JavaScript Proxy already registered")
|
|
619
|
+
return
|
|
620
|
+
}
|
|
588
621
|
let bridge: RNCWebViewBridge = {
|
|
589
622
|
postMessage: (data: string) => {
|
|
590
623
|
Logger.debug(TAG, `[RNOH] bridge postMessage, ${JSON.stringify(data)}`);
|
|
@@ -599,8 +632,13 @@ export struct RNCWebView {
|
|
|
599
632
|
}
|
|
600
633
|
};
|
|
601
634
|
this.controller.registerJavaScriptProxy(bridge, JAVASCRIPT_INTERFACE, ["postMessage"])
|
|
602
|
-
this.source.uri
|
|
603
|
-
|
|
635
|
+
if (this.source.uri && !this.source.html) {
|
|
636
|
+
this.controller.loadUrl(this.source.uri, this.headers)
|
|
637
|
+
} else if (this.source.html) {
|
|
638
|
+
Logger.debug(TAG, "[RNOH] JavaScript Proxy registered, HTML content will use it on next load")
|
|
639
|
+
} else {
|
|
640
|
+
this.controller.refresh()
|
|
641
|
+
}
|
|
604
642
|
this.hasRegisterJavaScriptProxy = true
|
|
605
643
|
}
|
|
606
644
|
}
|
|
@@ -190,10 +190,24 @@ export class BaseOperate {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
verifyURLFormat(url: string, html: string | undefined, baseUrl: string | undefined) {
|
|
194
|
+
const dataUrlPattern = /^data:text\/html;/;
|
|
195
|
+
if (dataUrlPattern.test(url)){
|
|
196
|
+
if (html != undefined && html != "") {
|
|
197
|
+
if (baseUrl != undefined && baseUrl != "") {
|
|
198
|
+
url = baseUrl.toLowerCase();
|
|
199
|
+
} else {
|
|
200
|
+
url = 'about:blank';
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return url;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
emitShouldStartLoadWithRequest(event: OnLoadInterceptEvent, html: string | undefined, baseUrl: string | undefined) {
|
|
194
208
|
try {
|
|
195
209
|
this.eventEmitter!.emit('shouldStartLoadWithRequest', {
|
|
196
|
-
url: event.data.getRequestUrl(),
|
|
210
|
+
url: this.verifyURLFormat(event.data.getRequestUrl(), html, baseUrl),
|
|
197
211
|
loading: false,
|
|
198
212
|
title: this.controller.getTitle(),
|
|
199
213
|
canGoBack: this.controller.accessBackward(),
|
package/harmony/rn_webview.har
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"Thibault Malbranche <malbranche.thibault@gmail.com>"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "13.10.5-rc.
|
|
12
|
+
"version": "13.10.5-rc.2",
|
|
13
13
|
"homepage": "https://github.com/react-native-oh-library/react-native-webview#readme",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"macos": "react-native run-macos --scheme WebviewExample --project-path example/macos",
|
|
@@ -37,8 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"escape-string-regexp": "2.0.0",
|
|
39
39
|
"invariant": "2.2.4",
|
|
40
|
-
"react-native-webview": "13.10.2"
|
|
41
|
-
"yarn": "^1.22.22"
|
|
40
|
+
"react-native-webview": "13.10.2"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"@babel/cli": "^7.20.0",
|
|
@@ -54,14 +53,12 @@
|
|
|
54
53
|
"@semantic-release/git": "7.0.16",
|
|
55
54
|
"@types/invariant": "^2.2.30",
|
|
56
55
|
"@types/jest": "^29.5.12",
|
|
57
|
-
"@types/minimatch": "^6.0.0",
|
|
58
56
|
"@types/react": "18.2.61",
|
|
59
57
|
"@types/selenium-webdriver": "4.0.9",
|
|
60
58
|
"appium": "1.17.0",
|
|
61
59
|
"eslint": "8.57.0",
|
|
62
60
|
"jest": "^29.6.3",
|
|
63
61
|
"metro-react-native-babel-preset": "0.73.7",
|
|
64
|
-
"minimatch": "^10.0.3",
|
|
65
62
|
"prettier": "2.8.8",
|
|
66
63
|
"react": "18.2.0",
|
|
67
64
|
"react-native": "0.73.5",
|
|
@@ -92,14 +89,14 @@
|
|
|
92
89
|
],
|
|
93
90
|
"publishConfig": {
|
|
94
91
|
"registry": "https://registry.npmjs.org/",
|
|
95
|
-
|
|
92
|
+
"access": "public"
|
|
96
93
|
},
|
|
97
94
|
"harmony": {
|
|
98
95
|
"alias": "react-native-webview",
|
|
99
96
|
"autolinking": {
|
|
100
|
-
"etsPackageClassName":
|
|
101
|
-
"cppPackageClassName":
|
|
102
|
-
"cmakeLibraryTargetName": "rnoh_webview",
|
|
97
|
+
"etsPackageClassName":"WebViewPackage",
|
|
98
|
+
"cppPackageClassName":"WebViewPackage",
|
|
99
|
+
"cmakeLibraryTargetName": "rnoh_webview",
|
|
103
100
|
"ohPackageName": "@react-native-ohos/react-native-webview"
|
|
104
101
|
}
|
|
105
102
|
},
|