diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 2b0dbe0fa..9b3388ced 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -133,6 +133,7 @@ public class InAppBrowser extends CordovaPlugin { private boolean hideUrlBar = false; private boolean showFooter = false; private String footerColor = ""; + private String[] allowedSchemes; /** * Executes the request and returns PluginResult. @@ -1110,6 +1111,29 @@ else if (url.startsWith("sms:")) { LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString()); } } + // Test for whitelisted custom scheme names like mycoolapp:// or twitteroauthresponse:// (Twitter Oauth Response) + else if (!url.startsWith("http:") && !url.startsWith("https:") && url.matches("^[a-z]*://.*?$")) { + if (allowedSchemes == null) { + String allowed = preferences.getString("AllowedSchemes", ""); + allowedSchemes = allowed.split(","); + } + if (allowedSchemes != null) { + for (String scheme : allowedSchemes) { + if (url.startsWith(scheme)) { + try { + JSONObject obj = new JSONObject(); + obj.put("type", "customscheme"); + obj.put("url", url); + sendUpdate(obj, true); + return true; + } catch (JSONException ex) { + LOG.e(LOG_TAG, "Custom Scheme URI passed in has caused a JSON error."); + } + } + } + } + } + return false; } @@ -1232,4 +1256,4 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, Str super.onReceivedHttpAuthRequest(view, handler, host, realm); } } -} +} \ No newline at end of file diff --git a/www/inappbrowser.js b/www/inappbrowser.js index 7c3e749e8..3619f173f 100644 --- a/www/inappbrowser.js +++ b/www/inappbrowser.js @@ -36,7 +36,8 @@ 'loadstart': channel.create('loadstart'), 'loadstop': channel.create('loadstop'), 'loaderror': channel.create('loaderror'), - 'exit': channel.create('exit') + 'exit': channel.create('exit'), + 'customscheme': channel.create('customscheme') }; }