diff --git a/library/build.gradle b/library/build.gradle index 033b014..d91a030 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -4,7 +4,7 @@ plugins { } def group = 'com.github.hjhrq1991' -def libraryVersion = '1.1.5' +def libraryVersion = '1.1.6' // Because the components are created only during the afterEvaluate phase, you must // configure your publications using the afterEvaluate() lifecycle method. diff --git a/library/src/main/java/com/hjhrq1991/library/BridgeConfig.java b/library/src/main/java/com/hjhrq1991/library/BridgeConfig.java index c4abc0a..2946279 100644 --- a/library/src/main/java/com/hjhrq1991/library/BridgeConfig.java +++ b/library/src/main/java/com/hjhrq1991/library/BridgeConfig.java @@ -18,4 +18,9 @@ public class BridgeConfig { * 自定义桥名 */ public static List customBridge = Collections.singletonList(defaultBridge); + + /** + * 需要过滤,不注入js桥的域名 + */ + public static List filterDomain; } diff --git a/library/src/main/java/com/hjhrq1991/library/BridgeWebViewClient.java b/library/src/main/java/com/hjhrq1991/library/BridgeWebViewClient.java index 7ee6953..731bef5 100644 --- a/library/src/main/java/com/hjhrq1991/library/BridgeWebViewClient.java +++ b/library/src/main/java/com/hjhrq1991/library/BridgeWebViewClient.java @@ -2,6 +2,7 @@ import android.graphics.Bitmap; import android.net.http.SslError; +import android.text.TextUtils; import android.view.KeyEvent; import android.webkit.ClientCertRequest; import android.webkit.HttpAuthHandler; @@ -120,19 +121,31 @@ public void onPageFinished(WebView view, String url) { if (bridgeWebViewClientListener != null) { bridgeWebViewClientListener.onPageFinishedFirst(view, url); } - //modify:hjhrq1991,web为渲染即跳转导致系统未调用onPageStarted就调用onPageFinished方法引起的js桥初始化失败 - if (BridgeConfig.toLoadJs != null && !url.contains("about:blank") && !isRedirected) { - for (int i = 0; i < BridgeConfig.customBridge.size(); i++) { - String bridgeName = BridgeConfig.customBridge.get(i); - BridgeUtil.webViewLoadLocalJs(view, BridgeConfig.toLoadJs, BridgeConfig.defaultBridge, bridgeName); + boolean canLoadJS = true; + //modify:hjhrq1991,检查是否需要注入js + if (BridgeConfig.filterDomain != null && !BridgeConfig.filterDomain.isEmpty()) { + for (int i = 0; i < BridgeConfig.filterDomain.size(); i++) { + String filter = BridgeConfig.filterDomain.get(i); + if (!TextUtils.isEmpty(url) && url.contains(filter)) { + canLoadJS = false; + } } } + if (canLoadJS){ + //modify:hjhrq1991,web为渲染即跳转导致系统未调用onPageStarted就调用onPageFinished方法引起的js桥初始化失败 + if (BridgeConfig.toLoadJs != null && !url.contains("about:blank") && !isRedirected) { + for (int i = 0; i < BridgeConfig.customBridge.size(); i++) { + String bridgeName = BridgeConfig.customBridge.get(i); + BridgeUtil.webViewLoadLocalJs(view, BridgeConfig.toLoadJs, BridgeConfig.defaultBridge, bridgeName); + } + } - if (webView.getStartupMessage() != null) { - for (Message m : webView.getStartupMessage()) { - webView.dispatchMessage(m); + if (webView.getStartupMessage() != null) { + for (Message m : webView.getStartupMessage()) { + webView.dispatchMessage(m); + } + webView.setStartupMessage(null); } - webView.setStartupMessage(null); } if (bridgeWebViewClientListener != null) {