Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: chrome/browser/policy/configuration_policy_handler_list_factory.cc

Issue 2401743003: Recommit and fix of "Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyM… (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler { 612 class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler {
612 public: 613 public:
613 ForceSafeSearchPolicyHandler() 614 ForceSafeSearchPolicyHandler()
614 : TypeCheckingPolicyHandler(key::kForceSafeSearch, 615 : TypeCheckingPolicyHandler(key::kForceSafeSearch,
615 base::Value::TYPE_BOOLEAN) {} 616 base::Value::TYPE_BOOLEAN) {}
616 ~ForceSafeSearchPolicyHandler() override {} 617 ~ForceSafeSearchPolicyHandler() override {}
617 618
618 // ConfigurationPolicyHandler implementation: 619 // ConfigurationPolicyHandler implementation:
619 void ApplyPolicySettings(const PolicyMap& policies, 620 void ApplyPolicySettings(const PolicyMap& policies,
620 PrefValueMap* prefs) override { 621 PrefValueMap* prefs) override {
621 // If either of the new GoogleSafeSearch or YouTubeSafetyMode policies is 622 // If either of the new ForceGoogleSafeSearch, ForceYouTubeSafetyMode or
622 // defined, then this one should be ignored. crbug.com/476908 623 // ForceYouTubeRestrict policies are defined, then this one should be
623 // Note: Those policies are declared in kSimplePolicyMap above. 624 // ignored. crbug.com/476908, crbug.com/590478
625 // Note: Those policies are declared in kSimplePolicyMap above, except
626 // ForceYouTubeSafetyMode, which has been replaced by ForceYouTubeRestrict.
624 if (policies.GetValue(key::kForceGoogleSafeSearch) || 627 if (policies.GetValue(key::kForceGoogleSafeSearch) ||
625 policies.GetValue(key::kForceYouTubeSafetyMode)) { 628 policies.GetValue(key::kForceYouTubeSafetyMode) ||
629 policies.GetValue(key::kForceYouTubeRestrict)) {
626 return; 630 return;
627 } 631 }
628 const base::Value* value = policies.GetValue(policy_name()); 632 const base::Value* value = policies.GetValue(policy_name());
629 if (value) { 633 if (value) {
634 bool enabled;
630 prefs->SetValue(prefs::kForceGoogleSafeSearch, value->CreateDeepCopy()); 635 prefs->SetValue(prefs::kForceGoogleSafeSearch, value->CreateDeepCopy());
631 prefs->SetValue(prefs::kForceYouTubeSafetyMode, value->CreateDeepCopy()); 636
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 }
632 } 646 }
633 } 647 }
634 648
635 private: 649 private:
636 DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler); 650 DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler);
637 }; 651 };
638 652
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
639 #if defined(ENABLE_EXTENSIONS) 683 #if defined(ENABLE_EXTENSIONS)
640 void GetExtensionAllowedTypesMap( 684 void GetExtensionAllowedTypesMap(
641 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) { 685 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) {
642 // Mapping from extension type names to Manifest::Type. 686 // Mapping from extension type names to Manifest::Type.
643 for (size_t index = 0; 687 for (size_t index = 0;
644 index < extensions::schema_constants::kAllowedTypesMapSize; 688 index < extensions::schema_constants::kAllowedTypesMapSize;
645 ++index) { 689 ++index) {
646 const extensions::schema_constants::AllowedTypesMapEntry& entry = 690 const extensions::schema_constants::AllowedTypesMapEntry& entry =
647 extensions::schema_constants::kAllowedTypesMap[index]; 691 extensions::schema_constants::kAllowedTypesMap[index];
648 result->push_back(new StringMappingListPolicyHandler::MappingEntry( 692 result->push_back(new StringMappingListPolicyHandler::MappingEntry(
(...skipping 30 matching lines...) Expand all
679 base::Bind(&GetChromePolicyDetails))); 723 base::Bind(&GetChromePolicyDetails)));
680 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) { 724 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) {
681 handlers->AddHandler(base::MakeUnique<SimplePolicyHandler>( 725 handlers->AddHandler(base::MakeUnique<SimplePolicyHandler>(
682 kSimplePolicyMap[i].policy_name, kSimplePolicyMap[i].preference_path, 726 kSimplePolicyMap[i].policy_name, kSimplePolicyMap[i].preference_path,
683 kSimplePolicyMap[i].value_type)); 727 kSimplePolicyMap[i].value_type));
684 } 728 }
685 729
686 handlers->AddHandler(base::MakeUnique<AutofillPolicyHandler>()); 730 handlers->AddHandler(base::MakeUnique<AutofillPolicyHandler>());
687 handlers->AddHandler(base::MakeUnique<DefaultSearchPolicyHandler>()); 731 handlers->AddHandler(base::MakeUnique<DefaultSearchPolicyHandler>());
688 handlers->AddHandler(base::MakeUnique<ForceSafeSearchPolicyHandler>()); 732 handlers->AddHandler(base::MakeUnique<ForceSafeSearchPolicyHandler>());
733 handlers->AddHandler(base::MakeUnique<ForceYouTubeSafetyModePolicyHandler>());
689 handlers->AddHandler(base::MakeUnique<IncognitoModePolicyHandler>()); 734 handlers->AddHandler(base::MakeUnique<IncognitoModePolicyHandler>());
690 handlers->AddHandler( 735 handlers->AddHandler(
691 base::MakeUnique<ManagedBookmarksPolicyHandler>(chrome_schema)); 736 base::MakeUnique<ManagedBookmarksPolicyHandler>(chrome_schema));
692 handlers->AddHandler(base::MakeUnique<ProxyPolicyHandler>()); 737 handlers->AddHandler(base::MakeUnique<ProxyPolicyHandler>());
693 handlers->AddHandler(base::MakeUnique<URLBlacklistPolicyHandler>()); 738 handlers->AddHandler(base::MakeUnique<URLBlacklistPolicyHandler>());
694 739
695 handlers->AddHandler(base::MakeUnique<SimpleSchemaValidatingPolicyHandler>( 740 handlers->AddHandler(base::MakeUnique<SimpleSchemaValidatingPolicyHandler>(
696 key::kCertificateTransparencyEnforcementDisabledForUrls, 741 key::kCertificateTransparencyEnforcementDisabledForUrls,
697 certificate_transparency::prefs::kCTExcludedHosts, chrome_schema, 742 certificate_transparency::prefs::kCTExcludedHosts, chrome_schema,
698 SCHEMA_STRICT, SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED, 743 SCHEMA_STRICT, SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED,
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED))); 929 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED)));
885 handlers->AddHandler( 930 handlers->AddHandler(
886 base::MakeUnique<chromeos::KeyPermissionsPolicyHandler>(chrome_schema)); 931 base::MakeUnique<chromeos::KeyPermissionsPolicyHandler>(chrome_schema));
887 handlers->AddHandler(base::WrapUnique(new DefaultGeolocationPolicyHandler())); 932 handlers->AddHandler(base::WrapUnique(new DefaultGeolocationPolicyHandler()));
888 #endif // defined(OS_CHROMEOS) 933 #endif // defined(OS_CHROMEOS)
889 934
890 return handlers; 935 return handlers;
891 } 936 }
892 937
893 } // namespace policy 938 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/net/safe_search_util_unittest.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698