Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/tuple.h" | |
| 10 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
| 11 #include "chrome/browser/content_settings/content_settings_details.h" | 12 #include "chrome/browser/content_settings/content_settings_details.h" |
| 12 #include "chrome/browser/content_settings/content_settings_pattern.h" | 13 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/prefs/scoped_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_pref_update.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/notification_details.h" | 17 #include "chrome/common/notification_details.h" |
| 17 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
| 18 #include "chrome/common/notification_source.h" | 19 #include "chrome/common/notification_source.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 | 21 |
| 22 #include "webkit/plugins/npapi/plugin_group.h" | |
| 23 #include "webkit/plugins/npapi/plugin_list.h" | |
| 24 | |
| 21 namespace { | 25 namespace { |
| 22 | 26 |
| 23 // Base pref path of the prefs that contain the managed default content | 27 // Base pref path of the prefs that contain the managed default content |
| 24 // settings values. | 28 // settings values. |
| 25 const std::string kManagedSettings = | 29 const std::string kManagedSettings = |
| 26 "profile.managed_default_content_settings"; | 30 "profile.managed_default_content_settings"; |
| 27 | 31 |
| 28 // The preferences used to manage ContentSettingsTypes. | 32 // The preferences used to manage ContentSettingsTypes. |
| 29 const char* kPrefToManageType[CONTENT_SETTINGS_NUM_TYPES] = { | 33 const char* kPrefToManageType[CONTENT_SETTINGS_NUM_TYPES] = { |
| 30 prefs::kManagedDefaultCookiesSetting, | 34 prefs::kManagedDefaultCookiesSetting, |
| 31 prefs::kManagedDefaultImagesSetting, | 35 prefs::kManagedDefaultImagesSetting, |
| 32 prefs::kManagedDefaultJavaScriptSetting, | 36 prefs::kManagedDefaultJavaScriptSetting, |
| 33 prefs::kManagedDefaultPluginsSetting, | 37 prefs::kManagedDefaultPluginsSetting, |
| 34 prefs::kManagedDefaultPopupsSetting, | 38 prefs::kManagedDefaultPopupsSetting, |
| 35 NULL, // Not used for Geolocation | 39 NULL, // Not used for Geolocation |
| 36 NULL, // Not used for Notifications | 40 NULL, // Not used for Notifications |
| 37 }; | 41 }; |
| 38 | 42 |
| 43 struct PrefsForManagedContentSettingsMapEntry { | |
| 44 const char* pref_name; | |
| 45 ContentSettingsType content_type; | |
| 46 ContentSetting setting; | |
| 47 }; | |
| 48 | |
| 49 const PrefsForManagedContentSettingsMapEntry | |
| 50 kPrefsForManagedContentSettingsMap[] = { | |
| 51 { | |
| 52 prefs::kManagedCookiesAllowedForUrls, | |
| 53 CONTENT_SETTINGS_TYPE_COOKIES, | |
| 54 CONTENT_SETTING_ALLOW | |
| 55 }, { | |
| 56 prefs::kManagedCookiesBlockedForUrls, | |
| 57 CONTENT_SETTINGS_TYPE_COOKIES, | |
| 58 CONTENT_SETTING_BLOCK | |
| 59 }, { | |
| 60 prefs::kManagedCookiesSessionOnlyForUrls, | |
| 61 CONTENT_SETTINGS_TYPE_COOKIES, | |
| 62 CONTENT_SETTING_SESSION_ONLY | |
| 63 }, { | |
| 64 prefs::kManagedImagesAllowedForUrls, | |
| 65 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 66 CONTENT_SETTING_ALLOW | |
| 67 }, { | |
| 68 prefs::kManagedImagesBlockedForUrls, | |
| 69 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 70 CONTENT_SETTING_BLOCK | |
| 71 }, { | |
| 72 prefs::kManagedJavaScriptAllowedForUrls, | |
| 73 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
| 74 CONTENT_SETTING_ALLOW | |
| 75 }, { | |
| 76 prefs::kManagedJavaScriptBlockedForUrls, | |
| 77 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
| 78 CONTENT_SETTING_BLOCK | |
| 79 }, { | |
| 80 prefs::kManagedPluginsAllowedForUrls, | |
| 81 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 82 CONTENT_SETTING_ALLOW | |
| 83 }, { | |
| 84 prefs::kManagedPluginsBlockedForUrls, | |
| 85 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 86 CONTENT_SETTING_BLOCK | |
| 87 }, { | |
| 88 prefs::kManagedPluginsAskForUrls, | |
| 89 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 90 CONTENT_SETTING_ASK | |
| 91 }, { | |
| 92 prefs::kManagedPopupsAllowedForUrls, | |
| 93 CONTENT_SETTINGS_TYPE_POPUPS, | |
| 94 CONTENT_SETTING_ALLOW | |
| 95 }, { | |
| 96 prefs::kManagedPopupsBlockedForUrls, | |
| 97 CONTENT_SETTINGS_TYPE_POPUPS, | |
| 98 CONTENT_SETTING_BLOCK | |
| 99 } | |
| 100 }; | |
| 101 | |
| 39 } // namespace | 102 } // namespace |
| 40 | 103 |
| 41 namespace content_settings { | 104 namespace content_settings { |
| 42 | 105 |
| 43 PolicyDefaultProvider::PolicyDefaultProvider(Profile* profile) | 106 PolicyDefaultProvider::PolicyDefaultProvider(Profile* profile) |
| 44 : profile_(profile), | 107 : profile_(profile), |
| 45 is_off_the_record_(profile_->IsOffTheRecord()) { | 108 is_off_the_record_(profile_->IsOffTheRecord()) { |
| 46 PrefService* prefs = profile->GetPrefs(); | 109 PrefService* prefs = profile->GetPrefs(); |
| 47 | 110 |
| 48 // Read global defaults. | 111 // Read global defaults. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 return; | 212 return; |
| 150 NotificationService::current()->Notify( | 213 NotificationService::current()->Notify( |
| 151 NotificationType::CONTENT_SETTINGS_CHANGED, | 214 NotificationType::CONTENT_SETTINGS_CHANGED, |
| 152 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 215 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), |
| 153 Details<const ContentSettingsDetails>(&details)); | 216 Details<const ContentSettingsDetails>(&details)); |
| 154 } | 217 } |
| 155 | 218 |
| 156 void PolicyDefaultProvider::ReadManagedDefaultSettings() { | 219 void PolicyDefaultProvider::ReadManagedDefaultSettings() { |
| 157 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { | 220 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { |
| 158 if (kPrefToManageType[type] == NULL) { | 221 if (kPrefToManageType[type] == NULL) { |
| 159 // TODO(markusheintz): Handle Geolocation and notification separately. | |
| 160 continue; | 222 continue; |
| 161 } | 223 } |
| 162 UpdateManagedDefaultSetting(ContentSettingsType(type)); | 224 UpdateManagedDefaultSetting(ContentSettingsType(type)); |
| 163 } | 225 } |
| 164 } | 226 } |
| 165 | 227 |
| 166 void PolicyDefaultProvider::UpdateManagedDefaultSetting( | 228 void PolicyDefaultProvider::UpdateManagedDefaultSetting( |
| 167 ContentSettingsType type) { | 229 ContentSettingsType type) { |
| 168 // If a pref to manage a default-content-setting was not set (NOTICE: | 230 // If a pref to manage a default-content-setting was not set (NOTICE: |
| 169 // "HasPrefPath" returns false if no value was set for a registered pref) then | 231 // "HasPrefPath" returns false if no value was set for a registered pref) then |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 188 prefs->RegisterIntegerPref(prefs::kManagedDefaultImagesSetting, | 250 prefs->RegisterIntegerPref(prefs::kManagedDefaultImagesSetting, |
| 189 CONTENT_SETTING_DEFAULT); | 251 CONTENT_SETTING_DEFAULT); |
| 190 prefs->RegisterIntegerPref(prefs::kManagedDefaultJavaScriptSetting, | 252 prefs->RegisterIntegerPref(prefs::kManagedDefaultJavaScriptSetting, |
| 191 CONTENT_SETTING_DEFAULT); | 253 CONTENT_SETTING_DEFAULT); |
| 192 prefs->RegisterIntegerPref(prefs::kManagedDefaultPluginsSetting, | 254 prefs->RegisterIntegerPref(prefs::kManagedDefaultPluginsSetting, |
| 193 CONTENT_SETTING_DEFAULT); | 255 CONTENT_SETTING_DEFAULT); |
| 194 prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting, | 256 prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting, |
| 195 CONTENT_SETTING_DEFAULT); | 257 CONTENT_SETTING_DEFAULT); |
| 196 } | 258 } |
| 197 | 259 |
| 260 // //////////////////////////////////////////////////////////////////////////// | |
| 261 // PolicyProvider | |
| 262 | |
| 263 // static | |
| 264 void PolicyProvider::RegisterUserPrefs(PrefService* prefs) { | |
| 265 prefs->RegisterListPref(prefs::kManagedCookiesAllowedForUrls); | |
| 266 prefs->RegisterListPref(prefs::kManagedCookiesBlockedForUrls); | |
| 267 prefs->RegisterListPref(prefs::kManagedCookiesSessionOnlyForUrls); | |
| 268 prefs->RegisterListPref(prefs::kManagedImagesAllowedForUrls); | |
| 269 prefs->RegisterListPref(prefs::kManagedImagesBlockedForUrls); | |
| 270 prefs->RegisterListPref(prefs::kManagedJavaScriptAllowedForUrls); | |
| 271 prefs->RegisterListPref(prefs::kManagedJavaScriptBlockedForUrls); | |
| 272 prefs->RegisterListPref(prefs::kManagedPluginsAllowedForUrls); | |
| 273 prefs->RegisterListPref(prefs::kManagedPluginsBlockedForUrls); | |
| 274 prefs->RegisterListPref(prefs::kManagedPluginsAskForUrls); | |
| 275 prefs->RegisterListPref(prefs::kManagedPopupsAllowedForUrls); | |
| 276 prefs->RegisterListPref(prefs::kManagedPopupsBlockedForUrls); | |
| 277 } | |
| 278 | |
| 279 PolicyProvider::PolicyProvider(Profile* profile) | |
| 280 : BaseProvider(profile->IsOffTheRecord()), | |
| 281 profile_(profile) { | |
| 282 Init(); | |
| 283 } | |
| 284 | |
| 285 PolicyProvider::~PolicyProvider() { | |
| 286 UnregisterObservers(); | |
| 287 } | |
| 288 | |
| 289 void PolicyProvider::ReadManagedContentSettingsTypes( | |
| 290 ContentSettingsType content_type) { | |
| 291 PrefService* prefs = profile_->GetPrefs(); | |
| 292 if (kPrefToManageType[content_type] == NULL) { | |
| 293 content_type_is_managed_[content_type] = false; | |
| 294 } else { | |
| 295 content_type_is_managed_[content_type] = | |
| 296 prefs->IsManagedPreference(kPrefToManageType[content_type]); | |
| 297 } | |
| 298 } | |
| 299 | |
| 300 void PolicyProvider::Init() { | |
| 301 PrefService* prefs = profile_->GetPrefs(); | |
| 302 | |
| 303 ReadManagedContentSettings(false); | |
| 304 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) | |
| 305 ReadManagedContentSettingsTypes(ContentSettingsType(i)); | |
| 306 | |
| 307 pref_change_registrar_.Init(prefs); | |
| 308 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); | |
| 309 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); | |
| 310 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); | |
| 311 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); | |
| 312 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); | |
| 313 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); | |
| 314 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); | |
| 315 pref_change_registrar_.Add(prefs::kManagedPluginsBlockedForUrls, this); | |
| 316 pref_change_registrar_.Add(prefs::kManagedPluginsAllowedForUrls, this); | |
| 317 pref_change_registrar_.Add(prefs::kManagedPluginsAskForUrls, this); | |
| 318 pref_change_registrar_.Add(prefs::kManagedPopupsBlockedForUrls, this); | |
| 319 pref_change_registrar_.Add(prefs::kManagedPopupsAllowedForUrls, this); | |
| 320 | |
| 321 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); | |
| 322 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); | |
| 323 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); | |
| 324 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); | |
| 325 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); | |
| 326 | |
| 327 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | |
| 328 Source<Profile>(profile_)); | |
| 329 } | |
| 330 | |
| 331 bool PolicyProvider::ContentSettingsTypeIsManaged( | |
| 332 ContentSettingsType content_type) { | |
| 333 return content_type_is_managed_[content_type]; | |
| 334 } | |
| 335 | |
| 336 namespace { | |
| 337 | |
| 338 typedef Tuple5< | |
| 339 ContentSettingsPattern, | |
| 340 ContentSettingsPattern, | |
| 341 ContentSettingsType, | |
| 342 ProviderInterface::ResourceIdentifier, | |
| 343 ContentSetting> ContentSettingsRule; | |
| 344 | |
| 345 typedef std::vector<ContentSettingsRule> ContentSettingsRules; | |
| 346 | |
| 347 const std::string WILDCARD = "*"; | |
| 348 const std::string SEPERATOR = ":"; | |
| 349 const std::string NO_IDENTIFIER = ""; | |
| 350 | |
| 351 } // namespace | |
| 352 | |
| 353 | |
| 354 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { | |
| 355 ContentSettingsRules rules; | |
| 356 | |
| 357 // Load managed content settings patterns from preferences. | |
| 358 PrefService* prefs = profile_->GetPrefs(); | |
| 359 for (size_t i = 0; i < arraysize(kPrefsForManagedContentSettingsMap); ++i) { | |
| 360 const char* pref_name = kPrefsForManagedContentSettingsMap[i].pref_name; | |
| 361 // Skip unset policies. | |
| 362 if (!prefs->HasPrefPath(pref_name)) | |
| 363 continue; | |
| 364 | |
| 365 const PrefService::Preference* pref = prefs->FindPreference(pref_name); | |
| 366 DCHECK(pref->IsManaged()); | |
| 367 DCHECK_EQ(Value::TYPE_LIST, pref->GetType()); | |
| 368 | |
| 369 const ListValue* pattern_str_list = | |
| 370 static_cast<const ListValue*>(pref->GetValue()); | |
| 371 for (size_t j = 0; j < pattern_str_list->GetSize(); ++j) { | |
| 372 std::string original_pattern_str; | |
| 373 pattern_str_list->GetString(j, &original_pattern_str); | |
| 374 | |
| 375 // Check if a resource identifier is in the pattern string. | |
| 376 | |
| 377 // For content_types that require a resource identifier extract the | |
| 378 // resource identifier from the pattern. | |
| 379 // <resource_identifier>:<content_settings_pattern> | |
| 380 std::string resource_identifier(NO_IDENTIFIER); | |
| 381 size_t separator_pos = original_pattern_str.find(SEPERATOR); | |
| 382 if (!separator_pos == std::string::npos) { | |
| 383 int resource_identifier_length = separator_pos + 1; | |
| 384 resource_identifier = | |
| 385 original_pattern_str.substr(0, resource_identifier_length); | |
| 386 // TODO(markusheintz): Normalize resource_identifier. | |
| 387 original_pattern_str.erase(0, resource_identifier_length); | |
| 388 } | |
| 389 | |
| 390 // If a resource identifier is required but no resource identifier is | |
| 391 // specified use the wildcard identifier. | |
| 392 if (RequiresResourceIdentifier( | |
| 393 kPrefsForManagedContentSettingsMap[i].content_type) && | |
| 394 resource_identifier == NO_IDENTIFIER) { | |
| 395 resource_identifier = WILDCARD; | |
| 396 LOG(WARNING) << "Managed content settings for " | |
| 397 << original_pattern_str << ": Content type " | |
| 398 << kPrefsForManagedContentSettingsMap[i].content_type | |
| 399 << " requires a resource identifer, but none was" | |
| 400 << "specified. Useing resource identifier wildcard."; | |
| 401 } | |
| 402 | |
| 403 // TODO(markusheintz): If a resource identifier is not required but | |
| 404 // specified, collapse the rules for different resource identifiers into | |
| 405 // one single rule and use the most restrictive content setting. | |
| 406 if (!RequiresResourceIdentifier( | |
| 407 kPrefsForManagedContentSettingsMap[i].content_type) && | |
| 408 resource_identifier != NO_IDENTIFIER) { | |
| 409 // Ignore rule for now. | |
| 410 LOG(WARNING) << "Ignoring content settings pattern " | |
| 411 << original_pattern_str | |
| 412 << " because a resource identifier is given but not" | |
| 413 << " required"; | |
| 414 continue; | |
| 415 } | |
| 416 | |
| 417 ContentSettingsPattern pattern(original_pattern_str); | |
| 418 if (!pattern.IsValid()) { | |
| 419 // Ignore invalid patterns | |
| 420 LOG(WARNING) << "Ignoring invalid content settings pattern: " | |
| 421 << pattern.AsString(); | |
| 422 } else { | |
| 423 rules.push_back(MakeTuple( | |
| 424 pattern, | |
| 425 pattern, | |
| 426 kPrefsForManagedContentSettingsMap[i].content_type, | |
| 427 resource_identifier, | |
| 428 kPrefsForManagedContentSettingsMap[i].setting)); | |
| 429 } | |
| 430 } | |
| 431 } | |
| 432 | |
| 433 // Perform wildcard expansions for CONTENT_SETTINGS_TYPE_PLUGINS. | |
| 434 ContentSettingsRules rules_to_add; | |
| 435 for (ContentSettingsRules::iterator rule = rules.begin(); | |
| 436 rule != rules.end();) { | |
| 437 if ((*rule).c == CONTENT_SETTINGS_TYPE_PLUGINS && | |
|
Bernhard Bauer
2011/02/23 13:18:53
Nit: |rule->c| et al.
markusheintz_
2011/02/23 18:42:09
Obsolete now.
| |
| 438 (*rule).d == WILDCARD) { | |
| 439 // Expand wildcard resource_identifier | |
| 440 // TODO(markusheintz): Must not be called on the UI THREAD | |
| 441 webkit::npapi::PluginList* plugin_list = | |
| 442 webkit::npapi::PluginList::Singleton(); | |
| 443 std::vector<webkit::npapi::PluginGroup> plugin_groups; | |
| 444 plugin_list->GetPluginGroups(true, &plugin_groups); | |
|
Bernhard Bauer
2011/02/23 13:18:53
As discussed offline, we should do this with a di
markusheintz_
2011/02/23 18:42:09
Agree.
| |
| 445 for (std::vector<webkit::npapi::PluginGroup>::iterator plugin_group = plug in_groups.begin(); | |
| 446 plugin_group != plugin_groups.end(); | |
| 447 ++plugin_group) { | |
| 448 rules_to_add.push_back(MakeTuple( | |
| 449 (*rule).a, | |
| 450 (*rule).b, | |
| 451 (*rule).c, | |
| 452 plugin_group->identifier(), | |
| 453 (*rule).e)); | |
| 454 LOG(WARNING) << "Adding rule: (" | |
| 455 << (*rule).a << ", " | |
| 456 << (*rule).b << ", " | |
| 457 << (*rule).c << ", " | |
| 458 << plugin_group->identifier() << ", " | |
| 459 << (*rule).e <<")"; | |
| 460 } | |
| 461 | |
| 462 // Remove expanded rule and increment iterator. | |
| 463 rule = rules.erase(rule); | |
| 464 } else { | |
| 465 ++rule; | |
| 466 } | |
| 467 } | |
| 468 rules.insert(rules.end(), rules_to_add.begin(), rules_to_add.end()); | |
| 469 | |
| 470 // Update the host_content_settings; | |
| 471 { | |
| 472 base::AutoLock(lock()); | |
| 473 HostContentSettings* content_settings_map = host_content_settings(); | |
| 474 if (overwrite) | |
| 475 content_settings_map->clear(); | |
| 476 | |
| 477 for (ContentSettingsRules::iterator rule = rules.begin(); | |
| 478 rule != rules.end(); | |
| 479 ++rule) { | |
| 480 DispatchToMethod(this, &PolicyProvider::UpdateContentSettingsMap, *rule); | |
| 481 } | |
| 482 } | |
| 483 } | |
| 484 | |
| 485 // Since the PolicyProvider is a read only content settings provider, all | |
| 486 // methodes of the ProviderInterface that set or delete any settings do nothing. | |
| 487 void PolicyProvider::SetContentSetting( | |
| 488 const ContentSettingsPattern& requesting_pattern, | |
| 489 const ContentSettingsPattern& embedding_pattern, | |
| 490 ContentSettingsType content_type, | |
| 491 const ResourceIdentifier& resource_identifier, | |
| 492 ContentSetting content_setting) { | |
| 493 } | |
| 494 | |
| 495 void PolicyProvider::ClearAllContentSettingsRules( | |
| 496 ContentSettingsType content_type) { | |
| 497 } | |
| 498 | |
| 499 void PolicyProvider::ResetToDefaults() { | |
| 500 } | |
| 501 | |
| 502 void PolicyProvider::UnregisterObservers() { | |
| 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 504 if (!profile_) | |
| 505 return; | |
| 506 pref_change_registrar_.RemoveAll(); | |
| 507 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | |
| 508 Source<Profile>(profile_)); | |
| 509 profile_ = NULL; | |
| 510 } | |
| 511 | |
| 512 void PolicyProvider::NotifyObservers( | |
| 513 const ContentSettingsDetails& details) { | |
| 514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 515 if (profile_ == NULL) | |
| 516 return; | |
| 517 NotificationService::current()->Notify( | |
| 518 NotificationType::CONTENT_SETTINGS_CHANGED, | |
| 519 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | |
| 520 Details<const ContentSettingsDetails>(&details)); | |
| 521 } | |
| 522 | |
| 523 void PolicyProvider::Observe(NotificationType type, | |
| 524 const NotificationSource& source, | |
| 525 const NotificationDetails& details) { | |
| 526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 527 | |
| 528 if (type == NotificationType::PREF_CHANGED) { | |
| 529 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | |
| 530 std::string* name = Details<std::string>(details).ptr(); | |
| 531 if (*name == prefs::kManagedCookiesAllowedForUrls) { | |
| 532 ReadManagedContentSettings(true); | |
| 533 } else if (*name == prefs::kManagedCookiesBlockedForUrls) { | |
|
Bernhard Bauer
2011/02/23 13:18:53
Collapse these into one big expression?
markusheintz_
2011/02/23 18:42:09
Done.
| |
| 534 ReadManagedContentSettings(true); | |
| 535 } else if (*name == prefs::kManagedCookiesSessionOnlyForUrls) { | |
| 536 ReadManagedContentSettings(true); | |
| 537 } else if (*name == prefs::kManagedImagesAllowedForUrls) { | |
| 538 ReadManagedContentSettings(true); | |
| 539 } else if (*name == prefs::kManagedImagesBlockedForUrls) { | |
| 540 ReadManagedContentSettings(true); | |
| 541 } else if (*name == prefs::kManagedJavaScriptAllowedForUrls) { | |
| 542 ReadManagedContentSettings(true); | |
| 543 } else if (*name == prefs::kManagedJavaScriptBlockedForUrls) { | |
| 544 ReadManagedContentSettings(true); | |
| 545 } else if (*name == prefs::kManagedPluginsAllowedForUrls) { | |
| 546 ReadManagedContentSettings(true); | |
| 547 } else if (*name == prefs::kManagedPluginsBlockedForUrls) { | |
| 548 ReadManagedContentSettings(true); | |
| 549 } else if (*name == prefs::kManagedPluginsAskForUrls) { | |
| 550 ReadManagedContentSettings(true); | |
| 551 } else if (*name == prefs::kManagedPopupsAllowedForUrls) { | |
| 552 ReadManagedContentSettings(true); | |
| 553 } else if (*name == prefs::kManagedPopupsBlockedForUrls) { | |
| 554 ReadManagedContentSettings(true); | |
| 555 } else if (*name == prefs::kManagedDefaultCookiesSetting) { | |
| 556 ReadManagedContentSettingsTypes(CONTENT_SETTINGS_TYPE_COOKIES); | |
| 557 } else if (*name == prefs::kManagedDefaultImagesSetting) { | |
| 558 ReadManagedContentSettingsTypes(CONTENT_SETTINGS_TYPE_IMAGES); | |
| 559 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { | |
| 560 ReadManagedContentSettingsTypes(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | |
| 561 } else if (*name == prefs::kManagedDefaultPluginsSetting) { | |
| 562 ReadManagedContentSettingsTypes(CONTENT_SETTINGS_TYPE_PLUGINS); | |
| 563 } else if (*name == prefs::kManagedDefaultPopupsSetting) { | |
| 564 ReadManagedContentSettingsTypes(CONTENT_SETTINGS_TYPE_POPUPS); | |
| 565 } | |
| 566 | |
| 567 NotifyObservers(ContentSettingsDetails( | |
| 568 ContentSettingsPattern(), CONTENT_SETTINGS_TYPE_DEFAULT, "")); | |
| 569 } else if (type == NotificationType::PROFILE_DESTROYED) { | |
| 570 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | |
| 571 UnregisterObservers(); | |
| 572 } else { | |
| 573 NOTREACHED() << "Unexpected notification"; | |
| 574 } | |
| 575 } | |
| 576 | |
| 198 } // namespace content_settings | 577 } // namespace content_settings |
| OLD | NEW |