Bug 1302936 - Ignore tab clicks when the tab has already been removed. r=sebastian, a=lizzard
authorTom Klein <twointofive@gmail.com>
Wed, 21 Dec 2016 14:17:59 -0600
changeset 359233 f783a9c2ac8f285bbd8533c96897884673021b67
parent 359232 71d0e04d0016c9ab6cd1eda6babf78a671be6fa8
child 359234 3648a587a3d9e5072064f0d8df1b31763aa5f188
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, lizzard
bugs1302936
milestone51.0
Bug 1302936 - Ignore tab clicks when the tab has already been removed. r=sebastian, a=lizzard
mobile/android/base/java/org/mozilla/gecko/Tabs.java
mobile/android/base/java/org/mozilla/gecko/tabs/TabsGridLayout.java
mobile/android/base/java/org/mozilla/gecko/tabs/TabsListLayout.java
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -246,17 +246,17 @@ public class Tabs implements GeckoEventL
             return null;
 
         final Tab oldTab = getSelectedTab();
         final Tab tab = mTabs.get(id);
 
         // This avoids a NPE below, but callers need to be careful to
         // handle this case.
         if (tab == null || oldTab == tab) {
-            return null;
+            return tab;
         }
 
         mSelectedTab = tab;
         notifyListeners(tab, TabEvents.SELECTED);
 
         if (mLayerView != null) {
             mLayerView.setClearColor(getTabColor(tab));
         }
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabsGridLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsGridLayout.java
@@ -97,23 +97,24 @@ class TabsGridLayout extends GridView
         // Your demise, GridView, cannot come fast enough.
         final int paddingBottom = paddingTop * 2;
 
         setPadding(padding, paddingTop, padding, paddingBottom);
 
         setOnItemClickListener(new OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-                final TabsLayoutItemView tab = (TabsLayoutItemView) view;
-                final int tabId = tab.getTabId();
-                Tabs.getInstance().selectTab(tabId);
+                final TabsLayoutItemView tabView = (TabsLayoutItemView) view;
+                final int tabId = tabView.getTabId();
+                final Tab tab = Tabs.getInstance().selectTab(tabId);
+                if (tab == null) {
+                    return;
+                }
                 autoHidePanel();
-                Tabs.getInstance().notifyListeners(
-                        Tabs.getInstance().getTab(tabId), Tabs.TabEvents.OPENED_FROM_TABS_TRAY
-                );
+                Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.OPENED_FROM_TABS_TRAY);
             }
         });
 
         TabSwipeGestureListener mSwipeListener = new TabSwipeGestureListener();
         setOnTouchListener(mSwipeListener);
         setOnScrollListener(mSwipeListener.makeScrollListener());
     }
 
@@ -574,21 +575,21 @@ class TabsGridLayout extends GridView
                     }
 
                     cancelCheckForTap();
                     mSwipeView.setPressed(false);
 
                     if (!mSwiping) {
                         final TabsLayoutItemView item = (TabsLayoutItemView) mSwipeView;
                         final int tabId = item.getTabId();
-                        Tabs.getInstance().selectTab(tabId);
-                        autoHidePanel();
-                        Tabs.getInstance().notifyListeners(
-                                Tabs.getInstance().getTab(tabId), Tabs.TabEvents.OPENED_FROM_TABS_TRAY
-                        );
+                        final Tab tab = Tabs.getInstance().selectTab(tabId);
+                        if (tab != null) {
+                            autoHidePanel();
+                            Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.OPENED_FROM_TABS_TRAY);
+                        }
 
                         mVelocityTracker.recycle();
                         mVelocityTracker = null;
                         break;
                     }
 
                     mVelocityTracker.addMovement(e);
                     mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity);
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabsListLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsListLayout.java
@@ -492,21 +492,21 @@ class TabsListLayout extends TwoWayView
                     }
 
                     cancelCheckForTap();
                     swipeView.setPressed(false);
 
                     if (!swiping) {
                         TabsLayoutItemView item = (TabsLayoutItemView) swipeView;
                         final int tabId = item.getTabId();
-                        Tabs.getInstance().selectTab(tabId);
-                        autoHidePanel();
-                        Tabs.getInstance().notifyListeners(
-                                Tabs.getInstance().getTab(tabId), Tabs.TabEvents.OPENED_FROM_TABS_TRAY
-                        );
+                        final Tab tab = Tabs.getInstance().selectTab(tabId);
+                        if (tab != null) {
+                            autoHidePanel();
+                            Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.OPENED_FROM_TABS_TRAY);
+                        }
                         velocityTracker.recycle();
                         velocityTracker = null;
                         break;
                     }
 
                     velocityTracker.addMovement(e);
                     velocityTracker.computeCurrentVelocity(1000, maxFlingVelocity);