react-native-webview-bootpay 13.8.41 → 13.13.4-4.alpha.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 (101) hide show
  1. package/README.md +53 -69
  2. package/android/build.gradle +1 -11
  3. package/android/gradle.properties +5 -47
  4. package/android/src/main/AndroidManifest.xml +9 -5
  5. package/android/src/main/AndroidManifestNew.xml +97 -0
  6. package/android/src/main/java/kr/co/bootpay/webview/BPCWebChromeClient.java +57 -11
  7. package/android/src/main/java/kr/co/bootpay/webview/BPCWebView.java +101 -68
  8. package/android/src/main/java/kr/co/bootpay/webview/BPCWebViewClient.java +70 -56
  9. package/android/src/main/java/kr/co/bootpay/webview/BPCWebViewManagerImpl.kt +119 -65
  10. package/android/src/main/java/kr/co/bootpay/webview/BPCWebViewMessagingModule.kt +9 -0
  11. package/android/src/main/java/kr/co/bootpay/webview/BPCWebViewModuleImpl.java +1 -1
  12. package/android/src/main/java/kr/co/bootpay/webview/BootpayUrlHelper.java +91 -75
  13. package/android/src/newarch/{com/reactnativecommunity → kr/co/bootpay}/webview/BPCWebViewManager.java +118 -109
  14. package/android/src/newarch/{com/reactnativecommunity → kr/co/bootpay}/webview/BPCWebViewModule.java +1 -1
  15. package/android/src/{main/java → oldarch}/kr/co/bootpay/webview/BPCWebViewManager.java +63 -58
  16. package/android/src/{main/java → oldarch}/kr/co/bootpay/webview/BPCWebViewModule.java +1 -1
  17. package/apple/BPCWebView.mm +21 -12
  18. package/apple/BPCWebViewImpl.h +10 -0
  19. package/apple/BPCWebViewImpl.m +267 -205
  20. package/apple/BPCWebViewManager.mm +5 -24
  21. package/apple/BPCWebViewModule.h +23 -0
  22. package/apple/BPCWebViewModule.mm +34 -0
  23. package/apple/RCTConvert+WKDataDetectorTypes.h +11 -0
  24. package/apple/RCTConvert+WKDataDetectorTypes.m +27 -0
  25. package/index.d.ts +54 -48
  26. package/ios/RNCWebView.xcodeproj/project.pbxproj +24 -24
  27. package/ios/RNCWebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  28. package/ios/RNCWebView.xcodeproj/project.xcworkspace/xcuserdata/taesupyoon.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  29. package/ios/RNCWebView.xcodeproj/xcuserdata/taesupyoon.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  30. package/lib/BPCWebViewNativeComponent.d.ts +24 -25
  31. package/lib/BPCWebViewNativeComponent.js +1 -1
  32. package/lib/{NativeBPCWebView.d.ts → NativeBPCWebViewModule.d.ts} +2 -5
  33. package/lib/{NativeBPCWebView.js → NativeBPCWebViewModule.js} +1 -1
  34. package/lib/WebView.android.d.ts +0 -1
  35. package/lib/WebView.android.js +1 -1
  36. package/lib/WebView.d.ts +0 -1
  37. package/lib/WebView.ios.d.ts +0 -1
  38. package/lib/WebView.ios.js +1 -1
  39. package/lib/WebView.js +1 -1
  40. package/lib/WebView.macos.d.ts +0 -1
  41. package/lib/WebView.macos.js +1 -1
  42. package/lib/WebView.styles.d.ts +37 -11
  43. package/lib/WebView.styles.js +1 -1
  44. package/lib/WebView.windows.d.ts +0 -1
  45. package/lib/WebView.windows.js +1 -1
  46. package/lib/WebViewNativeComponent.macos.d.ts +1 -2
  47. package/lib/WebViewNativeComponent.windows.d.ts +1 -2
  48. package/lib/WebViewShared.d.ts +0 -1
  49. package/lib/WebViewShared.js +1 -1
  50. package/lib/WebViewTypes.d.ts +51 -3
  51. package/lib/WebViewTypes.js +1 -1
  52. package/lib/index.d.ts +0 -1
  53. package/macos/RNCWebView.xcodeproj/project.pbxproj +36 -36
  54. package/package.json +12 -11
  55. package/react-native-webview-bootpay.podspec +2 -2
  56. package/react-native.config.js +1 -5
  57. package/src/BPCWebViewNativeComponent.ts +143 -79
  58. package/src/NativeBPCWebViewModule.ts +13 -0
  59. package/src/WebView.android.tsx +295 -190
  60. package/src/WebView.ios.tsx +253 -186
  61. package/src/WebView.macos.tsx +220 -152
  62. package/src/WebView.styles.ts +9 -12
  63. package/src/WebView.tsx +14 -7
  64. package/src/WebView.windows.tsx +180 -126
  65. package/src/WebViewNativeComponent.macos.ts +4 -5
  66. package/src/WebViewNativeComponent.windows.ts +6 -8
  67. package/src/WebViewShared.tsx +139 -91
  68. package/src/WebViewTypes.ts +80 -35
  69. package/src/__tests__/WebViewShared-test.js +170 -55
  70. package/windows/ReactNativeWebView/ReactNativeWebView.vcxproj +8 -17
  71. package/windows/ReactNativeWebView/ReactPackageProvider.cpp +5 -1
  72. package/windows/ReactNativeWebView/ReactWebView.cpp +73 -6
  73. package/windows/ReactNativeWebView/ReactWebView.h +11 -1
  74. package/windows/ReactNativeWebView/ReactWebView.idl +12 -3
  75. package/windows/ReactNativeWebView/ReactWebView2.cpp +294 -129
  76. package/windows/ReactNativeWebView/ReactWebView2.h +42 -5
  77. package/windows/ReactNativeWebView/ReactWebView2Manager.cpp +60 -34
  78. package/windows/ReactNativeWebView/ReactWebView2Manager.h +4 -4
  79. package/windows/ReactNativeWebView/ReactWebViewHelpers.cpp +70 -0
  80. package/windows/ReactNativeWebView/ReactWebViewHelpers.h +16 -0
  81. package/windows/ReactNativeWebView/ReactWebViewManager.cpp +22 -3
  82. package/windows/ReactNativeWebView/ReactWebViewManager.h +6 -1
  83. package/windows/ReactNativeWebView/pch.h +11 -7
  84. package/windows/ReactNativeWebView.sln +14 -14
  85. package/ios/main.jsbundle +0 -457
  86. package/lib/BPCWebViewNativeComponent.d.ts.map +0 -1
  87. package/lib/NativeBPCWebView.d.ts.map +0 -1
  88. package/lib/WebView.android.d.ts.map +0 -1
  89. package/lib/WebView.d.ts.map +0 -1
  90. package/lib/WebView.ios.d.ts.map +0 -1
  91. package/lib/WebView.macos.d.ts.map +0 -1
  92. package/lib/WebView.styles.d.ts.map +0 -1
  93. package/lib/WebView.windows.d.ts.map +0 -1
  94. package/lib/WebViewNativeComponent.macos.d.ts.map +0 -1
  95. package/lib/WebViewNativeComponent.windows.d.ts.map +0 -1
  96. package/lib/WebViewShared.d.ts.map +0 -1
  97. package/lib/WebViewTypes.d.ts.map +0 -1
  98. package/lib/index.d.ts.map +0 -1
  99. package/src/NativeBPCWebView.ts +0 -14
  100. package/windows/ReactNativeWebView/packages.config +0 -5
  101. /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 androidx.annotation.Nullable;
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.os.Build;
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
- BPCWebViewBridge bridge;
62
+ WebViewCompat.WebMessageListener bridgeListener = null;
62
63
 
64
+ /** bootpay added start ***/
65
+ protected static final String JAVASCRIPT_INTERFACE = "BootpayRNWebView";
63
66
 
64
- /** bootpay added start ***/
65
- protected static final String JAVASCRIPT_INTERFACE = "BootpayRNWebView";
66
- Dialog dialog; //popup dialog
67
- public void setDialog(Dialog dialog) {
68
- this.dialog = dialog;
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
- public void dissmissDialog() {
72
- if(this.dialog != null) this.dialog.dismiss();
73
- this.dialog = null;
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
- BPCWebViewClient mBPCWebViewClient;
91
+ BPCWebViewMessagingModule mMessagingJSModule;
89
92
  protected @Nullable
90
- CatalystInstance mCatalystInstance;
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.createCatalystInstance();
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
- this.getId(),
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.getId(), wMap));
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 BPCWebViewBridge createBPCWebViewBridge(BPCWebView webView) {
270
- if (bridge == null) {
271
- bridge = new BPCWebViewBridge(webView);
272
- addJavascriptInterface(bridge, JAVASCRIPT_INTERFACE);
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 (reactContext != null) {
281
- mCatalystInstance = reactContext.getCatalystInstance();
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
- if (getSettings().getJavaScriptEnabled()) {
320
- BPCWebViewBridge b = createBPCWebViewBridge(this);
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, webView.getUrl());
367
+ WritableMap data = mBPCWebViewClient.createWebViewEvent(webView, sourceUrl);
338
368
  data.putString("data", message);
339
369
 
340
- if (mCatalystInstance != null) {
341
- mWebView.sendDirectMessage("onMessage", data);
370
+ if (mMessagingJSModule != null) {
371
+ dispatchDirectMessage(data);
342
372
  } else {
343
- dispatchEvent(webView, new TopMessageEvent(webView.getId(), data));
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 (mCatalystInstance != null) {
352
- this.sendDirectMessage("onMessage", eventData);
381
+ if (mMessagingJSModule != null) {
382
+ dispatchDirectMessage(eventData);
353
383
  } else {
354
- dispatchEvent(this, new TopMessageEvent(this.getId(), eventData));
384
+ dispatchEvent(this, new TopMessageEvent(BPCWebViewWrapper.getReactTagFromWebView(this), eventData));
355
385
  }
356
386
  }
357
387
  }
358
388
 
359
- protected void sendDirectMessage(final String method, WritableMap data) {
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
- WritableNativeArray params = new WritableNativeArray();
364
- params.pushMap(event);
394
+ mMessagingJSModule.onMessage(event);
395
+ }
365
396
 
366
- mCatalystInstance.callFunction(messagingModuleName, method, params);
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
- this.getId(),
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 = webView.getId();
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,14 +31,16 @@ 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;
41
42
  import android.widget.Toast;
43
+ import android.util.Log;
42
44
 
43
45
  public class BPCWebViewClient extends WebViewClient {
44
46
  private static String TAG = "BPCWebViewClient";
@@ -60,6 +62,14 @@ public class BPCWebViewClient extends WebViewClient {
60
62
  @Override
61
63
  public void onPageFinished(WebView webView, String url) {
62
64
  super.onPageFinished(webView, url);
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
+ }
63
73
 
64
74
  if (!mLastLoadFailed) {
65
75
  BPCWebView reactWebView = (BPCWebView) webView;
@@ -77,7 +87,7 @@ public class BPCWebViewClient extends WebViewClient {
77
87
  ((BPCWebView) webView).dispatchEvent(
78
88
  webView,
79
89
  new TopLoadingStartEvent(
80
- webView.getId(),
90
+ BPCWebViewWrapper.getReactTagFromWebView(webView),
81
91
  createWebViewEvent(webView, url)));
82
92
  }
83
93
 
@@ -92,58 +102,63 @@ public class BPCWebViewClient extends WebViewClient {
92
102
 
93
103
  @Override
94
104
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
105
+
106
+ // Log.i("bootpay url", url);
95
107
  if(BootpayUrlHelper.shouldOverrideUrlLoading(view, url)) {
96
108
  return true;
97
109
  }
110
+ // return false;
98
111
  return shouldOverrideUrlLoadingRN(view, url);
99
112
  }
100
113
 
114
+
115
+
101
116
  public boolean shouldOverrideUrlLoadingRN(WebView view, String url) {
102
- final BPCWebView BPCWebView = (BPCWebView) view;
103
- final boolean isJsDebugging = ((ReactContext) view.getContext()).getJavaScriptContextHolder().get() == 0;
104
-
105
- if (!isJsDebugging && BPCWebView.mCatalystInstance != null) {
106
- final Pair<Double, AtomicReference<BPCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState>> lock = BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.getNewLock();
107
- final double lockIdentifier = lock.first;
108
- final AtomicReference<BPCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState> lockObject = lock.second;
109
-
110
- final WritableMap event = createWebViewEvent(view, url);
111
- event.putDouble("lockIdentifier", lockIdentifier);
112
- BPCWebView.sendDirectMessage("onShouldStartLoadWithRequest", event);
113
-
114
- try {
115
- assert lockObject != null;
116
- synchronized (lockObject) {
117
- final long startTime = SystemClock.elapsedRealtime();
118
- while (lockObject.get() == BPCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState.UNDECIDED) {
119
- if (SystemClock.elapsedRealtime() - startTime > SHOULD_OVERRIDE_URL_LOADING_TIMEOUT) {
120
- FLog.w(TAG, "Did not receive response to shouldOverrideUrlLoading in time, defaulting to allow loading.");
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);
121
144
  BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
122
145
  return false;
123
- }
124
- lockObject.wait(SHOULD_OVERRIDE_URL_LOADING_TIMEOUT);
125
146
  }
126
- }
127
- } catch (InterruptedException e) {
128
- FLog.e(TAG, "shouldOverrideUrlLoading was interrupted while waiting for result.", e);
129
- BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
130
- return false;
131
- }
132
147
 
133
- final boolean shouldOverride = lockObject.get() == BPCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState.SHOULD_OVERRIDE;
134
- BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
148
+ final boolean shouldOverride = lockObject.get() == BPCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState.SHOULD_OVERRIDE;
149
+ BPCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
135
150
 
136
- return shouldOverride;
137
- } else {
138
- 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.");
139
- progressChangedFilter.setWaitingForCommandLoadUrl(true);
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);
140
155
 
141
- int reactTag = view.getId();
142
- UIManagerHelper.getEventDispatcherForReactTag((ReactContext) view.getContext(), reactTag).dispatchEvent(new TopShouldStartLoadWithRequestEvent(
143
- reactTag,
144
- createWebViewEvent(view, url)));
145
- return true;
146
- }
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
+ }
147
162
  }
148
163
 
149
164
  @TargetApi(Build.VERSION_CODES.N)
@@ -176,11 +191,11 @@ public class BPCWebViewClient extends WebViewClient {
176
191
  // Undesired behavior: Return value of WebView.getUrl() may be the current URL instead of the failing URL.
177
192
  handler.cancel();
178
193
 
179
- // if (!topWindowUrl.equalsIgnoreCase(failingUrl)) {
180
- // // If error is not due to top-level navigation, then do not call onReceivedError()
181
- // Log.w(TAG, "Resource blocked from loading due to SSL error. Blocked URL: "+failingUrl);
182
- // return;
183
- // }
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
+ }
184
199
 
185
200
  int code = error.getPrimaryError();
186
201
  String description = "";
@@ -219,7 +234,6 @@ public class BPCWebViewClient extends WebViewClient {
219
234
  description,
220
235
  failingUrl
221
236
  );
222
- alertSSLError(webView, handler, error);
223
237
  }
224
238
 
225
239
  void alertSSLError(WebView view, SslErrorHandler handler, SslError error) {
@@ -284,8 +298,8 @@ public class BPCWebViewClient extends WebViewClient {
284
298
  eventData.putDouble("code", errorCode);
285
299
  eventData.putString("description", description);
286
300
 
287
- int reactTag = webView.getId();
288
- UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingErrorEvent(webView.getId(), eventData));
301
+ int reactTag = BPCWebViewWrapper.getReactTagFromWebView(webView);
302
+ UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingErrorEvent(reactTag, eventData));
289
303
  }
290
304
 
291
305
  @RequiresApi(api = Build.VERSION_CODES.M)
@@ -301,8 +315,8 @@ public class BPCWebViewClient extends WebViewClient {
301
315
  eventData.putInt("statusCode", errorResponse.getStatusCode());
302
316
  eventData.putString("description", errorResponse.getReasonPhrase());
303
317
 
304
- int reactTag = webView.getId();
305
- UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopHttpErrorEvent(webView.getId(), eventData));
318
+ int reactTag = BPCWebViewWrapper.getReactTagFromWebView(webView);
319
+ UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopHttpErrorEvent(reactTag, eventData));
306
320
  }
