Bug 1189336 - (Part 2) Rename Restriction class to Restrictable. r=ally

This is the first step to move from a list of DISALLOW_* things to a list of
features that can be enabled or disabled for a profile. At a later stage we
will check whether a "restrictable" feature is allowed or not.
This commit is contained in:
Sebastian Kaspari 2015-11-11 16:39:28 +01:00
parent d8cfe26d6c
commit 4a2458d1c3
18 changed files with 91 additions and 95 deletions

View File

@ -22,7 +22,7 @@ import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
import org.mozilla.gecko.fxa.login.Engaged;
import org.mozilla.gecko.fxa.login.State;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.setup.SyncAccounts;
@ -83,7 +83,7 @@ public class AccountsHelper implements NativeEventListener {
@Override
public void handleMessage(String event, NativeJSObject message, final EventCallback callback) {
if (!Restrictions.isAllowed(mContext, Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
if (!Restrictions.isAllowed(mContext, Restrictable.DISALLOW_MODIFY_ACCOUNTS)) {
// We register for messages in all contexts; we drop, with a log and an error to JavaScript,
// when the profile is restricted. It's better to return errors than silently ignore messages.
Log.e(LOGTAG, "Profile is not allowed to modify accounts! Ignoring event: " + event);

View File

@ -49,7 +49,7 @@ import org.mozilla.gecko.preferences.ClearOnShutdownPref;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.prompts.Prompt;
import org.mozilla.gecko.prompts.PromptListItem;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository;
import org.mozilla.gecko.tabqueue.TabQueueHelper;
import org.mozilla.gecko.tabqueue.TabQueuePrompt;
@ -1793,7 +1793,7 @@ public class BrowserApp extends GeckoApp
}
}
if (AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED && Restrictions.isAllowed(this, Restriction.DISALLOW_LOCATION_SERVICE)) {
if (AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED && Restrictions.isAllowed(this, Restrictable.DISALLOW_LOCATION_SERVICE)) {
// Start (this acts as ping if started already) the stumbler lib; if the stumbler has queued data it will upload it.
// Stumbler operates on its own thread, and startup impact is further minimized by delaying work (such as upload) a few seconds.
// Avoid any potential startup CPU/thread contention by delaying the pref broadcast.
@ -3084,11 +3084,11 @@ public class BrowserApp extends GeckoApp
}
// Disable share menuitem for about:, chrome:, file:, and resource: URIs
final boolean shareVisible = Restrictions.isAllowed(this, Restriction.DISALLOW_SHARE);
final boolean shareVisible = Restrictions.isAllowed(this, Restrictable.DISALLOW_SHARE);
share.setVisible(shareVisible);
final boolean shareEnabled = StringUtils.isShareableUrl(url) && shareVisible;
share.setEnabled(shareEnabled);
MenuUtils.safeSetEnabled(aMenu, R.id.downloads, Restrictions.isAllowed(this, Restriction.DISALLOW_DOWNLOADS));
MenuUtils.safeSetEnabled(aMenu, R.id.downloads, Restrictions.isAllowed(this, Restrictable.DISALLOW_DOWNLOADS));
// NOTE: Use MenuUtils.safeSetEnabled because some actions might
// be on the BrowserToolbar context menu.
@ -3151,7 +3151,7 @@ public class BrowserApp extends GeckoApp
}
}
final boolean privateTabVisible = Restrictions.isAllowed(this, Restriction.DISALLOW_PRIVATE_BROWSING);
final boolean privateTabVisible = Restrictions.isAllowed(this, Restrictable.DISALLOW_PRIVATE_BROWSING);
MenuUtils.safeSetVisible(aMenu, R.id.new_private_tab, privateTabVisible);
// Disable PDF generation (save and print) for about:home and xul pages.
@ -3173,11 +3173,11 @@ public class BrowserApp extends GeckoApp
enterGuestMode.setVisible(true);
}
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_GUEST_BROWSING)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_GUEST_BROWSING)) {
MenuUtils.safeSetVisible(aMenu, R.id.new_guest_session, false);
}
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_INSTALL_EXTENSION)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_INSTALL_EXTENSION)) {
MenuUtils.safeSetVisible(aMenu, R.id.addons, false);
}

