@@ -127,10 +127,11 @@ public class InAppBrowser extends CordovaPlugin {
127
127
private static final String FOOTER_COLOR = "footercolor" ;
128
128
private static final String BEFORELOAD = "beforeload" ;
129
129
private static final String FULLSCREEN = "fullscreen" ;
130
+ private static final String ALLOWEDSCHEMES = "allowedschemes" ;
130
131
private static final int MY_PERMISSIONS_REQUEST_RECORD_AUDIO = 101 ;
131
132
private static final int MY_PERMISSIONS_REQUEST_CAMERA = 102 ;
132
133
133
- private static final List customizableOptions = Arrays .asList (CLOSE_BUTTON_CAPTION , TOOLBAR_COLOR , NAVIGATION_COLOR , CLOSE_BUTTON_COLOR , FOOTER_COLOR );
134
+ private static final List customizableOptions = Arrays .asList (CLOSE_BUTTON_CAPTION , TOOLBAR_COLOR , NAVIGATION_COLOR , CLOSE_BUTTON_COLOR , FOOTER_COLOR , ALLOWEDSCHEMES );
134
135
135
136
private InAppBrowserDialog dialog ;
136
137
private WebView inAppWebView ;
@@ -181,6 +182,11 @@ public boolean execute(String action, CordovaArgs args, final CallbackContext ca
181
182
}
182
183
final String target = t ;
183
184
final HashMap <String , String > features = parseFeature (args .optString (2 ));
185
+ final String customscheme = features .get (ALLOWEDSCHEMES );
186
+ if (customscheme != null ) {
187
+ LOG .d (LOG_TAG , "customscheme = " + customscheme );
188
+ allowedSchemes = customscheme .split ("/" );
189
+ }
184
190
185
191
LOG .d (LOG_TAG , "target = " + target );
186
192
@@ -1029,6 +1035,7 @@ public void onClick(View v) {
1029
1035
1030
1036
// WebView
1031
1037
inAppWebView = new WebView (cordova .getActivity ());
1038
+ inAppWebView .setBackgroundColor (Color .WHITE );
1032
1039
inAppWebView .setLayoutParams (new LinearLayout .LayoutParams (LayoutParams .MATCH_PARENT , LayoutParams .MATCH_PARENT ));
1033
1040
inAppWebView .setId (Integer .valueOf (6 ));
1034
1041
// File Chooser Implemented ChromeClient
@@ -1443,29 +1450,37 @@ else if (url.startsWith(INTENT_PROTOCOL_START)) {
1443
1450
}
1444
1451
// Test for whitelisted custom scheme names like mycoolapp:// or twitteroauthresponse:// (Twitter Oauth Response)
1445
1452
else if (!url .startsWith ("http:" ) && !url .startsWith ("https:" ) && url .matches ("^[A-Za-z0-9+.-]*://.*?$" )) {
1446
- if (allowedSchemes == null ) {
1447
- String allowed = preferences .getString ("AllowedSchemes" , null );
1448
- if (allowed != null ) {
1449
- allowedSchemes = allowed .split ("," );
1450
- }
1451
- }
1452
1453
if (allowedSchemes != null ) {
1453
- for (String scheme : allowedSchemes ) {
1454
- if (url .startsWith (scheme )) {
1455
- try {
1456
- JSONObject obj = new JSONObject ();
1457
- obj .put ("type" , "customscheme" );
1458
- obj .put ("url" , url );
1459
- sendUpdate (obj , true );
1454
+ try {
1455
+ for (String scheme : allowedSchemes ) {
1456
+ if (scheme != null && (scheme .equals ("all" ) || url .startsWith (scheme ))) {
1457
+ LOG .d (LOG_TAG , "execute deeplink [" + url + "]" );
1458
+ try {
1459
+ cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (url )));
1460
+ JSONObject obj = new JSONObject ();
1461
+ obj .put ("type" , "customscheme" );
1462
+ obj .put ("url" , url );
1463
+ sendUpdate (obj , true );
1464
+ } catch (ActivityNotFoundException e ) {
1465
+ LOG .e (LOG_TAG , "not installed deeplink app [" + url + "] : " + e .toString ());
1466
+ } catch (JSONException ex ) {
1467
+ LOG .e (LOG_TAG , "Custom Scheme URI passed in has caused a JSON error." );
1468
+ }
1460
1469
override = true ;
1461
- } catch (JSONException ex ) {
1462
- LOG .e (LOG_TAG , "Custom Scheme URI passed in has caused a JSON error." );
1470
+ break ;
1463
1471
}
1464
1472
}
1473
+ if (!override ) {
1474
+ LOG .e (LOG_TAG , "not allowed this scheme [" + url + "]" );
1475
+ }
1476
+ } catch (NullPointerException e ) {
1477
+ LOG .e (LOG_TAG , "scheme is null?! : " + e .toString ());
1465
1478
}
1479
+ } else {
1480
+ LOG .e (LOG_TAG , "no allowedSchemes" );
1466
1481
}
1482
+ return true ;
1467
1483
}
1468
-
1469
1484
if (useBeforeload ) {
1470
1485
this .waitForBeforeload = true ;
1471
1486
}
0 commit comments