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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
// Copyright (c) 2012 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_POLICY_CONFIGURATION_POLICY_HANDLER_H_
#define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_
#pragma once
#include <vector>
#include "base/basictypes.h"
#include "base/values.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
class PrefValueMap;
namespace policy {
class PolicyErrorMap;
class PolicyMap;
// An abstract super class that subclasses should implement to map policies to
// their corresponding preferences, and to check whether the policies are valid.
class ConfigurationPolicyHandler {
public:
ConfigurationPolicyHandler();
virtual ~ConfigurationPolicyHandler();
// Returns whether the policy settings handled by this
// ConfigurationPolicyHandler can be applied. Fills |errors| with error
// messages or warnings. |errors| may contain error messages even when
// |CheckPolicySettings()| returns true.
virtual bool CheckPolicySettings(const PolicyMap& policies,
PolicyErrorMap* errors) = 0;
// Processes the policies handled by this ConfigurationPolicyHandler and sets
// the appropriate preferences in |prefs|.
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) = 0;
// Modifies the values of some of the policies in |policies| so that they
// are more suitable to display to the user. This can be used to remove
// sensitive values such as passwords, or to pretty-print values.
// The base implementation just converts DictionaryValue policies to a
// StringValue representation.
virtual void PrepareForDisplaying(PolicyMap* policies) const;
private:
DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandler);
};
// Abstract class derived from ConfigurationPolicyHandler that should be
// subclassed to handle a single policy (not a combination of policies).
class TypeCheckingPolicyHandler : public ConfigurationPolicyHandler {
public:
TypeCheckingPolicyHandler(const char* policy_name,
base::Value::Type value_type);
// ConfigurationPolicyHandler methods:
virtual bool CheckPolicySettings(const PolicyMap& policies,
PolicyErrorMap* errors) OVERRIDE;
protected:
virtual ~TypeCheckingPolicyHandler();
// Runs policy checks and returns the policy value if successful.
bool CheckAndGetValue(const PolicyMap& policies,
PolicyErrorMap* errors,
const Value** value);
const char* policy_name() const;
private:
// The name of the policy.
const char* policy_name_;
// The type the value of the policy should have.
base::Value::Type value_type_;
DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler);
};
// ConfigurationPolicyHandler for policies that map directly to a preference.
class SimplePolicyHandler : public TypeCheckingPolicyHandler {
public:
SimplePolicyHandler(const char* policy_name,
const char* pref_path,
base::Value::Type value_type);
virtual ~SimplePolicyHandler();
// ConfigurationPolicyHandler methods:
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
// The DictionaryValue path of the preference the policy maps to.
const char* pref_path_;
DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler);
};
// Implements additional checks for policies that are lists of extension IDs.
class ExtensionListPolicyHandler : public TypeCheckingPolicyHandler {
public:
ExtensionListPolicyHandler(const char* policy_name,
const char* pref_path,
bool allow_wildcards);
virtual ~ExtensionListPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual bool CheckPolicySettings(const PolicyMap& policies,
PolicyErrorMap* errors) OVERRIDE;
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
protected:
const char* pref_path() const;
// Runs sanity checks on the policy value and returns it in |extension_ids|.
bool CheckAndGetList(const PolicyMap& policies,
PolicyErrorMap* errors,
const base::ListValue** extension_ids);
private:
const char* pref_path_;
bool allow_wildcards_;
DISALLOW_COPY_AND_ASSIGN(ExtensionListPolicyHandler);
};
// ConfigurationPolicyHandler for the SyncDisabled policy.
class SyncPolicyHandler : public TypeCheckingPolicyHandler {
public:
SyncPolicyHandler();
virtual ~SyncPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(SyncPolicyHandler);
};
// ConfigurationPolicyHandler for the AutofillEnabled policy.
class AutofillPolicyHandler : public TypeCheckingPolicyHandler {
public:
AutofillPolicyHandler();
virtual ~AutofillPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(AutofillPolicyHandler);
};
// ConfigurationPolicyHandler for the DownloadDirectory policy.
class DownloadDirPolicyHandler : public TypeCheckingPolicyHandler {
public:
DownloadDirPolicyHandler();
virtual ~DownloadDirPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(DownloadDirPolicyHandler);
};
// ConfigurationPolicyHandler for the DiskCacheDir policy.
class DiskCacheDirPolicyHandler : public TypeCheckingPolicyHandler {
public:
explicit DiskCacheDirPolicyHandler();
virtual ~DiskCacheDirPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(DiskCacheDirPolicyHandler);
};
// ConfigurationPolicyHandler for the FileSelectionDialogsHandler policy.
class FileSelectionDialogsHandler : public TypeCheckingPolicyHandler {
public:
FileSelectionDialogsHandler();
virtual ~FileSelectionDialogsHandler();
// ConfigurationPolicyHandler methods:
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(FileSelectionDialogsHandler);
};
// ConfigurationPolicyHandler for the incognito mode policies.
class IncognitoModePolicyHandler : public ConfigurationPolicyHandler {
public:
IncognitoModePolicyHandler();
virtual ~IncognitoModePolicyHandler();
// ConfigurationPolicyHandler methods:
virtual bool CheckPolicySettings(const PolicyMap& policies,
PolicyErrorMap* errors) OVERRIDE;
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
IncognitoModePrefs::Availability GetAvailabilityValueAsEnum(
const Value* availability);
DISALLOW_COPY_AND_ASSIGN(IncognitoModePolicyHandler);
};
// ConfigurationPolicyHandler for the DefaultSearchEncodings policy.
class DefaultSearchEncodingsPolicyHandler : public TypeCheckingPolicyHandler {
public:
DefaultSearchEncodingsPolicyHandler();
virtual ~DefaultSearchEncodingsPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler);
};
// ConfigurationPolicyHandler for the default search policies.
class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler {
public:
DefaultSearchPolicyHandler();
virtual ~DefaultSearchPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual bool CheckPolicySettings(const PolicyMap& policies,
PolicyErrorMap* errors) OVERRIDE;
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
// Calls |CheckPolicySettings()| on each of the handlers in |handlers_|
// and returns whether all of the calls succeeded.
bool CheckIndividualPolicies(const PolicyMap& policies,
PolicyErrorMap* errors);
// Returns whether there is a value for |policy_name| in |policies|.
bool HasDefaultSearchPolicy(const PolicyMap& policies,
const char* policy_name);
// Returns whether any default search policies are specified in |policies|.
bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies);
// Returns whether the default search provider is disabled.
bool DefaultSearchProviderIsDisabled(const PolicyMap& policies);
// Returns whether the default search URL is set and valid. On success, both
// outparams (which must be non-NULL) are filled with the search URL.
bool DefaultSearchURLIsValid(const PolicyMap& policies,
const Value** url_value,
std::string* url_string);
// Make sure that the |path| if present in |prefs_|. If not, set it to
// a blank string.
void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path);
// The ConfigurationPolicyHandler handlers for each default search policy.
std::vector<ConfigurationPolicyHandler*> handlers_;
DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler);
};
// ConfigurationPolicyHandler for the proxy policies.
class ProxyPolicyHandler : public ConfigurationPolicyHandler {
public:
// Constants for the "Proxy Server Mode" defined in the policies.
// Note that these diverge from internal presentation defined in
// ProxyPrefs::ProxyMode for legacy reasons. The following four
// PolicyProxyModeType types were not very precise and had overlapping use
// cases.
enum ProxyModeType {
// Disable Proxy, connect directly.
PROXY_SERVER_MODE = 0,
// Auto detect proxy or use specific PAC script if given.
PROXY_AUTO_DETECT_PROXY_SERVER_MODE = 1,
// Use manually configured proxy servers (fixed servers).
PROXY_MANUALLY_CONFIGURED_PROXY_SERVER_MODE = 2,
// Use system proxy server.
PROXY_USE_SYSTEM_PROXY_SERVER_MODE = 3,
MODE_COUNT
};
ProxyPolicyHandler();
virtual ~ProxyPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual bool CheckPolicySettings(const PolicyMap& policies,
PolicyErrorMap* errors) OVERRIDE;
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
const Value* GetProxyPolicyValue(const PolicyMap& policies,
const char* policy_name);
// Converts the deprecated ProxyServerMode policy value to a ProxyMode value
// and places the result in |mode_value|. Returns whether the conversion
// succeeded.
bool CheckProxyModeAndServerMode(const PolicyMap& policies,
PolicyErrorMap* errors,
std::string* mode_value);
DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler);
};
// Handles JavaScript policies.
class JavascriptPolicyHandler : public ConfigurationPolicyHandler {
public:
JavascriptPolicyHandler();
virtual ~JavascriptPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual bool CheckPolicySettings(const PolicyMap& policies,
PolicyErrorMap* errors) OVERRIDE;
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(JavascriptPolicyHandler);
};
// Handles RestoreOnStartup policy.
class RestoreOnStartupPolicyHandler : public TypeCheckingPolicyHandler {
public:
RestoreOnStartupPolicyHandler();
virtual ~RestoreOnStartupPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual bool CheckPolicySettings(const PolicyMap& policies,
PolicyErrorMap* errors) OVERRIDE;
virtual void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) OVERRIDE;
private:
void ApplyPolicySettingsFromHomePage(const PolicyMap& policies,
PrefValueMap* prefs);
DISALLOW_COPY_AND_ASSIGN(RestoreOnStartupPolicyHandler);
};
} // namespace policy
#endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_
|