Bug 1426613 - Determine private mode via browser toolbar. r=nechen a=gchang
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 22 Dec 2017 18:23:03 +0100
changeset 445557 cb843e26235503704b941d47370b1686ddcec11c
parent 445556 641211059e52792538163f95dd447766e35a7d93
child 445558 2609db38f7d82c2433ce9d6ecb4ac9d3a85e35f8
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnechen, gchang
Bug 1426613 - Determine private mode via browser toolbar. r=nechen a=gchang 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
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -2446,24 +2446,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.gfx.LayerView;
 import org.mozilla.gecko.mozglue.SafeIntent;
@@ -381,21 +382,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
     public Tab getSelectedTab() {
         return mSelectedTab;
     public boolean isSelectedTab(Tab tab) {
         return tab != null && tab == mSelectedTab;