| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_default_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_default_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
| 17 #include "chrome/browser/content_settings/content_settings_utils.h" | 17 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "components/content_settings/core/browser/content_settings_rule.h" | 19 #include "components/content_settings/core/browser/content_settings_rule.h" |
| 20 #include "components/content_settings/core/common/content_settings.h" | 20 #include "components/content_settings/core/common/content_settings.h" |
| 21 #include "components/content_settings/core/common/content_settings_pattern.h" | 21 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 22 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
| 23 #include "content/public/browser/browser_thread.h" | |
| 24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 25 | 24 |
| 26 using content::BrowserThread; | |
| 27 | |
| 28 namespace { | 25 namespace { |
| 29 | 26 |
| 30 // The default setting for each content type. | 27 // The default setting for each content type. |
| 31 const ContentSetting kDefaultSettings[] = { | 28 const ContentSetting kDefaultSettings[] = { |
| 32 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES | 29 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES |
| 33 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES | 30 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES |
| 34 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT | 31 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT |
| 35 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS | 32 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS |
| 36 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS | 33 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS |
| 37 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_GEOLOCATION | 34 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_GEOLOCATION |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 175 |
| 179 DefaultProvider::~DefaultProvider() { | 176 DefaultProvider::~DefaultProvider() { |
| 180 } | 177 } |
| 181 | 178 |
| 182 bool DefaultProvider::SetWebsiteSetting( | 179 bool DefaultProvider::SetWebsiteSetting( |
| 183 const ContentSettingsPattern& primary_pattern, | 180 const ContentSettingsPattern& primary_pattern, |
| 184 const ContentSettingsPattern& secondary_pattern, | 181 const ContentSettingsPattern& secondary_pattern, |
| 185 ContentSettingsType content_type, | 182 ContentSettingsType content_type, |
| 186 const ResourceIdentifier& resource_identifier, | 183 const ResourceIdentifier& resource_identifier, |
| 187 base::Value* in_value) { | 184 base::Value* in_value) { |
| 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 185 DCHECK(CalledOnValidThread()); |
| 189 DCHECK(prefs_); | 186 DCHECK(prefs_); |
| 190 | 187 |
| 191 // Ignore non default settings | 188 // Ignore non default settings |
| 192 if (primary_pattern != ContentSettingsPattern::Wildcard() || | 189 if (primary_pattern != ContentSettingsPattern::Wildcard() || |
| 193 secondary_pattern != ContentSettingsPattern::Wildcard()) { | 190 secondary_pattern != ContentSettingsPattern::Wildcard()) { |
| 194 return false; | 191 return false; |
| 195 } | 192 } |
| 196 | 193 |
| 197 // The default settings may not be directly modified for OTR sessions. | 194 // The default settings may not be directly modified for OTR sessions. |
| 198 // Instead, they are synced to the main profile's setting. | 195 // Instead, they are synced to the main profile's setting. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 254 |
| 258 void DefaultProvider::ClearAllContentSettingsRules( | 255 void DefaultProvider::ClearAllContentSettingsRules( |
| 259 ContentSettingsType content_type) { | 256 ContentSettingsType content_type) { |
| 260 // TODO(markusheintz): This method is only called when the | 257 // TODO(markusheintz): This method is only called when the |
| 261 // |DesktopNotificationService| calls |ClearAllSettingsForType| method on the | 258 // |DesktopNotificationService| calls |ClearAllSettingsForType| method on the |
| 262 // |HostContentSettingsMap|. Don't implement this method yet, otherwise the | 259 // |HostContentSettingsMap|. Don't implement this method yet, otherwise the |
| 263 // default notification settings will be cleared as well. | 260 // default notification settings will be cleared as well. |
| 264 } | 261 } |
| 265 | 262 |
| 266 void DefaultProvider::ShutdownOnUIThread() { | 263 void DefaultProvider::ShutdownOnUIThread() { |
| 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 264 DCHECK(CalledOnValidThread()); |
| 268 DCHECK(prefs_); | 265 DCHECK(prefs_); |
| 269 RemoveAllObservers(); | 266 RemoveAllObservers(); |
| 270 pref_change_registrar_.RemoveAll(); | 267 pref_change_registrar_.RemoveAll(); |
| 271 prefs_ = NULL; | 268 prefs_ = NULL; |
| 272 } | 269 } |
| 273 | 270 |
| 274 void DefaultProvider::OnPreferenceChanged(const std::string& name) { | 271 void DefaultProvider::OnPreferenceChanged(const std::string& name) { |
| 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 DCHECK(CalledOnValidThread()); |
| 276 if (updating_preferences_) | 273 if (updating_preferences_) |
| 277 return; | 274 return; |
| 278 | 275 |
| 279 if (name == prefs::kDefaultContentSettings) { | 276 if (name == prefs::kDefaultContentSettings) { |
| 280 ReadDefaultSettings(true); | 277 ReadDefaultSettings(true); |
| 281 } else { | 278 } else { |
| 282 NOTREACHED() << "Unexpected preference observed"; | 279 NOTREACHED() << "Unexpected preference observed"; |
| 283 return; | 280 return; |
| 284 } | 281 } |
| 285 | 282 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 // Migrate obsolete cookie prompt mode. | 331 // Migrate obsolete cookie prompt mode. |
| 335 if (ValueToContentSetting( | 332 if (ValueToContentSetting( |
| 336 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].get()) == | 333 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].get()) == |
| 337 CONTENT_SETTING_ASK) { | 334 CONTENT_SETTING_ASK) { |
| 338 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].reset( | 335 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].reset( |
| 339 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 336 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); |
| 340 } | 337 } |
| 341 } | 338 } |
| 342 | 339 |
| 343 } // namespace content_settings | 340 } // namespace content_settings |
| OLD | NEW |