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 (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION || | |
scheib
2014/06/27 17:47:39
not if they block.
Daniel Nishi
2014/06/30 22:40:16
Fixed.
| |
304 content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | |
305 UpdateLastUsageByPattern(primary_pattern, secondary_pattern, content_type); | |
306 } | |
307 | |
301 base::Value* value = NULL; | 308 base::Value* value = NULL; |
302 if (setting != CONTENT_SETTING_DEFAULT) | 309 if (setting != CONTENT_SETTING_DEFAULT) |
303 value = base::Value::CreateIntegerValue(setting); | 310 value = base::Value::CreateIntegerValue(setting); |
304 SetWebsiteSetting(primary_pattern, | 311 SetWebsiteSetting(primary_pattern, |
305 secondary_pattern, | 312 secondary_pattern, |
306 content_type, | 313 content_type, |
307 resource_identifier, | 314 resource_identifier, |
308 value); | 315 value); |
309 } | 316 } |
310 | 317 |
318 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( | |
319 const GURL& primary_url, | |
320 const GURL& secondary_url, | |
321 ContentSettingsType content_type, | |
322 const std::string& resource_identifier) { | |
scheib
2014/06/27 17:47:39
DCHECK_CURRENTLY_ON(BrowserThread::UI);
Daniel Nishi
2014/06/30 22:40:16
Done.
| |
323 ContentSetting setting = GetContentSetting( | |
324 primary_url, secondary_url, content_type, resource_identifier); | |
325 if (setting == CONTENT_SETTING_ALLOW) { | |
326 UpdateLastUsageByPattern( | |
327 ContentSettingsPattern::FromURLNoWildcard(primary_url), | |
328 ContentSettingsPattern::FromURLNoWildcard(secondary_url), | |
329 content_type); | |
330 } | |
331 return setting; | |
332 } | |
333 | |
334 void HostContentSettingsMap::UpdateLastUsageByPattern( | |
335 const ContentSettingsPattern& primary_pattern, | |
336 const ContentSettingsPattern& secondary_pattern, | |
337 ContentSettingsType content_type) { | |
338 UsedContentSettingsProviders(); | |
339 | |
340 static_cast<content_settings::PrefProvider*>( | |
341 content_settings_providers_[PREF_PROVIDER]) | |
342 ->UpdateLastUsage(primary_pattern, secondary_pattern, content_type); | |
343 } | |
344 | |
345 base::Time HostContentSettingsMap::GetLastUsage( | |
346 const GURL& primary_url, | |
347 const GURL& secondary_url, | |
348 ContentSettingsType content_type) { | |
349 return GetLastUsageByPattern( | |
350 ContentSettingsPattern::FromURLNoWildcard(primary_url), | |
351 ContentSettingsPattern::FromURLNoWildcard(secondary_url), | |
352 content_type); | |
353 } | |
354 | |
355 base::Time HostContentSettingsMap::GetLastUsageByPattern( | |
356 const ContentSettingsPattern& primary_pattern, | |
357 const ContentSettingsPattern& secondary_pattern, | |
358 ContentSettingsType content_type) { | |
359 UsedContentSettingsProviders(); | |
360 | |
361 return static_cast<content_settings::PrefProvider*>( | |
362 content_settings_providers_[PREF_PROVIDER]) | |
363 ->GetLastUsage(primary_pattern, secondary_pattern, content_type); | |
364 } | |
365 | |
366 void HostContentSettingsMap::SetPrefClockForTesting(base::Clock* clock) { | |
367 UsedContentSettingsProviders(); | |
368 | |
369 static_cast<content_settings::PrefProvider*>( | |
370 content_settings_providers_[PREF_PROVIDER])->SetClockForTesting(clock); | |
371 } | |
372 | |
311 void HostContentSettingsMap::AddExceptionForURL( | 373 void HostContentSettingsMap::AddExceptionForURL( |
312 const GURL& primary_url, | 374 const GURL& primary_url, |
313 const GURL& secondary_url, | 375 const GURL& secondary_url, |
314 ContentSettingsType content_type, | 376 ContentSettingsType content_type, |
315 ContentSetting setting) { | 377 ContentSetting setting) { |
316 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must | 378 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must |
317 // match. | 379 // match. |
318 DCHECK(primary_url == secondary_url); | 380 DCHECK(primary_url == secondary_url); |
319 DCHECK(!ContentTypeHasCompoundValue(content_type)); | 381 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
320 | 382 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 HostContentSettingsMap::GetProviderTypeFromSource( | 693 HostContentSettingsMap::GetProviderTypeFromSource( |
632 const std::string& source) { | 694 const std::string& source) { |
633 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { | 695 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { |
634 if (source == kProviderNames[i]) | 696 if (source == kProviderNames[i]) |
635 return static_cast<ProviderType>(i); | 697 return static_cast<ProviderType>(i); |
636 } | 698 } |
637 | 699 |
638 NOTREACHED(); | 700 NOTREACHED(); |
639 return DEFAULT_PROVIDER; | 701 return DEFAULT_PROVIDER; |
640 } | 702 } |
OLD | NEW |