From 4f61531422147cfe4a8fa09bb37f8f2e77a73c2d Mon Sep 17 00:00:00 2001 From: macdonst Date: Fri, 27 Jan 2012 12:02:31 -0500 Subject: [PATCH] Fixing a timing issue with the web view history not being cleared properly --- .../src/com/phonegap/CordovaWebViewClient.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/framework/src/com/phonegap/CordovaWebViewClient.java b/framework/src/com/phonegap/CordovaWebViewClient.java index bf7233e2..fbb1f9f4 100755 --- a/framework/src/com/phonegap/CordovaWebViewClient.java +++ b/framework/src/com/phonegap/CordovaWebViewClient.java @@ -27,6 +27,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; import android.net.Uri; import android.net.http.SslError; +import android.util.Log; import android.view.View; import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; @@ -40,6 +41,7 @@ public class CordovaWebViewClient extends WebViewClient { private static final String TAG = "Cordova"; DroidGap ctx; + private boolean doClearHistory = false; /** * Constructor. @@ -185,6 +187,7 @@ public class CordovaWebViewClient extends WebViewClient { // Clear history so history.back() doesn't do anything. // So we can reinit() native side CallbackServer & PluginManager. view.clearHistory(); + this.doClearHistory = true; } /** @@ -197,6 +200,17 @@ public class CordovaWebViewClient extends WebViewClient { public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); + /** + * Because of a timing issue we need to clear this history in onPageFinished as well as + * onPageStarted. However we only want to do this if the doClearHistory boolean is set to + * true. You see when you load a url with a # in it which is common in jQuery applications + * onPageStared is not called. Clearing the history at that point would break jQuery apps. + */ + if (this.doClearHistory) { + view.clearHistory(); + this.doClearHistory = false; + } + // Clear timeout flag this.ctx.loadUrlTimeout++;