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 && | |
|
msramek
2015/11/27 16:30:04
Please add a comment what is happening here (maybe
johnme
2015/11/30 14:56:58
Done (in header declaration of helper function).
| |
| 169 ValueToContentSetting(value.get()) == CONTENT_SETTING_ALLOW) { | |
| 170 if (WebsiteSettingsRegistry::GetInstance()->Get(content_type) | |
| 171 ->incognito_behavior() | |
| 172 == WebsiteSettingsInfo::INHERIT_IN_INCOGNITO_EXCEPT_ALLOW) { | |
| 173 value = ContentSettingToValue(CONTENT_SETTING_ASK); | |
|
msramek
2015/11/27 16:30:04
As mentioned in HostContentSettingsMap, please DCH
johnme
2015/11/30 14:56:58
Done - HostContentSettingsMap::CoerceSettingInheri
| |
| 174 } | |
| 175 } | |
| 176 return value; | |
| 166 } | 177 } |
| 167 | 178 |
| 168 base::Value* GetContentSettingValueAndPatterns( | 179 scoped_ptr<base::Value> GetContentSettingValueAndPatterns( |
| 169 RuleIterator* rule_iterator, | 180 RuleIterator* rule_iterator, |
| 170 const GURL& primary_url, | 181 const GURL& primary_url, |
| 171 const GURL& secondary_url, | 182 const GURL& secondary_url, |
| 172 ContentSettingsPattern* primary_pattern, | 183 ContentSettingsPattern* primary_pattern, |
| 173 ContentSettingsPattern* secondary_pattern) { | 184 ContentSettingsPattern* secondary_pattern) { |
| 174 while (rule_iterator->HasNext()) { | 185 while (rule_iterator->HasNext()) { |
| 175 const Rule& rule = rule_iterator->Next(); | 186 const Rule& rule = rule_iterator->Next(); |
| 176 if (rule.primary_pattern.Matches(primary_url) && | 187 if (rule.primary_pattern.Matches(primary_url) && |
| 177 rule.secondary_pattern.Matches(secondary_url)) { | 188 rule.secondary_pattern.Matches(secondary_url)) { |
| 178 if (primary_pattern) | 189 if (primary_pattern) |
| 179 *primary_pattern = rule.primary_pattern; | 190 *primary_pattern = rule.primary_pattern; |
| 180 if (secondary_pattern) | 191 if (secondary_pattern) |
| 181 *secondary_pattern = rule.secondary_pattern; | 192 *secondary_pattern = rule.secondary_pattern; |
| 182 return rule.value.get()->DeepCopy(); | 193 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
| 183 } | 194 } |
| 184 } | 195 } |
| 185 return NULL; | 196 return scoped_ptr<base::Value>(); |
| 186 } | 197 } |
| 187 | 198 |
| 188 void GetRendererContentSettingRules(const HostContentSettingsMap* map, | 199 void GetRendererContentSettingRules(const HostContentSettingsMap* map, |
| 189 RendererContentSettingRules* rules) { | 200 RendererContentSettingRules* rules) { |
| 190 map->GetSettingsForOneType( | 201 map->GetSettingsForOneType( |
| 191 CONTENT_SETTINGS_TYPE_IMAGES, | 202 CONTENT_SETTINGS_TYPE_IMAGES, |
| 192 ResourceIdentifier(), | 203 ResourceIdentifier(), |
| 193 &(rules->image_rules)); | 204 &(rules->image_rules)); |
| 194 map->GetSettingsForOneType( | 205 map->GetSettingsForOneType( |
| 195 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 206 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 196 ResourceIdentifier(), | 207 ResourceIdentifier(), |
| 197 &(rules->script_rules)); | 208 &(rules->script_rules)); |
| 198 } | 209 } |
| 199 | 210 |
| 200 } // namespace content_settings | 211 } // namespace content_settings |
| OLD | NEW |