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