[tbb-commits] [tor-browser/tor-browser-60.7.0esr-9.0-1] Bug 24920 - Only create Private tabs if browser.privatebrowsing.autostart is true

gk at torproject.org gk at torproject.org
Tue Jun 4 07:39:51 UTC 2019


commit 1bce86ec5cfff504baf6e61b9d356ff74c62b297
Author: Matthew Finkel <Matthew.Finkel at gmail.com>
Date:   Mon May 27 15:55:33 2019 +0000

    Bug 24920 - Only create Private tabs if browser.privatebrowsing.autostart is true
---
 .../base/java/org/mozilla/gecko/BrowserApp.java    |  9 +++++++
 .../base/java/org/mozilla/gecko/GeckoApp.java      | 31 ++++++++++++++++++++++
 .../android/base/java/org/mozilla/gecko/Tabs.java  |  7 ++++-
 .../java/org/mozilla/gecko/tabs/TabsPanel.java     |  4 +++
 mobile/android/chrome/content/browser.js           |  2 +-
 5 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
index 006d5c11f210..0b369ca8d5ab 100644
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -3754,6 +3754,15 @@ public class BrowserApp extends GeckoApp
 
         share.setActionProvider(provider);
 
+        // Change visibility of new_tab. This may be called before
+        // mOnlyPrivateTabs is set in GeckoApp::onCreate(). If the PrefHelper
+        // callback was not already called, then the visibility will be correctly set
+        // in the callback.
+        MenuItem newTabMenuItem = (MenuItem) mMenu.findItem(R.id.new_tab);
+        if (newTabMenuItem != null) {
+            newTabMenuItem.setVisible(mOnlyPrivateTabs == false);
+        }
+
         return true;
     }
 
diff --git a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
index 42a4f191d525..64c93d900430 100644
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -154,6 +154,8 @@ public abstract class GeckoApp extends GeckoActivity
      */
     public static final String PREFS_IS_FIRST_RUN = "telemetry-isFirstRun";
 
+    public static final String PREFS_PRIVATEBROWSING_AUTOSTART = "browser.privatebrowsing.autostart";
+
     public static final String SAVED_STATE_IN_BACKGROUND   = "inBackground";
     public static final String SAVED_STATE_PRIVATE_SESSION = "privateSession";
 
@@ -325,6 +327,8 @@ public abstract class GeckoApp extends GeckoActivity
     private boolean mPrivateBrowsingSessionOutdated;
     private static final int MAX_PRIVATE_TABS_UPDATE_WAIT_MSEC = 500;
 
+    protected boolean mOnlyPrivateTabs = false;
+
     private volatile HealthRecorder mHealthRecorder;
     private volatile Locale mLastLocale;
 
@@ -1129,6 +1133,28 @@ public abstract class GeckoApp extends GeckoActivity
             "ToggleChrome:Show",
             null);
 
+        PrefsHelper.getPref(PREFS_PRIVATEBROWSING_AUTOSTART,
+                            new PrefsHelper.PrefHandlerBase() {
+            @Override public void prefValue(String pref, boolean value) {
+                if (pref != PREFS_PRIVATEBROWSING_AUTOSTART) {
+                    return;
+                }
+
+                mOnlyPrivateTabs = value;
+
+                // Change visibility here in case mMenu is initialized. If it is not initialized,
+                // then the visibility is set in BrowserApp::onCreateOptionsMenu().
+                if (mMenu != null) {
+                    MenuItem newTabMenuItem = (MenuItem) mMenu.findItem(R.id.new_tab);
+                    if (newTabMenuItem != null) {
+                        newTabMenuItem.setVisible(mOnlyPrivateTabs == false);
+                    }
+                }
+
+                Tabs.getInstance().setOnlyPrivateTabs(mOnlyPrivateTabs);
+            }
+        });
+
         Tabs.getInstance().attachToContext(this, mLayerView, getAppEventDispatcher());
         Tabs.registerOnTabsChangedListener(this);
 
