OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/policy/configuration_policy_handler_list_factory.h" | 5 #include "chrome/browser/policy/configuration_policy_handler_list_factory.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "chrome/browser/net/disk_cache_dir_policy_handler.h" | 18 #include "chrome/browser/net/disk_cache_dir_policy_handler.h" |
19 #include "chrome/browser/net/safe_search_util.h" | |
19 #include "chrome/browser/policy/file_selection_dialogs_policy_handler.h" | 20 #include "chrome/browser/policy/file_selection_dialogs_policy_handler.h" |
20 #include "chrome/browser/policy/javascript_policy_handler.h" | 21 #include "chrome/browser/policy/javascript_policy_handler.h" |
21 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h" | 22 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h" |
22 #include "chrome/browser/policy/network_prediction_policy_handler.h" | 23 #include "chrome/browser/policy/network_prediction_policy_handler.h" |
23 #include "chrome/browser/profiles/incognito_mode_policy_handler.h" | 24 #include "chrome/browser/profiles/incognito_mode_policy_handler.h" |
24 #include "chrome/browser/sessions/restore_on_startup_policy_handler.h" | 25 #include "chrome/browser/sessions/restore_on_startup_policy_handler.h" |
25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/features.h" | 27 #include "chrome/common/features.h" |
27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "components/bookmarks/common/bookmark_pref_names.h" | 29 #include "components/bookmarks/common/bookmark_pref_names.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 base::Value::TYPE_BOOLEAN }, | 108 base::Value::TYPE_BOOLEAN }, |
108 { key::kPacHttpsUrlStrippingEnabled, | 109 { key::kPacHttpsUrlStrippingEnabled, |
109 prefs::kPacHttpsUrlStrippingEnabled, | 110 prefs::kPacHttpsUrlStrippingEnabled, |
110 base::Value::TYPE_BOOLEAN }, | 111 base::Value::TYPE_BOOLEAN }, |
111 { key::kSafeBrowsingEnabled, | 112 { key::kSafeBrowsingEnabled, |
112 prefs::kSafeBrowsingEnabled, | 113 prefs::kSafeBrowsingEnabled, |
113 base::Value::TYPE_BOOLEAN }, | 114 base::Value::TYPE_BOOLEAN }, |
114 { key::kForceGoogleSafeSearch, | 115 { key::kForceGoogleSafeSearch, |
115 prefs::kForceGoogleSafeSearch, | 116 prefs::kForceGoogleSafeSearch, |
116 base::Value::TYPE_BOOLEAN }, | 117 base::Value::TYPE_BOOLEAN }, |
117 { key::kForceYouTubeSafetyMode, | 118 //{ key::kForceYouTubeSafetyMode, // Deprecated, the ForceYouTubeSafetyMode |
Thiemo Nagel
2016/08/12 12:12:20
Nit: We don't keep commented-out code. Just drop
ljusten (tachyonic)
2016/08/16 09:24:54
Done.
| |
118 prefs::kForceYouTubeSafetyMode, | 119 // prefs::kForceYouTubeSafetyMode, // POLICY is converted to the ForceYouTube- |
119 base::Value::TYPE_BOOLEAN }, | 120 // base::Value::TYPE_BOOLEAN }, // Restrict SETTING in the code below. |
121 { key::kForceYouTubeRestrict, | |
122 prefs::kForceYouTubeRestrict, | |
123 base::Value::TYPE_INTEGER}, | |
120 { key::kPasswordManagerEnabled, | 124 { key::kPasswordManagerEnabled, |
121 password_manager::prefs::kPasswordManagerSavingEnabled, | 125 password_manager::prefs::kPasswordManagerSavingEnabled, |
122 base::Value::TYPE_BOOLEAN }, | 126 base::Value::TYPE_BOOLEAN }, |
123 { key::kPrintingEnabled, | 127 { key::kPrintingEnabled, |
124 prefs::kPrintingEnabled, | 128 prefs::kPrintingEnabled, |
125 base::Value::TYPE_BOOLEAN }, | 129 base::Value::TYPE_BOOLEAN }, |
126 { key::kDisablePrintPreview, | 130 { key::kDisablePrintPreview, |
127 prefs::kPrintPreviewDisabled, | 131 prefs::kPrintPreviewDisabled, |
128 base::Value::TYPE_BOOLEAN }, | 132 base::Value::TYPE_BOOLEAN }, |
129 { key::kDefaultPrinterSelection, | 133 { key::kDefaultPrinterSelection, |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
591 class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler { | 595 class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler { |
592 public: | 596 public: |
593 ForceSafeSearchPolicyHandler() | 597 ForceSafeSearchPolicyHandler() |
594 : TypeCheckingPolicyHandler(key::kForceSafeSearch, | 598 : TypeCheckingPolicyHandler(key::kForceSafeSearch, |
595 base::Value::TYPE_BOOLEAN) {} | 599 base::Value::TYPE_BOOLEAN) {} |
596 ~ForceSafeSearchPolicyHandler() override {} | 600 ~ForceSafeSearchPolicyHandler() override {} |
597 | 601 |
598 // ConfigurationPolicyHandler implementation: | 602 // ConfigurationPolicyHandler implementation: |
599 void ApplyPolicySettings(const PolicyMap& policies, | 603 void ApplyPolicySettings(const PolicyMap& policies, |
600 PrefValueMap* prefs) override { | 604 PrefValueMap* prefs) override { |
601 // If either of the new GoogleSafeSearch or YouTubeSafetyMode policies is | 605 // If either of the new ForceGoogleSafeSearch, ForceYouTubeSafetyMode or |
602 // defined, then this one should be ignored. crbug.com/476908 | 606 // ForceYouTubeRestrict policies are defined, then this one should be |
603 // Note: Those policies are declared in kSimplePolicyMap above. | 607 // ignored. crbug.com/476908, crbug.com/590478 |
608 // Note: Those policies are declared in kSimplePolicyMap above. except | |
609 // ForceYouTubeSafetyMode, which has been replaced by | |
610 // ForceYouTubeRestrict. | |
604 if (policies.GetValue(key::kForceGoogleSafeSearch) || | 611 if (policies.GetValue(key::kForceGoogleSafeSearch) || |
Thiemo Nagel
2016/08/12 12:12:20
In principle, we have the concept of a LegacyPolic
ljusten (tachyonic)
2016/08/16 09:24:54
Yes, this could be done. However, I decided agains
| |
605 policies.GetValue(key::kForceYouTubeSafetyMode)) { | 612 policies.GetValue(key::kForceYouTubeSafetyMode) || |
613 policies.GetValue(key::kForceYouTubeRestrict)) { | |
606 return; | 614 return; |
607 } | 615 } |
608 const base::Value* value = policies.GetValue(policy_name()); | 616 const base::Value* value = policies.GetValue(policy_name()); |
609 if (value) { | 617 if (value) { |
618 bool enabled; | |
610 prefs->SetValue(prefs::kForceGoogleSafeSearch, value->CreateDeepCopy()); | 619 prefs->SetValue(prefs::kForceGoogleSafeSearch, value->CreateDeepCopy()); |
611 prefs->SetValue(prefs::kForceYouTubeSafetyMode, value->CreateDeepCopy()); | 620 |
621 // Note that ForceYouTubeRestrict is an int policy, | |
622 // we cannot simply deep copy value, which is a boolean. | |
623 if (value->GetAsBoolean(&enabled)) | |
624 prefs->SetValue(prefs::kForceYouTubeRestrict, | |
625 base::MakeUnique<base::FundamentalValue>( | |
626 (int)(enabled ? safe_search_util::YTRM_MODERATE | |
Thiemo Nagel
2016/08/12 12:12:20
I don't think the (int) cast is necessary. In gen
ljusten (tachyonic)
2016/08/16 09:24:54
Done.
| |
627 : safe_search_util::YTRM_OFF))); | |
612 } | 628 } |
613 } | 629 } |
614 | 630 |
615 private: | 631 private: |
616 DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler); | 632 DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler); |
617 }; | 633 }; |
618 | 634 |
635 class ForceYouTubeSafetyModePolicyHandler : public TypeCheckingPolicyHandler { | |
Thiemo Nagel
2016/08/12 12:12:20
configuration_policy_handler_list_factory.cc doesn
ljusten (tachyonic)
2016/08/16 09:24:54
I just copy&pasted code! Nothing wrong with that!
| |
636 public: | |
637 ForceYouTubeSafetyModePolicyHandler() | |
638 : TypeCheckingPolicyHandler(key::kForceYouTubeSafetyMode, | |
639 base::Value::TYPE_BOOLEAN) {} | |
640 ~ForceYouTubeSafetyModePolicyHandler() override {} | |
641 | |
642 // ConfigurationPolicyHandler implementation: | |
643 void ApplyPolicySettings(const PolicyMap& policies, | |
644 PrefValueMap* prefs) override { | |
645 // If only the deprecated ForceYouTubeSafetyMode policy is set, | |
646 // but not ForceYouTubeRestrict, set ForceYouTubeRestrict to Moderate. | |
647 if (policies.GetValue(key::kForceYouTubeRestrict)) | |
648 return; | |
649 | |
650 const base::Value* value = policies.GetValue(policy_name()); | |
651 bool enabled; | |
652 if (value && value->GetAsBoolean(&enabled)) | |
653 prefs->SetValue(prefs::kForceYouTubeRestrict, | |
654 base::MakeUnique<base::FundamentalValue>( | |
655 (int)(enabled ? safe_search_util::YTRM_MODERATE | |
Thiemo Nagel
2016/08/12 12:12:20
The (int) cast doesn't seem necessary.
ljusten (tachyonic)
2016/08/16 09:24:54
True, I've removed it. I added it because I don't
| |
656 : safe_search_util::YTRM_OFF))); | |
657 } | |
658 | |
659 private: | |
660 DISALLOW_COPY_AND_ASSIGN(ForceYouTubeSafetyModePolicyHandler); | |
661 }; | |
662 | |
619 #if defined(ENABLE_EXTENSIONS) | 663 #if defined(ENABLE_EXTENSIONS) |
620 void GetExtensionAllowedTypesMap( | 664 void GetExtensionAllowedTypesMap( |
621 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) { | 665 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) { |
622 // Mapping from extension type names to Manifest::Type. | 666 // Mapping from extension type names to Manifest::Type. |
623 for (size_t index = 0; | 667 for (size_t index = 0; |
624 index < extensions::schema_constants::kAllowedTypesMapSize; | 668 index < extensions::schema_constants::kAllowedTypesMapSize; |
625 ++index) { | 669 ++index) { |
626 const extensions::schema_constants::AllowedTypesMapEntry& entry = | 670 const extensions::schema_constants::AllowedTypesMapEntry& entry = |
627 extensions::schema_constants::kAllowedTypesMap[index]; | 671 extensions::schema_constants::kAllowedTypesMap[index]; |
628 result->push_back(new StringMappingListPolicyHandler::MappingEntry( | 672 result->push_back(new StringMappingListPolicyHandler::MappingEntry( |
(...skipping 30 matching lines...) Expand all Loading... | |
659 base::Bind(&GetChromePolicyDetails))); | 703 base::Bind(&GetChromePolicyDetails))); |
660 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) { | 704 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) { |
661 handlers->AddHandler(base::WrapUnique(new SimplePolicyHandler( | 705 handlers->AddHandler(base::WrapUnique(new SimplePolicyHandler( |
662 kSimplePolicyMap[i].policy_name, kSimplePolicyMap[i].preference_path, | 706 kSimplePolicyMap[i].policy_name, kSimplePolicyMap[i].preference_path, |
663 kSimplePolicyMap[i].value_type))); | 707 kSimplePolicyMap[i].value_type))); |
664 } | 708 } |
665 | 709 |
666 handlers->AddHandler(base::WrapUnique(new AutofillPolicyHandler())); | 710 handlers->AddHandler(base::WrapUnique(new AutofillPolicyHandler())); |
667 handlers->AddHandler(base::WrapUnique(new DefaultSearchPolicyHandler())); | 711 handlers->AddHandler(base::WrapUnique(new DefaultSearchPolicyHandler())); |
668 handlers->AddHandler(base::WrapUnique(new ForceSafeSearchPolicyHandler())); | 712 handlers->AddHandler(base::WrapUnique(new ForceSafeSearchPolicyHandler())); |
713 handlers->AddHandler( | |
714 base::WrapUnique(new ForceYouTubeSafetyModePolicyHandler())); | |
669 handlers->AddHandler(base::WrapUnique(new IncognitoModePolicyHandler())); | 715 handlers->AddHandler(base::WrapUnique(new IncognitoModePolicyHandler())); |
670 handlers->AddHandler( | 716 handlers->AddHandler( |
671 base::WrapUnique(new ManagedBookmarksPolicyHandler(chrome_schema))); | 717 base::WrapUnique(new ManagedBookmarksPolicyHandler(chrome_schema))); |
672 handlers->AddHandler(base::WrapUnique(new ProxyPolicyHandler())); | 718 handlers->AddHandler(base::WrapUnique(new ProxyPolicyHandler())); |
673 handlers->AddHandler(base::WrapUnique(new URLBlacklistPolicyHandler())); | 719 handlers->AddHandler(base::WrapUnique(new URLBlacklistPolicyHandler())); |
674 | 720 |
675 handlers->AddHandler(base::WrapUnique(new SimpleSchemaValidatingPolicyHandler( | 721 handlers->AddHandler(base::WrapUnique(new SimpleSchemaValidatingPolicyHandler( |
676 key::kCertificateTransparencyEnforcementDisabledForUrls, | 722 key::kCertificateTransparencyEnforcementDisabledForUrls, |
677 certificate_transparency::prefs::kCTExcludedHosts, chrome_schema, | 723 certificate_transparency::prefs::kCTExcludedHosts, chrome_schema, |
678 SCHEMA_STRICT, SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED, | 724 SCHEMA_STRICT, SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED, |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED, | 914 SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED, |
869 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED))); | 915 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED))); |
870 handlers->AddHandler(base::WrapUnique( | 916 handlers->AddHandler(base::WrapUnique( |
871 new chromeos::KeyPermissionsPolicyHandler(chrome_schema))); | 917 new chromeos::KeyPermissionsPolicyHandler(chrome_schema))); |
872 #endif // defined(OS_CHROMEOS) | 918 #endif // defined(OS_CHROMEOS) |
873 | 919 |
874 return handlers; | 920 return handlers; |
875 } | 921 } |
876 | 922 |
877 } // namespace policy | 923 } // namespace policy |
OLD | NEW |