Skip to content

Commit

Permalink
Allow managing Camera and Location for Supervised Users
Browse files Browse the repository at this point in the history
BUG=440721

Review URL: https://codereview.chromium.org/789173002

Cr-Commit-Position: refs/heads/master@{#309208}
  • Loading branch information
khannans authored and Commit bot committed Dec 19, 2014
1 parent 7c5016c commit b2025b7
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 16 deletions.
10 changes: 10 additions & 0 deletions base/prefs/pref_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ bool PrefService::IsManagedPreference(const std::string& pref_name) const {
return pref && pref->IsManaged();
}

bool PrefService::IsPreferenceManagedByCustodian(
const std::string& pref_name) const {
const Preference* pref = FindPreference(pref_name);
return pref && pref->IsManagedByCustodian();
}

bool PrefService::IsUserModifiablePreference(
const std::string& pref_name) const {
const Preference* pref = FindPreference(pref_name);
Expand Down Expand Up @@ -517,6 +523,10 @@ bool PrefService::Preference::IsManaged() const {
return pref_value_store()->PrefValueInManagedStore(name_);
}

bool PrefService::Preference::IsManagedByCustodian() const {
return pref_value_store()->PrefValueInSupervisedStore(name_.c_str());
}

bool PrefService::Preference::IsRecommended() const {
return pref_value_store()->PrefValueFromRecommendedStore(name_);
}
Expand Down
9 changes: 9 additions & 0 deletions base/prefs/pref_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe {
// whether the pref is actually being controlled by the policy setting.
bool IsManaged() const;

// Returns true if the Preference is controlled by the custodian of the
// supervised user. Since a supervised user is not expected to have an admin
// policy, this is the controlling pref if set.
bool IsManagedByCustodian() const;

// Returns true if the Preference is recommended, i.e. set by an admin
// policy but the user is allowed to change it.
bool IsRecommended() const;
Expand Down Expand Up @@ -158,6 +163,10 @@ class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe {
// and is managed.
bool IsManagedPreference(const std::string& pref_name) const;

// Returns true if the preference for the given preference name is available
// and is controlled by the parent/guardian of the child Account.
bool IsPreferenceManagedByCustodian(const std::string& pref_name) const;

// Returns |true| if a preference with the given name is available and its
// value can be changed by the user.
bool IsUserModifiablePreference(const std::string& pref_name) const;
Expand Down
4 changes: 4 additions & 0 deletions base/prefs/pref_value_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ bool PrefValueStore::PrefValueInManagedStore(const std::string& name) const {
return PrefValueInStore(name, MANAGED_STORE);
}

bool PrefValueStore::PrefValueInSupervisedStore(const std::string& name) const {
return PrefValueInStore(name, SUPERVISED_USER_STORE);
}

bool PrefValueStore::PrefValueInExtensionStore(const std::string& name) const {
return PrefValueInStore(name, EXTENSION_STORE);
}
Expand Down
1 change: 1 addition & 0 deletions base/prefs/pref_value_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class BASE_PREFS_EXPORT PrefValueStore {
// indicated pref store, even if that value is currently being overridden by
// a higher-priority source.
bool PrefValueInManagedStore(const std::string& name) const;
bool PrefValueInSupervisedStore(const std::string& name) const;
bool PrefValueInExtensionStore(const std::string& name) const;
bool PrefValueInUserStore(const std::string& name) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,25 @@ public static void showManagedByAdministratorToast(Context context) {
Toast.makeText(context, context.getString(R.string.managed_by_your_administrator),
Toast.LENGTH_LONG).show();
}
/**
* Shows a toast indicating that the previous action is managed by the parent(s) of the
* supervised user.
* This is usually used to explain to the user why a given control is disabled in the settings.
*
* @param context The context where the Toast will be shown.
*/
public static void showManagedByParentToast(Context context) {
boolean singleParentIsManager =
PrefServiceBridge.getInstance().getSupervisedUserSecondCustodianName().isEmpty();
Toast.makeText(context, context.getString(singleParentIsManager
? R.string.managed_by_your_parent : R.string.managed_by_your_parents),
Toast.LENGTH_LONG).show();
}

/**
* @return the resource ID for the Managed By Enterprise icon.
*/
public static int getManagedByEnterpriseIconId() {
return R.drawable.controlled_setting_mandatory;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.chromium.base.CalledByNative;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.search_engines.TemplateUrlService;

import java.util.ArrayList;
Expand Down Expand Up @@ -161,7 +160,6 @@ private static void onGotProfilePath(String profilePath, ProfilePathCallback cal
callback.onGotProfilePath(profilePath);
}

@VisibleForTesting
public boolean isAcceptCookiesEnabled() {
return nativeGetAcceptCookiesEnabled();
}
Expand Down Expand Up @@ -196,17 +194,32 @@ public boolean isRememberPasswordsManaged() {
}

/**
* @return whether geolocation informatoin can be shared with content
* @return whether push notifications are enabled.
*/
public boolean isPushNotificationsEnabled() {
return nativeGetPushNotificationsEnabled();
}

/**
* @return whether geolocation information can be shared with content
*/
public boolean isAllowLocationEnabled() {
return nativeGetAllowLocationEnabled();
}

/**
* @return whether the location preference is configured by policy
* @return whether the location preference is modifiable by the user.
*/
public boolean isAllowLocationManaged() {
return nativeGetAllowLocationManaged();
public boolean isAllowLocationUserModifiable() {
return nativeGetAllowLocationUserModifiable();
}

/**
* @return whether the location preference is
* being managed by the custodian of the supervised account.
*/
public boolean isAllowLocationManagedByCustodian() {
return nativeGetAllowLocationManagedByCustodian();
}

/**
Expand Down Expand Up @@ -520,6 +533,10 @@ public void setRememberPasswordsEnabled(boolean allow) {
nativeSetRememberPasswordsEnabled(allow);
}

public void setPushNotificationsEnabled(boolean allow) {
nativeSetPushNotificationsEnabled(allow);
}

public void setAllowLocationEnabled(boolean allow) {
nativeSetAllowLocationEnabled(allow);
}
Expand Down Expand Up @@ -554,11 +571,32 @@ public void setAllowPopupsEnabled(boolean allow) {
/**
* @return Whether the camera/microphone permission is enabled.
*/
@VisibleForTesting
public boolean isCameraMicEnabled() {
return nativeGetCameraMicEnabled();
}

/**
* Sets the preferences on whether to enable/disable camera and microphone
*/
public void setCameraMicEnabled(boolean enabled) {
nativeSetCameraMicEnabled(enabled);
}

/**
* @return Whether the camera/microphone permission is managed
* by the custodian of the supervised account.
*/
public boolean isCameraMicManagedByCustodian() {
return nativeGetCameraMicManagedByCustodian();
}

/**
* @return Whether the camera/microphone permission is editable by the user.
*/
public boolean isCameraMicUserModifiable() {
return nativeGetCameraMicUserModifiable();
}

/**
* @return true if incognito mode is enabled.
*/
Expand Down Expand Up @@ -685,11 +723,14 @@ public String getSupervisedUserSecondCustodianProfileImageURL() {
private native boolean nativeGetBlockThirdPartyCookiesManaged();
private native boolean nativeGetRememberPasswordsEnabled();
private native boolean nativeGetRememberPasswordsManaged();
private native boolean nativeGetAllowLocationManaged();
private native boolean nativeGetAllowLocationUserModifiable();
private native boolean nativeGetAllowLocationManagedByCustodian();
private native boolean nativeGetDoNotTrackEnabled();
private native boolean nativeGetPasswordEchoEnabled();
private native boolean nativeGetFirstRunEulaAccepted();
private native boolean nativeGetJavaScriptManaged();
private native boolean nativeGetCameraMicUserModifiable();
private native boolean nativeGetCameraMicManagedByCustodian();
private native boolean nativeGetTranslateEnabled();
private native boolean nativeGetTranslateManaged();
private native boolean nativeGetResolveNavigationErrorEnabled();
Expand All @@ -713,7 +754,10 @@ private native void nativeClearBrowsingData(boolean history, boolean cache,
private native void nativeSetRememberPasswordsEnabled(boolean allow);
private native void nativeSetProtectedMediaIdentifierEnabled(boolean enabled);
private native boolean nativeGetAllowLocationEnabled();
private native boolean nativeGetPushNotificationsEnabled();
private native void nativeSetAllowLocationEnabled(boolean allow);
private native void nativeSetCameraMicEnabled(boolean allow);
private native void nativeSetPushNotificationsEnabled(boolean allow);
private native void nativeSetPasswordEchoEnabled(boolean enabled);
private native boolean nativeGetAllowPopupsEnabled();
private native boolean nativeGetAllowPopupsManaged();
Expand Down
6 changes: 6 additions & 0 deletions chrome/android/java/strings/android_chrome_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@
<message name="IDS_MANAGED_BY_YOUR_ADMINISTRATOR" desc="Popup message when the user clicks a UI element that has been disabled by enterprise policy.">
Managed by your administrator
</message>
<message name="IDS_MANAGED_BY_YOUR_PARENTS" desc="Popup message when the user clicks a UI element that has been disabled by his/her parents.">
Managed by your parents
</message>
<message name="IDS_MANAGED_BY_YOUR_PARENT" desc="Popup message when the user clicks a UI element that has been disabled by his/her parent.">
Managed by your parent
</message>

<!-- Search engine preferences -->
<message name="IDS_PREFS_SEARCH_ENGINE" desc="Title for Search Engine preferences. [CHAR-LIMIT=32]">
Expand Down
85 changes: 78 additions & 7 deletions chrome/browser/android/preferences/pref_service_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ bool IsContentSettingManaged(HostContentSettingsMap* content_settings,
return provider == HostContentSettingsMap::POLICY_PROVIDER;
}

bool IsContentSettingUserModifiable(HostContentSettingsMap* content_settings,
ContentSettingsType content_settings_type) {
std::string source;
content_settings->GetDefaultContentSetting(content_settings_type, &source);
HostContentSettingsMap::ProviderType provider =
content_settings->GetProviderTypeFromSource(source);
return provider >= HostContentSettingsMap::PREF_PROVIDER;
}

void OnGotProfilePath(ScopedJavaGlobalRef<jobject>* callback,
std::string path) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
Expand Down Expand Up @@ -254,19 +263,42 @@ static jboolean GetSearchSuggestManaged(JNIEnv* env, jobject obj) {
static jboolean GetProtectedMediaIdentifierEnabled(JNIEnv* env, jobject obj) {
Profile* profile = GetOriginalProfile();
EnsureConsistentProtectedMediaIdentifierPreferences(profile);
return GetPrefService()->GetBoolean(prefs::kProtectedMediaIdentifierEnabled);
HostContentSettingsMap* content_settings =
profile->GetHostContentSettingsMap();
return GetBooleanForContentSetting(
content_settings,
CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) &&
GetPrefService()->GetBoolean(prefs::kProtectedMediaIdentifierEnabled);
}

static jboolean GetPushNotificationsEnabled(JNIEnv* env, jobject obj) {
HostContentSettingsMap* content_settings =
GetOriginalProfile()->GetHostContentSettingsMap();
return GetBooleanForContentSetting(content_settings,
CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
}

static jboolean GetAllowLocationEnabled(JNIEnv* env, jobject obj) {
Profile* profile = GetOriginalProfile();
EnsureConsistentGeolocationPreferences(profile);
return GetPrefService()->GetBoolean(prefs::kGeolocationEnabled);
HostContentSettingsMap* content_settings =
profile->GetHostContentSettingsMap();
return GetBooleanForContentSetting(content_settings,
CONTENT_SETTINGS_TYPE_GEOLOCATION) &&
GetPrefService()->GetBoolean(prefs::kGeolocationEnabled);
}

static jboolean GetAllowLocationManaged(JNIEnv* env, jobject obj) {
return IsContentSettingManaged(
GetOriginalProfile()->GetHostContentSettingsMap(),
CONTENT_SETTINGS_TYPE_GEOLOCATION);
static jboolean GetAllowLocationUserModifiable(JNIEnv* env, jobject obj) {
return IsContentSettingUserModifiable(
GetOriginalProfile()->GetHostContentSettingsMap(),
CONTENT_SETTINGS_TYPE_GEOLOCATION) &&
GetPrefService()->IsUserModifiablePreference(
prefs::kGeolocationEnabled);
}

static jboolean GetAllowLocationManagedByCustodian(JNIEnv* env, jobject obj) {
return GetPrefService()->IsPreferenceManagedByCustodian(
prefs::kGeolocationEnabled);
}

static jboolean GetResolveNavigationErrorEnabled(JNIEnv* env, jobject obj) {
Expand Down Expand Up @@ -396,6 +428,24 @@ static void SetAllowLocationEnabled(JNIEnv* env, jobject obj, jboolean allow) {
GetPrefService()->SetBoolean(prefs::kGeolocationEnabled, allow);
}

static void SetCameraMicEnabled(JNIEnv* env, jobject obj, jboolean allow) {
HostContentSettingsMap* host_content_settings_map =
GetOriginalProfile()->GetHostContentSettingsMap();
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_MEDIASTREAM,
allow ? CONTENT_SETTING_ASK : CONTENT_SETTING_BLOCK);
}

static void SetPushNotificationsEnabled(JNIEnv* env,
jobject obj,
jboolean allow) {
HostContentSettingsMap* host_content_settings_map =
GetOriginalProfile()->GetHostContentSettingsMap();
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
allow ? CONTENT_SETTING_ASK : CONTENT_SETTING_BLOCK);
}

static void SetCrashReporting(JNIEnv* env, jobject obj, jboolean reporting) {
PrefService* local_state = g_browser_process->local_state();
local_state->SetBoolean(prefs::kCrashReportingEnabled, reporting);
Expand Down Expand Up @@ -484,8 +534,29 @@ static void SetAllowPopupsEnabled(JNIEnv* env, jobject obj, jboolean allow) {
static jboolean GetCameraMicEnabled(JNIEnv* env, jobject obj) {
HostContentSettingsMap* content_settings =
GetOriginalProfile()->GetHostContentSettingsMap();
PrefService* prefs = GetPrefService();
return GetBooleanForContentSetting(content_settings,
CONTENT_SETTINGS_TYPE_MEDIASTREAM);
CONTENT_SETTINGS_TYPE_MEDIASTREAM) &&
prefs->GetBoolean(prefs::kAudioCaptureAllowed) &&
prefs->GetBoolean(prefs::kVideoCaptureAllowed);
}

static jboolean GetCameraMicUserModifiable(JNIEnv* env, jobject obj) {
PrefService* prefs = GetPrefService();
return IsContentSettingUserModifiable(
GetOriginalProfile()->GetHostContentSettingsMap(),
CONTENT_SETTINGS_TYPE_MEDIASTREAM) &&
prefs->IsUserModifiablePreference(prefs::kAudioCaptureAllowed) &&
prefs->IsUserModifiablePreference(prefs::kVideoCaptureAllowed);
}

static jboolean GetCameraMicManagedByCustodian(JNIEnv* env, jobject obj) {
PrefService* prefs = GetPrefService();
if (prefs->IsPreferenceManagedByCustodian(prefs::kVideoCaptureAllowed))
return true;
if (prefs->IsPreferenceManagedByCustodian(prefs::kAudioCaptureAllowed))
return true;
return false;
}

static jboolean GetAutologinEnabled(JNIEnv* env, jobject obj) {
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/supervised_user/supervised_user_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

namespace supervised_users {

const char kCameraMicAllowed[] = "CameraMicAllowed";
const char kContentPackDefaultFilteringBehavior[] =
"ContentPackDefaultFilteringBehavior";
const char kContentPackManualBehaviorHosts[] = "ContentPackManualBehaviorHosts";
const char kContentPackManualBehaviorURLs[] = "ContentPackManualBehaviorURLs";
const char kForceSafeSearch[] = "ForceSafeSearch";
const char kGeolocationAllowed[] = "GeolocationAllowed";
const char kRecordHistory[] = "RecordHistory";
const char kSigninAllowed[] = "SigninAllowed";
const char kUserName[] = "UserName";
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/supervised_user/supervised_user_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ namespace supervised_users {

// Keys for supervised user settings. These are configured remotely and mapped
// to preferences by the SupervisedUserPrefStore.
extern const char kCameraMicAllowed[];
extern const char kContentPackDefaultFilteringBehavior[];
extern const char kContentPackManualBehaviorHosts[];
extern const char kContentPackManualBehaviorURLs[];
extern const char kForceSafeSearch[];
extern const char kGeolocationAllowed[];
extern const char kRecordHistory[];
extern const char kSigninAllowed[];
extern const char kUserName[];
Expand Down

0 comments on commit b2025b7

Please sign in to comment.