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