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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 false); | 203 false); |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 void HostContentSettingsMap::SetDefaultContentSetting( | 207 void HostContentSettingsMap::SetDefaultContentSetting( |
208 ContentSettingsType content_type, | 208 ContentSettingsType content_type, |
209 ContentSetting setting) { | 209 ContentSetting setting) { |
210 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | 210 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); |
211 DCHECK(IsSettingAllowedForType(setting, content_type)); | 211 DCHECK(IsSettingAllowedForType(setting, content_type)); |
212 | 212 |
213 content_settings_providers_[DEFAULT_PROVIDER]->SetContentSetting( | 213 base::Value* value = Value::CreateIntegerValue(setting); |
| 214 content_settings_providers_[DEFAULT_PROVIDER]->SetWebsiteSetting( |
214 ContentSettingsPattern::Wildcard(), | 215 ContentSettingsPattern::Wildcard(), |
215 ContentSettingsPattern::Wildcard(), | 216 ContentSettingsPattern::Wildcard(), |
216 content_type, | 217 content_type, |
217 std::string(), | 218 std::string(), |
218 setting); | 219 value); |
| 220 } |
| 221 |
| 222 void HostContentSettingsMap::SetWebsiteSetting( |
| 223 const ContentSettingsPattern& primary_pattern, |
| 224 const ContentSettingsPattern& secondary_pattern, |
| 225 ContentSettingsType content_type, |
| 226 const std::string& resource_identifier, |
| 227 base::Value* value) { |
| 228 DCHECK(IsValueAllowedForType(value, content_type)); |
| 229 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || |
| 230 resource_identifier.empty()); |
| 231 for (ProviderIterator provider = content_settings_providers_.begin(); |
| 232 provider != content_settings_providers_.end(); |
| 233 ++provider) { |
| 234 if (provider->second->SetWebsiteSetting(primary_pattern, |
| 235 secondary_pattern, |
| 236 content_type, |
| 237 resource_identifier, |
| 238 value)) { |
| 239 return; |
| 240 } |
| 241 } |
| 242 NOTREACHED(); |
219 } | 243 } |
220 | 244 |
221 void HostContentSettingsMap::SetContentSetting( | 245 void HostContentSettingsMap::SetContentSetting( |
222 const ContentSettingsPattern& primary_pattern, | 246 const ContentSettingsPattern& primary_pattern, |
223 const ContentSettingsPattern& secondary_pattern, | 247 const ContentSettingsPattern& secondary_pattern, |
224 ContentSettingsType content_type, | 248 ContentSettingsType content_type, |
225 const std::string& resource_identifier, | 249 const std::string& resource_identifier, |
226 ContentSetting setting) { | 250 ContentSetting setting) { |
227 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | 251 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); |
228 DCHECK(IsSettingAllowedForType(setting, content_type)); | 252 base::Value* value = NULL; |
229 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 253 if (setting != CONTENT_SETTING_DEFAULT) |
230 resource_identifier.empty()); | 254 value = Value::CreateIntegerValue(setting); |
231 for (ProviderIterator provider = content_settings_providers_.begin(); | 255 SetWebsiteSetting(primary_pattern, |
232 provider != content_settings_providers_.end(); | 256 secondary_pattern, |
233 ++provider) { | 257 content_type, |
234 provider->second->SetContentSetting( | 258 resource_identifier, |
235 primary_pattern, | 259 value); |
236 secondary_pattern, | |
237 content_type, | |
238 resource_identifier, | |
239 setting); | |
240 } | |
241 } | 260 } |
242 | 261 |
243 void HostContentSettingsMap::AddExceptionForURL( | 262 void HostContentSettingsMap::AddExceptionForURL( |
244 const GURL& primary_url, | 263 const GURL& primary_url, |
245 const GURL& secondary_url, | 264 const GURL& secondary_url, |
246 ContentSettingsType content_type, | 265 ContentSettingsType content_type, |
247 const std::string& resource_identifier, | 266 const std::string& resource_identifier, |
248 ContentSetting setting) { | 267 ContentSetting setting) { |
249 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must | 268 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must |
250 // match. | 269 // match. |
(...skipping 16 matching lines...) Expand all Loading... |
267 | 286 |
268 void HostContentSettingsMap::ClearSettingsForOneType( | 287 void HostContentSettingsMap::ClearSettingsForOneType( |
269 ContentSettingsType content_type) { | 288 ContentSettingsType content_type) { |
270 for (ProviderIterator provider = content_settings_providers_.begin(); | 289 for (ProviderIterator provider = content_settings_providers_.begin(); |
271 provider != content_settings_providers_.end(); | 290 provider != content_settings_providers_.end(); |
272 ++provider) { | 291 ++provider) { |
273 provider->second->ClearAllContentSettingsRules(content_type); | 292 provider->second->ClearAllContentSettingsRules(content_type); |
274 } | 293 } |
275 } | 294 } |
276 | 295 |
| 296 bool HostContentSettingsMap::IsValueAllowedForType( |
| 297 const base::Value* value, ContentSettingsType type) { |
| 298 return IsSettingAllowedForType( |
| 299 content_settings::ValueToContentSetting(value), type); |
| 300 } |
| 301 |
277 // static | 302 // static |
278 bool HostContentSettingsMap::IsSettingAllowedForType( | 303 bool HostContentSettingsMap::IsSettingAllowedForType( |
279 ContentSetting setting, ContentSettingsType content_type) { | 304 ContentSetting setting, ContentSettingsType content_type) { |
280 // Intents content settings are hidden behind a switch for now. | 305 // Intents content settings are hidden behind a switch for now. |
281 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS && | 306 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS && |
282 !CommandLine::ForCurrentProcess()->HasSwitch( | 307 !CommandLine::ForCurrentProcess()->HasSwitch( |
283 switches::kEnableWebIntents)) | 308 switches::kEnableWebIntents)) |
284 return false; | 309 return false; |
285 | 310 |
286 // DEFAULT, ALLOW and BLOCK are always allowed. | 311 // DEFAULT, ALLOW and BLOCK are always allowed. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 442 } |
418 } | 443 } |
419 | 444 |
420 if (info) { | 445 if (info) { |
421 info->source = content_settings::SETTING_SOURCE_NONE; | 446 info->source = content_settings::SETTING_SOURCE_NONE; |
422 info->primary_pattern = ContentSettingsPattern(); | 447 info->primary_pattern = ContentSettingsPattern(); |
423 info->secondary_pattern = ContentSettingsPattern(); | 448 info->secondary_pattern = ContentSettingsPattern(); |
424 } | 449 } |
425 return NULL; | 450 return NULL; |
426 } | 451 } |
OLD | NEW |