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