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