Bug 1342820 - Reset navigation button state when clearing history. r?ahunt draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 01 Mar 2017 21:08:11 +0100
changeset 491131 03b30a61a2094acb8657cd749911366b1b1cf82e
parent 491130 eb0f65bdc8a3952e53fbbef361a13799a69722ff
child 492055 b367e5202da576d741b65f2626ed8b65d8b402f7
child 492070 772c218b9dbd789b9b284a31e47cff7cff22a144
push id47326
push usermozilla@buttercookie.de
push dateWed, 01 Mar 2017 20:10:21 +0000
reviewersahunt
bugs1342820
milestone54.0a1
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
mobile/android/base/java/org/mozilla/gecko/Tab.java
mobile/android/base/java/org/mozilla/gecko/Tabs.java
--- 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");