| 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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 prefs::kManagedPopupsBlockedForUrls, | 92 prefs::kManagedPopupsBlockedForUrls, |
| 93 CONTENT_SETTINGS_TYPE_POPUPS, | 93 CONTENT_SETTINGS_TYPE_POPUPS, |
| 94 CONTENT_SETTING_BLOCK | 94 CONTENT_SETTING_BLOCK |
| 95 } | 95 } |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 } // namespace | 98 } // namespace |
| 99 | 99 |
| 100 namespace content_settings { | 100 namespace content_settings { |
| 101 | 101 |
| 102 PolicyDefaultProvider::PolicyDefaultProvider(Profile* profile) | 102 PolicyDefaultProvider::PolicyDefaultProvider(HostContentSettingsMap* map, |
| 103 : profile_(profile), | 103 PrefService* prefs) |
| 104 is_off_the_record_(profile_->IsOffTheRecord()) { | 104 : map_(map), |
| 105 PrefService* prefs = profile->GetPrefs(); | 105 prefs_(prefs) { |
| 106 | |
| 107 // Read global defaults. | 106 // Read global defaults. |
| 108 DCHECK_EQ(arraysize(kPrefToManageType), | 107 DCHECK_EQ(arraysize(kPrefToManageType), |
| 109 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); | 108 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); |
| 110 ReadManagedDefaultSettings(); | 109 ReadManagedDefaultSettings(); |
| 111 | 110 |
| 112 pref_change_registrar_.Init(prefs); | 111 pref_change_registrar_.Init(prefs_); |
| 113 // The following preferences are only used to indicate if a | 112 // The following preferences are only used to indicate if a |
| 114 // default-content-setting is managed and to hold the managed default-setting | 113 // default-content-setting is managed and to hold the managed default-setting |
| 115 // value. If the value for any of the following perferences is set then the | 114 // value. If the value for any of the following perferences is set then the |
| 116 // corresponding default-content-setting is managed. These preferences exist | 115 // corresponding default-content-setting is managed. These preferences exist |
| 117 // in parallel to the preference default-content-settings. If a | 116 // in parallel to the preference default-content-settings. If a |
| 118 // default-content-settings-type is managed any user defined excpetions | 117 // default-content-settings-type is managed any user defined excpetions |
| 119 // (patterns) for this type are ignored. | 118 // (patterns) for this type are ignored. |
| 120 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); | 119 pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this); |
| 121 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); | 120 pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this); |
| 122 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); | 121 pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this); |
| 123 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); | 122 pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this); |
| 124 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); | 123 pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this); |
| 125 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | |
| 126 Source<Profile>(profile_)); | |
| 127 } | 124 } |
| 128 | 125 |
| 129 PolicyDefaultProvider::~PolicyDefaultProvider() { | 126 PolicyDefaultProvider::~PolicyDefaultProvider() { |
| 130 UnregisterObservers(); | 127 DCHECK(!prefs_); |
| 131 } | 128 } |
| 132 | 129 |
| 133 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting( | 130 ContentSetting PolicyDefaultProvider::ProvideDefaultSetting( |
| 134 ContentSettingsType content_type) const { | 131 ContentSettingsType content_type) const { |
| 135 base::AutoLock auto_lock(lock_); | 132 base::AutoLock auto_lock(lock_); |
| 136 return managed_default_content_settings_.settings[content_type]; | 133 return managed_default_content_settings_.settings[content_type]; |
| 137 } | 134 } |
| 138 | 135 |
| 139 void PolicyDefaultProvider::UpdateDefaultSetting( | 136 void PolicyDefaultProvider::UpdateDefaultSetting( |
| 140 ContentSettingsType content_type, | 137 ContentSettingsType content_type, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 151 return false; | 148 return false; |
| 152 } | 149 } |
| 153 } | 150 } |
| 154 | 151 |
| 155 void PolicyDefaultProvider::Observe(NotificationType type, | 152 void PolicyDefaultProvider::Observe(NotificationType type, |
| 156 const NotificationSource& source, | 153 const NotificationSource& source, |
| 157 const NotificationDetails& details) { | 154 const NotificationDetails& details) { |
| 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 159 | 156 |
| 160 if (type == NotificationType::PREF_CHANGED) { | 157 if (type == NotificationType::PREF_CHANGED) { |
| 161 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 158 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
| 162 std::string* name = Details<std::string>(details).ptr(); | 159 std::string* name = Details<std::string>(details).ptr(); |
| 163 if (*name == prefs::kManagedDefaultCookiesSetting) { | 160 if (*name == prefs::kManagedDefaultCookiesSetting) { |
| 164 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES); | 161 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES); |
| 165 } else if (*name == prefs::kManagedDefaultImagesSetting) { | 162 } else if (*name == prefs::kManagedDefaultImagesSetting) { |
| 166 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_IMAGES); | 163 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_IMAGES); |
| 167 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { | 164 } else if (*name == prefs::kManagedDefaultJavaScriptSetting) { |
| 168 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | 165 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
| 169 } else if (*name == prefs::kManagedDefaultPluginsSetting) { | 166 } else if (*name == prefs::kManagedDefaultPluginsSetting) { |
| 170 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS); | 167 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 171 } else if (*name == prefs::kManagedDefaultPopupsSetting) { | 168 } else if (*name == prefs::kManagedDefaultPopupsSetting) { |
| 172 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS); | 169 UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS); |
| 173 } else { | 170 } else { |
| 174 NOTREACHED() << "Unexpected preference observed"; | 171 NOTREACHED() << "Unexpected preference observed"; |
| 175 return; | 172 return; |
| 176 } | 173 } |
| 177 | 174 |
| 178 if (!is_off_the_record_) { | 175 ContentSettingsDetails details(ContentSettingsPattern(), |
| 179 ContentSettingsDetails details(ContentSettingsPattern(), | 176 ContentSettingsPattern(), |
| 180 ContentSettingsPattern(), | 177 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 181 CONTENT_SETTINGS_TYPE_DEFAULT, | 178 std::string()); |
| 182 std::string()); | 179 NotifyObservers(details); |
| 183 NotifyObservers(details); | |
| 184 } | |
| 185 } else if (type == NotificationType::PROFILE_DESTROYED) { | |
| 186 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | |
| 187 UnregisterObservers(); | |
| 188 } else { | 180 } else { |
| 189 NOTREACHED() << "Unexpected notification"; | 181 NOTREACHED() << "Unexpected notification"; |
| 190 } | 182 } |
| 191 } | 183 } |
| 192 | 184 |
| 193 void PolicyDefaultProvider::UnregisterObservers() { | 185 void PolicyDefaultProvider::ShutdownOnUIThread() { |
| 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 195 if (!profile_) | 187 DCHECK(prefs_); |
| 196 return; | |
| 197 pref_change_registrar_.RemoveAll(); | 188 pref_change_registrar_.RemoveAll(); |
| 198 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 189 prefs_ = NULL; |
| 199 Source<Profile>(profile_)); | 190 map_ = NULL; |
| 200 profile_ = NULL; | |
| 201 } | 191 } |
| 202 | 192 |
| 203 | 193 |
| 204 void PolicyDefaultProvider::NotifyObservers( | 194 void PolicyDefaultProvider::NotifyObservers( |
| 205 const ContentSettingsDetails& details) { | 195 const ContentSettingsDetails& details) { |
| 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 207 if (profile_ == NULL) | 197 if (map_ == NULL) |
| 208 return; | 198 return; |
| 209 NotificationService::current()->Notify( | 199 NotificationService::current()->Notify( |
| 210 NotificationType::CONTENT_SETTINGS_CHANGED, | 200 NotificationType::CONTENT_SETTINGS_CHANGED, |
| 211 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 201 Source<HostContentSettingsMap>(map_), |
| 212 Details<const ContentSettingsDetails>(&details)); | 202 Details<const ContentSettingsDetails>(&details)); |
| 213 } | 203 } |
| 214 | 204 |
| 215 void PolicyDefaultProvider::ReadManagedDefaultSettings() { | 205 void PolicyDefaultProvider::ReadManagedDefaultSettings() { |
| 216 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { | 206 for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) { |
| 217 if (kPrefToManageType[type] == NULL) { | 207 if (kPrefToManageType[type] == NULL) { |
| 218 continue; | 208 continue; |
| 219 } | 209 } |
| 220 UpdateManagedDefaultSetting(ContentSettingsType(type)); | 210 UpdateManagedDefaultSetting(ContentSettingsType(type)); |
| 221 } | 211 } |
| 222 } | 212 } |
| 223 | 213 |
| 224 void PolicyDefaultProvider::UpdateManagedDefaultSetting( | 214 void PolicyDefaultProvider::UpdateManagedDefaultSetting( |
| 225 ContentSettingsType type) { | 215 ContentSettingsType type) { |
| 226 // If a pref to manage a default-content-setting was not set (NOTICE: | 216 // If a pref to manage a default-content-setting was not set (NOTICE: |
| 227 // "HasPrefPath" returns false if no value was set for a registered pref) then | 217 // "HasPrefPath" returns false if no value was set for a registered pref) then |
| 228 // the default value of the preference is used. The default value of a | 218 // the default value of the preference is used. The default value of a |
| 229 // preference to manage a default-content-settings is CONTENT_SETTING_DEFAULT. | 219 // preference to manage a default-content-settings is CONTENT_SETTING_DEFAULT. |
| 230 // This indicates that no managed value is set. If a pref was set, than it | 220 // This indicates that no managed value is set. If a pref was set, than it |
| 231 // MUST be managed. | 221 // MUST be managed. |
| 232 PrefService* prefs = profile_->GetPrefs(); | 222 DCHECK(!prefs_->HasPrefPath(kPrefToManageType[type]) || |
| 233 DCHECK(!prefs->HasPrefPath(kPrefToManageType[type]) || | 223 prefs_->IsManagedPreference(kPrefToManageType[type])); |
| 234 prefs->IsManagedPreference(kPrefToManageType[type])); | |
| 235 base::AutoLock auto_lock(lock_); | 224 base::AutoLock auto_lock(lock_); |
| 236 managed_default_content_settings_.settings[type] = IntToContentSetting( | 225 managed_default_content_settings_.settings[type] = IntToContentSetting( |
| 237 prefs->GetInteger(kPrefToManageType[type])); | 226 prefs_->GetInteger(kPrefToManageType[type])); |
| 238 } | 227 } |
| 239 | 228 |
| 240 // static | 229 // static |
| 241 void PolicyDefaultProvider::RegisterUserPrefs(PrefService* prefs) { | 230 void PolicyDefaultProvider::RegisterUserPrefs(PrefService* prefs) { |
| 242 // Preferences for default content setting policies. A policy is not set of | 231 // Preferences for default content setting policies. A policy is not set of |
| 243 // the corresponding preferences below is set to CONTENT_SETTING_DEFAULT. | 232 // the corresponding preferences below is set to CONTENT_SETTING_DEFAULT. |
| 244 prefs->RegisterIntegerPref(prefs::kManagedDefaultCookiesSetting, | 233 prefs->RegisterIntegerPref(prefs::kManagedDefaultCookiesSetting, |
| 245 CONTENT_SETTING_DEFAULT, | 234 CONTENT_SETTING_DEFAULT, |
| 246 PrefService::UNSYNCABLE_PREF); | 235 PrefService::UNSYNCABLE_PREF); |
| 247 prefs->RegisterIntegerPref(prefs::kManagedDefaultImagesSetting, | 236 prefs->RegisterIntegerPref(prefs::kManagedDefaultImagesSetting, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 prefs->RegisterListPref(prefs::kManagedPluginsAllowedForUrls, | 269 prefs->RegisterListPref(prefs::kManagedPluginsAllowedForUrls, |
| 281 PrefService::UNSYNCABLE_PREF); | 270 PrefService::UNSYNCABLE_PREF); |
| 282 prefs->RegisterListPref(prefs::kManagedPluginsBlockedForUrls, | 271 prefs->RegisterListPref(prefs::kManagedPluginsBlockedForUrls, |
| 283 PrefService::UNSYNCABLE_PREF); | 272 PrefService::UNSYNCABLE_PREF); |
| 284 prefs->RegisterListPref(prefs::kManagedPopupsAllowedForUrls, | 273 prefs->RegisterListPref(prefs::kManagedPopupsAllowedForUrls, |
| 285 PrefService::UNSYNCABLE_PREF); | 274 PrefService::UNSYNCABLE_PREF); |
| 286 prefs->RegisterListPref(prefs::kManagedPopupsBlockedForUrls, | 275 prefs->RegisterListPref(prefs::kManagedPopupsBlockedForUrls, |
| 287 PrefService::UNSYNCABLE_PREF); | 276 PrefService::UNSYNCABLE_PREF); |
| 288 } | 277 } |
| 289 | 278 |
| 290 PolicyProvider::PolicyProvider(Profile* profile, | 279 PolicyProvider::PolicyProvider(HostContentSettingsMap* map, |
| 280 PrefService* prefs, |
| 291 DefaultProviderInterface* default_provider) | 281 DefaultProviderInterface* default_provider) |
| 292 : profile_(profile), | 282 : map_(map), |
| 283 prefs_(prefs), |
| 293 default_provider_(default_provider) { | 284 default_provider_(default_provider) { |
| 294 Init(); | |
| 295 } | |
| 296 | |
| 297 PolicyProvider::~PolicyProvider() { | |
| 298 UnregisterObservers(); | |
| 299 } | |
| 300 | |
| 301 void PolicyProvider::Init() { | |
| 302 PrefService* prefs = profile_->GetPrefs(); | |
| 303 | |
| 304 ReadManagedContentSettings(false); | 285 ReadManagedContentSettings(false); |
| 305 | 286 |
| 306 pref_change_registrar_.Init(prefs); | 287 pref_change_registrar_.Init(prefs_); |
| 307 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); | 288 pref_change_registrar_.Add(prefs::kManagedCookiesBlockedForUrls, this); |
| 308 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); | 289 pref_change_registrar_.Add(prefs::kManagedCookiesAllowedForUrls, this); |
| 309 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); | 290 pref_change_registrar_.Add(prefs::kManagedCookiesSessionOnlyForUrls, this); |
| 310 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); | 291 pref_change_registrar_.Add(prefs::kManagedImagesBlockedForUrls, this); |
| 311 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); | 292 pref_change_registrar_.Add(prefs::kManagedImagesAllowedForUrls, this); |
| 312 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); | 293 pref_change_registrar_.Add(prefs::kManagedJavaScriptBlockedForUrls, this); |
| 313 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); | 294 pref_change_registrar_.Add(prefs::kManagedJavaScriptAllowedForUrls, this); |
| 314 pref_change_registrar_.Add(prefs::kManagedPluginsBlockedForUrls, this); | 295 pref_change_registrar_.Add(prefs::kManagedPluginsBlockedForUrls, this); |
| 315 pref_change_registrar_.Add(prefs::kManagedPluginsAllowedForUrls, this); | 296 pref_change_registrar_.Add(prefs::kManagedPluginsAllowedForUrls, this); |
| 316 pref_change_registrar_.Add(prefs::kManagedPopupsBlockedForUrls, this); | 297 pref_change_registrar_.Add(prefs::kManagedPopupsBlockedForUrls, this); |
| 317 pref_change_registrar_.Add(prefs::kManagedPopupsAllowedForUrls, this); | 298 pref_change_registrar_.Add(prefs::kManagedPopupsAllowedForUrls, this); |
| 299 } |
| 318 | 300 |
| 319 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 301 PolicyProvider::~PolicyProvider() { |
| 320 Source<Profile>(profile_)); | 302 DCHECK(!prefs_); |
| 321 } | 303 } |
| 322 | 304 |
| 323 void PolicyProvider::GetContentSettingsFromPreferences( | 305 void PolicyProvider::GetContentSettingsFromPreferences( |
| 324 PrefService* prefs, | |
| 325 ContentSettingsRules* rules) { | 306 ContentSettingsRules* rules) { |
| 326 for (size_t i = 0; i < arraysize(kPrefsForManagedContentSettingsMap); ++i) { | 307 for (size_t i = 0; i < arraysize(kPrefsForManagedContentSettingsMap); ++i) { |
| 327 const char* pref_name = kPrefsForManagedContentSettingsMap[i].pref_name; | 308 const char* pref_name = kPrefsForManagedContentSettingsMap[i].pref_name; |
| 328 // Skip unset policies. | 309 // Skip unset policies. |
| 329 if (!prefs->HasPrefPath(pref_name)) { | 310 if (!prefs_->HasPrefPath(pref_name)) { |
| 330 VLOG(2) << "Skipping unset preference: " << pref_name; | 311 VLOG(2) << "Skipping unset preference: " << pref_name; |
| 331 continue; | 312 continue; |
| 332 } | 313 } |
| 333 | 314 |
| 334 const PrefService::Preference* pref = prefs->FindPreference(pref_name); | 315 const PrefService::Preference* pref = prefs_->FindPreference(pref_name); |
| 335 DCHECK(pref); | 316 DCHECK(pref); |
| 336 DCHECK(pref->IsManaged()); | 317 DCHECK(pref->IsManaged()); |
| 337 DCHECK_EQ(Value::TYPE_LIST, pref->GetType()); | |
| 338 | 318 |
| 339 const ListValue* pattern_str_list = | 319 const ListValue* pattern_str_list = NULL; |
| 340 static_cast<const ListValue*>(pref->GetValue()); | 320 if (!pref->GetValue()->GetAsList(&pattern_str_list)) { |
| 321 NOTREACHED(); |
| 322 return; |
| 323 } |
| 324 |
| 341 for (size_t j = 0; j < pattern_str_list->GetSize(); ++j) { | 325 for (size_t j = 0; j < pattern_str_list->GetSize(); ++j) { |
| 342 std::string original_pattern_str; | 326 std::string original_pattern_str; |
| 343 pattern_str_list->GetString(j, &original_pattern_str); | 327 pattern_str_list->GetString(j, &original_pattern_str); |
| 344 PatternPair pattern_pair = ParsePatternString(original_pattern_str); | 328 PatternPair pattern_pair = ParsePatternString(original_pattern_str); |
| 345 // Ignore invalid patterns. | 329 // Ignore invalid patterns. |
| 346 if (!pattern_pair.first.IsValid()) { | 330 if (!pattern_pair.first.IsValid()) { |
| 347 VLOG(1) << "Ignoring invalid content settings pattern: " << | 331 VLOG(1) << "Ignoring invalid content settings pattern: " << |
| 348 original_pattern_str; | 332 original_pattern_str; |
| 349 continue; | 333 continue; |
| 350 } | 334 } |
| 351 | 335 |
| 352 ContentSettingsType content_type = | 336 ContentSettingsType content_type = |
| 353 kPrefsForManagedContentSettingsMap[i].content_type; | 337 kPrefsForManagedContentSettingsMap[i].content_type; |
| 354 // If only one pattern was defined auto expand it to a pattern pair. | 338 // If only one pattern was defined auto expand it to a pattern pair. |
| 355 rules->push_back(MakeTuple( | 339 rules->push_back(MakeTuple( |
| 356 pattern_pair.first, | 340 pattern_pair.first, |
| 357 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard() | 341 !pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard() |
| 358 : pattern_pair.second, | 342 : pattern_pair.second, |
| 359 content_type, | 343 content_type, |
| 360 ResourceIdentifier(NO_RESOURCE_IDENTIFIER), | 344 ResourceIdentifier(NO_RESOURCE_IDENTIFIER), |
| 361 kPrefsForManagedContentSettingsMap[i].setting)); | 345 kPrefsForManagedContentSettingsMap[i].setting)); |
| 362 } | 346 } |
| 363 } | 347 } |
| 364 } | 348 } |
| 365 | 349 |
| 366 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { | 350 void PolicyProvider::ReadManagedContentSettings(bool overwrite) { |
| 367 ContentSettingsRules rules; | 351 ContentSettingsRules rules; |
| 368 PrefService* prefs = profile_->GetPrefs(); | 352 GetContentSettingsFromPreferences(&rules); |
| 369 GetContentSettingsFromPreferences(prefs, &rules); | |
| 370 { | 353 { |
| 371 base::AutoLock auto_lock(lock_); | 354 base::AutoLock auto_lock(lock_); |
| 372 if (overwrite) | 355 if (overwrite) |
| 373 value_map_.clear(); | 356 value_map_.clear(); |
| 374 for (ContentSettingsRules::iterator rule = rules.begin(); | 357 for (ContentSettingsRules::iterator rule = rules.begin(); |
| 375 rule != rules.end(); | 358 rule != rules.end(); |
| 376 ++rule) { | 359 ++rule) { |
| 377 value_map_.SetValue(rule->a, | 360 value_map_.SetValue(rule->a, |
| 378 rule->b, | 361 rule->b, |
| 379 rule->c, | 362 rule->c, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 setting); | 418 setting); |
| 436 content_setting_rules->push_back(new_rule); | 419 content_setting_rules->push_back(new_rule); |
| 437 } | 420 } |
| 438 } | 421 } |
| 439 } | 422 } |
| 440 | 423 |
| 441 void PolicyProvider::ClearAllContentSettingsRules( | 424 void PolicyProvider::ClearAllContentSettingsRules( |
| 442 ContentSettingsType content_type) { | 425 ContentSettingsType content_type) { |
| 443 } | 426 } |
| 444 | 427 |
| 445 void PolicyProvider::UnregisterObservers() { | 428 void PolicyProvider::ShutdownOnUIThread() { |
| 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 447 if (!profile_) | 430 if (!prefs_) |
| 448 return; | 431 return; |
| 449 pref_change_registrar_.RemoveAll(); | 432 pref_change_registrar_.RemoveAll(); |
| 450 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 433 prefs_ = NULL; |
| 451 Source<Profile>(profile_)); | 434 map_ = NULL; |
| 452 profile_ = NULL; | |
| 453 } | 435 } |
| 454 | 436 |
| 455 void PolicyProvider::NotifyObservers( | 437 void PolicyProvider::NotifyObservers( |
| 456 const ContentSettingsDetails& details) { | 438 const ContentSettingsDetails& details) { |
| 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 458 if (profile_ == NULL) | 440 if (map_ == NULL) |
| 459 return; | 441 return; |
| 460 NotificationService::current()->Notify( | 442 NotificationService::current()->Notify( |
| 461 NotificationType::CONTENT_SETTINGS_CHANGED, | 443 NotificationType::CONTENT_SETTINGS_CHANGED, |
| 462 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 444 Source<HostContentSettingsMap>(map_), |
| 463 Details<const ContentSettingsDetails>(&details)); | 445 Details<const ContentSettingsDetails>(&details)); |
| 464 } | 446 } |
| 465 | 447 |
| 466 void PolicyProvider::Observe(NotificationType type, | 448 void PolicyProvider::Observe(NotificationType type, |
| 467 const NotificationSource& source, | 449 const NotificationSource& source, |
| 468 const NotificationDetails& details) { | 450 const NotificationDetails& details) { |
| 469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 470 | 452 |
| 471 if (type == NotificationType::PREF_CHANGED) { | 453 if (type == NotificationType::PREF_CHANGED) { |
| 472 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 454 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
| 473 std::string* name = Details<std::string>(details).ptr(); | 455 std::string* name = Details<std::string>(details).ptr(); |
| 474 if (*name == prefs::kManagedCookiesAllowedForUrls || | 456 if (*name == prefs::kManagedCookiesAllowedForUrls || |
| 475 *name == prefs::kManagedCookiesBlockedForUrls || | 457 *name == prefs::kManagedCookiesBlockedForUrls || |
| 476 *name == prefs::kManagedCookiesSessionOnlyForUrls || | 458 *name == prefs::kManagedCookiesSessionOnlyForUrls || |
| 477 *name == prefs::kManagedImagesAllowedForUrls || | 459 *name == prefs::kManagedImagesAllowedForUrls || |
| 478 *name == prefs::kManagedImagesBlockedForUrls || | 460 *name == prefs::kManagedImagesBlockedForUrls || |
| 479 *name == prefs::kManagedJavaScriptAllowedForUrls || | 461 *name == prefs::kManagedJavaScriptAllowedForUrls || |
| 480 *name == prefs::kManagedJavaScriptBlockedForUrls || | 462 *name == prefs::kManagedJavaScriptBlockedForUrls || |
| 481 *name == prefs::kManagedPluginsAllowedForUrls || | 463 *name == prefs::kManagedPluginsAllowedForUrls || |
| 482 *name == prefs::kManagedPluginsBlockedForUrls || | 464 *name == prefs::kManagedPluginsBlockedForUrls || |
| 483 *name == prefs::kManagedPopupsAllowedForUrls || | 465 *name == prefs::kManagedPopupsAllowedForUrls || |
| 484 *name == prefs::kManagedPopupsBlockedForUrls) { | 466 *name == prefs::kManagedPopupsBlockedForUrls) { |
| 485 ReadManagedContentSettings(true); | 467 ReadManagedContentSettings(true); |
| 486 ContentSettingsDetails details(ContentSettingsPattern(), | 468 ContentSettingsDetails details(ContentSettingsPattern(), |
| 487 ContentSettingsPattern(), | 469 ContentSettingsPattern(), |
| 488 CONTENT_SETTINGS_TYPE_DEFAULT, | 470 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 489 std::string()); | 471 std::string()); |
| 490 NotifyObservers(details); | 472 NotifyObservers(details); |
| 491 } | 473 } |
| 492 } else if (type == NotificationType::PROFILE_DESTROYED) { | |
| 493 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | |
| 494 UnregisterObservers(); | |
| 495 } else { | 474 } else { |
| 496 NOTREACHED() << "Unexpected notification"; | 475 NOTREACHED() << "Unexpected notification"; |
| 497 } | 476 } |
| 498 } | 477 } |
| 499 | 478 |
| 500 } // namespace content_settings | 479 } // namespace content_settings |
| OLD | NEW |