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/content_settings_utils.h" | 5 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 } | 129 } |
| 130 | 130 |
| 131 scoped_ptr<base::Value> ContentSettingToValue(ContentSetting setting) { | 131 scoped_ptr<base::Value> ContentSettingToValue(ContentSetting setting) { |
| 132 if (setting <= CONTENT_SETTING_DEFAULT || | 132 if (setting <= CONTENT_SETTING_DEFAULT || |
| 133 setting >= CONTENT_SETTING_NUM_SETTINGS) { | 133 setting >= CONTENT_SETTING_NUM_SETTINGS) { |
| 134 return nullptr; | 134 return nullptr; |
| 135 } | 135 } |
| 136 return make_scoped_ptr(new base::FundamentalValue(setting)); | 136 return make_scoped_ptr(new base::FundamentalValue(setting)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 base::Value* GetContentSettingValueAndPatterns( | 139 scoped_ptr<base::Value> GetContentSettingValueAndPatterns( |
| 140 const ProviderInterface* provider, | 140 const ProviderInterface* provider, |
| 141 const GURL& primary_url, | 141 const GURL& primary_url, |
| 142 const GURL& secondary_url, | 142 const GURL& secondary_url, |
| 143 ContentSettingsType content_type, | 143 ContentSettingsType content_type, |
| 144 const std::string& resource_identifier, | 144 const std::string& resource_identifier, |
| 145 bool include_incognito, | 145 bool include_incognito, |
| 146 ContentSettingsPattern* primary_pattern, | 146 ContentSettingsPattern* primary_pattern, |
| 147 ContentSettingsPattern* secondary_pattern) { | 147 ContentSettingsPattern* secondary_pattern) { |
| 148 if (include_incognito) { | 148 if (include_incognito) { |
| 149 // Check incognito-only specific settings. It's essential that the | 149 // Check incognito-only specific settings. It's essential that the |
| 150 // |RuleIterator| gets out of scope before we get a rule iterator for the | 150 // |RuleIterator| gets out of scope before we get a rule iterator for the |
| 151 // normal mode. | 151 // normal mode. |
| 152 scoped_ptr<RuleIterator> incognito_rule_iterator( | 152 scoped_ptr<RuleIterator> incognito_rule_iterator( |
| 153 provider->GetRuleIterator(content_type, resource_identifier, true)); | 153 provider->GetRuleIterator(content_type, resource_identifier, |
| 154 base::Value* value = GetContentSettingValueAndPatterns( | 154 true /* incognito */)); |
| 155 scoped_ptr<base::Value> value = GetContentSettingValueAndPatterns( | |
| 155 incognito_rule_iterator.get(), primary_url, secondary_url, | 156 incognito_rule_iterator.get(), primary_url, secondary_url, |
| 156 primary_pattern, secondary_pattern); | 157 primary_pattern, secondary_pattern); |
| 157 if (value) | 158 if (value) |
| 158 return value; | 159 return value; |
| 159 } | 160 } |
| 160 // No settings from the incognito; use the normal mode. | 161 // No settings from the incognito; use the normal mode. |
| 161 scoped_ptr<RuleIterator> rule_iterator( | 162 scoped_ptr<RuleIterator> rule_iterator( |
| 162 provider->GetRuleIterator(content_type, resource_identifier, false)); | 163 provider->GetRuleIterator(content_type, resource_identifier, |
| 163 return GetContentSettingValueAndPatterns( | 164 false /* incognito */)); |
| 165 scoped_ptr<base::Value> value = GetContentSettingValueAndPatterns( | |
| 164 rule_iterator.get(), primary_url, secondary_url, | 166 rule_iterator.get(), primary_url, secondary_url, |
| 165 primary_pattern, secondary_pattern); | 167 primary_pattern, secondary_pattern); |
| 168 if (value && include_incognito) { | |
| 169 value = ContentSettingToValue( | |
| 170 HostContentSettingsMap::CoerceSettingInheritedToIncognito( | |
| 171 content_type, ValueToContentSetting(value.get()))); | |
| 172 } | |
|
raymes
2015/12/01 03:19:29
What I was suggesting is to move this code into Ho
msramek
2015/12/01 13:41:43
Either that, or we can just simply wrap the callsi
johnme
2015/12/02 15:13:17
I'm not quite sure what you're asking. If you're s
johnme
2015/12/02 15:13:17
Wrapping doesn't work, as Coerce should only be ca
raymes
2015/12/03 01:56:49
I don't quite understand why wrapping doesn't work
johnme
2015/12/03 19:06:40
That doesn't work: suppose the provider has an ALL
raymes
2015/12/03 22:19:42
I'm confused though - AFAICT the code I wrote is f
johnme
2015/12/04 17:14:31
My code does (simplified):
if (include_incognito
| |
| 173 return value; | |
| 166 } | 174 } |
| 167 | 175 |
| 168 base::Value* GetContentSettingValueAndPatterns( | 176 scoped_ptr<base::Value> GetContentSettingValueAndPatterns( |
| 169 RuleIterator* rule_iterator, | 177 RuleIterator* rule_iterator, |
| 170 const GURL& primary_url, | 178 const GURL& primary_url, |
| 171 const GURL& secondary_url, | 179 const GURL& secondary_url, |
| 172 ContentSettingsPattern* primary_pattern, | 180 ContentSettingsPattern* primary_pattern, |
| 173 ContentSettingsPattern* secondary_pattern) { | 181 ContentSettingsPattern* secondary_pattern) { |
| 174 while (rule_iterator->HasNext()) { | 182 while (rule_iterator->HasNext()) { |
| 175 const Rule& rule = rule_iterator->Next(); | 183 const Rule& rule = rule_iterator->Next(); |
| 176 if (rule.primary_pattern.Matches(primary_url) && | 184 if (rule.primary_pattern.Matches(primary_url) && |
| 177 rule.secondary_pattern.Matches(secondary_url)) { | 185 rule.secondary_pattern.Matches(secondary_url)) { |
| 178 if (primary_pattern) | 186 if (primary_pattern) |
| 179 *primary_pattern = rule.primary_pattern; | 187 *primary_pattern = rule.primary_pattern; |
| 180 if (secondary_pattern) | 188 if (secondary_pattern) |
| 181 *secondary_pattern = rule.secondary_pattern; | 189 *secondary_pattern = rule.secondary_pattern; |
| 182 return rule.value.get()->DeepCopy(); | 190 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
| 183 } | 191 } |
| 184 } | 192 } |
| 185 return NULL; | 193 return scoped_ptr<base::Value>(); |
| 186 } | 194 } |
| 187 | 195 |
| 188 void GetRendererContentSettingRules(const HostContentSettingsMap* map, | 196 void GetRendererContentSettingRules(const HostContentSettingsMap* map, |
| 189 RendererContentSettingRules* rules) { | 197 RendererContentSettingRules* rules) { |
| 190 map->GetSettingsForOneType( | 198 map->GetSettingsForOneType( |
| 191 CONTENT_SETTINGS_TYPE_IMAGES, | 199 CONTENT_SETTINGS_TYPE_IMAGES, |
| 192 ResourceIdentifier(), | 200 ResourceIdentifier(), |
| 193 &(rules->image_rules)); | 201 &(rules->image_rules)); |
| 194 map->GetSettingsForOneType( | 202 map->GetSettingsForOneType( |
| 195 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 203 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 196 ResourceIdentifier(), | 204 ResourceIdentifier(), |
| 197 &(rules->script_rules)); | 205 &(rules->script_rules)); |
| 198 } | 206 } |
| 199 | 207 |
| 200 } // namespace content_settings | 208 } // namespace content_settings |
| OLD | NEW |