13
13
import android .os .HandlerThread ;
14
14
import android .util .Log ;
15
15
import android .webkit .ValueCallback ;
16
- import android .webkit .WebResourceRequest ;
17
- import android .webkit .WebResourceResponse ;
18
16
import android .webkit .WebSettings ;
19
17
import android .webkit .WebView ;
20
- import android .webkit .WebViewClient ;
21
18
import android .content .SharedPreferences ;
22
19
23
20
import com .getcapacitor .android .BuildConfig ;
@@ -108,6 +105,7 @@ public class Bridge {
108
105
private final WebView webView ;
109
106
public final CordovaInterfaceImpl cordovaInterface ;
110
107
private CordovaPreferences preferences ;
108
+ private BridgeWebViewClient webViewClient ;
111
109
112
110
// Our MessageHandler for sending and receiving data to the WebView
113
111
private final MessageHandler msgHandler ;
@@ -143,6 +141,7 @@ public class Bridge {
143
141
public Bridge (Activity context , WebView webView , List <Class <? extends Plugin >> initialPlugins , CordovaInterfaceImpl cordovaInterface , PluginManager pluginManager , CordovaPreferences preferences ) {
144
142
this .context = context ;
145
143
this .webView = webView ;
144
+ this .webViewClient = new BridgeWebViewClient (this );
146
145
this .initialPlugins = initialPlugins ;
147
146
this .cordovaInterface = cordovaInterface ;
148
147
this .preferences = preferences ;
@@ -213,36 +212,7 @@ private void loadWebView() {
213
212
Log .d (LOG_TAG , "Loading app at " + appUrl );
214
213
215
214
webView .setWebChromeClient (new BridgeWebChromeClient (this ));
216
- webView .setWebViewClient (new WebViewClient () {
217
- @ Override
218
- public WebResourceResponse shouldInterceptRequest (WebView view , WebResourceRequest request ) {
219
- return localServer .shouldInterceptRequest (request );
220
- }
221
-
222
- @ Override
223
- public boolean shouldOverrideUrlLoading (WebView view , WebResourceRequest request ) {
224
- Uri url = request .getUrl ();
225
- return launchIntent (url );
226
- }
227
-
228
- @ Override
229
- public boolean shouldOverrideUrlLoading (WebView view , String url ) {
230
- return launchIntent (Uri .parse (url ));
231
- }
232
-
233
- private boolean launchIntent (Uri url ) {
234
- if (!url .toString ().contains (appUrl ) && !appAllowNavigationMask .matches (url .getHost ())) {
235
- try {
236
- Intent openIntent = new Intent (Intent .ACTION_VIEW , url );
237
- getContext ().startActivity (openIntent );
238
- } catch (ActivityNotFoundException e ) {
239
- // TODO - trigger an event
240
- }
241
- return true ;
242
- }
243
- return false ;
244
- }
245
- });
215
+ webView .setWebViewClient (this .webViewClient );
246
216
247
217
if (!isDeployDisabled () && !isNewBinary ()) {
248
218
SharedPreferences prefs = getContext ().getSharedPreferences (com .getcapacitor .plugin .WebView .WEBVIEW_PREFS_NAME , Activity .MODE_PRIVATE );
@@ -255,6 +225,19 @@ private boolean launchIntent(Uri url) {
255
225
webView .loadUrl (appUrl );
256
226
}
257
227
228
+ public boolean launchIntent (Uri url ) {
229
+ if (!url .toString ().contains (appUrl ) && !appAllowNavigationMask .matches (url .getHost ())) {
230
+ try {
231
+ Intent openIntent = new Intent (Intent .ACTION_VIEW , url );
232
+ getContext ().startActivity (openIntent );
233
+ } catch (ActivityNotFoundException e ) {
234
+ // TODO - trigger an event
235
+ }
236
+ return true ;
237
+ }
238
+ return false ;
239
+ }
240
+
258
241
259
242
private boolean isNewBinary () {
260
243
String versionCode = "" ;
@@ -899,4 +882,13 @@ public WebViewLocalServer getLocalServer() {
899
882
public HostMask getAppAllowNavigationMask () {
900
883
return appAllowNavigationMask ;
901
884
}
885
+
886
+ public BridgeWebViewClient getWebViewClient () {
887
+ return this .webViewClient ;
888
+ }
889
+
890
+ public void setWebViewClient (BridgeWebViewClient client ) {
891
+ this .webViewClient = client ;
892
+ }
893
+
902
894
}
0 commit comments