OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/settings_private/prefs_util.h" | 5 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/extensions/chrome_extension_function.h" | 9 #include "chrome/browser/extensions/chrome_extension_function.h" |
10 #include "chrome/browser/extensions/settings_api_helpers.h" | 10 #include "chrome/browser/extensions/settings_api_helpers.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "extensions/browser/management_policy.h" | 32 #include "extensions/browser/management_policy.h" |
33 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
34 | 34 |
35 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
36 #include "ash/public/cpp/ash_pref_names.h" // nogncheck | 36 #include "ash/public/cpp/ash_pref_names.h" // nogncheck |
37 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 37 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
38 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" | 38 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" |
39 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 39 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
40 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 40 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
41 #include "chrome/browser/chromeos/settings/cros_settings.h" | 41 #include "chrome/browser/chromeos/settings/cros_settings.h" |
42 #include "chrome/browser/chromeos/system/timezone_util.h" | |
42 #include "chromeos/settings/cros_settings_names.h" | 43 #include "chromeos/settings/cros_settings_names.h" |
43 #include "ui/chromeos/events/pref_names.h" | 44 #include "ui/chromeos/events/pref_names.h" |
44 #endif | 45 #endif |
45 | 46 |
46 namespace { | 47 namespace { |
47 | 48 |
48 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
49 bool IsPrivilegedCrosSetting(const std::string& pref_name) { | 50 bool IsPrivilegedCrosSetting(const std::string& pref_name) { |
50 if (!chromeos::CrosSettings::IsCrosSettings(pref_name)) | 51 if (!chromeos::CrosSettings::IsCrosSettings(pref_name)) |
51 return false; | 52 return false; |
52 // kSystemTimezone should be changeable by all users. | 53 if (!chromeos::system::PerUserTimezoneEnabled()) { |
53 if (pref_name == chromeos::kSystemTimezone) | 54 // kSystemTimezone should be changeable by all users. |
54 return false; | 55 if (pref_name == chromeos::kSystemTimezone) |
55 // All other Cros settings are considered privileged and are either policy | 56 return false; |
57 // All other Cros settings are considered privileged and are either policy | |
58 // controlled or owner controlled. | |
stevenjb
2017/07/10 19:10:52
I still think this is confusing. This comment is a
Alexander Alekseev
2017/07/14 03:32:47
Done.
| |
59 } | |
60 // All Cros settings are considered privileged and are either policy | |
stevenjb
2017/07/10 19:10:52
You can remove the 'All' to make this a bit more c
Alexander Alekseev
2017/07/14 03:32:47
Done.
| |
56 // controlled or owner controlled. | 61 // controlled or owner controlled. |
57 return true; | 62 return true; |
58 } | 63 } |
64 | |
65 bool IsCrosSettingReadOnly(const std::string& pref_name) { | |
66 if (chromeos::system::PerUserTimezoneEnabled()) { | |
67 // System timezone is never directly changable by user. | |
68 return pref_name == chromeos::kSystemTimezone; | |
69 } | |
70 return false; | |
71 } | |
59 #endif | 72 #endif |
60 | 73 |
61 } // namespace | 74 } // namespace |
62 | 75 |
63 namespace extensions { | 76 namespace extensions { |
64 | 77 |
65 namespace settings_private = api::settings_private; | 78 namespace settings_private = api::settings_private; |
66 | 79 |
67 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} | 80 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} |
68 | 81 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 295 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
283 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] = | 296 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] = |
284 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 297 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
285 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] = | 298 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] = |
286 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 299 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
287 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] = | 300 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] = |
288 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 301 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
289 | 302 |
290 // Timezone settings. | 303 // Timezone settings. |
291 (*s_whitelist)[chromeos::kSystemTimezone] = | 304 (*s_whitelist)[chromeos::kSystemTimezone] = |
305 settings_private::PrefType::PREF_TYPE_STRING; | |
306 (*s_whitelist)[prefs::kUserTimezone] = | |
307 settings_private::PrefType::PREF_TYPE_STRING; | |
308 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] = | |
292 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 309 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
293 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] = | 310 (*s_whitelist)[chromeos::kPerUserTimezoneEnabled] = |
294 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 311 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
295 | 312 |
296 // Ash settings. | 313 // Ash settings. |
297 (*s_whitelist)[::prefs::kEnableStylusTools] = | 314 (*s_whitelist)[::prefs::kEnableStylusTools] = |
298 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 315 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
299 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] = | 316 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] = |
300 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 317 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
301 (*s_whitelist)[::prefs::kNoteTakingAppEnabledOnLockScreen] = | 318 (*s_whitelist)[::prefs::kNoteTakingAppEnabledOnLockScreen] = |
302 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 319 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
303 (*s_whitelist)[ash::prefs::kNightLightEnabled] = | 320 (*s_whitelist)[ash::prefs::kNightLightEnabled] = |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 pref = pref_service->FindPreference(name); | 473 pref = pref_service->FindPreference(name); |
457 if (!pref) | 474 if (!pref) |
458 return nullptr; | 475 return nullptr; |
459 pref_object.reset(new settings_private::PrefObject()); | 476 pref_object.reset(new settings_private::PrefObject()); |
460 pref_object->key = pref->name(); | 477 pref_object->key = pref->name(); |
461 pref_object->type = GetType(name, pref->GetType()); | 478 pref_object->type = GetType(name, pref->GetType()); |
462 pref_object->value.reset(pref->GetValue()->DeepCopy()); | 479 pref_object->value.reset(pref->GetValue()->DeepCopy()); |
463 } | 480 } |
464 | 481 |
465 #if defined(OS_CHROMEOS) | 482 #if defined(OS_CHROMEOS) |
483 // We first check for enterprise-managed, then for primary-user managed. | |
484 // Otherwise in multiprofile mode enterprise preference for the secondary | |
485 // user will appear primary-user-controlled, which looks strange, because | |
486 // primary user preference will be disabled with "enterprise controlled" | |
487 // status. | |
488 if (IsPrefEnterpriseManaged(name)) { | |
489 // Enterprise managed prefs are treated the same as device policy restricted | |
490 // prefs in the UI. | |
491 pref_object->controlled_by = | |
492 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY; | |
493 pref_object->enforcement = | |
494 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | |
495 return pref_object; | |
496 } | |
497 | |
466 if (IsPrefPrimaryUserControlled(name)) { | 498 if (IsPrefPrimaryUserControlled(name)) { |
467 pref_object->controlled_by = | 499 pref_object->controlled_by = |
468 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; | 500 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; |
469 pref_object->enforcement = | 501 pref_object->enforcement = |
470 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 502 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
471 pref_object->controlled_by_name.reset( | 503 pref_object->controlled_by_name.reset( |
472 new std::string(user_manager::UserManager::Get() | 504 new std::string(user_manager::UserManager::Get() |
473 ->GetPrimaryUser() | 505 ->GetPrimaryUser() |
474 ->GetAccountId() | 506 ->GetAccountId() |
475 .GetUserEmail())); | 507 .GetUserEmail())); |
476 return pref_object; | 508 return pref_object; |
477 } | 509 } |
478 | |
479 if (IsPrefEnterpriseManaged(name)) { | |
480 // Enterprise managed prefs are treated the same as device policy restricted | |
481 // prefs in the UI. | |
482 pref_object->controlled_by = | |
483 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY; | |
484 pref_object->enforcement = | |
485 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | |
486 return pref_object; | |
487 } | |
488 #endif | 510 #endif |
489 | 511 |
490 if (pref && pref->IsManaged()) { | 512 if (pref && pref->IsManaged()) { |
491 pref_object->controlled_by = | 513 pref_object->controlled_by = |
492 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; | 514 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; |
493 pref_object->enforcement = | 515 pref_object->enforcement = |
494 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 516 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
495 return pref_object; | 517 return pref_object; |
496 } | 518 } |
497 | 519 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 #endif | 685 #endif |
664 } | 686 } |
665 | 687 |
666 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { | 688 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { |
667 return GetWhitelistedPrefType(pref_name) == | 689 return GetWhitelistedPrefType(pref_name) == |
668 settings_private::PrefType::PREF_TYPE_URL; | 690 settings_private::PrefType::PREF_TYPE_URL; |
669 } | 691 } |
670 | 692 |
671 #if defined(OS_CHROMEOS) | 693 #if defined(OS_CHROMEOS) |
672 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { | 694 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { |
673 if (IsPrivilegedCrosSetting(pref_name)) { | 695 if (chromeos::system::PerUserTimezoneEnabled()) { |
674 policy::BrowserPolicyConnectorChromeOS* connector = | 696 policy::BrowserPolicyConnectorChromeOS* connector = |
675 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 697 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
676 if (connector->IsEnterpriseManaged()) | 698 if (connector->IsEnterpriseManaged()) { |
677 return true; | 699 if (IsPrivilegedCrosSetting(pref_name)) |
700 return true; | |
701 | |
702 if (pref_name == prefs::kUserTimezone || | |
703 pref_name == prefs::kResolveTimezoneByGeolocation) { | |
704 return chromeos::system::IsTimezonePrefsManaged(pref_name); | |
705 } | |
706 } | |
707 } else { | |
708 if (IsPrivilegedCrosSetting(pref_name)) { | |
709 policy::BrowserPolicyConnectorChromeOS* connector = | |
710 g_browser_process->platform_part() | |
711 ->browser_policy_connector_chromeos(); | |
712 if (connector->IsEnterpriseManaged()) | |
713 return true; | |
714 } | |
678 } | 715 } |
stevenjb
2017/07/10 19:10:52
The above is confusing to read and duplicates logi
Alexander Alekseev
2017/07/14 03:32:47
Done.
| |
679 return false; | 716 return false; |
680 } | 717 } |
681 | 718 |
682 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { | 719 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { |
720 // chromeos::kSystemTimezone is global display-only preference and | |
721 // it should appear as disabled, but not owned. | |
722 if (pref_name == chromeos::kSystemTimezone) | |
723 return false; | |
724 | |
683 if (IsPrivilegedCrosSetting(pref_name)) { | 725 if (IsPrivilegedCrosSetting(pref_name)) { |
684 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) | 726 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) |
685 return true; | 727 return true; |
686 } | 728 } |
687 return false; | 729 return false; |
688 } | 730 } |
689 | 731 |
690 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { | 732 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { |
691 if (pref_name == prefs::kWakeOnWifiDarkConnect) { | 733 // chromeos::kSystemTimezone is read-only, but for the non-primary users |
734 // it should have "primary user controlled" attribute. | |
735 if (pref_name == prefs::kWakeOnWifiDarkConnect || | |
736 pref_name == prefs::kResolveTimezoneByGeolocation || | |
737 pref_name == prefs::kUserTimezone || | |
738 pref_name == chromeos::kSystemTimezone) { | |
692 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 739 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
693 const user_manager::User* user = | 740 const user_manager::User* user = |
694 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 741 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
695 if (user && | 742 if (user && user->GetAccountId() != |
696 user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId()) | 743 user_manager->GetPrimaryUser()->GetAccountId()) { |
697 return true; | 744 return true; |
745 } | |
698 } | 746 } |
699 return false; | 747 return false; |
700 } | 748 } |
701 #endif | 749 #endif |
702 | 750 |
703 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { | 751 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { |
704 if (pref_name != prefs::kBrowserGuestModeEnabled && | 752 if (pref_name != prefs::kBrowserGuestModeEnabled && |
705 pref_name != prefs::kBrowserAddPersonEnabled) { | 753 pref_name != prefs::kBrowserAddPersonEnabled) { |
706 return false; | 754 return false; |
707 } | 755 } |
708 return profile_->IsSupervised(); | 756 return profile_->IsSupervised(); |
709 } | 757 } |
710 | 758 |
711 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { | 759 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { |
760 #if defined(OS_CHROMEOS) | |
761 if (IsCrosSettingReadOnly(pref_name)) | |
762 return false; | |
763 #endif | |
764 | |
712 const PrefService::Preference* profile_pref = | 765 const PrefService::Preference* profile_pref = |
713 profile_->GetPrefs()->FindPreference(pref_name); | 766 profile_->GetPrefs()->FindPreference(pref_name); |
714 if (profile_pref) | 767 if (profile_pref) |
715 return profile_pref->IsUserModifiable(); | 768 return profile_pref->IsUserModifiable(); |
716 | 769 |
717 const PrefService::Preference* local_state_pref = | 770 const PrefService::Preference* local_state_pref = |
718 g_browser_process->local_state()->FindPreference(pref_name); | 771 g_browser_process->local_state()->FindPreference(pref_name); |
719 if (local_state_pref) | 772 if (local_state_pref) |
720 return local_state_pref->IsUserModifiable(); | 773 return local_state_pref->IsUserModifiable(); |
721 | 774 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) | 842 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) |
790 ->GetExtensionControllingPref(pref_object.key); | 843 ->GetExtensionControllingPref(pref_object.key); |
791 if (extension_id.empty()) | 844 if (extension_id.empty()) |
792 return nullptr; | 845 return nullptr; |
793 | 846 |
794 return ExtensionRegistry::Get(profile_)->GetExtensionById( | 847 return ExtensionRegistry::Get(profile_)->GetExtensionById( |
795 extension_id, ExtensionRegistry::ENABLED); | 848 extension_id, ExtensionRegistry::ENABLED); |
796 } | 849 } |
797 | 850 |
798 } // namespace extensions | 851 } // namespace extensions |
OLD | NEW |