Bug 1342820 - Reset navigation button state when clearing history. r=ahunt
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 01 Mar 2017 21:08:11 +0100
changeset 394485 65317946fe00a94ad3ace74581223d79d73858b3
parent 394484 dcd244eca42786620e4f508a5fd12ef3d82d05e6
child 394486 3bee9644cf4c29e69708ddca242b976ee95ad194
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt
bugs1342820
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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");