View File

@ -10,14 +10,13 @@ import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.restrictions.DefaultConfiguration;
import org.mozilla.gecko.restrictions.GuestProfileConfiguration;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.restrictions.RestrictedProfileConfiguration;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.restrictions.RestrictionConfiguration;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.UserManager;
import android.util.Log;
@ -83,8 +82,8 @@ public class Restrictions {
getConfiguration(context).update();
}
private static Restriction geckoActionToRestriction(int action) {
for (Restriction rest : Restriction.values()) {
private static Restrictable geckoActionToRestriction(int action) {
for (Restrictable rest : Restrictable.values()) {
if (rest.id == action) {
return rest;
}
@ -106,15 +105,15 @@ public class Restrictions {
return getConfiguration(context).isRestricted();
}
public static boolean isAllowed(final Context context, final Restriction restriction) {
return getConfiguration(context).isAllowed(restriction);
public static boolean isAllowed(final Context context, final Restrictable restrictable) {
return getConfiguration(context).isAllowed(restrictable);
}
@WrapForJNI
public static boolean isAllowed(int action, String url) {
final Restriction restriction;
final Restrictable restrictable;
try {
restriction = geckoActionToRestriction(action);
restrictable = geckoActionToRestriction(action);
} catch (IllegalArgumentException ex) {
// Unknown actions represent a coding error, so we
// refuse the action and log.
@ -124,10 +123,10 @@ public class Restrictions {
final Context context = GeckoAppShell.getApplicationContext();
if (Restriction.DISALLOW_BROWSE_FILES == restriction) {
if (Restrictable.DISALLOW_BROWSE_FILES == restrictable) {
return canLoadUrl(context, url);
} else {
return isAllowed(context, restriction);
return isAllowed(context, restrictable);
}
}
}

View File

@ -26,7 +26,7 @@ import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.util.ColorUtils;
import org.mozilla.gecko.util.HardwareUtils;
@ -224,7 +224,7 @@ public class HistoryPanel extends HomeFragment {
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
if (!Restrictions.isAllowed(getActivity(), Restriction.DISALLOW_CLEAR_HISTORY)) {
if (!Restrictions.isAllowed(getActivity(), Restrictable.DISALLOW_CLEAR_HISTORY)) {
menu.findItem(R.id.home_remove).setVisible(false);
}
}
@ -291,7 +291,7 @@ public class HistoryPanel extends HomeFragment {
private void updateUiFromCursor(Cursor c) {
if (c != null && c.getCount() > 0) {
if (Restrictions.isAllowed(getActivity(), Restriction.DISALLOW_CLEAR_HISTORY)) {
if (Restrictions.isAllowed(getActivity(), Restrictable.DISALLOW_CLEAR_HISTORY)) {
mClearHistoryButton.setVisibility(View.VISIBLE);
}
return;
@ -322,7 +322,7 @@ public class HistoryPanel extends HomeFragment {
emptyHint.setVisibility(View.VISIBLE);
}
if (!Restrictions.isAllowed(getActivity(), Restriction.DISALLOW_PRIVATE_BROWSING)) {
if (!Restrictions.isAllowed(getActivity(), Restrictable.DISALLOW_PRIVATE_BROWSING)) {
emptyHint.setVisibility(View.GONE);
}

View File

@ -21,7 +21,7 @@ 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.restrictions.Restriction;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.util.HardwareUtils;
import android.content.BroadcastReceiver;
@ -77,7 +77,7 @@ class HomeConfigPrefsBackend implements HomeConfigBackend {
panelConfigs.add(createBuiltinPanelConfig(mContext, PanelType.HISTORY));
// We disable Synced Tabs for guest mode / restricted profiles.
if (Restrictions.isAllowed(mContext, Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
if (Restrictions.isAllowed(mContext, Restrictable.DISALLOW_MODIFY_ACCOUNTS)) {
panelConfigs.add(createBuiltinPanelConfig(mContext, PanelType.REMOTE_TABS));
}

View File

@ -23,7 +23,7 @@ import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
import org.mozilla.gecko.home.HomePager.OnUrlOpenInBackgroundListener;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.TopSitesGridView.TopSitesGridContextMenuInfo;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.util.Clipboard;
import org.mozilla.gecko.util.StringUtils;
import org.mozilla.gecko.util.ThreadUtils;
@ -153,7 +153,7 @@ public abstract class HomeFragment extends Fragment {
menu.findItem(R.id.home_share).setVisible(false);
}
if (!Restrictions.isAllowed(view.getContext(), Restriction.DISALLOW_PRIVATE_BROWSING)) {
if (!Restrictions.isAllowed(view.getContext(), Restrictable.DISALLOW_PRIVATE_BROWSING)) {
menu.findItem(R.id.home_open_private_tab).setVisible(false);
}

View File

@ -34,7 +34,7 @@ import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.PinSiteDialog.OnSiteSelectedListener;
import org.mozilla.gecko.home.TopSitesGridView.OnEditPinnedSiteListener;
import org.mozilla.gecko.home.TopSitesGridView.TopSitesGridContextMenuInfo;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.tiles.TilesRecorder;
import org.mozilla.gecko.tiles.Tile;
import org.mozilla.gecko.util.StringUtils;
@ -343,7 +343,7 @@ public class TopSitesPanel extends HomeFragment {
// can handle this.
super.onCreateContextMenu(menu, view, menuInfo);
if (!Restrictions.isAllowed(view.getContext(), Restriction.DISALLOW_CLEAR_HISTORY)) {
if (!Restrictions.isAllowed(view.getContext(), Restrictable.DISALLOW_CLEAR_HISTORY)) {
menu.findItem(R.id.home_remove).setVisible(false);
}
@ -359,7 +359,7 @@ public class TopSitesPanel extends HomeFragment {
// Hide unused menu items.
menu.findItem(R.id.home_edit_bookmark).setVisible(false);
menu.findItem(R.id.home_remove).setVisible(Restrictions.isAllowed(context, Restriction.DISALLOW_CLEAR_HISTORY));
menu.findItem(R.id.home_remove).setVisible(Restrictions.isAllowed(context, Restrictable.DISALLOW_CLEAR_HISTORY));
TopSitesGridContextMenuInfo info = (TopSitesGridContextMenuInfo) menuInfo;
menu.setHeaderTitle(info.getDisplayTitle());
@ -381,7 +381,7 @@ public class TopSitesPanel extends HomeFragment {
menu.findItem(R.id.home_share).setVisible(false);
}
if (!Restrictions.isAllowed(context, Restriction.DISALLOW_PRIVATE_BROWSING)) {
if (!Restrictions.isAllowed(context, Restrictable.DISALLOW_PRIVATE_BROWSING)) {
menu.findItem(R.id.home_open_private_tab).setVisible(false);
}

View File

@ -481,8 +481,8 @@ gbjar.sources += [
'Restrictions.java',
'restrictions/DefaultConfiguration.java',
'restrictions/GuestProfileConfiguration.java',
'restrictions/Restrictable.java',
'restrictions/RestrictedProfileConfiguration.java',
'restrictions/Restriction.java',
'restrictions/RestrictionConfiguration.java',
'restrictions/RestrictionProvider.java',
'ServiceNotificationClient.java',

View File

@ -7,9 +7,9 @@ package org.mozilla.gecko.preferences;
import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.R;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.Restrictions;
import org.mozilla.gecko.restrictions.Restriction;
import java.util.Set;
@ -28,7 +28,7 @@ class AndroidImportPreference extends MultiPrefMultiChoicePreference {
public static class Handler implements GeckoPreferences.PrefHandler {
public boolean setupPref(Context context, Preference pref) {
// Feature disabled on devices running Android M+ (Bug 1183559)
return Versions.preM && Restrictions.isAllowed(context, Restriction.DISALLOW_IMPORT_SETTINGS);
return Versions.preM && Restrictions.isAllowed(context, Restrictable.DISALLOW_IMPORT_SETTINGS);
}
public void onChange(Context context, Preference pref, Object newValue) { }

View File

@ -30,7 +30,7 @@ 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.restrictions.Restriction;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.tabqueue.TabQueueHelper;
import org.mozilla.gecko.updater.UpdateService;
import org.mozilla.gecko.updater.UpdateServiceHelper;
@ -463,7 +463,7 @@ OnSharedPreferenceChangeListener
while (iterator.hasNext()) {
Header header = iterator.next();
if (header.id == R.id.pref_header_advanced && !Restrictions.isAllowed(this, Restriction.DISALLOW_ADVANCED_SETTINGS)) {
if (header.id == R.id.pref_header_advanced && !Restrictions.isAllowed(this, Restrictable.DISALLOW_ADVANCED_SETTINGS)) {
iterator.remove();
}
}
@ -678,7 +678,7 @@ OnSharedPreferenceChangeListener
continue;
}
} else if (PREFS_SCREEN_ADVANCED.equals(key) &&
!Restrictions.isAllowed(this, Restriction.DISALLOW_ADVANCED_SETTINGS)) {
!Restrictions.isAllowed(this, Restrictable.DISALLOW_ADVANCED_SETTINGS)) {
preferences.removePreference(pref);
i--;
continue;
@ -694,7 +694,7 @@ OnSharedPreferenceChangeListener
}
} else if (PREFS_OPEN_URLS_IN_PRIVATE.equals(key)) {
// Remove UI for opening external links in private browsing on non-Nightly builds.
if (!AppConstants.NIGHTLY_BUILD || !Restrictions.isAllowed(this, Restriction.DISALLOW_PRIVATE_BROWSING)) {
if (!AppConstants.NIGHTLY_BUILD || !Restrictions.isAllowed(this, Restrictable.DISALLOW_PRIVATE_BROWSING)) {
preferences.removePreference(pref);
i--;
continue;
@ -734,19 +734,19 @@ OnSharedPreferenceChangeListener
}
} else if (PREFS_GEO_REPORTING.equals(key) ||
PREFS_GEO_LEARN_MORE.equals(key)) {
if (!AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED || !Restrictions.isAllowed(this, Restriction.DISALLOW_LOCATION_SERVICE)) {
if (!AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED || !Restrictions.isAllowed(this, Restrictable.DISALLOW_LOCATION_SERVICE)) {
preferences.removePreference(pref);
i--;
continue;
}
} else if (PREFS_DEVTOOLS_REMOTE_USB_ENABLED.equals(key)) {
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_REMOTE_DEBUGGING)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_REMOTE_DEBUGGING)) {
preferences.removePreference(pref);
i--;
continue;
}
} else if (PREFS_DEVTOOLS_REMOTE_WIFI_ENABLED.equals(key)) {
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_REMOTE_DEBUGGING)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_REMOTE_DEBUGGING)) {
preferences.removePreference(pref);
i--;
continue;
@ -759,7 +759,7 @@ OnSharedPreferenceChangeListener
}
} else if (PREFS_DEVTOOLS_REMOTE_LINK.equals(key)) {
// Remove the "Learn more" link if remote debugging is disabled
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_REMOTE_DEBUGGING)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_REMOTE_DEBUGGING)) {
preferences.removePreference(pref);
i--;
continue;
@ -776,7 +776,7 @@ OnSharedPreferenceChangeListener
continue;
} else if (PREFS_SYNC.equals(key)) {
// Don't show sync prefs while in guest mode.
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_MODIFY_ACCOUNTS)) {
preferences.removePreference(pref);
i--;
continue;
@ -819,19 +819,19 @@ OnSharedPreferenceChangeListener
continue;
}
} else if (PREFS_TRACKING_PROTECTION_PRIVATE_BROWSING.equals(key)) {
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_PRIVATE_BROWSING)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_PRIVATE_BROWSING)) {
preferences.removePreference(pref);
i--;
continue;
}
} else if (PREFS_TRACKING_PROTECTION_LEARN_MORE.equals(key)) {
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_PRIVATE_BROWSING)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_PRIVATE_BROWSING)) {
preferences.removePreference(pref);
i--;
continue;
}
} else if (PREFS_MP_ENABLED.equals(key)) {
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_MASTER_PASSWORD)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_MASTER_PASSWORD)) {
preferences.removePreference(pref);
i--;
continue;
@ -843,7 +843,7 @@ OnSharedPreferenceChangeListener
continue;
}
} else if (PREFS_CLEAR_PRIVATE_DATA.equals(key) || PREFS_CLEAR_PRIVATE_DATA_EXIT.equals(key)) {
if (!Restrictions.isAllowed(this, Restriction.DISALLOW_CLEAR_HISTORY)) {
if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_CLEAR_HISTORY)) {
preferences.removePreference(pref);
i--;
continue;

View File

@ -11,7 +11,7 @@ package org.mozilla.gecko.restrictions;
*/
public class DefaultConfiguration implements RestrictionConfiguration {
@Override
public boolean isAllowed(Restriction restriction) {
public boolean isAllowed(Restrictable restrictable) {
return true;
}

View File

@ -14,18 +14,18 @@ import java.util.List;
* RestrictionConfiguration implementation for guest profiles.
*/
public class GuestProfileConfiguration implements RestrictionConfiguration {
static List<Restriction> DEFAULT_RESTRICTIONS = Arrays.asList(
Restriction.DISALLOW_DOWNLOADS,
Restriction.DISALLOW_INSTALL_EXTENSION,
Restriction.DISALLOW_INSTALL_APPS,
Restriction.DISALLOW_BROWSE_FILES,
Restriction.DISALLOW_SHARE,
Restriction.DISALLOW_BOOKMARK,
Restriction.DISALLOW_ADD_CONTACTS,
Restriction.DISALLOW_SET_IMAGE,
Restriction.DISALLOW_MODIFY_ACCOUNTS,
Restriction.DISALLOW_REMOTE_DEBUGGING,
Restriction.DISALLOW_IMPORT_SETTINGS
static List<Restrictable> DEFAULT_RESTRICTIONS = Arrays.asList(
Restrictable.DISALLOW_DOWNLOADS,
Restrictable.DISALLOW_INSTALL_EXTENSION,
Restrictable.DISALLOW_INSTALL_APPS,
Restrictable.DISALLOW_BROWSE_FILES,
Restrictable.DISALLOW_SHARE,
Restrictable.DISALLOW_BOOKMARK,
Restrictable.DISALLOW_ADD_CONTACTS,
Restrictable.DISALLOW_SET_IMAGE,
Restrictable.DISALLOW_MODIFY_ACCOUNTS,
Restrictable.DISALLOW_REMOTE_DEBUGGING,
Restrictable.DISALLOW_IMPORT_SETTINGS
);
@SuppressWarnings("serial")
@ -43,8 +43,8 @@ public class GuestProfileConfiguration implements RestrictionConfiguration {
);
@Override
public boolean isAllowed(Restriction restriction) {
return !DEFAULT_RESTRICTIONS.contains(restriction);
public boolean isAllowed(Restrictable restrictable) {
return !DEFAULT_RESTRICTIONS.contains(restrictable);
}
@Override

View File

@ -15,7 +15,7 @@ import android.support.annotation.StringRes;
* Others are specific to us.
* These constants should be in sync with the ones from toolkit/components/parentalcontrols/nsIParentalControlsService.idl
*/
public enum Restriction {
public enum Restrictable {
DISALLOW_DOWNLOADS(1, "no_download_files", 0),
DISALLOW_INSTALL_EXTENSION(2, "no_install_extensions", R.string.restriction_disallow_addons_title),
@ -60,7 +60,7 @@ public enum Restriction {
@StringRes
public final int title;
Restriction(final int id, final String name, @StringRes int title) {
Restrictable(final int id, final String name, @StringRes int title) {
this.id = id;
this.name = name;
this.title = title;

View File

@ -20,15 +20,15 @@ import java.util.List;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class RestrictedProfileConfiguration implements RestrictionConfiguration {
static List<Restriction> DEFAULT_RESTRICTIONS = Arrays.asList(
Restriction.DISALLOW_INSTALL_EXTENSION,
Restriction.DISALLOW_PRIVATE_BROWSING,
Restriction.DISALLOW_LOCATION_SERVICE,
Restriction.DISALLOW_CLEAR_HISTORY,
Restriction.DISALLOW_MASTER_PASSWORD,
Restriction.DISALLOW_GUEST_BROWSING,
Restriction.DISALLOW_ADVANCED_SETTINGS,
Restriction.DISALLOW_CAMERA_MICROPHONE
static List<Restrictable> DEFAULT_RESTRICTIONS = Arrays.asList(
Restrictable.DISALLOW_INSTALL_EXTENSION,
Restrictable.DISALLOW_PRIVATE_BROWSING,
Restrictable.DISALLOW_LOCATION_SERVICE,
Restrictable.DISALLOW_CLEAR_HISTORY,
Restrictable.DISALLOW_MASTER_PASSWORD,
Restrictable.DISALLOW_GUEST_BROWSING,
Restrictable.DISALLOW_ADVANCED_SETTINGS,
Restrictable.DISALLOW_CAMERA_MICROPHONE
);
private Context context;
@ -40,13 +40,13 @@ public class RestrictedProfileConfiguration implements RestrictionConfiguration
}
@Override
public synchronized boolean isAllowed(Restriction restriction) {
public synchronized boolean isAllowed(Restrictable restrictable) {
if (isCacheInvalid || !ThreadUtils.isOnUiThread()) {
cachedRestrictions = readRestrictions();
isCacheInvalid = false;
}
return !cachedRestrictions.getBoolean(restriction.name, DEFAULT_RESTRICTIONS.contains(restriction));
return !cachedRestrictions.getBoolean(restrictable.name, DEFAULT_RESTRICTIONS.contains(restrictable));
}
private Bundle readRestrictions() {
@ -66,11 +66,11 @@ public class RestrictedProfileConfiguration implements RestrictionConfiguration
@Override
public boolean canLoadUrl(String url) {
if (!isAllowed(Restriction.DISALLOW_INSTALL_EXTENSION) && AboutPages.isAboutAddons(url)) {
if (!isAllowed(Restrictable.DISALLOW_INSTALL_EXTENSION) && AboutPages.isAboutAddons(url)) {
return false;
}
if (!isAllowed(Restriction.DISALLOW_PRIVATE_BROWSING) && AboutPages.isAboutPrivateBrowsing(url)) {
if (!isAllowed(Restrictable.DISALLOW_PRIVATE_BROWSING) && AboutPages.isAboutPrivateBrowsing(url)) {
return false;
}

View File

@ -12,7 +12,7 @@ public interface RestrictionConfiguration {
/**
* Is the user allowed to perform this action?
*/
boolean isAllowed(Restriction restriction);
boolean isAllowed(Restrictable restrictable);
/**
* Is the user allowed to load the given URL?

View File

@ -6,9 +6,6 @@
package org.mozilla.gecko.restrictions;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.restrictions.RestrictedProfileConfiguration;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.sync.setup.Constants;
import android.annotation.TargetApi;
import android.app.Activity;
@ -53,23 +50,23 @@ public class RestrictionProvider extends BroadcastReceiver {
private ArrayList<RestrictionEntry> initRestrictions(Context context, Bundle oldRestrictions) {
ArrayList<RestrictionEntry> entries = new ArrayList<RestrictionEntry>();
for (Restriction restriction : RestrictedProfileConfiguration.DEFAULT_RESTRICTIONS) {
if (restriction == Restriction.DISALLOW_LOCATION_SERVICE && !AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED) {
for (Restrictable restrictable : RestrictedProfileConfiguration.DEFAULT_RESTRICTIONS) {
if (restrictable == Restrictable.DISALLOW_LOCATION_SERVICE && !AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED) {
continue;
}
RestrictionEntry entry = createRestrictionEntryWithDefaultValue(context, restriction,
oldRestrictions.getBoolean(restriction.name, true));
RestrictionEntry entry = createRestrictionEntryWithDefaultValue(context, restrictable,
oldRestrictions.getBoolean(restrictable.name, true));
entries.add(entry);
}
return entries;
}
private RestrictionEntry createRestrictionEntryWithDefaultValue(Context context, Restriction restriction, boolean defaultValue) {
RestrictionEntry entry = new RestrictionEntry(restriction.name, defaultValue);
private RestrictionEntry createRestrictionEntryWithDefaultValue(Context context, Restrictable restrictable, boolean defaultValue) {
RestrictionEntry entry = new RestrictionEntry(restrictable.name, defaultValue);
entry.setTitle(restriction.getTitle(context));
entry.setTitle(restrictable.getTitle(context));
return entry;
}

View File

@ -16,7 +16,7 @@ import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.animation.ViewHelper;
import org.mozilla.gecko.lwt.LightweightTheme;
import org.mozilla.gecko.lwt.LightweightThemeDrawable;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.util.ColorUtils;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.widget.GeckoPopupMenu;
@ -144,7 +144,7 @@ public class TabsPanel extends LinearLayout
(ThemedImageButton) mTabWidget.addTab(R.drawable.tabs_private, R.string.tabs_private);
privateTabsPanel.setPrivateMode(true);
if (!Restrictions.isAllowed(mContext, Restriction.DISALLOW_PRIVATE_BROWSING)) {
if (!Restrictions.isAllowed(mContext, Restrictable.DISALLOW_PRIVATE_BROWSING)) {
mTabWidget.setVisibility(View.GONE);
}
@ -173,7 +173,7 @@ public class TabsPanel extends LinearLayout
// Each panel has a "+" shortcut button, so don't show it for that panel.
menu.findItem(R.id.new_tab).setVisible(mCurrentPanel != Panel.NORMAL_TABS);
menu.findItem(R.id.new_private_tab).setVisible(mCurrentPanel != Panel.PRIVATE_TABS
&& Restrictions.isAllowed(mContext, Restriction.DISALLOW_PRIVATE_BROWSING));
&& Restrictions.isAllowed(mContext, Restrictable.DISALLOW_PRIVATE_BROWSING));
// Only show "Clear * tabs" for current panel.
menu.findItem(R.id.close_all_tabs).setVisible(mCurrentPanel == Panel.NORMAL_TABS);

View File

@ -7,7 +7,7 @@ package org.mozilla.gecko.tests;
import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertTrue;
import org.mozilla.gecko.Restrictions;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.restrictions.Restrictable;
import org.mozilla.gecko.tests.helpers.GeckoHelper;
public class testRestrictions extends UITest {
@ -15,9 +15,9 @@ public class testRestrictions extends UITest {
GeckoHelper.blockForReady();
// No restrictions should be enforced when using a normal profile
for (Restriction restriction : Restriction.values()) {
fAssertTrue(String.format("Restriction %s is not enforced", restriction.name),
Restrictions.isAllowed(getActivity(), restriction)
for (Restrictable restrictable : Restrictable.values()) {
fAssertTrue(String.format("Restriction %s is not enforced", restrictable.name),
Restrictions.isAllowed(getActivity(), restrictable)
);
}
}