Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" | |
| 6 | |
| 5 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 6 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" | |
| 8 #include "chrome/browser/extensions/chrome_extension_function.h" | 9 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 11 #include "components/url_formatter/url_fixer.h" | 12 #include "components/url_formatter/url_fixer.h" |
| 12 | 13 |
| 13 #if defined(OS_CHROMEOS) | 14 #if defined(OS_CHROMEOS) |
| 14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" | 16 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" |
| 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 20 #include "chromeos/settings/cros_settings_names.h" | |
| 17 #endif | 21 #endif |
| 18 | 22 |
| 23 namespace { | |
| 24 | |
| 25 #if defined(OS_CHROMEOS) | |
| 26 bool IsPrivilegedCrosSetting(const std::string& pref_name) { | |
| 27 if (!chromeos::CrosSettings::IsCrosSettings(pref_name)) | |
| 28 return false; | |
| 29 // kSystemTimezone should be changeable by all users. | |
| 30 if (pref_name == chromeos::kSystemTimezone) | |
| 31 return false; | |
| 32 // All other Cros settings are considered privileged and are either policy | |
| 33 // controlled or owner controlled. | |
| 34 return true; | |
| 35 } | |
| 36 #endif | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 19 namespace extensions { | 40 namespace extensions { |
| 20 | 41 |
| 21 namespace settings_private = api::settings_private; | 42 namespace settings_api = api::settings_private; |
|
Dan Beam
2015/08/28 00:20:22
can you do this in a separate CL?
stevenjb
2015/08/28 23:18:07
I'll undo it. I know the churn sucks. It helped al
Dan Beam
2015/08/29 00:09:08
churn is not bad. big diffs are bad. because the
| |
| 22 | 43 |
| 23 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) { | 44 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} |
| 24 } | |
| 25 | 45 |
| 26 PrefsUtil::~PrefsUtil() { | 46 PrefsUtil::~PrefsUtil() {} |
| 27 } | |
| 28 | 47 |
| 29 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 30 using CrosSettings = chromeos::CrosSettings; | 49 using CrosSettings = chromeos::CrosSettings; |
| 31 #endif | 50 #endif |
| 32 | 51 |
| 33 const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() { | 52 const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() { |
| 34 static PrefsUtil::TypedPrefMap* s_whitelist = nullptr; | 53 static PrefsUtil::TypedPrefMap* s_whitelist = nullptr; |
| 35 if (s_whitelist) | 54 if (s_whitelist) |
| 36 return *s_whitelist; | 55 return *s_whitelist; |
| 37 s_whitelist = new PrefsUtil::TypedPrefMap(); | 56 s_whitelist = new PrefsUtil::TypedPrefMap(); |
| 38 (*s_whitelist)["alternate_error_pages.enabled"] = | 57 (*s_whitelist)["alternate_error_pages.enabled"] = |
| 39 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 58 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 40 (*s_whitelist)["bookmark_bar.show_on_all_tabs"] = | 59 (*s_whitelist)["bookmark_bar.show_on_all_tabs"] = |
| 41 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 60 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 42 (*s_whitelist)["browser.show_home_button"] = | 61 (*s_whitelist)["browser.show_home_button"] = |
| 43 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 62 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 44 (*s_whitelist)["download.default_directory"] = | 63 (*s_whitelist)["download.default_directory"] = |
| 45 settings_private::PrefType::PREF_TYPE_STRING; | 64 settings_api::PrefType::PREF_TYPE_STRING; |
| 46 (*s_whitelist)["download.prompt_for_download"] = | 65 (*s_whitelist)["download.prompt_for_download"] = |
| 47 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 66 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 48 (*s_whitelist)["enable_do_not_track"] = | 67 (*s_whitelist)["enable_do_not_track"] = |
| 49 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 68 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 50 (*s_whitelist)["homepage"] = settings_private::PrefType::PREF_TYPE_URL; | 69 (*s_whitelist)["homepage"] = settings_api::PrefType::PREF_TYPE_URL; |
| 51 (*s_whitelist)["net.network_prediction_options"] = | 70 (*s_whitelist)["net.network_prediction_options"] = |
| 52 settings_private::PrefType::PREF_TYPE_NUMBER; | 71 settings_api::PrefType::PREF_TYPE_NUMBER; |
| 53 (*s_whitelist)["safebrowsing.enabled"] = | 72 (*s_whitelist)["safebrowsing.enabled"] = |
| 54 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 73 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 55 (*s_whitelist)["safebrowsing.extended_reporting_enabled"] = | 74 (*s_whitelist)["safebrowsing.extended_reporting_enabled"] = |
| 56 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 75 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 57 (*s_whitelist)["search.suggest_enabled"] = | 76 (*s_whitelist)["search.suggest_enabled"] = |
| 58 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 77 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 59 (*s_whitelist)["spellcheck.use_spelling_service"] = | 78 (*s_whitelist)["spellcheck.use_spelling_service"] = |
| 60 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 79 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 61 | 80 |
| 62 #if defined(OS_CHROMEOS) | 81 #if defined(OS_CHROMEOS) |
| 63 (*s_whitelist)["cros.accounts.allowBWSI"] = | 82 (*s_whitelist)["cros.accounts.allowBWSI"] = |
| 64 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 83 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 65 (*s_whitelist)["cros.accounts.supervisedUsersEnabled"] = | 84 (*s_whitelist)["cros.accounts.supervisedUsersEnabled"] = |
| 66 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 85 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 67 (*s_whitelist)["cros.accounts.showUserNamesOnSignIn"] = | 86 (*s_whitelist)["cros.accounts.showUserNamesOnSignIn"] = |
| 68 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 87 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 69 (*s_whitelist)["cros.accounts.allowGuest"] = | 88 (*s_whitelist)["cros.accounts.allowGuest"] = |
| 70 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 89 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 71 (*s_whitelist)["cros.accounts.users"] = | 90 (*s_whitelist)["cros.accounts.users"] = |
| 72 settings_private::PrefType::PREF_TYPE_LIST; | 91 settings_api::PrefType::PREF_TYPE_LIST; |
| 73 (*s_whitelist)["settings.accessibility"] = | 92 (*s_whitelist)["settings.accessibility"] = |
| 74 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 93 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 75 (*s_whitelist)["settings.a11y.autoclick"] = | 94 (*s_whitelist)["settings.a11y.autoclick"] = |
| 76 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 95 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 77 (*s_whitelist)["settings.a11y.autoclick_delay_ms"] = | 96 (*s_whitelist)["settings.a11y.autoclick_delay_ms"] = |
| 78 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 97 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 79 (*s_whitelist)["settings.a11y.enable_menu"] = | 98 (*s_whitelist)["settings.a11y.enable_menu"] = |
| 80 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 99 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 81 (*s_whitelist)["settings.a11y.high_contrast_enabled"] = | 100 (*s_whitelist)["settings.a11y.high_contrast_enabled"] = |
| 82 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 101 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 83 (*s_whitelist)["settings.a11y.large_cursor_enabled"] = | 102 (*s_whitelist)["settings.a11y.large_cursor_enabled"] = |
| 84 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 103 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 85 (*s_whitelist)["settings.a11y.screen_magnifier"] = | 104 (*s_whitelist)["settings.a11y.screen_magnifier"] = |
| 86 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 105 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 87 (*s_whitelist)["settings.a11y.sticky_keys_enabled"] = | 106 (*s_whitelist)["settings.a11y.sticky_keys_enabled"] = |
| 88 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 107 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 89 (*s_whitelist)["settings.a11y.virtual_keyboard"] = | 108 (*s_whitelist)["settings.a11y.virtual_keyboard"] = |
| 90 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 109 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 91 (*s_whitelist)["settings.clock.use_24hour_clock"] = | 110 (*s_whitelist)["settings.clock.use_24hour_clock"] = |
| 92 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 111 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 93 (*s_whitelist)["settings.touchpad.enable_tap_dragging"] = | 112 (*s_whitelist)["settings.touchpad.enable_tap_dragging"] = |
| 94 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 113 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 95 (*s_whitelist)["cros.metrics.reportingEnabled"] = | 114 (*s_whitelist)["cros.metrics.reportingEnabled"] = |
| 96 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 115 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 97 (*s_whitelist)["cros.device.attestation_for_content_protection_enabled"] = | 116 (*s_whitelist)["cros.device.attestation_for_content_protection_enabled"] = |
| 98 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 117 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 99 (*s_whitelist)["settings.internet.wake_on_wifi_ssid"] = | 118 (*s_whitelist)["settings.internet.wake_on_wifi_ssid"] = |
| 100 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 119 settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 101 #endif | 120 #endif |
| 102 | 121 |
| 103 return *s_whitelist; | 122 return *s_whitelist; |
| 104 } | 123 } |
| 105 | 124 |
| 106 api::settings_private::PrefType PrefsUtil::GetType(const std::string& name, | 125 settings_api::PrefType PrefsUtil::GetType(const std::string& name, |
| 107 base::Value::Type type) { | 126 base::Value::Type type) { |
| 108 switch (type) { | 127 switch (type) { |
| 109 case base::Value::Type::TYPE_BOOLEAN: | 128 case base::Value::Type::TYPE_BOOLEAN: |
| 110 return api::settings_private::PrefType::PREF_TYPE_BOOLEAN; | 129 return settings_api::PrefType::PREF_TYPE_BOOLEAN; |
| 111 case base::Value::Type::TYPE_INTEGER: | 130 case base::Value::Type::TYPE_INTEGER: |
| 112 case base::Value::Type::TYPE_DOUBLE: | 131 case base::Value::Type::TYPE_DOUBLE: |
| 113 return api::settings_private::PrefType::PREF_TYPE_NUMBER; | 132 return settings_api::PrefType::PREF_TYPE_NUMBER; |
| 114 case base::Value::Type::TYPE_STRING: | 133 case base::Value::Type::TYPE_STRING: |
| 115 return IsPrefTypeURL(name) | 134 return IsPrefTypeURL(name) ? settings_api::PrefType::PREF_TYPE_URL |
| 116 ? api::settings_private::PrefType::PREF_TYPE_URL | 135 : settings_api::PrefType::PREF_TYPE_STRING; |
| 117 : api::settings_private::PrefType::PREF_TYPE_STRING; | |
| 118 case base::Value::Type::TYPE_LIST: | 136 case base::Value::Type::TYPE_LIST: |
| 119 return api::settings_private::PrefType::PREF_TYPE_LIST; | 137 return settings_api::PrefType::PREF_TYPE_LIST; |
| 120 default: | 138 default: |
| 121 return api::settings_private::PrefType::PREF_TYPE_NONE; | 139 return settings_api::PrefType::PREF_TYPE_NONE; |
| 122 } | 140 } |
| 123 } | 141 } |
| 124 | 142 |
| 125 scoped_ptr<api::settings_private::PrefObject> PrefsUtil::GetCrosSettingsPref( | 143 scoped_ptr<settings_api::PrefObject> PrefsUtil::GetCrosSettingsPref( |
| 126 const std::string& name) { | 144 const std::string& name) { |
| 127 scoped_ptr<api::settings_private::PrefObject> pref_object( | 145 scoped_ptr<settings_api::PrefObject> pref_object( |
| 128 new api::settings_private::PrefObject()); | 146 new settings_api::PrefObject()); |
| 129 | 147 |
| 130 #if defined(OS_CHROMEOS) | 148 #if defined(OS_CHROMEOS) |
| 131 const base::Value* value = CrosSettings::Get()->GetPref(name); | 149 const base::Value* value = CrosSettings::Get()->GetPref(name); |
|
michaelpg
2015/08/27 23:40:01
GetPref doesn't check the whitelist, so |value| co
stevenjb
2015/08/28 23:18:07
We probably do care, I'll fix that while I'm in he
| |
| 132 pref_object->key = name; | 150 pref_object->key = name; |
| 133 pref_object->type = GetType(name, value->GetType()); | 151 pref_object->type = GetType(name, value->GetType()); |
| 134 pref_object->value.reset(value->DeepCopy()); | 152 pref_object->value.reset(value->DeepCopy()); |
| 135 #endif | 153 #endif |
| 136 | 154 |
| 137 return pref_object.Pass(); | 155 return pref_object.Pass(); |
| 138 } | 156 } |
| 139 | 157 |
| 140 scoped_ptr<api::settings_private::PrefObject> PrefsUtil::GetPref( | 158 scoped_ptr<settings_api::PrefObject> PrefsUtil::GetPref( |
| 141 const std::string& name) { | 159 const std::string& name) { |
| 142 if (IsCrosSetting(name)) | 160 const PrefService::Preference* pref = nullptr; |
| 143 return GetCrosSettingsPref(name); | 161 scoped_ptr<settings_api::PrefObject> pref_object; |
| 162 if (IsCrosSetting(name)) { | |
| 163 pref_object = GetCrosSettingsPref(name); | |
| 164 } else { | |
| 165 PrefService* pref_service = FindServiceForPref(name); | |
| 166 pref = pref_service->FindPreference(name); | |
| 167 if (!pref) | |
| 168 return nullptr; | |
| 169 pref_object.reset(new settings_api::PrefObject()); | |
| 170 pref_object->key = pref->name(); | |
| 171 pref_object->type = GetType(name, pref->GetType()); | |
| 172 pref_object->value.reset(pref->GetValue()->DeepCopy()); | |
| 173 } | |
| 144 | 174 |
| 145 PrefService* pref_service = FindServiceForPref(name); | 175 settings_api::PolicySource source = |
| 146 const PrefService::Preference* pref = pref_service->FindPreference(name); | 176 settings_api::PolicySource::POLICY_SOURCE_NONE; |
| 147 if (!pref) | 177 settings_api::PolicyEnforcement enforcement = |
| 148 return nullptr; | 178 settings_api::PolicyEnforcement::POLICY_ENFORCEMENT_NONE; |
| 149 | 179 |
| 150 scoped_ptr<api::settings_private::PrefObject> pref_object( | 180 if (IsPrefEnterpriseManaged(name)) { |
| 151 new api::settings_private::PrefObject()); | 181 // Enterprise managed prefs are treated the same as device policy restricted |
| 152 pref_object->key = pref->name(); | 182 // prefs in the UI. |
| 153 pref_object->type = GetType(name, pref->GetType()); | 183 source = settings_api::PolicySource::POLICY_SOURCE_DEVICE; |
| 154 pref_object->value.reset(pref->GetValue()->DeepCopy()); | 184 enforcement = settings_api::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; |
| 155 | 185 } else if (IsPrefOwnerControlled(name)) { |
| 156 if (pref->IsManaged()) { | 186 source = settings_api::PolicySource::POLICY_SOURCE_OWNER; |
| 157 if (pref->IsManagedByCustodian()) { | 187 enforcement = settings_api::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; |
| 158 pref_object->policy_source = | 188 } else if (IsPrefSupervisorControlled(name)) { |
| 159 api::settings_private::PolicySource::POLICY_SOURCE_DEVICE; | 189 // We treat supervised prefs as 'OWNER' because on Chrome OS they are |
| 190 // also restricted to the owner, and on non Chrome OS we hide these controls | |
|
michaelpg
2015/08/27 23:40:01
nit: "non-Chrome OS"
stevenjb
2015/08/28 23:18:07
really? :P
| |
| 191 // so do not need to distinguish them. | |
| 192 source = settings_api::PolicySource::POLICY_SOURCE_OWNER; | |
| 193 enforcement = settings_api::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | |
| 194 } else if (pref && pref->IsManaged()) { | |
| 195 if (pref->IsManagedByCustodian()) | |
|
michaelpg
2015/08/27 23:40:01
I'm confused about the difference between "managed
stevenjb
2015/08/28 23:18:07
I'm a bit confused too. I didn't change this logic
| |
| 196 source = settings_api::PolicySource::POLICY_SOURCE_DEVICE; | |
| 197 else | |
| 198 source = settings_api::PolicySource::POLICY_SOURCE_USER; | |
|
michaelpg
2015/08/27 23:40:01
When is a preference "managed", but not mandated b
stevenjb
2015/08/28 23:18:07
I believe that desktop chrome allows for managed p
| |
| 199 if (pref->IsRecommended()) { | |
|
michaelpg
2015/08/27 23:40:01
Another point of confusion :-) How can a pref be i
stevenjb
2015/08/28 23:18:07
Wow, the existing logic is just... wrong. Looking
| |
| 200 enforcement = | |
| 201 settings_api::PolicyEnforcement::POLICY_ENFORCEMENT_RECOMMENDED; | |
| 202 pref_object->recommended_value.reset( | |
| 203 pref->GetRecommendedValue()->DeepCopy()); | |
| 160 } else { | 204 } else { |
| 161 pref_object->policy_source = | 205 enforcement = |
| 162 api::settings_private::PolicySource::POLICY_SOURCE_USER; | 206 settings_api::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; |
| 163 } | 207 } |
| 164 pref_object->policy_enforcement = | 208 } else if (IsPrefPrimaryUserControlled(name)) { |
| 165 pref->IsRecommended() ? api::settings_private::PolicyEnforcement:: | 209 source = settings_api::PolicySource::POLICY_SOURCE_PRIMARY_USER; |
| 166 POLICY_ENFORCEMENT_RECOMMENDED | 210 enforcement = settings_api::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; |
| 167 : api::settings_private::PolicyEnforcement:: | 211 } else if (pref && !pref->IsUserModifiable()) { |
| 168 POLICY_ENFORCEMENT_ENFORCED; | 212 source = settings_api::PolicySource::POLICY_SOURCE_USER; |
|
michaelpg
2015/08/27 23:40:01
What is a user policy? In this case the pref is co
stevenjb
2015/08/28 23:18:07
Yeah, we appear to be conflating things here. The
| |
| 169 } else if (!IsPrefUserModifiable(name)) { | 213 enforcement = settings_api::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; |
| 170 pref_object->policy_source = | |
| 171 api::settings_private::PolicySource::POLICY_SOURCE_USER; | |
| 172 pref_object->policy_enforcement = | |
| 173 api::settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | |
| 174 } | 214 } |
| 215 pref_object->policy_source = source; | |
| 216 pref_object->policy_enforcement = enforcement; | |
| 175 | 217 |
| 176 return pref_object.Pass(); | 218 return pref_object.Pass(); |
| 177 } | 219 } |
| 178 | 220 |
| 179 bool PrefsUtil::SetPref(const std::string& pref_name, | 221 bool PrefsUtil::SetPref(const std::string& pref_name, |
| 180 const base::Value* value) { | 222 const base::Value* value) { |
| 181 if (IsCrosSetting(pref_name)) | 223 if (IsCrosSetting(pref_name)) |
| 182 return SetCrosSettingsPref(pref_name, value); | 224 return SetCrosSettingsPref(pref_name, value); |
| 183 | 225 |
| 184 PrefService* pref_service = FindServiceForPref(pref_name); | 226 PrefService* pref_service = FindServiceForPref(pref_name); |
| 185 | 227 |
| 186 if (!IsPrefUserModifiable(pref_name)) | 228 if (!IsPrefUserModifiable(pref_name)) |
| 187 return false; | 229 return false; |
| 188 | 230 |
| 189 const PrefService::Preference* pref = | 231 const PrefService::Preference* pref = pref_service->FindPreference(pref_name); |
| 190 pref_service->FindPreference(pref_name); | |
| 191 if (!pref) | 232 if (!pref) |
| 192 return false; | 233 return false; |
| 193 | 234 |
| 194 DCHECK_EQ(pref->GetType(), value->GetType()); | 235 DCHECK_EQ(pref->GetType(), value->GetType()); |
| 195 | 236 |
| 196 switch (pref->GetType()) { | 237 switch (pref->GetType()) { |
| 197 case base::Value::TYPE_BOOLEAN: | 238 case base::Value::TYPE_BOOLEAN: |
| 198 case base::Value::TYPE_DOUBLE: | 239 case base::Value::TYPE_DOUBLE: |
| 199 case base::Value::TYPE_LIST: | 240 case base::Value::TYPE_LIST: |
| 200 pref_service->Set(pref_name, *value); | 241 pref_service->Set(pref_name, *value); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 const base::Value* value) { | 275 const base::Value* value) { |
| 235 #if defined(OS_CHROMEOS) | 276 #if defined(OS_CHROMEOS) |
| 236 chromeos::OwnerSettingsServiceChromeOS* service = | 277 chromeos::OwnerSettingsServiceChromeOS* service = |
| 237 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( | 278 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
| 238 profile_); | 279 profile_); |
| 239 | 280 |
| 240 // Returns false if not the owner, for settings requiring owner. | 281 // Returns false if not the owner, for settings requiring owner. |
| 241 if (service && service->HandlesSetting(pref_name)) | 282 if (service && service->HandlesSetting(pref_name)) |
| 242 return service->Set(pref_name, *value); | 283 return service->Set(pref_name, *value); |
| 243 | 284 |
| 244 chromeos::CrosSettings::Get()->Set(pref_name, *value); | 285 CrosSettings::Get()->Set(pref_name, *value); |
| 245 return true; | 286 return true; |
| 246 #else | 287 #else |
| 247 return false; | 288 return false; |
| 248 #endif | 289 #endif |
| 249 } | 290 } |
| 250 | 291 |
| 251 bool PrefsUtil::AppendToListCrosSetting(const std::string& pref_name, | 292 bool PrefsUtil::AppendToListCrosSetting(const std::string& pref_name, |
| 252 const base::Value& value) { | 293 const base::Value& value) { |
| 253 #if defined(OS_CHROMEOS) | 294 #if defined(OS_CHROMEOS) |
| 254 chromeos::OwnerSettingsServiceChromeOS* service = | 295 chromeos::OwnerSettingsServiceChromeOS* service = |
| 255 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( | 296 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
| 256 profile_); | 297 profile_); |
| 257 | 298 |
| 258 // Returns false if not the owner, for settings requiring owner. | 299 // Returns false if not the owner, for settings requiring owner. |
| 259 if (service && service->HandlesSetting(pref_name)) { | 300 if (service && service->HandlesSetting(pref_name)) { |
| 260 return service->AppendToList(pref_name, value); | 301 return service->AppendToList(pref_name, value); |
| 261 } | 302 } |
| 262 | 303 |
| 263 chromeos::CrosSettings::Get()->AppendToList(pref_name, &value); | 304 CrosSettings::Get()->AppendToList(pref_name, &value); |
| 264 return true; | 305 return true; |
| 265 #else | 306 #else |
| 266 return false; | 307 return false; |
| 267 #endif | 308 #endif |
| 268 } | 309 } |
| 269 | 310 |
| 270 bool PrefsUtil::RemoveFromListCrosSetting(const std::string& pref_name, | 311 bool PrefsUtil::RemoveFromListCrosSetting(const std::string& pref_name, |
| 271 const base::Value& value) { | 312 const base::Value& value) { |
| 272 #if defined(OS_CHROMEOS) | 313 #if defined(OS_CHROMEOS) |
| 273 chromeos::OwnerSettingsServiceChromeOS* service = | 314 chromeos::OwnerSettingsServiceChromeOS* service = |
| 274 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( | 315 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
| 275 profile_); | 316 profile_); |
| 276 | 317 |
| 277 // Returns false if not the owner, for settings requiring owner. | 318 // Returns false if not the owner, for settings requiring owner. |
| 278 if (service && service->HandlesSetting(pref_name)) { | 319 if (service && service->HandlesSetting(pref_name)) { |
| 279 return service->RemoveFromList(pref_name, value); | 320 return service->RemoveFromList(pref_name, value); |
| 280 } | 321 } |
| 281 | 322 |
| 282 chromeos::CrosSettings::Get()->RemoveFromList(pref_name, &value); | 323 CrosSettings::Get()->RemoveFromList(pref_name, &value); |
| 283 return true; | 324 return true; |
| 284 #else | 325 #else |
| 285 return false; | 326 return false; |
| 286 #endif | 327 #endif |
| 287 } | 328 } |
| 288 | 329 |
| 289 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { | 330 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { |
| 290 settings_private::PrefType pref_type = | 331 settings_api::PrefType pref_type = settings_api::PrefType::PREF_TYPE_NONE; |
| 291 settings_private::PrefType::PREF_TYPE_NONE; | |
| 292 | 332 |
| 293 const TypedPrefMap keys = GetWhitelistedKeys(); | 333 const TypedPrefMap keys = GetWhitelistedKeys(); |
| 294 const auto& iter = keys.find(pref_name); | 334 const auto& iter = keys.find(pref_name); |
| 295 if (iter != keys.end()) | 335 if (iter != keys.end()) |
| 296 pref_type = iter->second; | 336 pref_type = iter->second; |
| 297 | 337 |
| 298 return pref_type == settings_private::PrefType::PREF_TYPE_URL; | 338 return pref_type == settings_api::PrefType::PREF_TYPE_URL; |
| 339 } | |
| 340 | |
| 341 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { | |
| 342 #if defined(OS_CHROMEOS) | |
| 343 if (IsPrivilegedCrosSetting(pref_name)) { | |
| 344 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 345 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 346 if (connector->IsEnterpriseManaged()) | |
| 347 return true; | |
| 348 } | |
| 349 #endif | |
| 350 return false; | |
| 351 } | |
| 352 | |
| 353 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { | |
| 354 #if defined(OS_CHROMEOS) | |
| 355 if (IsPrivilegedCrosSetting(pref_name)) { | |
| 356 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) | |
| 357 return true; | |
| 358 } | |
| 359 #endif | |
| 360 return false; | |
| 361 } | |
| 362 | |
| 363 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { | |
|
michaelpg
2015/08/27 23:40:01
Does PrefService::IsManagedByCustodian result in d
stevenjb
2015/08/28 23:18:07
This should also be 'readOnly' = true to match the
| |
| 364 if (pref_name == prefs::kBrowserGuestModeEnabled || | |
| 365 pref_name == prefs::kBrowserAddPersonEnabled) { | |
| 366 if (profile_->IsSupervised()) | |
| 367 return true; | |
| 368 } | |
| 369 return false; | |
| 370 } | |
| 371 | |
| 372 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { | |
| 373 if (pref_name == prefs::kWakeOnWifiSsid) { | |
|
michaelpg
2015/08/27 23:40:01
#if defined(OS_CHROMEOS)?
stevenjb
2015/08/28 23:18:07
Done.
| |
| 374 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | |
| 375 const user_manager::User* user = | |
| 376 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | |
| 377 if (user && user->email() != user_manager->GetPrimaryUser()->email()) | |
| 378 return true; | |
| 379 } | |
| 380 return false; | |
| 299 } | 381 } |
| 300 | 382 |
| 301 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { | 383 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { |
| 302 if (pref_name != prefs::kBrowserGuestModeEnabled && | |
| 303 pref_name != prefs::kBrowserAddPersonEnabled) { | |
| 304 return true; | |
| 305 } | |
| 306 | |
| 307 PrefService* pref_service = profile_->GetPrefs(); | 384 PrefService* pref_service = profile_->GetPrefs(); |
| 308 const PrefService::Preference* pref = | 385 const PrefService::Preference* pref = |
| 309 pref_service->FindPreference(pref_name.c_str()); | 386 pref_service->FindPreference(pref_name.c_str()); |
| 310 if (!pref || !pref->IsUserModifiable() || profile_->IsSupervised()) | 387 if (!pref || !pref->IsUserModifiable()) |
| 311 return false; | 388 return false; |
| 312 | 389 if (IsPrefEnterpriseManaged(pref_name) || IsPrefOwnerControlled(pref_name) || |
| 390 IsPrefSupervisorControlled(pref_name) || | |
|
michaelpg
2015/08/27 23:40:01
Why isn't it enough to check pref->IsUserModifiabl
Dan Beam
2015/08/28 00:20:21
+1
stevenjb
2015/08/28 23:18:07
I think actually that should be sufficient. Elimin
| |
| 391 IsPrefPrimaryUserControlled(pref_name)) { | |
| 392 return false; | |
| 393 } | |
| 313 return true; | 394 return true; |
| 314 } | 395 } |
| 315 | 396 |
| 316 PrefService* PrefsUtil::FindServiceForPref(const std::string& pref_name) { | 397 PrefService* PrefsUtil::FindServiceForPref(const std::string& pref_name) { |
| 317 PrefService* user_prefs = profile_->GetPrefs(); | 398 PrefService* user_prefs = profile_->GetPrefs(); |
| 318 | 399 |
| 319 // Proxy is a peculiar case: on ChromeOS, settings exist in both user | 400 // Proxy is a peculiar case: on ChromeOS, settings exist in both user |
| 320 // prefs and local state, but chrome://settings should affect only user prefs. | 401 // prefs and local state, but chrome://settings should affect only user prefs. |
| 321 // Elsewhere the proxy settings are stored in local state. | 402 // Elsewhere the proxy settings are stored in local state. |
| 322 // See http://crbug.com/157147 | 403 // See http://crbug.com/157147 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 343 | 424 |
| 344 bool PrefsUtil::IsCrosSetting(const std::string& pref_name) { | 425 bool PrefsUtil::IsCrosSetting(const std::string& pref_name) { |
| 345 #if defined(OS_CHROMEOS) | 426 #if defined(OS_CHROMEOS) |
| 346 return CrosSettings::Get()->IsCrosSettings(pref_name); | 427 return CrosSettings::Get()->IsCrosSettings(pref_name); |
| 347 #else | 428 #else |
| 348 return false; | 429 return false; |
| 349 #endif | 430 #endif |
| 350 } | 431 } |
| 351 | 432 |
| 352 } // namespace extensions | 433 } // namespace extensions |
| OLD | NEW |