| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 177 |
| 181 DefaultProvider::~DefaultProvider() { | 178 DefaultProvider::~DefaultProvider() { |
| 182 } | 179 } |
| 183 | 180 |
| 184 bool DefaultProvider::SetWebsiteSetting( | 181 bool DefaultProvider::SetWebsiteSetting( |
| 185 const ContentSettingsPattern& primary_pattern, | 182 const ContentSettingsPattern& primary_pattern, |
| 186 const ContentSettingsPattern& secondary_pattern, | 183 const ContentSettingsPattern& secondary_pattern, |
| 187 ContentSettingsType content_type, | 184 ContentSettingsType content_type, |
| 188 const ResourceIdentifier& resource_identifier, | 185 const ResourceIdentifier& resource_identifier, |
| 189 base::Value* in_value) { | 186 base::Value* in_value) { |
| 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 187 DCHECK(CalledOnValidThread()); |
| 191 DCHECK(prefs_); | 188 DCHECK(prefs_); |
| 192 | 189 |
| 193 // Ignore non default settings | 190 // Ignore non default settings |
| 194 if (primary_pattern != ContentSettingsPattern::Wildcard() || | 191 if (primary_pattern != ContentSettingsPattern::Wildcard() || |
| 195 secondary_pattern != ContentSettingsPattern::Wildcard()) { | 192 secondary_pattern != ContentSettingsPattern::Wildcard()) { |
| 196 return false; | 193 return false; |
| 197 } | 194 } |
| 198 | 195 |
| 199 // The default settings may not be directly modified for OTR sessions. | 196 // The default settings may not be directly modified for OTR sessions. |
| 200 // Instead, they are synced to the main profile's setting. | 197 // Instead, they are synced to the main profile's setting. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 256 |
| 260 void DefaultProvider::ClearAllContentSettingsRules( | 257 void DefaultProvider::ClearAllContentSettingsRules( |
| 261 ContentSettingsType content_type) { | 258 ContentSettingsType content_type) { |
| 262 // TODO(markusheintz): This method is only called when the | 259 // TODO(markusheintz): This method is only called when the |
| 263 // |DesktopNotificationService| calls |ClearAllSettingsForType| method on the | 260 // |DesktopNotificationService| calls |ClearAllSettingsForType| method on the |
| 264 // |HostContentSettingsMap|. Don't implement this method yet, otherwise the | 261 // |HostContentSettingsMap|. Don't implement this method yet, otherwise the |
| 265 // default notification settings will be cleared as well. | 262 // default notification settings will be cleared as well. |
| 266 } | 263 } |
| 267 | 264 |
| 268 void DefaultProvider::ShutdownOnUIThread() { | 265 void DefaultProvider::ShutdownOnUIThread() { |
| 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 266 DCHECK(CalledOnValidThread()); |
| 270 DCHECK(prefs_); | 267 DCHECK(prefs_); |
| 271 RemoveAllObservers(); | 268 RemoveAllObservers(); |
| 272 pref_change_registrar_.RemoveAll(); | 269 pref_change_registrar_.RemoveAll(); |
| 273 prefs_ = NULL; | 270 prefs_ = NULL; |
| 274 } | 271 } |
| 275 | 272 |
| 276 void DefaultProvider::OnPreferenceChanged(const std::string& name) { | 273 void DefaultProvider::OnPreferenceChanged(const std::string& name) { |
| 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 274 DCHECK(CalledOnValidThread()); |
| 278 if (updating_preferences_) | 275 if (updating_preferences_) |
| 279 return; | 276 return; |
| 280 | 277 |
| 281 if (name == prefs::kDefaultContentSettings) { | 278 if (name == prefs::kDefaultContentSettings) { |
| 282 ReadDefaultSettings(true); | 279 ReadDefaultSettings(true); |
| 283 } else { | 280 } else { |
| 284 NOTREACHED() << "Unexpected preference observed"; | 281 NOTREACHED() << "Unexpected preference observed"; |
| 285 return; | 282 return; |
| 286 } | 283 } |
| 287 | 284 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // Migrate obsolete cookie prompt mode. | 333 // Migrate obsolete cookie prompt mode. |
| 337 if (ValueToContentSetting( | 334 if (ValueToContentSetting( |
| 338 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].get()) == | 335 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].get()) == |
| 339 CONTENT_SETTING_ASK) { | 336 CONTENT_SETTING_ASK) { |
| 340 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].reset( | 337 default_settings_[CONTENT_SETTINGS_TYPE_COOKIES].reset( |
| 341 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 338 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); |
| 342 } | 339 } |
| 343 } | 340 } |
| 344 | 341 |
| 345 } // namespace content_settings | 342 } // namespace content_settings |
| OLD | NEW |