OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/content_settings/content_settings_extension_provider.h" | 10 #include "chrome/browser/content_settings/content_settings_extension_provider.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 url, ContentSettingsType(j) , ""); | 253 url, ContentSettingsType(j) , ""); |
254 } | 254 } |
255 return output; | 255 return output; |
256 } | 256 } |
257 | 257 |
258 void HostContentSettingsMap::GetSettingsForOneType( | 258 void HostContentSettingsMap::GetSettingsForOneType( |
259 ContentSettingsType content_type, | 259 ContentSettingsType content_type, |
260 const std::string& resource_identifier, | 260 const std::string& resource_identifier, |
261 SettingsForOneType* settings) const { | 261 SettingsForOneType* settings) const { |
262 DCHECK(settings); | 262 DCHECK(settings); |
263 settings->clear(); | |
264 | |
265 // Collect content_settings::Rules for the given content_type and | 263 // Collect content_settings::Rules for the given content_type and |
266 // resource_identifier from the content settings providers. | 264 // resource_identifier from the content settings providers. |
267 Rules content_settings_rules; | 265 std::map<std::string, PatternSettingPair> |
| 266 pattern_str_pattern_setting_pair_map; |
268 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 267 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
269 provider != content_settings_providers_.end(); | 268 provider != content_settings_providers_.end(); |
270 ++provider) { | 269 ++provider) { |
271 // TODO(markusheintz): Only the rules that are applied should be collected. | |
272 // Merge rules. | |
273 // TODO(markusheintz): GetAllContentSettingsRules should maybe not clear the | |
274 // passed vector in case rule sets are just unified. | |
275 Rules rules; | 270 Rules rules; |
276 (*provider)->GetAllContentSettingsRules( | 271 (*provider)->GetAllContentSettingsRules( |
277 content_type, resource_identifier, &rules); | 272 content_type, resource_identifier, &rules); |
278 content_settings_rules.insert(content_settings_rules.end(), | 273 // TODO(markusheintz): Only the rules that are applied should be collected. |
279 rules.begin(), | 274 for (Rules::iterator rule = rules.begin(); |
280 rules.end()); | 275 rule != rules.end(); |
| 276 ++rule) { |
| 277 const ContentSettingsPattern& pattern(rule->requesting_url_pattern); |
| 278 pattern_str_pattern_setting_pair_map[pattern.ToString()] = |
| 279 PatternSettingPair(pattern, rule->content_setting); |
| 280 } |
281 } | 281 } |
282 | 282 |
283 // convert Rules to SettingsForOneType | 283 settings->clear(); |
284 for (const_rules_iterator rule_iterator = | 284 // Rely on the maps iterator to sort the rules. |
285 content_settings_rules.begin(); | 285 for (std::map<std::string, PatternSettingPair>::iterator i( |
286 rule_iterator != content_settings_rules.end(); | 286 pattern_str_pattern_setting_pair_map.begin()); |
287 ++rule_iterator) { | 287 i != pattern_str_pattern_setting_pair_map.end(); |
288 settings->push_back(std::make_pair(ContentSettingsPattern( | 288 ++i) { |
289 rule_iterator->requesting_url_pattern), | 289 settings->push_back(i->second); |
290 rule_iterator->content_setting)); | |
291 } | 290 } |
292 } | 291 } |
293 | 292 |
294 void HostContentSettingsMap::SetDefaultContentSetting( | 293 void HostContentSettingsMap::SetDefaultContentSetting( |
295 ContentSettingsType content_type, | 294 ContentSettingsType content_type, |
296 ContentSetting setting) { | 295 ContentSetting setting) { |
297 for (DefaultProviderIterator provider = | 296 for (DefaultProviderIterator provider = |
298 default_content_settings_providers_.begin(); | 297 default_content_settings_providers_.begin(); |
299 provider != default_content_settings_providers_.end(); ++provider) { | 298 provider != default_content_settings_providers_.end(); ++provider) { |
300 (*provider)->UpdateDefaultSetting(content_type, setting); | 299 (*provider)->UpdateDefaultSetting(content_type, setting); |
(...skipping 13 matching lines...) Expand all Loading... |
314 } | 313 } |
315 } | 314 } |
316 | 315 |
317 void HostContentSettingsMap::AddExceptionForURL( | 316 void HostContentSettingsMap::AddExceptionForURL( |
318 const GURL& url, | 317 const GURL& url, |
319 ContentSettingsType content_type, | 318 ContentSettingsType content_type, |
320 const std::string& resource_identifier, | 319 const std::string& resource_identifier, |
321 ContentSetting setting) { | 320 ContentSetting setting) { |
322 // Make sure there is no entry that would override the pattern we are about | 321 // Make sure there is no entry that would override the pattern we are about |
323 // to insert for exactly this URL. | 322 // to insert for exactly this URL. |
324 SetContentSetting(ContentSettingsPattern::LegacyFromURLNoWildcard(url), | 323 SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(url), |
325 content_type, | 324 content_type, |
326 resource_identifier, | 325 resource_identifier, |
327 CONTENT_SETTING_DEFAULT); | 326 CONTENT_SETTING_DEFAULT); |
328 SetContentSetting(ContentSettingsPattern::LegacyFromURL(url), | 327 SetContentSetting(ContentSettingsPattern::FromURL(url), |
329 content_type, | 328 content_type, |
330 resource_identifier, | 329 resource_identifier, |
331 setting); | 330 setting); |
332 } | 331 } |
333 | 332 |
334 void HostContentSettingsMap::ClearSettingsForOneType( | 333 void HostContentSettingsMap::ClearSettingsForOneType( |
335 ContentSettingsType content_type) { | 334 ContentSettingsType content_type) { |
336 for (ProviderIterator provider = content_settings_providers_.begin(); | 335 for (ProviderIterator provider = content_settings_providers_.begin(); |
337 provider != content_settings_providers_.end(); | 336 provider != content_settings_providers_.end(); |
338 ++provider) { | 337 ++provider) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 461 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
463 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | 462 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? |
464 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | 463 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); |
465 } | 464 } |
466 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | 465 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { |
467 SetBlockThirdPartyCookies(cookie_behavior == | 466 SetBlockThirdPartyCookies(cookie_behavior == |
468 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 467 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
469 } | 468 } |
470 } | 469 } |
471 } | 470 } |
OLD | NEW |