Skip to content

Commit 9688fa6

Browse files
committed
fix: added an option(ALLOWEDSCHEMES) with open function instead of customschemes event
1 parent 2d730af commit 9688fa6

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/android/InAppBrowser.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ public class InAppBrowser extends CordovaPlugin {
127127
private static final String FOOTER_COLOR = "footercolor";
128128
private static final String BEFORELOAD = "beforeload";
129129
private static final String FULLSCREEN = "fullscreen";
130+
private static final String ALLOWEDSCHEMES = "allowedschemes";
130131
private static final int MY_PERMISSIONS_REQUEST_RECORD_AUDIO = 101;
131132
private static final int MY_PERMISSIONS_REQUEST_CAMERA = 102;
132133

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);
134135

135136
private InAppBrowserDialog dialog;
136137
private WebView inAppWebView;
@@ -181,6 +182,11 @@ public boolean execute(String action, CordovaArgs args, final CallbackContext ca
181182
}
182183
final String target = t;
183184
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+
}
184190

185191
LOG.d(LOG_TAG, "target = " + target);
186192

@@ -1444,15 +1450,26 @@ else if (url.startsWith(INTENT_PROTOCOL_START)) {
14441450
}
14451451
// Test for whitelisted custom scheme names like mycoolapp:// or twitteroauthresponse:// (Twitter Oauth Response)
14461452
else if (!url.startsWith("http:") && !url.startsWith("https:") && url.matches("^[A-Za-z0-9+.-]*://.*?$")) {
1447-
try {
1448-
JSONObject obj = new JSONObject();
1449-
obj.put("type", "customscheme");
1450-
obj.put("url", url);
1451-
sendUpdate(obj, true);
1452-
override = true;
1453-
} catch (JSONException ex) {
1454-
LOG.e(LOG_TAG, "Custom Scheme URI passed in has caused a JSON error.");
1453+
if (allowedSchemes != null) {
1454+
for (String scheme : allowedSchemes) {
1455+
if (scheme.equals("all") || url.startsWith(scheme)) {
1456+
LOG.d(LOG_TAG, "execute deeplink [" + url + "]");
1457+
try {
1458+
cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
1459+
} catch (ActivityNotFoundException e) {
1460+
LOG.e(LOG_TAG, "not installed deeplink app [" + url + "] : " + e.toString());
1461+
}
1462+
override = true;
1463+
break;
1464+
}
1465+
}
1466+
if (!override) {
1467+
LOG.e(LOG_TAG, "not allowed this scheme [" + url + "]");
1468+
}
1469+
} else {
1470+
LOG.e(LOG_TAG, "no allowedSchemes");
14551471
}
1472+
return true;
14561473
}
14571474
if (useBeforeload) {
14581475
this.waitForBeforeload = true;

0 commit comments

Comments
 (0)