From c21943fa3e48e0e26d26ae31b595ca64d886a46f Mon Sep 17 00:00:00 2001 From: Pawel Lewandowski Date: Thu, 26 Mar 2015 08:39:03 +0100 Subject: [PATCH 01/10] inAppBrowser will allow back-to-the-app-redirections using application's custom scheme scheme can be configured in config.xml using "CustomAppScheme" proererty --- src/android/InAppBrowser.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 217e48e1c..aca3840cd 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -57,6 +57,7 @@ Licensed to the Apache Software Foundation (ASF) under one import org.apache.cordova.LOG; import org.apache.cordova.PluginManager; import org.apache.cordova.PluginResult; +import org.apache.cordova.CordovaPreferences; import org.json.JSONException; import org.json.JSONObject; @@ -84,6 +85,11 @@ public class InAppBrowser extends CordovaPlugin { private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; private static final String HARDWARE_BACK_BUTTON = "hardwareback"; + /* + Configuration property. Custom applicaiton scheme to be handeld in a _system. + */ + private static final String CUSTOM_APPLICATION_SCHEME = "CustomAppScheme"; + private InAppBrowserDialog dialog; private WebView inAppWebView; private EditText edittext; @@ -113,7 +119,7 @@ public boolean execute(String action, CordovaArgs args, final CallbackContext ca } final String target = t; final HashMap features = parseFeature(args.optString(2)); - + Log.d(LOG_TAG, "target = " + target); this.cordova.getActivity().runOnUiThread(new Runnable() { @@ -772,6 +778,7 @@ public InAppBrowserClient(CordovaWebView webView, EditText mEditText) { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); + final CordovaPreferences preferences = Config.getPreferences(); String newloc = ""; if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) { newloc = url; @@ -827,6 +834,18 @@ else if (url.startsWith("sms:")) { LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString()); } } + else if (url.startsWith(preferences.getString(CUSTOM_APPLICATION_SCHEME, "!@#$"))) { + try { + final Intent intent = new Intent(Intent.ACTION_VIEW); + final Uri uri = Uri.parse(url); + intent.setData(uri); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + cordova.getActivity().startActivity(intent); + } catch (final android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error during redirection " + url + ":" + e.toString()); + } + newloc = ""; + } else { newloc = "http://" + url; } From ebca6c767767e46ffee5356cb7433794740f188d Mon Sep 17 00:00:00 2001 From: Pawel Lewandowski Date: Thu, 26 Mar 2015 12:31:41 +0100 Subject: [PATCH 02/10] inAppBrowser will not show the error while redirecting back to application --- src/android/InAppBrowser.java | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index aca3840cd..3b7ac874f 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -777,8 +777,23 @@ public InAppBrowserClient(CordovaWebView webView, EditText mEditText) { */ @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { + // handle back to application redirect without processing url by webView + final CordovaPreferences preferences = Config.getPreferences(); + if (url.startsWith(preferences.getString(CUSTOM_APPLICATION_SCHEME, "!@#$"))) { + try { + final Intent intent = new Intent(Intent.ACTION_VIEW); + final Uri uri = Uri.parse(url); + intent.setData(uri); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + cordova.getActivity().startActivity(intent); + closeDialog(); + return; + } catch (final android.content.ActivityNotFoundException e) { + LOG.e(LOG_TAG, "Error during redirection " + url + ":" + e.toString()); + } + } + super.onPageStarted(view, url, favicon); - final CordovaPreferences preferences = Config.getPreferences(); String newloc = ""; if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) { newloc = url; @@ -834,18 +849,6 @@ else if (url.startsWith("sms:")) { LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString()); } } - else if (url.startsWith(preferences.getString(CUSTOM_APPLICATION_SCHEME, "!@#$"))) { - try { - final Intent intent = new Intent(Intent.ACTION_VIEW); - final Uri uri = Uri.parse(url); - intent.setData(uri); - intent.addCategory(Intent.CATEGORY_BROWSABLE); - cordova.getActivity().startActivity(intent); - } catch (final android.content.ActivityNotFoundException e) { - LOG.e(LOG_TAG, "Error during redirection " + url + ":" + e.toString()); - } - newloc = ""; - } else { newloc = "http://" + url; } From 5fbd28fa4730d03c500143470bff0f58ef35b716 Mon Sep 17 00:00:00 2001 From: Robert Szuba Date: Fri, 8 May 2015 12:13:49 +0200 Subject: [PATCH 03/10] OAUTH-773 disable back button functionality for android --- src/android/InAppBrowser.java | 14 ++++++++++++++ src/android/InAppBrowserDialog.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 3b7ac874f..e6342f63c 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -84,6 +84,7 @@ public class InAppBrowser extends CordovaPlugin { private static final String CLEAR_ALL_CACHE = "clearcache"; private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; private static final String HARDWARE_BACK_BUTTON = "hardwareback"; + private static final String DISMISSABLE_WITH_BACK_BUTTON = "dismissablewithbackbutton"; /* Configuration property. Custom applicaiton scheme to be handeld in a _system. @@ -100,6 +101,7 @@ public class InAppBrowser extends CordovaPlugin { private boolean clearAllCache= false; private boolean clearSessionCache=false; private boolean hadwareBackButton=true; + private boolean dismissableWithBackButton = true; /** * Executes the request and returns PluginResult. @@ -425,6 +427,14 @@ public boolean hardwareBack() { return hadwareBackButton; } + /** + * Has the user set that back button can dismiss the dialog + * @return + */ + public boolean isDismissableWithBackButton() { + return dismissableWithBackButton; + } + /** * Checks to see if it is possible to go forward one page in history, then does so. */ @@ -502,6 +512,10 @@ public String showWebPage(final String url, HashMap features) { if (hardwareBack != null) { hadwareBackButton = hardwareBack.booleanValue(); } + Boolean dismissable = features.get(DISMISSABLE_WITH_BACK_BUTTON); + if (dismissable != null) { + dismissableWithBackButton = dismissable.booleanValue(); + } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); diff --git a/src/android/InAppBrowserDialog.java b/src/android/InAppBrowserDialog.java index d70172023..a00b0ffef 100644 --- a/src/android/InAppBrowserDialog.java +++ b/src/android/InAppBrowserDialog.java @@ -50,7 +50,7 @@ public void onBackPressed () { // because it does a clean up if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) { this.inAppBrowser.goBack(); - } else { + } else if (this.inAppBrowser.isDismissableWithBackButton()) { this.inAppBrowser.closeDialog(); } } From 71bb6bd0da76b16bf43ab06066bb3de9c13be951 Mon Sep 17 00:00:00 2001 From: Robert Szuba Date: Fri, 8 May 2015 12:22:48 +0200 Subject: [PATCH 04/10] OAUTH-773 updated README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 47bbac04c..ed98655df 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,8 @@ instance, or the system browser. - __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened - __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`. - - __hardwareback__: set to `yes` to use the hardware back button to navigate backwards through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will close. The default value is `yes`, so you must set it to `no` if you want the back button to simply close the InAppBrowser. + - __hardwareback__: set to `yes` to use the hardware back button to navigate backwards through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will close if `dismissablewithbackbutton` is set to `yes`. The default value is `yes`, so you must set it to `no` if you want the back button to simply close the InAppBrowser or to do nothing (check `dismissablewithbackbutton` option). + - __dismissablewithbackbutton__: set to `no` to prevent the webview dismiss on back button pressed (when there's no previous page or `hardwareback` is set to `no`). Default value is `yes`. iOS only: From f0c2258433725d9f04b1b97837230c6b04843e07 Mon Sep 17 00:00:00 2001 From: Pawel Lewandowski Date: Thu, 20 Aug 2015 13:00:20 +0200 Subject: [PATCH 05/10] MS-608, fixed statusBar overlapping issue within inAppBrowser view --- src/ios/CDVInAppBrowser.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m index 6d141d3e8..971a591b4 100644 --- a/src/ios/CDVInAppBrowser.m +++ b/src/ios/CDVInAppBrowser.m @@ -724,6 +724,13 @@ - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition - (void)viewDidLoad { + CGRect frame = [UIApplication sharedApplication].statusBarFrame; + UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:frame]; + bgToolbar.barStyle = UIBarStyleDefault; + bgToolbar.tintColor = [UIColor whiteColor]; + bgToolbar.barTintColor = [UIColor whiteColor]; + [self.view addSubview:bgToolbar]; + [super viewDidLoad]; } From efb781a44087995b91dcb7dfe17b54460c43d6bc Mon Sep 17 00:00:00 2001 From: Pawel Lewandowski Date: Thu, 3 Sep 2015 07:42:16 +0200 Subject: [PATCH 06/10] inAppBrowser will attempt to retry failing redirect using system once --- src/ios/CDVInAppBrowser.m | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m index 971a591b4..d23219c90 100644 --- a/src/ios/CDVInAppBrowser.m +++ b/src/ios/CDVInAppBrowser.m @@ -36,6 +36,7 @@ Licensed to the Apache Software Foundation (ASF) under one @interface CDVInAppBrowser () { NSInteger _previousStatusBarStyle; + BOOL _retryFailingRequest; } @end @@ -45,6 +46,7 @@ - (void)pluginInitialize { _previousStatusBarStyle = -1; _callbackIdPattern = nil; + _retryFailingRequest = YES; } - (void)onReset @@ -419,13 +421,20 @@ - (void)webViewDidFinishLoad:(UIWebView*)theWebView - (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error { - if (self.callbackId != nil) { - NSString* url = [self.inAppBrowserViewController.currentURL absoluteString]; - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR - messageAsDictionary:@{@"type":@"loaderror", @"url":url, @"code": [NSNumber numberWithInteger:error.code], @"message": error.localizedDescription}]; - [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; - - [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; + if (_retryFailingRequest) { + _retryFailingRequest = NO; + [self openInSystem:error.userInfo[@"NSErrorFailingURLStringKey"]]; + return; + } else { + _retryFailingRequest = YES; + if (self.callbackId != nil) { + NSString* url = [self.inAppBrowserViewController.currentURL absoluteString]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR + messageAsDictionary:@{@"type":@"loaderror", @"url":url, @"code": [NSNumber numberWithInteger:error.code], @"message": error.localizedDescription}]; + [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; + + [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; + } } } @@ -729,6 +738,9 @@ - (void)viewDidLoad bgToolbar.barStyle = UIBarStyleDefault; bgToolbar.tintColor = [UIColor whiteColor]; bgToolbar.barTintColor = [UIColor whiteColor]; +// [[UIBarItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor whiteColor]}]; + + [self.view addSubview:bgToolbar]; [super viewDidLoad]; From a88b95b97936382229384072378f438b10f99ac6 Mon Sep 17 00:00:00 2001 From: Pawel Lewandowski Date: Thu, 3 Sep 2015 08:13:38 +0200 Subject: [PATCH 07/10] added string to url conversion to avoid invalid selector exception --- src/ios/CDVInAppBrowser.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m index d23219c90..d9c2d9dc3 100644 --- a/src/ios/CDVInAppBrowser.m +++ b/src/ios/CDVInAppBrowser.m @@ -423,7 +423,8 @@ - (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error { if (_retryFailingRequest) { _retryFailingRequest = NO; - [self openInSystem:error.userInfo[@"NSErrorFailingURLStringKey"]]; + NSURL *url =[NSURL URLWithString:error.userInfo[@"NSErrorFailingURLStringKey"]]; + [self openInSystem:url]; return; } else { _retryFailingRequest = YES; From 839cdf1278e0ddf0c248fa2d383acc61bb4eb882 Mon Sep 17 00:00:00 2001 From: Pawel Lewandowski Date: Fri, 18 Sep 2015 09:26:27 +0200 Subject: [PATCH 08/10] changed application scheme property name --- src/android/InAppBrowser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index e6342f63c..9b8252c8b 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -89,7 +89,7 @@ public class InAppBrowser extends CordovaPlugin { /* Configuration property. Custom applicaiton scheme to be handeld in a _system. */ - private static final String CUSTOM_APPLICATION_SCHEME = "CustomAppScheme"; + private static final String CUSTOM_APPLICATION_SCHEME = "kOGAppScheme"; private InAppBrowserDialog dialog; private WebView inAppWebView; From 7dc06fa350b667060116557fcee31c6b11e22126 Mon Sep 17 00:00:00 2001 From: Pawel Lewandowski Date: Wed, 27 Apr 2016 08:47:31 +0200 Subject: [PATCH 09/10] removed application scheme property and detecting if there is an activity which can handle the uri --- src/android/InAppBrowser.java | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index c7f0b48b2..7821429b2 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -22,6 +22,8 @@ Licensed to the Apache Software Foundation (ASF) under one import android.content.Context; import android.content.Intent; import android.provider.Browser; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; @@ -67,6 +69,7 @@ Licensed to the Apache Software Foundation (ASF) under one import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashMap; +import java.util.List; import java.util.StringTokenizer; @SuppressLint("SetJavaScriptEnabled") @@ -89,11 +92,6 @@ public class InAppBrowser extends CordovaPlugin { private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction"; private static final String DISMISSABLE_WITH_BACK_BUTTON = "dismissablewithbackbutton"; - /* - Configuration property. Custom applicaiton scheme to be handeld in a _system. - */ - private static final String CUSTOM_APPLICATION_SCHEME = "kOGAppScheme"; - private InAppBrowserDialog dialog; private WebView inAppWebView; private EditText edittext; @@ -810,23 +808,16 @@ public InAppBrowserClient(CordovaWebView webView, EditText mEditText) { */ @Override public boolean shouldOverrideUrlLoading(WebView webView, String url) { - // handle back to application redirect without processing url by webView - final CordovaPreferences preferences = Config.getPreferences(); - if (url.startsWith(preferences.getString(CUSTOM_APPLICATION_SCHEME, "!@#$"))) { - try { - final Intent intent = new Intent(Intent.ACTION_VIEW); - final Uri uri = Uri.parse(url); - intent.setData(uri); - intent.addCategory(Intent.CATEGORY_BROWSABLE); - cordova.getActivity().startActivity(intent); - closeDialog(); - return; - } catch (final android.content.ActivityNotFoundException e) { - LOG.e(LOG_TAG, "Error during redirection " + url + ":" + e.toString()); - } + // handle back to application redirect without processing url by webView + final Intent customSchemeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + final PackageManager packageManager = cordova.getActivity().getApplicationContext().getPackageManager(); + final List resolvedActivities = packageManager.queryIntentActivities(customSchemeIntent, 0); + if(resolvedActivities.size() > 0) { + cordova.getActivity().startActivity(customSchemeIntent); + closeDialog(); + return true; } - super.onPageStarted(view, url, favicon); String newloc = ""; if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) { newloc = url; From 01968d06004645fb6289d35c1ba31eb048c8620d Mon Sep 17 00:00:00 2001 From: Pawel Lewandowski Date: Fri, 13 May 2016 17:14:37 +0200 Subject: [PATCH 10/10] inAppBrowser should attempt to dispatch intents only in case it is not capable of handling redirection --- src/android/InAppBrowser.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 7821429b2..b49aff007 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -812,11 +812,6 @@ public boolean shouldOverrideUrlLoading(WebView webView, String url) { final Intent customSchemeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); final PackageManager packageManager = cordova.getActivity().getApplicationContext().getPackageManager(); final List resolvedActivities = packageManager.queryIntentActivities(customSchemeIntent, 0); - if(resolvedActivities.size() > 0) { - cordova.getActivity().startActivity(customSchemeIntent); - closeDialog(); - return true; - } String newloc = ""; if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) { @@ -870,6 +865,10 @@ else if (url.startsWith("sms:")) { } catch (android.content.ActivityNotFoundException e) { LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString()); } + } else if(resolvedActivities.size() > 0) { + cordova.getActivity().startActivity(customSchemeIntent); + closeDialog(); + return true; } return false; }