OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/content_settings/content_settings_override_provider.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/auto_reset.h" | |
10 #include "base/prefs/pref_service.h" | |
11 #include "base/prefs/scoped_user_pref_update.h" | |
12 #include "base/values.h" | |
13 #include "chrome/browser/content_settings/content_settings_utils.h" | |
14 #include "chrome/common/content_settings.h" | |
15 #include "chrome/common/pref_names.h" | |
16 #include "components/pref_registry/pref_registry_syncable.h" | |
17 #include "content/public/browser/browser_thread.h" | |
18 | |
19 using content::BrowserThread; | |
20 | |
21 namespace content_settings { | |
22 | |
23 // static | |
24 void OverrideProvider::RegisterProfilePrefs( | |
25 user_prefs::PrefRegistrySyncable* registry) { | |
26 base::DictionaryValue* override_content_settings = | |
Bernhard Bauer
2014/09/10 09:07:17
Inline this?
Actually, there is a version of Regi
Daniel Nishi
2014/09/10 16:38:28
Using the empty dictionary version.
| |
27 new base::DictionaryValue(); | |
28 registry->RegisterDictionaryPref( | |
29 prefs::kOverrideContentSettings, | |
30 override_content_settings, | |
31 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | |
32 } | |
33 | |
34 OverrideProvider::OverrideProvider(PrefService* prefs, bool incognito) | |
35 : prefs_(prefs), is_incognito_(incognito) { | |
36 DCHECK(prefs_); | |
37 | |
38 // Read global overrides. | |
39 ReadOverrideSettings(); | |
40 } | |
41 | |
42 OverrideProvider::~OverrideProvider() { | |
43 } | |
44 | |
45 void OverrideProvider::SetContentSetting(ContentSettingsType content_type, | |
46 bool is_enabled) { | |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
48 DCHECK(prefs_); | |
49 | |
50 if (is_incognito_) | |
Bernhard Bauer
2014/09/10 09:07:17
So, in incognito, settings are silently immutable?
Daniel Nishi
2014/09/10 16:38:28
The only way to modify it right now would be throu
Bernhard Bauer
2014/09/10 17:44:53
Right... I think I'm okay with not having the abil
Daniel Nishi
2014/09/10 23:30:20
Done.
| |
51 return; | |
52 | |
53 DictionaryPrefUpdate update(prefs_, prefs::kOverrideContentSettings); | |
54 base::DictionaryValue* default_settings_dictionary = update.Get(); | |
55 base::AutoLock lock(lock_); | |
56 override_settings_[content_type] = is_enabled; | |
57 default_settings_dictionary->SetWithoutPathExpansion( | |
58 GetTypeName(content_type), new base::FundamentalValue(is_enabled)); | |
59 } | |
60 | |
61 bool OverrideProvider::IsEnabled(ContentSettingsType content_type) const { | |
Bernhard Bauer
2014/09/10 09:07:17
There is of course another way: You could make thi
Daniel Nishi
2014/09/10 16:38:28
Would taking this path with some special cases for
Bernhard Bauer
2014/09/10 17:44:53
I think so... if there aren't too many special cas
Daniel Nishi
2014/09/10 17:55:52
It mainly comes from the distinction of trying to
Bernhard Bauer
2014/09/11 16:49:56
Hm... I think in the content settings UI we get ar
| |
62 std::map<ContentSettingsType, bool>::const_iterator it = | |
63 override_settings_.find(content_type); | |
64 if (it == override_settings_.end()) | |
65 return true; | |
66 | |
67 return it->second; | |
68 } | |
69 | |
70 void OverrideProvider::ReadOverrideSettings() { | |
71 base::AutoLock lock(lock_); | |
Bernhard Bauer
2014/09/10 09:07:17
If this method is only called during construction,
Daniel Nishi
2014/09/10 16:38:28
Done.
| |
72 const base::DictionaryValue* override_settings_dictionary = | |
73 prefs_->GetDictionary(prefs::kOverrideContentSettings); | |
74 | |
75 override_settings_.clear(); | |
76 | |
77 if (override_settings_dictionary) { | |
78 for (base::DictionaryValue::Iterator i(*override_settings_dictionary); | |
79 !i.IsAtEnd(); | |
80 i.Advance()) { | |
81 const std::string& content_type(i.key()); | |
82 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | |
83 if (content_type == GetTypeName(ContentSettingsType(type))) { | |
84 bool bool_value = true; | |
85 bool rv = i.value().GetAsBoolean(&bool_value); | |
86 DCHECK(rv); | |
87 override_settings_[ContentSettingsType(type)] = bool_value; | |
88 break; | |
89 } | |
90 } | |
91 } | |
92 } | |
93 } | |
94 } // namespace content_settings | |
OLD | NEW |