diff options
-rw-r--r-- | src/com/android/browser/PreloadedTabControl.java | 18 | ||||
-rw-r--r-- | src/com/android/browser/Tab.java | 20 |
2 files changed, 29 insertions, 9 deletions
diff --git a/src/com/android/browser/PreloadedTabControl.java b/src/com/android/browser/PreloadedTabControl.java index ed066f2..4ffe6b4 100644 --- a/src/com/android/browser/PreloadedTabControl.java +++ b/src/com/android/browser/PreloadedTabControl.java @@ -21,6 +21,7 @@ import android.util.Log; import android.webkit.SearchBox; import java.util.Map; +import java.util.regex.Pattern; /** * Class to manage the controlling of preloaded tab. @@ -74,6 +75,7 @@ public class PreloadedTabControl { } maybeSetQuery(query, sb); if (LOGD_ENABLED) Log.d(LOGTAG, "Submitting query " + query); + final String currentUrl = mTab.getUrl(); sb.onsubmit(new SearchBox.SearchBoxListener() { @Override public void onSubmitComplete(boolean called) { @@ -83,7 +85,21 @@ public class PreloadedTabControl { if (LOGD_ENABLED) Log.d(LOGTAG, "Query not submitted; falling back"); loadUrl(fallbackUrl, fallbackHeaders); // make sure that the failed, preloaded URL is cleared from the back stack - mTab.clearBackStackWhenItemAdded(fallbackUrl); + mTab.clearBackStackWhenItemAdded(Pattern.compile( + "^" + Pattern.quote(fallbackUrl) + "$")); + } else { + // ignore the next fragment change, to avoid leaving a blank page in the browser + // after the query has been submitted. + String currentWithoutFragment = Uri.parse(currentUrl) + .buildUpon() + .fragment(null) + .toString(); + mTab.clearBackStackWhenItemAdded( + Pattern.compile( + "^" + + Pattern.quote(currentWithoutFragment) + + "(\\#.*)?" + + "$")); } }}); return true; diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index 3b283cc..8c9dc02 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -84,6 +84,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Map; import java.util.Vector; +import java.util.regex.Pattern; import java.util.zip.GZIPOutputStream; /** @@ -175,7 +176,7 @@ class Tab implements PictureListener { /** * See {@link #clearBackStackWhenItemAdded(String)}. */ - private String mClearHistoryMatchUrl; + private Pattern mClearHistoryUrlPattern; private static synchronized Bitmap getDefaultFavicon(Context context) { if (sDefaultFavicon == null) { @@ -1391,17 +1392,20 @@ class Tab implements PictureListener { if (isInVoiceSearchMode()) { item.setCustomData(mVoiceSearchData.mVoiceSearchIntent); } - if (mClearHistoryMatchUrl != null) { + if (mClearHistoryUrlPattern != null) { + boolean match = + mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches(); if (LOGD_ENABLED) { - Log.d(LOGTAG, "onNewHistoryItem:\n\t" + item.getUrl() + "\n\t" - + mClearHistoryMatchUrl); + Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t" + + item.getUrl() + "\n\t" + + mClearHistoryUrlPattern); } - if (TextUtils.equals(item.getOriginalUrl(), mClearHistoryMatchUrl)) { + if (match) { if (mMainView != null) { mMainView.clearHistory(); } } - mClearHistoryMatchUrl = null; + mClearHistoryUrlPattern = null; } } @Override @@ -2106,8 +2110,8 @@ class Tab implements PictureListener { * This is used to ensure that preloaded URLs that are not subsequently seen by the user do * not appear in the back stack. */ - public void clearBackStackWhenItemAdded(String urlToMatch) { - mClearHistoryMatchUrl = urlToMatch; + public void clearBackStackWhenItemAdded(Pattern urlPattern) { + mClearHistoryUrlPattern = urlPattern; } protected void persistThumbnail() { |