react-native-webview-bootpay 13.8.42 → 13.13.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/README.md +53 -69
- package/android/build.gradle +1 -11
- package/android/gradle.properties +0 -42
- package/android/src/main/AndroidManifest.xml +3 -1
- package/android/src/main/AndroidManifestNew.xml +13 -0
- package/android/src/main/java/kr/co/bootpay/webview/BPCWebChromeClient.java +54 -10
- package/android/src/main/java/kr/co/bootpay/webview/BPCWebView.java +101 -68
- package/android/src/main/java/kr/co/bootpay/webview/BPCWebViewClient.java +68 -60
- package/android/src/main/java/kr/co/bootpay/webview/BPCWebViewManagerImpl.kt +119 -65
- package/android/src/main/java/kr/co/bootpay/webview/BPCWebViewMessagingModule.kt +9 -0
- package/android/src/main/java/kr/co/bootpay/webview/BPCWebViewModuleImpl.java +1 -1
- package/android/src/main/java/kr/co/bootpay/webview/BootpayUrlHelper.java +4 -12
- package/android/src/newarch/{com/reactnativecommunity → kr/co/bootpay}/webview/BPCWebViewManager.java +118 -109
- package/android/src/newarch/{com/reactnativecommunity → kr/co/bootpay}/webview/BPCWebViewModule.java +1 -1
- package/android/src/{main/java → oldarch}/kr/co/bootpay/webview/BPCWebViewManager.java +63 -58
- package/android/src/{main/java → oldarch}/kr/co/bootpay/webview/BPCWebViewModule.java +1 -1
- package/apple/BPCWebView.mm +21 -12
- package/apple/BPCWebViewImpl.h +11 -1
- package/apple/BPCWebViewImpl.m +278 -216
- package/apple/BPCWebViewManager.mm +5 -24
- package/apple/BPCWebViewModule.h +23 -0
- package/apple/BPCWebViewModule.mm +34 -0
- package/apple/RCTConvert+WKDataDetectorTypes.h +11 -0
- package/apple/RCTConvert+WKDataDetectorTypes.m +27 -0
- package/ios/RNCWebView.xcodeproj/project.pbxproj +24 -24
- package/ios/RNCWebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/RNCWebView.xcodeproj/project.xcworkspace/xcuserdata/taesupyoon.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/RNCWebView.xcodeproj/xcuserdata/taesupyoon.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/BPCWebViewNativeComponent.d.ts +24 -25
- package/lib/BPCWebViewNativeComponent.js +1 -1
- package/lib/{NativeBPCWebView.d.ts → NativeBPCWebViewModule.d.ts} +2 -5
- package/lib/{NativeBPCWebView.js → NativeBPCWebViewModule.js} +1 -1
- package/lib/WebView.android.d.ts +0 -1
- package/lib/WebView.android.js +1 -1
- package/lib/WebView.d.ts +0 -1
- package/lib/WebView.ios.d.ts +0 -1
- package/lib/WebView.ios.js +1 -1
- package/lib/WebView.js +1 -1
- package/lib/WebView.macos.d.ts +0 -1
- package/lib/WebView.macos.js +1 -1
- package/lib/WebView.styles.d.ts +37 -11
- package/lib/WebView.styles.js +1 -1
- package/lib/WebView.windows.d.ts +0 -1
- package/lib/WebView.windows.js +1 -1
- package/lib/WebViewNativeComponent.macos.d.ts +1 -2
- package/lib/WebViewNativeComponent.windows.d.ts +1 -2
- package/lib/WebViewShared.d.ts +0 -1
- package/lib/WebViewShared.js +1 -1
- package/lib/WebViewTypes.d.ts +51 -3
- package/lib/WebViewTypes.js +1 -1
- package/lib/index.d.ts +0 -1
- package/macos/RNCWebView.xcodeproj/project.pbxproj +36 -36
- package/package.json +13 -12
- package/react-native.config.js +1 -5
- package/src/BPCWebViewNativeComponent.ts +143 -79
- package/src/NativeBPCWebViewModule.ts +13 -0
- package/src/WebView.android.tsx +295 -190
- package/src/WebView.ios.tsx +253 -186
- package/src/WebView.macos.tsx +220 -152
- package/src/WebView.styles.ts +9 -12
- package/src/WebView.tsx +14 -7
- package/src/WebView.windows.tsx +180 -126
- package/src/WebViewNativeComponent.macos.ts +4 -5
- package/src/WebViewNativeComponent.windows.ts +6 -8
- package/src/WebViewShared.tsx +139 -91
- package/src/WebViewTypes.ts +80 -35
- package/src/__tests__/WebViewShared-test.js +170 -55
- package/windows/ReactNativeWebView/ReactNativeWebView.vcxproj +8 -17
- package/windows/ReactNativeWebView/ReactPackageProvider.cpp +5 -1
- package/windows/ReactNativeWebView/ReactWebView.cpp +73 -6
- package/windows/ReactNativeWebView/ReactWebView.h +11 -1
- package/windows/ReactNativeWebView/ReactWebView.idl +12 -3
- package/windows/ReactNativeWebView/ReactWebView2.cpp +294 -129
- package/windows/ReactNativeWebView/ReactWebView2.h +42 -5
- package/windows/ReactNativeWebView/ReactWebView2Manager.cpp +60 -34
- package/windows/ReactNativeWebView/ReactWebView2Manager.h +4 -4
- package/windows/ReactNativeWebView/ReactWebViewHelpers.cpp +70 -0
- package/windows/ReactNativeWebView/ReactWebViewHelpers.h +16 -0
- package/windows/ReactNativeWebView/ReactWebViewManager.cpp +22 -3
- package/windows/ReactNativeWebView/ReactWebViewManager.h +6 -1
- package/windows/ReactNativeWebView/pch.h +11 -7
- package/windows/ReactNativeWebView.sln +14 -14
- package/ios/main.jsbundle +0 -457
- package/lib/BPCWebViewNativeComponent.d.ts.map +0 -1
- package/lib/NativeBPCWebView.d.ts.map +0 -1
- package/lib/WebView.android.d.ts.map +0 -1
- package/lib/WebView.d.ts.map +0 -1
- package/lib/WebView.ios.d.ts.map +0 -1
- package/lib/WebView.macos.d.ts.map +0 -1
- package/lib/WebView.styles.d.ts.map +0 -1
- package/lib/WebView.windows.d.ts.map +0 -1
- package/lib/WebViewNativeComponent.macos.d.ts.map +0 -1
- package/lib/WebViewNativeComponent.windows.d.ts.map +0 -1
- package/lib/WebViewShared.d.ts.map +0 -1
- package/lib/WebViewTypes.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/react-native-webview-bootpay.podspec +0 -46
- package/src/NativeBPCWebView.ts +0 -14
- package/windows/ReactNativeWebView/packages.config +0 -5
- /package/android/src/main/java/kr/co/bootpay/webview/{BPCWebviewWrapper.kt → BPCWebViewWrapper.kt} +0 -0
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
package kr.co.bootpay.webview;
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import android.app.Dialog;
|
|
4
4
|
|
|
5
5
|
import android.annotation.SuppressLint;
|
|
6
|
-
import android.app.Dialog;
|
|
7
|
-
import android.content.Context;
|
|
8
6
|
import android.graphics.Rect;
|
|
9
|
-
import android.
|
|
7
|
+
import android.net.Uri;
|
|
10
8
|
import android.text.TextUtils;
|
|
11
|
-
import android.util.AttributeSet;
|
|
12
|
-
import android.util.Log;
|
|
13
|
-
|
|
14
9
|
import android.view.ActionMode;
|
|
15
10
|
import android.view.Menu;
|
|
16
11
|
import android.view.MenuItem;
|
|
@@ -22,9 +17,17 @@ import android.webkit.WebChromeClient;
|
|
|
22
17
|
import android.webkit.WebView;
|
|
23
18
|
import android.webkit.WebViewClient;
|
|
24
19
|
|
|
20
|
+
import androidx.annotation.NonNull;
|
|
21
|
+
import androidx.annotation.Nullable;
|
|
22
|
+
import androidx.webkit.JavaScriptReplyProxy;
|
|
23
|
+
import androidx.webkit.WebMessageCompat;
|
|
24
|
+
import androidx.webkit.WebViewCompat;
|
|
25
|
+
import androidx.webkit.WebViewFeature;
|
|
26
|
+
|
|
25
27
|
import com.facebook.common.logging.FLog;
|
|
26
28
|
import com.facebook.react.bridge.Arguments;
|
|
27
29
|
import com.facebook.react.bridge.CatalystInstance;
|
|
30
|
+
import com.facebook.react.bridge.JavaScriptModule;
|
|
28
31
|
import com.facebook.react.bridge.LifecycleEventListener;
|
|
29
32
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
30
33
|
import com.facebook.react.bridge.WritableMap;
|
|
@@ -32,46 +35,46 @@ import com.facebook.react.bridge.WritableNativeArray;
|
|
|
32
35
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
33
36
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
34
37
|
import com.facebook.react.uimanager.UIManagerHelper;
|
|
35
|
-
import com.facebook.react.uimanager.UIManagerModule;
|
|
36
38
|
import com.facebook.react.uimanager.events.ContentSizeChangeEvent;
|
|
37
39
|
import com.facebook.react.uimanager.events.Event;
|
|
38
|
-
import com.facebook.react.uimanager.events.EventDispatcher;
|
|
39
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
40
40
|
import com.facebook.react.views.scroll.OnScrollDispatchHelper;
|
|
41
41
|
import com.facebook.react.views.scroll.ScrollEvent;
|
|
42
42
|
import com.facebook.react.views.scroll.ScrollEventType;
|
|
43
43
|
import kr.co.bootpay.webview.events.TopCustomMenuSelectionEvent;
|
|
44
|
-
import kr.co.bootpay.webview.events.TopLoadingProgressEvent;
|
|
45
44
|
import kr.co.bootpay.webview.events.TopMessageEvent;
|
|
46
45
|
|
|
47
46
|
import org.json.JSONException;
|
|
48
47
|
import org.json.JSONObject;
|
|
49
48
|
|
|
50
|
-
import java.io.UnsupportedEncodingException;
|
|
51
|
-
import java.net.URLEncoder;
|
|
52
49
|
import java.util.List;
|
|
53
50
|
import java.util.Map;
|
|
51
|
+
import java.util.Set;
|
|
54
52
|
|
|
55
53
|
public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
56
54
|
protected @Nullable
|
|
57
55
|
String injectedJS;
|
|
58
56
|
protected @Nullable
|
|
59
57
|
String injectedJSBeforeContentLoaded;
|
|
58
|
+
|
|
59
|
+
protected @Nullable
|
|
60
|
+
BPCWebViewBridge fallbackBridge;
|
|
60
61
|
protected @Nullable
|
|
61
|
-
|
|
62
|
+
WebViewCompat.WebMessageListener bridgeListener = null;
|
|
62
63
|
|
|
64
|
+
/** bootpay added start ***/
|
|
65
|
+
protected static final String JAVASCRIPT_INTERFACE = "BootpayRNWebView";
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
// protected static final String JAVASCRIPT_INTERFACE = "ReactNativeWebView";
|
|
68
|
+
|
|
69
|
+
Dialog dialog; //popup dialog
|
|
70
|
+
public void setDialog(Dialog dialog) {
|
|
71
|
+
this.dialog = dialog;
|
|
72
|
+
}
|
|
70
73
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
public void dissmissDialog() {
|
|
75
|
+
if(this.dialog != null) this.dialog.dismiss();
|
|
76
|
+
this.dialog = null;
|
|
77
|
+
}
|
|
75
78
|
/** bootpay added end ***/
|
|
76
79
|
|
|
77
80
|
/**
|
|
@@ -85,9 +88,9 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
85
88
|
protected @Nullable
|
|
86
89
|
String messagingModuleName;
|
|
87
90
|
protected @Nullable
|
|
88
|
-
|
|
91
|
+
BPCWebViewMessagingModule mMessagingJSModule;
|
|
89
92
|
protected @Nullable
|
|
90
|
-
|
|
93
|
+
BPCWebViewClient mBPCWebViewClient;
|
|
91
94
|
protected boolean sendContentSizeChangeEvents = false;
|
|
92
95
|
private OnScrollDispatchHelper mOnScrollDispatchHelper;
|
|
93
96
|
protected boolean hasScrollEvent = false;
|
|
@@ -102,7 +105,7 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
102
105
|
*/
|
|
103
106
|
public BPCWebView(ThemedReactContext reactContext) {
|
|
104
107
|
super(reactContext);
|
|
105
|
-
this.
|
|
108
|
+
mMessagingJSModule = ((ThemedReactContext) this.getContext()).getReactApplicationContext().getJSModule(BPCWebViewMessagingModule.class);
|
|
106
109
|
progressChangedFilter = new ProgressChangedFilter();
|
|
107
110
|
}
|
|
108
111
|
|
|
@@ -157,7 +160,7 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
157
160
|
dispatchEvent(
|
|
158
161
|
this,
|
|
159
162
|
new ContentSizeChangeEvent(
|
|
160
|
-
|
|
163
|
+
BPCWebViewWrapper.getReactTagFromWebView(this),
|
|
161
164
|
w,
|
|
162
165
|
h
|
|
163
166
|
)
|
|
@@ -208,7 +211,7 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
208
211
|
selectionText = new JSONObject(selectionJson).getString("selection");
|
|
209
212
|
} catch (JSONException ignored) {}
|
|
210
213
|
wMap.putString("selectedText", selectionText);
|
|
211
|
-
dispatchEvent(BPCWebView.this, new TopCustomMenuSelectionEvent(BPCWebView.this
|
|
214
|
+
dispatchEvent(BPCWebView.this, new TopCustomMenuSelectionEvent(BPCWebViewWrapper.getReactTagFromWebView(BPCWebView.this), wMap));
|
|
212
215
|
mode.finish();
|
|
213
216
|
}
|
|
214
217
|
}
|
|
@@ -266,20 +269,45 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
266
269
|
return this.messagingEnabled;
|
|
267
270
|
}
|
|
268
271
|
|
|
269
|
-
protected
|
|
270
|
-
if (
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
protected void createBPCWebViewBridge(BPCWebView webView) {
|
|
273
|
+
if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)){
|
|
274
|
+
if (this.bridgeListener == null) {
|
|
275
|
+
this.bridgeListener = new WebViewCompat.WebMessageListener() {
|
|
276
|
+
@Override
|
|
277
|
+
public void onPostMessage(@NonNull WebView view, @NonNull WebMessageCompat message, @NonNull Uri sourceOrigin, boolean isMainFrame, @NonNull JavaScriptReplyProxy replyProxy) {
|
|
278
|
+
BPCWebView.this.onMessage(message.getData(), sourceOrigin.toString());
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
WebViewCompat.addWebMessageListener(
|
|
282
|
+
webView,
|
|
283
|
+
JAVASCRIPT_INTERFACE,
|
|
284
|
+
Set.of("*"),
|
|
285
|
+
this.bridgeListener
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
if (fallbackBridge == null) {
|
|
290
|
+
fallbackBridge = new BPCWebViewBridge(webView);
|
|
291
|
+
addJavascriptInterface(fallbackBridge, JAVASCRIPT_INTERFACE);
|
|
292
|
+
}
|
|
273
293
|
}
|
|
274
|
-
return bridge;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
protected void createCatalystInstance() {
|
|
278
|
-
ThemedReactContext reactContext = (ThemedReactContext) this.getContext();
|
|
279
294
|
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
-
|
|
295
|
+
// if (fallbackBridge == null) {
|
|
296
|
+
// fallbackBridge = new BPCWebViewBridge(webView);
|
|
297
|
+
// addJavascriptInterface(fallbackBridge, JAVASCRIPT_INTERFACE);
|
|
298
|
+
// }
|
|
299
|
+
|
|
300
|
+
injectJavascriptObject();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private void injectJavascriptObject() {
|
|
304
|
+
if (getSettings().getJavaScriptEnabled()) {
|
|
305
|
+
String js = "(function(){\n" +
|
|
306
|
+
" window." + JAVASCRIPT_INTERFACE + " = window." + JAVASCRIPT_INTERFACE + " || {};\n" +
|
|
307
|
+
" window." + JAVASCRIPT_INTERFACE + ".injectedObjectJson = function () { return " + (injectedJavaScriptObject == null ? null : ("`" + injectedJavaScriptObject + "`")) + "; };\n" +
|
|
308
|
+
"})();";
|
|
309
|
+
evaluateJavascriptWithFallback(js);
|
|
310
|
+
}
|
|
283
311
|
}
|
|
284
312
|
|
|
285
313
|
@SuppressLint("AddJavascriptInterface")
|
|
@@ -304,6 +332,7 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
304
332
|
injectedJS != null &&
|
|
305
333
|
!TextUtils.isEmpty(injectedJS)) {
|
|
306
334
|
evaluateJavascriptWithFallback("(function() {\n" + injectedJS + ";\n})();");
|
|
335
|
+
injectJavascriptObject(); // re-inject the Javascript object in case it has been overwritten.
|
|
307
336
|
}
|
|
308
337
|
}
|
|
309
338
|
|
|
@@ -312,17 +341,18 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
312
341
|
injectedJSBeforeContentLoaded != null &&
|
|
313
342
|
!TextUtils.isEmpty(injectedJSBeforeContentLoaded)) {
|
|
314
343
|
evaluateJavascriptWithFallback("(function() {\n" + injectedJSBeforeContentLoaded + ";\n})();");
|
|
344
|
+
injectJavascriptObject(); // re-inject the Javascript object in case it has been overwritten.
|
|
315
345
|
}
|
|
316
346
|
}
|
|
317
347
|
|
|
348
|
+
protected String injectedJavaScriptObject = null;
|
|
349
|
+
|
|
318
350
|
public void setInjectedJavaScriptObject(String obj) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
b.setInjectedObjectJson(obj);
|
|
322
|
-
}
|
|
351
|
+
this.injectedJavaScriptObject = obj;
|
|
352
|
+
injectJavascriptObject();
|
|
323
353
|
}
|
|
324
354
|
|
|
325
|
-
public void onMessage(String message) {
|
|
355
|
+
public void onMessage(String message, String sourceUrl) {
|
|
326
356
|
ThemedReactContext reactContext = getThemedReactContext();
|
|
327
357
|
BPCWebView mWebView = this;
|
|
328
358
|
|
|
@@ -334,13 +364,13 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
334
364
|
if (mBPCWebViewClient == null) {
|
|
335
365
|
return;
|
|
336
366
|
}
|
|
337
|
-
WritableMap data = mBPCWebViewClient.createWebViewEvent(webView,
|
|
367
|
+
WritableMap data = mBPCWebViewClient.createWebViewEvent(webView, sourceUrl);
|
|
338
368
|
data.putString("data", message);
|
|
339
369
|
|
|
340
|
-
if (
|
|
341
|
-
|
|
370
|
+
if (mMessagingJSModule != null) {
|
|
371
|
+
dispatchDirectMessage(data);
|
|
342
372
|
} else {
|
|
343
|
-
dispatchEvent(webView, new TopMessageEvent(
|
|
373
|
+
dispatchEvent(webView, new TopMessageEvent(BPCWebViewWrapper.getReactTagFromWebView(webView), data));
|
|
344
374
|
}
|
|
345
375
|
}
|
|
346
376
|
});
|
|
@@ -348,22 +378,29 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
348
378
|
WritableMap eventData = Arguments.createMap();
|
|
349
379
|
eventData.putString("data", message);
|
|
350
380
|
|
|
351
|
-
if (
|
|
352
|
-
|
|
381
|
+
if (mMessagingJSModule != null) {
|
|
382
|
+
dispatchDirectMessage(eventData);
|
|
353
383
|
} else {
|
|
354
|
-
dispatchEvent(this, new TopMessageEvent(
|
|
384
|
+
dispatchEvent(this, new TopMessageEvent(BPCWebViewWrapper.getReactTagFromWebView(this), eventData));
|
|
355
385
|
}
|
|
356
386
|
}
|
|
357
387
|
}
|
|
358
388
|
|
|
359
|
-
protected void
|
|
389
|
+
protected void dispatchDirectMessage(WritableMap data) {
|
|
360
390
|
WritableNativeMap event = new WritableNativeMap();
|
|
361
391
|
event.putMap("nativeEvent", data);
|
|
392
|
+
event.putString("messagingModuleName", messagingModuleName);
|
|
362
393
|
|
|
363
|
-
|
|
364
|
-
|
|
394
|
+
mMessagingJSModule.onMessage(event);
|
|
395
|
+
}
|
|
365
396
|
|
|
366
|
-
|
|
397
|
+
protected boolean dispatchDirectShouldStartLoadWithRequest(WritableMap data) {
|
|
398
|
+
WritableNativeMap event = new WritableNativeMap();
|
|
399
|
+
event.putMap("nativeEvent", data);
|
|
400
|
+
event.putString("messagingModuleName", messagingModuleName);
|
|
401
|
+
|
|
402
|
+
mMessagingJSModule.onShouldStartLoadWithRequest(event);
|
|
403
|
+
return true;
|
|
367
404
|
}
|
|
368
405
|
|
|
369
406
|
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
|
|
@@ -379,7 +416,7 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
379
416
|
|
|
380
417
|
if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
|
|
381
418
|
ScrollEvent event = ScrollEvent.obtain(
|
|
382
|
-
|
|
419
|
+
BPCWebViewWrapper.getReactTagFromWebView(this),
|
|
383
420
|
ScrollEventType.SCROLL,
|
|
384
421
|
x,
|
|
385
422
|
y,
|
|
@@ -396,7 +433,7 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
396
433
|
|
|
397
434
|
protected void dispatchEvent(WebView webView, Event event) {
|
|
398
435
|
ThemedReactContext reactContext = getThemedReactContext();
|
|
399
|
-
int reactTag =
|
|
436
|
+
int reactTag = BPCWebViewWrapper.getReactTagFromWebView(webView);
|
|
400
437
|
UIManagerHelper.getEventDispatcherForReactTag(reactContext, reactTag).dispatchEvent(event);
|
|
401
438
|
}
|
|
402
439
|
|
|
@@ -417,19 +454,18 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
417
454
|
return (ThemedReactContext) this.getContext();
|
|
418
455
|
}
|
|
419
456
|
|
|
457
|
+
public ReactApplicationContext getReactApplicationContext() {
|
|
458
|
+
return this.getThemedReactContext().getReactApplicationContext();
|
|
459
|
+
}
|
|
460
|
+
|
|
420
461
|
protected class BPCWebViewBridge {
|
|
421
462
|
private String TAG = "BPCWebViewBridge";
|
|
422
463
|
BPCWebView mWebView;
|
|
423
|
-
String injectedObjectJson;
|
|
424
464
|
|
|
425
465
|
BPCWebViewBridge(BPCWebView c) {
|
|
426
466
|
mWebView = c;
|
|
427
467
|
}
|
|
428
468
|
|
|
429
|
-
public void setInjectedObjectJson(String s) {
|
|
430
|
-
injectedObjectJson = s;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
469
|
/**
|
|
434
470
|
* This method is called whenever JavaScript running within the web view calls:
|
|
435
471
|
* - window[JAVASCRIPT_INTERFACE].postMessage
|
|
@@ -437,14 +473,11 @@ public class BPCWebView extends WebView implements LifecycleEventListener {
|
|
|
437
473
|
@JavascriptInterface
|
|
438
474
|
public void postMessage(String message) {
|
|
439
475
|
if (mWebView.getMessagingEnabled()) {
|
|
440
|
-
mWebView.onMessage(message);
|
|
476
|
+
mWebView.onMessage(message, mWebView.getUrl());
|
|
441
477
|
} else {
|
|
442
478
|
FLog.w(TAG, "ReactNativeWebView.postMessage method was called but messaging is disabled. Pass an onMessage handler to the WebView.");
|
|
443
479
|
}
|
|
444
480
|
}
|
|
445
|
-
|
|
446
|
-
@JavascriptInterface
|
|
447
|
-
public String injectedObjectJson() { return injectedObjectJson; }
|
|
448
481
|
}
|
|
449
482
|
|
|
450
483
|
|
|
@@ -31,10 +31,11 @@ import kr.co.bootpay.webview.events.TopLoadingFinishEvent;
|
|
|
31
31
|
import kr.co.bootpay.webview.events.TopLoadingStartEvent;
|
|
32
32
|
import kr.co.bootpay.webview.events.TopRenderProcessGoneEvent;
|
|
33
33
|
import kr.co.bootpay.webview.events.TopShouldStartLoadWithRequestEvent;
|
|
34
|
+
import android.webkit.CookieManager;
|
|
35
|
+
import android.webkit.CookieSyncManager;
|
|
34
36
|
|
|
35
37
|
import java.util.concurrent.atomic.AtomicReference;
|
|
36
38
|
|
|
37
|
-
|
|
38
39
|
import android.app.AlertDialog;
|
|
39
40
|
import android.content.DialogInterface;
|
|
40
41
|
import android.content.Intent;
|
|
@@ -61,9 +62,14 @@ public class BPCWebViewClient extends WebViewClient {
|
|
|
61
62
|
@Override
|
|
62
63
|
public void onPageFinished(WebView webView, String url) {
|
|
63
64
|
super.onPageFinished(webView, url);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
String cookies = CookieManager.getInstance().getCookie(url);
|
|
66
|
+
if (cookies != null) {
|
|
67
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
68
|
+
CookieManager.getInstance().flush();
|
|
69
|
+
}else {
|
|
70
|
+
CookieSyncManager.getInstance().sync();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
67
73
|
|
|
68
74
|
if (!mLastLoadFailed) {
|
|
69
75
|
BPCWebView reactWebView = (BPCWebView) webView;
|
|
@@ -81,7 +87,7 @@ public class BPCWebViewClient extends WebViewClient {
|
|
|
81
87
|
((BPCWebView) webView).dispatchEvent(
|
|
82
88
|
webView,
|
|
83
89
|
new TopLoadingStartEvent(
|
|
84
|
-
|
|
90
|
+
BPCWebViewWrapper.getReactTagFromWebView(webView),
|
|
85
91
|
createWebViewEvent(webView, url)));
|
|
86
92
|
}
|
|
87
93
|
|
|
@@ -96,60 +102,63 @@ public class BPCWebViewClient extends WebViewClient {
|
|
|
96
102
|
|
|
97
103
|
@Override
|
|
98
104
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
99
|
-
Log.d("bootpay url", url);
|
|
100
105
|
|
|
106
|
+
// Log.i("bootpay url", url);
|
|
101
107
|
if(BootpayUrlHelper.shouldOverrideUrlLoading(view, url)) {
|
|
102
108
|
return true;
|
|
103
109
|
}
|
|
110
|
+
// return false;
|
|
104
111
|
return shouldOverrideUrlLoadingRN(view, url);
|
|
105
112
|
}
|
|
106
113
|
|
|
114
|
+
|
|
115
|
+
|
|
107
116
|
public boolean shouldOverrideUrlLoadingRN(WebView view, String url) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
117
|
+
final BPCWebView BPCWebView = (BPCWebView) view;
|
|
118
|
+
final boolean isJsDebugging = BPCWebView.getReactApplicationContext().getJavaScriptContextHolder().get() == 0;
|
|
119
|
+
|
|
120
|
+
if (!isJsDebugging && BPCWebView.mMessagingJSModule != null) {
|
|
121
|
+
final Pair<Double, AtomicReference<BPCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState>> lock = BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.getNewLock();
|
|
122
|
+
final double lockIdentifier = lock.first;
|
|
123
|
+
final AtomicReference<BPCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState> lockObject = lock.second;
|
|
124
|
+
|
|
125
|
+
final WritableMap event = createWebViewEvent(view, url);
|
|
126
|
+
event.putDouble("lockIdentifier", lockIdentifier);
|
|
127
|
+
BPCWebView.dispatchDirectShouldStartLoadWithRequest(event);
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
assert lockObject != null;
|
|
131
|
+
synchronized (lockObject) {
|
|
132
|
+
final long startTime = SystemClock.elapsedRealtime();
|
|
133
|
+
while (lockObject.get() == BPCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState.UNDECIDED) {
|
|
134
|
+
if (SystemClock.elapsedRealtime() - startTime > SHOULD_OVERRIDE_URL_LOADING_TIMEOUT) {
|
|
135
|
+
FLog.w(TAG, "Did not receive response to shouldOverrideUrlLoading in time, defaulting to allow loading.");
|
|
136
|
+
BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
lockObject.wait(SHOULD_OVERRIDE_URL_LOADING_TIMEOUT);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} catch (InterruptedException e) {
|
|
143
|
+
FLog.e(TAG, "shouldOverrideUrlLoading was interrupted while waiting for result.", e);
|
|
127
144
|
BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
|
|
128
145
|
return false;
|
|
129
|
-
}
|
|
130
|
-
lockObject.wait(SHOULD_OVERRIDE_URL_LOADING_TIMEOUT);
|
|
131
146
|
}
|
|
132
|
-
}
|
|
133
|
-
} catch (InterruptedException e) {
|
|
134
|
-
FLog.e(TAG, "shouldOverrideUrlLoading was interrupted while waiting for result.", e);
|
|
135
|
-
BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
147
|
|
|
139
|
-
|
|
140
|
-
|
|
148
|
+
final boolean shouldOverride = lockObject.get() == BPCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState.SHOULD_OVERRIDE;
|
|
149
|
+
BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
|
|
141
150
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
151
|
+
return shouldOverride;
|
|
152
|
+
} else {
|
|
153
|
+
FLog.w(TAG, "Couldn't use blocking synchronous call for onShouldStartLoadWithRequest due to debugging or missing Catalyst instance, falling back to old event-and-load.");
|
|
154
|
+
progressChangedFilter.setWaitingForCommandLoadUrl(true);
|
|
146
155
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
156
|
+
int reactTag = BPCWebViewWrapper.getReactTagFromWebView(view);
|
|
157
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) view.getContext(), reactTag).dispatchEvent(new TopShouldStartLoadWithRequestEvent(
|
|
158
|
+
reactTag,
|
|
159
|
+
createWebViewEvent(view, url)));
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
153
162
|
}
|
|
154
163
|
|
|
155
164
|
@TargetApi(Build.VERSION_CODES.N)
|
|
@@ -182,11 +191,11 @@ public class BPCWebViewClient extends WebViewClient {
|
|
|
182
191
|
// Undesired behavior: Return value of WebView.getUrl() may be the current URL instead of the failing URL.
|
|
183
192
|
handler.cancel();
|
|
184
193
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
194
|
+
if (!topWindowUrl.equalsIgnoreCase(failingUrl)) {
|
|
195
|
+
// If error is not due to top-level navigation, then do not call onReceivedError()
|
|
196
|
+
Log.w(TAG, "Resource blocked from loading due to SSL error. Blocked URL: "+failingUrl);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
190
199
|
|
|
191
200
|
int code = error.getPrimaryError();
|
|
192
201
|
String description = "";
|
|
@@ -225,7 +234,6 @@ public class BPCWebViewClient extends WebViewClient {
|
|
|
225
234
|
description,
|
|
226
235
|
failingUrl
|
|
227
236
|
);
|
|
228
|
-
alertSSLError(webView, handler, error);
|
|
229
237
|
}
|
|
230
238
|
|
|
231
239
|
void alertSSLError(WebView view, SslErrorHandler handler, SslError error) {
|
|
@@ -290,8 +298,8 @@ public class BPCWebViewClient extends WebViewClient {
|
|
|
290
298
|
eventData.putDouble("code", errorCode);
|
|
291
299
|
eventData.putString("description", description);
|
|
292
300
|
|
|
293
|
-
int reactTag =
|
|
294
|
-
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingErrorEvent(
|
|
301
|
+
int reactTag = BPCWebViewWrapper.getReactTagFromWebView(webView);
|
|
302
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingErrorEvent(reactTag, eventData));
|
|
295
303
|
}
|
|
296
304
|
|
|
297
305
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
@@ -307,8 +315,8 @@ public class BPCWebViewClient extends WebViewClient {
|
|
|
307
315
|
eventData.putInt("statusCode", errorResponse.getStatusCode());
|
|
308
316
|
eventData.putString("description", errorResponse.getReasonPhrase());
|
|
309
317
|
|
|
310
|
-
int reactTag =
|
|
311
|
-
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopHttpErrorEvent(
|
|
318
|
+
int reactTag = BPCWebViewWrapper.getReactTagFromWebView(webView);
|
|
319
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopHttpErrorEvent(reactTag, eventData));
|
|
312
320
|
}
|
|
313
321
|
}
|
|
314
322
|
|
|
@@ -337,21 +345,21 @@ public class BPCWebViewClient extends WebViewClient {
|
|
|
337
345
|
|
|
338
346
|
WritableMap event = createWebViewEvent(webView, webView.getUrl());
|
|
339
347
|
event.putBoolean("didCrash", detail.didCrash());
|
|
340
|
-
int reactTag =
|
|
341
|
-
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopRenderProcessGoneEvent(
|
|
348
|
+
int reactTag = BPCWebViewWrapper.getReactTagFromWebView(webView);
|
|
349
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopRenderProcessGoneEvent(reactTag, event));
|
|
342
350
|
|
|
343
351
|
// returning false would crash the app.
|
|
344
352
|
return true;
|
|
345
353
|
}
|
|
346
354
|
|
|
347
355
|
protected void emitFinishEvent(WebView webView, String url) {
|
|
348
|
-
int reactTag =
|
|
349
|
-
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingFinishEvent(
|
|
356
|
+
int reactTag = BPCWebViewWrapper.getReactTagFromWebView(webView);
|
|
357
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingFinishEvent(reactTag, createWebViewEvent(webView, url)));
|
|
350
358
|
}
|
|
351
359
|
|
|
352
360
|
protected WritableMap createWebViewEvent(WebView webView, String url) {
|
|
353
361
|
WritableMap event = Arguments.createMap();
|
|
354
|
-
event.putDouble("target",
|
|
362
|
+
event.putDouble("target", BPCWebViewWrapper.getReactTagFromWebView(webView));
|
|
355
363
|
// Don't use webView.getUrl() here, the URL isn't updated to the new value yet in callbacks
|
|
356
364
|
// like onPageFinished
|
|
357
365
|
event.putString("url", url);
|