1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_
#define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_
#pragma once
// A content settings provider that takes its settings out of the pref service.
#include <map>
#include <string>
#include <utility>
#include "base/basictypes.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/content_settings/content_settings_origin_identifier_value_map.h"
#include "chrome/browser/content_settings/content_settings_provider.h"
#include "chrome/browser/content_settings/content_settings_utils.h"
#include "chrome/browser/prefs/pref_change_registrar.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
class ContentSettingsDetails;
class DictionaryValue;
class HostContentSettingsMap;
class PrefService;
namespace content_settings {
// Content settings provider that provides default content settings based on
// user prefs.
class PrefDefaultProvider : public DefaultProviderInterface,
public NotificationObserver {
public:
PrefDefaultProvider(HostContentSettingsMap* map,
PrefService* prefs,
bool incognito);
virtual ~PrefDefaultProvider();
// DefaultContentSettingsProvider implementation.
virtual ContentSetting ProvideDefaultSetting(
ContentSettingsType content_type) const;
virtual void UpdateDefaultSetting(ContentSettingsType content_type,
ContentSetting setting);
virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const;
void ShutdownOnUIThread();
static void RegisterUserPrefs(PrefService* prefs);
// NotificationObserver implementation.
virtual void Observe(int type,
const NotificationSource& source,
const NotificationDetails& details);
private:
// Informs observers that content settings have changed. Make sure that
// |lock_| is not held when calling this, as listeners will usually call one
// of the GetSettings functions in response, which would then lead to a
// mutex deadlock.
void NotifyObservers(const ContentSettingsDetails& details);
// Sets the fields of |settings| based on the values in |dictionary|.
void GetSettingsFromDictionary(const DictionaryValue* dictionary,
ContentSettings* settings);
// Forces the default settings to be explicitly set instead of themselves
// being CONTENT_SETTING_DEFAULT.
void ForceDefaultsToBeExplicit();
// Reads the default settings from the preferences service. If |overwrite| is
// true and the preference is missing, the local copy will be cleared as well.
void ReadDefaultSettings(bool overwrite);
void MigrateObsoleteNotificationPref();
// Copies of the pref data, so that we can read it on the IO thread.
ContentSettings default_content_settings_;
HostContentSettingsMap* host_content_settings_map_;
PrefService* prefs_;
// Whether this settings map is for an Incognito session.
bool is_incognito_;
// Used around accesses to the default_content_settings_ object to guarantee
// thread safety.
mutable base::Lock lock_;
PrefChangeRegistrar pref_change_registrar_;
// Whether we are currently updating preferences, this is used to ignore
// notifications from the preferences service that we triggered ourself.
bool updating_preferences_;
DISALLOW_COPY_AND_ASSIGN(PrefDefaultProvider);
};
// Content settings provider that provides content settings from the user
// preference.
class PrefProvider : public ProviderInterface,
public NotificationObserver {
public:
static void RegisterUserPrefs(PrefService* prefs);
PrefProvider(HostContentSettingsMap* map,
PrefService* prefs,
bool incognito);
virtual ~PrefProvider();
// ProviderInterface implementations.
virtual void SetContentSetting(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
ContentSetting content_setting);
virtual ContentSetting GetContentSetting(
const GURL& primary_url,
const GURL& secondary_url,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier) const;
virtual void GetAllContentSettingsRules(
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
Rules* content_setting_rules) const;
virtual void ClearAllContentSettingsRules(
ContentSettingsType content_type);
virtual void ShutdownOnUIThread();
// NotificationObserver implementation.
virtual void Observe(int type,
const NotificationSource& source,
const NotificationDetails& details);
private:
void Init();
// Reads all content settings exceptions from the preference and load them
// into the |value_map_|. The |value_map_| is cleared first if |overwrite| is
// true.
void ReadContentSettingsFromPref(bool overwrite);
// Update the preference that stores content settings exceptions and syncs the
// value to the obsolete preference.
void UpdatePref(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
ContentSetting setting);
// Update the preference prefs::kContentSettingsPatternPairs, which is used to
// persist content settigns exceptions and supposed to replace the preferences
// prefs::kContentSettingsPatterns.
void UpdatePatternPairsPref(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
ContentSetting setting);
// Updates the preferences prefs::kContentSettingsPatterns. This preferences
// is obsolete and only used for compatibility reasons.
void UpdatePatternsPref(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
ContentSetting setting);
// Various migration methods (old cookie, popup and per-host data gets
// migrated to the new format).
void MigrateObsoletePerhostPref();
void MigrateObsoletePopupsPref();
void MigrateObsoleteContentSettingsPatternPref();
// Copies the value of the preference that stores the content settings
// exceptions to the obsolete preference for content settings exceptions. This
// is necessary to allow content settings exceptions beeing synced to older
// versions of chrome that only use the obsolete.
void SyncObsoletePref();
static void CanonicalizeContentSettingsExceptions(
DictionaryValue* all_settings_dictionary);
void NotifyObservers(const ContentSettingsDetails& details);
// Weak; owned by the Profile and reset in ShutdownOnUIThread.
PrefService* prefs_;
// Weak; owns us
HostContentSettingsMap* host_content_settings_map_;
bool is_incognito_;
PrefChangeRegistrar pref_change_registrar_;
// Whether we are currently updating preferences, this is used to ignore
// notifications from the preferences service that we triggered ourself.
bool updating_preferences_;
OriginIdentifierValueMap value_map_;
OriginIdentifierValueMap incognito_value_map_;
// Used around accesses to the value map objects to guarantee
// thread safety.
mutable base::Lock lock_;
DISALLOW_COPY_AND_ASSIGN(PrefProvider);
};
} // namespace content_settings
#endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_
|