OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/content_settings/content_settings_policy_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // The preferences used to manage ContentSettingsTypes. | 31 // The preferences used to manage ContentSettingsTypes. |
32 const char* kPrefToManageType[CONTENT_SETTINGS_NUM_TYPES] = { | 32 const char* kPrefToManageType[CONTENT_SETTINGS_NUM_TYPES] = { |
33 prefs::kManagedDefaultCookiesSetting, | 33 prefs::kManagedDefaultCookiesSetting, |
34 prefs::kManagedDefaultImagesSetting, | 34 prefs::kManagedDefaultImagesSetting, |
35 prefs::kManagedDefaultJavaScriptSetting, | 35 prefs::kManagedDefaultJavaScriptSetting, |
36 prefs::kManagedDefaultPluginsSetting, | 36 prefs::kManagedDefaultPluginsSetting, |
37 prefs::kManagedDefaultPopupsSetting, | 37 prefs::kManagedDefaultPopupsSetting, |
38 prefs::kManagedDefaultGeolocationSetting, | 38 prefs::kManagedDefaultGeolocationSetting, |
39 prefs::kManagedDefaultNotificationsSetting, | 39 prefs::kManagedDefaultNotificationsSetting, |
| 40 NULL, |
| 41 prefs::kManagedDefaultAutoSelectCertificateSetting, |
40 }; | 42 }; |
41 | 43 |
42 struct PrefsForManagedContentSettingsMapEntry { | 44 struct PrefsForManagedContentSettingsMapEntry { |
43 const char* pref_name; | 45 const char* pref_name; |
44 ContentSettingsType content_type; | 46 ContentSettingsType content_type; |
45 ContentSetting setting; | 47 ContentSetting setting; |
46 }; | 48 }; |
47 | 49 |
48 const PrefsForManagedContentSettingsMapEntry | 50 const PrefsForManagedContentSettingsMapEntry |
49 kPrefsForManagedContentSettingsMap[] = { | 51 kPrefsForManagedContentSettingsMap[] = { |
50 { | 52 { |
| 53 prefs::kManagedAutoSelectCertificateForUrls, |
| 54 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 55 CONTENT_SETTING_ALLOW |
| 56 }, { |
51 prefs::kManagedCookiesAllowedForUrls, | 57 prefs::kManagedCookiesAllowedForUrls, |
52 CONTENT_SETTINGS_TYPE_COOKIES, | 58 CONTENT_SETTINGS_TYPE_COOKIES, |
53 CONTENT_SETTING_ALLOW | 59 CONTENT_SETTING_ALLOW |
54 }, { | 60 }, { |
55 prefs::kManagedCookiesSessionOnlyForUrls, | 61 prefs::kManagedCookiesSessionOnlyForUrls, |
56 CONTENT_SETTINGS_TYPE_COOKIES, | 62 CONTENT_SETTINGS_TYPE_COOKIES, |
57 CONTENT_SETTING_SESSION_ONLY | 63 CONTENT_SETTING_SESSION_ONLY |
58 }, { | 64 }, { |
59 prefs::kManagedCookiesBlockedForUrls, | 65 prefs::kManagedCookiesBlockedForUrls, |
60 CONTENT_SETTINGS_TYPE_COOKIES, | 66 CONTENT_SETTINGS_TYPE_COOKIES, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // in parallel to the preference default-content-settings. If a | 119 // in parallel to the preference default-content-settings. If a |
114 // default-content-settings-type is managed any user defined excpetions | 120 // default-content-settings-type is managed any user defined excpetions |
115 // (patterns) for this type are ignored. | 121 // (patterns) for this type are ignored. |
116 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); | 122 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); |
117 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); | 123 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); |
118 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); | 124 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); |
119 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); | 125 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); |
120 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); | 126 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); |
121 pref_change_registrar_.Add(prefs::kManagedDefaultGeolocationSetting, this); | 127 pref_change_registrar_.Add(prefs::kManagedDefaultGeolocationSetting, this); |
122 pref_change_registrar_.Add(prefs::kManagedDefaultNotificationsSetting, this); | 128 pref_change_registrar_.Add(prefs::kManagedDefaultNotificationsSetting, this); |
| 129 pref_change_registrar_.Add( |
| 130 prefs::kManagedDefaultAutoSelectCertificateSetting, this); |
123 } | 131 } |
124 | 132 |
125 PolicyDefaultProvider::~PolicyDefaultProvider() { | 133 PolicyDefaultProvider::~PolicyDefaultProvider() { |
126 DCHECK(!prefs_); | 134 DCHECK(!prefs_); |
127 } | 135 } |
128 | 136 |
129 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting( | 137 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting( |
130 ContentSettingsType content_type) const { | 138 ContentSettingsType content_type) const { |
131 base::AutoLock auto_lock(lock_); | 139 base::AutoLock auto_lock(lock_); |
132 return managed_default_content_settings_.settings[content_type]; | 140 return managed_default_content_settings_.settings[content_type]; |
(...skipping 30 matching lines...) Expand all Loading... |
163 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { | 171 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { |
164 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | 172 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
165 } else if (*name == prefs::kManagedDefaultPluginsSetting) { | 173 } else if (*name == prefs::kManagedDefaultPluginsSetting) { |
166 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS); | 174 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS); |
167 } else if (*name == prefs::kManagedDefaultPopupsSetting) { | 175 } else if (*name == prefs::kManagedDefaultPopupsSetting) { |
168 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS); | 176 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS); |
169 } else if (*name == prefs::kManagedDefaultGeolocationSetting) { | 177 } else if (*name == prefs::kManagedDefaultGeolocationSetting) { |
170 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 178 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
171 } else if (*name == prefs::kManagedDefaultNotificationsSetting) { | 179 } else if (*name == prefs::kManagedDefaultNotificationsSetting) { |
172 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 180 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 181 } else if (*name == prefs::kManagedDefaultAutoSelectCertificateSetting) { |
| 182 UpdateManagedDefaultSetting( |
| 183 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); |
173 } else { | 184 } else { |
174 NOTREACHED() << "Unexpected preference observed"; | 185 NOTREACHED() << "Unexpected preference observed"; |
175 return; | 186 return; |
176 } | 187 } |
177 | 188 |
178 NotifyObservers(ContentSettingsPattern(), | 189 NotifyObservers(ContentSettingsPattern(), |
179 ContentSettingsPattern(), | 190 ContentSettingsPattern(), |
180 CONTENT_SETTINGS_TYPE_DEFAULT, | 191 CONTENT_SETTINGS_TYPE_DEFAULT, |
181 std::string()); | 192 std::string()); |
182 } else { | 193 } else { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 PrefService::UNSYNCABLE_PREF); | 245 PrefService::UNSYNCABLE_PREF); |
235 prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting, | 246 prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting, |
236 CONTENT_SETTING_DEFAULT, | 247 CONTENT_SETTING_DEFAULT, |
237 PrefService::UNSYNCABLE_PREF); | 248 PrefService::UNSYNCABLE_PREF); |
238 prefs->RegisterIntegerPref(prefs::kManagedDefaultGeolocationSetting, | 249 prefs->RegisterIntegerPref(prefs::kManagedDefaultGeolocationSetting, |
239 CONTENT_SETTING_DEFAULT, | 250 CONTENT_SETTING_DEFAULT, |
240 PrefService::UNSYNCABLE_PREF); | 251 PrefService::UNSYNCABLE_PREF); |
241 prefs->RegisterIntegerPref(prefs::kManagedDefaultNotificationsSetting, | 252 prefs->RegisterIntegerPref(prefs::kManagedDefaultNotificationsSetting, |
242 CONTENT_SETTING_DEFAULT, | 253 CONTENT_SETTING_DEFAULT, |
243 PrefService::UNSYNCABLE_PREF); | 254 PrefService::UNSYNCABLE_PREF); |
| 255 prefs->RegisterIntegerPref(prefs::kManagedDefaultAutoSelectCertificateSetting, |
| 256 CONTENT_SETTING_ASK, |
| 257 PrefService::UNSYNCABLE_PREF); |
244 } | 258 } |
245 | 259 |
246 // //////////////////////////////////////////////////////////////////////////// | 260 // //////////////////////////////////////////////////////////////////////////// |
247 // PolicyProvider | 261 // PolicyProvider |
248 | 262 |
249 // static | 263 // static |
250 void PolicyProvider::RegisterUserPrefs(PrefService* prefs) { | 264 void PolicyProvider::RegisterUserPrefs(PrefService* prefs) { |
| 265 prefs->RegisterListPref(prefs::kManagedAutoSelectCertificateForUrls, |
| 266 PrefService::UNSYNCABLE_PREF); |
251 prefs->RegisterListPref(prefs::kManagedCookiesAllowedForUrls, | 267 prefs->RegisterListPref(prefs::kManagedCookiesAllowedForUrls, |
252 PrefService::UNSYNCABLE_PREF); | 268 PrefService::UNSYNCABLE_PREF); |
253 prefs->RegisterListPref(prefs::kManagedCookiesBlockedForUrls, | 269 prefs->RegisterListPref(prefs::kManagedCookiesBlockedForUrls, |
254 PrefService::UNSYNCABLE_PREF); | 270 PrefService::UNSYNCABLE_PREF); |
255 prefs->RegisterListPref(prefs::kManagedCookiesSessionOnlyForUrls, | 271 prefs->RegisterListPref(prefs::kManagedCookiesSessionOnlyForUrls, |
256 PrefService::UNSYNCABLE_PREF); | 272 PrefService::UNSYNCABLE_PREF); |
257 prefs->RegisterListPref(prefs::kManagedImagesAllowedForUrls, | 273 prefs->RegisterListPref(prefs::kManagedImagesAllowedForUrls, |
258 PrefService::UNSYNCABLE_PREF); | 274 PrefService::UNSYNCABLE_PREF); |
259 prefs->RegisterListPref(prefs::kManagedImagesBlockedForUrls, | 275 prefs->RegisterListPref(prefs::kManagedImagesBlockedForUrls, |
260 PrefService::UNSYNCABLE_PREF); | 276 PrefService::UNSYNCABLE_PREF); |
(...skipping 11 matching lines...) Expand all Loading... |
272 PrefService::UNSYNCABLE_PREF); | 288 PrefService::UNSYNCABLE_PREF); |
273 } | 289 } |
274 | 290 |
275 PolicyProvider::PolicyProvider(PrefService* prefs, | 291 PolicyProvider::PolicyProvider(PrefService* prefs, |
276 DefaultProviderInterface* default_provider) | 292 DefaultProviderInterface* default_provider) |
277 : prefs_(prefs), | 293 : prefs_(prefs), |
278 default_provider_(default_provider) { | 294 default_provider_(default_provider) { |
279 ReadManagedContentSettings(false); | 295 ReadManagedContentSettings(false); |
280 | 296 |
281 pref_change_registrar_.Init(prefs_); | 297 pref_change_registrar_.Init(prefs_); |
| 298 pref_change_registrar_.Add(prefs::kManagedAutoSelectCertificateForUrls, this); |
282 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); | 299 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); |
283 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); | 300 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); |
284 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); | 301 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); |
285 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); | 302 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); |
286 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); | 303 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); |
287 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); | 304 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); |
288 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); | 305 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); |
289 pref_change_registrar_.Add(prefs::kManagedPluginsBlockedForUrls, this); | 306 pref_change_registrar_.Add(prefs::kManagedPluginsBlockedForUrls, this); |
290 pref_change_registrar_.Add(prefs::kManagedPluginsAllowedForUrls, this); | 307 pref_change_registrar_.Add(prefs::kManagedPluginsAllowedForUrls, this); |
291 pref_change_registrar_.Add(prefs::kManagedPopupsBlockedForUrls, this); | 308 pref_change_registrar_.Add(prefs::kManagedPopupsBlockedForUrls, this); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // Ignore invalid patterns. | 340 // Ignore invalid patterns. |
324 if (!pattern_pair.first.IsValid()) { | 341 if (!pattern_pair.first.IsValid()) { |
325 VLOG(1) << "Ignoring invalid content settings pattern: " << | 342 VLOG(1) << "Ignoring invalid content settings pattern: " << |
326 original_pattern_str; | 343 original_pattern_str; |
327 continue; | 344 continue; |
328 } | 345 } |
329 | 346 |
330 ContentSettingsType content_type = | 347 ContentSettingsType content_type = |
331 kPrefsForManagedContentSettingsMap[i].content_type; | 348 kPrefsForManagedContentSettingsMap[i].content_type; |
332 // If only one pattern was defined auto expand it to a pattern pair. | 349 // If only one pattern was defined auto expand it to a pattern pair. |
| 350 ContentSettingsPattern secondary_pattern = |
| 351 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard() |
| 352 : pattern_pair.second; |
333 rules->push_back(MakeTuple( | 353 rules->push_back(MakeTuple( |
334 pattern_pair.first, | 354 pattern_pair.first, |
335 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard() | 355 secondary_pattern, |
336 : pattern_pair.second, | |
337 content_type, | 356 content_type, |
338 ResourceIdentifier(NO_RESOURCE_IDENTIFIER), | 357 ResourceIdentifier(NO_RESOURCE_IDENTIFIER), |
339 kPrefsForManagedContentSettingsMap[i].setting)); | 358 kPrefsForManagedContentSettingsMap[i].setting)); |
340 } | 359 } |
341 } | 360 } |
342 } | 361 } |
343 | 362 |
344 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { | 363 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { |
345 ContentSettingsRules rules; | 364 ContentSettingsRules rules; |
346 GetContentSettingsFromPreferences(&rules); | 365 GetContentSettingsFromPreferences(&rules); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 } | 448 } |
430 | 449 |
431 void PolicyProvider::Observe(int type, | 450 void PolicyProvider::Observe(int type, |
432 const NotificationSource& source, | 451 const NotificationSource& source, |
433 const NotificationDetails& details) { | 452 const NotificationDetails& details) { |
434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
435 | 454 |
436 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 455 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
437 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); | 456 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
438 std::string* name = Details<std::string>(details).ptr(); | 457 std::string* name = Details<std::string>(details).ptr(); |
439 if (*name == prefs::kManagedCookiesAllowedForUrls || | 458 if (*name == prefs::kManagedAutoSelectCertificateForUrls || |
| 459 *name == prefs::kManagedCookiesAllowedForUrls || |
440 *name == prefs::kManagedCookiesBlockedForUrls || | 460 *name == prefs::kManagedCookiesBlockedForUrls || |
441 *name == prefs::kManagedCookiesSessionOnlyForUrls || | 461 *name == prefs::kManagedCookiesSessionOnlyForUrls || |
442 *name == prefs::kManagedImagesAllowedForUrls || | 462 *name == prefs::kManagedImagesAllowedForUrls || |
443 *name == prefs::kManagedImagesBlockedForUrls || | 463 *name == prefs::kManagedImagesBlockedForUrls || |
444 *name == prefs::kManagedJavaScriptAllowedForUrls || | 464 *name == prefs::kManagedJavaScriptAllowedForUrls || |
445 *name == prefs::kManagedJavaScriptBlockedForUrls || | 465 *name == prefs::kManagedJavaScriptBlockedForUrls || |
446 *name == prefs::kManagedPluginsAllowedForUrls || | 466 *name == prefs::kManagedPluginsAllowedForUrls || |
447 *name == prefs::kManagedPluginsBlockedForUrls || | 467 *name == prefs::kManagedPluginsBlockedForUrls || |
448 *name == prefs::kManagedPopupsAllowedForUrls || | 468 *name == prefs::kManagedPopupsAllowedForUrls || |
449 *name == prefs::kManagedPopupsBlockedForUrls) { | 469 *name == prefs::kManagedPopupsBlockedForUrls) { |
450 ReadManagedContentSettings(true); | 470 ReadManagedContentSettings(true); |
451 NotifyObservers(ContentSettingsPattern(), | 471 NotifyObservers(ContentSettingsPattern(), |
452 ContentSettingsPattern(), | 472 ContentSettingsPattern(), |
453 CONTENT_SETTINGS_TYPE_DEFAULT, | 473 CONTENT_SETTINGS_TYPE_DEFAULT, |
454 std::string()); | 474 std::string()); |
455 } | 475 } |
456 } else { | 476 } else { |
457 NOTREACHED() << "Unexpected notification"; | 477 NOTREACHED() << "Unexpected notification"; |
458 } | 478 } |
459 } | 479 } |
460 | 480 |
461 } // namespace content_settings | 481 } // namespace content_settings |
OLD | NEW |