@@ -170,33 +170,10 @@ public void run() {
170
170
Boolean shouldAllowNavigation = null ;
171
171
if (url .startsWith ("javascript:" )) {
172
172
shouldAllowNavigation = true ;
173
+ } else {
174
+ shouldAllowNavigation = isURLWhiteListed (url );
173
175
}
174
- if (shouldAllowNavigation == null ) {
175
- try {
176
- Method iuw = Config .class .getMethod ("isUrlWhiteListed" , String .class );
177
- shouldAllowNavigation = (Boolean )iuw .invoke (null , url );
178
- } catch (NoSuchMethodException e ) {
179
- LOG .d (LOG_TAG , e .getLocalizedMessage ());
180
- } catch (IllegalAccessException e ) {
181
- LOG .d (LOG_TAG , e .getLocalizedMessage ());
182
- } catch (InvocationTargetException e ) {
183
- LOG .d (LOG_TAG , e .getLocalizedMessage ());
184
- }
185
- }
186
- if (shouldAllowNavigation == null ) {
187
- try {
188
- Method gpm = webView .getClass ().getMethod ("getPluginManager" );
189
- PluginManager pm = (PluginManager )gpm .invoke (webView );
190
- Method san = pm .getClass ().getMethod ("shouldAllowNavigation" , String .class );
191
- shouldAllowNavigation = (Boolean )san .invoke (pm , url );
192
- } catch (NoSuchMethodException e ) {
193
- LOG .d (LOG_TAG , e .getLocalizedMessage ());
194
- } catch (IllegalAccessException e ) {
195
- LOG .d (LOG_TAG , e .getLocalizedMessage ());
196
- } catch (InvocationTargetException e ) {
197
- LOG .d (LOG_TAG , e .getLocalizedMessage ());
198
- }
199
- }
176
+
200
177
// load in webview
201
178
if (Boolean .TRUE .equals (shouldAllowNavigation )) {
202
179
LOG .d (LOG_TAG , "loading in webview" );
@@ -302,6 +279,47 @@ public void run() {
302
279
return true ;
303
280
}
304
281
282
+ /**
283
+ * Is the URL or Scheme WhiteListed
284
+ * This code exists for compatibility between 3.x and 4.x versions of Cordova.
285
+ * Previously the Config class had a static method, isUrlWhitelisted(). That
286
+ * responsibility has been moved to the plugins, with an aggregating method in
287
+ * PluginManager.
288
+ */
289
+ * @ param url , the URL as a String
290
+ * @ return true if WhiteListed , otherwise null or false
291
+ */
292
+ private Boolean isURLWhiteListed (String url ) {
293
+ Boolean shouldAllowNavigation = null ;
294
+ if (shouldAllowNavigation == null ) {
295
+ try {
296
+ Method iuw = Config .class .getMethod ("isUrlWhiteListed" , String .class );
297
+ shouldAllowNavigation = (Boolean )iuw .invoke (null , url );
298
+ } catch (NoSuchMethodException e ) {
299
+ LOG .d (LOG_TAG , e .getLocalizedMessage ());
300
+ } catch (IllegalAccessException e ) {
301
+ LOG .d (LOG_TAG , e .getLocalizedMessage ());
302
+ } catch (InvocationTargetException e ) {
303
+ LOG .d (LOG_TAG , e .getLocalizedMessage ());
304
+ }
305
+ }
306
+ if (shouldAllowNavigation == null ) {
307
+ try {
308
+ Method gpm = webView .getClass ().getMethod ("getPluginManager" );
309
+ PluginManager pm = (PluginManager )gpm .invoke (webView );
310
+ Method san = pm .getClass ().getMethod ("shouldAllowNavigation" , String .class );
311
+ shouldAllowNavigation = (Boolean )san .invoke (pm , url );
312
+ } catch (NoSuchMethodException e ) {
313
+ LOG .d (LOG_TAG , e .getLocalizedMessage ());
314
+ } catch (IllegalAccessException e ) {
315
+ LOG .d (LOG_TAG , e .getLocalizedMessage ());
316
+ } catch (InvocationTargetException e ) {
317
+ LOG .d (LOG_TAG , e .getLocalizedMessage ());
318
+ }
319
+ }
320
+ return shouldAllowNavigation ;
321
+ }
322
+
305
323
/**
306
324
* Called when the view navigates.
307
325
*/
@@ -1110,6 +1128,24 @@ else if (url.startsWith("sms:")) {
1110
1128
LOG .e (LOG_TAG , "Error sending sms " + url + ":" + e .toString ());
1111
1129
}
1112
1130
}
1131
+ // Test for whitelisted custom scheme names, less than 20 chars long, like mycoolapp: or twitteroauthresponse: (Twitter Oauth Response)
1132
+ else if (url .matches ("^[a-z]{0,20}://.*?$" )) {
1133
+ if (Boolean .TRUE .equals (isURLWhiteListed (url ))) {
1134
+ try {
1135
+ LOG .w ("STEVE IN InAppBrowser.java, whiteliste url SUCCESS: " , url );
1136
+ JSONObject obj = new JSONObject ();
1137
+ obj .put ("type" , "customscheme" );
1138
+ obj .put ("url" , url );
1139
+ sendUpdate (obj , true );
1140
+ return true ;
1141
+ } catch (JSONException ex ) {
1142
+ LOG .e (LOG_TAG , "Custom Scheme URI passed in has caused a JSON error." );
1143
+ }
1144
+ } else {
1145
+ LOG .w ("STEVE IN InAppBrowser.java, whitelisted url FAILURE: " , url );
1146
+ }
1147
+ }
1148
+
1113
1149
return false ;
1114
1150
}
1115
1151
0 commit comments