| 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/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/clock.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/content_settings/content_settings_custom_extension_prov
ider.h" | 17 #include "chrome/browser/content_settings/content_settings_custom_extension_prov
ider.h" |
| 17 #include "chrome/browser/content_settings/content_settings_default_provider.h" | 18 #include "chrome/browser/content_settings/content_settings_default_provider.h" |
| 18 #include "chrome/browser/content_settings/content_settings_details.h" | 19 #include "chrome/browser/content_settings/content_settings_details.h" |
| 19 #include "chrome/browser/content_settings/content_settings_internal_extension_pr
ovider.h" | 20 #include "chrome/browser/content_settings/content_settings_internal_extension_pr
ovider.h" |
| 20 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" | 21 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" |
| 21 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 22 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
| 22 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 23 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
| 23 #include "chrome/browser/content_settings/content_settings_provider.h" | 24 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 24 #include "chrome/browser/content_settings/content_settings_rule.h" | 25 #include "chrome/browser/content_settings/content_settings_rule.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 NOTREACHED(); | 292 NOTREACHED(); |
| 292 } | 293 } |
| 293 | 294 |
| 294 void HostContentSettingsMap::SetContentSetting( | 295 void HostContentSettingsMap::SetContentSetting( |
| 295 const ContentSettingsPattern& primary_pattern, | 296 const ContentSettingsPattern& primary_pattern, |
| 296 const ContentSettingsPattern& secondary_pattern, | 297 const ContentSettingsPattern& secondary_pattern, |
| 297 ContentSettingsType content_type, | 298 ContentSettingsType content_type, |
| 298 const std::string& resource_identifier, | 299 const std::string& resource_identifier, |
| 299 ContentSetting setting) { | 300 ContentSetting setting) { |
| 300 DCHECK(!ContentTypeHasCompoundValue(content_type)); | 301 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
| 302 |
| 303 if (setting == CONTENT_SETTING_ALLOW && |
| 304 (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION || |
| 305 content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS)) { |
| 306 UpdateLastUsageByPattern(primary_pattern, secondary_pattern, content_type); |
| 307 } |
| 308 |
| 301 base::Value* value = NULL; | 309 base::Value* value = NULL; |
| 302 if (setting != CONTENT_SETTING_DEFAULT) | 310 if (setting != CONTENT_SETTING_DEFAULT) |
| 303 value = base::Value::CreateIntegerValue(setting); | 311 value = base::Value::CreateIntegerValue(setting); |
| 304 SetWebsiteSetting(primary_pattern, | 312 SetWebsiteSetting(primary_pattern, |
| 305 secondary_pattern, | 313 secondary_pattern, |
| 306 content_type, | 314 content_type, |
| 307 resource_identifier, | 315 resource_identifier, |
| 308 value); | 316 value); |
| 309 } | 317 } |
| 310 | 318 |
| 319 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
| 320 const GURL& primary_url, |
| 321 const GURL& secondary_url, |
| 322 ContentSettingsType content_type, |
| 323 const std::string& resource_identifier) { |
| 324 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 325 |
| 326 ContentSetting setting = GetContentSetting( |
| 327 primary_url, secondary_url, content_type, resource_identifier); |
| 328 if (setting == CONTENT_SETTING_ALLOW) { |
| 329 UpdateLastUsageByPattern( |
| 330 ContentSettingsPattern::FromURLNoWildcard(primary_url), |
| 331 ContentSettingsPattern::FromURLNoWildcard(secondary_url), |
| 332 content_type); |
| 333 } |
| 334 return setting; |
| 335 } |
| 336 |
| 337 void HostContentSettingsMap::UpdateLastUsage(const GURL& primary_url, |
| 338 const GURL& secondary_url, |
| 339 ContentSettingsType content_type) { |
| 340 UpdateLastUsageByPattern( |
| 341 ContentSettingsPattern::FromURLNoWildcard(primary_url), |
| 342 ContentSettingsPattern::FromURLNoWildcard(secondary_url), |
| 343 content_type); |
| 344 } |
| 345 |
| 346 void HostContentSettingsMap::UpdateLastUsageByPattern( |
| 347 const ContentSettingsPattern& primary_pattern, |
| 348 const ContentSettingsPattern& secondary_pattern, |
| 349 ContentSettingsType content_type) { |
| 350 UsedContentSettingsProviders(); |
| 351 |
| 352 GetPrefProvider()->UpdateLastUsage( |
| 353 primary_pattern, secondary_pattern, content_type); |
| 354 } |
| 355 |
| 356 base::Time HostContentSettingsMap::GetLastUsage( |
| 357 const GURL& primary_url, |
| 358 const GURL& secondary_url, |
| 359 ContentSettingsType content_type) { |
| 360 return GetLastUsageByPattern( |
| 361 ContentSettingsPattern::FromURLNoWildcard(primary_url), |
| 362 ContentSettingsPattern::FromURLNoWildcard(secondary_url), |
| 363 content_type); |
| 364 } |
| 365 |
| 366 base::Time HostContentSettingsMap::GetLastUsageByPattern( |
| 367 const ContentSettingsPattern& primary_pattern, |
| 368 const ContentSettingsPattern& secondary_pattern, |
| 369 ContentSettingsType content_type) { |
| 370 UsedContentSettingsProviders(); |
| 371 |
| 372 return GetPrefProvider()->GetLastUsage( |
| 373 primary_pattern, secondary_pattern, content_type); |
| 374 } |
| 375 |
| 376 void HostContentSettingsMap::SetPrefClockForTesting( |
| 377 scoped_ptr<base::Clock> clock) { |
| 378 UsedContentSettingsProviders(); |
| 379 |
| 380 GetPrefProvider()->SetClockForTesting(clock.Pass()); |
| 381 } |
| 382 |
| 311 void HostContentSettingsMap::AddExceptionForURL( | 383 void HostContentSettingsMap::AddExceptionForURL( |
| 312 const GURL& primary_url, | 384 const GURL& primary_url, |
| 313 const GURL& secondary_url, | 385 const GURL& secondary_url, |
| 314 ContentSettingsType content_type, | 386 ContentSettingsType content_type, |
| 315 ContentSetting setting) { | 387 ContentSetting setting) { |
| 316 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must | 388 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must |
| 317 // match. | 389 // match. |
| 318 DCHECK(primary_url == secondary_url); | 390 DCHECK(primary_url == secondary_url); |
| 319 DCHECK(!ContentTypeHasCompoundValue(content_type)); | 391 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
| 320 | 392 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 HostContentSettingsMap::GetProviderTypeFromSource( | 703 HostContentSettingsMap::GetProviderTypeFromSource( |
| 632 const std::string& source) { | 704 const std::string& source) { |
| 633 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { | 705 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { |
| 634 if (source == kProviderNames[i]) | 706 if (source == kProviderNames[i]) |
| 635 return static_cast<ProviderType>(i); | 707 return static_cast<ProviderType>(i); |
| 636 } | 708 } |
| 637 | 709 |
| 638 NOTREACHED(); | 710 NOTREACHED(); |
| 639 return DEFAULT_PROVIDER; | 711 return DEFAULT_PROVIDER; |
| 640 } | 712 } |
| 713 |
| 714 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { |
| 715 return static_cast<content_settings::PrefProvider*>( |
| 716 content_settings_providers_[PREF_PROVIDER]); |
| 717 } |
| OLD | NEW |