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 static_cast<content_settings::PrefProvider*>( |
| 353 content_settings_providers_[PREF_PROVIDER]) |
| 354 ->UpdateLastUsage(primary_pattern, secondary_pattern, content_type); |
| 355 } |
| 356 |
| 357 base::Time HostContentSettingsMap::GetLastUsage( |
| 358 const GURL& primary_url, |
| 359 const GURL& secondary_url, |
| 360 ContentSettingsType content_type) { |
| 361 return GetLastUsageByPattern( |
| 362 ContentSettingsPattern::FromURLNoWildcard(primary_url), |
| 363 ContentSettingsPattern::FromURLNoWildcard(secondary_url), |
| 364 content_type); |
| 365 } |
| 366 |
| 367 base::Time HostContentSettingsMap::GetLastUsageByPattern( |
| 368 const ContentSettingsPattern& primary_pattern, |
| 369 const ContentSettingsPattern& secondary_pattern, |
| 370 ContentSettingsType content_type) { |
| 371 UsedContentSettingsProviders(); |
| 372 |
| 373 return static_cast<content_settings::PrefProvider*>( |
| 374 content_settings_providers_[PREF_PROVIDER]) |
| 375 ->GetLastUsage(primary_pattern, secondary_pattern, content_type); |
| 376 } |
| 377 |
| 378 void HostContentSettingsMap::SetPrefClockForTesting(base::Clock* clock) { |
| 379 UsedContentSettingsProviders(); |
| 380 |
| 381 static_cast<content_settings::PrefProvider*>( |
| 382 content_settings_providers_[PREF_PROVIDER])->SetClockForTesting(clock); |
| 383 } |
| 384 |
311 void HostContentSettingsMap::AddExceptionForURL( | 385 void HostContentSettingsMap::AddExceptionForURL( |
312 const GURL& primary_url, | 386 const GURL& primary_url, |
313 const GURL& secondary_url, | 387 const GURL& secondary_url, |
314 ContentSettingsType content_type, | 388 ContentSettingsType content_type, |
315 ContentSetting setting) { | 389 ContentSetting setting) { |
316 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must | 390 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must |
317 // match. | 391 // match. |
318 DCHECK(primary_url == secondary_url); | 392 DCHECK(primary_url == secondary_url); |
319 DCHECK(!ContentTypeHasCompoundValue(content_type)); | 393 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
320 | 394 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 HostContentSettingsMap::GetProviderTypeFromSource( | 705 HostContentSettingsMap::GetProviderTypeFromSource( |
632 const std::string& source) { | 706 const std::string& source) { |
633 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { | 707 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { |
634 if (source == kProviderNames[i]) | 708 if (source == kProviderNames[i]) |
635 return static_cast<ProviderType>(i); | 709 return static_cast<ProviderType>(i); |
636 } | 710 } |
637 | 711 |
638 NOTREACHED(); | 712 NOTREACHED(); |
639 return DEFAULT_PROVIDER; | 713 return DEFAULT_PROVIDER; |
640 } | 714 } |
OLD | NEW |