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" | |
30 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" | 32 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
31 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 33 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
32 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" | 34 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" |
33 #include "chrome/browser/supervised_user/supervised_user_site_list.h" | 35 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
34 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" | 36 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" |
35 #include "chrome/browser/sync/profile_sync_service_factory.h" | 37 #include "chrome/browser/sync/profile_sync_service_factory.h" |
36 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
37 #include "chrome/browser/ui/browser_list.h" | 39 #include "chrome/browser/ui/browser_list.h" |
38 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
39 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
61 #endif | 63 #endif |
62 | 64 |
63 #if defined(OS_CHROMEOS) | 65 #if defined(OS_CHROMEOS) |
64 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 66 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
65 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 67 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
66 #include "components/user_manager/user_manager.h" | 68 #include "components/user_manager/user_manager.h" |
67 #endif | 69 #endif |
68 | 70 |
69 #if defined(ENABLE_EXTENSIONS) | 71 #if defined(ENABLE_EXTENSIONS) |
70 #include "chrome/browser/extensions/extension_service.h" | 72 #include "chrome/browser/extensions/extension_service.h" |
73 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | |
74 #include "extensions/browser/extension_prefs.h" | |
71 #include "extensions/browser/extension_system.h" | 75 #include "extensions/browser/extension_system.h" |
72 #endif | 76 #endif |
73 | 77 |
74 #if defined(ENABLE_THEMES) | 78 #if defined(ENABLE_THEMES) |
75 #include "chrome/browser/themes/theme_service.h" | 79 #include "chrome/browser/themes/theme_service.h" |
76 #include "chrome/browser/themes/theme_service_factory.h" | 80 #include "chrome/browser/themes/theme_service_factory.h" |
77 #endif | 81 #endif |
78 | 82 |
79 using base::DictionaryValue; | 83 using base::DictionaryValue; |
80 using base::UserMetricsAction; | 84 using base::UserMetricsAction; |
(...skipping 18 matching lines...) Expand all Loading... | |
99 prefs::kSupervisedUserSecondCustodianProfileURL, | 103 prefs::kSupervisedUserSecondCustodianProfileURL, |
100 }; | 104 }; |
101 | 105 |
102 void CreateURLAccessRequest( | 106 void CreateURLAccessRequest( |
103 const GURL& url, | 107 const GURL& url, |
104 PermissionRequestCreator* creator, | 108 PermissionRequestCreator* creator, |
105 const SupervisedUserService::SuccessCallback& callback) { | 109 const SupervisedUserService::SuccessCallback& callback) { |
106 creator->CreateURLAccessRequest(url, callback); | 110 creator->CreateURLAccessRequest(url, callback); |
107 } | 111 } |
108 | 112 |
113 void CreateExtensionInstallRequest( | |
114 const std::string& id, | |
115 PermissionRequestCreator* creator, | |
116 const SupervisedUserService::SuccessCallback& callback) { | |
117 creator->CreateExtensionInstallRequest(id, callback); | |
118 } | |
119 | |
109 void CreateExtensionUpdateRequest( | 120 void CreateExtensionUpdateRequest( |
110 const std::string& id, | 121 const std::string& id, |
111 PermissionRequestCreator* creator, | 122 PermissionRequestCreator* creator, |
112 const SupervisedUserService::SuccessCallback& callback) { | 123 const SupervisedUserService::SuccessCallback& callback) { |
113 creator->CreateExtensionUpdateRequest(id, callback); | 124 creator->CreateExtensionUpdateRequest(id, callback); |
114 } | 125 } |
115 | 126 |
127 // Default callback for AddExtensionInstallRequest. | |
128 void ExtensionInstallRequestSent(const std::string& id, bool success) { | |
129 VLOG_IF(1, !success) << "Failed sending install request for " << id; | |
130 } | |
131 | |
116 // Default callback for AddExtensionUpdateRequest. | 132 // Default callback for AddExtensionUpdateRequest. |
117 void ExtensionUpdateRequestSent(const std::string& id, bool success) { | 133 void ExtensionUpdateRequestSent(const std::string& id, bool success) { |
118 VLOG_IF(1, !success) << "Failed sending update request for " << id; | 134 VLOG_IF(1, !success) << "Failed sending update request for " << id; |
119 } | 135 } |
120 | 136 |
121 base::FilePath GetBlacklistPath() { | 137 base::FilePath GetBlacklistPath() { |
122 base::FilePath blacklist_dir; | 138 base::FilePath blacklist_dir; |
123 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); | 139 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); |
124 return blacklist_dir.AppendASCII(kBlacklistFilename); | 140 return blacklist_dir.AppendASCII(kBlacklistFilename); |
125 } | 141 } |
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 | 142 } // namespace |
167 | 143 |
168 SupervisedUserService::~SupervisedUserService() { | 144 SupervisedUserService::~SupervisedUserService() { |
169 DCHECK(!did_init_ || did_shutdown_); | 145 DCHECK(!did_init_ || did_shutdown_); |
170 url_filter_context_.ui_url_filter()->RemoveObserver(this); | 146 url_filter_context_.ui_url_filter()->RemoveObserver(this); |
171 } | 147 } |
172 | 148 |
173 // static | 149 // static |
174 void SupervisedUserService::RegisterProfilePrefs( | 150 void SupervisedUserService::RegisterProfilePrefs( |
175 user_prefs::PrefRegistrySyncable* registry) { | 151 user_prefs::PrefRegistrySyncable* registry) { |
152 registry->RegisterDictionaryPref(prefs::kSupervisedUserApprovedExtensions); | |
176 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts); | 153 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts); |
177 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs); | 154 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs); |
178 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior, | 155 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior, |
179 SupervisedUserURLFilter::ALLOW); | 156 SupervisedUserURLFilter::ALLOW); |
180 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true); | 157 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true); |
181 registry->RegisterBooleanPref(prefs::kSupervisedUserSafeSites, true); | 158 registry->RegisterBooleanPref(prefs::kSupervisedUserSafeSites, true); |
182 for (const char* pref : kCustodianInfoPrefs) { | 159 for (const char* pref : kCustodianInfoPrefs) { |
183 registry->RegisterStringPref(pref, std::string()); | 160 registry->RegisterStringPref(pref, std::string()); |
184 } | 161 } |
185 } | 162 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 } | 233 } |
257 | 234 |
258 void SupervisedUserService::ReportURL(const GURL& url, | 235 void SupervisedUserService::ReportURL(const GURL& url, |
259 const SuccessCallback& callback) { | 236 const SuccessCallback& callback) { |
260 if (url_reporter_) | 237 if (url_reporter_) |
261 url_reporter_->ReportUrl(url, callback); | 238 url_reporter_->ReportUrl(url, callback); |
262 else | 239 else |
263 callback.Run(false); | 240 callback.Run(false); |
264 } | 241 } |
265 | 242 |
243 void SupervisedUserService::AddExtensionInstallRequest( | |
244 const std::string& extension_id, | |
245 const base::Version& version, | |
246 const SuccessCallback& callback) { | |
247 std::string id = GetExtensionRequestId(extension_id, version); | |
248 AddPermissionRequestInternal(base::Bind(CreateExtensionInstallRequest, id), | |
249 callback, 0); | |
250 } | |
251 | |
252 void SupervisedUserService::AddExtensionInstallRequest( | |
253 const std::string& extension_id, | |
254 const base::Version& version) { | |
255 std::string id = GetExtensionRequestId(extension_id, version); | |
256 AddPermissionRequestInternal(base::Bind(CreateExtensionInstallRequest, id), | |
257 base::Bind(ExtensionInstallRequestSent, id), 0); | |
258 } | |
259 | |
266 void SupervisedUserService::AddExtensionUpdateRequest( | 260 void SupervisedUserService::AddExtensionUpdateRequest( |
267 const std::string& extension_id, | 261 const std::string& extension_id, |
268 const base::Version& version, | 262 const base::Version& version, |
269 const SuccessCallback& callback) { | 263 const SuccessCallback& callback) { |
270 std::string id = GetExtensionUpdateRequestId(extension_id, version); | 264 std::string id = GetExtensionRequestId(extension_id, version); |
271 AddPermissionRequestInternal( | 265 AddPermissionRequestInternal( |
272 base::Bind(CreateExtensionUpdateRequest, id), callback, 0); | 266 base::Bind(CreateExtensionUpdateRequest, id), callback, 0); |
273 } | 267 } |
274 | 268 |
275 void SupervisedUserService::AddExtensionUpdateRequest( | 269 void SupervisedUserService::AddExtensionUpdateRequest( |
276 const std::string& extension_id, | 270 const std::string& extension_id, |
277 const base::Version& version) { | 271 const base::Version& version) { |
278 std::string id = GetExtensionUpdateRequestId(extension_id, version); | 272 std::string id = GetExtensionRequestId(extension_id, version); |
279 AddExtensionUpdateRequest(extension_id, version, | 273 AddExtensionUpdateRequest(extension_id, version, |
280 base::Bind(ExtensionUpdateRequestSent, id)); | 274 base::Bind(ExtensionUpdateRequestSent, id)); |
281 } | 275 } |
282 | 276 |
283 // static | 277 // static |
284 std::string SupervisedUserService::GetExtensionUpdateRequestId( | 278 std::string SupervisedUserService::GetExtensionRequestId( |
285 const std::string& extension_id, | 279 const std::string& extension_id, |
286 const base::Version& version) { | 280 const base::Version& version) { |
287 return base::StringPrintf("%s:%s", extension_id.c_str(), | 281 return base::StringPrintf("%s:%s", extension_id.c_str(), |
288 version.GetString().c_str()); | 282 version.GetString().c_str()); |
289 } | 283 } |
290 | 284 |
291 std::string SupervisedUserService::GetCustodianEmailAddress() const { | 285 std::string SupervisedUserService::GetCustodianEmailAddress() const { |
292 std::string email = profile_->GetPrefs()->GetString( | 286 std::string email = profile_->GetPrefs()->GetString( |
293 prefs::kSupervisedUserCustodianEmail); | 287 prefs::kSupervisedUserCustodianEmail); |
294 #if defined(OS_CHROMEOS) | 288 #if defined(OS_CHROMEOS) |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 | 574 |
581 #if defined(ENABLE_EXTENSIONS) | 575 #if defined(ENABLE_EXTENSIONS) |
582 SetExtensionsActive(); | 576 SetExtensionsActive(); |
583 #endif | 577 #endif |
584 | 578 |
585 if (active_) { | 579 if (active_) { |
586 pref_change_registrar_.Add( | 580 pref_change_registrar_.Add( |
587 prefs::kDefaultSupervisedUserFilteringBehavior, | 581 prefs::kDefaultSupervisedUserFilteringBehavior, |
588 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, | 582 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, |
589 base::Unretained(this))); | 583 base::Unretained(this))); |
584 pref_change_registrar_.Add( | |
585 prefs::kSupervisedUserApprovedExtensions, | |
586 base::Bind(&SupervisedUserService::UpdateApprovedExtensions, | |
587 base::Unretained(this))); | |
590 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, | 588 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, |
591 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, | 589 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, |
592 base::Unretained(this))); | 590 base::Unretained(this))); |
593 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, | 591 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, |
594 base::Bind(&SupervisedUserService::UpdateManualHosts, | 592 base::Bind(&SupervisedUserService::UpdateManualHosts, |
595 base::Unretained(this))); | 593 base::Unretained(this))); |
596 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, | 594 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, |
597 base::Bind(&SupervisedUserService::UpdateManualURLs, | 595 base::Bind(&SupervisedUserService::UpdateManualURLs, |
598 base::Unretained(this))); | 596 base::Unretained(this))); |
599 for (const char* pref : kCustodianInfoPrefs) { | 597 for (const char* pref : kCustodianInfoPrefs) { |
600 pref_change_registrar_.Add(pref, | 598 pref_change_registrar_.Add(pref, |
601 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, | 599 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, |
602 base::Unretained(this))); | 600 base::Unretained(this))); |
603 } | 601 } |
604 | 602 |
605 // Initialize the filter. | 603 // Initialize the filter. |
606 OnDefaultFilteringBehaviorChanged(); | 604 OnDefaultFilteringBehaviorChanged(); |
607 OnSafeSitesSettingChanged(); | 605 OnSafeSitesSettingChanged(); |
608 whitelist_service_->Init(); | 606 whitelist_service_->Init(); |
609 UpdateManualHosts(); | 607 UpdateManualHosts(); |
610 UpdateManualURLs(); | 608 UpdateManualURLs(); |
609 UpdateApprovedExtensions(); | |
611 | 610 |
612 #if !defined(OS_ANDROID) | 611 #if !defined(OS_ANDROID) |
613 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 612 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
614 // http://crbug.com/313377 | 613 // http://crbug.com/313377 |
615 BrowserList::AddObserver(this); | 614 BrowserList::AddObserver(this); |
616 #endif | 615 #endif |
617 } else { | 616 } else { |
618 permissions_creators_.clear(); | 617 permissions_creators_.clear(); |
619 url_reporter_.reset(); | 618 url_reporter_.reset(); |
620 | 619 |
621 pref_change_registrar_.Remove( | 620 pref_change_registrar_.Remove( |
622 prefs::kDefaultSupervisedUserFilteringBehavior); | 621 prefs::kDefaultSupervisedUserFilteringBehavior); |
622 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions); | |
623 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); | 623 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
624 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); | 624 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
625 for (const char* pref : kCustodianInfoPrefs) { | 625 for (const char* pref : kCustodianInfoPrefs) { |
626 pref_change_registrar_.Remove(pref); | 626 pref_change_registrar_.Remove(pref); |
627 } | 627 } |
628 | 628 |
629 url_filter_context_.Clear(); | 629 url_filter_context_.Clear(); |
630 FOR_EACH_OBSERVER( | 630 FOR_EACH_OBSERVER( |
631 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 631 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
632 | 632 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 bool result = it.value().GetAsBoolean(&allow); | 908 bool result = it.value().GetAsBoolean(&allow); |
909 DCHECK(result); | 909 DCHECK(result); |
910 (*url_map)[GURL(it.key())] = allow; | 910 (*url_map)[GURL(it.key())] = allow; |
911 } | 911 } |
912 url_filter_context_.SetManualURLs(std::move(url_map)); | 912 url_filter_context_.SetManualURLs(std::move(url_map)); |
913 | 913 |
914 FOR_EACH_OBSERVER( | 914 FOR_EACH_OBSERVER( |
915 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 915 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
916 } | 916 } |
917 | 917 |
918 void SupervisedUserService::UpdateApprovedExtensions() { | |
919 const base::DictionaryValue* dict = profile_->GetPrefs()->GetDictionary( | |
920 prefs::kSupervisedUserApprovedExtensions); | |
921 std::map<std::string, base::Version> approved_extensions_map; | |
Marc Treib
2016/05/24 09:54:58
Why the separate variable? Can't you just approved
mamir
2016/06/03 09:45:55
Done.
| |
922 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | |
923 std::string version; | |
924 bool result = it.value().GetAsString(&version); | |
925 DCHECK(result); | |
926 approved_extensions_map[it.key()] = base::Version(version); | |
Marc Treib
2016/05/24 09:54:58
Check that the version is valid before using it.
mamir
2016/06/03 09:45:55
Done.
| |
927 } | |
928 approved_extensions_map_ = approved_extensions_map; | |
929 | |
930 ExtensionService* service = | |
931 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
932 extensions::ExtensionPrefs* extension_prefs = | |
933 extensions::ExtensionPrefs::Get(profile_); | |
934 for (const auto& extensions_entry : approved_extensions_map_) { | |
935 std::string extension_id = extensions_entry.first; | |
Marc Treib
2016/05/24 09:54:58
const std::string& ?
mamir
2016/06/03 09:45:55
Done.
| |
936 // Check other disable reasons and if none, enable the extension. | |
937 if (!(extension_prefs->GetDisableReasons(extension_id) | |
938 & ~extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)) { | |
939 // Try to enable the extension, this will call the ManagmentPolicy and | |
940 // properly enable the extension if possible. | |
941 service->EnableExtension(extension_id); | |
Marc Treib
2016/05/24 09:54:58
This will get called even if the extension is alre
mamir
2016/06/03 09:45:55
Done.
| |
942 } | |
943 } | |
944 } | |
945 | |
918 std::string SupervisedUserService::GetSupervisedUserName() const { | 946 std::string SupervisedUserService::GetSupervisedUserName() const { |
919 #if defined(OS_CHROMEOS) | 947 #if defined(OS_CHROMEOS) |
920 // The active user can be NULL in unit tests. | 948 // The active user can be NULL in unit tests. |
921 if (user_manager::UserManager::Get()->GetActiveUser()) { | 949 if (user_manager::UserManager::Get()->GetActiveUser()) { |
922 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 950 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
923 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId())); | 951 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId())); |
924 } | 952 } |
925 return std::string(); | 953 return std::string(); |
926 #else | 954 #else |
927 return profile_->GetPrefs()->GetString(prefs::kProfileName); | 955 return profile_->GetPrefs()->GetString(prefs::kProfileName); |
(...skipping 19 matching lines...) Expand all Loading... | |
947 | 975 |
948 ProfileSyncService* sync_service = | 976 ProfileSyncService* sync_service = |
949 ProfileSyncServiceFactory::GetForProfile(profile_); | 977 ProfileSyncServiceFactory::GetForProfile(profile_); |
950 | 978 |
951 // Can be null in tests. | 979 // Can be null in tests. |
952 if (sync_service) | 980 if (sync_service) |
953 sync_service->RemovePreferenceProvider(this); | 981 sync_service->RemovePreferenceProvider(this); |
954 } | 982 } |
955 | 983 |
956 #if defined(ENABLE_EXTENSIONS) | 984 #if defined(ENABLE_EXTENSIONS) |
985 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( | |
986 const extensions::Extension& extension) const { | |
987 bool was_installed_by_default = extension.was_installed_by_default(); | |
988 #if defined(OS_CHROMEOS) | |
989 // On Chrome OS all external sources are controlled by us so it means that | |
990 // they are "default". Method was_installed_by_default returns false because | |
991 // extensions creation flags are ignored in case of default extensions with | |
992 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). | |
993 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation | |
994 // flags are not ignored. | |
995 was_installed_by_default = | |
996 extensions::Manifest::IsExternalLocation(extension->location()); | |
997 #endif | |
998 // Note: Component extensions are protected from modification/uninstallation | |
999 // anyway, so there's no need to enforce them again for supervised users. | |
1000 // Also, leave policy-installed extensions alone - they have their own | |
1001 // management; in particular we don't want to override the force-install list. | |
1002 if (extensions::Manifest::IsComponentLocation(extension.location()) || | |
1003 extensions::Manifest::IsPolicyLocation(extension.location()) || | |
1004 extension.is_theme() || extension.from_bookmark() || | |
1005 extension.is_shared_module() || was_installed_by_default) { | |
1006 return ExtensionState::ALLOWED; | |
1007 } | |
1008 | |
1009 if (extension.was_installed_by_custodian()) | |
1010 return ExtensionState::FORCED; | |
1011 | |
1012 // TODO(mamir): if(on blacklist) return BLOCKED; | |
1013 if (!base::FeatureList::IsEnabled( | |
1014 supervised_users::kSupervisedUserInitiatedExtensionInstall)) | |
1015 return ExtensionState::BLOCKED; | |
1016 | |
1017 const std::string& id = extension.id(); | |
1018 // TODO(mamir) : compare the approved and installed versions before returning. | |
1019 if (approved_extensions_map_.count(id) == 0) | |
1020 return ExtensionState::REQUIRE_APPROVAL; | |
1021 | |
1022 | |
Marc Treib
2016/05/24 09:54:58
nit: extra empty line
mamir
2016/06/03 09:45:55
Done.
| |
1023 extensions::ExtensionPrefs* extension_prefs = | |
1024 extensions::ExtensionPrefs::Get(profile_); | |
1025 | |
1026 if (extension_prefs->GetInstalledExtensionInfo(id) | |
Marc Treib
2016/05/24 09:54:58
Is this check needed?
mamir
2016/06/03 09:45:55
Done.
| |
1027 && extension_prefs->HasDisableReason( | |
1028 id, extensions::Extension::DISABLE_PERMISSIONS_INCREASE)) | |
1029 return ExtensionState::REQUIRE_APPROVAL; | |
1030 | |
1031 return ExtensionState::ALLOWED; | |
1032 } | |
1033 | |
957 std::string SupervisedUserService::GetDebugPolicyProviderName() const { | 1034 std::string SupervisedUserService::GetDebugPolicyProviderName() const { |
958 // Save the string space in official builds. | 1035 // Save the string space in official builds. |
959 #ifdef NDEBUG | 1036 #ifdef NDEBUG |
960 NOTREACHED(); | 1037 NOTREACHED(); |
961 return std::string(); | 1038 return std::string(); |
962 #else | 1039 #else |
963 return "Supervised User Service"; | 1040 return "Supervised User Service"; |
964 #endif | 1041 #endif |
965 } | 1042 } |
966 | 1043 |
967 bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, | 1044 bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, |
968 base::string16* error) const { | 1045 base::string16* error) const { |
969 DCHECK(ProfileIsSupervised()); | 1046 DCHECK(ProfileIsSupervised()); |
970 ExtensionState result = GetExtensionState(extension); | 1047 ExtensionState result = GetExtensionState(*extension); |
971 bool may_load = (result != EXTENSION_BLOCKED); | 1048 bool may_load = (result != ExtensionState::BLOCKED); |
972 if (!may_load && error) | 1049 if (!may_load && error) |
973 *error = GetExtensionsLockedMessage(); | 1050 *error = GetExtensionsLockedMessage(); |
974 return may_load; | 1051 return may_load; |
975 } | 1052 } |
976 | 1053 |
977 bool SupervisedUserService::UserMayModifySettings( | 1054 bool SupervisedUserService::UserMayModifySettings( |
978 const extensions::Extension* extension, | 1055 const extensions::Extension* extension, |
979 base::string16* error) const { | 1056 base::string16* error) const { |
980 DCHECK(ProfileIsSupervised()); | 1057 DCHECK(ProfileIsSupervised()); |
981 ExtensionState result = GetExtensionState(extension); | 1058 ExtensionState result = GetExtensionState(*extension); |
982 bool may_modify = (result == EXTENSION_ALLOWED); | 1059 // While the following check allows the SU to modify the settings and enable |
1060 // or disable the extension, MustRemainDisabled properly takes care of | |
1061 // keeping an extension disabled when required. | |
1062 // For custodian-installed extensions, the state is always FORCED, even if | |
1063 // it's waiting for an update approval. | |
1064 bool may_modify = (result != ExtensionState::FORCED); | |
983 if (!may_modify && error) | 1065 if (!may_modify && error) |
984 *error = GetExtensionsLockedMessage(); | 1066 *error = GetExtensionsLockedMessage(); |
985 return may_modify; | 1067 return may_modify; |
986 } | 1068 } |
987 | 1069 |
988 // Note: Having MustRemainInstalled always say "true" for custodian-installed | 1070 // Note: Having MustRemainInstalled always say "true" for custodian-installed |
989 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but | 1071 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but |
990 // exactly what we want). | 1072 // exactly what we want). |
991 bool SupervisedUserService::MustRemainInstalled( | 1073 bool SupervisedUserService::MustRemainInstalled( |
992 const extensions::Extension* extension, | 1074 const extensions::Extension* extension, |
993 base::string16* error) const { | 1075 base::string16* error) const { |
994 DCHECK(ProfileIsSupervised()); | 1076 DCHECK(ProfileIsSupervised()); |
995 ExtensionState result = GetExtensionState(extension); | 1077 ExtensionState result = GetExtensionState(*extension); |
996 bool may_not_uninstall = (result == EXTENSION_FORCED); | 1078 bool may_not_uninstall = (result == ExtensionState::FORCED); |
997 if (may_not_uninstall && error) | 1079 if (may_not_uninstall && error) |
998 *error = GetExtensionsLockedMessage(); | 1080 *error = GetExtensionsLockedMessage(); |
999 return may_not_uninstall; | 1081 return may_not_uninstall; |
1000 } | 1082 } |
1001 | 1083 |
1084 bool SupervisedUserService::MustRemainDisabled( | |
1085 const extensions::Extension* extension, | |
Marc Treib
2016/05/24 09:54:58
optional: You could add
using extensions::Extensio
mamir
2016/06/03 09:45:55
Done.
| |
1086 extensions::Extension::DisableReason* reason, | |
1087 base::string16* error) const { | |
1088 DCHECK(ProfileIsSupervised()); | |
1089 ExtensionState state = GetExtensionState(*extension); | |
1090 bool must_remain_disabled = (state == ExtensionState::BLOCKED) | |
1091 || (state == ExtensionState::REQUIRE_APPROVAL); | |
1092 | |
1093 if (must_remain_disabled) { | |
1094 if (reason) | |
1095 *reason = extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED; | |
1096 if (error) | |
1097 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); | |
1098 if (base::FeatureList::IsEnabled( | |
1099 supervised_users::kSupervisedUserInitiatedExtensionInstall)) { | |
1100 // If the Extension isn't pending a custodian approval already, send | |
1101 // an approval request. | |
1102 extensions::ExtensionPrefs* extension_prefs = | |
1103 extensions::ExtensionPrefs::Get(profile_); | |
1104 if (!extension_prefs->HasDisableReason( | |
1105 extension->id(), | |
1106 extensions::Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)) { | |
1107 // MustRemainDisabled is a const method and hence cannot call | |
1108 // AddExtensionInstallRequest directly. | |
1109 SupervisedUserService* supervised_user_service = | |
1110 SupervisedUserServiceFactory::GetForProfile(profile_); | |
1111 supervised_user_service->AddExtensionInstallRequest( | |
1112 extension->id(), *extension->version()); | |
1113 } | |
1114 } | |
1115 } | |
1116 return must_remain_disabled; | |
1117 } | |
1118 | |
1002 void SupervisedUserService::SetExtensionsActive() { | 1119 void SupervisedUserService::SetExtensionsActive() { |
1003 extensions::ExtensionSystem* extension_system = | 1120 extensions::ExtensionSystem* extension_system = |
1004 extensions::ExtensionSystem::Get(profile_); | 1121 extensions::ExtensionSystem::Get(profile_); |
1005 extensions::ManagementPolicy* management_policy = | 1122 extensions::ManagementPolicy* management_policy = |
1006 extension_system->management_policy(); | 1123 extension_system->management_policy(); |
1007 | 1124 |
1008 if (management_policy) { | 1125 if (management_policy) { |
1009 if (active_) | 1126 if (active_) |
1010 management_policy->RegisterProvider(this); | 1127 management_policy->RegisterProvider(this); |
1011 else | 1128 else |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1057 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 1174 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
1058 | 1175 |
1059 is_profile_active_ = profile_became_active; | 1176 is_profile_active_ = profile_became_active; |
1060 } | 1177 } |
1061 #endif // !defined(OS_ANDROID) | 1178 #endif // !defined(OS_ANDROID) |
1062 | 1179 |
1063 void SupervisedUserService::OnSiteListUpdated() { | 1180 void SupervisedUserService::OnSiteListUpdated() { |
1064 FOR_EACH_OBSERVER( | 1181 FOR_EACH_OBSERVER( |
1065 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 1182 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
1066 } | 1183 } |
OLD | NEW |