| 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 | 5 |
| 6 #include "chrome/browser/content_settings/content_settings_base_provider.h" | 6 #include "chrome/browser/content_settings/content_settings_base_provider.h" |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 ExtendedContentSettings::ExtendedContentSettings() {} | 32 ExtendedContentSettings::ExtendedContentSettings() {} |
| 33 | 33 |
| 34 ExtendedContentSettings::ExtendedContentSettings( | 34 ExtendedContentSettings::ExtendedContentSettings( |
| 35 const ExtendedContentSettings& rhs) | 35 const ExtendedContentSettings& rhs) |
| 36 : content_settings(rhs.content_settings), | 36 : content_settings(rhs.content_settings), |
| 37 content_settings_for_resources(rhs.content_settings_for_resources) { | 37 content_settings_for_resources(rhs.content_settings_for_resources) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 ExtendedContentSettings::~ExtendedContentSettings() {} | 40 ExtendedContentSettings::~ExtendedContentSettings() {} |
| 41 | 41 |
| 42 BaseProvider::BaseProvider(bool is_otr) | 42 BaseProvider::BaseProvider(bool is_incognito) |
| 43 : is_off_the_record_(is_otr) { | 43 : is_incognito_(is_incognito) { |
| 44 } | 44 } |
| 45 | 45 |
| 46 BaseProvider::~BaseProvider() {} | 46 BaseProvider::~BaseProvider() {} |
| 47 | 47 |
| 48 bool BaseProvider::RequiresResourceIdentifier( | 48 bool BaseProvider::RequiresResourceIdentifier( |
| 49 ContentSettingsType content_type) const { | 49 ContentSettingsType content_type) const { |
| 50 if (CommandLine::ForCurrentProcess()->HasSwitch( | 50 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 51 switches::kEnableResourceContentSettings)) { | 51 switches::kEnableResourceContentSettings)) { |
| 52 return kRequiresResourceIdentifier[content_type]; | 52 return kRequiresResourceIdentifier[content_type]; |
| 53 } else { | 53 } else { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 72 // Support for embedding_patterns is not implemented yet. | 72 // Support for embedding_patterns is not implemented yet. |
| 73 DCHECK(requesting_url == embedding_url); | 73 DCHECK(requesting_url == embedding_url); |
| 74 | 74 |
| 75 if (!RequiresResourceIdentifier(content_type) || | 75 if (!RequiresResourceIdentifier(content_type) || |
| 76 (RequiresResourceIdentifier(content_type) && resource_identifier.empty())) | 76 (RequiresResourceIdentifier(content_type) && resource_identifier.empty())) |
| 77 return GetNonDefaultContentSettings(requesting_url).settings[content_type]; | 77 return GetNonDefaultContentSettings(requesting_url).settings[content_type]; |
| 78 | 78 |
| 79 // Resolve content settings with resource identifier. | 79 // Resolve content settings with resource identifier. |
| 80 // 1. Check for pattern that exactly match the url/host | 80 // 1. Check for pattern that exactly match the url/host |
| 81 // 1.1 In the content-settings-map | 81 // 1.1 In the content-settings-map |
| 82 // 1.2 In the off_the_record content-settings-map | 82 // 1.2 In the incognito content-settings-map |
| 83 // 3. Shorten the url subdomain by subdomain and try to find a pattern in | 83 // 3. Shorten the url subdomain by subdomain and try to find a pattern in |
| 84 // 3.1 OTR content-settings-map | 84 // 3.1 OTR content-settings-map |
| 85 // 3.2 content-settings-map | 85 // 3.2 content-settings-map |
| 86 base::AutoLock auto_lock(lock_); | 86 base::AutoLock auto_lock(lock_); |
| 87 const std::string host(net::GetHostOrSpecFromURL(requesting_url)); | 87 const std::string host(net::GetHostOrSpecFromURL(requesting_url)); |
| 88 ContentSettingsTypeResourceIdentifierPair | 88 ContentSettingsTypeResourceIdentifierPair |
| 89 requested_setting(content_type, resource_identifier); | 89 requested_setting(content_type, resource_identifier); |
| 90 | 90 |
| 91 // Check for exact matches first. | 91 // Check for exact matches first. |
| 92 HostContentSettings::const_iterator i(host_content_settings_.find(host)); | 92 HostContentSettings::const_iterator i(host_content_settings_.find(host)); |
| 93 if (i != host_content_settings_.end() && | 93 if (i != host_content_settings_.end() && |
| 94 i->second.content_settings_for_resources.find(requested_setting) != | 94 i->second.content_settings_for_resources.find(requested_setting) != |
| 95 i->second.content_settings_for_resources.end()) { | 95 i->second.content_settings_for_resources.end()) { |
| 96 return i->second.content_settings_for_resources.find( | 96 return i->second.content_settings_for_resources.find( |
| 97 requested_setting)->second; | 97 requested_setting)->second; |
| 98 } | 98 } |
| 99 | 99 |
| 100 // If this map is not for an incognito profile, these searches will never | 100 // If this map is not for an incognito profile, these searches will never |
| 101 // match. The additional incognito exceptions always overwrite the | 101 // match. The additional incognito exceptions always overwrite the |
| 102 // regular ones. | 102 // regular ones. |
| 103 i = off_the_record_settings_.find(host); | 103 i = incognito_settings_.find(host); |
| 104 if (i != off_the_record_settings_.end() && | 104 if (i != incognito_settings_.end() && |
| 105 i->second.content_settings_for_resources.find(requested_setting) != | 105 i->second.content_settings_for_resources.find(requested_setting) != |
| 106 i->second.content_settings_for_resources.end()) { | 106 i->second.content_settings_for_resources.end()) { |
| 107 return i->second.content_settings_for_resources.find( | 107 return i->second.content_settings_for_resources.find( |
| 108 requested_setting)->second; | 108 requested_setting)->second; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Match patterns starting with the most concrete pattern match. | 111 // Match patterns starting with the most concrete pattern match. |
| 112 for (std::string key = | 112 for (std::string key = |
| 113 std::string(ContentSettingsPattern::kDomainWildcard) + host; ; ) { | 113 std::string(ContentSettingsPattern::kDomainWildcard) + host; ; ) { |
| 114 HostContentSettings::const_iterator i(off_the_record_settings_.find(key)); | 114 HostContentSettings::const_iterator i(incognito_settings_.find(key)); |
| 115 if (i != off_the_record_settings_.end() && | 115 if (i != incognito_settings_.end() && |
| 116 i->second.content_settings_for_resources.find(requested_setting) != | 116 i->second.content_settings_for_resources.find(requested_setting) != |
| 117 i->second.content_settings_for_resources.end()) { | 117 i->second.content_settings_for_resources.end()) { |
| 118 return i->second.content_settings_for_resources.find( | 118 return i->second.content_settings_for_resources.find( |
| 119 requested_setting)->second; | 119 requested_setting)->second; |
| 120 } | 120 } |
| 121 | 121 |
| 122 i = host_content_settings_.find(key); | 122 i = host_content_settings_.find(key); |
| 123 if (i != host_content_settings_.end() && | 123 if (i != host_content_settings_.end() && |
| 124 i->second.content_settings_for_resources.find(requested_setting) != | 124 i->second.content_settings_for_resources.find(requested_setting) != |
| 125 i->second.content_settings_for_resources.end()) { | 125 i->second.content_settings_for_resources.end()) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 139 } | 139 } |
| 140 | 140 |
| 141 void BaseProvider::GetAllContentSettingsRules( | 141 void BaseProvider::GetAllContentSettingsRules( |
| 142 ContentSettingsType content_type, | 142 ContentSettingsType content_type, |
| 143 const ResourceIdentifier& resource_identifier, | 143 const ResourceIdentifier& resource_identifier, |
| 144 Rules* content_setting_rules) const { | 144 Rules* content_setting_rules) const { |
| 145 DCHECK(content_setting_rules); | 145 DCHECK(content_setting_rules); |
| 146 content_setting_rules->clear(); | 146 content_setting_rules->clear(); |
| 147 | 147 |
| 148 const HostContentSettings* map_to_return = | 148 const HostContentSettings* map_to_return = |
| 149 is_off_the_record_ ? &off_the_record_settings_ : &host_content_settings_; | 149 is_incognito_ ? &incognito_settings_ : &host_content_settings_; |
| 150 ContentSettingsTypeResourceIdentifierPair requested_setting( | 150 ContentSettingsTypeResourceIdentifierPair requested_setting( |
| 151 content_type, resource_identifier); | 151 content_type, resource_identifier); |
| 152 | 152 |
| 153 base::AutoLock auto_lock(lock_); | 153 base::AutoLock auto_lock(lock_); |
| 154 for (HostContentSettings::const_iterator i(map_to_return->begin()); | 154 for (HostContentSettings::const_iterator i(map_to_return->begin()); |
| 155 i != map_to_return->end(); ++i) { | 155 i != map_to_return->end(); ++i) { |
| 156 ContentSetting setting; | 156 ContentSetting setting; |
| 157 if (RequiresResourceIdentifier(content_type)) { | 157 if (RequiresResourceIdentifier(content_type)) { |
| 158 if (i->second.content_settings_for_resources.find(requested_setting) != | 158 if (i->second.content_settings_for_resources.find(requested_setting) != |
| 159 i->second.content_settings_for_resources.end()) { | 159 i->second.content_settings_for_resources.end()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 185 output.settings[j] = CONTENT_SETTING_DEFAULT; | 185 output.settings[j] = CONTENT_SETTING_DEFAULT; |
| 186 | 186 |
| 187 // Check for exact matches first. | 187 // Check for exact matches first. |
| 188 HostContentSettings::const_iterator i(host_content_settings_.find(host)); | 188 HostContentSettings::const_iterator i(host_content_settings_.find(host)); |
| 189 if (i != host_content_settings_.end()) | 189 if (i != host_content_settings_.end()) |
| 190 output = i->second.content_settings; | 190 output = i->second.content_settings; |
| 191 | 191 |
| 192 // If this map is not for an incognito profile, these searches will never | 192 // If this map is not for an incognito profile, these searches will never |
| 193 // match. The additional incognito exceptions always overwrite the | 193 // match. The additional incognito exceptions always overwrite the |
| 194 // regular ones. | 194 // regular ones. |
| 195 i = off_the_record_settings_.find(host); | 195 i = incognito_settings_.find(host); |
| 196 if (i != off_the_record_settings_.end()) { | 196 if (i != incognito_settings_.end()) { |
| 197 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) | 197 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) |
| 198 if (i->second.content_settings.settings[j] != CONTENT_SETTING_DEFAULT) | 198 if (i->second.content_settings.settings[j] != CONTENT_SETTING_DEFAULT) |
| 199 output.settings[j] = i->second.content_settings.settings[j]; | 199 output.settings[j] = i->second.content_settings.settings[j]; |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Match patterns starting with the most concrete pattern match. | 202 // Match patterns starting with the most concrete pattern match. |
| 203 for (std::string key = | 203 for (std::string key = |
| 204 std::string(ContentSettingsPattern::kDomainWildcard) + host; ; ) { | 204 std::string(ContentSettingsPattern::kDomainWildcard) + host; ; ) { |
| 205 HostContentSettings::const_iterator i(off_the_record_settings_.find(key)); | 205 HostContentSettings::const_iterator i(incognito_settings_.find(key)); |
| 206 if (i != off_the_record_settings_.end()) { | 206 if (i != incognito_settings_.end()) { |
| 207 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { | 207 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
| 208 if (output.settings[j] == CONTENT_SETTING_DEFAULT) | 208 if (output.settings[j] == CONTENT_SETTING_DEFAULT) |
| 209 output.settings[j] = i->second.content_settings.settings[j]; | 209 output.settings[j] = i->second.content_settings.settings[j]; |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 i = host_content_settings_.find(key); | 212 i = host_content_settings_.find(key); |
| 213 if (i != host_content_settings_.end()) { | 213 if (i != host_content_settings_.end()) { |
| 214 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { | 214 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
| 215 if (output.settings[j] == CONTENT_SETTING_DEFAULT) | 215 if (output.settings[j] == CONTENT_SETTING_DEFAULT) |
| 216 output.settings[j] = i->second.content_settings.settings[j]; | 216 output.settings[j] = i->second.content_settings.settings[j]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 246 if (setting == CONTENT_SETTING_ASK && | 246 if (setting == CONTENT_SETTING_ASK && |
| 247 content_type == CONTENT_SETTINGS_TYPE_PLUGINS && | 247 content_type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 248 !CommandLine::ForCurrentProcess()->HasSwitch( | 248 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 249 switches::kEnableClickToPlay)) { | 249 switches::kEnableClickToPlay)) { |
| 250 return CONTENT_SETTING_BLOCK; | 250 return CONTENT_SETTING_BLOCK; |
| 251 } | 251 } |
| 252 return setting; | 252 return setting; |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace content_settings | 255 } // namespace content_settings |
| OLD | NEW |