Bug 1064177 - Part 2: Don't show Synced Tabs home panel in Guest Mode. r=wesj
authorNick Alexander <nalexander@mozilla.com>
Fri, 26 Sep 2014 11:44:56 -0700
changeset 207449 67f1009c3eba005942c7f29dab0708bb55d6059a
parent 207448 3b86d4a1dd9f1c387569274ae56b8f6ad812eb81
child 207450 b28b8ec17fba1e3b5bddcb42f6160e381596d6c8
push id9018
push usernalexander@mozilla.com
push dateFri, 26 Sep 2014 18:48:16 +0000
treeherderfx-team@5698141fb2b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs1064177
milestone35.0a1
Bug 1064177 - Part 2: Don't show Synced Tabs home panel in Guest Mode. r=wesj We hard-code a number of default panel configuration options here, so let's add another. I don't care to migrate serialized Guest profile Home Panel configurations forward. I don't expect there are any: no Home Panel configuration is written to SharedPreferences until the user edits the default configuration in Settings > Customize > Home, and I expect ~0 folks to have taken these steps while in Guest Mode. While I was here, I updated the other uses of GeckoProfile.inGuestMode to guard Sync related things that I found.
mobile/android/base/home/HomeConfigPrefsBackend.java
mobile/android/base/preferences/GeckoPreferences.java
mobile/android/base/tabs/TabsPanel.java
--- a/mobile/android/base/home/HomeConfigPrefsBackend.java
+++ b/mobile/android/base/home/HomeConfigPrefsBackend.java
@@ -10,16 +10,17 @@ import static org.mozilla.gecko.home.Hom
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.Locale;
 
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.GeckoSharedPrefs;
+import org.mozilla.gecko.RestrictedProfiles;
 import org.mozilla.gecko.home.HomeConfig.HomeConfigBackend;
 import org.mozilla.gecko.home.HomeConfig.OnReloadListener;
 import org.mozilla.gecko.home.HomeConfig.PanelConfig;
 import org.mozilla.gecko.home.HomeConfig.PanelType;
 import org.mozilla.gecko.home.HomeConfig.State;
 import org.mozilla.gecko.util.HardwareUtils;
 
 import android.content.BroadcastReceiver;
@@ -76,28 +77,39 @@ class HomeConfigPrefsBackend implements 
         // We disable reader mode support on low memory devices. Hence the
         // reading list panel should not show up on such devices.
         if (!HardwareUtils.isLowMemoryPlatform()) {
             panelConfigs.add(createBuiltinPanelConfig(mContext, PanelType.READING_LIST));
         }
 
         final PanelConfig historyEntry = createBuiltinPanelConfig(mContext, PanelType.HISTORY);
         final PanelConfig recentTabsEntry = createBuiltinPanelConfig(mContext, PanelType.RECENT_TABS);
-        final PanelConfig remoteTabsEntry = createBuiltinPanelConfig(mContext, PanelType.REMOTE_TABS);
+
+        // We disable Synced Tabs for guest mode profiles.
+        final PanelConfig remoteTabsEntry;
+        if (RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
+            remoteTabsEntry = createBuiltinPanelConfig(mContext, PanelType.REMOTE_TABS);
+        } else {
+            remoteTabsEntry = null;
+        }
 
         // On tablets, we go [...|History|Recent Tabs|Synced Tabs].
         // On phones, we go [Synced Tabs|Recent Tabs|History|...].
         if (HardwareUtils.isTablet()) {
             panelConfigs.add(historyEntry);
             panelConfigs.add(recentTabsEntry);
-            panelConfigs.add(remoteTabsEntry);
+            if (remoteTabsEntry != null) {
+                panelConfigs.add(remoteTabsEntry);
+            }
         } else {
             panelConfigs.add(0, historyEntry);
             panelConfigs.add(0, recentTabsEntry);
-            panelConfigs.add(0, remoteTabsEntry);
+            if (remoteTabsEntry != null) {
+                panelConfigs.add(0, remoteTabsEntry);
+            }
         }
 
         return new State(panelConfigs, true);
     }
 
     /**
      * Iterate through the panels to check if they are all disabled.
      */
--- a/mobile/android/base/preferences/GeckoPreferences.java
+++ b/mobile/android/base/preferences/GeckoPreferences.java
@@ -24,16 +24,17 @@ import org.mozilla.gecko.GeckoApplicatio
 import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.GuestSession;
 import org.mozilla.gecko.LocaleManager;
 import org.mozilla.gecko.NewTabletUI;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.RestrictedProfiles;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.TelemetryContract.Method;
 import org.mozilla.gecko.background.common.GlobalConstants;
 import org.mozilla.gecko.background.healthreport.HealthReportConstants;
 import org.mozilla.gecko.db.BrowserContract.SuggestedSites;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.HardwareUtils;
@@ -712,17 +713,18 @@ OnSharedPreferenceChangeListener
                     // Set the summary string to the current entry. The summary
                     // for other list prefs will be set in the PrefsHelper
                     // callback, but since this pref doesn't live in Gecko, we
                     // need to handle it separately.
                     ListPreference listPref = (ListPreference) pref;
                     CharSequence selectedEntry = listPref.getEntry();
                     listPref.setSummary(selectedEntry);
                     continue;
-                } else if (PREFS_SYNC.equals(key) && GeckoProfile.get(this).inGuestMode()) {
+                } else if (PREFS_SYNC.equals(key) &&
+                           !RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
                     // Don't show sync prefs while in guest mode.
                     preferences.removePreference(pref);
                     i--;
                     continue;
                 } else if (PREFS_SEARCH_RESTORE_DEFAULTS.equals(key)) {
                     pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                         @Override
                         public boolean onPreferenceClick(Preference preference) {
--- a/mobile/android/base/tabs/TabsPanel.java
+++ b/mobile/android/base/tabs/TabsPanel.java
@@ -10,16 +10,17 @@ import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoAppShell.AppStateListener;
 import org.mozilla.gecko.GeckoApplication;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.LightweightTheme;
 import org.mozilla.gecko.LightweightThemeDrawable;
 import org.mozilla.gecko.NewTabletUI;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.RestrictedProfiles;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.ViewHelper;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.widget.GeckoPopupMenu;
 import org.mozilla.gecko.widget.IconTabWidget;
 
@@ -168,17 +169,17 @@ public class TabsPanel extends LinearLay
             }
         });
 
         mTabWidget = (IconTabWidget) findViewById(R.id.tab_widget);
 
         mTabWidget.addTab(R.drawable.tabs_normal, R.string.tabs_normal);
         mTabWidget.addTab(R.drawable.tabs_private, R.string.tabs_private);
 
-        if (!GeckoProfile.get(mContext).inGuestMode()) {
+        if (RestrictedProfiles.isAllowed(RestrictedProfiles.Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
             // The initial icon is not the animated icon, because on Android
             // 4.4.2, the animation starts immediately (and can start at other
             // unpredictable times). See Bug 1015974.
             mTabWidget.addTab(R.drawable.tabs_synced, R.string.tabs_synced);
         }
 
         mTabWidget.setTabSelectionListener(this);