307
321
  }
308
322
 
@@ -331,21 +345,21 @@ public class BPCWebViewClient extends WebViewClient {
331
345
 
332
346
  WritableMap event = createWebViewEvent(webView, webView.getUrl());
333
347
  event.putBoolean("didCrash", detail.didCrash());
334
- int reactTag = webView.getId();
335
- UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopRenderProcessGoneEvent(webView.getId(), event));
348
+ int reactTag = BPCWebViewWrapper.getReactTagFromWebView(webView);
349
+ UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopRenderProcessGoneEvent(reactTag, event));
336
350
 
337
351
  // returning false would crash the app.
338
352
  return true;
339
353
  }
340
354
 
341
355
  protected void emitFinishEvent(WebView webView, String url) {
342
- int reactTag = webView.getId();
343
- UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingFinishEvent(webView.getId(), createWebViewEvent(webView, url)));
356
+ int reactTag = BPCWebViewWrapper.getReactTagFromWebView(webView);
357
+ UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingFinishEvent(reactTag, createWebViewEvent(webView, url)));
344
358
  }
345
359
 
346
360
  protected WritableMap createWebViewEvent(WebView webView, String url) {
347
361
  WritableMap event = Arguments.createMap();
348
- event.putDouble("target", webView.getId());
362
+ event.putDouble("target", BPCWebViewWrapper.getReactTagFromWebView(webView));
349
363
  // Don't use webView.getUrl() here, the URL isn't updated to the new value yet in callbacks
350
364
  // like onPageFinished
351
365
  event.putString("url", url);