[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



commit 576ff6dcffff7ad57c21c4bc469b52566d8da3dd
Author: Matthew Finkel <Matthew.Finkel@xxxxxxxxx>
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           |  4 +--
 5 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
index da25e3b395be..c2a463ad6ed1 100644
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -3362,6 +3362,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 = 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 e01318dab422..9c66f56b0485 100644
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -165,6 +165,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";
     /**
@@ -352,6 +354,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;
 
@@ -1164,6 +1168,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 = 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);
 
@@ -1202,6 +1228,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())));
@@ -2306,6 +2333,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 068d8cb7ca28..30c75b68aad8 100644
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -106,6 +106,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
@@ -211,6 +212,10 @@ public class Tabs implements BundleEventListener {
         }
     }
 
+    public synchronized void setOnlyPrivateTabs(boolean onlyPrivateTabs) {
+        mOnlyPrivateTabs = onlyPrivateTabs;
+    }
+
     public void detachFromContext() {
         mGeckoView = null;
     }
@@ -1026,7 +1031,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 e139e59a7f40..f8e9399f51c4 100644
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -4410,9 +4410,9 @@ 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;
+      attrs['privateBrowsingId'] = 1;
     }
 
     this.browser.docShell.setOriginAttributes(attrs);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits