| 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 "chrome/browser/content_settings/content_settings_details.h" | 11 #include "chrome/browser/content_settings/content_settings_details.h" |
| 12 #include "chrome/browser/content_settings/content_settings_pattern.h" | 12 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 13 #include "chrome/browser/content_settings/content_settings_utils.h" | 13 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
| 20 #include "content/common/notification_details.h" | |
| 21 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
| 22 #include "content/common/notification_source.h" | 21 #include "content/common/notification_source.h" |
| 23 #include "webkit/plugins/npapi/plugin_group.h" | 22 #include "webkit/plugins/npapi/plugin_group.h" |
| 24 #include "webkit/plugins/npapi/plugin_list.h" | 23 #include "webkit/plugins/npapi/plugin_list.h" |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 | 26 |
| 28 // 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 |
| 29 // settings values. | 28 // settings values. |
| 30 const std::string kManagedSettings = | 29 const std::string kManagedSettings = |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 prefs->RegisterListPref(prefs::kManagedPluginsAllowedForUrls, | 269 prefs->RegisterListPref(prefs::kManagedPluginsAllowedForUrls, |
| 271 PrefService::UNSYNCABLE_PREF); | 270 PrefService::UNSYNCABLE_PREF); |
| 272 prefs->RegisterListPref(prefs::kManagedPluginsBlockedForUrls, | 271 prefs->RegisterListPref(prefs::kManagedPluginsBlockedForUrls, |
| 273 PrefService::UNSYNCABLE_PREF); | 272 PrefService::UNSYNCABLE_PREF); |
| 274 prefs->RegisterListPref(prefs::kManagedPopupsAllowedForUrls, | 273 prefs->RegisterListPref(prefs::kManagedPopupsAllowedForUrls, |
| 275 PrefService::UNSYNCABLE_PREF); | 274 PrefService::UNSYNCABLE_PREF); |
| 276 prefs->RegisterListPref(prefs::kManagedPopupsBlockedForUrls, | 275 prefs->RegisterListPref(prefs::kManagedPopupsBlockedForUrls, |
| 277 PrefService::UNSYNCABLE_PREF); | 276 PrefService::UNSYNCABLE_PREF); |
| 278 } | 277 } |
| 279 | 278 |
| 280 PolicyProvider::PolicyProvider(HostContentSettingsMap* map, | 279 PolicyProvider::PolicyProvider(PrefService* prefs, |
| 281 PrefService* prefs, | |
| 282 DefaultProviderInterface* default_provider) | 280 DefaultProviderInterface* default_provider) |
| 283 : host_content_settings_map_(map), | 281 : prefs_(prefs), |
| 284 prefs_(prefs), | |
| 285 default_provider_(default_provider) { | 282 default_provider_(default_provider) { |
| 286 ReadManagedContentSettings(false); | 283 ReadManagedContentSettings(false); |
| 287 | 284 |
| 288 pref_change_registrar_.Init(prefs_); | 285 pref_change_registrar_.Init(prefs_); |
| 289 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); | 286 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); |
| 290 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); | 287 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); |
| 291 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); | 288 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); |
| 292 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); | 289 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); |
| 293 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); | 290 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); |
| 294 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); | 291 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } | 418 } |
| 422 } | 419 } |
| 423 } | 420 } |
| 424 | 421 |
| 425 void PolicyProvider::ClearAllContentSettingsRules( | 422 void PolicyProvider::ClearAllContentSettingsRules( |
| 426 ContentSettingsType content_type) { | 423 ContentSettingsType content_type) { |
| 427 } | 424 } |
| 428 | 425 |
| 429 void PolicyProvider::ShutdownOnUIThread() { | 426 void PolicyProvider::ShutdownOnUIThread() { |
| 430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 428 RemoveAllObservers(); |
| 431 if (!prefs_) | 429 if (!prefs_) |
| 432 return; | 430 return; |
| 433 pref_change_registrar_.RemoveAll(); | 431 pref_change_registrar_.RemoveAll(); |
| 434 prefs_ = NULL; | 432 prefs_ = NULL; |
| 435 host_content_settings_map_ = NULL; | |
| 436 } | |
| 437 | |
| 438 void PolicyProvider::NotifyObservers( | |
| 439 const ContentSettingsDetails& details) { | |
| 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 441 if (host_content_settings_map_ == NULL) | |
| 442 return; | |
| 443 NotificationService::current()->Notify( | |
| 444 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, | |
| 445 Source<HostContentSettingsMap>(host_content_settings_map_), | |
| 446 Details<const ContentSettingsDetails>(&details)); | |
| 447 } | 433 } |
| 448 | 434 |
| 449 void PolicyProvider::Observe(int type, | 435 void PolicyProvider::Observe(int type, |
| 450 const NotificationSource& source, | 436 const NotificationSource& source, |
| 451 const NotificationDetails& details) { | 437 const NotificationDetails& details) { |
| 452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 453 | 439 |
| 454 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 440 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 455 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); | 441 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
| 456 std::string* name = Details<std::string>(details).ptr(); | 442 std::string* name = Details<std::string>(details).ptr(); |
| 457 if (*name == prefs::kManagedCookiesAllowedForUrls || | 443 if (*name == prefs::kManagedCookiesAllowedForUrls || |
| 458 *name == prefs::kManagedCookiesBlockedForUrls || | 444 *name == prefs::kManagedCookiesBlockedForUrls || |
| 459 *name == prefs::kManagedCookiesSessionOnlyForUrls || | 445 *name == prefs::kManagedCookiesSessionOnlyForUrls || |
| 460 *name == prefs::kManagedImagesAllowedForUrls || | 446 *name == prefs::kManagedImagesAllowedForUrls || |
| 461 *name == prefs::kManagedImagesBlockedForUrls || | 447 *name == prefs::kManagedImagesBlockedForUrls || |
| 462 *name == prefs::kManagedJavaScriptAllowedForUrls || | 448 *name == prefs::kManagedJavaScriptAllowedForUrls || |
| 463 *name == prefs::kManagedJavaScriptBlockedForUrls || | 449 *name == prefs::kManagedJavaScriptBlockedForUrls || |
| 464 *name == prefs::kManagedPluginsAllowedForUrls || | 450 *name == prefs::kManagedPluginsAllowedForUrls || |
| 465 *name == prefs::kManagedPluginsBlockedForUrls || | 451 *name == prefs::kManagedPluginsBlockedForUrls || |
| 466 *name == prefs::kManagedPopupsAllowedForUrls || | 452 *name == prefs::kManagedPopupsAllowedForUrls || |
| 467 *name == prefs::kManagedPopupsBlockedForUrls) { | 453 *name == prefs::kManagedPopupsBlockedForUrls) { |
| 468 ReadManagedContentSettings(true); | 454 ReadManagedContentSettings(true); |
| 469 ContentSettingsDetails details(ContentSettingsPattern(), | 455 NotifyObservers(ContentSettingsPattern(), |
| 470 ContentSettingsPattern(), | 456 ContentSettingsPattern(), |
| 471 CONTENT_SETTINGS_TYPE_DEFAULT, | 457 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 472 std::string()); | 458 std::string()); |
| 473 NotifyObservers(details); | |
| 474 } | 459 } |
| 475 } else { | 460 } else { |
| 476 NOTREACHED() << "Unexpected notification"; | 461 NOTREACHED() << "Unexpected notification"; |
| 477 } | 462 } |
| 478 } | 463 } |
| 479 | 464 |
| 480 } // namespace content_settings | 465 } // namespace content_settings |
| OLD | NEW |