1 // Copyright 2013 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/policy/configuration_policy_handler_list_factory.h"
6
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/values.h"
11 #include "chrome/browser/net/proxy_policy_handler.h"
12 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h"
13 #include "chrome/browser/profiles/incognito_mode_policy_handler.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/password_manager/core/common/password_manager_pref_names.h"
17 #include "components/policy/core/browser/autofill_policy_handler.h"
18 #include "components/policy/core/browser/configuration_policy_handler.h"
19 #include "components/policy/core/browser/configuration_policy_handler_list.h"
20 #include "components/policy/core/browser/configuration_policy_handler_parameters.h"
21 #include "components/policy/core/browser/url_blacklist_policy_handler.h"
22 #include "components/policy/core/common/policy_details.h"
23 #include "components/policy/core/common/policy_map.h"
24 #include "components/policy/core/common/policy_pref_names.h"
25 #include "components/policy/core/common/schema.h"
26 #include "components/search_engines/default_search_policy_handler.h"
27 #include "components/translate/core/common/translate_pref_names.h"
28 #include "policy/policy_constants.h"
29
30 #if !defined(OS_IOS)
31 #include "chrome/browser/net/disk_cache_dir_policy_handler.h"
32 #include "chrome/browser/policy/file_selection_dialogs_policy_handler.h"
33 #include "chrome/browser/policy/javascript_policy_handler.h"
34 #include "chrome/browser/policy/network_prediction_policy_handler.h"
35 #include "chrome/browser/sessions/restore_on_startup_policy_handler.h"
36 #include "chrome/browser/sync/sync_policy_handler.h"
37 #endif
38
39 #if defined(OS_CHROMEOS)
40 #include "ash/magnifier/magnifier_constants.h"
41 #include "chrome/browser/chromeos/policy/configuration_policy_handler_chromeos.h"
42 #include "chromeos/dbus/power_policy_controller.h"
43 #include "components/user_manager/user.h"
44 #include "components/user_manager/user_manager.h"
45 #endif
46
47 #if !defined(OS_ANDROID) && !defined(OS_IOS)
48 #include "chrome/browser/download/download_dir_policy_handler.h"
49 #endif
50
51 #if defined(ENABLE_EXTENSIONS)
52 #include "chrome/browser/extensions/api/messaging/native_messaging_policy_handler.h"
53 #include "chrome/browser/extensions/extension_management_constants.h"
54 #include "chrome/browser/extensions/policy_handlers.h"
55 #include "extensions/browser/pref_names.h"
56 #include "extensions/common/manifest.h"
57 #endif
58
59 namespace policy {
60
61 namespace {
62
63 // List of policy types to preference names. This is used for simple policies
64 // that directly map to a single preference.
65 const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
66 { key::kHomepageLocation,
67 prefs::kHomePage,
68 base::Value::TYPE_STRING },
69 { key::kHomepageIsNewTabPage,
70 prefs::kHomePageIsNewTabPage,
71 base::Value::TYPE_BOOLEAN },
72 { key::kRestoreOnStartupURLs,
73 prefs::kURLsToRestoreOnStartup,
74 base::Value::TYPE_LIST },
75 { key::kAlternateErrorPagesEnabled,
76 prefs::kAlternateErrorPagesEnabled,
77 base::Value::TYPE_BOOLEAN },
78 { key::kSearchSuggestEnabled,
79 prefs::kSearchSuggestEnabled,
80 base::Value::TYPE_BOOLEAN },
81 { key::kBuiltInDnsClientEnabled,
82 prefs::kBuiltInDnsClientEnabled,
83 base::Value::TYPE_BOOLEAN },
84 { key::kWPADQuickCheckEnabled,
85 prefs::kQuickCheckEnabled,
86 base::Value::TYPE_BOOLEAN },
87 { key::kDisableSpdy,
88 prefs::kDisableSpdy,
89 base::Value::TYPE_BOOLEAN },
90 { key::kSafeBrowsingEnabled,
91 prefs::kSafeBrowsingEnabled,
92 base::Value::TYPE_BOOLEAN },
93 { key::kForceSafeSearch,
94 prefs::kForceSafeSearch,
95 base::Value::TYPE_BOOLEAN },
96 { key::kPasswordManagerEnabled,
97 password_manager::prefs::kPasswordManagerSavingEnabled,
98 base::Value::TYPE_BOOLEAN },
99 { key::kPasswordManagerAllowShowPasswords,
100 password_manager::prefs::kPasswordManagerAllowShowPasswords,
101 base::Value::TYPE_BOOLEAN },
102 { key::kPrintingEnabled,
103 prefs::kPrintingEnabled,
104 base::Value::TYPE_BOOLEAN },
105 { key::kDisablePrintPreview,
106 prefs::kPrintPreviewDisabled,
107 base::Value::TYPE_BOOLEAN },
108 { key::kMetricsReportingEnabled,
109 prefs::kMetricsReportingEnabled,
110 base::Value::TYPE_BOOLEAN },
111 { key::kApplicationLocaleValue,
112 prefs::kApplicationLocale,
113 base::Value::TYPE_STRING },
114 { key::kDisabledPlugins,
115 prefs::kPluginsDisabledPlugins,
116 base::Value::TYPE_LIST },
117 { key::kDisabledPluginsExceptions,
118 prefs::kPluginsDisabledPluginsExceptions,
119 base::Value::TYPE_LIST },
120 { key::kEnabledPlugins,
121 prefs::kPluginsEnabledPlugins,
122 base::Value::TYPE_LIST },
123 { key::kShowHomeButton,
124 prefs::kShowHomeButton,
125 base::Value::TYPE_BOOLEAN },
126 { key::kSavingBrowserHistoryDisabled,
127 prefs::kSavingBrowserHistoryDisabled,
128 base::Value::TYPE_BOOLEAN },
129 { key::kAllowDeletingBrowserHistory,
130 prefs::kAllowDeletingBrowserHistory,
131 base::Value::TYPE_BOOLEAN },
132 { key::kDeveloperToolsDisabled,
133 prefs::kDevToolsDisabled,
134 base::Value::TYPE_BOOLEAN },
135 { key::kBlockThirdPartyCookies,
136 prefs::kBlockThirdPartyCookies,
137 base::Value::TYPE_BOOLEAN },
138 { key::kDefaultCookiesSetting,
139 prefs::kManagedDefaultCookiesSetting,
140 base::Value::TYPE_INTEGER },
141 { key::kDefaultImagesSetting,
142 prefs::kManagedDefaultImagesSetting,
143 base::Value::TYPE_INTEGER },
144 { key::kDefaultPluginsSetting,
145 prefs::kManagedDefaultPluginsSetting,
146 base::Value::TYPE_INTEGER },
147 { key::kDefaultPopupsSetting,
148 prefs::kManagedDefaultPopupsSetting,
149 base::Value::TYPE_INTEGER },
150 { key::kAutoSelectCertificateForUrls,
151 prefs::kManagedAutoSelectCertificateForUrls,
152 base::Value::TYPE_LIST },
153 { key::kCookiesAllowedForUrls,
154 prefs::kManagedCookiesAllowedForUrls,
155 base::Value::TYPE_LIST },
156 { key::kCookiesBlockedForUrls,
157 prefs::kManagedCookiesBlockedForUrls,
158 base::Value::TYPE_LIST },
159 { key::kCookiesSessionOnlyForUrls,
160 prefs::kManagedCookiesSessionOnlyForUrls,
161 base::Value::TYPE_LIST },
162 { key::kImagesAllowedForUrls,
163 prefs::kManagedImagesAllowedForUrls,
164 base::Value::TYPE_LIST },
165 { key::kImagesBlockedForUrls,
166 prefs::kManagedImagesBlockedForUrls,
167 base::Value::TYPE_LIST },
168 { key::kJavaScriptAllowedForUrls,
169 prefs::kManagedJavaScriptAllowedForUrls,
170 base::Value::TYPE_LIST },
171 { key::kJavaScriptBlockedForUrls,
172 prefs::kManagedJavaScriptBlockedForUrls,
173 base::Value::TYPE_LIST },
174 { key::kPluginsAllowedForUrls,
175 prefs::kManagedPluginsAllowedForUrls,
176 base::Value::TYPE_LIST },
177 { key::kPluginsBlockedForUrls,
178 prefs::kManagedPluginsBlockedForUrls,
179 base::Value::TYPE_LIST },
180 { key::kPopupsAllowedForUrls,
181 prefs::kManagedPopupsAllowedForUrls,
182 base::Value::TYPE_LIST },
183 { key::kPopupsBlockedForUrls,
184 prefs::kManagedPopupsBlockedForUrls,
185 base::Value::TYPE_LIST },
186 { key::kNotificationsAllowedForUrls,
187 prefs::kManagedNotificationsAllowedForUrls,
188 base::Value::TYPE_LIST },
189 { key::kNotificationsBlockedForUrls,
190 prefs::kManagedNotificationsBlockedForUrls,
191 base::Value::TYPE_LIST },
192 { key::kDefaultNotificationsSetting,
193 prefs::kManagedDefaultNotificationsSetting,
194 base::Value::TYPE_INTEGER },
195 { key::kDefaultGeolocationSetting,
196 prefs::kManagedDefaultGeolocationSetting,
197 base::Value::TYPE_INTEGER },
198 { key::kSigninAllowed,
199 prefs::kSigninAllowed,
200 base::Value::TYPE_BOOLEAN },
201 { key::kDisableSSLRecordSplitting,
202 prefs::kDisableSSLRecordSplitting,
203 base::Value::TYPE_BOOLEAN },
204 { key::kEnableOnlineRevocationChecks,
205 prefs::kCertRevocationCheckingEnabled,
206 base::Value::TYPE_BOOLEAN },
207 { key::kRequireOnlineRevocationChecksForLocalAnchors,
208 prefs::kCertRevocationCheckingRequiredLocalAnchors,
209 base::Value::TYPE_BOOLEAN },
210 { key::kAuthSchemes,
211 prefs::kAuthSchemes,
212 base::Value::TYPE_STRING },
213 { key::kDisableAuthNegotiateCnameLookup,
214 prefs::kDisableAuthNegotiateCnameLookup,
215 base::Value::TYPE_BOOLEAN },
216 { key::kEnableAuthNegotiatePort,
217 prefs::kEnableAuthNegotiatePort,
218 base::Value::TYPE_BOOLEAN },
219 { key::kAuthServerWhitelist,
220 prefs::kAuthServerWhitelist,
221 base::Value::TYPE_STRING },
222 { key::kAuthNegotiateDelegateWhitelist,
223 prefs::kAuthNegotiateDelegateWhitelist,
224 base::Value::TYPE_STRING },
225 { key::kGSSAPILibraryName,
226 prefs::kGSSAPILibraryName,
227 base::Value::TYPE_STRING },
228 { key::kAllowCrossOriginAuthPrompt,
229 prefs::kAllowCrossOriginAuthPrompt,
230 base::Value::TYPE_BOOLEAN },
231 { key::kDisable3DAPIs,
232 prefs::kDisable3DAPIs,
233 base::Value::TYPE_BOOLEAN },
234 { key::kDisablePluginFinder,
235 prefs::kDisablePluginFinder,
236 base::Value::TYPE_BOOLEAN },
237 { key::kDiskCacheSize,
238 prefs::kDiskCacheSize,
239 base::Value::TYPE_INTEGER },
240 { key::kMediaCacheSize,
241 prefs::kMediaCacheSize,
242 base::Value::TYPE_INTEGER },
243 { key::kPolicyRefreshRate,
244 policy_prefs::kUserPolicyRefreshRate,
245 base::Value::TYPE_INTEGER },
246 { key::kDevicePolicyRefreshRate,
247 prefs::kDevicePolicyRefreshRate,
248 base::Value::TYPE_INTEGER },
249 { key::kDefaultBrowserSettingEnabled,
250 prefs::kDefaultBrowserSettingEnabled,
251 base::Value::TYPE_BOOLEAN },
252 { key::kRemoteAccessHostFirewallTraversal,
253 prefs::kRemoteAccessHostFirewallTraversal,
254 base::Value::TYPE_BOOLEAN },
255 { key::kRemoteAccessHostRequireTwoFactor,
256 prefs::kRemoteAccessHostRequireTwoFactor,
257 base::Value::TYPE_BOOLEAN },
258 { key::kRemoteAccessHostDomain,
259 prefs::kRemoteAccessHostDomain,
260 base::Value::TYPE_STRING },
261 { key::kRemoteAccessHostTalkGadgetPrefix,
262 prefs::kRemoteAccessHostTalkGadgetPrefix,
263 base::Value::TYPE_STRING },
264 { key::kRemoteAccessHostRequireCurtain,
265 prefs::kRemoteAccessHostRequireCurtain,
266 base::Value::TYPE_BOOLEAN },
267 { key::kRemoteAccessHostAllowClientPairing,
268 prefs::kRemoteAccessHostAllowClientPairing,
269 base::Value::TYPE_BOOLEAN },
270 { key::kRemoteAccessHostAllowGnubbyAuth,
271 prefs::kRemoteAccessHostAllowGnubbyAuth,
272 base::Value::TYPE_BOOLEAN },
273 { key::kRemoteAccessHostAllowRelayedConnection,
274 prefs::kRemoteAccessHostAllowRelayedConnection,
275 base::Value::TYPE_BOOLEAN },
276 { key::kRemoteAccessHostUdpPortRange,
277 prefs::kRemoteAccessHostUdpPortRange,
278 base::Value::TYPE_STRING },
279 { key::kCloudPrintProxyEnabled,
280 prefs::kCloudPrintProxyEnabled,
281 base::Value::TYPE_BOOLEAN },
282 { key::kCloudPrintSubmitEnabled,
283 prefs::kCloudPrintSubmitEnabled,
284 base::Value::TYPE_BOOLEAN },
285 { key::kTranslateEnabled,
286 prefs::kEnableTranslate,
287 base::Value::TYPE_BOOLEAN },
288 { key::kAllowOutdatedPlugins,
289 prefs::kPluginsAllowOutdated,
290 base::Value::TYPE_BOOLEAN },
291 { key::kAlwaysAuthorizePlugins,
292 prefs::kPluginsAlwaysAuthorize,
293 base::Value::TYPE_BOOLEAN },
294 { key::kBookmarkBarEnabled,
295 bookmarks::prefs::kShowBookmarkBar,
296 base::Value::TYPE_BOOLEAN },
297 { key::kEditBookmarksEnabled,
298 bookmarks::prefs::kEditBookmarksEnabled,
299 base::Value::TYPE_BOOLEAN },
300 { key::kShowAppsShortcutInBookmarkBar,
301 bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
302 base::Value::TYPE_BOOLEAN },
303 { key::kAllowFileSelectionDialogs,
304 prefs::kAllowFileSelectionDialogs,
305 base::Value::TYPE_BOOLEAN },
306 { key::kImportBookmarks,
307 prefs::kImportBookmarks,
308 base::Value::TYPE_BOOLEAN },
309 { key::kImportHistory,
310 prefs::kImportHistory,
311 base::Value::TYPE_BOOLEAN },
312 { key::kImportHomepage,
313 prefs::kImportHomepage,
314 base::Value::TYPE_BOOLEAN },
315 { key::kImportSearchEngine,
316 prefs::kImportSearchEngine,
317 base::Value::TYPE_BOOLEAN },
318 { key::kImportSavedPasswords,
319 prefs::kImportSavedPasswords,
320 base::Value::TYPE_BOOLEAN },
321 { key::kImportAutofillFormData,
322 prefs::kImportAutofillFormData,
323 base::Value::TYPE_BOOLEAN },
324 { key::kMaxConnectionsPerProxy,
325 prefs::kMaxConnectionsPerProxy,
326 base::Value::TYPE_INTEGER },
327 { key::kURLWhitelist,
328 policy_prefs::kUrlWhitelist,
329 base::Value::TYPE_LIST },
330 { key::kRestrictSigninToPattern,
331 prefs::kGoogleServicesUsernamePattern,
332 base::Value::TYPE_STRING },
333 { key::kDefaultMediaStreamSetting,
334 prefs::kManagedDefaultMediaStreamSetting,
335 base::Value::TYPE_INTEGER },
336 { key::kDisableSafeBrowsingProceedAnyway,
337 prefs::kSafeBrowsingProceedAnywayDisabled,
338 base::Value::TYPE_BOOLEAN },
339 { key::kSpellCheckServiceEnabled,
340 prefs::kSpellCheckUseSpellingService,
341 base::Value::TYPE_BOOLEAN },
342 { key::kDisableScreenshots,
343 prefs::kDisableScreenshots,
344 base::Value::TYPE_BOOLEAN },
345 { key::kAudioCaptureAllowed,
346 prefs::kAudioCaptureAllowed,
347 base::Value::TYPE_BOOLEAN },
348 { key::kVideoCaptureAllowed,
349 prefs::kVideoCaptureAllowed,
350 base::Value::TYPE_BOOLEAN },
351 { key::kAudioCaptureAllowedUrls,
352 prefs::kAudioCaptureAllowedUrls,
353 base::Value::TYPE_LIST },
354 { key::kVideoCaptureAllowedUrls,
355 prefs::kVideoCaptureAllowedUrls,
356 base::Value::TYPE_LIST },
357 { key::kHideWebStoreIcon,
358 prefs::kHideWebStoreIcon,
359 base::Value::TYPE_BOOLEAN },
360 { key::kVariationsRestrictParameter,
361 prefs::kVariationsRestrictParameter,
362 base::Value::TYPE_STRING },
363 { key::kSupervisedUserCreationEnabled,
364 prefs::kSupervisedUserCreationAllowed,
365 base::Value::TYPE_BOOLEAN },
366 { key::kForceEphemeralProfiles,
367 prefs::kForceEphemeralProfiles,
368 base::Value::TYPE_BOOLEAN },
369 { key::kSSLVersionMin,
370 prefs::kSSLVersionMin,
371 base::Value::TYPE_STRING },
372 { key::kSSLVersionFallbackMin,
373 prefs::kSSLVersionFallbackMin,
374 base::Value::TYPE_STRING },
375
376 #if !defined(OS_MACOSX) && !defined(OS_IOS)
377 { key::kFullscreenAllowed,
378 prefs::kFullscreenAllowed,
379 base::Value::TYPE_BOOLEAN },
380 #if defined(ENABLE_EXTENSIONS)
381 { key::kFullscreenAllowed,
382 extensions::pref_names::kAppFullscreenAllowed,
383 base::Value::TYPE_BOOLEAN },
384 #endif // defined(ENABLE_EXTENSIONS)
385 #endif // !defined(OS_MACOSX) && !defined(OS_IOS)
386
387 #if defined(OS_CHROMEOS)
388 { key::kChromeOsLockOnIdleSuspend,
389 prefs::kEnableAutoScreenLock,
390 base::Value::TYPE_BOOLEAN },
391 { key::kChromeOsReleaseChannel,
392 prefs::kChromeOsReleaseChannel,
393 base::Value::TYPE_STRING },
394 { key::kDriveDisabled,
395 prefs::kDisableDrive,
396 base::Value::TYPE_BOOLEAN },
397 { key::kDriveDisabledOverCellular,
398 prefs::kDisableDriveOverCellular,
399 base::Value::TYPE_BOOLEAN },
400 { key::kExternalStorageDisabled,
401 prefs::kExternalStorageDisabled,
402 base::Value::TYPE_BOOLEAN },
403 { key::kAudioOutputAllowed,
404 prefs::kAudioOutputAllowed,
405 base::Value::TYPE_BOOLEAN },
406 { key::kShowLogoutButtonInTray,
407 prefs::kShowLogoutButtonInTray,
408 base::Value::TYPE_BOOLEAN },
409 { key::kShelfAutoHideBehavior,
410 prefs::kShelfAutoHideBehaviorLocal,
411 base::Value::TYPE_STRING },
412 { key::kSessionLengthLimit,
413 prefs::kSessionLengthLimit,
414 base::Value::TYPE_INTEGER },
415 { key::kWaitForInitialUserActivity,
416 prefs::kSessionWaitForInitialUserActivity,
417 base::Value::TYPE_BOOLEAN },
418 { key::kPowerManagementUsesAudioActivity,
419 prefs::kPowerUseAudioActivity,
420 base::Value::TYPE_BOOLEAN },
421 { key::kPowerManagementUsesVideoActivity,
422 prefs::kPowerUseVideoActivity,
423 base::Value::TYPE_BOOLEAN },
424 { key::kAllowScreenWakeLocks,
425 prefs::kPowerAllowScreenWakeLocks,
426 base::Value::TYPE_BOOLEAN },
427 { key::kWaitForInitialUserActivity,
428 prefs::kPowerWaitForInitialUserActivity,
429 base::Value::TYPE_BOOLEAN },
430 { key::kTermsOfServiceURL,
431 prefs::kTermsOfServiceURL,
432 base::Value::TYPE_STRING },
433 { key::kShowAccessibilityOptionsInSystemTrayMenu,
434 prefs::kShouldAlwaysShowAccessibilityMenu,
435 base::Value::TYPE_BOOLEAN },
436 { key::kLargeCursorEnabled,
437 prefs::kAccessibilityLargeCursorEnabled,
438 base::Value::TYPE_BOOLEAN },
439 { key::kSpokenFeedbackEnabled,
440 prefs::kAccessibilitySpokenFeedbackEnabled,
441 base::Value::TYPE_BOOLEAN },
442 { key::kHighContrastEnabled,
443 prefs::kAccessibilityHighContrastEnabled,
444 base::Value::TYPE_BOOLEAN },
445 { key::kVirtualKeyboardEnabled,
446 prefs::kAccessibilityVirtualKeyboardEnabled,
447 base::Value::TYPE_BOOLEAN },
448 { key::kDeviceLoginScreenDefaultLargeCursorEnabled,
449 NULL,
450 base::Value::TYPE_BOOLEAN },
451 { key::kDeviceLoginScreenDefaultSpokenFeedbackEnabled,
452 NULL,
453 base::Value::TYPE_BOOLEAN },
454 { key::kDeviceLoginScreenDefaultHighContrastEnabled,
455 NULL,
456 base::Value::TYPE_BOOLEAN },
457 { key::kDeviceLoginScreenDefaultVirtualKeyboardEnabled,
458 NULL,
459 base::Value::TYPE_BOOLEAN },
460 { key::kRebootAfterUpdate,
461 prefs::kRebootAfterUpdate,
462 base::Value::TYPE_BOOLEAN },
463 { key::kAttestationEnabledForUser,
464 prefs::kAttestationEnabled,
465 base::Value::TYPE_BOOLEAN },
466 { key::kChromeOsMultiProfileUserBehavior,
467 prefs::kMultiProfileUserBehavior,
468 base::Value::TYPE_STRING },
469 { key::kKeyboardDefaultToFunctionKeys,
470 prefs::kLanguageSendFunctionKeys,
471 base::Value::TYPE_BOOLEAN },
472 { key::kTouchVirtualKeyboardEnabled,
473 prefs::kTouchVirtualKeyboardEnabled,
474 base::Value::TYPE_BOOLEAN },
475 { key::kEasyUnlockAllowed,
476 prefs::kEasyUnlockAllowed,
477 base::Value::TYPE_BOOLEAN },
478 #endif // defined(OS_CHROMEOS)
479
480 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
481 { key::kBackgroundModeEnabled,
482 prefs::kBackgroundModeEnabled,
483 base::Value::TYPE_BOOLEAN },
484 #endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
485
486 #if defined(OS_ANDROID)
487 { key::kDataCompressionProxyEnabled,
488 data_reduction_proxy::prefs::kDataReductionProxyEnabled,
489 base::Value::TYPE_BOOLEAN },
490 #endif // defined(OS_ANDROID)
491
492 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
493 { key::kNativeMessagingUserLevelHosts,
494 extensions::pref_names::kNativeMessagingUserLevelHosts,
495 base::Value::TYPE_BOOLEAN },
496 { key::kBrowserGuestModeEnabled,
497 prefs::kBrowserGuestModeEnabled,
498 base::Value::TYPE_BOOLEAN },
499 { key::kBrowserAddPersonEnabled,
500 prefs::kBrowserAddPersonEnabled,
501 base::Value::TYPE_BOOLEAN },
502 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
503 };
504
505 #if defined(ENABLE_EXTENSIONS)
GetExtensionAllowedTypesMap(ScopedVector<StringMappingListPolicyHandler::MappingEntry> * result)506 void GetExtensionAllowedTypesMap(
507 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) {
508 // Mapping from extension type names to Manifest::Type.
509 for (size_t index = 0;
510 index < extensions::schema_constants::kAllowedTypesMapSize;
511 ++index) {
512 const extensions::schema_constants::AllowedTypesMapEntry& entry =
513 extensions::schema_constants::kAllowedTypesMap[index];
514 result->push_back(new StringMappingListPolicyHandler::MappingEntry(
515 entry.name,
516 scoped_ptr<base::Value>(
517 new base::FundamentalValue(entry.manifest_type))));
518 }
519 }
520 #endif
521
522 #if !defined(OS_IOS)
GetDeprecatedFeaturesMap(ScopedVector<StringMappingListPolicyHandler::MappingEntry> * result)523 void GetDeprecatedFeaturesMap(
524 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) {
525 // Maps feature tags as specified in policy to the corresponding switch to
526 // re-enable them.
527 // TODO: Remove after 2015-04-30 per http://crbug.com/374782.
528 result->push_back(new StringMappingListPolicyHandler::MappingEntry(
529 "ShowModalDialog_EffectiveUntil20150430",
530 scoped_ptr<base::Value>(new base::StringValue(
531 switches::kEnableShowModalDialog))));
532 }
533 #endif // !defined(OS_IOS)
534
535 } // namespace
536
PopulatePolicyHandlerParameters(PolicyHandlerParameters * parameters)537 void PopulatePolicyHandlerParameters(PolicyHandlerParameters* parameters) {
538 #if defined(OS_CHROMEOS)
539 if (user_manager::UserManager::IsInitialized()) {
540 const user_manager::User* user =
541 user_manager::UserManager::Get()->GetActiveUser();
542 if (user)
543 parameters->user_id_hash = user->username_hash();
544 }
545 #endif
546 }
547
BuildHandlerList(const Schema & chrome_schema)548 scoped_ptr<ConfigurationPolicyHandlerList> BuildHandlerList(
549 const Schema& chrome_schema) {
550 scoped_ptr<ConfigurationPolicyHandlerList> handlers(
551 new ConfigurationPolicyHandlerList(
552 base::Bind(&PopulatePolicyHandlerParameters),
553 base::Bind(&GetChromePolicyDetails)));
554 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) {
555 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
556 new SimplePolicyHandler(kSimplePolicyMap[i].policy_name,
557 kSimplePolicyMap[i].preference_path,
558 kSimplePolicyMap[i].value_type)));
559 }
560
561 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
562 new AutofillPolicyHandler()));
563 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
564 new DefaultSearchPolicyHandler()));
565 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
566 new IncognitoModePolicyHandler()));
567 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
568 new ManagedBookmarksPolicyHandler(chrome_schema)));
569 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
570 new ProxyPolicyHandler()));
571 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
572 new URLBlacklistPolicyHandler()));
573
574 #if !defined(OS_IOS)
575 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
576 new FileSelectionDialogsPolicyHandler()));
577 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
578 new JavascriptPolicyHandler()));
579 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
580 new NetworkPredictionPolicyHandler()));
581 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
582 new RestoreOnStartupPolicyHandler()));
583 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
584 new browser_sync::SyncPolicyHandler()));
585
586 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
587 new StringMappingListPolicyHandler(
588 key::kEnableDeprecatedWebPlatformFeatures,
589 prefs::kEnableDeprecatedWebPlatformFeatures,
590 base::Bind(GetDeprecatedFeaturesMap))));
591 #endif // !defined(OS_IOS)
592
593 #if defined(ENABLE_EXTENSIONS)
594 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
595 new extensions::ExtensionListPolicyHandler(
596 key::kExtensionInstallWhitelist,
597 extensions::pref_names::kInstallAllowList,
598 false)));
599 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
600 new extensions::ExtensionListPolicyHandler(
601 key::kExtensionInstallBlacklist,
602 extensions::pref_names::kInstallDenyList,
603 true)));
604 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
605 new extensions::ExtensionInstallForcelistPolicyHandler()));
606 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
607 new extensions::ExtensionURLPatternListPolicyHandler(
608 key::kExtensionInstallSources,
609 extensions::pref_names::kAllowedInstallSites)));
610 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
611 new StringMappingListPolicyHandler(
612 key::kExtensionAllowedTypes,
613 extensions::pref_names::kAllowedTypes,
614 base::Bind(GetExtensionAllowedTypesMap))));
615 #endif
616
617 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
618 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
619 new DiskCacheDirPolicyHandler()));
620
621 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
622 new extensions::NativeMessagingHostListPolicyHandler(
623 key::kNativeMessagingWhitelist,
624 extensions::pref_names::kNativeMessagingWhitelist,
625 false)));
626 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
627 new extensions::NativeMessagingHostListPolicyHandler(
628 key::kNativeMessagingBlacklist,
629 extensions::pref_names::kNativeMessagingBlacklist,
630 true)));
631 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
632
633 #if !defined(OS_ANDROID) && !defined(OS_IOS)
634 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
635 new DownloadDirPolicyHandler));
636
637 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
638 new SimpleSchemaValidatingPolicyHandler(
639 key::kRegisteredProtocolHandlers,
640 prefs::kPolicyRegisteredProtocolHandlers,
641 chrome_schema,
642 SCHEMA_STRICT,
643 SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED,
644 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED)));
645 #endif
646
647 #if defined(OS_CHROMEOS)
648 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
649 new extensions::ExtensionListPolicyHandler(
650 key::kAttestationExtensionWhitelist,
651 prefs::kAttestationExtensionWhitelist,
652 false)));
653 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
654 NetworkConfigurationPolicyHandler::CreateForDevicePolicy()));
655 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
656 NetworkConfigurationPolicyHandler::CreateForUserPolicy()));
657 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
658 new PinnedLauncherAppsPolicyHandler()));
659 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
660 new ScreenMagnifierPolicyHandler()));
661 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
662 new LoginScreenPowerManagementPolicyHandler(chrome_schema)));
663
664 ScopedVector<ConfigurationPolicyHandler>
665 power_management_idle_legacy_policies;
666 power_management_idle_legacy_policies.push_back(
667 new IntRangePolicyHandler(key::kScreenDimDelayAC,
668 prefs::kPowerAcScreenDimDelayMs,
669 0,
670 INT_MAX,
671 true));
672 power_management_idle_legacy_policies.push_back(
673 new IntRangePolicyHandler(key::kScreenOffDelayAC,
674 prefs::kPowerAcScreenOffDelayMs,
675 0,
676 INT_MAX,
677 true));
678 power_management_idle_legacy_policies.push_back(
679 new IntRangePolicyHandler(key::kIdleWarningDelayAC,
680 prefs::kPowerAcIdleWarningDelayMs,
681 0,
682 INT_MAX,
683 true));
684 power_management_idle_legacy_policies.push_back(new IntRangePolicyHandler(
685 key::kIdleDelayAC, prefs::kPowerAcIdleDelayMs, 0, INT_MAX, true));
686 power_management_idle_legacy_policies.push_back(
687 new IntRangePolicyHandler(key::kScreenDimDelayBattery,
688 prefs::kPowerBatteryScreenDimDelayMs,
689 0,
690 INT_MAX,
691 true));
692 power_management_idle_legacy_policies.push_back(
693 new IntRangePolicyHandler(key::kScreenOffDelayBattery,
694 prefs::kPowerBatteryScreenOffDelayMs,
695 0,
696 INT_MAX,
697 true));
698 power_management_idle_legacy_policies.push_back(
699 new IntRangePolicyHandler(key::kIdleWarningDelayBattery,
700 prefs::kPowerBatteryIdleWarningDelayMs,
701 0,
702 INT_MAX,
703 true));
704 power_management_idle_legacy_policies.push_back(
705 new IntRangePolicyHandler(key::kIdleDelayBattery,
706 prefs::kPowerBatteryIdleDelayMs,
707 0,
708 INT_MAX,
709 true));
710 power_management_idle_legacy_policies.push_back(new IntRangePolicyHandler(
711 key::kIdleActionAC,
712 prefs::kPowerAcIdleAction,
713 chromeos::PowerPolicyController::ACTION_SUSPEND,
714 chromeos::PowerPolicyController::ACTION_DO_NOTHING,
715 false));
716 power_management_idle_legacy_policies.push_back(new IntRangePolicyHandler(
717 key::kIdleActionBattery,
718 prefs::kPowerBatteryIdleAction,
719 chromeos::PowerPolicyController::ACTION_SUSPEND,
720 chromeos::PowerPolicyController::ACTION_DO_NOTHING,
721 false));
722 power_management_idle_legacy_policies.push_back(
723 new DeprecatedIdleActionHandler());
724
725 ScopedVector<ConfigurationPolicyHandler> screen_lock_legacy_policies;
726 screen_lock_legacy_policies.push_back(
727 new IntRangePolicyHandler(key::kScreenLockDelayAC,
728 prefs::kPowerAcScreenLockDelayMs,
729 0,
730 INT_MAX,
731 true));
732 screen_lock_legacy_policies.push_back(
733 new IntRangePolicyHandler(key::kScreenLockDelayBattery,
734 prefs::kPowerBatteryScreenLockDelayMs,
735 0,
736 INT_MAX,
737 true));
738
739 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
740 new IntRangePolicyHandler(key::kSAMLOfflineSigninTimeLimit,
741 prefs::kSAMLOfflineSigninTimeLimit,
742 -1,
743 INT_MAX,
744 true)));
745 handlers->AddHandler(
746 make_scoped_ptr<ConfigurationPolicyHandler>(new IntRangePolicyHandler(
747 key::kLidCloseAction,
748 prefs::kPowerLidClosedAction,
749 chromeos::PowerPolicyController::ACTION_SUSPEND,
750 chromeos::PowerPolicyController::ACTION_DO_NOTHING,
751 false)));
752 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
753 new IntPercentageToDoublePolicyHandler(
754 key::kPresentationScreenDimDelayScale,
755 prefs::kPowerPresentationScreenDimDelayFactor,
756 100,
757 INT_MAX,
758 true)));
759 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
760 new IntPercentageToDoublePolicyHandler(
761 key::kUserActivityScreenDimDelayScale,
762 prefs::kPowerUserActivityScreenDimDelayFactor,
763 100,
764 INT_MAX,
765 true)));
766 handlers->AddHandler(
767 make_scoped_ptr<ConfigurationPolicyHandler>(new IntRangePolicyHandler(
768 key::kUptimeLimit, prefs::kUptimeLimit, 3600, INT_MAX, true)));
769 handlers->AddHandler(
770 make_scoped_ptr<ConfigurationPolicyHandler>(new IntRangePolicyHandler(
771 key::kDeviceLoginScreenDefaultScreenMagnifierType,
772 NULL,
773 0,
774 ash::MAGNIFIER_FULL,
775 false)));
776 // TODO(binjin): Remove LegacyPoliciesDeprecatingPolicyHandler for these two
777 // policies once deprecation of legacy power management policies is done.
778 // http://crbug.com/346229
779 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
780 new LegacyPoliciesDeprecatingPolicyHandler(
781 power_management_idle_legacy_policies.Pass(),
782 make_scoped_ptr<SchemaValidatingPolicyHandler>(
783 new PowerManagementIdleSettingsPolicyHandler(chrome_schema)))));
784 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
785 new LegacyPoliciesDeprecatingPolicyHandler(
786 screen_lock_legacy_policies.Pass(),
787 make_scoped_ptr<SchemaValidatingPolicyHandler>(
788 new ScreenLockDelayPolicyHandler(chrome_schema)))));
789 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
790 new ExternalDataPolicyHandler(key::kUserAvatarImage)));
791 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
792 new ExternalDataPolicyHandler(key::kWallpaperImage)));
793 handlers->AddHandler(make_scoped_ptr<ConfigurationPolicyHandler>(
794 new SimpleSchemaValidatingPolicyHandler(
795 key::kSessionLocales,
796 NULL,
797 chrome_schema,
798 SCHEMA_STRICT,
799 SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED,
800 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED)));
801 #endif // defined(OS_CHROMEOS)
802
803 return handlers.Pass();
804 }
805
806 } // namespace policy
807