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

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: Remove unrelated changes from patchset. 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,
36 prefs::kManagedDefaultAutoSelectCertificateSetting, 37 NULL,
Pam (message me for reviews) 2011/09/04 09:10:14 It'd be nice to add a comment explaining why these
markusheintz_ 2011/09/04 18:07:01 Done.
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 rules->push_back(MakeTuple( 338 rules->push_back(MakeTuple(
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 kPrefsForManagedContentSettingsMap[i].setting)); 343 kPrefsForManagedContentSettingsMap[i].setting));
354 } 344 }
355 } 345 }
356 } 346 }
357 347
348 void PolicyProvider::GetAutoSelectCertificateSettingsFromPreferences(
349 OriginIdentifierValueMap* value_map) {
350 const char* pref_name = prefs::kManagedAutoSelectCertificateForUrls;
351
352 if (!prefs_->HasPrefPath(pref_name)) {
353 VLOG(2) << "Skipping unset preference: " << pref_name;
354 return;
355 }
356
357 const PrefService::Preference* pref = prefs_->FindPreference(pref_name);
358 DCHECK(pref);
359 DCHECK(pref->IsManaged());
360
361 const ListValue* pattern_filter_str_list = NULL;
362 if (!pref->GetValue()->GetAsList(&pattern_filter_str_list)) {
363 NOTREACHED();
364 return;
365 }
366
367 // Parse the list of pattern filter strings. A pattern filter string has the
368 // following JSON format:
369 //
370 // {
371 // "pattern": <content settings pattern string>,
372 // "filter" : <certificate filter in JSON format>
373 // }
374 //
375 // e.g. {
376 // "pattern": "[*.]example.com",
377 // "filter": {
378 // "ISSUER": {
379 // "CN": "some name"
380 // }
381 // }
382 for (size_t j = 0; j < pattern_filter_str_list->GetSize(); ++j) {
383 std::string pattern_filter_json;
384 pattern_filter_str_list->GetString(j, &pattern_filter_json);
385
386 scoped_ptr<Value> value(base::JSONReader::Read(pattern_filter_json, true));
387 if (!value.get()) {
388 VLOG(1) << "TODO";
Pam (message me for reviews) 2011/09/04 09:10:14 Please do TODO. Also two more below.
markusheintz_ 2011/09/04 18:07:01 Double *grrr* to myself. Fixing them got lost some
389 continue;
390 }
391
392 scoped_ptr<DictionaryValue> pattern_filter_pair(
393 static_cast<DictionaryValue*>(value.release()));
394 std::string pattern_str;
395 bool pattern_read = pattern_filter_pair->GetString("pattern", &pattern_str);
396 Value* cert_filter_ptr = NULL;
397 bool filter_read = pattern_filter_pair->Remove("filter", &cert_filter_ptr);
398 scoped_ptr<Value> cert_filter(cert_filter_ptr);
399 if (!pattern_read || !filter_read) {
400 VLOG(1) << "TODO";
401 continue;
402 }
403
404 ContentSettingsPattern pattern =
405 ContentSettingsPattern::FromString(pattern_str);
406 // Ignore invalid patterns.
407 if (!pattern.IsValid()) {
408 VLOG(1) << "TODO";
409 continue;
410 }
411
412 DCHECK(cert_filter->IsType(Value::TYPE_DICTIONARY));
413 value_map->SetValue(pattern,
414 ContentSettingsPattern::Wildcard(),
415 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
416 std::string(),
417 cert_filter.release());
418 }
419 }
420
358 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { 421 void PolicyProvider::ReadManagedContentSettings(bool overwrite) {
359 ContentSettingsRules rules; 422 ContentSettingsRules rules;
360 GetContentSettingsFromPreferences(&rules); 423 GetContentSettingsFromPreferences(&rules);
361 { 424 {
362 base::AutoLock auto_lock(lock_); 425 base::AutoLock auto_lock(lock_);
363 if (overwrite) 426 if (overwrite)
364 value_map_.clear(); 427 value_map_.clear();
365 for (ContentSettingsRules::iterator rule = rules.begin(); 428 for (ContentSettingsRules::iterator rule = rules.begin();
366 rule != rules.end(); 429 rule != rules.end();
367 ++rule) { 430 ++rule) {
368 value_map_.SetValue(rule->a, 431 value_map_.SetValue(rule->a,
369 rule->b, 432 rule->b,
370 rule->c, 433 rule->c,
371 rule->d, 434 rule->d,
372 Value::CreateIntegerValue(rule->e)); 435 Value::CreateIntegerValue(rule->e));
373 } 436 }
437 GetAutoSelectCertificateSettingsFromPreferences(&value_map_);
374 } 438 }
375 } 439 }
376 440
377 // Since the PolicyProvider is a read only content settings provider, all 441 // Since the PolicyProvider is a read only content settings provider, all
378 // methodes of the ProviderInterface that set or delete any settings do nothing. 442 // methodes of the ProviderInterface that set or delete any settings do nothing.
379 void PolicyProvider::SetContentSetting( 443 void PolicyProvider::SetContentSetting(
380 const ContentSettingsPattern& primary_pattern, 444 const ContentSettingsPattern& primary_pattern,
381 const ContentSettingsPattern& secondary_pattern, 445 const ContentSettingsPattern& secondary_pattern,
382 ContentSettingsType content_type, 446 ContentSettingsType content_type,
383 const ResourceIdentifier& resource_identifier, 447 const ResourceIdentifier& resource_identifier,
384 ContentSetting content_setting) { 448 ContentSetting content_setting) {
385 } 449 }
386 450
387 ContentSetting PolicyProvider::GetContentSetting( 451 ContentSetting PolicyProvider::GetContentSetting(
388 const GURL& primary_url, 452 const GURL& primary_url,
389 const GURL& secondary_url, 453 const GURL& secondary_url,
390 ContentSettingsType content_type, 454 ContentSettingsType content_type,
391 const ResourceIdentifier& resource_identifier) const { 455 const ResourceIdentifier& resource_identifier) const {
456 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
392 // Resource identifier are not supported by policies as long as the feature is 457 // Resource identifier are not supported by policies as long as the feature is
393 // behind a flag. So resource identifiers are simply ignored. 458 // behind a flag. So resource identifiers are simply ignored.
394 scoped_ptr<Value> value(GetContentSettingValue(primary_url, 459 scoped_ptr<Value> value(GetContentSettingValue(primary_url,
395 secondary_url, 460 secondary_url,
396 content_type, 461 content_type,
397 resource_identifier)); 462 resource_identifier));
398 ContentSetting setting = 463 ContentSetting setting =
399 value.get() ? ValueToContentSetting(value.get()) 464 value.get() ? ValueToContentSetting(value.get())
400 : CONTENT_SETTING_DEFAULT; 465 : CONTENT_SETTING_DEFAULT;
401 if (setting == CONTENT_SETTING_DEFAULT && default_provider_) 466 if (setting == CONTENT_SETTING_DEFAULT && default_provider_)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 ContentSettingsPattern(), 547 ContentSettingsPattern(),
483 CONTENT_SETTINGS_TYPE_DEFAULT, 548 CONTENT_SETTINGS_TYPE_DEFAULT,
484 std::string()); 549 std::string());
485 } 550 }
486 } else { 551 } else {
487 NOTREACHED() << "Unexpected notification"; 552 NOTREACHED() << "Unexpected notification";
488 } 553 }
489 } 554 }
490 555
491 } // namespace content_settings 556 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698