Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map.cc

Issue 10537099: add "always allow" option to the mediastream infobar and allow user to allow/not allow acces to devi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use only content settings, added a device controller, addressed all the comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 content_settings::SETTING_SOURCE_USER, 63 content_settings::SETTING_SOURCE_USER,
64 }; 64 };
65 COMPILE_ASSERT(arraysize(kProviderSourceMap) == 65 COMPILE_ASSERT(arraysize(kProviderSourceMap) ==
66 HostContentSettingsMap::NUM_PROVIDER_TYPES, 66 HostContentSettingsMap::NUM_PROVIDER_TYPES,
67 kProviderSourceMap_has_incorrect_size); 67 kProviderSourceMap_has_incorrect_size);
68 68
69 bool ContentTypeHasCompoundValue(ContentSettingsType type) { 69 bool ContentTypeHasCompoundValue(ContentSettingsType type) {
70 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are 70 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are
71 // of type dictionary/map. Compound types like dictionaries can't be mapped to 71 // of type dictionary/map. Compound types like dictionaries can't be mapped to
72 // the type |ContentSetting|. 72 // the type |ContentSetting|.
73 return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE; 73 return (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE ||
74 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM);
74 } 75 }
75 76
76 // Returns true if the |content_type| supports a resource identifier. 77 // Returns true if the |content_type| supports a resource identifier.
77 // Resource identifiers are supported (but not required) for plug-ins. 78 // Resource identifiers are supported (but not required) for plug-ins.
78 bool SupportsResourceIdentifier(ContentSettingsType content_type) { 79 bool SupportsResourceIdentifier(ContentSettingsType content_type) {
79 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; 80 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS;
80 } 81 }
81 82
82 } // namespace 83 } // namespace
83 84
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 rule.secondary_pattern == wildcard) { 179 rule.secondary_pattern == wildcard) {
179 return content_settings::ValueToContentSetting(rule.value.get()); 180 return content_settings::ValueToContentSetting(rule.value.get());
180 } 181 }
181 } 182 }
182 return CONTENT_SETTING_DEFAULT; 183 return CONTENT_SETTING_DEFAULT;
183 } 184 }
184 185
185 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( 186 ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
186 ContentSettingsType content_type, 187 ContentSettingsType content_type,
187 std::string* provider_id) const { 188 std::string* provider_id) const {
188 DCHECK(!ContentTypeHasCompoundValue(content_type));
Bernhard Bauer 2012/06/18 17:38:14 Are you sure about this? This method is supposed t
no longer working on chromium 2012/06/19 12:23:16 I assume the default values are only "ask/allow/bl
Bernhard Bauer 2012/06/19 14:33:34 Hm, ok. I guess it's fair to say that a content ty
189
190 // Iterate through the list of providers and return the first non-NULL value 189 // Iterate through the list of providers and return the first non-NULL value
191 // that matches |primary_url| and |secondary_url|. 190 // that matches |primary_url| and |secondary_url|.
192 for (ConstProviderIterator provider = content_settings_providers_.begin(); 191 for (ConstProviderIterator provider = content_settings_providers_.begin();
193 provider != content_settings_providers_.end(); 192 provider != content_settings_providers_.end();
194 ++provider) { 193 ++provider) {
195 if (provider->first == PREF_PROVIDER) 194 if (provider->first == PREF_PROVIDER)
196 continue; 195 continue;
197 ContentSetting default_setting = 196 ContentSetting default_setting =
198 GetDefaultContentSettingFromProvider(content_type, provider->second); 197 GetDefaultContentSettingFromProvider(content_type, provider->second);
199 if (default_setting != CONTENT_SETTING_DEFAULT) { 198 if (default_setting != CONTENT_SETTING_DEFAULT) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 content_type, 247 content_type,
249 resource_identifier, 248 resource_identifier,
250 settings, 249 settings,
251 false); 250 false);
252 } 251 }
253 } 252 }
254 253
255 void HostContentSettingsMap::SetDefaultContentSetting( 254 void HostContentSettingsMap::SetDefaultContentSetting(
256 ContentSettingsType content_type, 255 ContentSettingsType content_type,
257 ContentSetting setting) { 256 ContentSetting setting) {
258 DCHECK(!ContentTypeHasCompoundValue(content_type));
Bernhard Bauer 2012/06/18 17:38:14 In this case it's easier; we can replace calls to
no longer working on chromium 2012/06/19 12:23:16 See reply above.
259 DCHECK(IsSettingAllowedForType(prefs_, setting, content_type)); 257 DCHECK(IsSettingAllowedForType(prefs_, setting, content_type));
260 258
261 base::Value* value = NULL; 259 base::Value* value = NULL;
262 if (setting != CONTENT_SETTING_DEFAULT) 260 if (setting != CONTENT_SETTING_DEFAULT)
263 value = Value::CreateIntegerValue(setting); 261 value = Value::CreateIntegerValue(setting);
264 SetWebsiteSetting( 262 SetWebsiteSetting(
265 ContentSettingsPattern::Wildcard(), 263 ContentSettingsPattern::Wildcard(),
266 ContentSettingsPattern::Wildcard(), 264 ContentSettingsPattern::Wildcard(),
267 content_type, 265 content_type,
268 std::string(), 266 std::string(),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 ContentSettingsType content_type) { 337 ContentSettingsType content_type) {
340 for (ProviderIterator provider = content_settings_providers_.begin(); 338 for (ProviderIterator provider = content_settings_providers_.begin();
341 provider != content_settings_providers_.end(); 339 provider != content_settings_providers_.end();
342 ++provider) { 340 ++provider) {
343 provider->second->ClearAllContentSettingsRules(content_type); 341 provider->second->ClearAllContentSettingsRules(content_type);
344 } 342 }
345 } 343 }
346 344
347 bool HostContentSettingsMap::IsValueAllowedForType( 345 bool HostContentSettingsMap::IsValueAllowedForType(
348 PrefService* prefs, const base::Value* value, ContentSettingsType type) { 346 PrefService* prefs, const base::Value* value, ContentSettingsType type) {
349 return IsSettingAllowedForType( 347 return ContentTypeHasCompoundValue(type) || IsSettingAllowedForType(
350 prefs, content_settings::ValueToContentSetting(value), type); 348 prefs, content_settings::ValueToContentSetting(value), type);
351 } 349 }
352 350
353 // static 351 // static
354 bool HostContentSettingsMap::IsSettingAllowedForType( 352 bool HostContentSettingsMap::IsSettingAllowedForType(
355 PrefService* prefs, 353 PrefService* prefs,
356 ContentSetting setting, 354 ContentSetting setting,
357 ContentSettingsType content_type) { 355 ContentSettingsType content_type) {
358 // Intents content settings are hidden behind a switch for now. 356 // Intents content settings are hidden behind a switch for now.
359 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS) { 357 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS) {
(...skipping 14 matching lines...) Expand all
374 return true; 372 return true;
375 } 373 }
376 switch (content_type) { 374 switch (content_type) {
377 case CONTENT_SETTINGS_TYPE_COOKIES: 375 case CONTENT_SETTINGS_TYPE_COOKIES:
378 return setting == CONTENT_SETTING_SESSION_ONLY; 376 return setting == CONTENT_SETTING_SESSION_ONLY;
379 case CONTENT_SETTINGS_TYPE_PLUGINS: 377 case CONTENT_SETTINGS_TYPE_PLUGINS:
380 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 378 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
381 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 379 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
382 case CONTENT_SETTINGS_TYPE_INTENTS: 380 case CONTENT_SETTINGS_TYPE_INTENTS:
383 case CONTENT_SETTINGS_TYPE_MOUSELOCK: 381 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
382 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
384 return setting == CONTENT_SETTING_ASK; 383 return setting == CONTENT_SETTING_ASK;
385 default: 384 default:
386 return false; 385 return false;
387 } 386 }
388 } 387 }
389 388
390 void HostContentSettingsMap::OnContentSettingChanged( 389 void HostContentSettingsMap::OnContentSettingChanged(
391 const ContentSettingsPattern& primary_pattern, 390 const ContentSettingsPattern& primary_pattern,
392 const ContentSettingsPattern& secondary_pattern, 391 const ContentSettingsPattern& secondary_pattern,
393 ContentSettingsType content_type, 392 ContentSettingsType content_type,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 ContentSettingsType content_type, 474 ContentSettingsType content_type,
476 const std::string& resource_identifier, 475 const std::string& resource_identifier,
477 ContentSettingsForOneType* settings, 476 ContentSettingsForOneType* settings,
478 bool incognito) const { 477 bool incognito) const {
479 scoped_ptr<content_settings::RuleIterator> rule_iterator( 478 scoped_ptr<content_settings::RuleIterator> rule_iterator(
480 provider->GetRuleIterator(content_type, 479 provider->GetRuleIterator(content_type,
481 resource_identifier, 480 resource_identifier,
482 incognito)); 481 incognito));
483 while (rule_iterator->HasNext()) { 482 while (rule_iterator->HasNext()) {
484 const content_settings::Rule& rule = rule_iterator->Next(); 483 const content_settings::Rule& rule = rule_iterator->Next();
484 ContentSetting setting_value = CONTENT_SETTING_DEFAULT;
Bernhard Bauer 2012/06/18 17:38:14 Can you add a TODO(bauerb) that we should return r
no longer working on chromium 2012/06/19 12:23:16 Done.
485 // For the cases using compound value, we assume it is valid as long as
486 // the value is not NULL.
487 if (ContentTypeHasCompoundValue(content_type) && rule.value.get()) {
488 setting_value = CONTENT_SETTING_ALLOW;
489 } else {
490 setting_value = content_settings::ValueToContentSetting(rule.value.get());
491 }
485 settings->push_back(ContentSettingPatternSource( 492 settings->push_back(ContentSettingPatternSource(
486 rule.primary_pattern, rule.secondary_pattern, 493 rule.primary_pattern, rule.secondary_pattern,
487 content_settings::ValueToContentSetting(rule.value.get()), 494 setting_value,
488 kProviderNames[provider_type], 495 kProviderNames[provider_type],
489 incognito)); 496 incognito));
490 } 497 }
491 } 498 }
492 499
493 bool HostContentSettingsMap::ShouldAllowAllContent( 500 bool HostContentSettingsMap::ShouldAllowAllContent(
494 const GURL& primary_url, 501 const GURL& primary_url,
495 const GURL& secondary_url, 502 const GURL& secondary_url,
496 ContentSettingsType content_type) { 503 ContentSettingsType content_type) {
497 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS || 504 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS ||
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 557 }
551 } 558 }
552 559
553 if (info) { 560 if (info) {
554 info->source = content_settings::SETTING_SOURCE_NONE; 561 info->source = content_settings::SETTING_SOURCE_NONE;
555 info->primary_pattern = ContentSettingsPattern(); 562 info->primary_pattern = ContentSettingsPattern();
556 info->secondary_pattern = ContentSettingsPattern(); 563 info->secondary_pattern = ContentSettingsPattern();
557 } 564 }
558 return NULL; 565 return NULL;
559 } 566 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698