diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java index 5bf232e3..664fe353 100755 --- a/framework/src/org/apache/cordova/App.java +++ b/framework/src/org/apache/cordova/App.java @@ -161,7 +161,7 @@ public class App extends Plugin { * Clear page history for the app. */ public void clearHistory() { - ((DroidGap)this.ctx).clearHistory(); + webView.clearHistory(); } /** @@ -169,7 +169,7 @@ public class App extends Plugin { * This is the same as pressing the backbutton on Android device. */ public void backHistory() { - ((DroidGap)this.ctx).backHistory(); + webView.backHistory(); } /** diff --git a/framework/src/org/apache/cordova/CordovaChromeClient.java b/framework/src/org/apache/cordova/CordovaChromeClient.java index f5cebb97..b915bc83 100755 --- a/framework/src/org/apache/cordova/CordovaChromeClient.java +++ b/framework/src/org/apache/cordova/CordovaChromeClient.java @@ -64,7 +64,10 @@ public class CordovaChromeClient extends WebChromeClient { appView = app; } - + public void setWebView(CordovaWebView view) + { + appView = view; + } /** * Tell the client to display a javascript alert dialog. diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index ffc686df..1b139f38 100644 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -270,6 +270,11 @@ public class CordovaWebView extends WebView { return false; } + /** + * We override loadUrl so that we can track the back history + * @see android.webkit.WebView#loadUrl(java.lang.String) + */ + @Override public void loadUrl(String url) { @@ -283,25 +288,53 @@ public class CordovaWebView extends WebView { else { this.baseUrl = this.url + "/"; } - } - - // Create callback server and plugin manager - if (callbackServer == null) { - callbackServer = new CallbackServer(); - callbackServer.init(url); + // Create callback server and plugin manager + if (callbackServer == null) { + callbackServer = new CallbackServer(); + callbackServer.init(url); + } + else { + callbackServer.reinit(url); + } + pluginManager.init(); + + this.urls.push(url); } - else { - callbackServer.reinit(url); - } - pluginManager.init(); - - this.urls.push(url); } - super.loadUrl(url); } + + + public void loadUrl(final String url, final int time) + { + // If not first page of app, then load immediately + if (this.urls.size() > 0) { + this.loadUrl(url); + } + + if (!url.startsWith("javascript:")) { + LOG.d(TAG, "DroidGap.loadUrl(%s, %d)", url, time); + } + + final CordovaWebView me = this; + Runnable runnable = new Runnable() { + public void run() { + try { + synchronized(this) { + this.wait(time); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + //I'm pretty sure this has to be on the UI thread + me.loadUrl(url); + } + }; + Thread thread = new Thread(runnable); + thread.start(); + } public void sendJavascript(String statement) { callbackServer.sendJavascript(statement); @@ -330,4 +363,29 @@ public class CordovaWebView extends WebView { public void pushUrl(String url) { urls.push(url); } + + /** + * Go to previous page in history. (We manage our own history) + * + * @return true if we went back, false if we are already at top + */ + public boolean backHistory() { + + // Check webview first to see if there is a history + // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior) + if (this.canGoBack()) { + this.goBack(); + return true; + } + + // If our managed history has prev url + if (this.urls.size() > 1) { + this.urls.pop(); // Pop current url + String url = this.urls.pop(); // Pop prev url that we want to load, since it will be added back by loadUrl() + loadUrl(url); + return true; + } + + return false; + } } diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java index 20dbcbc0..7338ed21 100755 --- a/framework/src/org/apache/cordova/CordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java @@ -61,6 +61,11 @@ public class CordovaWebViewClient extends WebViewClient { appView = view; } + public void setWebView(CordovaWebView view) + { + appView = view; + } + /** * Give the host application a chance to take over the control when a new url * is about to be loaded in the current WebView. diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index 85a217fd..e523b00a 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -531,30 +531,7 @@ public class DroidGap extends Activity implements CordovaInterface { } } - /** - * Go to previous page in history. (We manage our own history) - * - * @return true if we went back, false if we are already at top - */ - public boolean backHistory() { - - // Check webview first to see if there is a history - // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior) - if (this.appView.canGoBack()) { - this.appView.goBack(); - return true; - } - - // If our managed history has prev url - if (this.urls.size() > 1) { - this.urls.pop(); // Pop current url - String url = this.urls.pop(); // Pop prev url that we want to load, since it will be added back by loadUrl() - this.loadUrl(url); - return true; - } - - return false; - } + @Override /** @@ -1208,4 +1185,8 @@ public class DroidGap extends Activity implements CordovaInterface { return this.bound; } + public boolean backHistory() { + return appView.backHistory(); + } + } diff --git a/test/src/org/apache/cordova/test/PhoneGapSplash.java b/test/src/org/apache/cordova/test/PhoneGapSplash.java index 104720df..bda34b3e 100644 --- a/test/src/org/apache/cordova/test/PhoneGapSplash.java +++ b/test/src/org/apache/cordova/test/PhoneGapSplash.java @@ -14,7 +14,7 @@ public class PhoneGapSplash extends Activity { setContentView(R.layout.main); phoneGap = (CordovaWebView) findViewById(R.id.phoneGapView); - //phoneGap.loadUrl("file:///android_asset/index.html", 5000); + phoneGap.loadUrl("file:///android_asset/index.html", 5000); } public void onDestroy() diff --git a/test/src/org/apache/cordova/test/WebDriverTest.java b/test/src/org/apache/cordova/test/WebDriverTest.java index 5cf7dc43..31a3cca7 100644 --- a/test/src/org/apache/cordova/test/WebDriverTest.java +++ b/test/src/org/apache/cordova/test/WebDriverTest.java @@ -34,6 +34,8 @@ public class WebDriverTest extends ActivityInstrumentationTestCase2