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 <algorithm> | |
7 #include <list> | 8 #include <list> |
8 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/content_settings/content_settings_details.h" | 13 #include "chrome/browser/content_settings/content_settings_details.h" |
13 #include "chrome/browser/content_settings/content_settings_extension_provider.h" | 14 #include "chrome/browser/content_settings/content_settings_extension_provider.h" |
14 #include "chrome/browser/content_settings/content_settings_observable_provider.h " | 15 #include "chrome/browser/content_settings/content_settings_observable_provider.h " |
15 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 16 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
16 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 17 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 ContentSettingsType(j), | 341 ContentSettingsType(j), |
341 ""); | 342 ""); |
342 } | 343 } |
343 } | 344 } |
344 return output; | 345 return output; |
345 } | 346 } |
346 | 347 |
347 void HostContentSettingsMap::GetSettingsForOneType( | 348 void HostContentSettingsMap::GetSettingsForOneType( |
348 ContentSettingsType content_type, | 349 ContentSettingsType content_type, |
349 const std::string& resource_identifier, | 350 const std::string& resource_identifier, |
350 SettingsForOneType* settings) const { | 351 content_settings::ProviderInterface::Rule::SortFunction sort_function, |
352 ContentSettingsForOneType* settings) | |
Bernhard Bauer
2011/09/16 09:16:48
Nit: I think the |const| belongs on this line?
marja
2011/09/19 11:53:40
Done.
| |
353 const { | |
351 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), | 354 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), |
352 resource_identifier.empty()); | 355 resource_identifier.empty()); |
353 DCHECK(settings); | 356 DCHECK(settings); |
354 | 357 |
355 settings->clear(); | 358 settings->clear(); |
356 for (size_t i = 0; i < content_settings_providers_.size(); ++i) { | 359 for (size_t i = 0; i < content_settings_providers_.size(); ++i) { |
357 // Get rules from the content settings provider. | 360 // Get rules from the content settings provider. |
358 Rules rules; | 361 Rules rules_for_provider; |
359 content_settings_providers_[i]->GetAllContentSettingsRules( | 362 content_settings_providers_[i]->GetAllContentSettingsRules( |
360 content_type, resource_identifier, &rules); | 363 content_type, resource_identifier, &rules_for_provider); |
361 | 364 |
362 // Sort rules according to their primary-secondary pattern string pairs | 365 // The rules are returned in arbitrary order. Sort them according to the |
363 // using a map. | 366 // ContentSettingsPattern precedence relation. |
364 std::map<StringPair, PatternSettingSourceTuple> settings_map; | 367 if (sort_function) { |
365 for (Rules::iterator rule = rules.begin(); | 368 std::sort(rules_for_provider.begin(), rules_for_provider.end(), |
366 rule != rules.end(); | 369 sort_function); |
367 ++rule) { | |
368 StringPair sort_key(rule->primary_pattern.ToString(), | |
369 rule->secondary_pattern.ToString()); | |
370 settings_map[sort_key] = PatternSettingSourceTuple( | |
371 rule->primary_pattern, | |
372 rule->secondary_pattern, | |
373 rule->content_setting, | |
374 kProviderNames[i]); | |
375 } | 370 } |
376 | 371 |
377 // TODO(markusheintz): Only the rules that are applied should be added. | 372 // TODO(markusheintz): Only the rules that are applied should be added. |
378 for (std::map<StringPair, PatternSettingSourceTuple>::iterator i( | 373 for (Rules::const_iterator it = rules_for_provider.begin(); |
379 settings_map.begin()); | 374 it != rules_for_provider.end(); ++it) { |
380 i != settings_map.end(); | 375 settings->push_back(ContentSettingPatternSourceTuple( |
381 ++i) { | 376 it->primary_pattern, it->secondary_pattern, |
382 settings->push_back(i->second); | 377 it->content_setting, kProviderNames[i])); |
383 } | 378 } |
384 } | 379 } |
385 } | 380 } |
386 | 381 |
387 void HostContentSettingsMap::SetDefaultContentSetting( | 382 void HostContentSettingsMap::SetDefaultContentSetting( |
388 ContentSettingsType content_type, | 383 ContentSettingsType content_type, |
389 ContentSetting setting) { | 384 ContentSetting setting) { |
390 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | 385 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); |
391 DCHECK(IsSettingAllowedForType(setting, content_type)); | 386 DCHECK(IsSettingAllowedForType(setting, content_type)); |
392 for (DefaultProviderIterator provider = | 387 for (DefaultProviderIterator provider = |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 586 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
592 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | 587 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? |
593 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | 588 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); |
594 } | 589 } |
595 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | 590 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) { |
596 SetBlockThirdPartyCookies(cookie_behavior == | 591 SetBlockThirdPartyCookies(cookie_behavior == |
597 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 592 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
598 } | 593 } |
599 } | 594 } |
600 } | 595 } |
OLD | NEW |