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

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

Issue 2239753002: Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyMode policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Inc'ed id of new policy to 346 Created 4 years, 3 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
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))
Marc Treib 2016/09/05 09:58:10 Braces please if the body doesn't fit on one line.
ljusten (tachyonic) 2016/09/05 15:24:32 Done.
635 prefs->SetValue(prefs::kForceYouTubeRestrict,
636 base::MakeUnique<base::FundamentalValue>(
637 enabled ? safe_search_util::YOUTUBE_MODERATE
638 : safe_search_util::YOUTUBE_OFF));
626 } 639 }
627 } 640 }
628 641
629 private: 642 private:
630 DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler); 643 DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler);
631 }; 644 };
632 645
646 class ForceYouTubeSafetyModePolicyHandler : public TypeCheckingPolicyHandler {
647 public:
648 ForceYouTubeSafetyModePolicyHandler()
649 : TypeCheckingPolicyHandler(key::kForceYouTubeSafetyMode,
650 base::Value::TYPE_BOOLEAN) {}
651 ~ForceYouTubeSafetyModePolicyHandler() override {}
652
653 // ConfigurationPolicyHandler implementation:
654 void ApplyPolicySettings(const PolicyMap& policies,
655 PrefValueMap* prefs) override {
656 // If only the deprecated ForceYouTubeSafetyMode policy is set,
657 // but not ForceYouTubeRestrict, set ForceYouTubeRestrict to Moderate.
658 if (policies.GetValue(key::kForceYouTubeRestrict))
659 return;
660
661 const base::Value* value = policies.GetValue(policy_name());
662 bool enabled;
663 if (value && value->GetAsBoolean(&enabled))
Marc Treib 2016/09/05 09:58:10 Also here, braces please.
ljusten (tachyonic) 2016/09/05 15:24:32 Done.
664 prefs->SetValue(prefs::kForceYouTubeRestrict,
665 base::MakeUnique<base::FundamentalValue>(
666 enabled ? safe_search_util::YOUTUBE_MODERATE
667 : safe_search_util::YOUTUBE_OFF));
668 }
669
670 private:
671 DISALLOW_COPY_AND_ASSIGN(ForceYouTubeSafetyModePolicyHandler);
672 };
673
633 #if defined(ENABLE_EXTENSIONS) 674 #if defined(ENABLE_EXTENSIONS)
634 void GetExtensionAllowedTypesMap( 675 void GetExtensionAllowedTypesMap(
635 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) { 676 ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) {
636 // Mapping from extension type names to Manifest::Type. 677 // Mapping from extension type names to Manifest::Type.
637 for (size_t index = 0; 678 for (size_t index = 0;
638 index < extensions::schema_constants::kAllowedTypesMapSize; 679 index < extensions::schema_constants::kAllowedTypesMapSize;
639 ++index) { 680 ++index) {
640 const extensions::schema_constants::AllowedTypesMapEntry& entry = 681 const extensions::schema_constants::AllowedTypesMapEntry& entry =
641 extensions::schema_constants::kAllowedTypesMap[index]; 682 extensions::schema_constants::kAllowedTypesMap[index];
642 result->push_back(new StringMappingListPolicyHandler::MappingEntry( 683 result->push_back(new StringMappingListPolicyHandler::MappingEntry(
(...skipping 30 matching lines...) Expand all
673 base::Bind(&GetChromePolicyDetails))); 714 base::Bind(&GetChromePolicyDetails)));
674 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) { 715 for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) {
675 handlers->AddHandler(base::WrapUnique(new SimplePolicyHandler( 716 handlers->AddHandler(base::WrapUnique(new SimplePolicyHandler(
676 kSimplePolicyMap[i].policy_name, kSimplePolicyMap[i].preference_path, 717 kSimplePolicyMap[i].policy_name, kSimplePolicyMap[i].preference_path,
677 kSimplePolicyMap[i].value_type))); 718 kSimplePolicyMap[i].value_type)));
678 } 719 }
679 720
680 handlers->AddHandler(base::WrapUnique(new AutofillPolicyHandler())); 721 handlers->AddHandler(base::WrapUnique(new AutofillPolicyHandler()));
681 handlers->AddHandler(base::WrapUnique(new DefaultSearchPolicyHandler())); 722 handlers->AddHandler(base::WrapUnique(new DefaultSearchPolicyHandler()));
682 handlers->AddHandler(base::WrapUnique(new ForceSafeSearchPolicyHandler())); 723 handlers->AddHandler(base::WrapUnique(new ForceSafeSearchPolicyHandler()));
724 handlers->AddHandler(
725 base::WrapUnique(new ForceYouTubeSafetyModePolicyHandler()));
683 handlers->AddHandler(base::WrapUnique(new IncognitoModePolicyHandler())); 726 handlers->AddHandler(base::WrapUnique(new IncognitoModePolicyHandler()));
684 handlers->AddHandler( 727 handlers->AddHandler(
685 base::WrapUnique(new ManagedBookmarksPolicyHandler(chrome_schema))); 728 base::WrapUnique(new ManagedBookmarksPolicyHandler(chrome_schema)));
686 handlers->AddHandler(base::WrapUnique(new ProxyPolicyHandler())); 729 handlers->AddHandler(base::WrapUnique(new ProxyPolicyHandler()));
687 handlers->AddHandler(base::WrapUnique(new URLBlacklistPolicyHandler())); 730 handlers->AddHandler(base::WrapUnique(new URLBlacklistPolicyHandler()));
688 731
689 handlers->AddHandler(base::WrapUnique(new SimpleSchemaValidatingPolicyHandler( 732 handlers->AddHandler(base::WrapUnique(new SimpleSchemaValidatingPolicyHandler(
690 key::kCertificateTransparencyEnforcementDisabledForUrls, 733 key::kCertificateTransparencyEnforcementDisabledForUrls,
691 certificate_transparency::prefs::kCTExcludedHosts, chrome_schema, 734 certificate_transparency::prefs::kCTExcludedHosts, chrome_schema,
692 SCHEMA_STRICT, SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED, 735 SCHEMA_STRICT, SimpleSchemaValidatingPolicyHandler::RECOMMENDED_ALLOWED,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED))); 926 SimpleSchemaValidatingPolicyHandler::MANDATORY_PROHIBITED)));
884 handlers->AddHandler(base::WrapUnique( 927 handlers->AddHandler(base::WrapUnique(
885 new chromeos::KeyPermissionsPolicyHandler(chrome_schema))); 928 new chromeos::KeyPermissionsPolicyHandler(chrome_schema)));
886 handlers->AddHandler(base::WrapUnique(new DefaultGeolocationPolicyHandler())); 929 handlers->AddHandler(base::WrapUnique(new DefaultGeolocationPolicyHandler()));
887 #endif // defined(OS_CHROMEOS) 930 #endif // defined(OS_CHROMEOS)
888 931
889 return handlers; 932 return handlers;
890 } 933 }
891 934
892 } // namespace policy 935 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698