Chromium Code Reviews| 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. | |
| 59 } | |
| 60 // All Cros settings are considered privileged and are either policy | |
| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 pref = pref_service->FindPreference(name); | 467 pref = pref_service->FindPreference(name); |
| 451 if (!pref) | 468 if (!pref) |
| 452 return nullptr; | 469 return nullptr; |
| 453 pref_object.reset(new settings_private::PrefObject()); | 470 pref_object.reset(new settings_private::PrefObject()); |
| 454 pref_object->key = pref->name(); | 471 pref_object->key = pref->name(); |
| 455 pref_object->type = GetType(name, pref->GetType()); | 472 pref_object->type = GetType(name, pref->GetType()); |
| 456 pref_object->value.reset(pref->GetValue()->DeepCopy()); | 473 pref_object->value.reset(pref->GetValue()->DeepCopy()); |
| 457 } | 474 } |
| 458 | 475 |
| 459 #if defined(OS_CHROMEOS) | 476 #if defined(OS_CHROMEOS) |
| 477 // We first check for enterprise-managed, then for primary-user managed. | |
| 478 // Otherwise in multiprofile mode enterprise preference for the secondary | |
| 479 // user will appear primary-user-controlled, which looks strange, because | |
| 480 // primary user preference will be disabled with "enterprise controlled" | |
| 481 // status. | |
| 482 if (IsPrefEnterpriseManaged(name)) { | |
| 483 // Enterprise managed prefs are treated the same as device policy restricted | |
| 484 // prefs in the UI. | |
| 485 pref_object->controlled_by = | |
| 486 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY; | |
| 487 pref_object->enforcement = | |
| 488 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | |
| 489 return pref_object; | |
| 490 } | |
| 491 | |
| 460 if (IsPrefPrimaryUserControlled(name)) { | 492 if (IsPrefPrimaryUserControlled(name)) { |
| 461 pref_object->controlled_by = | 493 pref_object->controlled_by = |
| 462 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; | 494 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; |
| 463 pref_object->enforcement = | 495 pref_object->enforcement = |
| 464 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 496 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
| 465 pref_object->controlled_by_name.reset( | 497 pref_object->controlled_by_name.reset( |
| 466 new std::string(user_manager::UserManager::Get() | 498 new std::string(user_manager::UserManager::Get() |
| 467 ->GetPrimaryUser() | 499 ->GetPrimaryUser() |
| 468 ->GetAccountId() | 500 ->GetAccountId() |
| 469 .GetUserEmail())); | 501 .GetUserEmail())); |
| 470 return pref_object; | 502 return pref_object; |
| 471 } | 503 } |
| 472 | |
| 473 if (IsPrefEnterpriseManaged(name)) { | |
| 474 // Enterprise managed prefs are treated the same as device policy restricted | |
| 475 // prefs in the UI. | |
| 476 pref_object->controlled_by = | |
| 477 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY; | |
| 478 pref_object->enforcement = | |
| 479 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | |
| 480 return pref_object; | |
| 481 } | |
| 482 #endif | 504 #endif |
| 483 | 505 |
| 484 if (pref && pref->IsManaged()) { | 506 if (pref && pref->IsManaged()) { |
| 485 pref_object->controlled_by = | 507 pref_object->controlled_by = |
| 486 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; | 508 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; |
| 487 pref_object->enforcement = | 509 pref_object->enforcement = |
| 488 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 510 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
| 489 return pref_object; | 511 return pref_object; |
| 490 } | 512 } |
| 491 | 513 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 #endif | 679 #endif |
| 658 } | 680 } |
| 659 | 681 |
| 660 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { | 682 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { |
| 661 return GetWhitelistedPrefType(pref_name) == | 683 return GetWhitelistedPrefType(pref_name) == |
| 662 settings_private::PrefType::PREF_TYPE_URL; | 684 settings_private::PrefType::PREF_TYPE_URL; |
| 663 } | 685 } |
| 664 | 686 |
| 665 #if defined(OS_CHROMEOS) | 687 #if defined(OS_CHROMEOS) |
| 666 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { | 688 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { |
| 667 if (IsPrivilegedCrosSetting(pref_name)) { | 689 if (chromeos::system::PerUserTimezoneEnabled()) { |
| 668 policy::BrowserPolicyConnectorChromeOS* connector = | 690 policy::BrowserPolicyConnectorChromeOS* connector = |
| 669 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 691 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 670 if (connector->IsEnterpriseManaged()) | 692 if (connector->IsEnterpriseManaged()) { |
| 671 return true; | 693 if (IsPrivilegedCrosSetting(pref_name)) |
| 694 return true; | |
|
stevenjb
2017/05/25 22:13:06
In the interest of readability, can we do this che
Alexander Alekseev
2017/05/29 21:10:23
Done.
| |
| 695 | |
| 696 if (pref_name == prefs::kUserTimezone || | |
| 697 pref_name == prefs::kResolveTimezoneByGeolocation) { | |
| 698 return chromeos::system::IsTimezonePrefsManaged(pref_name); | |
| 699 } | |
| 700 } | |
| 701 } else { | |
| 702 if (IsPrivilegedCrosSetting(pref_name)) { | |
| 703 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 704 g_browser_process->platform_part() | |
| 705 ->browser_policy_connector_chromeos(); | |
| 706 if (connector->IsEnterpriseManaged()) | |
| 707 return true; | |
| 708 } | |
| 672 } | 709 } |
| 673 return false; | 710 return false; |
| 674 } | 711 } |
| 675 | 712 |
| 676 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { | 713 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { |
| 714 // chromeos::kSystemTimezone is global display-only preference and | |
| 715 // it should appear as disabled, but not owned. | |
| 716 if (pref_name == chromeos::kSystemTimezone) | |
| 717 return false; | |
| 718 | |
| 677 if (IsPrivilegedCrosSetting(pref_name)) { | 719 if (IsPrivilegedCrosSetting(pref_name)) { |
| 678 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) | 720 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) |
| 679 return true; | 721 return true; |
| 680 } | 722 } |
| 681 return false; | 723 return false; |
| 682 } | 724 } |
| 683 | 725 |
| 684 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { | 726 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { |
| 685 if (pref_name == prefs::kWakeOnWifiDarkConnect) { | 727 // chromeos::kSystemTimezone is read-only, but for the non-primary users |
| 728 // it should have "primary user controlled" attribute. | |
| 729 if (pref_name == prefs::kWakeOnWifiDarkConnect || | |
| 730 pref_name == prefs::kResolveTimezoneByGeolocation || | |
| 731 pref_name == prefs::kUserTimezone || | |
| 732 pref_name == chromeos::kSystemTimezone) { | |
| 686 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 733 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 687 const user_manager::User* user = | 734 const user_manager::User* user = |
| 688 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 735 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| 689 if (user && | 736 if (user && user->GetAccountId() != |
| 690 user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId()) | 737 user_manager->GetPrimaryUser()->GetAccountId()) { |
| 691 return true; | 738 return true; |
| 739 } | |
| 692 } | 740 } |
| 693 return false; | 741 return false; |
| 694 } | 742 } |
| 695 #endif | 743 #endif |
| 696 | 744 |
| 697 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { | 745 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { |
| 698 if (pref_name != prefs::kBrowserGuestModeEnabled && | 746 if (pref_name != prefs::kBrowserGuestModeEnabled && |
| 699 pref_name != prefs::kBrowserAddPersonEnabled) { | 747 pref_name != prefs::kBrowserAddPersonEnabled) { |
| 700 return false; | 748 return false; |
| 701 } | 749 } |
| 702 return profile_->IsSupervised(); | 750 return profile_->IsSupervised(); |
| 703 } | 751 } |
| 704 | 752 |
| 705 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { | 753 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { |
| 754 #if defined(OS_CHROMEOS) | |
| 755 if (IsCrosSettingReadOnly(pref_name)) | |
| 756 return false; | |
| 757 #endif | |
| 758 | |
| 706 const PrefService::Preference* profile_pref = | 759 const PrefService::Preference* profile_pref = |
| 707 profile_->GetPrefs()->FindPreference(pref_name); | 760 profile_->GetPrefs()->FindPreference(pref_name); |
| 708 if (profile_pref) | 761 if (profile_pref) |
| 709 return profile_pref->IsUserModifiable(); | 762 return profile_pref->IsUserModifiable(); |
| 710 | 763 |
| 711 const PrefService::Preference* local_state_pref = | 764 const PrefService::Preference* local_state_pref = |
| 712 g_browser_process->local_state()->FindPreference(pref_name); | 765 g_browser_process->local_state()->FindPreference(pref_name); |
| 713 if (local_state_pref) | 766 if (local_state_pref) |
| 714 return local_state_pref->IsUserModifiable(); | 767 return local_state_pref->IsUserModifiable(); |
| 715 | 768 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) | 836 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) |
| 784 ->GetExtensionControllingPref(pref_object.key); | 837 ->GetExtensionControllingPref(pref_object.key); |
| 785 if (extension_id.empty()) | 838 if (extension_id.empty()) |
| 786 return nullptr; | 839 return nullptr; |
| 787 | 840 |
| 788 return ExtensionRegistry::Get(profile_)->GetExtensionById( | 841 return ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 789 extension_id, ExtensionRegistry::ENABLED); | 842 extension_id, ExtensionRegistry::ENABLED); |
| 790 } | 843 } |
| 791 | 844 |
| 792 } // namespace extensions | 845 } // namespace extensions |
| OLD | NEW |