Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: chrome/browser/content_settings/content_settings_policy_provider.cc

Issue 7828022: Add a method to the HostContentSettings map to return the |Value| of a content setting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update example value of AutoSelectCertificate policy in policy_template.json Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/json/json_reader.h"
11 #include "chrome/browser/content_settings/content_settings_pattern.h" 12 #include "chrome/browser/content_settings/content_settings_pattern.h"
12 #include "chrome/browser/content_settings/content_settings_utils.h" 13 #include "chrome/browser/content_settings/content_settings_utils.h"
13 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" 15 #include "chrome/browser/prefs/scoped_user_pref_update.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
18 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
19 #include "content/common/notification_service.h" 20 #include "content/common/notification_service.h"
20 #include "content/common/notification_source.h" 21 #include "content/common/notification_source.h"
21 #include "webkit/plugins/npapi/plugin_group.h" 22 #include "webkit/plugins/npapi/plugin_group.h"
22 #include "webkit/plugins/npapi/plugin_list.h" 23 #include "webkit/plugins/npapi/plugin_list.h"
23 24
24 namespace { 25 namespace {
25 26
26 // The preferences used to manage ContentSettingsTypes. 27 // The preferences used to manage ContentSettingsTypes.
27 const char* kPrefToManageType[CONTENT_SETTINGS_NUM_TYPES] = { 28 const char* kPrefToManageType[CONTENT_SETTINGS_NUM_TYPES] = {
28 prefs::kManagedDefaultCookiesSetting, 29 prefs::kManagedDefaultCookiesSetting,
29 prefs::kManagedDefaultImagesSetting, 30 prefs::kManagedDefaultImagesSetting,
30 prefs::kManagedDefaultJavaScriptSetting, 31 prefs::kManagedDefaultJavaScriptSetting,
31 prefs::kManagedDefaultPluginsSetting, 32 prefs::kManagedDefaultPluginsSetting,
32 prefs::kManagedDefaultPopupsSetting, 33 prefs::kManagedDefaultPopupsSetting,
33 prefs::kManagedDefaultGeolocationSetting, 34 prefs::kManagedDefaultGeolocationSetting,
34 prefs::kManagedDefaultNotificationsSetting, 35 prefs::kManagedDefaultNotificationsSetting,
35 NULL, 36 NULL, // No policy for default value of content type intents
36 prefs::kManagedDefaultAutoSelectCertificateSetting, 37 NULL, // No policy for default value of content type auto-select-certificate
37 }; 38 };
38 39
39 struct PrefsForManagedContentSettingsMapEntry { 40 struct PrefsForManagedContentSettingsMapEntry {
40 const char* pref_name; 41 const char* pref_name;
41 ContentSettingsType content_type; 42 ContentSettingsType content_type;
42 ContentSetting setting; 43 ContentSetting setting;
43 }; 44 };
44 45
45 const PrefsForManagedContentSettingsMapEntry 46 const PrefsForManagedContentSettingsMapEntry
46 kPrefsForManagedContentSettingsMap[] = { 47 kPrefsForManagedContentSettingsMap[] = {
47 { 48 {
48 prefs::kManagedAutoSelectCertificateForUrls,
49 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
50 CONTENT_SETTING_ALLOW
51 }, {
52 prefs::kManagedCookiesAllowedForUrls, 49 prefs::kManagedCookiesAllowedForUrls,
53 CONTENT_SETTINGS_TYPE_COOKIES, 50 CONTENT_SETTINGS_TYPE_COOKIES,
54 CONTENT_SETTING_ALLOW 51 CONTENT_SETTING_ALLOW
55 }, { 52 }, {
56 prefs::kManagedCookiesSessionOnlyForUrls, 53 prefs::kManagedCookiesSessionOnlyForUrls,
57 CONTENT_SETTINGS_TYPE_COOKIES, 54 CONTENT_SETTINGS_TYPE_COOKIES,
58 CONTENT_SETTING_SESSION_ONLY 55 CONTENT_SETTING_SESSION_ONLY
59 }, { 56 }, {
60 prefs::kManagedCookiesBlockedForUrls, 57 prefs::kManagedCookiesBlockedForUrls,
61 CONTENT_SETTINGS_TYPE_COOKIES, 58 CONTENT_SETTINGS_TYPE_COOKIES,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // in parallel to the preference default-content-settings. If a 111 // in parallel to the preference default-content-settings. If a
115 // default-content-settings-type is managed any user defined excpetions 112 // default-content-settings-type is managed any user defined excpetions
116 // (patterns) for this type are ignored. 113 // (patterns) for this type are ignored.
117 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); 114 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this);
118 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); 115 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this);
119 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); 116 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this);
120 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); 117 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this);
121 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); 118 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this);
122 pref_change_registrar_.Add(prefs::kManagedDefaultGeolocationSetting, this); 119 pref_change_registrar_.Add(prefs::kManagedDefaultGeolocationSetting, this);
123 pref_change_registrar_.Add(prefs::kManagedDefaultNotificationsSetting, this); 120 pref_change_registrar_.Add(prefs::kManagedDefaultNotificationsSetting, this);
124 pref_change_registrar_.Add(
125 prefs::kManagedDefaultAutoSelectCertificateSetting, this);
126 } 121 }
127 122
128 PolicyDefaultProvider::~PolicyDefaultProvider() { 123 PolicyDefaultProvider::~PolicyDefaultProvider() {
129 DCHECK(!prefs_); 124 DCHECK(!prefs_);
130 } 125 }
131 126
132 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting( 127 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting(
133 ContentSettingsType content_type) const { 128 ContentSettingsType content_type) const {
134 base::AutoLock auto_lock(lock_); 129 base::AutoLock auto_lock(lock_);
135 return managed_default_content_settings_.settings[content_type]; 130 return managed_default_content_settings_.settings[content_type];
(...skipping 30 matching lines...) Expand all
166 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { 161 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) {
167 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); 162 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
168 } else if (*name == prefs::kManagedDefaultPluginsSetting) { 163 } else if (*name == prefs::kManagedDefaultPluginsSetting) {
169 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS); 164 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS);
170 } else if (*name == prefs::kManagedDefaultPopupsSetting) { 165 } else if (*name == prefs::kManagedDefaultPopupsSetting) {
171 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS); 166 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS);
172 } else if (*name == prefs::kManagedDefaultGeolocationSetting) { 167 } else if (*name == prefs::kManagedDefaultGeolocationSetting) {
173 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION); 168 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION);
174 } else if (*name == prefs::kManagedDefaultNotificationsSetting) { 169 } else if (*name == prefs::kManagedDefaultNotificationsSetting) {
175 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 170 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
176 } else if (*name == prefs::kManagedDefaultAutoSelectCertificateSetting) {
177 UpdateManagedDefaultSetting(
178 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
179 } else { 171 } else {
180 NOTREACHED() << "Unexpected preference observed"; 172 NOTREACHED() << "Unexpected preference observed";
181 return; 173 return;
182 } 174 }
183 175
184 NotifyObservers(ContentSettingsPattern(), 176 NotifyObservers(ContentSettingsPattern(),
185 ContentSettingsPattern(), 177 ContentSettingsPattern(),
186 CONTENT_SETTINGS_TYPE_DEFAULT, 178 CONTENT_SETTINGS_TYPE_DEFAULT,
187 std::string()); 179 std::string());
188 } else { 180 } else {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 PrefService::UNSYNCABLE_PREF); 232 PrefService::UNSYNCABLE_PREF);
241 prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting, 233 prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting,
242 CONTENT_SETTING_DEFAULT, 234 CONTENT_SETTING_DEFAULT,
243 PrefService::UNSYNCABLE_PREF); 235 PrefService::UNSYNCABLE_PREF);
244 prefs->RegisterIntegerPref(prefs::kManagedDefaultGeolocationSetting, 236 prefs->RegisterIntegerPref(prefs::kManagedDefaultGeolocationSetting,
245 CONTENT_SETTING_DEFAULT, 237 CONTENT_SETTING_DEFAULT,
246 PrefService::UNSYNCABLE_PREF); 238 PrefService::UNSYNCABLE_PREF);
247 prefs->RegisterIntegerPref(prefs::kManagedDefaultNotificationsSetting, 239 prefs->RegisterIntegerPref(prefs::kManagedDefaultNotificationsSetting,
248 CONTENT_SETTING_DEFAULT, 240 CONTENT_SETTING_DEFAULT,
249 PrefService::UNSYNCABLE_PREF); 241 PrefService::UNSYNCABLE_PREF);
250 prefs->RegisterIntegerPref(prefs::kManagedDefaultAutoSelectCertificateSetting,
251 CONTENT_SETTING_ASK,
252 PrefService::UNSYNCABLE_PREF);
253 } 242 }
254 243
255 // //////////////////////////////////////////////////////////////////////////// 244 // ////////////////////////////////////////////////////////////////////////////
256 // PolicyProvider 245 // PolicyProvider
257 246
258 // static 247 // static
259 void PolicyProvider::RegisterUserPrefs(PrefService* prefs) { 248 void PolicyProvider::RegisterUserPrefs(PrefService* prefs) {
260 prefs->RegisterListPref(prefs::kManagedAutoSelectCertificateForUrls, 249 prefs->RegisterListPref(prefs::kManagedAutoSelectCertificateForUrls,
261 PrefService::UNSYNCABLE_PREF); 250 PrefService::UNSYNCABLE_PREF);
262 prefs->RegisterListPref(prefs::kManagedCookiesAllowedForUrls, 251 prefs->RegisterListPref(prefs::kManagedCookiesAllowedForUrls,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 PatternPair pattern_pair = ParsePatternString(original_pattern_str); 323 PatternPair pattern_pair = ParsePatternString(original_pattern_str);
335 // Ignore invalid patterns. 324 // Ignore invalid patterns.
336 if (!pattern_pair.first.IsValid()) { 325 if (!pattern_pair.first.IsValid()) {
337 VLOG(1) << "Ignoring invalid content settings pattern: " << 326 VLOG(1) << "Ignoring invalid content settings pattern: " <<
338 original_pattern_str; 327 original_pattern_str;
339 continue; 328 continue;
340 } 329 }
341 330
342 ContentSettingsType content_type = 331 ContentSettingsType content_type =
343 kPrefsForManagedContentSettingsMap[i].content_type; 332 kPrefsForManagedContentSettingsMap[i].content_type;
333 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
344 // If only one pattern was defined auto expand it to a pattern pair. 334 // If only one pattern was defined auto expand it to a pattern pair.
345 ContentSettingsPattern secondary_pattern = 335 ContentSettingsPattern secondary_pattern =
346 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard() 336 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard()
347 : pattern_pair.second; 337 : pattern_pair.second;
348 value_map->SetValue( 338 value_map->SetValue(
349 pattern_pair.first, 339 pattern_pair.first,
350 secondary_pattern, 340 secondary_pattern,
351 content_type, 341 content_type,
352 ResourceIdentifier(NO_RESOURCE_IDENTIFIER), 342 ResourceIdentifier(NO_RESOURCE_IDENTIFIER),
353 static_cast<Value*>(Value::CreateIntegerValue( 343 static_cast<Value*>(Value::CreateIntegerValue(
wtc 2011/09/06 22:11:42 Is this static_cast necessary? Value::CreateInteg
markusheintz_ 2011/09/07 19:29:48 Done
354 kPrefsForManagedContentSettingsMap[i].setting))); 344 kPrefsForManagedContentSettingsMap[i].setting)));
355 } 345 }
356 } 346 }
357 } 347 }
358 348
349 void PolicyProvider::GetAutoSelectCertificateSettingsFromPreferences(
350 OriginIdentifierValueMap* value_map) {
351 const char* pref_name = prefs::kManagedAutoSelectCertificateForUrls;
352
353 if (!prefs_->HasPrefPath(pref_name)) {
354 VLOG(2) << "Skipping unset preference: " << pref_name;
355 return;
356 }
357
358 const PrefService::Preference* pref = prefs_->FindPreference(pref_name);
359 DCHECK(pref);
360 DCHECK(pref->IsManaged());
361
362 const ListValue* pattern_filter_str_list = NULL;
363 if (!pref->GetValue()->GetAsList(&pattern_filter_str_list)) {
364 NOTREACHED();
365 return;
366 }
367
368 // Parse the list of pattern filter strings. A pattern filter string has
369 // the following JSON format:
370 //
371 // {
372 // "pattern": <content settings pattern string>,
373 // "filter" : <certificate filter in JSON format>
374 // }
375 //
376 // e.g.
377 // {
378 // "pattern": "[*.]example.com",
379 // "filter": {
380 // "ISSUER": {
381 // "CN": "some name"
382 // }
383 // }
384 for (size_t j = 0; j < pattern_filter_str_list->GetSize(); ++j) {
385 std::string pattern_filter_json;
386 pattern_filter_str_list->GetString(j, &pattern_filter_json);
387
388 scoped_ptr<Value> value(base::JSONReader::Read(pattern_filter_json, true));
389 if (!value.get()) {
390 VLOG(1) << "Ignoring invalid certificate auto select setting. Reason:"
391 << " Invalid JSON format: " << pattern_filter_json;
392 continue;
393 }
394
395 scoped_ptr<DictionaryValue> pattern_filter_pair(
396 static_cast<DictionaryValue*>(value.release()));
397 std::string pattern_str;
398 bool pattern_read = pattern_filter_pair->GetString("pattern", &pattern_str);
399 Value* cert_filter_ptr = NULL;
400 bool filter_read = pattern_filter_pair->Remove("filter", &cert_filter_ptr);
401 scoped_ptr<Value> cert_filter(cert_filter_ptr);
402 if (!pattern_read || !filter_read) {
wtc 2011/09/07 17:27:48 We need to allow a policy that specifies no additi
markusheintz_ 2011/09/07 19:29:48 I guess my question here is why do we need this?
wtc 2011/09/07 21:31:35 An SSL/TLS server can specify the list of acceptab
markusheintz_ 2011/09/07 22:23:37 I'm not really a TLS expert but I'm trying to fill
wtc 2011/09/07 23:14:20 Yes, that's how a TLS server requests client authe
403 VLOG(1) << "Ignoring invalid certificate auto select setting. Reason:"
404 << " Missing pattern or filtern.";
wtc 2011/09/06 22:11:42 Typo: filtern => filter Nit: to concatendate stri
markusheintz_ 2011/09/07 19:29:48 What the suggested style for this? Jost ommitting
wtc 2011/09/07 21:31:35 There is no suggested style in the Style Guide. J
405 continue;
406 }
407
408 ContentSettingsPattern pattern =
409 ContentSettingsPattern::FromString(pattern_str);
410 // Ignore invalid patterns.
411 if (!pattern.IsValid()) {
412 VLOG(1) << "Ignoring invalid certificate auto select setting:"
413 << " Invalid content settings pattern: " << pattern;
414 continue;
415 }
416
417 DCHECK(cert_filter->IsType(Value::TYPE_DICTIONARY));
418 value_map->SetValue(pattern,
419 ContentSettingsPattern::Wildcard(),
420 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
421 std::string(),
422 cert_filter.release());
423 }
424 }
425
359 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { 426 void PolicyProvider::ReadManagedContentSettings(bool overwrite) {
360 { 427 {
361 base::AutoLock auto_lock(lock_); 428 base::AutoLock auto_lock(lock_);
362 if (overwrite) 429 if (overwrite)
363 value_map_.clear(); 430 value_map_.clear();
364 GetContentSettingsFromPreferences(&value_map_); 431 GetContentSettingsFromPreferences(&value_map_);
432 GetAutoSelectCertificateSettingsFromPreferences(&value_map_);
365 } 433 }
wtc 2011/09/06 22:11:42 Remove the curly braces on lines 427 and 433.
markusheintz_ 2011/09/07 19:29:48 Done.
366 } 434 }
367 435
368 // Since the PolicyProvider is a read only content settings provider, all 436 // Since the PolicyProvider is a read only content settings provider, all
369 // methodes of the ProviderInterface that set or delete any settings do nothing. 437 // methodes of the ProviderInterface that set or delete any settings do nothing.
370 void PolicyProvider::SetContentSetting( 438 void PolicyProvider::SetContentSetting(
371 const ContentSettingsPattern& primary_pattern, 439 const ContentSettingsPattern& primary_pattern,
372 const ContentSettingsPattern& secondary_pattern, 440 const ContentSettingsPattern& secondary_pattern,
373 ContentSettingsType content_type, 441 ContentSettingsType content_type,
374 const ResourceIdentifier& resource_identifier, 442 const ResourceIdentifier& resource_identifier,
375 ContentSetting content_setting) { 443 ContentSetting content_setting) {
376 } 444 }
377 445
378 ContentSetting PolicyProvider::GetContentSetting( 446 ContentSetting PolicyProvider::GetContentSetting(
379 const GURL& primary_url, 447 const GURL& primary_url,
380 const GURL& secondary_url, 448 const GURL& secondary_url,
381 ContentSettingsType content_type, 449 ContentSettingsType content_type,
382 const ResourceIdentifier& resource_identifier) const { 450 const ResourceIdentifier& resource_identifier) const {
451 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
383 // Resource identifier are not supported by policies as long as the feature is 452 // Resource identifier are not supported by policies as long as the feature is
384 // behind a flag. So resource identifiers are simply ignored. 453 // behind a flag. So resource identifiers are simply ignored.
385 scoped_ptr<Value> value(GetContentSettingValue(primary_url, 454 scoped_ptr<Value> value(GetContentSettingValue(primary_url,
386 secondary_url, 455 secondary_url,
387 content_type, 456 content_type,
388 resource_identifier)); 457 resource_identifier));
389 ContentSetting setting = 458 ContentSetting setting =
390 value.get() ? ValueToContentSetting(value.get()) 459 value.get() ? ValueToContentSetting(value.get())
391 : CONTENT_SETTING_DEFAULT; 460 : CONTENT_SETTING_DEFAULT;
392 if (setting == CONTENT_SETTING_DEFAULT && default_provider_) 461 if (setting == CONTENT_SETTING_DEFAULT && default_provider_)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 ContentSettingsPattern(), 542 ContentSettingsPattern(),
474 CONTENT_SETTINGS_TYPE_DEFAULT, 543 CONTENT_SETTINGS_TYPE_DEFAULT,
475 std::string()); 544 std::string());
476 } 545 }
477 } else { 546 } else {
478 NOTREACHED() << "Unexpected notification"; 547 NOTREACHED() << "Unexpected notification";
479 } 548 }
480 } 549 }
481 550
482 } // namespace content_settings 551 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698