Bug 1426613 - Determine private mode via browser toolbar. r? draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 22 Dec 2017 18:23:03 +0100
changeset 714600 b9c754af5d22ea06de7172f7741fa1b3b4d9b5c3
parent 714597 6de19cc17677ce05435c367a499dc25c355c7b75
child 714601 6c4bf952b408506b085ed0dac707f2650c0171d3
push id93960
push usermozilla@buttercookie.de
push dateTue, 26 Dec 2017 17:37:08 +0000
bugs1426613
milestone59.0a1
Bug 1426613 - Determine private mode via browser toolbar. r? The currently selected tab might not actually exist immediately after startup, in which case the browser toolbar is a safer bet for determining whether we're in private mode or not. I think the current worst case is when we're - not restoring a previous session, and - need to open some tab queue tabs, and - also need to open some other tab in response to our launch intent in which case we won't have a selected tab in Java until after Gecko is up and running. This in turn can take a while, especially when a fresh copy of libxul.so needs to be extracted after an update/installation/cleared cache/..., which potentially gives the user ample time to click on a search result/Top Sites entry/... that then triggers this crash. MozReview-Commit-ID: FlJZw2aL8OM
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/Tabs.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -2434,24 +2434,24 @@ public class BrowserApp extends GeckoApp
      *        is not present, return false.
      * @return true if we successfully switched to a tab, false otherwise.
      */
     private boolean maybeSwitchToTab(String url, EnumSet<OnUrlOpenListener.Flags> flags) {
         if (!flags.contains(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB)) {
             return false;
         }
 
+        final boolean isPrivate = mBrowserToolbar.isPrivateMode();
         final Tabs tabs = Tabs.getInstance();
-        final Tab selectedTab = tabs.getSelectedTab();
         final Tab tab;
 
         if (AboutPages.isAboutReader(url)) {
-            tab = tabs.getFirstReaderTabForUrl(url, selectedTab.isPrivate());
+            tab = tabs.getFirstReaderTabForUrl(url, isPrivate);
         } else {
-            tab = tabs.getFirstTabForUrl(url, selectedTab.isPrivate());
+            tab = tabs.getFirstTabForUrl(url, isPrivate);
         }
 
         if (tab == null) {
             return false;
         }
 
         return maybeSwitchToTab(tab.getId());
     }
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -8,16 +8,17 @@ package org.mozilla.gecko;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import android.content.SharedPreferences;
+import android.support.annotation.CheckResult;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.distribution.PartnerBrowserCustomizationsClient;
 import org.mozilla.gecko.mozglue.SafeIntent;
 import org.mozilla.gecko.notifications.WhatsNewReceiver;
@@ -380,21 +381,22 @@ public class Tabs implements BundleEvent
             }
         }
         return null;
     }
 
     /**
      * Gets the selected tab.
      *
-     * The selected tab can be null if we're doing a session restore after a
-     * crash and Gecko isn't ready yet.
+     * The selected tab can be null immediately after startup, in the worst case until after Gecko
+     * is up and running.
      *
      * @return the selected tab, or null if no tabs exist
      */
+    @CheckResult
     @Nullable
     public Tab getSelectedTab() {
         return mSelectedTab;
     }
 
     public boolean isSelectedTab(Tab tab) {
         return tab != null && tab == mSelectedTab;
     }