Bug 1304914 - Don't show "offline version" notifications on error pages r=sebastian draft
authorGrigory Kruglov <gkruglov@mozilla.com>
Mon, 26 Sep 2016 13:53:52 -0700
changeset 417754 4e214556445e92643b670a780eaa46243e56e37d
parent 417649 c55bcb7c777ea09431b4d16903ed079ae5632648
child 532169 560981592df075bf4f61e56365dfc90d23747841
push id30488
push usergkruglov@mozilla.com
push dateMon, 26 Sep 2016 20:53:33 +0000
reviewerssebastian
bugs1304914
milestone52.0a1
Bug 1304914 - Don't show "offline version" notifications on error pages r=sebastian MozReview-Commit-ID: BE6GPLCAU3h
mobile/android/base/java/org/mozilla/gecko/delegates/OfflineTabStatusDelegate.java
--- a/mobile/android/base/java/org/mozilla/gecko/delegates/OfflineTabStatusDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/delegates/OfflineTabStatusDelegate.java
@@ -58,19 +58,29 @@ public class OfflineTabStatusDelegate ex
             return;
         }
 
         // Ignore tabs displaying about pages
         if (AboutPages.isAboutPage(tab.getURL())) {
             return;
         }
 
+        // We only want to show these notifications for tabs that were loaded successfully.
+        if (tab.getState() != Tab.STATE_SUCCESS) {
+            return;
+        }
+
         switch (event) {
-            // Show offline notification if tab is visible, or queue it for display later.
-            case PAGE_SHOW:
+            // We listen specifically for the STOP event (as opposed to PAGE_SHOW), because we need
+            // to know if page load actually succeeded. When STOP is triggered, tab.getState()
+            // will return definitive STATE_SUCCESS or STATE_ERROR. When PAGE_SHOW is triggered,
+            // tab.getState() will return STATE_LOADING, which is ambiguous for our purposes.
+            // We don't want to show these notifications for 404 pages, for example. See Bug 1304914.
+            case STOP:
+                // Show offline notification if tab is visible, or queue it for display later.
                 if (!isTabsTrayVisible() && Tabs.getInstance().isSelectedTab(tab)) {
                     showLoadedOfflineSnackbar(activityReference.get());
                 } else {
                     tabsQueuedForOfflineSnackbar.put(tab, null);
                 }
                 break;
             // Fallthrough; see Bug 1278980 for details on why this event is here.
             case OPENED_FROM_TABS_TRAY: