Bug 1342820 - Reset navigation button state when clearing history. r?ahunt
Clearing history purges a tab's session history as well. Normally, we only update the navigation button state in the UI for a location change, so now we need to start listening for the appropriate message as well.
BrowserApp has already registered a background thread listener for "Sanitize:ClearHistory" - since this can be called during shutdown as well and their listener is more important (clearing the history DB), we defer to them and redispatch to the UI thread ourselves, so BrowserApp doesn't have to do this during shutdown.
MozReview-Commit-ID: C83mk6Z56Oq
--- a/mobile/android/base/java/org/mozilla/gecko/Tab.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tab.java
@@ -649,16 +649,21 @@ public class Tab {
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, oldUrl);
}
void handleButtonStateChange(final GeckoBundle message) {
mCanDoBack = message.getBoolean("canGoBack");
mCanDoForward = message.getBoolean("canGoForward");
}
+ void handleButtonStateChange(boolean canGoBack, boolean canGoForward) {
+ mCanDoBack = canGoBack;
+ mCanDoForward = canGoForward;
+ }
+
private static boolean shouldShowProgress(final String url) {
return !AboutPages.isAboutPage(url);
}
void handleDocumentStart(boolean restoring, String url) {
setLoadProgress(LOAD_PROGRESS_START);
setState((!restoring && shouldShowProgress(url)) ? STATE_LOADING : STATE_SUCCESS);
mSiteIdentity.reset();
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -131,16 +131,21 @@ public class Tabs implements BundleEvent
"Tab:AudioPlayingChange",
"Tab:Close",
"Tab:MediaPlaybackChange",
"Tab:RecordingChange",
"Tab:Select",
"Tab:SetParentId",
null);
+ EventDispatcher.getInstance().registerBackgroundThreadListener(this,
+ // BrowserApp already wants this on the background thread.
+ "Sanitize:ClearHistory",
+ null);
+
mPrivateClearColor = Color.RED;
}
public synchronized void attachToContext(Context context, LayerView layerView) {
final Context appContext = context.getApplicationContext();
if (mAppContext == appContext) {
return;
}
@@ -478,16 +483,31 @@ public class Tabs implements BundleEvent
@RobocopTarget
public static Tabs getInstance() {
return Tabs.TabsInstanceHolder.INSTANCE;
}
@Override // BundleEventListener
public synchronized void handleMessage(final String event, final GeckoBundle message,
final EventCallback callback) {
+ if ("Sanitize:ClearHistory".equals(event)) {
+ ThreadUtils.postToUiThread(new Runnable() {
+ @Override
+ public void run() {
+ // Tab session history will be cleared as well,
+ // so we need to reset the navigation buttons.
+ for (final Tab tab : mOrder) {
+ tab.handleButtonStateChange(false, false);
+ notifyListeners(tab, TabEvents.LOCATION_CHANGE, tab.getURL());
+ }
+ }
+ });
+ return;
+ }
+
// All other events handled below should contain a tabID property
final int id = message.getInt("tabID", -1);
Tab tab = getTab(id);
// "Tab:Added" is a special case because tab will be null if the tab was just added
if ("Tab:Added".equals(event)) {
String url = message.getString("uri");