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/policy_content_settings_provider.h" | 5 #include "chrome/browser/content_settings/policy_content_settings_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 "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 prefs::kManagedDefaultImagesSetting, | 31 prefs::kManagedDefaultImagesSetting, |
| 32 prefs::kManagedDefaultJavaScriptSetting, | 32 prefs::kManagedDefaultJavaScriptSetting, |
| 33 prefs::kManagedDefaultPluginsSetting, | 33 prefs::kManagedDefaultPluginsSetting, |
| 34 prefs::kManagedDefaultPopupsSetting, | 34 prefs::kManagedDefaultPopupsSetting, |
| 35 NULL, // Not used for Geolocation | 35 NULL, // Not used for Geolocation |
| 36 NULL, // Not used for Notifications | 36 NULL, // Not used for Notifications |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 PolicyContentSettingsProvider::PolicyContentSettingsProvider(Profile* profile) | 41 namespace content_settings { |
| 42 : profile_(profile), | 42 |
| 43 is_off_the_record_(profile_->IsOffTheRecord()) { | 43 PolicyDefaultContentSettingsProvider::PolicyDefaultContentSettingsProvider( |
| 44 Profile* profile) | |
| 45 : profile_(profile), | |
|
Bernhard Bauer
2011/01/27 09:54:26
Indent only four spaces in total here as well.
markusheintz_
2011/01/27 10:24:37
Done.
| |
| 46 is_off_the_record_(profile_->IsOffTheRecord()) { | |
| 44 PrefService* prefs = profile->GetPrefs(); | 47 PrefService* prefs = profile->GetPrefs(); |
| 45 | 48 |
| 46 // Read global defaults. | 49 // Read global defaults. |
| 47 DCHECK_EQ(arraysize(kPrefToManageType), | 50 DCHECK_EQ(arraysize(kPrefToManageType), |
| 48 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); | 51 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); |
| 49 ReadManagedDefaultSettings(); | 52 ReadManagedDefaultSettings(); |
| 50 | 53 |
| 51 pref_change_registrar_.Init(prefs); | 54 pref_change_registrar_.Init(prefs); |
| 52 // The following preferences are only used to indicate if a | 55 // The following preferences are only used to indicate if a |
| 53 // default-content-setting is managed and to hold the managed default-setting | 56 // default-content-setting is managed and to hold the managed default-setting |
| 54 // value. If the value for any of the following perferences is set then the | 57 // value. If the value for any of the following perferences is set then the |
| 55 // corresponding default-content-setting is managed. These preferences exist | 58 // corresponding default-content-setting is managed. These preferences exist |
| 56 // in parallel to the preference default-content-settings. If a | 59 // in parallel to the preference default-content-settings. If a |
| 57 // default-content-settings-type is managed any user defined excpetions | 60 // default-content-settings-type is managed any user defined excpetions |
| 58 // (patterns) for this type are ignored. | 61 // (patterns) for this type are ignored. |
| 59 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); | 62 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); |
| 60 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); | 63 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); |
| 61 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); | 64 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); |
| 62 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); | 65 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); |
| 63 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); | 66 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); |
| 64 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 67 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
| 65 Source<Profile>(profile_)); | 68 Source<Profile>(profile_)); |
| 66 } | 69 } |
| 67 | 70 |
| 68 PolicyContentSettingsProvider::~PolicyContentSettingsProvider() { | 71 PolicyDefaultContentSettingsProvider::~PolicyDefaultContentSettingsProvider() { |
| 69 UnregisterObservers(); | 72 UnregisterObservers(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 bool PolicyContentSettingsProvider::CanProvideDefaultSetting( | 75 bool PolicyDefaultContentSettingsProvider::CanProvideDefaultSetting( |
| 73 ContentSettingsType content_type) const { | 76 ContentSettingsType content_type) const { |
| 74 base::AutoLock lock(lock_); | 77 base::AutoLock lock(lock_); |
| 75 if (managed_default_content_settings_.settings[content_type] != | 78 if (managed_default_content_settings_.settings[content_type] != |
| 76 CONTENT_SETTING_DEFAULT) { | 79 CONTENT_SETTING_DEFAULT) { |
| 77 return true; | 80 return true; |
| 78 } else { | 81 } else { |
| 79 return false; | 82 return false; |
| 80 } | 83 } |
| 81 } | 84 } |
| 82 | 85 |
| 83 ContentSetting PolicyContentSettingsProvider::ProvideDefaultSetting( | 86 ContentSetting PolicyDefaultContentSettingsProvider::ProvideDefaultSetting( |
| 84 ContentSettingsType content_type) const { | 87 ContentSettingsType content_type) const { |
| 85 base::AutoLock auto_lock(lock_); | 88 base::AutoLock auto_lock(lock_); |
| 86 return managed_default_content_settings_.settings[content_type]; | 89 return managed_default_content_settings_.settings[content_type]; |
| 87 } | 90 } |
| 88 | 91 |
| 89 void PolicyContentSettingsProvider::UpdateDefaultSetting( | 92 void PolicyDefaultContentSettingsProvider::UpdateDefaultSetting( |
| 90 ContentSettingsType content_type, | 93 ContentSettingsType content_type, |
| 91 ContentSetting setting) { | 94 ContentSetting setting) { |
| 92 } | 95 } |
| 93 | 96 |
| 94 bool PolicyContentSettingsProvider::DefaultSettingIsManaged( | 97 bool PolicyDefaultContentSettingsProvider::DefaultSettingIsManaged( |
| 95 ContentSettingsType content_type) const { | 98 ContentSettingsType content_type) const { |
| 96 base::AutoLock lock(lock_); | 99 base::AutoLock lock(lock_); |
| 97 if (managed_default_content_settings_.settings[content_type] != | 100 if (managed_default_content_settings_.settings[content_type] != |
| 98 CONTENT_SETTING_DEFAULT) { | 101 CONTENT_SETTING_DEFAULT) { |
| 99 return true; | 102 return true; |
| 100 } else { | 103 } else { |
| 101 return false; | 104 return false; |
| 102 } | 105 } |
| 103 } | 106 } |
| 104 | 107 |
| 105 void PolicyContentSettingsProvider::ResetToDefaults() { | 108 void PolicyDefaultContentSettingsProvider::ResetToDefaults() { |
| 106 } | 109 } |
| 107 | 110 |
| 108 void PolicyContentSettingsProvider::Observe(NotificationType type, | 111 void PolicyDefaultContentSettingsProvider::Observe(NotificationType type, |
| 109 const NotificationSource& source, | 112 const NotificationSource& source, |
| 110 const NotificationDetails& details) { | 113 const NotificationDetails& details) { |
| 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 112 | 115 |
| 113 if (type == NotificationType::PREF_CHANGED) { | 116 if (type == NotificationType::PREF_CHANGED) { |
| 114 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 117 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); |
| 115 std::string* name = Details<std::string>(details).ptr(); | 118 std::string* name = Details<std::string>(details).ptr(); |
| 116 if (*name == prefs::kManagedDefaultCookiesSetting) { | 119 if (*name == prefs::kManagedDefaultCookiesSetting) { |
| 117 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES); | 120 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES); |
| 118 } else if (*name == prefs::kManagedDefaultImagesSetting) { | 121 } else if (*name == prefs::kManagedDefaultImagesSetting) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 133 ContentSettingsPattern(), CONTENT_SETTINGS_TYPE_DEFAULT, "")); | 136 ContentSettingsPattern(), CONTENT_SETTINGS_TYPE_DEFAULT, "")); |
| 134 } | 137 } |
| 135 } else if (type == NotificationType::PROFILE_DESTROYED) { | 138 } else if (type == NotificationType::PROFILE_DESTROYED) { |
| 136 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | 139 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); |
| 137 UnregisterObservers(); | 140 UnregisterObservers(); |
| 138 } else { | 141 } else { |
| 139 NOTREACHED() << "Unexpected notification"; | 142 NOTREACHED() << "Unexpected notification"; |
| 140 } | 143 } |
| 141 } | 144 } |
| 142 | 145 |
| 143 void PolicyContentSettingsProvider::UnregisterObservers() { | 146 void PolicyDefaultContentSettingsProvider::UnregisterObservers() { |
| 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 145 if (!profile_) | 148 if (!profile_) |
| 146 return; | 149 return; |
| 147 pref_change_registrar_.RemoveAll(); | 150 pref_change_registrar_.RemoveAll(); |
| 148 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 151 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, |
| 149 Source<Profile>(profile_)); | 152 Source<Profile>(profile_)); |
| 150 profile_ = NULL; | 153 profile_ = NULL; |
| 151 } | 154 } |
| 152 | 155 |
| 153 | 156 |
| 154 void PolicyContentSettingsProvider::NotifyObservers( | 157 void PolicyDefaultContentSettingsProvider::NotifyObservers( |
| 155 const ContentSettingsDetails& details) { | 158 const ContentSettingsDetails& details) { |
| 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 157 if (profile_ == NULL) | 160 if (profile_ == NULL) |
| 158 return; | 161 return; |
| 159 NotificationService::current()->Notify( | 162 NotificationService::current()->Notify( |
| 160 NotificationType::CONTENT_SETTINGS_CHANGED, | 163 NotificationType::CONTENT_SETTINGS_CHANGED, |
| 161 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 164 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), |
| 162 Details<const ContentSettingsDetails>(&details)); | 165 Details<const ContentSettingsDetails>(&details)); |
| 163 } | 166 } |
| 164 | 167 |
| 165 void PolicyContentSettingsProvider::ReadManagedDefaultSettings() { | 168 void PolicyDefaultContentSettingsProvider::ReadManagedDefaultSettings() { |
| 166 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { | 169 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { |
| 167 if (kPrefToManageType[type] == NULL) { | 170 if (kPrefToManageType[type] == NULL) { |
| 168 // TODO(markusheintz): Handle Geolocation and notification separately. | 171 // TODO(markusheintz): Handle Geolocation and notification separately. |
| 169 continue; | 172 continue; |
| 170 } | 173 } |
| 171 UpdateManagedDefaultSetting(ContentSettingsType(type)); | 174 UpdateManagedDefaultSetting(ContentSettingsType(type)); |
| 172 } | 175 } |
| 173 } | 176 } |
| 174 | 177 |
| 175 void PolicyContentSettingsProvider::UpdateManagedDefaultSetting( | 178 void PolicyDefaultContentSettingsProvider::UpdateManagedDefaultSetting( |
| 176 ContentSettingsType type) { | 179 ContentSettingsType type) { |
| 177 // If a pref to manage a default-content-setting was not set (NOTICE: | 180 // If a pref to manage a default-content-setting was not set (NOTICE: |
| 178 // "HasPrefPath" returns false if no value was set for a registered pref) then | 181 // "HasPrefPath" returns false if no value was set for a registered pref) then |
| 179 // the default value of the preference is used. The default value of a | 182 // the default value of the preference is used. The default value of a |
| 180 // preference to manage a default-content-settings is | 183 // preference to manage a default-content-settings is CONTENT_SETTING_DEFAULT. |
| 181 // CONTENT_SETTING_DEFAULT. This indicates that no managed value is set. If a | 184 // This indicates that no managed value is set. If a pref was set, than it |
| 182 // pref was set, than it MUST be managed. | 185 // MUST be managed. |
| 183 PrefService* prefs = profile_->GetPrefs(); | 186 PrefService* prefs = profile_->GetPrefs(); |
| 184 DCHECK(!prefs->HasPrefPath(kPrefToManageType[type]) || | 187 DCHECK(!prefs->HasPrefPath(kPrefToManageType[type]) || |
| 185 prefs->IsManagedPreference(kPrefToManageType[type])); | 188 prefs->IsManagedPreference(kPrefToManageType[type])); |
| 186 base::AutoLock auto_lock(lock_); | 189 base::AutoLock auto_lock(lock_); |
| 187 managed_default_content_settings_.settings[type] = IntToContentSetting( | 190 managed_default_content_settings_.settings[type] = IntToContentSetting( |
| 188 prefs->GetInteger(kPrefToManageType[type])); | 191 prefs->GetInteger(kPrefToManageType[type])); |
| 189 } | 192 } |
| 190 | 193 |
| 191 // static | 194 // static |
| 192 void PolicyContentSettingsProvider::RegisterUserPrefs(PrefService* prefs) { | 195 void PolicyDefaultContentSettingsProvider::RegisterUserPrefs( |
| 196 PrefService* prefs) { | |
| 193 // Preferences for default content setting policies. A policy is not set of | 197 // Preferences for default content setting policies. A policy is not set of |
| 194 // the corresponding preferences below is set to CONTENT_SETTING_DEFAULT. | 198 // the corresponding preferences below is set to CONTENT_SETTING_DEFAULT. |
| 195 prefs->RegisterIntegerPref(prefs::kManagedDefaultCookiesSetting, | 199 prefs->RegisterIntegerPref(prefs::kManagedDefaultCookiesSetting, |
| 196 CONTENT_SETTING_DEFAULT); | 200 CONTENT_SETTING_DEFAULT); |
| 197 prefs->RegisterIntegerPref(prefs::kManagedDefaultImagesSetting, | 201 prefs->RegisterIntegerPref(prefs::kManagedDefaultImagesSetting, |
| 198 CONTENT_SETTING_DEFAULT); | 202 CONTENT_SETTING_DEFAULT); |
| 199 prefs->RegisterIntegerPref(prefs::kManagedDefaultJavaScriptSetting, | 203 prefs->RegisterIntegerPref(prefs::kManagedDefaultJavaScriptSetting, |
| 200 CONTENT_SETTING_DEFAULT); | 204 CONTENT_SETTING_DEFAULT); |
| 201 prefs->RegisterIntegerPref(prefs::kManagedDefaultPluginsSetting, | 205 prefs->RegisterIntegerPref(prefs::kManagedDefaultPluginsSetting, |
| 202 CONTENT_SETTING_DEFAULT); | 206 CONTENT_SETTING_DEFAULT); |
| 203 prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting, | 207 prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting, |
| 204 CONTENT_SETTING_DEFAULT); | 208 CONTENT_SETTING_DEFAULT); |
| 205 } | 209 } |
| 210 | |
| 211 } // namespace content_settings | |
| OLD | NEW |