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; |
Michael van Ouwerkerk
2015/11/26 18:51:06
I'm wondering whether this should be "return std::
johnme
2015/11/27 14:12:28
Based on "Once you call return on an object, the n
| |
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 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); | |
174 } | |
175 return value; | |
166 } | 176 } |
167 | 177 |
168 base::Value* GetContentSettingValueAndPatterns( | 178 scoped_ptr<base::Value> GetContentSettingValueAndPatterns( |
169 RuleIterator* rule_iterator, | 179 RuleIterator* rule_iterator, |
170 const GURL& primary_url, | 180 const GURL& primary_url, |
171 const GURL& secondary_url, | 181 const GURL& secondary_url, |
172 ContentSettingsPattern* primary_pattern, | 182 ContentSettingsPattern* primary_pattern, |
173 ContentSettingsPattern* secondary_pattern) { | 183 ContentSettingsPattern* secondary_pattern) { |
174 while (rule_iterator->HasNext()) { | 184 while (rule_iterator->HasNext()) { |
175 const Rule& rule = rule_iterator->Next(); | 185 const Rule& rule = rule_iterator->Next(); |
176 if (rule.primary_pattern.Matches(primary_url) && | 186 if (rule.primary_pattern.Matches(primary_url) && |
177 rule.secondary_pattern.Matches(secondary_url)) { | 187 rule.secondary_pattern.Matches(secondary_url)) { |
178 if (primary_pattern) | 188 if (primary_pattern) |
179 *primary_pattern = rule.primary_pattern; | 189 *primary_pattern = rule.primary_pattern; |
180 if (secondary_pattern) | 190 if (secondary_pattern) |
181 *secondary_pattern = rule.secondary_pattern; | 191 *secondary_pattern = rule.secondary_pattern; |
182 return rule.value.get()->DeepCopy(); | 192 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
183 } | 193 } |
184 } | 194 } |
185 return NULL; | 195 return scoped_ptr<base::Value>(); |
186 } | 196 } |
187 | 197 |
188 void GetRendererContentSettingRules(const HostContentSettingsMap* map, | 198 void GetRendererContentSettingRules(const HostContentSettingsMap* map, |
189 RendererContentSettingRules* rules) { | 199 RendererContentSettingRules* rules) { |
190 map->GetSettingsForOneType( | 200 map->GetSettingsForOneType( |
191 CONTENT_SETTINGS_TYPE_IMAGES, | 201 CONTENT_SETTINGS_TYPE_IMAGES, |
192 ResourceIdentifier(), | 202 ResourceIdentifier(), |
193 &(rules->image_rules)); | 203 &(rules->image_rules)); |
194 map->GetSettingsForOneType( | 204 map->GetSettingsForOneType( |
195 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 205 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
196 ResourceIdentifier(), | 206 ResourceIdentifier(), |
197 &(rules->script_rules)); | 207 &(rules->script_rules)); |
198 } | 208 } |
199 | 209 |
200 } // namespace content_settings | 210 } // namespace content_settings |
OLD | NEW |