@@ -1167,6 +1193,7 @@ public abstract class GeckoApp extends GeckoActivity
                 }
 
                 // If we are doing a restore, read the session data so we can send it to Gecko later.
+
                 GeckoBundle restoreMessage = null;
                 if (!mIsRestoringActivity && mShouldRestore) {
                     final boolean isExternalURL = invokedWithExternalURL(getIntentURI(new SafeIntent(getIntent())));
@@ -2244,6 +2271,10 @@ public abstract class GeckoApp extends GeckoActivity
         }
     }
 
+    public boolean isOnlyPrivateTabs() {
+        return mOnlyPrivateTabs;
+    }
+
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
     protected void finishAndShutdown(final boolean restart) {
         ThreadUtils.assertOnUiThread();
diff --git a/mobile/android/base/java/org/mozilla/gecko/Tabs.java b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
index 36d1b474bb87..d139b26cc217 100644
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -104,6 +104,7 @@ public class Tabs implements BundleEventListener {
     private ContentObserver mBookmarksContentObserver;
     private PersistTabsRunnable mPersistTabsRunnable;
     private int mPrivateClearColor;
+    private boolean mOnlyPrivateTabs = true;
 
     // Close all tabs including normal and private tabs.
     @RobocopTarget
@@ -208,6 +209,10 @@ public class Tabs implements BundleEventListener {
         }
     }
 
+    public synchronized void setOnlyPrivateTabs(boolean onlyPrivateTabs) {
+        mOnlyPrivateTabs = onlyPrivateTabs;
+    }
+
     public void detachFromContext() {
         mGeckoView = null;
     }
@@ -989,7 +994,7 @@ public class Tabs implements BundleEventListener {
         // delayLoad implies background tab
         boolean background = delayLoad || (flags & LOADURL_BACKGROUND) != 0;
 
-        boolean isPrivate = (flags & LOADURL_PRIVATE) != 0 || (intent != null && intent.getBooleanExtra(PRIVATE_TAB_INTENT_EXTRA, false));
+        boolean isPrivate = (flags & LOADURL_PRIVATE) != 0 || (intent != null && intent.getBooleanExtra(PRIVATE_TAB_INTENT_EXTRA, false)) || mOnlyPrivateTabs;
         boolean userEntered = (flags & LOADURL_USER_ENTERED) != 0;
         boolean desktopMode = (flags & LOADURL_DESKTOP) != 0;
         boolean external = (flags & LOADURL_EXTERNAL) != 0;
diff --git a/mobile/android/base/java/org/mozilla/gecko/tabs/TabsPanel.java b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsPanel.java
index 08c107ebb62d..fc27ac03c929 100644
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabsPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsPanel.java
@@ -167,6 +167,10 @@ public class TabsPanel extends LinearLayout
         final View tabNormal = mTabWidget.addTab(R.drawable.tabs_normal, R.string.tabs_normal);
         mNormalTabsPanel = tabNormal instanceof ThemedImageButton ? ((ThemedImageButton) tabNormal) : null;
 
+        if (mActivity.isOnlyPrivateTabs()) {
+            tabNormal.setVisibility(View.GONE);
+        }
+
         final View tabPrivate = mTabWidget.addTab(R.drawable.tabs_private, R.string.tabs_private);
         mPrivateTabsPanel = tabPrivate instanceof ThemedImageButton ? ((ThemedImageButton) tabPrivate) : null;
         if (mPrivateTabsPanel != null) {
diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js
index c3430f5b5a4c..5e2291865b89 100644
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3652,7 +3652,7 @@ Tab.prototype = {
     // Must be called after appendChild so the docShell has been created.
     this.setActive(false);
 
-    let isPrivate = ("isPrivate" in aParams) && aParams.isPrivate;
+    let isPrivate = (("isPrivate" in aParams) && aParams.isPrivate) || Services.prefs.getBoolPref("browser.privatebrowsing.autostart");
     if (isPrivate) {
       attrs['privateBrowsingId'] = 1;
     }





More information about the tbb-commits mailing list