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

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: addressed comments from joaodasilva and bauerb, added support to Incognito mode. 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 content_settings::SETTING_SOURCE_EXTENSION, 59 content_settings::SETTING_SOURCE_EXTENSION,
60 content_settings::SETTING_SOURCE_POLICY, 60 content_settings::SETTING_SOURCE_POLICY,
61 content_settings::SETTING_SOURCE_EXTENSION, 61 content_settings::SETTING_SOURCE_EXTENSION,
62 content_settings::SETTING_SOURCE_USER, 62 content_settings::SETTING_SOURCE_USER,
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) {
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
72 // the type |ContentSetting|.
73 return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE;
74 }
75
76 // Returns true if the |content_type| supports a resource identifier. 69 // Returns true if the |content_type| supports a resource identifier.
77 // Resource identifiers are supported (but not required) for plug-ins. 70 // Resource identifiers are supported (but not required) for plug-ins.
78 bool SupportsResourceIdentifier(ContentSettingsType content_type) { 71 bool SupportsResourceIdentifier(ContentSettingsType content_type) {
79 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; 72 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS;
80 } 73 }
81 74
82 } // namespace 75 } // namespace
83 76
84 HostContentSettingsMap::HostContentSettingsMap( 77 HostContentSettingsMap::HostContentSettingsMap(
85 PrefService* prefs, 78 PrefService* prefs,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 rule.secondary_pattern == wildcard) { 153 rule.secondary_pattern == wildcard) {
161 return content_settings::ValueToContentSetting(rule.value.get()); 154 return content_settings::ValueToContentSetting(rule.value.get());
162 } 155 }
163 } 156 }
164 return CONTENT_SETTING_DEFAULT; 157 return CONTENT_SETTING_DEFAULT;
165 } 158 }
166 159
167 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( 160 ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
168 ContentSettingsType content_type, 161 ContentSettingsType content_type,
169 std::string* provider_id) const { 162 std::string* provider_id) const {
170 DCHECK(!ContentTypeHasCompoundValue(content_type));
171
172 // Iterate through the list of providers and return the first non-NULL value 163 // Iterate through the list of providers and return the first non-NULL value
173 // that matches |primary_url| and |secondary_url|. 164 // that matches |primary_url| and |secondary_url|.
174 for (ConstProviderIterator provider = content_settings_providers_.begin(); 165 for (ConstProviderIterator provider = content_settings_providers_.begin();
175 provider != content_settings_providers_.end(); 166 provider != content_settings_providers_.end();
176 ++provider) { 167 ++provider) {
177 if (provider->first == PREF_PROVIDER) 168 if (provider->first == PREF_PROVIDER)
178 continue; 169 continue;
179 ContentSetting default_setting = 170 ContentSetting default_setting =
180 GetDefaultContentSettingFromProvider(content_type, provider->second); 171 GetDefaultContentSettingFromProvider(content_type, provider->second);
181 if (default_setting != CONTENT_SETTING_DEFAULT) { 172 if (default_setting != CONTENT_SETTING_DEFAULT) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 content_type, 221 content_type,
231 resource_identifier, 222 resource_identifier,
232 settings, 223 settings,
233 false); 224 false);
234 } 225 }
235 } 226 }
236 227
237 void HostContentSettingsMap::SetDefaultContentSetting( 228 void HostContentSettingsMap::SetDefaultContentSetting(
238 ContentSettingsType content_type, 229 ContentSettingsType content_type,
239 ContentSetting setting) { 230 ContentSetting setting) {
240 DCHECK(!ContentTypeHasCompoundValue(content_type));
241 DCHECK(IsSettingAllowedForType(prefs_, setting, content_type)); 231 DCHECK(IsSettingAllowedForType(prefs_, setting, content_type));
242 232
243 base::Value* value = NULL; 233 base::Value* value = NULL;
244 if (setting != CONTENT_SETTING_DEFAULT) 234 if (setting != CONTENT_SETTING_DEFAULT)
245 value = Value::CreateIntegerValue(setting); 235 value = Value::CreateIntegerValue(setting);
246 SetWebsiteSetting( 236 SetWebsiteSetting(
247 ContentSettingsPattern::Wildcard(), 237 ContentSettingsPattern::Wildcard(),
248 ContentSettingsPattern::Wildcard(), 238 ContentSettingsPattern::Wildcard(),
249 content_type, 239 content_type,
250 std::string(), 240 std::string(),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 ContentSettingsType content_type) { 311 ContentSettingsType content_type) {
322 for (ProviderIterator provider = content_settings_providers_.begin(); 312 for (ProviderIterator provider = content_settings_providers_.begin();
323 provider != content_settings_providers_.end(); 313 provider != content_settings_providers_.end();
324 ++provider) { 314 ++provider) {
325 provider->second->ClearAllContentSettingsRules(content_type); 315 provider->second->ClearAllContentSettingsRules(content_type);
326 } 316 }
327 } 317 }
328 318
329 bool HostContentSettingsMap::IsValueAllowedForType( 319 bool HostContentSettingsMap::IsValueAllowedForType(
330 PrefService* prefs, const base::Value* value, ContentSettingsType type) { 320 PrefService* prefs, const base::Value* value, ContentSettingsType type) {
331 return IsSettingAllowedForType( 321 return ContentTypeHasCompoundValue(type) || IsSettingAllowedForType(
332 prefs, content_settings::ValueToContentSetting(value), type); 322 prefs, content_settings::ValueToContentSetting(value), type);
333 } 323 }
334 324
335 // static 325 // static
336 bool HostContentSettingsMap::IsSettingAllowedForType( 326 bool HostContentSettingsMap::IsSettingAllowedForType(
337 PrefService* prefs, 327 PrefService* prefs,
338 ContentSetting setting, 328 ContentSetting setting,
339 ContentSettingsType content_type) { 329 ContentSettingsType content_type) {
340 // Intents content settings are hidden behind a switch for now. 330 // Intents content settings are hidden behind a switch for now.
341 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS) { 331 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS) {
(...skipping 14 matching lines...) Expand all
356 return true; 346 return true;
357 } 347 }
358 switch (content_type) { 348 switch (content_type) {
359 case CONTENT_SETTINGS_TYPE_COOKIES: 349 case CONTENT_SETTINGS_TYPE_COOKIES:
360 return setting == CONTENT_SETTING_SESSION_ONLY; 350 return setting == CONTENT_SETTING_SESSION_ONLY;
361 case CONTENT_SETTINGS_TYPE_PLUGINS: 351 case CONTENT_SETTINGS_TYPE_PLUGINS:
362 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 352 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
363 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 353 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
364 case CONTENT_SETTINGS_TYPE_INTENTS: 354 case CONTENT_SETTINGS_TYPE_INTENTS:
365 case CONTENT_SETTINGS_TYPE_MOUSELOCK: 355 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
356 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
366 return setting == CONTENT_SETTING_ASK; 357 return setting == CONTENT_SETTING_ASK;
367 default: 358 default:
368 return false; 359 return false;
369 } 360 }
370 } 361 }
371 362
363 // static
364 bool HostContentSettingsMap::ContentTypeHasCompoundValue(
365 ContentSettingsType type) {
366 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are
367 // of type dictionary/map. Compound types like dictionaries can't be mapped to
368 // the type |ContentSetting|.
369 return (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE ||
370 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM);
371 }
372
372 void HostContentSettingsMap::OnContentSettingChanged( 373 void HostContentSettingsMap::OnContentSettingChanged(
373 const ContentSettingsPattern& primary_pattern, 374 const ContentSettingsPattern& primary_pattern,
374 const ContentSettingsPattern& secondary_pattern, 375 const ContentSettingsPattern& secondary_pattern,
375 ContentSettingsType content_type, 376 ContentSettingsType content_type,
376 std::string resource_identifier) { 377 std::string resource_identifier) {
377 const ContentSettingsDetails details(primary_pattern, 378 const ContentSettingsDetails details(primary_pattern,
378 secondary_pattern, 379 secondary_pattern,
379 content_type, 380 content_type,
380 resource_identifier); 381 resource_identifier);
381 content::NotificationService::current()->Notify( 382 content::NotificationService::current()->Notify(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 ContentSettingsType content_type, 458 ContentSettingsType content_type,
458 const std::string& resource_identifier, 459 const std::string& resource_identifier,
459 ContentSettingsForOneType* settings, 460 ContentSettingsForOneType* settings,
460 bool incognito) const { 461 bool incognito) const {
461 scoped_ptr<content_settings::RuleIterator> rule_iterator( 462 scoped_ptr<content_settings::RuleIterator> rule_iterator(
462 provider->GetRuleIterator(content_type, 463 provider->GetRuleIterator(content_type,
463 resource_identifier, 464 resource_identifier,
464 incognito)); 465 incognito));
465 while (rule_iterator->HasNext()) { 466 while (rule_iterator->HasNext()) {
466 const content_settings::Rule& rule = rule_iterator->Next(); 467 const content_settings::Rule& rule = rule_iterator->Next();
468 ContentSetting setting_value = CONTENT_SETTING_DEFAULT;
469 // TODO(bauerb): Return rules as a list of values, not content settings.
470 // Handle the case using compound values for its exceptions and arbitrary
471 // values for its default setting. Here we assume all the exceptions
472 // are granted as |CONTENT_SETTING_ALLOW|.
473 if (ContentTypeHasCompoundValue(content_type) &&
474 rule.value.get() &&
475 rule.primary_pattern != ContentSettingsPattern::Wildcard()) {
476 setting_value = CONTENT_SETTING_ALLOW;
477 } else {
478 setting_value = content_settings::ValueToContentSetting(rule.value.get());
479 }
467 settings->push_back(ContentSettingPatternSource( 480 settings->push_back(ContentSettingPatternSource(
468 rule.primary_pattern, rule.secondary_pattern, 481 rule.primary_pattern, rule.secondary_pattern,
469 content_settings::ValueToContentSetting(rule.value.get()), 482 setting_value,
470 kProviderNames[provider_type], 483 kProviderNames[provider_type],
471 incognito)); 484 incognito));
472 } 485 }
473 } 486 }
474 487
475 bool HostContentSettingsMap::ShouldAllowAllContent( 488 bool HostContentSettingsMap::ShouldAllowAllContent(
476 const GURL& primary_url, 489 const GURL& primary_url,
477 const GURL& secondary_url, 490 const GURL& secondary_url,
478 ContentSettingsType content_type) { 491 ContentSettingsType content_type) {
479 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS || 492 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS ||
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 } 545 }
533 } 546 }
534 547
535 if (info) { 548 if (info) {
536 info->source = content_settings::SETTING_SOURCE_NONE; 549 info->source = content_settings::SETTING_SOURCE_NONE;
537 info->primary_pattern = ContentSettingsPattern(); 550 info->primary_pattern = ContentSettingsPattern();
538 info->secondary_pattern = ContentSettingsPattern(); 551 info->secondary_pattern = ContentSettingsPattern();
539 } 552 }
540 return NULL; 553 return NULL;
541 } 554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698