|
@@ -84,10 +84,10 @@ import org.json.JSONObject;
|
84
|
84
|
* - canGoBack - boolean, whether there is anything on a history stack to go back
|
85
|
85
|
* - canGoForward - boolean, whether it is possible to request GO_FORWARD command
|
86
|
86
|
*/
|
87
|
|
-@ReactModule(name = RCTWebViewManager.REACT_CLASS)
|
88
|
|
-public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
|
87
|
+@ReactModule(name = RNCWebViewManager.REACT_CLASS)
|
|
88
|
+public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
89
|
89
|
|
90
|
|
- protected static final String REACT_CLASS = "RCTWebView";
|
|
90
|
+ protected static final String REACT_CLASS = "RNCWebView";
|
91
|
91
|
|
92
|
92
|
protected static final String HTML_ENCODING = "UTF-8";
|
93
|
93
|
protected static final String HTML_MIME_TYPE = "text/html";
|
|
@@ -109,7 +109,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
109
|
109
|
protected WebViewConfig mWebViewConfig;
|
110
|
110
|
protected @Nullable WebView.PictureListener mPictureListener;
|
111
|
111
|
|
112
|
|
- protected static class RCTWebViewClient extends WebViewClient {
|
|
112
|
+ protected static class RNCWebViewClient extends WebViewClient {
|
113
|
113
|
|
114
|
114
|
protected boolean mLastLoadFailed = false;
|
115
|
115
|
protected @Nullable ReadableArray mUrlPrefixesForDefaultIntent;
|
|
@@ -120,7 +120,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
120
|
120
|
super.onPageFinished(webView, url);
|
121
|
121
|
|
122
|
122
|
if (!mLastLoadFailed) {
|
123
|
|
- RCTWebView reactWebView = (RCTWebView) webView;
|
|
123
|
+ RNCWebView reactWebView = (RNCWebView) webView;
|
124
|
124
|
reactWebView.callInjectedJavaScript();
|
125
|
125
|
reactWebView.linkBridge();
|
126
|
126
|
emitFinishEvent(webView, url);
|
|
@@ -243,15 +243,15 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
243
|
243
|
* Subclass of {@link WebView} that implements {@link LifecycleEventListener} interface in order
|
244
|
244
|
* to call {@link WebView#destroy} on activity destroy event and also to clear the client
|
245
|
245
|
*/
|
246
|
|
- protected static class RCTWebView extends WebView implements LifecycleEventListener {
|
|
246
|
+ protected static class RNCWebView extends WebView implements LifecycleEventListener {
|
247
|
247
|
protected @Nullable String injectedJS;
|
248
|
248
|
protected boolean messagingEnabled = false;
|
249
|
|
- protected @Nullable RCTWebViewClient mRCTWebViewClient;
|
|
249
|
+ protected @Nullable RNCWebViewClient mRNCWebViewClient;
|
250
|
250
|
|
251
|
|
- protected class RCTWebViewBridge {
|
252
|
|
- RCTWebView mContext;
|
|
251
|
+ protected class RNCWebViewBridge {
|
|
252
|
+ RNCWebView mContext;
|
253
|
253
|
|
254
|
|
- RCTWebViewBridge(RCTWebView c) {
|
|
254
|
+ RNCWebViewBridge(RNCWebView c) {
|
255
|
255
|
mContext = c;
|
256
|
256
|
}
|
257
|
257
|
|
|
@@ -268,7 +268,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
268
|
268
|
* Reactive Native needed for access to ReactNative internal system functionality
|
269
|
269
|
*
|
270
|
270
|
*/
|
271
|
|
- public RCTWebView(ThemedReactContext reactContext) {
|
|
271
|
+ public RNCWebView(ThemedReactContext reactContext) {
|
272
|
272
|
super(reactContext);
|
273
|
273
|
}
|
274
|
274
|
|
|
@@ -290,19 +290,19 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
290
|
290
|
@Override
|
291
|
291
|
public void setWebViewClient(WebViewClient client) {
|
292
|
292
|
super.setWebViewClient(client);
|
293
|
|
- mRCTWebViewClient = (RCTWebViewClient)client;
|
|
293
|
+ mRNCWebViewClient = (RNCWebViewClient)client;
|
294
|
294
|
}
|
295
|
295
|
|
296
|
|
- public @Nullable RCTWebViewClient getRCTWebViewClient() {
|
297
|
|
- return mRCTWebViewClient;
|
|
296
|
+ public @Nullable RNCWebViewClient getRNCWebViewClient() {
|
|
297
|
+ return mRNCWebViewClient;
|
298
|
298
|
}
|
299
|
299
|
|
300
|
300
|
public void setInjectedJavaScript(@Nullable String js) {
|
301
|
301
|
injectedJS = js;
|
302
|
302
|
}
|
303
|
303
|
|
304
|
|
- protected RCTWebViewBridge createRCTWebViewBridge(RCTWebView webView) {
|
305
|
|
- return new RCTWebViewBridge(webView);
|
|
304
|
+ protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
|
|
305
|
+ return new RNCWebViewBridge(webView);
|
306
|
306
|
}
|
307
|
307
|
|
308
|
308
|
public void setMessagingEnabled(boolean enabled) {
|
|
@@ -312,7 +312,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
312
|
312
|
|
313
|
313
|
messagingEnabled = enabled;
|
314
|
314
|
if (enabled) {
|
315
|
|
- addJavascriptInterface(createRCTWebViewBridge(this), BRIDGE_NAME);
|
|
315
|
+ addJavascriptInterface(createRNCWebViewBridge(this), BRIDGE_NAME);
|
316
|
316
|
linkBridge();
|
317
|
317
|
} else {
|
318
|
318
|
removeJavascriptInterface(BRIDGE_NAME);
|
|
@@ -375,14 +375,14 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
375
|
375
|
}
|
376
|
376
|
}
|
377
|
377
|
|
378
|
|
- public RCTWebViewManager() {
|
|
378
|
+ public RNCWebViewManager() {
|
379
|
379
|
mWebViewConfig = new WebViewConfig() {
|
380
|
380
|
public void configWebView(WebView webView) {
|
381
|
381
|
}
|
382
|
382
|
};
|
383
|
383
|
}
|
384
|
384
|
|
385
|
|
- public RCTWebViewManager(WebViewConfig webViewConfig) {
|
|
385
|
+ public RNCWebViewManager(WebViewConfig webViewConfig) {
|
386
|
386
|
mWebViewConfig = webViewConfig;
|
387
|
387
|
}
|
388
|
388
|
|
|
@@ -391,14 +391,14 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
391
|
391
|
return REACT_CLASS;
|
392
|
392
|
}
|
393
|
393
|
|
394
|
|
- protected RCTWebView createRCTWebViewInstance(ThemedReactContext reactContext) {
|
395
|
|
- return new RCTWebView(reactContext);
|
|
394
|
+ protected RNCWebView createRNCWebViewInstance(ThemedReactContext reactContext) {
|
|
395
|
+ return new RNCWebView(reactContext);
|
396
|
396
|
}
|
397
|
397
|
|
398
|
398
|
@Override
|
399
|
399
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
400
|
400
|
protected WebView createViewInstance(ThemedReactContext reactContext) {
|
401
|
|
- RCTWebView webView = createRCTWebViewInstance(reactContext);
|
|
401
|
+ RNCWebView webView = createRNCWebViewInstance(reactContext);
|
402
|
402
|
webView.setWebChromeClient(new WebChromeClient() {
|
403
|
403
|
@Override
|
404
|
404
|
public boolean onConsoleMessage(ConsoleMessage message) {
|
|
@@ -489,12 +489,12 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
489
|
489
|
|
490
|
490
|
@ReactProp(name = "injectedJavaScript")
|
491
|
491
|
public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
|
492
|
|
- ((RCTWebView) view).setInjectedJavaScript(injectedJavaScript);
|
|
492
|
+ ((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
|
493
|
493
|
}
|
494
|
494
|
|
495
|
495
|
@ReactProp(name = "messagingEnabled")
|
496
|
496
|
public void setMessagingEnabled(WebView view, boolean enabled) {
|
497
|
|
- ((RCTWebView) view).setMessagingEnabled(enabled);
|
|
497
|
+ ((RNCWebView) view).setMessagingEnabled(enabled);
|
498
|
498
|
}
|
499
|
499
|
|
500
|
500
|
@ReactProp(name = "source")
|
|
@@ -583,7 +583,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
583
|
583
|
public void setUrlPrefixesForDefaultIntent(
|
584
|
584
|
WebView view,
|
585
|
585
|
@Nullable ReadableArray urlPrefixesForDefaultIntent) {
|
586
|
|
- RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
|
|
586
|
+ RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
|
587
|
587
|
if (client != null && urlPrefixesForDefaultIntent != null) {
|
588
|
588
|
client.setUrlPrefixesForDefaultIntent(urlPrefixesForDefaultIntent);
|
589
|
589
|
}
|
|
@@ -607,7 +607,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
607
|
607
|
public void setOriginWhitelist(
|
608
|
608
|
WebView view,
|
609
|
609
|
@Nullable ReadableArray originWhitelist) {
|
610
|
|
- RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
|
|
610
|
+ RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
|
611
|
611
|
if (client != null && originWhitelist != null) {
|
612
|
612
|
List<Pattern> whiteList = new LinkedList<>();
|
613
|
613
|
for (int i = 0 ; i < originWhitelist.size() ; i++) {
|
|
@@ -620,7 +620,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
620
|
620
|
@Override
|
621
|
621
|
protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
|
622
|
622
|
// Do not register default touch emitter and let WebView implementation handle touches
|
623
|
|
- view.setWebViewClient(new RCTWebViewClient());
|
|
623
|
+ view.setWebViewClient(new RNCWebViewClient());
|
624
|
624
|
}
|
625
|
625
|
|
626
|
626
|
@Override
|
|
@@ -652,7 +652,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
652
|
652
|
break;
|
653
|
653
|
case COMMAND_POST_MESSAGE:
|
654
|
654
|
try {
|
655
|
|
- RCTWebView reactWebView = (RCTWebView) root;
|
|
655
|
+ RNCWebView reactWebView = (RNCWebView) root;
|
656
|
656
|
JSONObject eventInitDict = new JSONObject();
|
657
|
657
|
eventInitDict.put("data", args.getString(0));
|
658
|
658
|
reactWebView.evaluateJavascriptWithFallback("(function () {" +
|
|
@@ -671,7 +671,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
671
|
671
|
}
|
672
|
672
|
break;
|
673
|
673
|
case COMMAND_INJECT_JAVASCRIPT:
|
674
|
|
- RCTWebView reactWebView = (RCTWebView) root;
|
|
674
|
+ RNCWebView reactWebView = (RNCWebView) root;
|
675
|
675
|
reactWebView.evaluateJavascriptWithFallback(args.getString(0));
|
676
|
676
|
break;
|
677
|
677
|
}
|
|
@@ -680,8 +680,8 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
|
680
|
680
|
@Override
|
681
|
681
|
public void onDropViewInstance(WebView webView) {
|
682
|
682
|
super.onDropViewInstance(webView);
|
683
|
|
- ((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RCTWebView) webView);
|
684
|
|
- ((RCTWebView) webView).cleanupCallbacksAndDestroy();
|
|
683
|
+ ((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RNCWebView) webView);
|
|
684
|
+ ((RNCWebView) webView).cleanupCallbacksAndDestroy();
|
685
|
685
|
}
|
686
|
686
|
|
687
|
687
|
protected WebView.PictureListener getPictureListener() {
|