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 20 matching lines...) Expand all Loading... | |
| 31 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
| 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 "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 36 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 37 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" | 37 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" |
| 38 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 38 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 39 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 39 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 40 #include "chrome/browser/chromeos/settings/cros_settings.h" | 40 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 41 #include "chrome/browser/chromeos/system/timezone_util.h" | |
| 41 #include "chromeos/settings/cros_settings_names.h" | 42 #include "chromeos/settings/cros_settings_names.h" |
| 42 #include "ui/chromeos/events/pref_names.h" | 43 #include "ui/chromeos/events/pref_names.h" |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 48 bool IsPrivilegedCrosSetting(const std::string& pref_name) { | 49 bool IsPrivilegedCrosSetting(const std::string& pref_name) { |
| 49 if (!chromeos::CrosSettings::IsCrosSettings(pref_name)) | 50 if (!chromeos::CrosSettings::IsCrosSettings(pref_name)) |
| 50 return false; | 51 return false; |
| 51 // kSystemTimezone should be changeable by all users. | 52 // All Cros settings are considered privileged and are either policy |
| 52 if (pref_name == chromeos::kSystemTimezone) | |
| 53 return false; | |
| 54 // All other Cros settings are considered privileged and are either policy | |
| 55 // controlled or owner controlled. | 53 // controlled or owner controlled. |
| 56 return true; | 54 return true; |
| 57 } | 55 } |
| 56 | |
| 57 bool IsCrosSettingReadOnly(const std::string& pref_name) { | |
| 58 // System timezone is never directly changable by user. | |
| 59 return pref_name == chromeos::kSystemTimezone; | |
| 60 } | |
| 58 #endif | 61 #endif |
| 59 | 62 |
| 60 } // namespace | 63 } // namespace |
| 61 | 64 |
| 62 namespace extensions { | 65 namespace extensions { |
| 63 | 66 |
| 64 namespace settings_private = api::settings_private; | 67 namespace settings_private = api::settings_private; |
| 65 | 68 |
| 66 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} | 69 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} |
| 67 | 70 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 280 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 278 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] = | 281 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] = |
| 279 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 282 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 280 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] = | 283 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] = |
| 281 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 284 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 282 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] = | 285 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] = |
| 283 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 286 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 284 | 287 |
| 285 // Timezone settings. | 288 // Timezone settings. |
| 286 (*s_whitelist)[chromeos::kSystemTimezone] = | 289 (*s_whitelist)[chromeos::kSystemTimezone] = |
| 287 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 290 settings_private::PrefType::PREF_TYPE_STRING; |
| 291 (*s_whitelist)[prefs::kUserTimezone] = | |
| 292 settings_private::PrefType::PREF_TYPE_STRING; | |
| 288 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] = | 293 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] = |
| 289 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 294 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 290 | 295 |
| 291 // Ash settings. | 296 // Ash settings. |
| 292 (*s_whitelist)[::prefs::kEnableStylusTools] = | 297 (*s_whitelist)[::prefs::kEnableStylusTools] = |
| 293 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 298 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 294 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] = | 299 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] = |
| 295 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 300 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 296 | 301 |
| 297 // Input method settings. | 302 // Input method settings. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 pref = pref_service->FindPreference(name); | 444 pref = pref_service->FindPreference(name); |
| 440 if (!pref) | 445 if (!pref) |
| 441 return nullptr; | 446 return nullptr; |
| 442 pref_object.reset(new settings_private::PrefObject()); | 447 pref_object.reset(new settings_private::PrefObject()); |
| 443 pref_object->key = pref->name(); | 448 pref_object->key = pref->name(); |
| 444 pref_object->type = GetType(name, pref->GetType()); | 449 pref_object->type = GetType(name, pref->GetType()); |
| 445 pref_object->value.reset(pref->GetValue()->DeepCopy()); | 450 pref_object->value.reset(pref->GetValue()->DeepCopy()); |
| 446 } | 451 } |
| 447 | 452 |
| 448 #if defined(OS_CHROMEOS) | 453 #if defined(OS_CHROMEOS) |
| 454 // We first check for enterprise-managed, then for primary-user managed. | |
| 455 // Otherwise in multiprofile mode enterprise preference for the secondary | |
| 456 // user will appear primary-user-controlled, which looks strange, because | |
| 457 // primary user preference will be disabled with "enterprise controlled" | |
| 458 // status. | |
| 459 if (IsPrefEnterpriseManaged(name)) { | |
| 460 // Enterprise managed prefs are treated the same as device policy restricted | |
| 461 // prefs in the UI. | |
| 462 pref_object->controlled_by = | |
| 463 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY; | |
| 464 pref_object->enforcement = | |
| 465 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | |
| 466 return pref_object; | |
| 467 } | |
| 468 | |
| 449 if (IsPrefPrimaryUserControlled(name)) { | 469 if (IsPrefPrimaryUserControlled(name)) { |
| 450 pref_object->controlled_by = | 470 pref_object->controlled_by = |
| 451 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; | 471 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; |
| 452 pref_object->enforcement = | 472 pref_object->enforcement = |
| 453 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 473 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
| 454 pref_object->controlled_by_name.reset( | 474 pref_object->controlled_by_name.reset( |
| 455 new std::string(user_manager::UserManager::Get() | 475 new std::string(user_manager::UserManager::Get() |
| 456 ->GetPrimaryUser() | 476 ->GetPrimaryUser() |
| 457 ->GetAccountId() | 477 ->GetAccountId() |
| 458 .GetUserEmail())); | 478 .GetUserEmail())); |
| 459 return pref_object; | 479 return pref_object; |
| 460 } | 480 } |
| 461 | |
| 462 if (IsPrefEnterpriseManaged(name)) { | |
| 463 // Enterprise managed prefs are treated the same as device policy restricted | |
| 464 // prefs in the UI. | |
| 465 pref_object->controlled_by = | |
| 466 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY; | |
| 467 pref_object->enforcement = | |
| 468 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | |
| 469 return pref_object; | |
| 470 } | |
| 471 #endif | 481 #endif |
| 472 | 482 |
| 473 if (pref && pref->IsManaged()) { | 483 if (pref && pref->IsManaged()) { |
| 474 pref_object->controlled_by = | 484 pref_object->controlled_by = |
| 475 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; | 485 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; |
| 476 pref_object->enforcement = | 486 pref_object->enforcement = |
| 477 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 487 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
| 478 return pref_object; | 488 return pref_object; |
| 479 } | 489 } |
| 480 | 490 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 523 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
| 514 pref_object->extension_id.reset(new std::string(extension->id())); | 524 pref_object->extension_id.reset(new std::string(extension->id())); |
| 515 pref_object->controlled_by_name.reset(new std::string(extension->name())); | 525 pref_object->controlled_by_name.reset(new std::string(extension->name())); |
| 516 bool can_be_disabled = !ExtensionSystem::Get(profile_)->management_policy() | 526 bool can_be_disabled = !ExtensionSystem::Get(profile_)->management_policy() |
| 517 ->MustRemainEnabled(extension, nullptr); | 527 ->MustRemainEnabled(extension, nullptr); |
| 518 pref_object->extension_can_be_disabled.reset(new bool(can_be_disabled)); | 528 pref_object->extension_can_be_disabled.reset(new bool(can_be_disabled)); |
| 519 return pref_object; | 529 return pref_object; |
| 520 } | 530 } |
| 521 | 531 |
| 522 // TODO(dbeam): surface !IsUserModifiable or IsPrefSupervisorControlled? | 532 // TODO(dbeam): surface !IsUserModifiable or IsPrefSupervisorControlled? |
| 523 | |
| 524 return pref_object; | 533 return pref_object; |
| 525 } | 534 } |
| 526 | 535 |
| 527 PrefsUtil::SetPrefResult PrefsUtil::SetPref(const std::string& pref_name, | 536 PrefsUtil::SetPrefResult PrefsUtil::SetPref(const std::string& pref_name, |
| 528 const base::Value* value) { | 537 const base::Value* value) { |
| 529 if (GetWhitelistedPrefType(pref_name) == | 538 if (GetWhitelistedPrefType(pref_name) == |
| 530 settings_private::PrefType::PREF_TYPE_NONE) { | 539 settings_private::PrefType::PREF_TYPE_NONE) { |
| 531 return PREF_NOT_FOUND; | 540 return PREF_NOT_FOUND; |
| 532 } | 541 } |
| 533 | 542 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 return false; | 653 return false; |
| 645 #endif | 654 #endif |
| 646 } | 655 } |
| 647 | 656 |
| 648 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { | 657 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { |
| 649 return GetWhitelistedPrefType(pref_name) == | 658 return GetWhitelistedPrefType(pref_name) == |
| 650 settings_private::PrefType::PREF_TYPE_URL; | 659 settings_private::PrefType::PREF_TYPE_URL; |
| 651 } | 660 } |
| 652 | 661 |
| 653 #if defined(OS_CHROMEOS) | 662 #if defined(OS_CHROMEOS) |
| 663 | |
| 654 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { | 664 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { |
| 655 if (IsPrivilegedCrosSetting(pref_name)) { | 665 policy::BrowserPolicyConnectorChromeOS* connector = |
| 656 policy::BrowserPolicyConnectorChromeOS* connector = | 666 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 657 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 667 if (connector->IsEnterpriseManaged()) { |
| 658 if (connector->IsEnterpriseManaged()) | 668 if (IsPrivilegedCrosSetting(pref_name)) |
| 659 return true; | 669 return true; |
| 670 | |
| 671 if (pref_name == prefs::kUserTimezone || | |
| 672 pref_name == prefs::kResolveTimezoneByGeolocation) { | |
| 673 return chromeos::system::IsTimezonePrefsManaged(pref_name); | |
| 674 } | |
| 660 } | 675 } |
| 661 return false; | 676 return false; |
| 662 } | 677 } |
| 663 | 678 |
| 664 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { | 679 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { |
| 665 if (IsPrivilegedCrosSetting(pref_name)) { | 680 if (IsPrivilegedCrosSetting(pref_name)) { |
| 666 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) | 681 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) |
| 667 return true; | 682 return true; |
| 668 } | 683 } |
| 669 return false; | 684 return false; |
| 670 } | 685 } |
| 671 | 686 |
| 672 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { | 687 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { |
| 673 if (pref_name == prefs::kWakeOnWifiDarkConnect) { | 688 if (pref_name == prefs::kWakeOnWifiDarkConnect || |
| 689 pref_name == prefs::kResolveTimezoneByGeolocation || | |
| 690 pref_name == prefs::kUserTimezone) { | |
| 674 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 691 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 675 const user_manager::User* user = | 692 const user_manager::User* user = |
| 676 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 693 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| 677 if (user && | 694 if (user && |
| 678 user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId()) | 695 user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId()) |
| 679 return true; | 696 return true; |
|
stevenjb
2017/05/16 17:16:57
{}
Alexander Alekseev
2017/05/19 11:25:29
Done.
| |
| 680 } | 697 } |
| 681 return false; | 698 return false; |
| 682 } | 699 } |
| 683 #endif | 700 #endif |
| 684 | 701 |
| 685 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { | 702 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { |
| 686 if (pref_name != prefs::kBrowserGuestModeEnabled && | 703 if (pref_name != prefs::kBrowserGuestModeEnabled && |
| 687 pref_name != prefs::kBrowserAddPersonEnabled) { | 704 pref_name != prefs::kBrowserAddPersonEnabled) { |
| 688 return false; | 705 return false; |
| 689 } | 706 } |
| 690 return profile_->IsSupervised(); | 707 return profile_->IsSupervised(); |
| 691 } | 708 } |
| 692 | 709 |
| 693 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { | 710 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { |
| 711 #if defined(OS_CHROMEOS) | |
| 712 if (IsCrosSettingReadOnly(pref_name)) | |
| 713 return false; | |
| 714 #endif | |
| 715 | |
| 694 const PrefService::Preference* profile_pref = | 716 const PrefService::Preference* profile_pref = |
| 695 profile_->GetPrefs()->FindPreference(pref_name); | 717 profile_->GetPrefs()->FindPreference(pref_name); |
| 696 if (profile_pref) | 718 if (profile_pref) |
| 697 return profile_pref->IsUserModifiable(); | 719 return profile_pref->IsUserModifiable(); |
| 698 | 720 |
| 699 const PrefService::Preference* local_state_pref = | 721 const PrefService::Preference* local_state_pref = |
| 700 g_browser_process->local_state()->FindPreference(pref_name); | 722 g_browser_process->local_state()->FindPreference(pref_name); |
| 701 if (local_state_pref) | 723 if (local_state_pref) |
| 702 return local_state_pref->IsUserModifiable(); | 724 return local_state_pref->IsUserModifiable(); |
| 703 | 725 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) | 793 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) |
| 772 ->GetExtensionControllingPref(pref_object.key); | 794 ->GetExtensionControllingPref(pref_object.key); |
| 773 if (extension_id.empty()) | 795 if (extension_id.empty()) |
| 774 return nullptr; | 796 return nullptr; |
| 775 | 797 |
| 776 return ExtensionRegistry::Get(profile_)->GetExtensionById( | 798 return ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 777 extension_id, ExtensionRegistry::ENABLED); | 799 extension_id, ExtensionRegistry::ENABLED); |
| 778 } | 800 } |
| 779 | 801 |
| 780 } // namespace extensions | 802 } // namespace extensions |
| OLD | NEW |