Bug 1426613 - Determine private mode via browser toolbar. r=nechen
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 22 Dec 2017 18:23:03 +0100
changeset 449204 90f70240f40956ab6eba75ecb8f985bb92a8ac22
parent 449202 67104a1227e43cee6ff365eff7a3cf7142af5138
child 449205 36b69642c15c332a26834289db75c5aaeab1c4d4
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnechen
bugs1426613
milestone59.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 1426613 - Determine private mode via browser toolbar. r=nechen 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;
     }