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 } | |
58 // Cros settings are considered privileged and are either policy | |
56 // controlled or owner controlled. | 59 // controlled or owner controlled. |
57 return true; | 60 return true; |
58 } | 61 } |
62 | |
63 bool IsCrosSettingReadOnly(const std::string& pref_name) { | |
64 if (chromeos::system::PerUserTimezoneEnabled()) { | |
65 // System timezone is never directly changable by user. | |
66 return pref_name == chromeos::kSystemTimezone; | |
67 } | |
68 return false; | |
69 } | |
59 #endif | 70 #endif |
60 | 71 |
61 } // namespace | 72 } // namespace |
62 | 73 |
63 namespace extensions { | 74 namespace extensions { |
64 | 75 |
65 namespace settings_private = api::settings_private; | 76 namespace settings_private = api::settings_private; |
66 | 77 |
67 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} | 78 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} |
68 | 79 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 293 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
283 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] = | 294 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] = |
284 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 295 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
285 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] = | 296 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] = |
286 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 297 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
287 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] = | 298 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] = |
288 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 299 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
289 | 300 |
290 // Timezone settings. | 301 // Timezone settings. |
291 (*s_whitelist)[chromeos::kSystemTimezone] = | 302 (*s_whitelist)[chromeos::kSystemTimezone] = |
303 settings_private::PrefType::PREF_TYPE_STRING; | |
304 (*s_whitelist)[prefs::kUserTimezone] = | |
305 settings_private::PrefType::PREF_TYPE_STRING; | |
306 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] = | |
292 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 307 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
293 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] = | 308 (*s_whitelist)[chromeos::kPerUserTimezoneEnabled] = |
294 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 309 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
295 | 310 |
296 // Ash settings. | 311 // Ash settings. |
297 (*s_whitelist)[::prefs::kEnableStylusTools] = | 312 (*s_whitelist)[::prefs::kEnableStylusTools] = |
298 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 313 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
299 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] = | 314 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] = |
300 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 315 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
301 (*s_whitelist)[::prefs::kNoteTakingAppEnabledOnLockScreen] = | 316 (*s_whitelist)[::prefs::kNoteTakingAppEnabledOnLockScreen] = |
302 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 317 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
303 (*s_whitelist)[ash::prefs::kNightLightEnabled] = | 318 (*s_whitelist)[ash::prefs::kNightLightEnabled] = |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 pref = pref_service->FindPreference(name); | 471 pref = pref_service->FindPreference(name); |
457 if (!pref) | 472 if (!pref) |
458 return nullptr; | 473 return nullptr; |
459 pref_object.reset(new settings_private::PrefObject()); | 474 pref_object.reset(new settings_private::PrefObject()); |
460 pref_object->key = pref->name(); | 475 pref_object->key = pref->name(); |
461 pref_object->type = GetType(name, pref->GetType()); | 476 pref_object->type = GetType(name, pref->GetType()); |
462 pref_object->value.reset(pref->GetValue()->DeepCopy()); | 477 pref_object->value.reset(pref->GetValue()->DeepCopy()); |
463 } | 478 } |
464 | 479 |
465 #if defined(OS_CHROMEOS) | 480 #if defined(OS_CHROMEOS) |
481 // We first check for enterprise-managed, then for primary-user managed. | |
482 // Otherwise in multiprofile mode enterprise preference for the secondary | |
483 // user will appear primary-user-controlled, which looks strange, because | |
484 // primary user preference will be disabled with "enterprise controlled" | |
485 // status. | |
486 if (IsPrefEnterpriseManaged(name)) { | |
487 // Enterprise managed prefs are treated the same as device policy restricted | |
488 // prefs in the UI. | |
489 pref_object->controlled_by = | |
490 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY; | |
491 pref_object->enforcement = | |
492 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | |
493 return pref_object; | |
494 } | |
495 | |
466 if (IsPrefPrimaryUserControlled(name)) { | 496 if (IsPrefPrimaryUserControlled(name)) { |
467 pref_object->controlled_by = | 497 pref_object->controlled_by = |
468 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; | 498 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; |
469 pref_object->enforcement = | 499 pref_object->enforcement = |
470 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 500 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
471 pref_object->controlled_by_name.reset( | 501 pref_object->controlled_by_name.reset( |
472 new std::string(user_manager::UserManager::Get() | 502 new std::string(user_manager::UserManager::Get() |
473 ->GetPrimaryUser() | 503 ->GetPrimaryUser() |
474 ->GetAccountId() | 504 ->GetAccountId() |
475 .GetUserEmail())); | 505 .GetUserEmail())); |
476 return pref_object; | 506 return pref_object; |
477 } | 507 } |
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 | 508 #endif |
489 | 509 |
490 if (pref && pref->IsManaged()) { | 510 if (pref && pref->IsManaged()) { |
491 pref_object->controlled_by = | 511 pref_object->controlled_by = |
492 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; | 512 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; |
493 pref_object->enforcement = | 513 pref_object->enforcement = |
494 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 514 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
495 return pref_object; | 515 return pref_object; |
496 } | 516 } |
497 | 517 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 #endif | 683 #endif |
664 } | 684 } |
665 | 685 |
666 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { | 686 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { |
667 return GetWhitelistedPrefType(pref_name) == | 687 return GetWhitelistedPrefType(pref_name) == |
668 settings_private::PrefType::PREF_TYPE_URL; | 688 settings_private::PrefType::PREF_TYPE_URL; |
669 } | 689 } |
670 | 690 |
671 #if defined(OS_CHROMEOS) | 691 #if defined(OS_CHROMEOS) |
672 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { | 692 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { |
673 if (IsPrivilegedCrosSetting(pref_name)) { | 693 policy::BrowserPolicyConnectorChromeOS* connector = |
674 policy::BrowserPolicyConnectorChromeOS* connector = | 694 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
675 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 695 if (connector->IsEnterpriseManaged()) { |
stevenjb
2017/07/17 16:57:11
Much more clear now, thanks!
nit: Now it looks li
Alexander Alekseev
2017/07/20 00:30:53
Done.
| |
676 if (connector->IsEnterpriseManaged()) | 696 if (IsPrivilegedCrosSetting(pref_name)) |
677 return true; | 697 return true; |
698 if (chromeos::system::PerUserTimezoneEnabled() && | |
699 (pref_name == prefs::kUserTimezone || | |
700 pref_name == prefs::kResolveTimezoneByGeolocation)) { | |
701 return chromeos::system::IsTimezonePrefsManaged(pref_name); | |
702 } | |
678 } | 703 } |
679 return false; | 704 return false; |
680 } | 705 } |
681 | 706 |
682 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { | 707 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { |
708 // chromeos::kSystemTimezone is global display-only preference and | |
709 // it should appear as disabled, but not owned. | |
710 if (pref_name == chromeos::kSystemTimezone) | |
711 return false; | |
712 | |
683 if (IsPrivilegedCrosSetting(pref_name)) { | 713 if (IsPrivilegedCrosSetting(pref_name)) { |
684 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) | 714 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) |
685 return true; | 715 return true; |
686 } | 716 } |
687 return false; | 717 return false; |
688 } | 718 } |
689 | 719 |
690 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { | 720 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { |
691 if (pref_name == prefs::kWakeOnWifiDarkConnect) { | 721 // chromeos::kSystemTimezone is read-only, but for the non-primary users |
722 // it should have "primary user controlled" attribute. | |
723 if (pref_name == prefs::kWakeOnWifiDarkConnect || | |
724 pref_name == prefs::kResolveTimezoneByGeolocation || | |
725 pref_name == prefs::kUserTimezone || | |
726 pref_name == chromeos::kSystemTimezone) { | |
692 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 727 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
693 const user_manager::User* user = | 728 const user_manager::User* user = |
694 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 729 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
695 if (user && | 730 if (user && user->GetAccountId() != |
696 user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId()) | 731 user_manager->GetPrimaryUser()->GetAccountId()) { |
697 return true; | 732 return true; |
733 } | |
698 } | 734 } |
699 return false; | 735 return false; |
700 } | 736 } |
701 #endif | 737 #endif |
702 | 738 |
703 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { | 739 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { |
704 if (pref_name != prefs::kBrowserGuestModeEnabled && | 740 if (pref_name != prefs::kBrowserGuestModeEnabled && |
705 pref_name != prefs::kBrowserAddPersonEnabled) { | 741 pref_name != prefs::kBrowserAddPersonEnabled) { |
706 return false; | 742 return false; |
707 } | 743 } |
708 return profile_->IsSupervised(); | 744 return profile_->IsSupervised(); |
709 } | 745 } |
710 | 746 |
711 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { | 747 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { |
748 #if defined(OS_CHROMEOS) | |
749 if (IsCrosSettingReadOnly(pref_name)) | |
750 return false; | |
751 #endif | |
752 | |
712 const PrefService::Preference* profile_pref = | 753 const PrefService::Preference* profile_pref = |
713 profile_->GetPrefs()->FindPreference(pref_name); | 754 profile_->GetPrefs()->FindPreference(pref_name); |
714 if (profile_pref) | 755 if (profile_pref) |
715 return profile_pref->IsUserModifiable(); | 756 return profile_pref->IsUserModifiable(); |
716 | 757 |
717 const PrefService::Preference* local_state_pref = | 758 const PrefService::Preference* local_state_pref = |
718 g_browser_process->local_state()->FindPreference(pref_name); | 759 g_browser_process->local_state()->FindPreference(pref_name); |
719 if (local_state_pref) | 760 if (local_state_pref) |
720 return local_state_pref->IsUserModifiable(); | 761 return local_state_pref->IsUserModifiable(); |
721 | 762 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) | 830 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) |
790 ->GetExtensionControllingPref(pref_object.key); | 831 ->GetExtensionControllingPref(pref_object.key); |
791 if (extension_id.empty()) | 832 if (extension_id.empty()) |
792 return nullptr; | 833 return nullptr; |
793 | 834 |
794 return ExtensionRegistry::Get(profile_)->GetExtensionById( | 835 return ExtensionRegistry::Get(profile_)->GetExtensionById( |
795 extension_id, ExtensionRegistry::ENABLED); | 836 extension_id, ExtensionRegistry::ENABLED); |
796 } | 837 } |
797 | 838 |
798 } // namespace extensions | 839 } // namespace extensions |
OLD | NEW |