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) |
| 49 const size_t primary_user_prefs_len = 4; | |
| 50 const char* const primary_user_prefs[primary_user_prefs_len] = { | |
| 51 prefs::kResolveTimezoneByGeolocation, | |
| 52 prefs::kUserTimezone, | |
| 53 prefs::kWakeOnWifiDarkConnect, | |
| 54 prefs::kWakeOnWifiDarkConnect | |
| 55 }; | |
|
stevenjb
2017/05/15 17:08:02
const char* const primary_user_prefs[] = {
...
};
Alexander Alekseev
2017/05/16 01:11:56
Done.
| |
| 56 | |
| 48 bool IsPrivilegedCrosSetting(const std::string& pref_name) { | 57 bool IsPrivilegedCrosSetting(const std::string& pref_name) { |
| 49 if (!chromeos::CrosSettings::IsCrosSettings(pref_name)) | 58 if (!chromeos::CrosSettings::IsCrosSettings(pref_name)) |
| 50 return false; | 59 return false; |
| 51 // kSystemTimezone should be changeable by all users. | 60 // 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. | 61 // controlled or owner controlled. |
| 56 return true; | 62 return true; |
| 57 } | 63 } |
| 64 | |
| 65 bool IsCrosSettingReadOnly(const std::string& pref_name) { | |
| 66 // System timezone is never directly changable by user. | |
| 67 return pref_name == chromeos::kSystemTimezone; | |
| 68 } | |
| 58 #endif | 69 #endif |
| 59 | 70 |
| 60 } // namespace | 71 } // namespace |
| 61 | 72 |
| 62 namespace extensions { | 73 namespace extensions { |
| 63 | 74 |
| 64 namespace settings_private = api::settings_private; | 75 namespace settings_private = api::settings_private; |
| 65 | 76 |
| 66 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} | 77 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} |
| 67 | 78 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 288 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 278 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] = | 289 (*s_whitelist)[proxy_config::prefs::kUseSharedProxies] = |
| 279 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 290 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 280 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] = | 291 (*s_whitelist)[::prefs::kWakeOnWifiDarkConnect] = |
| 281 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 292 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 282 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] = | 293 (*s_whitelist)[::chromeos::kSignedDataRoamingEnabled] = |
| 283 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 294 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 284 | 295 |
| 285 // Timezone settings. | 296 // Timezone settings. |
| 286 (*s_whitelist)[chromeos::kSystemTimezone] = | 297 (*s_whitelist)[chromeos::kSystemTimezone] = |
| 287 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 298 settings_private::PrefType::PREF_TYPE_STRING; |
| 299 (*s_whitelist)[prefs::kUserTimezone] = | |
| 300 settings_private::PrefType::PREF_TYPE_STRING; | |
| 288 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] = | 301 (*s_whitelist)[::prefs::kResolveTimezoneByGeolocation] = |
| 289 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 302 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 290 | 303 |
| 291 // Ash settings. | 304 // Ash settings. |
| 292 (*s_whitelist)[::prefs::kEnableStylusTools] = | 305 (*s_whitelist)[::prefs::kEnableStylusTools] = |
| 293 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 306 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 294 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] = | 307 (*s_whitelist)[::prefs::kLaunchPaletteOnEjectEvent] = |
| 295 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 308 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 296 | 309 |
| 297 // Input method settings. | 310 // Input method settings. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 pref = pref_service->FindPreference(name); | 452 pref = pref_service->FindPreference(name); |
| 440 if (!pref) | 453 if (!pref) |
| 441 return nullptr; | 454 return nullptr; |
| 442 pref_object.reset(new settings_private::PrefObject()); | 455 pref_object.reset(new settings_private::PrefObject()); |
| 443 pref_object->key = pref->name(); | 456 pref_object->key = pref->name(); |
| 444 pref_object->type = GetType(name, pref->GetType()); | 457 pref_object->type = GetType(name, pref->GetType()); |
| 445 pref_object->value.reset(pref->GetValue()->DeepCopy()); | 458 pref_object->value.reset(pref->GetValue()->DeepCopy()); |
| 446 } | 459 } |
| 447 | 460 |
| 448 #if defined(OS_CHROMEOS) | 461 #if defined(OS_CHROMEOS) |
| 462 // We first check for enterprise-managed, then for primary-user managed. | |
| 463 // Otherwise in multiprofile mode enterprise preference for the secondary | |
| 464 // user will appear primary-user-controlled, which looks strange, because | |
| 465 // primary user preference will be disabled with "enterprise controlled" | |
| 466 // status. | |
| 467 if (IsPrefEnterpriseManaged(name)) { | |
| 468 // Enterprise managed prefs are treated the same as device policy restricted | |
| 469 // prefs in the UI. | |
| 470 pref_object->controlled_by = | |
| 471 settings_private::ControlledBy::CONTROLLED_BY_DEVICE_POLICY; | |
| 472 pref_object->enforcement = | |
| 473 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | |
| 474 return pref_object; | |
| 475 } | |
| 476 | |
| 449 if (IsPrefPrimaryUserControlled(name)) { | 477 if (IsPrefPrimaryUserControlled(name)) { |
| 450 pref_object->controlled_by = | 478 pref_object->controlled_by = |
| 451 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; | 479 settings_private::ControlledBy::CONTROLLED_BY_PRIMARY_USER; |
| 452 pref_object->enforcement = | 480 pref_object->enforcement = |
| 453 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 481 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
| 454 pref_object->controlled_by_name.reset( | 482 pref_object->controlled_by_name.reset( |
| 455 new std::string(user_manager::UserManager::Get() | 483 new std::string(user_manager::UserManager::Get() |
| 456 ->GetPrimaryUser() | 484 ->GetPrimaryUser() |
| 457 ->GetAccountId() | 485 ->GetAccountId() |
| 458 .GetUserEmail())); | 486 .GetUserEmail())); |
| 459 return pref_object; | 487 return pref_object; |
| 460 } | 488 } |
| 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 | 489 #endif |
| 472 | 490 |
| 473 if (pref && pref->IsManaged()) { | 491 if (pref && pref->IsManaged()) { |
| 474 pref_object->controlled_by = | 492 pref_object->controlled_by = |
| 475 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; | 493 settings_private::ControlledBy::CONTROLLED_BY_USER_POLICY; |
| 476 pref_object->enforcement = | 494 pref_object->enforcement = |
| 477 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 495 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
| 478 return pref_object; | 496 return pref_object; |
| 479 } | 497 } |
| 480 | 498 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 settings_private::Enforcement::ENFORCEMENT_ENFORCED; | 531 settings_private::Enforcement::ENFORCEMENT_ENFORCED; |
| 514 pref_object->extension_id.reset(new std::string(extension->id())); | 532 pref_object->extension_id.reset(new std::string(extension->id())); |
| 515 pref_object->controlled_by_name.reset(new std::string(extension->name())); | 533 pref_object->controlled_by_name.reset(new std::string(extension->name())); |
| 516 bool can_be_disabled = !ExtensionSystem::Get(profile_)->management_policy() | 534 bool can_be_disabled = !ExtensionSystem::Get(profile_)->management_policy() |
| 517 ->MustRemainEnabled(extension, nullptr); | 535 ->MustRemainEnabled(extension, nullptr); |
| 518 pref_object->extension_can_be_disabled.reset(new bool(can_be_disabled)); | 536 pref_object->extension_can_be_disabled.reset(new bool(can_be_disabled)); |
| 519 return pref_object; | 537 return pref_object; |
| 520 } | 538 } |
| 521 | 539 |
| 522 // TODO(dbeam): surface !IsUserModifiable or IsPrefSupervisorControlled? | 540 // TODO(dbeam): surface !IsUserModifiable or IsPrefSupervisorControlled? |
| 523 | |
| 524 return pref_object; | 541 return pref_object; |
| 525 } | 542 } |
| 526 | 543 |
| 527 PrefsUtil::SetPrefResult PrefsUtil::SetPref(const std::string& pref_name, | 544 PrefsUtil::SetPrefResult PrefsUtil::SetPref(const std::string& pref_name, |
| 528 const base::Value* value) { | 545 const base::Value* value) { |
| 529 if (GetWhitelistedPrefType(pref_name) == | 546 if (GetWhitelistedPrefType(pref_name) == |
| 530 settings_private::PrefType::PREF_TYPE_NONE) { | 547 settings_private::PrefType::PREF_TYPE_NONE) { |
| 531 return PREF_NOT_FOUND; | 548 return PREF_NOT_FOUND; |
| 532 } | 549 } |
| 533 | 550 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 return false; | 661 return false; |
| 645 #endif | 662 #endif |
| 646 } | 663 } |
| 647 | 664 |
| 648 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { | 665 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { |
| 649 return GetWhitelistedPrefType(pref_name) == | 666 return GetWhitelistedPrefType(pref_name) == |
| 650 settings_private::PrefType::PREF_TYPE_URL; | 667 settings_private::PrefType::PREF_TYPE_URL; |
| 651 } | 668 } |
| 652 | 669 |
| 653 #if defined(OS_CHROMEOS) | 670 #if defined(OS_CHROMEOS) |
| 671 | |
| 654 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { | 672 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { |
| 655 if (IsPrivilegedCrosSetting(pref_name)) { | 673 policy::BrowserPolicyConnectorChromeOS* connector = |
| 656 policy::BrowserPolicyConnectorChromeOS* connector = | 674 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 657 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 675 if (connector->IsEnterpriseManaged()) { |
| 658 if (connector->IsEnterpriseManaged()) | 676 if (IsPrivilegedCrosSetting(pref_name)) |
| 659 return true; | 677 return true; |
| 678 | |
| 679 if (pref_name == prefs::kUserTimezone || | |
| 680 pref_name == prefs::kResolveTimezoneByGeolocation) { | |
| 681 return chromeos::system::IfTimezonePrefsmanaged(pref_name); | |
| 682 } | |
| 660 } | 683 } |
| 661 return false; | 684 return false; |
| 662 } | 685 } |
| 663 | 686 |
| 664 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { | 687 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { |
| 665 if (IsPrivilegedCrosSetting(pref_name)) { | 688 if (IsPrivilegedCrosSetting(pref_name)) { |
| 666 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) | 689 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) |
| 667 return true; | 690 return true; |
| 668 } | 691 } |
| 669 return false; | 692 return false; |
| 670 } | 693 } |
| 671 | 694 |
| 672 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { | 695 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { |
| 673 if (pref_name == prefs::kWakeOnWifiDarkConnect) { | 696 const char* const* end = primary_user_prefs + primary_user_prefs_len; |
| 674 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 697 if (std::find(primary_user_prefs, end, pref_name) == end) |
| 675 const user_manager::User* user = | 698 return false; |
|
stevenjb
2017/05/15 17:08:02
Since this appears to be the only place we use |pr
Alexander Alekseev
2017/05/16 01:11:56
Done.
| |
| 676 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 699 |
| 677 if (user && | 700 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 678 user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId()) | 701 const user_manager::User* user = |
| 679 return true; | 702 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| 680 } | 703 if (user->GetAccountId() != user_manager->GetPrimaryUser()->GetAccountId()) |
| 704 return true; | |
| 705 | |
| 681 return false; | 706 return false; |
| 682 } | 707 } |
| 683 #endif | 708 #endif |
| 684 | 709 |
| 685 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { | 710 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { |
| 686 if (pref_name != prefs::kBrowserGuestModeEnabled && | 711 if (pref_name != prefs::kBrowserGuestModeEnabled && |
| 687 pref_name != prefs::kBrowserAddPersonEnabled) { | 712 pref_name != prefs::kBrowserAddPersonEnabled) { |
| 688 return false; | 713 return false; |
| 689 } | 714 } |
| 690 return profile_->IsSupervised(); | 715 return profile_->IsSupervised(); |
| 691 } | 716 } |
| 692 | 717 |
| 693 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { | 718 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { |
| 719 #if defined(OS_CHROMEOS) | |
| 720 if (IsCrosSettingReadOnly(pref_name)) | |
| 721 return false; | |
| 722 #endif | |
| 723 | |
| 694 const PrefService::Preference* profile_pref = | 724 const PrefService::Preference* profile_pref = |
| 695 profile_->GetPrefs()->FindPreference(pref_name); | 725 profile_->GetPrefs()->FindPreference(pref_name); |
| 696 if (profile_pref) | 726 if (profile_pref) |
| 697 return profile_pref->IsUserModifiable(); | 727 return profile_pref->IsUserModifiable(); |
| 698 | 728 |
| 699 const PrefService::Preference* local_state_pref = | 729 const PrefService::Preference* local_state_pref = |
| 700 g_browser_process->local_state()->FindPreference(pref_name); | 730 g_browser_process->local_state()->FindPreference(pref_name); |
| 701 if (local_state_pref) | 731 if (local_state_pref) |
| 702 return local_state_pref->IsUserModifiable(); | 732 return local_state_pref->IsUserModifiable(); |
| 703 | 733 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) | 801 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) |
| 772 ->GetExtensionControllingPref(pref_object.key); | 802 ->GetExtensionControllingPref(pref_object.key); |
| 773 if (extension_id.empty()) | 803 if (extension_id.empty()) |
| 774 return nullptr; | 804 return nullptr; |
| 775 | 805 |
| 776 return ExtensionRegistry::Get(profile_)->GetExtensionById( | 806 return ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 777 extension_id, ExtensionRegistry::ENABLED); | 807 extension_id, ExtensionRegistry::ENABLED); |
| 778 } | 808 } |
| 779 | 809 |
| 780 } // namespace extensions | 810 } // namespace extensions |
| OLD | NEW |