mirror of
https://github.com/status-im/react-native-webview-bridge.git
synced 2026-08-30 21:01:12 +00:00
Fix Android web3 injection on pages with redirects
It still doesn't work on Androids version < 7 though.
This commit is contained in:
+26
-12
@@ -466,20 +466,29 @@ public class WebViewBridgeManager extends ReactWebViewManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
if (url.startsWith("http://") || url.startsWith("https://") ||
|
||||
url.startsWith("file://")) {
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
if (request == null || view == null) {
|
||||
return false;
|
||||
} else {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
view.getContext().startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
Log.d(TAG, "Ignoring " + url + ": " + e.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
|
||||
/*
|
||||
* In order to follow redirects properly, we return null in interceptRequest().
|
||||
* Doing this breaks the web3 injection on the resulting page, so we have to reload to
|
||||
* make sure web3 is available.
|
||||
* */
|
||||
|
||||
if (request.isForMainFrame() && request.isRedirect()) {
|
||||
view.loadUrl(request.getUrl().toString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* API < 24: TODO: implement based on https://github.com/toshiapp/toshi-android-client/blob/f4840d3d24ff60223662eddddceca8586a1be8bb/app/src/main/java/com/toshi/view/activity/webView/ToshiWebClient.kt#L99
|
||||
* */
|
||||
return super.shouldOverrideUrlLoading(view, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -536,6 +545,11 @@ public class WebViewBridgeManager extends ReactWebViewManager {
|
||||
return event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||
String urlStr = request.getUrl().toString();
|
||||
|
||||
Reference in New Issue
Block a user