Chromium Code Reviews| 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 "components/content_settings/core/browser/host_content_settings_map.h" | 5 #include "components/content_settings/core/browser/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" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 | 150 |
| 151 // Iterate through the list of providers and return the first non-NULL value | 151 // Iterate through the list of providers and return the first non-NULL value |
| 152 // that matches |primary_url| and |secondary_url|. | 152 // that matches |primary_url| and |secondary_url|. |
| 153 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 153 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 154 provider != content_settings_providers_.end(); | 154 provider != content_settings_providers_.end(); |
| 155 ++provider) { | 155 ++provider) { |
| 156 if (provider->first == PREF_PROVIDER) | 156 if (provider->first == PREF_PROVIDER) |
| 157 continue; | 157 continue; |
| 158 ContentSetting default_setting = | 158 ContentSetting default_setting = |
| 159 GetDefaultContentSettingFromProvider(content_type, provider->second); | 159 GetDefaultContentSettingFromProvider(content_type, provider->second); |
| 160 if (is_off_the_record_) { | |
| 161 default_setting = | |
| 162 CoerceSettingInheritedToIncognito(content_type, default_setting); | |
| 163 } | |
| 160 if (default_setting != CONTENT_SETTING_DEFAULT) { | 164 if (default_setting != CONTENT_SETTING_DEFAULT) { |
| 161 if (provider_id) | 165 if (provider_id) |
| 162 *provider_id = kProviderNamesSourceMap[provider->first].provider_name; | 166 *provider_id = kProviderNamesSourceMap[provider->first].provider_name; |
| 163 return default_setting; | 167 return default_setting; |
| 164 } | 168 } |
| 165 } | 169 } |
| 166 | 170 |
| 167 return CONTENT_SETTING_DEFAULT; | 171 return CONTENT_SETTING_DEFAULT; |
| 168 } | 172 } |
| 169 | 173 |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 if (info) { | 650 if (info) { |
| 647 primary_pattern = &info->primary_pattern; | 651 primary_pattern = &info->primary_pattern; |
| 648 secondary_pattern = &info->secondary_pattern; | 652 secondary_pattern = &info->secondary_pattern; |
| 649 } | 653 } |
| 650 | 654 |
| 651 // The list of |content_settings_providers_| is ordered according to their | 655 // The list of |content_settings_providers_| is ordered according to their |
| 652 // precedence. | 656 // precedence. |
| 653 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 657 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 654 provider != content_settings_providers_.end(); | 658 provider != content_settings_providers_.end(); |
| 655 ++provider) { | 659 ++provider) { |
| 656 | 660 scoped_ptr<base::Value> value = GetContentSettingValueAndPatternsInternal( |
| 657 scoped_ptr<base::Value> value( | 661 provider->second, primary_url, secondary_url, content_type, |
| 658 content_settings::GetContentSettingValueAndPatterns(provider->second, | 662 resource_identifier, is_off_the_record_, primary_pattern, |
| 659 primary_url, | 663 secondary_pattern); |
| 660 secondary_url, | |
| 661 content_type, | |
| 662 resource_identifier, | |
| 663 is_off_the_record_, | |
| 664 primary_pattern, | |
| 665 secondary_pattern)); | |
| 666 if (value) { | 664 if (value) { |
| 667 if (info) | 665 if (info) |
| 668 info->source = kProviderNamesSourceMap[provider->first].provider_source; | 666 info->source = kProviderNamesSourceMap[provider->first].provider_source; |
| 669 return value.Pass(); | 667 return value.Pass(); |
| 670 } | 668 } |
| 671 } | 669 } |
| 672 | 670 |
| 673 if (info) { | 671 if (info) { |
| 674 info->source = content_settings::SETTING_SOURCE_NONE; | 672 info->source = content_settings::SETTING_SOURCE_NONE; |
| 675 info->primary_pattern = ContentSettingsPattern(); | 673 info->primary_pattern = ContentSettingsPattern(); |
| 676 info->secondary_pattern = ContentSettingsPattern(); | 674 info->secondary_pattern = ContentSettingsPattern(); |
| 677 } | 675 } |
| 678 return scoped_ptr<base::Value>(); | 676 return scoped_ptr<base::Value>(); |
| 679 } | 677 } |
| 678 | |
| 679 // static | |
| 680 scoped_ptr<base::Value> | |
| 681 HostContentSettingsMap::GetContentSettingValueAndPatternsInternal( | |
| 682 const content_settings::ProviderInterface* provider, | |
| 683 const GURL& primary_url, | |
| 684 const GURL& secondary_url, | |
| 685 ContentSettingsType content_type, | |
| 686 const std::string& resource_identifier, | |
| 687 bool include_incognito, | |
| 688 ContentSettingsPattern* primary_pattern, | |
| 689 ContentSettingsPattern* secondary_pattern) { | |
| 690 if (include_incognito) { | |
| 691 // Check incognito-only specific settings. It's essential that the | |
| 692 // |RuleIterator| gets out of scope before we get a rule iterator for the | |
| 693 // normal mode. | |
| 694 scoped_ptr<content_settings::RuleIterator> incognito_rule_iterator( | |
| 695 provider->GetRuleIterator(content_type, resource_identifier, | |
| 696 true /* incognito */)); | |
| 697 scoped_ptr<base::Value> value = GetContentSettingValueAndPatternsInternal( | |
| 698 incognito_rule_iterator.get(), primary_url, secondary_url, | |
| 699 primary_pattern, secondary_pattern); | |
| 700 if (value) | |
| 701 return value; | |
| 702 } | |
| 703 // No settings from the incognito; use the normal mode. | |
| 704 scoped_ptr<content_settings::RuleIterator> rule_iterator( | |
| 705 provider->GetRuleIterator(content_type, resource_identifier, | |
| 706 false /* incognito */)); | |
| 707 scoped_ptr<base::Value> value = GetContentSettingValueAndPatternsInternal( | |
| 708 rule_iterator.get(), primary_url, secondary_url, primary_pattern, | |
| 709 secondary_pattern); | |
| 710 if (value && include_incognito) { | |
| 711 value = content_settings::ContentSettingToValue( | |
|
raymes
2015/12/03 01:56:49
This isn't going to give the right answer for webs
johnme
2015/12/03 19:06:40
Done.
| |
| 712 CoerceSettingInheritedToIncognito( | |
| 713 content_type, | |
| 714 content_settings::ValueToContentSetting(value.get()))); | |
| 715 } | |
| 716 return value; | |
| 717 } | |
| 718 | |
| 719 // static | |
| 720 scoped_ptr<base::Value> | |
| 721 HostContentSettingsMap::GetContentSettingValueAndPatternsInternal( | |
| 722 content_settings::RuleIterator* rule_iterator, | |
| 723 const GURL& primary_url, | |
| 724 const GURL& secondary_url, | |
| 725 ContentSettingsPattern* primary_pattern, | |
| 726 ContentSettingsPattern* secondary_pattern) { | |
| 727 while (rule_iterator->HasNext()) { | |
| 728 const content_settings::Rule& rule = rule_iterator->Next(); | |
| 729 if (rule.primary_pattern.Matches(primary_url) && | |
| 730 rule.secondary_pattern.Matches(secondary_url)) { | |
| 731 if (primary_pattern) | |
| 732 *primary_pattern = rule.primary_pattern; | |
| 733 if (secondary_pattern) | |
| 734 *secondary_pattern = rule.secondary_pattern; | |
| 735 return make_scoped_ptr(rule.value.get()->DeepCopy()); | |
| 736 } | |
| 737 } | |
| 738 return scoped_ptr<base::Value>(); | |
| 739 } | |
| 740 | |
| 741 // static | |
| 742 ContentSetting HostContentSettingsMap::CoerceSettingInheritedToIncognito( | |
|
raymes
2015/12/03 01:56:49
This doesn't need to be a static function, it coul
johnme
2015/12/03 19:06:40
Done.
| |
| 743 ContentSettingsType content_type, | |
| 744 ContentSetting setting) { | |
| 745 if (setting != CONTENT_SETTING_ALLOW) | |
| 746 return setting; | |
| 747 const content_settings::ContentSettingsInfo* info = | |
| 748 content_settings::ContentSettingsRegistry::GetInstance()->Get( | |
| 749 content_type); | |
| 750 if (info->incognito_behavior() != | |
| 751 content_settings::ContentSettingsInfo::INHERIT_IN_INCOGNITO_EXCEPT_ALLOW) | |
| 752 return setting; | |
| 753 DCHECK(info->IsSettingValid(CONTENT_SETTING_ASK)); | |
| 754 return CONTENT_SETTING_ASK; | |
| 755 } | |
| OLD | NEW |