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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 base::Value::TYPE_BOOLEAN }, | 113 base::Value::TYPE_BOOLEAN }, |
113 { key::kPacHttpsUrlStrippingEnabled, | 114 { key::kPacHttpsUrlStrippingEnabled, |
114 prefs::kPacHttpsUrlStrippingEnabled, | 115 prefs::kPacHttpsUrlStrippingEnabled, |
115 base::Value::TYPE_BOOLEAN }, | 116 base::Value::TYPE_BOOLEAN }, |
116 { key::kSafeBrowsingEnabled, | 117 { key::kSafeBrowsingEnabled, |
117 prefs::kSafeBrowsingEnabled, | 118 prefs::kSafeBrowsingEnabled, |
118 base::Value::TYPE_BOOLEAN }, | 119 base::Value::TYPE_BOOLEAN }, |
119 { key::kForceGoogleSafeSearch, | 120 { key::kForceGoogleSafeSearch, |
120 prefs::kForceGoogleSafeSearch, | 121 prefs::kForceGoogleSafeSearch, |
121 base::Value::TYPE_BOOLEAN }, | 122 base::Value::TYPE_BOOLEAN }, |
122 { key::kForceYouTubeSafetyMode, | 123 { key::kForceYouTubeRestrict, |
123 prefs::kForceYouTubeSafetyMode, | 124 prefs::kForceYouTubeRestrict, |
124 base::Value::TYPE_BOOLEAN }, | 125 base::Value::TYPE_INTEGER}, |
125 { key::kPasswordManagerEnabled, | 126 { key::kPasswordManagerEnabled, |
126 password_manager::prefs::kPasswordManagerSavingEnabled, | 127 password_manager::prefs::kPasswordManagerSavingEnabled, |
127 base::Value::TYPE_BOOLEAN }, | 128 base::Value::TYPE_BOOLEAN }, |
128 { key::kPrintingEnabled, | 129 { key::kPrintingEnabled, |
129 prefs::kPrintingEnabled, | 130 prefs::kPrintingEnabled, |
130 base::Value::TYPE_BOOLEAN }, | 131 base::Value::TYPE_BOOLEAN }, |
131 { key::kDisablePrintPreview, | 132 { key::kDisablePrintPreview, |
132 prefs::kPrintPreviewDisabled, | 133 prefs::kPrintPreviewDisabled, |
133 base::Value::TYPE_BOOLEAN }, | 134 base::Value::TYPE_BOOLEAN }, |
134 { key::kDefaultPrinterSelection, | 135 { key::kDefaultPrinterSelection, |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler { | 606 class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler { |
606 public: | 607 public: |
607 ForceSafeSearchPolicyHandler() | 608 ForceSafeSearchPolicyHandler() |
608 : TypeCheckingPolicyHandler(key::kForceSafeSearch, | 609 : TypeCheckingPolicyHandler(key::kForceSafeSearch, |
609 base::Value::TYPE_BOOLEAN) {} | 610 base::Value::TYPE_BOOLEAN) {} |
610 ~ForceSafeSearchPolicyHandler() override {} | 611 ~ForceSafeSearchPolicyHandler() override {} |
611 | 612 |
612 // ConfigurationPolicyHandler implementation: | 613 // ConfigurationPolicyHandler implementation: |
613 void ApplyPolicySettings(const PolicyMap& policies, | 614 void ApplyPolicySettings(const PolicyMap& policies, |
614 PrefValueMap* prefs) override { | 615 PrefValueMap* prefs) override { |
615 // If either of the new GoogleSafeSearch or YouTubeSafetyMode policies is | 616 // If either of the new ForceGoogleSafeSearch, ForceYouTubeSafetyMode or |
616 // defined, then this one should be ignored. crbug.com/476908 | 617 // ForceYouTubeRestrict policies are defined, then this one should be |
617 // Note: Those policies are declared in kSimplePolicyMap above. | 618 // ignored. crbug.com/476908, crbug.com/590478 |
| 619 // Note: Those policies are declared in kSimplePolicyMap above. except |
| 620 // ForceYouTubeSafetyMode, which has been replaced by |
| 621 // ForceYouTubeRestrict. |
618 if (policies.GetValue(key::kForceGoogleSafeSearch) || | 622 if (policies.GetValue(key::kForceGoogleSafeSearch) || |
619 policies.GetValue(key::kForceYouTubeSafetyMode)) { | 623 policies.GetValue(key::kForceYouTubeSafetyMode) || |
| 624 policies.GetValue(key::kForceYouTubeRestrict)) { |
620 return; | 625 return; |
621 } | 626 } |
622 const base::Value* value = policies.GetValue(policy_name()); | 627 const base::Value* value = policies.GetValue(policy_name()); |
623 if (value) { | 628 if (value) { |
| 629 bool enabled; |
624 prefs->SetValue(prefs::kForceGoogleSafeSearch, value->CreateDeepCopy()); | 630 prefs->SetValue(prefs::kForceGoogleSafeSearch, value->CreateDeepCopy()); |
625 prefs->SetValue(prefs::kForceYouTubeSafetyMode, value->CreateDeepCopy()); | 631 |
| 632 // Note that ForceYouTubeRestrict is an int policy, |
| 633 // we cannot simply deep copy value, which is a boolean. |
| 634 if (value->GetAsBoolean(&enabled)) { |
| 635 prefs->SetValue( |
| 636 prefs::kForceYouTubeRestrict, |
| 637 base::MakeUnique<base::FundamentalValue>(static_cast<int>( |
| 638 enabled ? safe_search_util::YouTubeRestrictMode::MODERATE |
| 639 : safe_search_util::YouTubeRestrictMode::OFF))); |
| 640 } |
626 } | 641 } |
627 } | 642 } |
628 | 643 |
629 private: | 644 private: |
630 DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler); | 645 DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler); |
631 }; | 646 }; |
632 | 647 |
| 648 class ForceYouTubeSafetyModePolicyHandler : public TypeCheckingPolicyHandler { |
| 649 public: |
| 650 ForceYouTubeSafetyModePolicyHandler() |
| 651 : TypeCheckingPolicyHandler(key::kForceYouTubeSafetyMode, |
| 652 base::Value::TYPE_BOOLEAN) {} |
| 653 ~ForceYouTubeSafetyModePolicyHandler() override {} |
| 654 |
| 655 // ConfigurationPolicyHandler implementation: |
| 656 void ApplyPolicySettings(const PolicyMap& policies, |
| 657 PrefValueMap* prefs) override { |
| 658 // If only the deprecated ForceYouTubeSafetyMode policy is set, |
| 659 // but not ForceYouTubeRestrict, set ForceYouTubeRestrict to Moderate. |
| 660 if (policies.GetValue(key::kForceYouTubeRestrict)) |
| 661 return; |
| 662 |
| 663 const base::Value* value = policies.GetValue(policy_name()); |
| 664 bool enabled; |
| 665 if (value && value->GetAsBoolean(&enabled)) { |
| 666 prefs->SetValue( |
| 667 prefs::kForceYouTubeRestrict, |
| 668 base::MakeUnique<base::FundamentalValue>(static_cast<int>( |
| 669 enabled ? safe_search_util::YouTubeRestrictMode::MODERATE |
| 670 : safe_search_util::YouTubeRestrictMode::OFF))); |
| 671 } |
| 672 } |
| 673 |
| 674 private: |
| 675 DISALLOW_COPY_AND_ASSIGN(ForceYouTubeSafetyModePolicyHandler); |
| 676 }; |
| 677 |
633 #if defined(ENABLE_EXTENSIONS) | 678 #if defined(ENABLE_EXTENSIONS) |
634 void GetExtensionAllowedTypesMap( | 679 void GetExtensionAllowedTypesMap( |
635 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) { | 680 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) { |
636 // Mapping from extension type names to Manifest::Type. | 681 // Mapping from extension type names to Manifest::Type. |
637 for (size_t index = 0; | 682 for (size_t index = 0; |
638 index < extensions::schema_constants::kAllowedTypesMapSize; | 683 index < extensions::schema_constants::kAllowedTypesMapSize; |
639 ++index) { | 684 ++index) { |
640 const extensions::schema_constants::AllowedTypesMapEntry& entry = | 685 const extensions::schema_constants::AllowedTypesMapEntry& entry = |
641 extensions::schema_constants::kAllowedTypesMap[index]; | 686 extensions::schema_constants::kAllowedTypesMap[index]; |
642 result->push_back(new StringMappingListPolicyHandler::MappingEntry( | 687 result->push_back(new StringMappingListPolicyHandler::MappingEntry( |
(...skipping 30 matching lines...) Expand all Loading... |
673 base::Bind(&GetChromePolicyDetails))); | 718 base::Bind(&GetChromePolicyDetails))); |
674 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) { | 719 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) { |
675 handlers->AddHandler(base::WrapUnique(new SimplePolicyHandler( | 720 handlers->AddHandler(base::WrapUnique(new SimplePolicyHandler( |
676 kSimplePolicyMap[i].policy_name, kSimplePolicyMap[i].preference_path, | 721 kSimplePolicyMap[i].policy_name, kSimplePolicyMap[i].preference_path, |
677 kSimplePolicyMap[i].value_type))); | 722 kSimplePolicyMap[i].value_type))); |
678 } | 723 } |
679 | 724 |
680 handlers->AddHandler(base::WrapUnique(new AutofillPolicyHandler())); | 725 handlers->AddHandler(base::WrapUnique(new AutofillPolicyHandler())); |
681 handlers->AddHandler(base::WrapUnique(new DefaultSearchPolicyHandler())); | 726 handlers->AddHandler(base::WrapUnique(new DefaultSearchPolicyHandler())); |
682 handlers->AddHandler(base::WrapUnique(new ForceSafeSearchPolicyHandler())); | 727 handlers->AddHandler(base::WrapUnique(new ForceSafeSearchPolicyHandler())); |
| 728 handlers->AddHandler( |
| 729 base::WrapUnique(new ForceYouTubeSafetyModePolicyHandler())); |
683 handlers->AddHandler(base::WrapUnique(new IncognitoModePolicyHandler())); | 730 handlers->AddHandler(base::WrapUnique(new IncognitoModePolicyHandler())); |
684 handlers->AddHandler( | 731 handlers->AddHandler( |
685 base::WrapUnique(new ManagedBookmarksPolicyHandler(chrome_schema))); | 732 base::WrapUnique(new ManagedBookmarksPolicyHandler(chrome_schema))); |
686 handlers->AddHandler(base::WrapUnique(new ProxyPolicyHandler())); | 733 handlers->AddHandler(base::WrapUnique(new ProxyPolicyHandler())); |
687 handlers->AddHandler(base::WrapUnique(new URLBlacklistPolicyHandler())); | 734 handlers->AddHandler(base::WrapUnique(new URLBlacklistPolicyHandler())); |
688 | 735 |
689 handlers->AddHandler(base::WrapUnique(new SimpleSchemaValidatingPolicyHandler( | 736 handlers->AddHandler(base::WrapUnique(new SimpleSchemaValidatingPolicyHandler( |
690 key::kCertificateTransparencyEnforcementDisabledForUrls, | 737 key::kCertificateTransparencyEnforcementDisabledForUrls, |
691 certificate_transparency::prefs::kCTExcludedHosts, chrome_schema, | 738 certificate_transparency::prefs::kCTExcludedHosts, chrome_schema, |
692 SCHEMA_STRICT, SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED, | 739 SCHEMA_STRICT, SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED))); | 930 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED))); |
884 handlers->AddHandler(base::WrapUnique( | 931 handlers->AddHandler(base::WrapUnique( |
885 new chromeos::KeyPermissionsPolicyHandler(chrome_schema))); | 932 new chromeos::KeyPermissionsPolicyHandler(chrome_schema))); |
886 handlers->AddHandler(base::WrapUnique(new DefaultGeolocationPolicyHandler())); | 933 handlers->AddHandler(base::WrapUnique(new DefaultGeolocationPolicyHandler())); |
887 #endif // defined(OS_CHROMEOS) | 934 #endif // defined(OS_CHROMEOS) |
888 | 935 |
889 return handlers; | 936 return handlers; |
890 } | 937 } |
891 | 938 |
892 } // namespace policy | 939 } // namespace policy |
OLD | NEW |