Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/supervised_user_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/feature_list.h" | |
| 10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/task_runner_util.h" | 17 #include "base/task_runner_util.h" |
| 17 #include "base/version.h" | 18 #include "base/version.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h " | 21 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h " |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_attributes_entry.h" | 23 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 23 #include "chrome/browser/profiles/profile_attributes_storage.h" | 24 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 26 #include "chrome/browser/signin/signin_manager_factory.h" | 27 #include "chrome/browser/signin/signin_manager_factory.h" |
| 27 #include "chrome/browser/supervised_user/experimental/supervised_user_filtering_ switches.h" | 28 #include "chrome/browser/supervised_user/experimental/supervised_user_filtering_ switches.h" |
| 28 #include "chrome/browser/supervised_user/permission_request_creator.h" | 29 #include "chrome/browser/supervised_user/permission_request_creator.h" |
| 29 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 30 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 31 #include "chrome/browser/supervised_user/supervised_user_features.h" | |
| 32 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | |
| 30 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" | 33 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
| 31 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 34 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 32 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" | 35 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" |
| 33 #include "chrome/browser/supervised_user/supervised_user_site_list.h" | 36 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
| 34 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" | 37 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" |
| 35 #include "chrome/browser/sync/profile_sync_service_factory.h" | 38 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 36 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
| 37 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
| 38 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
| 39 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 61 #endif | 64 #endif |
| 62 | 65 |
| 63 #if defined(OS_CHROMEOS) | 66 #if defined(OS_CHROMEOS) |
| 64 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 67 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 65 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 68 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
| 66 #include "components/user_manager/user_manager.h" | 69 #include "components/user_manager/user_manager.h" |
| 67 #endif | 70 #endif |
| 68 | 71 |
| 69 #if defined(ENABLE_EXTENSIONS) | 72 #if defined(ENABLE_EXTENSIONS) |
| 70 #include "chrome/browser/extensions/extension_service.h" | 73 #include "chrome/browser/extensions/extension_service.h" |
| 74 #include "chrome/browser/extensions/extension_util.h" | |
| 75 #include "extensions/browser/extension_prefs.h" | |
| 76 #include "extensions/browser/extension_registry.h" | |
| 71 #include "extensions/browser/extension_system.h" | 77 #include "extensions/browser/extension_system.h" |
| 72 #endif | 78 #endif |
| 73 | 79 |
| 74 #if defined(ENABLE_THEMES) | 80 #if defined(ENABLE_THEMES) |
| 75 #include "chrome/browser/themes/theme_service.h" | 81 #include "chrome/browser/themes/theme_service.h" |
| 76 #include "chrome/browser/themes/theme_service_factory.h" | 82 #include "chrome/browser/themes/theme_service_factory.h" |
| 77 #endif | 83 #endif |
| 78 | 84 |
| 79 using base::DictionaryValue; | 85 using base::DictionaryValue; |
| 80 using base::UserMetricsAction; | 86 using base::UserMetricsAction; |
| 81 using content::BrowserThread; | 87 using content::BrowserThread; |
| 82 | 88 |
| 89 #if defined(ENABLE_EXTENSIONS) | |
| 90 using extensions::Extension; | |
| 91 using extensions::ExtensionPrefs; | |
| 92 using extensions::ExtensionRegistry; | |
| 93 using extensions::ExtensionSystem; | |
| 94 #endif | |
| 95 | |
| 83 namespace { | 96 namespace { |
| 84 | 97 |
| 85 // The URL from which to download a host blacklist if no local one exists yet. | 98 // The URL from which to download a host blacklist if no local one exists yet. |
| 86 const char kBlacklistURL[] = | 99 const char kBlacklistURL[] = |
| 87 "https://www.gstatic.com/chrome/supervised_user/blacklist-20141001-1k.bin"; | 100 "https://www.gstatic.com/chrome/supervised_user/blacklist-20141001-1k.bin"; |
| 88 // The filename under which we'll store the blacklist (in the user data dir). | 101 // The filename under which we'll store the blacklist (in the user data dir). |
| 89 const char kBlacklistFilename[] = "su-blacklist.bin"; | 102 const char kBlacklistFilename[] = "su-blacklist.bin"; |
| 90 | 103 |
| 91 const char* const kCustodianInfoPrefs[] = { | 104 const char* const kCustodianInfoPrefs[] = { |
| 92 prefs::kSupervisedUserCustodianName, | 105 prefs::kSupervisedUserCustodianName, |
| 93 prefs::kSupervisedUserCustodianEmail, | 106 prefs::kSupervisedUserCustodianEmail, |
| 94 prefs::kSupervisedUserCustodianProfileImageURL, | 107 prefs::kSupervisedUserCustodianProfileImageURL, |
| 95 prefs::kSupervisedUserCustodianProfileURL, | 108 prefs::kSupervisedUserCustodianProfileURL, |
| 96 prefs::kSupervisedUserSecondCustodianName, | 109 prefs::kSupervisedUserSecondCustodianName, |
| 97 prefs::kSupervisedUserSecondCustodianEmail, | 110 prefs::kSupervisedUserSecondCustodianEmail, |
| 98 prefs::kSupervisedUserSecondCustodianProfileImageURL, | 111 prefs::kSupervisedUserSecondCustodianProfileImageURL, |
| 99 prefs::kSupervisedUserSecondCustodianProfileURL, | 112 prefs::kSupervisedUserSecondCustodianProfileURL, |
| 100 }; | 113 }; |
| 101 | 114 |
| 102 void CreateURLAccessRequest( | 115 void CreateURLAccessRequest( |
| 103 const GURL& url, | 116 const GURL& url, |
| 104 PermissionRequestCreator* creator, | 117 PermissionRequestCreator* creator, |
| 105 const SupervisedUserService::SuccessCallback& callback) { | 118 const SupervisedUserService::SuccessCallback& callback) { |
| 106 creator->CreateURLAccessRequest(url, callback); | 119 creator->CreateURLAccessRequest(url, callback); |
| 107 } | 120 } |
| 108 | 121 |
| 122 void CreateExtensionInstallRequest( | |
| 123 const std::string& id, | |
| 124 PermissionRequestCreator* creator, | |
| 125 const SupervisedUserService::SuccessCallback& callback) { | |
| 126 creator->CreateExtensionInstallRequest(id, callback); | |
| 127 } | |
| 128 | |
| 109 void CreateExtensionUpdateRequest( | 129 void CreateExtensionUpdateRequest( |
| 110 const std::string& id, | 130 const std::string& id, |
| 111 PermissionRequestCreator* creator, | 131 PermissionRequestCreator* creator, |
| 112 const SupervisedUserService::SuccessCallback& callback) { | 132 const SupervisedUserService::SuccessCallback& callback) { |
| 113 creator->CreateExtensionUpdateRequest(id, callback); | 133 creator->CreateExtensionUpdateRequest(id, callback); |
| 114 } | 134 } |
| 115 | 135 |
| 136 // Default callback for AddExtensionInstallRequest. | |
| 137 void ExtensionInstallRequestSent(const std::string& id, bool success) { | |
| 138 VLOG_IF(1, !success) << "Failed sending install request for " << id; | |
| 139 } | |
| 140 | |
| 116 // Default callback for AddExtensionUpdateRequest. | 141 // Default callback for AddExtensionUpdateRequest. |
| 117 void ExtensionUpdateRequestSent(const std::string& id, bool success) { | 142 void ExtensionUpdateRequestSent(const std::string& id, bool success) { |
| 118 VLOG_IF(1, !success) << "Failed sending update request for " << id; | 143 VLOG_IF(1, !success) << "Failed sending update request for " << id; |
| 119 } | 144 } |
| 120 | 145 |
| 121 base::FilePath GetBlacklistPath() { | 146 base::FilePath GetBlacklistPath() { |
| 122 base::FilePath blacklist_dir; | 147 base::FilePath blacklist_dir; |
| 123 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); | 148 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); |
| 124 return blacklist_dir.AppendASCII(kBlacklistFilename); | 149 return blacklist_dir.AppendASCII(kBlacklistFilename); |
| 125 } | 150 } |
| 126 | |
| 127 #if defined(ENABLE_EXTENSIONS) | |
| 128 enum ExtensionState { | |
| 129 EXTENSION_FORCED, | |
| 130 EXTENSION_BLOCKED, | |
| 131 EXTENSION_ALLOWED | |
| 132 }; | |
| 133 | |
| 134 ExtensionState GetExtensionState(const extensions::Extension* extension) { | |
| 135 bool was_installed_by_default = extension->was_installed_by_default(); | |
| 136 #if defined(OS_CHROMEOS) | |
| 137 // On Chrome OS all external sources are controlled by us so it means that | |
| 138 // they are "default". Method was_installed_by_default returns false because | |
| 139 // extensions creation flags are ignored in case of default extensions with | |
| 140 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). | |
| 141 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation | |
| 142 // flags are not ignored. | |
| 143 was_installed_by_default = | |
| 144 extensions::Manifest::IsExternalLocation(extension->location()); | |
| 145 #endif | |
| 146 // Note: Component extensions are protected from modification/uninstallation | |
| 147 // anyway, so there's no need to enforce them again for supervised users. | |
| 148 // Also, leave policy-installed extensions alone - they have their own | |
| 149 // management; in particular we don't want to override the force-install list. | |
| 150 if (extensions::Manifest::IsComponentLocation(extension->location()) || | |
| 151 extensions::Manifest::IsPolicyLocation(extension->location()) || | |
| 152 extension->is_theme() || | |
| 153 extension->from_bookmark() || | |
| 154 extension->is_shared_module() || | |
| 155 was_installed_by_default) { | |
| 156 return EXTENSION_ALLOWED; | |
| 157 } | |
| 158 | |
| 159 if (extension->was_installed_by_custodian()) | |
| 160 return EXTENSION_FORCED; | |
| 161 | |
| 162 return EXTENSION_BLOCKED; | |
| 163 } | |
| 164 #endif | |
| 165 | |
| 166 } // namespace | 151 } // namespace |
| 167 | 152 |
| 168 SupervisedUserService::~SupervisedUserService() { | 153 SupervisedUserService::~SupervisedUserService() { |
| 169 DCHECK(!did_init_ || did_shutdown_); | 154 DCHECK(!did_init_ || did_shutdown_); |
| 170 url_filter_context_.ui_url_filter()->RemoveObserver(this); | 155 url_filter_context_.ui_url_filter()->RemoveObserver(this); |
| 171 } | 156 } |
| 172 | 157 |
| 173 // static | 158 // static |
| 174 void SupervisedUserService::RegisterProfilePrefs( | 159 void SupervisedUserService::RegisterProfilePrefs( |
| 175 user_prefs::PrefRegistrySyncable* registry) { | 160 user_prefs::PrefRegistrySyncable* registry) { |
| 161 registry->RegisterDictionaryPref(prefs::kSupervisedUserApprovedExtensions); | |
| 176 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts); | 162 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts); |
| 177 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs); | 163 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs); |
| 178 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior, | 164 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior, |
| 179 SupervisedUserURLFilter::ALLOW); | 165 SupervisedUserURLFilter::ALLOW); |
| 180 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true); | 166 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true); |
| 181 registry->RegisterBooleanPref(prefs::kSupervisedUserSafeSites, true); | 167 registry->RegisterBooleanPref(prefs::kSupervisedUserSafeSites, true); |
| 182 for (const char* pref : kCustodianInfoPrefs) { | 168 for (const char* pref : kCustodianInfoPrefs) { |
| 183 registry->RegisterStringPref(pref, std::string()); | 169 registry->RegisterStringPref(pref, std::string()); |
| 184 } | 170 } |
| 185 } | 171 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 } | 242 } |
| 257 | 243 |
| 258 void SupervisedUserService::ReportURL(const GURL& url, | 244 void SupervisedUserService::ReportURL(const GURL& url, |
| 259 const SuccessCallback& callback) { | 245 const SuccessCallback& callback) { |
| 260 if (url_reporter_) | 246 if (url_reporter_) |
| 261 url_reporter_->ReportUrl(url, callback); | 247 url_reporter_->ReportUrl(url, callback); |
| 262 else | 248 else |
| 263 callback.Run(false); | 249 callback.Run(false); |
| 264 } | 250 } |
| 265 | 251 |
| 252 void SupervisedUserService::AddExtensionInstallRequest( | |
| 253 const std::string& extension_id, | |
| 254 const base::Version& version, | |
| 255 const SuccessCallback& callback) { | |
| 256 std::string id = GetExtensionRequestId(extension_id, version); | |
| 257 AddPermissionRequestInternal(base::Bind(CreateExtensionInstallRequest, id), | |
| 258 callback, 0); | |
| 259 } | |
| 260 | |
| 261 void SupervisedUserService::AddExtensionInstallRequest( | |
| 262 const std::string& extension_id, | |
| 263 const base::Version& version) { | |
| 264 std::string id = GetExtensionRequestId(extension_id, version); | |
| 265 AddPermissionRequestInternal(base::Bind(CreateExtensionInstallRequest, id), | |
| 266 base::Bind(ExtensionInstallRequestSent, id), 0); | |
| 267 } | |
| 268 | |
| 266 void SupervisedUserService::AddExtensionUpdateRequest( | 269 void SupervisedUserService::AddExtensionUpdateRequest( |
| 267 const std::string& extension_id, | 270 const std::string& extension_id, |
| 268 const base::Version& version, | 271 const base::Version& version, |
| 269 const SuccessCallback& callback) { | 272 const SuccessCallback& callback) { |
| 270 std::string id = GetExtensionUpdateRequestId(extension_id, version); | 273 std::string id = GetExtensionRequestId(extension_id, version); |
| 271 AddPermissionRequestInternal( | 274 AddPermissionRequestInternal( |
| 272 base::Bind(CreateExtensionUpdateRequest, id), callback, 0); | 275 base::Bind(CreateExtensionUpdateRequest, id), callback, 0); |
| 273 } | 276 } |
| 274 | 277 |
| 275 void SupervisedUserService::AddExtensionUpdateRequest( | 278 void SupervisedUserService::AddExtensionUpdateRequest( |
| 276 const std::string& extension_id, | 279 const std::string& extension_id, |
| 277 const base::Version& version) { | 280 const base::Version& version) { |
| 278 std::string id = GetExtensionUpdateRequestId(extension_id, version); | 281 std::string id = GetExtensionRequestId(extension_id, version); |
| 279 AddExtensionUpdateRequest(extension_id, version, | 282 AddExtensionUpdateRequest(extension_id, version, |
| 280 base::Bind(ExtensionUpdateRequestSent, id)); | 283 base::Bind(ExtensionUpdateRequestSent, id)); |
| 281 } | 284 } |
| 282 | 285 |
| 286 void SupervisedUserService::ChangeExtensionStateIfNecessary( | |
| 287 const std::string& extension_id) { | |
| 288 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | |
| 289 const Extension* extension = registry->GetInstalledExtension(extension_id); | |
| 290 // If the extension is not installed (yet), do nothing. | |
| 291 // When it gets installed, GetExtensionState() will return ALLOWED, hence | |
| 292 // it will be enabled. | |
| 293 if (!extension) | |
| 294 return; | |
| 295 | |
| 296 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); | |
| 297 ExtensionService* service = | |
| 298 ExtensionSystem::Get(profile_)->extension_service(); | |
| 299 | |
| 300 ExtensionState state = GetExtensionState(*extension); | |
| 301 // BLOCKED/FORCED extensions should be already disabled/enabled | |
| 302 // and we don't need to change their state here. | |
| 303 if (state == ExtensionState::BLOCKED || state == ExtensionState::FORCED) | |
| 304 return; | |
| 305 | |
| 306 if (state == ExtensionState::REQUIRE_APPROVAL) { | |
| 307 service->DisableExtension(extension_id, | |
| 308 Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED); | |
| 309 return; | |
| 310 } | |
| 311 | |
| 312 if (state == ExtensionState::ALLOWED) { | |
| 313 extension_prefs->RemoveDisableReason( | |
| 314 extension_id, Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED); | |
| 315 extension_prefs->RemoveDisableReason( | |
| 316 extension_id, Extension::DISABLE_PERMISSIONS_INCREASE); | |
| 317 // If not disabled for other reasons, enable it. | |
| 318 if (extension_prefs->GetDisableReasons(extension_id) == | |
| 319 Extension::DISABLE_NONE) { | |
| 320 service->EnableExtension(extension_id); | |
| 321 } | |
| 322 } | |
| 323 } | |
| 324 | |
| 283 // static | 325 // static |
| 284 std::string SupervisedUserService::GetExtensionUpdateRequestId( | 326 std::string SupervisedUserService::GetExtensionRequestId( |
| 285 const std::string& extension_id, | 327 const std::string& extension_id, |
| 286 const base::Version& version) { | 328 const base::Version& version) { |
| 287 return base::StringPrintf("%s:%s", extension_id.c_str(), | 329 return base::StringPrintf("%s:%s", extension_id.c_str(), |
| 288 version.GetString().c_str()); | 330 version.GetString().c_str()); |
| 289 } | 331 } |
| 290 | 332 |
| 291 std::string SupervisedUserService::GetCustodianEmailAddress() const { | 333 std::string SupervisedUserService::GetCustodianEmailAddress() const { |
| 292 std::string email = profile_->GetPrefs()->GetString( | 334 std::string email = profile_->GetPrefs()->GetString( |
| 293 prefs::kSupervisedUserCustodianEmail); | 335 prefs::kSupervisedUserCustodianEmail); |
| 294 #if defined(OS_CHROMEOS) | 336 #if defined(OS_CHROMEOS) |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 SupervisedUserService::SupervisedUserService(Profile* profile) | 556 SupervisedUserService::SupervisedUserService(Profile* profile) |
| 515 : includes_sync_sessions_type_(true), | 557 : includes_sync_sessions_type_(true), |
| 516 profile_(profile), | 558 profile_(profile), |
| 517 active_(false), | 559 active_(false), |
| 518 delegate_(NULL), | 560 delegate_(NULL), |
| 519 waiting_for_sync_initialization_(false), | 561 waiting_for_sync_initialization_(false), |
| 520 is_profile_active_(false), | 562 is_profile_active_(false), |
| 521 did_init_(false), | 563 did_init_(false), |
| 522 did_shutdown_(false), | 564 did_shutdown_(false), |
| 523 blacklist_state_(BlacklistLoadState::NOT_LOADED), | 565 blacklist_state_(BlacklistLoadState::NOT_LOADED), |
| 566 registry_observer_(this), | |
| 524 weak_ptr_factory_(this) { | 567 weak_ptr_factory_(this) { |
| 525 url_filter_context_.ui_url_filter()->AddObserver(this); | 568 url_filter_context_.ui_url_filter()->AddObserver(this); |
| 569 registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); | |
| 526 } | 570 } |
| 527 | 571 |
| 528 void SupervisedUserService::SetActive(bool active) { | 572 void SupervisedUserService::SetActive(bool active) { |
| 529 if (active_ == active) | 573 if (active_ == active) |
| 530 return; | 574 return; |
| 531 active_ = active; | 575 active_ = active; |
| 532 | 576 |
| 533 if (!delegate_ || !delegate_->SetActive(active_)) { | 577 if (!delegate_ || !delegate_->SetActive(active_)) { |
| 534 if (active_) { | 578 if (active_) { |
| 535 #if !defined(OS_ANDROID) | 579 #if !defined(OS_ANDROID) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 | 624 |
| 581 #if defined(ENABLE_EXTENSIONS) | 625 #if defined(ENABLE_EXTENSIONS) |
| 582 SetExtensionsActive(); | 626 SetExtensionsActive(); |
| 583 #endif | 627 #endif |
| 584 | 628 |
| 585 if (active_) { | 629 if (active_) { |
| 586 pref_change_registrar_.Add( | 630 pref_change_registrar_.Add( |
| 587 prefs::kDefaultSupervisedUserFilteringBehavior, | 631 prefs::kDefaultSupervisedUserFilteringBehavior, |
| 588 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, | 632 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, |
| 589 base::Unretained(this))); | 633 base::Unretained(this))); |
| 634 pref_change_registrar_.Add( | |
| 635 prefs::kSupervisedUserApprovedExtensions, | |
| 636 base::Bind(&SupervisedUserService::UpdateApprovedExtensions, | |
| 637 base::Unretained(this))); | |
| 590 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, | 638 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, |
| 591 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, | 639 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, |
| 592 base::Unretained(this))); | 640 base::Unretained(this))); |
| 593 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, | 641 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, |
| 594 base::Bind(&SupervisedUserService::UpdateManualHosts, | 642 base::Bind(&SupervisedUserService::UpdateManualHosts, |
| 595 base::Unretained(this))); | 643 base::Unretained(this))); |
| 596 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, | 644 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, |
| 597 base::Bind(&SupervisedUserService::UpdateManualURLs, | 645 base::Bind(&SupervisedUserService::UpdateManualURLs, |
| 598 base::Unretained(this))); | 646 base::Unretained(this))); |
| 599 for (const char* pref : kCustodianInfoPrefs) { | 647 for (const char* pref : kCustodianInfoPrefs) { |
| 600 pref_change_registrar_.Add(pref, | 648 pref_change_registrar_.Add(pref, |
| 601 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, | 649 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, |
| 602 base::Unretained(this))); | 650 base::Unretained(this))); |
| 603 } | 651 } |
| 604 | 652 |
| 605 // Initialize the filter. | 653 // Initialize the filter. |
| 606 OnDefaultFilteringBehaviorChanged(); | 654 OnDefaultFilteringBehaviorChanged(); |
| 607 OnSafeSitesSettingChanged(); | 655 OnSafeSitesSettingChanged(); |
| 608 whitelist_service_->Init(); | 656 whitelist_service_->Init(); |
| 609 UpdateManualHosts(); | 657 UpdateManualHosts(); |
| 610 UpdateManualURLs(); | 658 UpdateManualURLs(); |
| 659 UpdateApprovedExtensions(); | |
| 611 | 660 |
| 612 #if !defined(OS_ANDROID) | 661 #if !defined(OS_ANDROID) |
| 613 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 662 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| 614 // http://crbug.com/313377 | 663 // http://crbug.com/313377 |
| 615 BrowserList::AddObserver(this); | 664 BrowserList::AddObserver(this); |
| 616 #endif | 665 #endif |
| 617 } else { | 666 } else { |
| 618 permissions_creators_.clear(); | 667 permissions_creators_.clear(); |
| 619 url_reporter_.reset(); | 668 url_reporter_.reset(); |
| 620 | 669 |
| 621 pref_change_registrar_.Remove( | 670 pref_change_registrar_.Remove( |
| 622 prefs::kDefaultSupervisedUserFilteringBehavior); | 671 prefs::kDefaultSupervisedUserFilteringBehavior); |
| 672 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions); | |
| 623 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); | 673 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
| 624 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); | 674 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
| 625 for (const char* pref : kCustodianInfoPrefs) { | 675 for (const char* pref : kCustodianInfoPrefs) { |
| 626 pref_change_registrar_.Remove(pref); | 676 pref_change_registrar_.Remove(pref); |
| 627 } | 677 } |
| 628 | 678 |
| 629 url_filter_context_.Clear(); | 679 url_filter_context_.Clear(); |
| 630 FOR_EACH_OBSERVER( | 680 FOR_EACH_OBSERVER( |
| 631 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 681 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
| 632 | 682 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 bool result = it.value().GetAsBoolean(&allow); | 958 bool result = it.value().GetAsBoolean(&allow); |
| 909 DCHECK(result); | 959 DCHECK(result); |
| 910 (*url_map)[GURL(it.key())] = allow; | 960 (*url_map)[GURL(it.key())] = allow; |
| 911 } | 961 } |
| 912 url_filter_context_.SetManualURLs(std::move(url_map)); | 962 url_filter_context_.SetManualURLs(std::move(url_map)); |
| 913 | 963 |
| 914 FOR_EACH_OBSERVER( | 964 FOR_EACH_OBSERVER( |
| 915 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 965 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
| 916 } | 966 } |
| 917 | 967 |
| 968 void SupervisedUserService::UpdateApprovedExtensions() { | |
| 969 const base::DictionaryValue* dict = profile_->GetPrefs()->GetDictionary( | |
| 970 prefs::kSupervisedUserApprovedExtensions); | |
| 971 approved_extensions_map_.clear(); | |
| 972 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | |
| 973 std::string version_str; | |
| 974 bool result = it.value().GetAsString(&version_str); | |
| 975 DCHECK(result); | |
| 976 base::Version version(version_str); | |
| 977 if (version.IsValid()) | |
| 978 approved_extensions_map_[it.key()] = version; | |
| 979 else | |
| 980 LOG(WARNING) << "Invalid version number " << version_str; | |
| 981 } | |
| 982 | |
| 983 for (const auto& extensions_entry : approved_extensions_map_) { | |
| 984 ChangeExtensionStateIfNecessary(extensions_entry.first); | |
| 985 } | |
| 986 } | |
| 987 | |
| 918 std::string SupervisedUserService::GetSupervisedUserName() const { | 988 std::string SupervisedUserService::GetSupervisedUserName() const { |
| 919 #if defined(OS_CHROMEOS) | 989 #if defined(OS_CHROMEOS) |
| 920 // The active user can be NULL in unit tests. | 990 // The active user can be NULL in unit tests. |
| 921 if (user_manager::UserManager::Get()->GetActiveUser()) { | 991 if (user_manager::UserManager::Get()->GetActiveUser()) { |
| 922 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 992 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
| 923 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId())); | 993 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId())); |
| 924 } | 994 } |
| 925 return std::string(); | 995 return std::string(); |
| 926 #else | 996 #else |
| 927 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 997 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
| 928 #endif | 998 #endif |
| 929 } | 999 } |
| 930 | 1000 |
| 931 void SupervisedUserService::OnForceSessionSyncChanged() { | 1001 void SupervisedUserService::OnForceSessionSyncChanged() { |
| 932 includes_sync_sessions_type_ = | 1002 includes_sync_sessions_type_ = |
| 933 profile_->GetPrefs()->GetBoolean(prefs::kForceSessionSync); | 1003 profile_->GetPrefs()->GetBoolean(prefs::kForceSessionSync); |
| 934 ProfileSyncServiceFactory::GetForProfile(profile_) | 1004 ProfileSyncServiceFactory::GetForProfile(profile_) |
| 935 ->ReconfigureDatatypeManager(); | 1005 ->ReconfigureDatatypeManager(); |
| 936 } | 1006 } |
| 937 | 1007 |
| 1008 void SupervisedUserService::OnExtensionInstalled( | |
| 1009 content::BrowserContext* browser_context, | |
| 1010 const extensions::Extension* extension, | |
| 1011 bool is_update) { | |
| 1012 // This callback is responsible only for updating the approved version | |
| 1013 // upon extension update if it doesn't require extra permission. | |
| 1014 if (!is_update) | |
| 1015 return; | |
| 1016 | |
| 1017 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); | |
| 1018 const std::string& id = extension->id(); | |
| 1019 const base::Version& version = *extension->version(); | |
| 1020 | |
| 1021 // If an already approved extension is updated without requiring | |
| 1022 // new permissions, we update the approved_version and re-enable it. | |
| 1023 if (!extension_prefs->HasDisableReason( | |
| 1024 id, Extension::DISABLE_PERMISSIONS_INCREASE) && | |
| 1025 approved_extensions_map_.count(id) > 0 && | |
| 1026 approved_extensions_map_[id] < version) { | |
| 1027 approved_extensions_map_[id] = version; | |
| 1028 | |
| 1029 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey( | |
| 1030 supervised_users::kApprovedExtensions, id); | |
| 1031 std::unique_ptr<base::Value> version_value( | |
| 1032 new base::StringValue(version.GetString())); | |
| 1033 GetSettingsService()->UpdateSetting(key, std::move(version_value)); | |
| 1034 } | |
| 1035 ChangeExtensionStateIfNecessary(id); | |
| 1036 } | |
| 1037 | |
| 938 void SupervisedUserService::Shutdown() { | 1038 void SupervisedUserService::Shutdown() { |
| 939 if (!did_init_) | 1039 if (!did_init_) |
| 940 return; | 1040 return; |
| 941 DCHECK(!did_shutdown_); | 1041 DCHECK(!did_shutdown_); |
| 942 did_shutdown_ = true; | 1042 did_shutdown_ = true; |
| 943 if (ProfileIsSupervised()) { | 1043 if (ProfileIsSupervised()) { |
| 944 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); | 1044 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); |
| 945 } | 1045 } |
| 946 SetActive(false); | 1046 SetActive(false); |
| 947 | 1047 |
| 948 ProfileSyncService* sync_service = | 1048 ProfileSyncService* sync_service = |
| 949 ProfileSyncServiceFactory::GetForProfile(profile_); | 1049 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 950 | 1050 |
| 951 // Can be null in tests. | 1051 // Can be null in tests. |
| 952 if (sync_service) | 1052 if (sync_service) |
| 953 sync_service->RemovePreferenceProvider(this); | 1053 sync_service->RemovePreferenceProvider(this); |
| 954 } | 1054 } |
| 955 | 1055 |
| 956 #if defined(ENABLE_EXTENSIONS) | 1056 #if defined(ENABLE_EXTENSIONS) |
| 1057 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( | |
| 1058 const Extension& extension) const { | |
| 1059 bool was_installed_by_default = extension.was_installed_by_default(); | |
| 1060 #if defined(OS_CHROMEOS) | |
| 1061 // On Chrome OS all external sources are controlled by us so it means that | |
| 1062 // they are "default". Method was_installed_by_default returns false because | |
| 1063 // extensions creation flags are ignored in case of default extensions with | |
| 1064 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). | |
| 1065 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation | |
| 1066 // flags are not ignored. | |
| 1067 was_installed_by_default = | |
| 1068 extensions::Manifest::IsExternalLocation(extension->location()); | |
| 1069 #endif | |
| 1070 // Note: Component extensions are protected from modification/uninstallation | |
| 1071 // anyway, so there's no need to enforce them again for supervised users. | |
| 1072 // Also, leave policy-installed extensions alone - they have their own | |
| 1073 // management; in particular we don't want to override the force-install list. | |
| 1074 if (extensions::Manifest::IsComponentLocation(extension.location()) || | |
| 1075 extensions::Manifest::IsPolicyLocation(extension.location()) || | |
| 1076 extension.is_theme() || extension.from_bookmark() || | |
| 1077 extension.is_shared_module() || was_installed_by_default) { | |
| 1078 return ExtensionState::ALLOWED; | |
| 1079 } | |
| 1080 | |
| 1081 if (extension.was_installed_by_custodian()) | |
| 1082 return ExtensionState::FORCED; | |
| 1083 | |
| 1084 if (!base::FeatureList::IsEnabled( | |
| 1085 supervised_users::kSupervisedUserInitiatedExtensionInstall)) { | |
| 1086 return ExtensionState::BLOCKED; | |
| 1087 } | |
| 1088 | |
| 1089 const std::string& id = extension.id(); | |
| 1090 | |
| 1091 auto extension_it = approved_extensions_map_.find(id); | |
| 1092 // If the installed version is approved, then the extension is allowed, | |
| 1093 // otherwise, it requires approval. | |
| 1094 if (extension_it != approved_extensions_map_.end() && | |
| 1095 extension_it->second == *extension.version()) { | |
| 1096 return ExtensionState::ALLOWED; | |
| 1097 } | |
| 1098 return ExtensionState::REQUIRE_APPROVAL; | |
| 1099 } | |
| 1100 | |
| 957 std::string SupervisedUserService::GetDebugPolicyProviderName() const { | 1101 std::string SupervisedUserService::GetDebugPolicyProviderName() const { |
| 958 // Save the string space in official builds. | 1102 // Save the string space in official builds. |
| 959 #ifdef NDEBUG | 1103 #ifdef NDEBUG |
| 960 NOTREACHED(); | 1104 NOTREACHED(); |
| 961 return std::string(); | 1105 return std::string(); |
| 962 #else | 1106 #else |
| 963 return "Supervised User Service"; | 1107 return "Supervised User Service"; |
| 964 #endif | 1108 #endif |
| 965 } | 1109 } |
| 966 | 1110 |
| 967 bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, | 1111 bool SupervisedUserService::UserMayLoad(const Extension* extension, |
| 968 base::string16* error) const { | 1112 base::string16* error) const { |
| 969 DCHECK(ProfileIsSupervised()); | 1113 DCHECK(ProfileIsSupervised()); |
| 970 ExtensionState result = GetExtensionState(extension); | 1114 ExtensionState result = GetExtensionState(*extension); |
| 971 bool may_load = (result != EXTENSION_BLOCKED); | 1115 bool may_load = (result != ExtensionState::BLOCKED); |
|
Devlin
2016/06/20 17:32:28
nit: no parens needed
mamir
2016/06/21 11:00:44
Done.
| |
| 972 if (!may_load && error) | 1116 if (!may_load && error) |
| 973 *error = GetExtensionsLockedMessage(); | 1117 *error = GetExtensionsLockedMessage(); |
| 974 return may_load; | 1118 return may_load; |
| 975 } | 1119 } |
| 976 | 1120 |
| 977 bool SupervisedUserService::UserMayModifySettings( | 1121 bool SupervisedUserService::UserMayModifySettings(const Extension* extension, |
| 978 const extensions::Extension* extension, | 1122 base::string16* error) const { |
| 979 base::string16* error) const { | |
| 980 DCHECK(ProfileIsSupervised()); | 1123 DCHECK(ProfileIsSupervised()); |
| 981 ExtensionState result = GetExtensionState(extension); | 1124 ExtensionState result = GetExtensionState(*extension); |
| 982 bool may_modify = (result == EXTENSION_ALLOWED); | 1125 // While the following check allows the supervised user to modify the settings |
| 1126 // and enable or disable the extension, MustRemainDisabled properly takes care | |
| 1127 // of keeping an extension disabled when required. | |
| 1128 // For custodian-installed extensions, the state is always FORCED, even if | |
| 1129 // it's waiting for an update approval. | |
| 1130 bool may_modify = result != ExtensionState::FORCED; | |
| 983 if (!may_modify && error) | 1131 if (!may_modify && error) |
| 984 *error = GetExtensionsLockedMessage(); | 1132 *error = GetExtensionsLockedMessage(); |
| 985 return may_modify; | 1133 return may_modify; |
| 986 } | 1134 } |
| 987 | 1135 |
| 988 // Note: Having MustRemainInstalled always say "true" for custodian-installed | 1136 // Note: Having MustRemainInstalled always say "true" for custodian-installed |
| 989 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but | 1137 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but |
| 990 // exactly what we want). | 1138 // exactly what we want). |
| 991 bool SupervisedUserService::MustRemainInstalled( | 1139 bool SupervisedUserService::MustRemainInstalled(const Extension* extension, |
| 992 const extensions::Extension* extension, | 1140 base::string16* error) const { |
| 993 base::string16* error) const { | |
| 994 DCHECK(ProfileIsSupervised()); | 1141 DCHECK(ProfileIsSupervised()); |
| 995 ExtensionState result = GetExtensionState(extension); | 1142 ExtensionState result = GetExtensionState(*extension); |
| 996 bool may_not_uninstall = (result == EXTENSION_FORCED); | 1143 bool may_not_uninstall = (result == ExtensionState::FORCED); |
| 997 if (may_not_uninstall && error) | 1144 if (may_not_uninstall && error) |
| 998 *error = GetExtensionsLockedMessage(); | 1145 *error = GetExtensionsLockedMessage(); |
| 999 return may_not_uninstall; | 1146 return may_not_uninstall; |
| 1000 } | 1147 } |
| 1001 | 1148 |
| 1149 bool SupervisedUserService::MustRemainDisabled(const Extension* extension, | |
| 1150 Extension::DisableReason* reason, | |
| 1151 base::string16* error) const { | |
| 1152 DCHECK(ProfileIsSupervised()); | |
| 1153 ExtensionState state = GetExtensionState(*extension); | |
| 1154 bool must_remain_disabled = state == ExtensionState::BLOCKED || | |
| 1155 state == ExtensionState::REQUIRE_APPROVAL; | |
| 1156 | |
| 1157 if (must_remain_disabled) { | |
| 1158 // If the extension must remain disabled due to permission increase, | |
| 1159 // then the update request has been already sent at update time. | |
| 1160 // We do nothing and we don't add an extra disable reason. | |
| 1161 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); | |
| 1162 if (extension_prefs->HasDisableReason( | |
| 1163 extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE)) { | |
| 1164 if (reason) | |
| 1165 *reason = Extension::DISABLE_PERMISSIONS_INCREASE; | |
| 1166 if (error) { | |
| 1167 *error = | |
| 1168 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); | |
| 1169 } | |
| 1170 return true; | |
| 1171 } | |
| 1172 if (reason) | |
| 1173 *reason = Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED; | |
| 1174 if (error) | |
|
Devlin
2016/06/20 17:32:28
this is the same as line 1168, right? Can we just
mamir
2016/06/21 11:00:44
Done.
| |
| 1175 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); | |
| 1176 if (base::FeatureList::IsEnabled( | |
| 1177 supervised_users::kSupervisedUserInitiatedExtensionInstall)) { | |
| 1178 // If the Extension isn't pending a custodian approval already, send | |
| 1179 // an approval request. | |
| 1180 if (!extension_prefs->HasDisableReason( | |
| 1181 extension->id(), | |
| 1182 Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)) { | |
| 1183 // MustRemainDisabled is a const method and hence cannot call | |
| 1184 // AddExtensionInstallRequest directly. | |
| 1185 SupervisedUserService* supervised_user_service = | |
| 1186 SupervisedUserServiceFactory::GetForProfile(profile_); | |
| 1187 supervised_user_service->AddExtensionInstallRequest( | |
| 1188 extension->id(), *extension->version()); | |
| 1189 } | |
| 1190 } | |
| 1191 } | |
| 1192 return must_remain_disabled; | |
| 1193 } | |
| 1194 | |
| 1002 void SupervisedUserService::SetExtensionsActive() { | 1195 void SupervisedUserService::SetExtensionsActive() { |
| 1003 extensions::ExtensionSystem* extension_system = | 1196 extensions::ExtensionSystem* extension_system = |
| 1004 extensions::ExtensionSystem::Get(profile_); | 1197 extensions::ExtensionSystem::Get(profile_); |
| 1005 extensions::ManagementPolicy* management_policy = | 1198 extensions::ManagementPolicy* management_policy = |
| 1006 extension_system->management_policy(); | 1199 extension_system->management_policy(); |
| 1007 | 1200 |
| 1008 if (management_policy) { | 1201 if (management_policy) { |
| 1009 if (active_) | 1202 if (active_) |
| 1010 management_policy->RegisterProvider(this); | 1203 management_policy->RegisterProvider(this); |
| 1011 else | 1204 else |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1057 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 1250 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
| 1058 | 1251 |
| 1059 is_profile_active_ = profile_became_active; | 1252 is_profile_active_ = profile_became_active; |
| 1060 } | 1253 } |
| 1061 #endif // !defined(OS_ANDROID) | 1254 #endif // !defined(OS_ANDROID) |
| 1062 | 1255 |
| 1063 void SupervisedUserService::OnSiteListUpdated() { | 1256 void SupervisedUserService::OnSiteListUpdated() { |
| 1064 FOR_EACH_OBSERVER( | 1257 FOR_EACH_OBSERVER( |
| 1065 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 1258 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
| 1066 } | 1259 } |
| OLD | NEW |