Chromium Code Reviews| 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" |
| 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" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 PatternPair pattern_pair = ParsePatternString(original_pattern_str); | 331 PatternPair pattern_pair = ParsePatternString(original_pattern_str); |
| 335 // Ignore invalid patterns. | 332 // Ignore invalid patterns. |
| 336 if (!pattern_pair.first.IsValid()) { | 333 if (!pattern_pair.first.IsValid()) { |
| 337 VLOG(1) << "Ignoring invalid content settings pattern: " << | 334 VLOG(1) << "Ignoring invalid content settings pattern: " << |
| 338 original_pattern_str; | 335 original_pattern_str; |
| 339 continue; | 336 continue; |
| 340 } | 337 } |
| 341 | 338 |
| 342 ContentSettingsType content_type = | 339 ContentSettingsType content_type = |
| 343 kPrefsForManagedContentSettingsMap[i].content_type; | 340 kPrefsForManagedContentSettingsMap[i].content_type; |
| 341 DCHECK(content_type != CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | |
|
wtc
2011/09/01 22:42:34
Nit: use DCHECK_NE.
markusheintz_
2011/09/02 14:55:59
Done.
| |
| 344 // If only one pattern was defined auto expand it to a pattern pair. | 342 // If only one pattern was defined auto expand it to a pattern pair. |
| 345 ContentSettingsPattern secondary_pattern = | 343 ContentSettingsPattern secondary_pattern = |
| 346 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard() | 344 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard() |
| 347 : pattern_pair.second; | 345 : pattern_pair.second; |
| 348 rules->push_back(MakeTuple( | 346 rules->push_back(MakeTuple( |
| 349 pattern_pair.first, | 347 pattern_pair.first, |
| 350 secondary_pattern, | 348 secondary_pattern, |
| 351 content_type, | 349 content_type, |
| 352 ResourceIdentifier(NO_RESOURCE_IDENTIFIER), | 350 ResourceIdentifier(NO_RESOURCE_IDENTIFIER), |
| 353 kPrefsForManagedContentSettingsMap[i].setting)); | 351 kPrefsForManagedContentSettingsMap[i].setting)); |
| 354 } | 352 } |
| 355 } | 353 } |
| 356 } | 354 } |
| 357 | 355 |
| 356 void PolicyProvider::GetAutoSelectCertificateSettingsFromPreferences( | |
| 357 OriginIdentifierValueMap* value_map) { | |
| 358 const char* pref_name = prefs::kManagedAutoSelectCertificateForUrls; | |
| 359 | |
| 360 if (!prefs_->HasPrefPath(pref_name)) { | |
| 361 VLOG(2) << "Skipping unset preference: " << pref_name; | |
| 362 return; | |
| 363 } | |
| 364 | |
| 365 const PrefService::Preference* pref = prefs_->FindPreference(pref_name); | |
| 366 DCHECK(pref); | |
| 367 DCHECK(pref->IsManaged()); | |
| 368 | |
| 369 const ListValue* pattern_filter_str_list = NULL; | |
| 370 if (!pref->GetValue()->GetAsList(&pattern_filter_str_list)) { | |
| 371 NOTREACHED(); | |
| 372 return; | |
| 373 } | |
| 374 | |
| 375 for (size_t j = 0; j < pattern_filter_str_list->GetSize(); ++j) { | |
| 376 std::string pattern_filter_str; | |
| 377 pattern_filter_str_list->GetString(j, &pattern_filter_str); | |
| 378 | |
| 379 size_t separator_pos = pattern_filter_str.find("|"); | |
|
wtc
2011/09/01 22:42:34
Nit: is there a version of find() that takes a cha
markusheintz_
2011/09/02 14:55:59
Done.
| |
| 380 if (separator_pos == std::string::npos) { | |
| 381 VLOG(1) << "No filter string found. Ignoring list entry: " | |
| 382 << pattern_filter_str; | |
| 383 continue; | |
| 384 } | |
| 385 std::string pattern_str = pattern_filter_str.substr(0, separator_pos); | |
| 386 std::string filter_str = pattern_filter_str.substr(separator_pos + 1); | |
| 387 | |
| 388 ContentSettingsPattern pattern = | |
| 389 ContentSettingsPattern::FromString(pattern_str); | |
| 390 // Ignore invalid patterns. | |
| 391 if (!pattern.IsValid()) { | |
| 392 VLOG(1) << "Invalid content settings pattern: " << pattern_str | |
| 393 << ". Ignoring list entry: " << pattern_filter_str; | |
| 394 continue; | |
| 395 } | |
| 396 | |
| 397 // Allow trailing commas to be more fault tolerant. | |
| 398 scoped_ptr<Value> filter_value(base::JSONReader::Read(filter_str, true)); | |
| 399 DCHECK(filter_value->IsType(Value::TYPE_DICTIONARY)); | |
|
wtc
2011/09/01 22:42:34
The DCHECK should be done after the null pointer t
markusheintz_
2011/09/02 14:55:59
Done.
| |
| 400 if (!filter_value.get()) { | |
| 401 VLOG(1) << "Invalid JSON string: " << filter_str | |
| 402 << ". Ignoring list entry: " << pattern_filter_str; | |
| 403 continue; | |
| 404 } | |
| 405 | |
| 406 value_map->SetValue(pattern, | |
| 407 ContentSettingsPattern::Wildcard(), | |
| 408 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | |
| 409 std::string(), | |
| 410 filter_value.release()); | |
| 411 } | |
| 412 } | |
| 413 | |
| 358 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { | 414 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { |
| 359 ContentSettingsRules rules; | 415 ContentSettingsRules rules; |
| 360 GetContentSettingsFromPreferences(&rules); | 416 GetContentSettingsFromPreferences(&rules); |
| 361 { | 417 { |
| 362 base::AutoLock auto_lock(lock_); | 418 base::AutoLock auto_lock(lock_); |
| 363 if (overwrite) | 419 if (overwrite) |
| 364 value_map_.clear(); | 420 value_map_.clear(); |
| 365 for (ContentSettingsRules::iterator rule = rules.begin(); | 421 for (ContentSettingsRules::iterator rule = rules.begin(); |
| 366 rule != rules.end(); | 422 rule != rules.end(); |
| 367 ++rule) { | 423 ++rule) { |
| 368 value_map_.SetValue(rule->a, | 424 value_map_.SetValue(rule->a, |
| 369 rule->b, | 425 rule->b, |
| 370 rule->c, | 426 rule->c, |
| 371 rule->d, | 427 rule->d, |
| 372 Value::CreateIntegerValue(rule->e)); | 428 Value::CreateIntegerValue(rule->e)); |
| 373 } | 429 } |
| 430 GetAutoSelectCertificateSettingsFromPreferences(&value_map_); | |
| 374 } | 431 } |
| 375 } | 432 } |
| 376 | 433 |
| 377 // Since the PolicyProvider is a read only content settings provider, all | 434 // Since the PolicyProvider is a read only content settings provider, all |
| 378 // methodes of the ProviderInterface that set or delete any settings do nothing. | 435 // methodes of the ProviderInterface that set or delete any settings do nothing. |
| 379 void PolicyProvider::SetContentSetting( | 436 void PolicyProvider::SetContentSetting( |
| 380 const ContentSettingsPattern& primary_pattern, | 437 const ContentSettingsPattern& primary_pattern, |
| 381 const ContentSettingsPattern& secondary_pattern, | 438 const ContentSettingsPattern& secondary_pattern, |
| 382 ContentSettingsType content_type, | 439 ContentSettingsType content_type, |
| 383 const ResourceIdentifier& resource_identifier, | 440 const ResourceIdentifier& resource_identifier, |
| 384 ContentSetting content_setting) { | 441 ContentSetting content_setting) { |
| 385 } | 442 } |
| 386 | 443 |
| 387 ContentSetting PolicyProvider::GetContentSetting( | 444 ContentSetting PolicyProvider::GetContentSetting( |
| 388 const GURL& primary_url, | 445 const GURL& primary_url, |
| 389 const GURL& secondary_url, | 446 const GURL& secondary_url, |
| 390 ContentSettingsType content_type, | 447 ContentSettingsType content_type, |
| 391 const ResourceIdentifier& resource_identifier) const { | 448 const ResourceIdentifier& resource_identifier) const { |
| 449 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | |
| 392 // Resource identifier are not supported by policies as long as the feature is | 450 // Resource identifier are not supported by policies as long as the feature is |
| 393 // behind a flag. So resource identifiers are simply ignored. | 451 // behind a flag. So resource identifiers are simply ignored. |
| 394 scoped_ptr<Value> value(GetContentSettingValue(primary_url, | 452 scoped_ptr<Value> value(GetContentSettingValue(primary_url, |
| 395 secondary_url, | 453 secondary_url, |
| 396 content_type, | 454 content_type, |
| 397 resource_identifier)); | 455 resource_identifier)); |
| 398 ContentSetting setting = | 456 ContentSetting setting = |
| 399 value.get() ? ValueToContentSetting(value.get()) | 457 value.get() ? ValueToContentSetting(value.get()) |
| 400 : CONTENT_SETTING_DEFAULT; | 458 : CONTENT_SETTING_DEFAULT; |
| 401 if (setting == CONTENT_SETTING_DEFAULT && default_provider_) | 459 if (setting == CONTENT_SETTING_DEFAULT && default_provider_) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 ContentSettingsPattern(), | 542 ContentSettingsPattern(), |
| 485 CONTENT_SETTINGS_TYPE_DEFAULT, | 543 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 486 std::string()); | 544 std::string()); |
| 487 } | 545 } |
| 488 } else { | 546 } else { |
| 489 NOTREACHED() << "Unexpected notification"; | 547 NOTREACHED() << "Unexpected notification"; |
| 490 } | 548 } |
| 491 } | 549 } |
| 492 | 550 |
| 493 } // namespace content_settings | 551 } // namespace content_settings |
| OLD | NEW |