From 67ae683af3fa6bec8b3138b83b44bbea69a15cc6 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Wed, 11 Nov 2015 18:17:19 +0100 Subject: [PATCH] Bug 1189336 - (Part 3) Move from a list of disallowed things to a list of restrictable features. r=ally --- mobile/android/base/AccountsHelper.java | 2 +- mobile/android/base/BrowserApp.java | 12 ++--- mobile/android/base/Restrictions.java | 2 +- mobile/android/base/home/HistoryPanel.java | 6 +-- .../base/home/HomeConfigPrefsBackend.java | 2 +- mobile/android/base/home/HomeFragment.java | 2 +- mobile/android/base/home/TopSitesPanel.java | 6 +-- .../base/locales/en-US/android_strings.dtd | 20 ++++---- .../preferences/AndroidImportPreference.java | 2 +- .../base/preferences/GeckoPreferences.java | 24 +++++----- .../GuestProfileConfiguration.java | 26 +++++------ .../base/restrictions/Restrictable.java | 36 +++++++-------- .../RestrictedProfileConfiguration.java | 46 +++++++++++-------- .../restrictions/RestrictionProvider.java | 6 +-- mobile/android/base/strings.xml.in | 18 ++++---- mobile/android/base/tabs/TabsPanel.java | 4 +- mobile/android/chrome/content/browser.js | 4 +- .../chrome/test_restricted_profiles.html | 2 +- .../nsIParentalControlsService.idl | 4 +- 19 files changed, 115 insertions(+), 109 deletions(-) diff --git a/mobile/android/base/AccountsHelper.java b/mobile/android/base/AccountsHelper.java index 5aae9d41cff..fce925d2c7b 100644 --- a/mobile/android/base/AccountsHelper.java +++ b/mobile/android/base/AccountsHelper.java @@ -83,7 +83,7 @@ public class AccountsHelper implements NativeEventListener { @Override public void handleMessage(String event, NativeJSObject message, final EventCallback callback) { - if (!Restrictions.isAllowed(mContext, Restrictable.DISALLOW_MODIFY_ACCOUNTS)) { + if (!Restrictions.isAllowed(mContext, Restrictable.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); diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 99a216ec0a5..294c107f163 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -1793,7 +1793,7 @@ public class BrowserApp extends GeckoApp } } - if (AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED && Restrictions.isAllowed(this, Restrictable.DISALLOW_LOCATION_SERVICE)) { + if (AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED && Restrictions.isAllowed(this, Restrictable.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, Restrictable.DISALLOW_SHARE); + final boolean shareVisible = Restrictions.isAllowed(this, Restrictable.SHARE); share.setVisible(shareVisible); final boolean shareEnabled = StringUtils.isShareableUrl(url) && shareVisible; share.setEnabled(shareEnabled); - MenuUtils.safeSetEnabled(aMenu, R.id.downloads, Restrictions.isAllowed(this, Restrictable.DISALLOW_DOWNLOADS)); + MenuUtils.safeSetEnabled(aMenu, R.id.downloads, Restrictions.isAllowed(this, Restrictable.DOWNLOAD)); // 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, Restrictable.DISALLOW_PRIVATE_BROWSING); + final boolean privateTabVisible = Restrictions.isAllowed(this, Restrictable.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, Restrictable.DISALLOW_GUEST_BROWSING)) { + if (!Restrictions.isAllowed(this, Restrictable.GUEST_BROWSING)) { MenuUtils.safeSetVisible(aMenu, R.id.new_guest_session, false); } - if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_INSTALL_EXTENSION)) { + if (!Restrictions.isAllowed(this, Restrictable.INSTALL_EXTENSION)) { MenuUtils.safeSetVisible(aMenu, R.id.addons, false); } diff --git a/mobile/android/base/Restrictions.java b/mobile/android/base/Restrictions.java index 6808ea67fb7..54079a451bd 100644 --- a/mobile/android/base/Restrictions.java +++ b/mobile/android/base/Restrictions.java @@ -123,7 +123,7 @@ public class Restrictions { final Context context = GeckoAppShell.getApplicationContext(); - if (Restrictable.DISALLOW_BROWSE_FILES == restrictable) { + if (Restrictable.BROWSE == restrictable) { return canLoadUrl(context, url); } else { return isAllowed(context, restrictable); diff --git a/mobile/android/base/home/HistoryPanel.java b/mobile/android/base/home/HistoryPanel.java index 364b702ce00..7ef071ec252 100644 --- a/mobile/android/base/home/HistoryPanel.java +++ b/mobile/android/base/home/HistoryPanel.java @@ -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(), Restrictable.DISALLOW_CLEAR_HISTORY)) { + if (!Restrictions.isAllowed(getActivity(), Restrictable.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(), Restrictable.DISALLOW_CLEAR_HISTORY)) { + if (Restrictions.isAllowed(getActivity(), Restrictable.CLEAR_HISTORY)) { mClearHistoryButton.setVisibility(View.VISIBLE); } return; @@ -322,7 +322,7 @@ public class HistoryPanel extends HomeFragment { emptyHint.setVisibility(View.VISIBLE); } - if (!Restrictions.isAllowed(getActivity(), Restrictable.DISALLOW_PRIVATE_BROWSING)) { + if (!Restrictions.isAllowed(getActivity(), Restrictable.PRIVATE_BROWSING)) { emptyHint.setVisibility(View.GONE); } diff --git a/mobile/android/base/home/HomeConfigPrefsBackend.java b/mobile/android/base/home/HomeConfigPrefsBackend.java index b83ca9edf63..8621f5734f8 100644 --- a/mobile/android/base/home/HomeConfigPrefsBackend.java +++ b/mobile/android/base/home/HomeConfigPrefsBackend.java @@ -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, Restrictable.DISALLOW_MODIFY_ACCOUNTS)) { + if (Restrictions.isAllowed(mContext, Restrictable.MODIFY_ACCOUNTS)) { panelConfigs.add(createBuiltinPanelConfig(mContext, PanelType.REMOTE_TABS)); } diff --git a/mobile/android/base/home/HomeFragment.java b/mobile/android/base/home/HomeFragment.java index 8fd9ecf01bb..c98a7afb889 100644 --- a/mobile/android/base/home/HomeFragment.java +++ b/mobile/android/base/home/HomeFragment.java @@ -153,7 +153,7 @@ public abstract class HomeFragment extends Fragment { menu.findItem(R.id.home_share).setVisible(false); } - if (!Restrictions.isAllowed(view.getContext(), Restrictable.DISALLOW_PRIVATE_BROWSING)) { + if (!Restrictions.isAllowed(view.getContext(), Restrictable.PRIVATE_BROWSING)) { menu.findItem(R.id.home_open_private_tab).setVisible(false); } diff --git a/mobile/android/base/home/TopSitesPanel.java b/mobile/android/base/home/TopSitesPanel.java index ade2f3caef4..96334333a4a 100644 --- a/mobile/android/base/home/TopSitesPanel.java +++ b/mobile/android/base/home/TopSitesPanel.java @@ -343,7 +343,7 @@ public class TopSitesPanel extends HomeFragment { // can handle this. super.onCreateContextMenu(menu, view, menuInfo); - if (!Restrictions.isAllowed(view.getContext(), Restrictable.DISALLOW_CLEAR_HISTORY)) { + if (!Restrictions.isAllowed(view.getContext(), Restrictable.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, Restrictable.DISALLOW_CLEAR_HISTORY)); + menu.findItem(R.id.home_remove).setVisible(Restrictions.isAllowed(context, Restrictable.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, Restrictable.DISALLOW_PRIVATE_BROWSING)) { + if (!Restrictions.isAllowed(context, Restrictable.PRIVATE_BROWSING)) { menu.findItem(R.id.home_open_private_tab).setVisible(false); } diff --git a/mobile/android/base/locales/en-US/android_strings.dtd b/mobile/android/base/locales/en-US/android_strings.dtd index 3c999eeb4e7..02c8e7f3840 100644 --- a/mobile/android/base/locales/en-US/android_strings.dtd +++ b/mobile/android/base/locales/en-US/android_strings.dtd @@ -713,17 +713,17 @@ just addresses the organization to follow, e.g. "This site is run by " --> code. --> - - + - - - - - - - - + + + + + + + + diff --git a/mobile/android/base/preferences/AndroidImportPreference.java b/mobile/android/base/preferences/AndroidImportPreference.java index 81172bbd07f..68dd86eef10 100644 --- a/mobile/android/base/preferences/AndroidImportPreference.java +++ b/mobile/android/base/preferences/AndroidImportPreference.java @@ -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, Restrictable.DISALLOW_IMPORT_SETTINGS); + return Versions.preM && Restrictions.isAllowed(context, Restrictable.IMPORT_SETTINGS); } public void onChange(Context context, Preference pref, Object newValue) { } diff --git a/mobile/android/base/preferences/GeckoPreferences.java b/mobile/android/base/preferences/GeckoPreferences.java index c4c3740a510..7177b451103 100644 --- a/mobile/android/base/preferences/GeckoPreferences.java +++ b/mobile/android/base/preferences/GeckoPreferences.java @@ -463,7 +463,7 @@ OnSharedPreferenceChangeListener while (iterator.hasNext()) { Header header = iterator.next(); - if (header.id == R.id.pref_header_advanced && !Restrictions.isAllowed(this, Restrictable.DISALLOW_ADVANCED_SETTINGS)) { + if (header.id == R.id.pref_header_advanced && !Restrictions.isAllowed(this, Restrictable.ADVANCED_SETTINGS)) { iterator.remove(); } } @@ -678,7 +678,7 @@ OnSharedPreferenceChangeListener continue; } } else if (PREFS_SCREEN_ADVANCED.equals(key) && - !Restrictions.isAllowed(this, Restrictable.DISALLOW_ADVANCED_SETTINGS)) { + !Restrictions.isAllowed(this, Restrictable.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, Restrictable.DISALLOW_PRIVATE_BROWSING)) { + if (!AppConstants.NIGHTLY_BUILD || !Restrictions.isAllowed(this, Restrictable.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, Restrictable.DISALLOW_LOCATION_SERVICE)) { + if (!AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED || !Restrictions.isAllowed(this, Restrictable.LOCATION_SERVICE)) { preferences.removePreference(pref); i--; continue; } } else if (PREFS_DEVTOOLS_REMOTE_USB_ENABLED.equals(key)) { - if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_REMOTE_DEBUGGING)) { + if (!Restrictions.isAllowed(this, Restrictable.REMOTE_DEBUGGING)) { preferences.removePreference(pref); i--; continue; } } else if (PREFS_DEVTOOLS_REMOTE_WIFI_ENABLED.equals(key)) { - if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_REMOTE_DEBUGGING)) { + if (!Restrictions.isAllowed(this, Restrictable.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, Restrictable.DISALLOW_REMOTE_DEBUGGING)) { + if (!Restrictions.isAllowed(this, Restrictable.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, Restrictable.DISALLOW_MODIFY_ACCOUNTS)) { + if (!Restrictions.isAllowed(this, Restrictable.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, Restrictable.DISALLOW_PRIVATE_BROWSING)) { + if (!Restrictions.isAllowed(this, Restrictable.PRIVATE_BROWSING)) { preferences.removePreference(pref); i--; continue; } } else if (PREFS_TRACKING_PROTECTION_LEARN_MORE.equals(key)) { - if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_PRIVATE_BROWSING)) { + if (!Restrictions.isAllowed(this, Restrictable.PRIVATE_BROWSING)) { preferences.removePreference(pref); i--; continue; } } else if (PREFS_MP_ENABLED.equals(key)) { - if (!Restrictions.isAllowed(this, Restrictable.DISALLOW_MASTER_PASSWORD)) { + if (!Restrictions.isAllowed(this, Restrictable.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, Restrictable.DISALLOW_CLEAR_HISTORY)) { + if (!Restrictions.isAllowed(this, Restrictable.CLEAR_HISTORY)) { preferences.removePreference(pref); i--; continue; diff --git a/mobile/android/base/restrictions/GuestProfileConfiguration.java b/mobile/android/base/restrictions/GuestProfileConfiguration.java index 7650bbf8978..aee84ae5f01 100644 --- a/mobile/android/base/restrictions/GuestProfileConfiguration.java +++ b/mobile/android/base/restrictions/GuestProfileConfiguration.java @@ -14,18 +14,18 @@ import java.util.List; * RestrictionConfiguration implementation for guest profiles. */ public class GuestProfileConfiguration implements RestrictionConfiguration { - static List 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 + static List DISABLED_FEATURES = Arrays.asList( + Restrictable.DOWNLOAD, + Restrictable.INSTALL_EXTENSION, + Restrictable.INSTALL_APPS, + Restrictable.BROWSE, + Restrictable.SHARE, + Restrictable.BOOKMARK, + Restrictable.ADD_CONTACT, + Restrictable.SET_IMAGE, + Restrictable.MODIFY_ACCOUNTS, + Restrictable.REMOTE_DEBUGGING, + Restrictable.IMPORT_SETTINGS ); @SuppressWarnings("serial") @@ -44,7 +44,7 @@ public class GuestProfileConfiguration implements RestrictionConfiguration { @Override public boolean isAllowed(Restrictable restrictable) { - return !DEFAULT_RESTRICTIONS.contains(restrictable); + return !DISABLED_FEATURES.contains(restrictable); } @Override diff --git a/mobile/android/base/restrictions/Restrictable.java b/mobile/android/base/restrictions/Restrictable.java index d17d3e18cba..e9a53013b3b 100644 --- a/mobile/android/base/restrictions/Restrictable.java +++ b/mobile/android/base/restrictions/Restrictable.java @@ -16,43 +16,43 @@ import android.support.annotation.StringRes; * These constants should be in sync with the ones from toolkit/components/parentalcontrols/nsIParentalControlsService.idl */ public enum Restrictable { - DISALLOW_DOWNLOADS(1, "no_download_files", 0), + DOWNLOAD(1, "downloads", 0), - DISALLOW_INSTALL_EXTENSION(2, "no_install_extensions", R.string.restriction_disallow_addons_title), + INSTALL_EXTENSION(2, "no_install_extensions", R.string.restrictable_feature_addons_installation), // UserManager.DISALLOW_INSTALL_APPS - DISALLOW_INSTALL_APPS(3, "no_install_apps", 0), + INSTALL_APPS(3, "no_install_apps", 0), - DISALLOW_BROWSE_FILES(4, "no_browse_files", 0), + BROWSE(4, "browse", 0), - DISALLOW_SHARE(5, "no_share", 0), + SHARE(5, "share", 0), - DISALLOW_BOOKMARK(6, "no_bookmark", 0), + BOOKMARK(6, "bookmark", 0), - DISALLOW_ADD_CONTACTS(7, "no_add_contacts", 0), + ADD_CONTACT(7, "add_contact", 0), - DISALLOW_SET_IMAGE(8, "no_set_image", 0), + SET_IMAGE(8, "set_image", 0), // UserManager.DISALLOW_MODIFY_ACCOUNTS - DISALLOW_MODIFY_ACCOUNTS(9, "no_modify_accounts", 0), + MODIFY_ACCOUNTS(9, "no_modify_accounts", 0), - DISALLOW_REMOTE_DEBUGGING(10, "no_remote_debugging", 0), + REMOTE_DEBUGGING(10, "remote_debugging", 0), - DISALLOW_IMPORT_SETTINGS(11, "no_import_settings", 0), + IMPORT_SETTINGS(11, "import_settings", 0), - DISALLOW_PRIVATE_BROWSING(12, "no_private_browsing", R.string.restriction_disallow_private_browsing_title), + PRIVATE_BROWSING(12, "private_browsing", R.string.restrictable_feature_private_browsing), - DISALLOW_LOCATION_SERVICE(13, "no_location_service", R.string.restriction_disallow_location_services_title), + LOCATION_SERVICE(13, "location_service", R.string.restrictable_feature_location_services), - DISALLOW_CLEAR_HISTORY(14, "no_clear_history", R.string.restriction_disallow_clear_history_title), + CLEAR_HISTORY(14, "clear_history", R.string.restrictable_feature_clear_history), - DISALLOW_MASTER_PASSWORD(15, "no_master_password", R.string.restriction_disallow_master_password_title), + MASTER_PASSWORD(15, "master_password", R.string.restrictable_feature_master_password), - DISALLOW_GUEST_BROWSING(16, "no_guest_browsing", R.string.restriction_disallow_guest_browsing_title), + GUEST_BROWSING(16, "guest_browsing", R.string.restrictable_feature_guest_browsing), - DISALLOW_ADVANCED_SETTINGS(17, "no_advanced_settings", R.string.restriction_disallow_advanced_settings_title), + ADVANCED_SETTINGS(17, "advanced_settings", R.string.restrictable_feature_advanced_settings), - DISALLOW_CAMERA_MICROPHONE(18, "no_camera_microphone", R.string.restriction_disallow_camera_microphone_title); + CAMERA_MICROPHONE(18, "camera_microphone", R.string.restrictable_feature_camera_microphone); public final int id; public final String name; diff --git a/mobile/android/base/restrictions/RestrictedProfileConfiguration.java b/mobile/android/base/restrictions/RestrictedProfileConfiguration.java index 7fb3a17b688..f7e9d8e99b0 100644 --- a/mobile/android/base/restrictions/RestrictedProfileConfiguration.java +++ b/mobile/android/base/restrictions/RestrictedProfileConfiguration.java @@ -20,19 +20,20 @@ import java.util.List; @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public class RestrictedProfileConfiguration implements RestrictionConfiguration { - static List 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 + static List DEFAULT_DISABLED_FEATURES = Arrays.asList( + Restrictable.INSTALL_EXTENSION, + Restrictable.PRIVATE_BROWSING, + Restrictable.LOCATION_SERVICE, + Restrictable.CLEAR_HISTORY, + Restrictable.MASTER_PASSWORD, + Restrictable.GUEST_BROWSING, + Restrictable.ADVANCED_SETTINGS, + Restrictable.CAMERA_MICROPHONE ); private Context context; - private Bundle cachedRestrictions; + private Bundle cachedAppRestrictions; + private Bundle cachedUserRestrictions; private boolean isCacheInvalid = true; public RestrictedProfileConfiguration(Context context) { @@ -42,23 +43,28 @@ public class RestrictedProfileConfiguration implements RestrictionConfiguration @Override public synchronized boolean isAllowed(Restrictable restrictable) { if (isCacheInvalid || !ThreadUtils.isOnUiThread()) { - cachedRestrictions = readRestrictions(); + readRestrictions(); isCacheInvalid = false; } - return !cachedRestrictions.getBoolean(restrictable.name, DEFAULT_RESTRICTIONS.contains(restrictable)); + // Special casing system/user restrictions + if (restrictable == Restrictable.INSTALL_APPS || restrictable == Restrictable.MODIFY_ACCOUNTS) { + return !cachedUserRestrictions.getBoolean(restrictable.name); + } + + return cachedAppRestrictions.getBoolean(restrictable.name, !DEFAULT_DISABLED_FEATURES.contains(restrictable)); } - private Bundle readRestrictions() { + private void readRestrictions() { final UserManager mgr = (UserManager) context.getSystemService(Context.USER_SERVICE); StrictMode.ThreadPolicy policy = StrictMode.allowThreadDiskReads(); try { - Bundle restrictions = new Bundle(); - restrictions.putAll(mgr.getApplicationRestrictions(context.getPackageName())); - restrictions.putAll(mgr.getUserRestrictions()); - return restrictions; + cachedAppRestrictions = mgr.getApplicationRestrictions(context.getPackageName()); + cachedUserRestrictions = mgr.getUserRestrictions(); + + } finally { StrictMode.setThreadPolicy(policy); } @@ -66,11 +72,11 @@ public class RestrictedProfileConfiguration implements RestrictionConfiguration @Override public boolean canLoadUrl(String url) { - if (!isAllowed(Restrictable.DISALLOW_INSTALL_EXTENSION) && AboutPages.isAboutAddons(url)) { + if (!isAllowed(Restrictable.INSTALL_EXTENSION) && AboutPages.isAboutAddons(url)) { return false; } - if (!isAllowed(Restrictable.DISALLOW_PRIVATE_BROWSING) && AboutPages.isAboutPrivateBrowsing(url)) { + if (!isAllowed(Restrictable.PRIVATE_BROWSING) && AboutPages.isAboutPrivateBrowsing(url)) { return false; } @@ -91,4 +97,4 @@ public class RestrictedProfileConfiguration implements RestrictionConfiguration public synchronized void update() { isCacheInvalid = true; } -} +} \ No newline at end of file diff --git a/mobile/android/base/restrictions/RestrictionProvider.java b/mobile/android/base/restrictions/RestrictionProvider.java index 985b09fab73..c41c5a034c6 100644 --- a/mobile/android/base/restrictions/RestrictionProvider.java +++ b/mobile/android/base/restrictions/RestrictionProvider.java @@ -50,13 +50,13 @@ public class RestrictionProvider extends BroadcastReceiver { private ArrayList initRestrictions(Context context, Bundle oldRestrictions) { ArrayList entries = new ArrayList(); - for (Restrictable restrictable : RestrictedProfileConfiguration.DEFAULT_RESTRICTIONS) { - if (restrictable == Restrictable.DISALLOW_LOCATION_SERVICE && !AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED) { + for (Restrictable restrictable : RestrictedProfileConfiguration.DEFAULT_DISABLED_FEATURES) { + if (restrictable == Restrictable.LOCATION_SERVICE && !AppConstants.MOZ_STUMBLER_BUILD_TIME_ENABLED) { continue; } RestrictionEntry entry = createRestrictionEntryWithDefaultValue(context, restrictable, - oldRestrictions.getBoolean(restrictable.name, true)); + oldRestrictions.getBoolean(restrictable.name, false)); entries.add(entry); } diff --git a/mobile/android/base/strings.xml.in b/mobile/android/base/strings.xml.in index 0af9fc84038..b75e6fcb3ac 100644 --- a/mobile/android/base/strings.xml.in +++ b/mobile/android/base/strings.xml.in @@ -564,15 +564,15 @@ &voicesearch_prompt; - - &restriction_disallow_addons_title2; - &restriction_disallow_private_browsing_title2; - &restriction_disallow_location_services_title2; - &restriction_disallow_clear_history_title2; - &restriction_disallow_master_password_title2; - &restriction_disallow_guest_browsing_title2; - &restriction_disallow_advanced_settings_title; - &restriction_disallow_camera_microphone_title; + + &restrictable_feature_addons_installation; + &restrictable_feature_private_browsing; + &restrictable_feature_location_services; + &restrictable_feature_clear_history; + &restrictable_feature_guest_browsing; + &restrictable_feature_master_password; + &restrictable_feature_advanced_settings; + &restrictable_feature_camera_microphone; &ellipsis; diff --git a/mobile/android/base/tabs/TabsPanel.java b/mobile/android/base/tabs/TabsPanel.java index dc4c27b359d..c9617f5603f 100644 --- a/mobile/android/base/tabs/TabsPanel.java +++ b/mobile/android/base/tabs/TabsPanel.java @@ -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, Restrictable.DISALLOW_PRIVATE_BROWSING)) { + if (!Restrictions.isAllowed(mContext, Restrictable.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, Restrictable.DISALLOW_PRIVATE_BROWSING)); + && Restrictions.isAllowed(mContext, Restrictable.PRIVATE_BROWSING)); // Only show "Clear * tabs" for current panel. menu.findItem(R.id.close_all_tabs).setVisible(mCurrentPanel == Panel.NORMAL_TABS); diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 0af3affaf4a..e2f7a3ad22b 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -4487,8 +4487,8 @@ Tab.prototype = { fixedURI = URIFixup.createExposableURI(aLocationURI); } catch (ex) { } - // In restricted profiles, we refuse to let you open any file urls. - if (!ParentalControls.isAllowed(ParentalControls.VISIT_FILE_URLS, fixedURI)) { + // In restricted profiles, we refuse to let you open various urls. + if (!ParentalControls.isAllowed(ParentalControls.BROWSE, fixedURI)) { aRequest.cancel(Cr.NS_BINDING_ABORTED); this.browser.docShell.displayLoadError(Cr.NS_ERROR_UNKNOWN_PROTOCOL, fixedURI, null); diff --git a/mobile/android/tests/browser/chrome/test_restricted_profiles.html b/mobile/android/tests/browser/chrome/test_restricted_profiles.html index ad6af326e18..d699176b5f6 100644 --- a/mobile/android/tests/browser/chrome/test_restricted_profiles.html +++ b/mobile/android/tests/browser/chrome/test_restricted_profiles.html @@ -32,7 +32,7 @@ Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186 ok(pc.isAllowed(Ci.nsIParentalControlsService.DOWNLOAD)); ok(pc.isAllowed(Ci.nsIParentalControlsService.INSTALL_EXTENSION)); ok(pc.isAllowed(Ci.nsIParentalControlsService.INSTALL_APP)); - ok(pc.isAllowed(Ci.nsIParentalControlsService.VISIT_FILE_URLS)); + ok(pc.isAllowed(Ci.nsIParentalControlsService.BROWSE)); ok(pc.isAllowed(Ci.nsIParentalControlsService.SHARE)); ok(pc.isAllowed(Ci.nsIParentalControlsService.BOOKMARK)); ok(pc.isAllowed(Ci.nsIParentalControlsService.INSTALL_EXTENSION)); diff --git a/toolkit/components/parentalcontrols/nsIParentalControlsService.idl b/toolkit/components/parentalcontrols/nsIParentalControlsService.idl index 6f7fac6924d..2a5c47368e9 100644 --- a/toolkit/components/parentalcontrols/nsIParentalControlsService.idl +++ b/toolkit/components/parentalcontrols/nsIParentalControlsService.idl @@ -11,7 +11,7 @@ interface nsIFile; interface nsIInterfaceRequestor; interface nsIArray; -[scriptable, uuid(c7713ad7-0804-4353-91d5-4d7f1376bded)] +[scriptable, uuid(ec6ae96e-e161-481e-bb51-78b11fc1fdbe)] interface nsIParentalControlsService : nsISupports { /** @@ -20,7 +20,7 @@ interface nsIParentalControlsService : nsISupports const short DOWNLOAD = 1; // Downloading files const short INSTALL_EXTENSION = 2; // Installing extensions const short INSTALL_APP = 3; // Installing webapps - const short VISIT_FILE_URLS = 4; // Opening file:/// urls + const short BROWSE = 4; // Opening specific urls const short SHARE = 5; // Sharing const short BOOKMARK = 6; // Creating bookmarks const short ADD_CONTACT = 7; // Add contacts to the system database