This commit is contained in:
Jesse MacFadyen 2015-03-04 00:13:29 -08:00
commit 9de15ac8bf
2 changed files with 28 additions and 2 deletions

View File

@ -81,6 +81,7 @@ public class InAppBrowser extends CordovaPlugin {
private static final String LOAD_ERROR_EVENT = "loaderror"; private static final String LOAD_ERROR_EVENT = "loaderror";
private static final String CLEAR_ALL_CACHE = "clearcache"; private static final String CLEAR_ALL_CACHE = "clearcache";
private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
private static final String HARDWARE_BACK_BUTTON = "hardwareback";
private InAppBrowserDialog dialog; private InAppBrowserDialog dialog;
private WebView inAppWebView; private WebView inAppWebView;
@ -90,6 +91,7 @@ public class InAppBrowser extends CordovaPlugin {
private boolean openWindowHidden = false; private boolean openWindowHidden = false;
private boolean clearAllCache= false; private boolean clearAllCache= false;
private boolean clearSessionCache=false; private boolean clearSessionCache=false;
private boolean hadwareBackButton=false;
/** /**
* Executes the request and returns PluginResult. * Executes the request and returns PluginResult.
@ -393,12 +395,28 @@ public class InAppBrowser extends CordovaPlugin {
/** /**
* Checks to see if it is possible to go back one page in history, then does so. * Checks to see if it is possible to go back one page in history, then does so.
*/ */
private void goBack() { public void goBack() {
if (this.inAppWebView.canGoBack()) { if (this.inAppWebView.canGoBack()) {
this.inAppWebView.goBack(); this.inAppWebView.goBack();
} }
} }
/**
* Can the web browser go back?
* @return boolean
*/
public boolean canGoBack() {
return this.inAppWebView.canGoBack();
}
/**
* Has the user set the hardware back button to go back
* @return boolean
*/
public boolean hardwareBack() {
return hadwareBackButton;
}
/** /**
* Checks to see if it is possible to go forward one page in history, then does so. * Checks to see if it is possible to go forward one page in history, then does so.
*/ */
@ -458,6 +476,10 @@ public class InAppBrowser extends CordovaPlugin {
if (hidden != null) { if (hidden != null) {
openWindowHidden = hidden.booleanValue(); openWindowHidden = hidden.booleanValue();
} }
Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
if (hardwareBack != null) {
hadwareBackButton = hardwareBack.booleanValue();
}
Boolean cache = features.get(CLEAR_ALL_CACHE); Boolean cache = features.get(CLEAR_ALL_CACHE);
if (cache != null) { if (cache != null) {
clearAllCache = cache.booleanValue(); clearAllCache = cache.booleanValue();

View File

@ -48,7 +48,11 @@ public class InAppBrowserDialog extends Dialog {
} else { } else {
// better to go through the in inAppBrowser // better to go through the in inAppBrowser
// because it does a clean up // because it does a clean up
this.inAppBrowser.closeDialog(); if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) {
this.inAppBrowser.goBack();
} else {
this.inAppBrowser.closeDialog();
}
} }
} }
} }