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/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_details.h" | 20 #include "content/common/notification_details.h" |
20 #include "content/common/notification_service.h" | 21 #include "content/common/notification_service.h" |
21 #include "content/common/notification_source.h" | 22 #include "content/common/notification_source.h" |
22 #include "webkit/plugins/npapi/plugin_group.h" | 23 #include "webkit/plugins/npapi/plugin_group.h" |
23 #include "webkit/plugins/npapi/plugin_list.h" | 24 #include "webkit/plugins/npapi/plugin_list.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // value. If the value for any of the following perferences is set then the | 116 // value. If the value for any of the following perferences is set then the |
116 // corresponding default-content-setting is managed. These preferences exist | 117 // corresponding default-content-setting is managed. These preferences exist |
117 // in parallel to the preference default-content-settings. If a | 118 // in parallel to the preference default-content-settings. If a |
118 // default-content-settings-type is managed any user defined excpetions | 119 // default-content-settings-type is managed any user defined excpetions |
119 // (patterns) for this type are ignored. | 120 // (patterns) for this type are ignored. |
120 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); | 121 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); |
121 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); | 122 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); |
122 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); | 123 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); |
123 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); | 124 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); |
124 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); | 125 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); |
125 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 126 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
126 Source<Profile>(profile_)); | 127 Source<Profile>(profile_)); |
127 } | 128 } |
128 | 129 |
129 PolicyDefaultProvider::~PolicyDefaultProvider() { | 130 PolicyDefaultProvider::~PolicyDefaultProvider() { |
130 UnregisterObservers(); | 131 UnregisterObservers(); |
131 } | 132 } |
132 | 133 |
133 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting( | 134 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting( |
134 ContentSettingsType content_type) const { | 135 ContentSettingsType content_type) const { |
135 base::AutoLock auto_lock(lock_); | 136 base::AutoLock auto_lock(lock_); |
136 return managed_default_content_settings_.settings[content_type]; | 137 return managed_default_content_settings_.settings[content_type]; |
137 } | 138 } |
138 | 139 |
139 void PolicyDefaultProvider::UpdateDefaultSetting( | 140 void PolicyDefaultProvider::UpdateDefaultSetting( |
140 ContentSettingsType content_type, | 141 ContentSettingsType content_type, |
141 ContentSetting setting) { | 142 ContentSetting setting) { |
142 } | 143 } |
143 | 144 |
144 bool PolicyDefaultProvider::DefaultSettingIsManaged( | 145 bool PolicyDefaultProvider::DefaultSettingIsManaged( |
145 ContentSettingsType content_type) const { | 146 ContentSettingsType content_type) const { |
146 base::AutoLock lock(lock_); | 147 base::AutoLock lock(lock_); |
147 if (managed_default_content_settings_.settings[content_type] != | 148 if (managed_default_content_settings_.settings[content_type] != |
148 CONTENT_SETTING_DEFAULT) { | 149 CONTENT_SETTING_DEFAULT) { |
149 return true; | 150 return true; |
150 } else { | 151 } else { |
151 return false; | 152 return false; |
152 } | 153 } |
153 } | 154 } |
154 | 155 |
155 void PolicyDefaultProvider::Observe(NotificationType type, | 156 void PolicyDefaultProvider::Observe(int type, |
156 const NotificationSource& source, | 157 const NotificationSource& source, |
157 const NotificationDetails& details) { | 158 const NotificationDetails& details) { |
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
159 | 160 |
160 if (type == NotificationType::PREF_CHANGED) { | 161 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
161 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 162 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); |
162 std::string* name = Details<std::string>(details).ptr(); | 163 std::string* name = Details<std::string>(details).ptr(); |
163 if (*name == prefs::kManagedDefaultCookiesSetting) { | 164 if (*name == prefs::kManagedDefaultCookiesSetting) { |
164 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES); | 165 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES); |
165 } else if (*name == prefs::kManagedDefaultImagesSetting) { | 166 } else if (*name == prefs::kManagedDefaultImagesSetting) { |
166 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_IMAGES); | 167 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_IMAGES); |
167 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { | 168 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { |
168 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | 169 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
169 } else if (*name == prefs::kManagedDefaultPluginsSetting) { | 170 } else if (*name == prefs::kManagedDefaultPluginsSetting) { |
170 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS); | 171 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS); |
171 } else if (*name == prefs::kManagedDefaultPopupsSetting) { | 172 } else if (*name == prefs::kManagedDefaultPopupsSetting) { |
172 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS); | 173 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS); |
173 } else { | 174 } else { |
174 NOTREACHED() << "Unexpected preference observed"; | 175 NOTREACHED() << "Unexpected preference observed"; |
175 return; | 176 return; |
176 } | 177 } |
177 | 178 |
178 if (!is_off_the_record_) { | 179 if (!is_off_the_record_) { |
179 ContentSettingsDetails details(ContentSettingsPattern(), | 180 ContentSettingsDetails details(ContentSettingsPattern(), |
180 ContentSettingsPattern(), | 181 ContentSettingsPattern(), |
181 CONTENT_SETTINGS_TYPE_DEFAULT, | 182 CONTENT_SETTINGS_TYPE_DEFAULT, |
182 std::string()); | 183 std::string()); |
183 NotifyObservers(details); | 184 NotifyObservers(details); |
184 } | 185 } |
185 } else if (type == NotificationType::PROFILE_DESTROYED) { | 186 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { |
186 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | 187 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); |
187 UnregisterObservers(); | 188 UnregisterObservers(); |
188 } else { | 189 } else { |
189 NOTREACHED() << "Unexpected notification"; | 190 NOTREACHED() << "Unexpected notification"; |
190 } | 191 } |
191 } | 192 } |
192 | 193 |
193 void PolicyDefaultProvider::UnregisterObservers() { | 194 void PolicyDefaultProvider::UnregisterObservers() { |
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
195 if (!profile_) | 196 if (!profile_) |
196 return; | 197 return; |
197 pref_change_registrar_.RemoveAll(); | 198 pref_change_registrar_.RemoveAll(); |
198 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 199 notification_registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
199 Source<Profile>(profile_)); | 200 Source<Profile>(profile_)); |
200 profile_ = NULL; | 201 profile_ = NULL; |
201 } | 202 } |
202 | 203 |
203 | 204 |
204 void PolicyDefaultProvider::NotifyObservers( | 205 void PolicyDefaultProvider::NotifyObservers( |
205 const ContentSettingsDetails& details) { | 206 const ContentSettingsDetails& details) { |
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
207 if (profile_ == NULL) | 208 if (profile_ == NULL) |
208 return; | 209 return; |
209 NotificationService::current()->Notify( | 210 NotificationService::current()->Notify( |
210 NotificationType::CONTENT_SETTINGS_CHANGED, | 211 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
211 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 212 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), |
212 Details<const ContentSettingsDetails>(&details)); | 213 Details<const ContentSettingsDetails>(&details)); |
213 } | 214 } |
214 | 215 |
215 void PolicyDefaultProvider::ReadManagedDefaultSettings() { | 216 void PolicyDefaultProvider::ReadManagedDefaultSettings() { |
216 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { | 217 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { |
217 if (kPrefToManageType[type] == NULL) { | 218 if (kPrefToManageType[type] == NULL) { |
218 continue; | 219 continue; |
219 } | 220 } |
220 UpdateManagedDefaultSetting(ContentSettingsType(type)); | 221 UpdateManagedDefaultSetting(ContentSettingsType(type)); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); | 310 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); |
310 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); | 311 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); |
311 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); | 312 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); |
312 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); | 313 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); |
313 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); | 314 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); |
314 pref_change_registrar_.Add(prefs::kManagedPluginsBlockedForUrls, this); | 315 pref_change_registrar_.Add(prefs::kManagedPluginsBlockedForUrls, this); |
315 pref_change_registrar_.Add(prefs::kManagedPluginsAllowedForUrls, this); | 316 pref_change_registrar_.Add(prefs::kManagedPluginsAllowedForUrls, this); |
316 pref_change_registrar_.Add(prefs::kManagedPopupsBlockedForUrls, this); | 317 pref_change_registrar_.Add(prefs::kManagedPopupsBlockedForUrls, this); |
317 pref_change_registrar_.Add(prefs::kManagedPopupsAllowedForUrls, this); | 318 pref_change_registrar_.Add(prefs::kManagedPopupsAllowedForUrls, this); |
318 | 319 |
319 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 320 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
320 Source<Profile>(profile_)); | 321 Source<Profile>(profile_)); |
321 } | 322 } |
322 | 323 |
323 void PolicyProvider::GetContentSettingsFromPreferences( | 324 void PolicyProvider::GetContentSettingsFromPreferences( |
324 PrefService* prefs, | 325 PrefService* prefs, |
325 ContentSettingsRules* rules) { | 326 ContentSettingsRules* rules) { |
326 for (size_t i = 0; i < arraysize(kPrefsForManagedContentSettingsMap); ++i) { | 327 for (size_t i = 0; i < arraysize(kPrefsForManagedContentSettingsMap); ++i) { |
327 const char* pref_name = kPrefsForManagedContentSettingsMap[i].pref_name; | 328 const char* pref_name = kPrefsForManagedContentSettingsMap[i].pref_name; |
328 // Skip unset policies. | 329 // Skip unset policies. |
329 if (!prefs->HasPrefPath(pref_name)) { | 330 if (!prefs->HasPrefPath(pref_name)) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 | 441 |
441 void PolicyProvider::ClearAllContentSettingsRules( | 442 void PolicyProvider::ClearAllContentSettingsRules( |
442 ContentSettingsType content_type) { | 443 ContentSettingsType content_type) { |
443 } | 444 } |
444 | 445 |
445 void PolicyProvider::UnregisterObservers() { | 446 void PolicyProvider::UnregisterObservers() { |
446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
447 if (!profile_) | 448 if (!profile_) |
448 return; | 449 return; |
449 pref_change_registrar_.RemoveAll(); | 450 pref_change_registrar_.RemoveAll(); |
450 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 451 notification_registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
451 Source<Profile>(profile_)); | 452 Source<Profile>(profile_)); |
452 profile_ = NULL; | 453 profile_ = NULL; |
453 } | 454 } |
454 | 455 |
455 void PolicyProvider::NotifyObservers( | 456 void PolicyProvider::NotifyObservers( |
456 const ContentSettingsDetails& details) { | 457 const ContentSettingsDetails& details) { |
457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
458 if (profile_ == NULL) | 459 if (profile_ == NULL) |
459 return; | 460 return; |
460 NotificationService::current()->Notify( | 461 NotificationService::current()->Notify( |
461 NotificationType::CONTENT_SETTINGS_CHANGED, | 462 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
462 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 463 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), |
463 Details<const ContentSettingsDetails>(&details)); | 464 Details<const ContentSettingsDetails>(&details)); |
464 } | 465 } |
465 | 466 |
466 void PolicyProvider::Observe(NotificationType type, | 467 void PolicyProvider::Observe(int type, |
467 const NotificationSource& source, | 468 const NotificationSource& source, |
468 const NotificationDetails& details) { | 469 const NotificationDetails& details) { |
469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
470 | 471 |
471 if (type == NotificationType::PREF_CHANGED) { | 472 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
472 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 473 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); |
473 std::string* name = Details<std::string>(details).ptr(); | 474 std::string* name = Details<std::string>(details).ptr(); |
474 if (*name == prefs::kManagedCookiesAllowedForUrls || | 475 if (*name == prefs::kManagedCookiesAllowedForUrls || |
475 *name == prefs::kManagedCookiesBlockedForUrls || | 476 *name == prefs::kManagedCookiesBlockedForUrls || |
476 *name == prefs::kManagedCookiesSessionOnlyForUrls || | 477 *name == prefs::kManagedCookiesSessionOnlyForUrls || |
477 *name == prefs::kManagedImagesAllowedForUrls || | 478 *name == prefs::kManagedImagesAllowedForUrls || |
478 *name == prefs::kManagedImagesBlockedForUrls || | 479 *name == prefs::kManagedImagesBlockedForUrls || |
479 *name == prefs::kManagedJavaScriptAllowedForUrls || | 480 *name == prefs::kManagedJavaScriptAllowedForUrls || |
480 *name == prefs::kManagedJavaScriptBlockedForUrls || | 481 *name == prefs::kManagedJavaScriptBlockedForUrls || |
481 *name == prefs::kManagedPluginsAllowedForUrls || | 482 *name == prefs::kManagedPluginsAllowedForUrls || |
482 *name == prefs::kManagedPluginsBlockedForUrls || | 483 *name == prefs::kManagedPluginsBlockedForUrls || |
483 *name == prefs::kManagedPopupsAllowedForUrls || | 484 *name == prefs::kManagedPopupsAllowedForUrls || |
484 *name == prefs::kManagedPopupsBlockedForUrls) { | 485 *name == prefs::kManagedPopupsBlockedForUrls) { |
485 ReadManagedContentSettings(true); | 486 ReadManagedContentSettings(true); |
486 ContentSettingsDetails details(ContentSettingsPattern(), | 487 ContentSettingsDetails details(ContentSettingsPattern(), |
487 ContentSettingsPattern(), | 488 ContentSettingsPattern(), |
488 CONTENT_SETTINGS_TYPE_DEFAULT, | 489 CONTENT_SETTINGS_TYPE_DEFAULT, |
489 std::string()); | 490 std::string()); |
490 NotifyObservers(details); | 491 NotifyObservers(details); |
491 } | 492 } |
492 } else if (type == NotificationType::PROFILE_DESTROYED) { | 493 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { |
493 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | 494 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); |
494 UnregisterObservers(); | 495 UnregisterObservers(); |
495 } else { | 496 } else { |
496 NOTREACHED() << "Unexpected notification"; | 497 NOTREACHED() << "Unexpected notification"; |
497 } | 498 } |
498 } | 499 } |
499 | 500 |
500 } // namespace content_settings | 501 } // namespace content_settings |
OLD | NEW |