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

Side by Side Diff: components/content_settings/core/browser/content_settings_pref.cc

Issue 1320673013: Remove HostContentSettingsMap::IsSettingAllowedForType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-issetting-allowed
Patch Set: Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/content_settings/core/browser/content_settings_pref.h" 5 #include "components/content_settings/core/browser/content_settings_pref.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
13 #include "base/time/clock.h" 13 #include "base/time/clock.h"
14 #include "components/content_settings/core/browser/content_settings_info.h"
15 #include "components/content_settings/core/browser/content_settings_registry.h"
14 #include "components/content_settings/core/browser/content_settings_rule.h" 16 #include "components/content_settings/core/browser/content_settings_rule.h"
15 #include "components/content_settings/core/browser/content_settings_utils.h" 17 #include "components/content_settings/core/browser/content_settings_utils.h"
16 #include "components/content_settings/core/browser/host_content_settings_map.h" 18 #include "components/content_settings/core/browser/host_content_settings_map.h"
17 #include "components/content_settings/core/common/content_settings.h" 19 #include "components/content_settings/core/common/content_settings.h"
18 #include "components/content_settings/core/common/content_settings_pattern.h" 20 #include "components/content_settings/core/common/content_settings_pattern.h"
19 #include "components/content_settings/core/common/pref_names.h" 21 #include "components/content_settings/core/common/pref_names.h"
20 #include "url/gurl.h" 22 #include "url/gurl.h"
21 23
22 namespace { 24 namespace {
23 25
24 const char kSettingPath[] = "setting"; 26 const char kSettingPath[] = "setting";
25 const char kPerResourceIdentifierPrefName[] = "per_resource"; 27 const char kPerResourceIdentifierPrefName[] = "per_resource";
26 const char kLastUsed[] = "last_used"; 28 const char kLastUsed[] = "last_used";
27 29
28 // If the given content type supports resource identifiers in user preferences, 30 // If the given content type supports resource identifiers in user preferences,
29 // returns true and sets |pref_key| to the key in the content settings 31 // returns true and sets |pref_key| to the key in the content settings
30 // dictionary under which per-resource content settings are stored. 32 // dictionary under which per-resource content settings are stored.
31 // Otherwise, returns false. 33 // Otherwise, returns false.
32 bool SupportsResourceIdentifiers(ContentSettingsType content_type) { 34 bool SupportsResourceIdentifiers(ContentSettingsType content_type) {
33 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; 35 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS;
34 } 36 }
35 37
38 bool IsValueAllowedForType(const base::Value* value, ContentSettingsType type) {
39 const content_settings::ContentSettingsInfo* info =
40 content_settings::ContentSettingsRegistry::GetInstance()->Get(type);
41 if (info) {
42 int setting;
43 if (!value->GetAsInteger(&setting))
44 return false;
45 if (setting == CONTENT_SETTING_DEFAULT)
46 return false;
47 return info->IsSettingValid(IntToContentSetting(setting));
48 }
49
50 // TODO(raymes): We should permit different types of base::Value for
51 // website settings.
52 return value->GetType() == base::Value::TYPE_DICTIONARY;
53 }
54
36 } // namespace 55 } // namespace
37 56
38 namespace content_settings { 57 namespace content_settings {
39 58
40 ContentSettingsPref::ContentSettingsPref( 59 ContentSettingsPref::ContentSettingsPref(
41 ContentSettingsType content_type, 60 ContentSettingsType content_type,
42 PrefService* prefs, 61 PrefService* prefs,
43 PrefChangeRegistrar* registrar, 62 PrefChangeRegistrar* registrar,
44 const std::string& pref_name, 63 const std::string& pref_name,
45 bool incognito, 64 bool incognito,
(...skipping 25 matching lines...) Expand all
71 resource_identifier, 90 resource_identifier,
72 &lock_); 91 &lock_);
73 return value_map_.GetRuleIterator(content_type_, resource_identifier, &lock_); 92 return value_map_.GetRuleIterator(content_type_, resource_identifier, &lock_);
74 } 93 }
75 94
76 bool ContentSettingsPref::SetWebsiteSetting( 95 bool ContentSettingsPref::SetWebsiteSetting(
77 const ContentSettingsPattern& primary_pattern, 96 const ContentSettingsPattern& primary_pattern,
78 const ContentSettingsPattern& secondary_pattern, 97 const ContentSettingsPattern& secondary_pattern,
79 const ResourceIdentifier& resource_identifier, 98 const ResourceIdentifier& resource_identifier,
80 base::Value* in_value) { 99 base::Value* in_value) {
100 DCHECK(!in_value || IsValueAllowedForType(in_value, content_type_));
81 DCHECK(thread_checker_.CalledOnValidThread()); 101 DCHECK(thread_checker_.CalledOnValidThread());
82 DCHECK(prefs_); 102 DCHECK(prefs_);
83 DCHECK(primary_pattern != ContentSettingsPattern::Wildcard() || 103 DCHECK(primary_pattern != ContentSettingsPattern::Wildcard() ||
84 secondary_pattern != ContentSettingsPattern::Wildcard() || 104 secondary_pattern != ContentSettingsPattern::Wildcard() ||
85 !resource_identifier.empty()); 105 !resource_identifier.empty());
86 106
87 // At this point take the ownership of the |in_value|. 107 // At this point take the ownership of the |in_value|.
88 scoped_ptr<base::Value> value(in_value); 108 scoped_ptr<base::Value> value(in_value);
89 109
90 // Update in memory value map. 110 // Update in memory value map.
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 resource_identifier, 316 resource_identifier,
297 setting_ptr->DeepCopy()); 317 setting_ptr->DeepCopy());
298 } 318 }
299 } 319 }
300 } 320 }
301 321
302 const base::Value* value = nullptr; 322 const base::Value* value = nullptr;
303 settings_dictionary->GetWithoutPathExpansion(kSettingPath, &value); 323 settings_dictionary->GetWithoutPathExpansion(kSettingPath, &value);
304 324
305 if (value) { 325 if (value) {
306 DCHECK( 326 DCHECK(IsValueAllowedForType(value, content_type_));
307 HostContentSettingsMap::IsValueAllowedForType(value, content_type_));
308 value_map_.SetValue(pattern_pair.first, 327 value_map_.SetValue(pattern_pair.first,
309 pattern_pair.second, 328 pattern_pair.second,
310 content_type_, 329 content_type_,
311 ResourceIdentifier(), 330 ResourceIdentifier(),
312 value->DeepCopy()); 331 value->DeepCopy());
313 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { 332 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) {
314 ContentSetting s = ValueToContentSetting(value); 333 ContentSetting s = ValueToContentSetting(value);
315 switch (s) { 334 switch (s) {
316 case CONTENT_SETTING_ALLOW : 335 case CONTENT_SETTING_ALLOW :
317 ++cookies_allow_exception_count; 336 ++cookies_allow_exception_count;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 503
485 void ContentSettingsPref::AssertLockNotHeld() const { 504 void ContentSettingsPref::AssertLockNotHeld() const {
486 #if !defined(NDEBUG) 505 #if !defined(NDEBUG)
487 // |Lock::Acquire()| will assert if the lock is held by this thread. 506 // |Lock::Acquire()| will assert if the lock is held by this thread.
488 lock_.Acquire(); 507 lock_.Acquire();
489 lock_.Release(); 508 lock_.Release();
490 #endif 509 #endif
491 } 510 }
492 511
493 } // namespace content_settings 512 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698