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 23 matching lines...) Expand all Loading... | |
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" |
71 #include "chrome/browser/extensions/extension_util.h" | 74 #include "chrome/browser/extensions/extension_util.h" |
72 #include "extensions/browser/extension_prefs.h" | 75 #include "extensions/browser/extension_prefs.h" |
76 #include "extensions/browser/extension_registry.h" | |
73 #include "extensions/browser/extension_system.h" | 77 #include "extensions/browser/extension_system.h" |
74 #endif | 78 #endif |
75 | 79 |
76 #if defined(ENABLE_THEMES) | 80 #if defined(ENABLE_THEMES) |
77 #include "chrome/browser/themes/theme_service.h" | 81 #include "chrome/browser/themes/theme_service.h" |
78 #include "chrome/browser/themes/theme_service_factory.h" | 82 #include "chrome/browser/themes/theme_service_factory.h" |
79 #endif | 83 #endif |
80 | 84 |
81 using base::DictionaryValue; | 85 using base::DictionaryValue; |
82 using base::UserMetricsAction; | 86 using base::UserMetricsAction; |
83 using content::BrowserThread; | 87 using content::BrowserThread; |
84 | 88 |
85 #if defined(ENABLE_EXTENSIONS) | 89 #if defined(ENABLE_EXTENSIONS) |
90 using extensions::Extension; | |
91 using extensions::ExtensionPrefs; | |
92 using extensions::ExtensionRegistry; | |
93 using extensions::ExtensionSystem; | |
94 #endif | |
95 | |
96 #if defined(ENABLE_EXTENSIONS) | |
86 using extensions::ExtensionPrefs; | 97 using extensions::ExtensionPrefs; |
87 #endif | 98 #endif |
88 | 99 |
89 namespace { | 100 namespace { |
90 | 101 |
91 // The URL from which to download a host blacklist if no local one exists yet. | 102 // The URL from which to download a host blacklist if no local one exists yet. |
92 const char kBlacklistURL[] = | 103 const char kBlacklistURL[] = |
93 "https://www.gstatic.com/chrome/supervised_user/blacklist-20141001-1k.bin"; | 104 "https://www.gstatic.com/chrome/supervised_user/blacklist-20141001-1k.bin"; |
94 // The filename under which we'll store the blacklist (in the user data dir). | 105 // The filename under which we'll store the blacklist (in the user data dir). |
95 const char kBlacklistFilename[] = "su-blacklist.bin"; | 106 const char kBlacklistFilename[] = "su-blacklist.bin"; |
96 | 107 |
97 const char* const kCustodianInfoPrefs[] = { | 108 const char* const kCustodianInfoPrefs[] = { |
98 prefs::kSupervisedUserCustodianName, | 109 prefs::kSupervisedUserCustodianName, |
99 prefs::kSupervisedUserCustodianEmail, | 110 prefs::kSupervisedUserCustodianEmail, |
100 prefs::kSupervisedUserCustodianProfileImageURL, | 111 prefs::kSupervisedUserCustodianProfileImageURL, |
101 prefs::kSupervisedUserCustodianProfileURL, | 112 prefs::kSupervisedUserCustodianProfileURL, |
102 prefs::kSupervisedUserSecondCustodianName, | 113 prefs::kSupervisedUserSecondCustodianName, |
103 prefs::kSupervisedUserSecondCustodianEmail, | 114 prefs::kSupervisedUserSecondCustodianEmail, |
104 prefs::kSupervisedUserSecondCustodianProfileImageURL, | 115 prefs::kSupervisedUserSecondCustodianProfileImageURL, |
105 prefs::kSupervisedUserSecondCustodianProfileURL, | 116 prefs::kSupervisedUserSecondCustodianProfileURL, |
106 }; | 117 }; |
107 | 118 |
108 void CreateURLAccessRequest( | 119 void CreateURLAccessRequest( |
109 const GURL& url, | 120 const GURL& url, |
110 PermissionRequestCreator* creator, | 121 PermissionRequestCreator* creator, |
111 const SupervisedUserService::SuccessCallback& callback) { | 122 const SupervisedUserService::SuccessCallback& callback) { |
112 creator->CreateURLAccessRequest(url, callback); | 123 creator->CreateURLAccessRequest(url, callback); |
113 } | 124 } |
114 | 125 |
126 void CreateExtensionInstallRequest( | |
127 const std::string& id, | |
128 PermissionRequestCreator* creator, | |
129 const SupervisedUserService::SuccessCallback& callback) { | |
130 creator->CreateExtensionInstallRequest(id, callback); | |
131 } | |
132 | |
115 void CreateExtensionUpdateRequest( | 133 void CreateExtensionUpdateRequest( |
116 const std::string& id, | 134 const std::string& id, |
117 PermissionRequestCreator* creator, | 135 PermissionRequestCreator* creator, |
118 const SupervisedUserService::SuccessCallback& callback) { | 136 const SupervisedUserService::SuccessCallback& callback) { |
119 creator->CreateExtensionUpdateRequest(id, callback); | 137 creator->CreateExtensionUpdateRequest(id, callback); |
120 } | 138 } |
121 | 139 |
140 // Default callback for AddExtensionInstallRequest. | |
141 void ExtensionInstallRequestSent(const std::string& id, bool success) { | |
142 VLOG_IF(1, !success) << "Failed sending install request for " << id; | |
143 } | |
144 | |
122 // Default callback for AddExtensionUpdateRequest. | 145 // Default callback for AddExtensionUpdateRequest. |
123 void ExtensionUpdateRequestSent(const std::string& id, bool success) { | 146 void ExtensionUpdateRequestSent(const std::string& id, bool success) { |
124 VLOG_IF(1, !success) << "Failed sending update request for " << id; | 147 VLOG_IF(1, !success) << "Failed sending update request for " << id; |
125 } | 148 } |
126 | 149 |
127 base::FilePath GetBlacklistPath() { | 150 base::FilePath GetBlacklistPath() { |
128 base::FilePath blacklist_dir; | 151 base::FilePath blacklist_dir; |
129 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); | 152 PathService::Get(chrome::DIR_USER_DATA, &blacklist_dir); |
130 return blacklist_dir.AppendASCII(kBlacklistFilename); | 153 return blacklist_dir.AppendASCII(kBlacklistFilename); |
131 } | 154 } |
132 | 155 |
133 } // namespace | 156 } // namespace |
134 | 157 |
135 SupervisedUserService::~SupervisedUserService() { | 158 SupervisedUserService::~SupervisedUserService() { |
136 DCHECK(!did_init_ || did_shutdown_); | 159 DCHECK(!did_init_ || did_shutdown_); |
137 url_filter_context_.ui_url_filter()->RemoveObserver(this); | 160 url_filter_context_.ui_url_filter()->RemoveObserver(this); |
138 } | 161 } |
139 | 162 |
140 // static | 163 // static |
141 void SupervisedUserService::RegisterProfilePrefs( | 164 void SupervisedUserService::RegisterProfilePrefs( |
142 user_prefs::PrefRegistrySyncable* registry) { | 165 user_prefs::PrefRegistrySyncable* registry) { |
166 registry->RegisterDictionaryPref(prefs::kSupervisedUserApprovedExtensions); | |
143 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts); | 167 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualHosts); |
144 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs); | 168 registry->RegisterDictionaryPref(prefs::kSupervisedUserManualURLs); |
145 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior, | 169 registry->RegisterIntegerPref(prefs::kDefaultSupervisedUserFilteringBehavior, |
146 SupervisedUserURLFilter::ALLOW); | 170 SupervisedUserURLFilter::ALLOW); |
147 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true); | 171 registry->RegisterBooleanPref(prefs::kSupervisedUserCreationAllowed, true); |
148 registry->RegisterBooleanPref(prefs::kSupervisedUserSafeSites, true); | 172 registry->RegisterBooleanPref(prefs::kSupervisedUserSafeSites, true); |
149 for (const char* pref : kCustodianInfoPrefs) { | 173 for (const char* pref : kCustodianInfoPrefs) { |
150 registry->RegisterStringPref(pref, std::string()); | 174 registry->RegisterStringPref(pref, std::string()); |
151 } | 175 } |
152 } | 176 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 } | 247 } |
224 | 248 |
225 void SupervisedUserService::ReportURL(const GURL& url, | 249 void SupervisedUserService::ReportURL(const GURL& url, |
226 const SuccessCallback& callback) { | 250 const SuccessCallback& callback) { |
227 if (url_reporter_) | 251 if (url_reporter_) |
228 url_reporter_->ReportUrl(url, callback); | 252 url_reporter_->ReportUrl(url, callback); |
229 else | 253 else |
230 callback.Run(false); | 254 callback.Run(false); |
231 } | 255 } |
232 | 256 |
257 void SupervisedUserService::AddExtensionInstallRequest( | |
258 const std::string& extension_id, | |
259 const base::Version& version, | |
260 const SuccessCallback& callback) { | |
261 std::string id = GetExtensionRequestId(extension_id, version); | |
262 AddPermissionRequestInternal(base::Bind(CreateExtensionInstallRequest, id), | |
263 callback, 0); | |
264 } | |
265 | |
266 void SupervisedUserService::AddExtensionInstallRequest( | |
267 const std::string& extension_id, | |
268 const base::Version& version) { | |
269 std::string id = GetExtensionRequestId(extension_id, version); | |
270 AddPermissionRequestInternal(base::Bind(CreateExtensionInstallRequest, id), | |
271 base::Bind(ExtensionInstallRequestSent, id), 0); | |
272 } | |
273 | |
233 void SupervisedUserService::AddExtensionUpdateRequest( | 274 void SupervisedUserService::AddExtensionUpdateRequest( |
234 const std::string& extension_id, | 275 const std::string& extension_id, |
235 const base::Version& version, | 276 const base::Version& version, |
236 const SuccessCallback& callback) { | 277 const SuccessCallback& callback) { |
237 std::string id = GetExtensionUpdateRequestId(extension_id, version); | 278 std::string id = GetExtensionRequestId(extension_id, version); |
238 AddPermissionRequestInternal( | 279 AddPermissionRequestInternal( |
239 base::Bind(CreateExtensionUpdateRequest, id), callback, 0); | 280 base::Bind(CreateExtensionUpdateRequest, id), callback, 0); |
240 } | 281 } |
241 | 282 |
242 void SupervisedUserService::AddExtensionUpdateRequest( | 283 void SupervisedUserService::AddExtensionUpdateRequest( |
243 const std::string& extension_id, | 284 const std::string& extension_id, |
244 const base::Version& version) { | 285 const base::Version& version) { |
245 std::string id = GetExtensionUpdateRequestId(extension_id, version); | 286 std::string id = GetExtensionRequestId(extension_id, version); |
246 AddExtensionUpdateRequest(extension_id, version, | 287 AddExtensionUpdateRequest(extension_id, version, |
247 base::Bind(ExtensionUpdateRequestSent, id)); | 288 base::Bind(ExtensionUpdateRequestSent, id)); |
248 } | 289 } |
249 | 290 |
250 // static | 291 // static |
251 std::string SupervisedUserService::GetExtensionUpdateRequestId( | 292 std::string SupervisedUserService::GetExtensionRequestId( |
252 const std::string& extension_id, | 293 const std::string& extension_id, |
253 const base::Version& version) { | 294 const base::Version& version) { |
254 return base::StringPrintf("%s:%s", extension_id.c_str(), | 295 return base::StringPrintf("%s:%s", extension_id.c_str(), |
255 version.GetString().c_str()); | 296 version.GetString().c_str()); |
256 } | 297 } |
257 | 298 |
258 std::string SupervisedUserService::GetCustodianEmailAddress() const { | 299 std::string SupervisedUserService::GetCustodianEmailAddress() const { |
259 std::string email = profile_->GetPrefs()->GetString( | 300 std::string email = profile_->GetPrefs()->GetString( |
260 prefs::kSupervisedUserCustodianEmail); | 301 prefs::kSupervisedUserCustodianEmail); |
261 #if defined(OS_CHROMEOS) | 302 #if defined(OS_CHROMEOS) |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 SupervisedUserService::SupervisedUserService(Profile* profile) | 522 SupervisedUserService::SupervisedUserService(Profile* profile) |
482 : includes_sync_sessions_type_(true), | 523 : includes_sync_sessions_type_(true), |
483 profile_(profile), | 524 profile_(profile), |
484 active_(false), | 525 active_(false), |
485 delegate_(NULL), | 526 delegate_(NULL), |
486 waiting_for_sync_initialization_(false), | 527 waiting_for_sync_initialization_(false), |
487 is_profile_active_(false), | 528 is_profile_active_(false), |
488 did_init_(false), | 529 did_init_(false), |
489 did_shutdown_(false), | 530 did_shutdown_(false), |
490 blacklist_state_(BlacklistLoadState::NOT_LOADED), | 531 blacklist_state_(BlacklistLoadState::NOT_LOADED), |
532 #if defined(ENABLE_EXTENSIONS) | |
533 registry_observer_(this), | |
534 #endif | |
491 weak_ptr_factory_(this) { | 535 weak_ptr_factory_(this) { |
492 url_filter_context_.ui_url_filter()->AddObserver(this); | 536 url_filter_context_.ui_url_filter()->AddObserver(this); |
537 #if defined(ENABLE_EXTENSIONS) | |
538 registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); | |
539 #endif | |
493 } | 540 } |
494 | 541 |
495 void SupervisedUserService::SetActive(bool active) { | 542 void SupervisedUserService::SetActive(bool active) { |
496 if (active_ == active) | 543 if (active_ == active) |
497 return; | 544 return; |
498 active_ = active; | 545 active_ = active; |
499 | 546 |
500 if (!delegate_ || !delegate_->SetActive(active_)) { | 547 if (!delegate_ || !delegate_->SetActive(active_)) { |
501 if (active_) { | 548 if (active_) { |
502 #if !defined(OS_ANDROID) | 549 #if !defined(OS_ANDROID) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 | 594 |
548 #if defined(ENABLE_EXTENSIONS) | 595 #if defined(ENABLE_EXTENSIONS) |
549 SetExtensionsActive(); | 596 SetExtensionsActive(); |
550 #endif | 597 #endif |
551 | 598 |
552 if (active_) { | 599 if (active_) { |
553 pref_change_registrar_.Add( | 600 pref_change_registrar_.Add( |
554 prefs::kDefaultSupervisedUserFilteringBehavior, | 601 prefs::kDefaultSupervisedUserFilteringBehavior, |
555 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, | 602 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, |
556 base::Unretained(this))); | 603 base::Unretained(this))); |
604 #if defined(ENABLE_EXTENSIONS) | |
605 pref_change_registrar_.Add( | |
606 prefs::kSupervisedUserApprovedExtensions, | |
607 base::Bind(&SupervisedUserService::UpdateApprovedExtensions, | |
608 base::Unretained(this))); | |
609 #endif | |
557 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, | 610 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, |
558 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, | 611 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, |
559 base::Unretained(this))); | 612 base::Unretained(this))); |
560 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, | 613 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, |
561 base::Bind(&SupervisedUserService::UpdateManualHosts, | 614 base::Bind(&SupervisedUserService::UpdateManualHosts, |
562 base::Unretained(this))); | 615 base::Unretained(this))); |
563 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, | 616 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, |
564 base::Bind(&SupervisedUserService::UpdateManualURLs, | 617 base::Bind(&SupervisedUserService::UpdateManualURLs, |
565 base::Unretained(this))); | 618 base::Unretained(this))); |
566 for (const char* pref : kCustodianInfoPrefs) { | 619 for (const char* pref : kCustodianInfoPrefs) { |
567 pref_change_registrar_.Add(pref, | 620 pref_change_registrar_.Add(pref, |
568 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, | 621 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, |
569 base::Unretained(this))); | 622 base::Unretained(this))); |
570 } | 623 } |
571 | 624 |
572 // Initialize the filter. | 625 // Initialize the filter. |
573 OnDefaultFilteringBehaviorChanged(); | 626 OnDefaultFilteringBehaviorChanged(); |
574 OnSafeSitesSettingChanged(); | 627 OnSafeSitesSettingChanged(); |
575 whitelist_service_->Init(); | 628 whitelist_service_->Init(); |
576 UpdateManualHosts(); | 629 UpdateManualHosts(); |
577 UpdateManualURLs(); | 630 UpdateManualURLs(); |
578 | 631 |
632 #if defined(ENABLE_EXTENSIONS) | |
633 UpdateApprovedExtensions(); | |
634 #endif | |
635 | |
579 #if !defined(OS_ANDROID) | 636 #if !defined(OS_ANDROID) |
580 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 637 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
581 // http://crbug.com/313377 | 638 // http://crbug.com/313377 |
582 BrowserList::AddObserver(this); | 639 BrowserList::AddObserver(this); |
583 #endif | 640 #endif |
584 } else { | 641 } else { |
585 permissions_creators_.clear(); | 642 permissions_creators_.clear(); |
586 url_reporter_.reset(); | 643 url_reporter_.reset(); |
587 | 644 |
588 pref_change_registrar_.Remove( | 645 pref_change_registrar_.Remove( |
589 prefs::kDefaultSupervisedUserFilteringBehavior); | 646 prefs::kDefaultSupervisedUserFilteringBehavior); |
647 #if defined(ENABLE_EXTENSIONS) | |
648 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions); | |
649 #endif | |
590 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); | 650 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
591 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); | 651 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
592 for (const char* pref : kCustodianInfoPrefs) { | 652 for (const char* pref : kCustodianInfoPrefs) { |
593 pref_change_registrar_.Remove(pref); | 653 pref_change_registrar_.Remove(pref); |
594 } | 654 } |
595 | 655 |
596 url_filter_context_.Clear(); | 656 url_filter_context_.Clear(); |
597 FOR_EACH_OBSERVER( | 657 FOR_EACH_OBSERVER( |
598 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 658 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
599 | 659 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 ProfileSyncService* sync_service = | 977 ProfileSyncService* sync_service = |
918 ProfileSyncServiceFactory::GetForProfile(profile_); | 978 ProfileSyncServiceFactory::GetForProfile(profile_); |
919 | 979 |
920 // Can be null in tests. | 980 // Can be null in tests. |
921 if (sync_service) | 981 if (sync_service) |
922 sync_service->RemovePreferenceProvider(this); | 982 sync_service->RemovePreferenceProvider(this); |
923 } | 983 } |
924 | 984 |
925 #if defined(ENABLE_EXTENSIONS) | 985 #if defined(ENABLE_EXTENSIONS) |
926 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( | 986 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( |
927 const extensions::Extension* extension) const { | 987 const Extension& extension) const { |
928 bool was_installed_by_default = extension->was_installed_by_default(); | 988 bool was_installed_by_default = extension.was_installed_by_default(); |
929 #if defined(OS_CHROMEOS) | 989 #if defined(OS_CHROMEOS) |
930 // On Chrome OS all external sources are controlled by us so it means that | 990 // On Chrome OS all external sources are controlled by us so it means that |
931 // they are "default". Method was_installed_by_default returns false because | 991 // they are "default". Method was_installed_by_default returns false because |
932 // extensions creation flags are ignored in case of default extensions with | 992 // extensions creation flags are ignored in case of default extensions with |
933 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). | 993 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). |
934 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation | 994 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation |
935 // flags are not ignored. | 995 // flags are not ignored. |
936 was_installed_by_default = | 996 was_installed_by_default = |
937 extensions::Manifest::IsExternalLocation(extension->location()); | 997 extensions::Manifest::IsExternalLocation(extension.location()); |
938 #endif | 998 #endif |
939 // Note: Component extensions are protected from modification/uninstallation | 999 // Note: Component extensions are protected from modification/uninstallation |
940 // anyway, so there's no need to enforce them again for supervised users. | 1000 // anyway, so there's no need to enforce them again for supervised users. |
941 // Also, leave policy-installed extensions alone - they have their own | 1001 // Also, leave policy-installed extensions alone - they have their own |
942 // management; in particular we don't want to override the force-install list. | 1002 // management; in particular we don't want to override the force-install list. |
943 if (extensions::Manifest::IsComponentLocation(extension->location()) || | 1003 if (extensions::Manifest::IsComponentLocation(extension.location()) || |
944 extensions::Manifest::IsPolicyLocation(extension->location()) || | 1004 extensions::Manifest::IsPolicyLocation(extension.location()) || |
945 extension->is_theme() || | 1005 extension.is_theme() || extension.from_bookmark() || |
946 extension->from_bookmark() || | 1006 extension.is_shared_module() || was_installed_by_default) { |
947 extension->is_shared_module() || | 1007 return ExtensionState::ALLOWED; |
948 was_installed_by_default) { | |
949 return ExtensionState::EXTENSION_ALLOWED; | |
950 } | 1008 } |
951 | 1009 |
952 if (extensions::util::WasInstalledByCustodian(extension->id(), profile_)) | 1010 if (extensions::util::WasInstalledByCustodian(extension.id(), profile_)) |
953 return ExtensionState::EXTENSION_FORCED; | 1011 return ExtensionState::FORCED; |
954 | 1012 |
955 return ExtensionState::EXTENSION_BLOCKED; | 1013 if (!base::FeatureList::IsEnabled( |
1014 supervised_users::kSupervisedUserInitiatedExtensionInstall)) { | |
1015 return ExtensionState::BLOCKED; | |
1016 } | |
1017 | |
1018 auto extension_it = approved_extensions_map_.find(extension.id()); | |
1019 // If the installed version is approved, then the extension is allowed, | |
1020 // otherwise, it requires approval. | |
1021 if (extension_it != approved_extensions_map_.end() && | |
1022 extension_it->second == *extension.version()) { | |
1023 return ExtensionState::ALLOWED; | |
1024 } | |
1025 return ExtensionState::REQUIRE_APPROVAL; | |
956 } | 1026 } |
957 | 1027 |
958 std::string SupervisedUserService::GetDebugPolicyProviderName() const { | 1028 std::string SupervisedUserService::GetDebugPolicyProviderName() const { |
959 // Save the string space in official builds. | 1029 // Save the string space in official builds. |
960 #ifdef NDEBUG | 1030 #ifdef NDEBUG |
961 NOTREACHED(); | 1031 NOTREACHED(); |
962 return std::string(); | 1032 return std::string(); |
963 #else | 1033 #else |
964 return "Supervised User Service"; | 1034 return "Supervised User Service"; |
965 #endif | 1035 #endif |
966 } | 1036 } |
967 | 1037 |
968 bool SupervisedUserService::UserMayLoad(const extensions::Extension* extension, | 1038 bool SupervisedUserService::UserMayLoad(const Extension* extension, |
969 base::string16* error) const { | 1039 base::string16* error) const { |
970 DCHECK(ProfileIsSupervised()); | 1040 DCHECK(ProfileIsSupervised()); |
971 ExtensionState result = GetExtensionState(extension); | 1041 ExtensionState result = GetExtensionState(*extension); |
972 bool may_load = (result != EXTENSION_BLOCKED); | 1042 bool may_load = result != ExtensionState::BLOCKED; |
973 if (!may_load && error) | 1043 if (!may_load && error) |
974 *error = GetExtensionsLockedMessage(); | 1044 *error = GetExtensionsLockedMessage(); |
975 return may_load; | 1045 return may_load; |
976 } | 1046 } |
977 | 1047 |
978 bool SupervisedUserService::UserMayModifySettings( | 1048 bool SupervisedUserService::UserMayModifySettings(const Extension* extension, |
979 const extensions::Extension* extension, | 1049 base::string16* error) const { |
980 base::string16* error) const { | |
981 DCHECK(ProfileIsSupervised()); | 1050 DCHECK(ProfileIsSupervised()); |
982 ExtensionState result = GetExtensionState(extension); | 1051 ExtensionState result = GetExtensionState(*extension); |
983 bool may_modify = (result == EXTENSION_ALLOWED); | 1052 // While the following check allows the supervised user to modify the settings |
1053 // and enable or disable the extension, MustRemainDisabled properly takes care | |
1054 // of keeping an extension disabled when required. | |
1055 // For custodian-installed extensions, the state is always FORCED, even if | |
1056 // it's waiting for an update approval. | |
1057 bool may_modify = result != ExtensionState::FORCED; | |
984 if (!may_modify && error) | 1058 if (!may_modify && error) |
985 *error = GetExtensionsLockedMessage(); | 1059 *error = GetExtensionsLockedMessage(); |
986 return may_modify; | 1060 return may_modify; |
987 } | 1061 } |
988 | 1062 |
989 // Note: Having MustRemainInstalled always say "true" for custodian-installed | 1063 // Note: Having MustRemainInstalled always say "true" for custodian-installed |
990 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but | 1064 // extensions does NOT prevent remote uninstalls (which is a bit unexpected, but |
991 // exactly what we want). | 1065 // exactly what we want). |
992 bool SupervisedUserService::MustRemainInstalled( | 1066 bool SupervisedUserService::MustRemainInstalled(const Extension* extension, |
993 const extensions::Extension* extension, | 1067 base::string16* error) const { |
994 base::string16* error) const { | |
995 DCHECK(ProfileIsSupervised()); | 1068 DCHECK(ProfileIsSupervised()); |
996 ExtensionState result = GetExtensionState(extension); | 1069 ExtensionState result = GetExtensionState(*extension); |
997 bool may_not_uninstall = (result == EXTENSION_FORCED); | 1070 bool may_not_uninstall = result == ExtensionState::FORCED; |
998 if (may_not_uninstall && error) | 1071 if (may_not_uninstall && error) |
999 *error = GetExtensionsLockedMessage(); | 1072 *error = GetExtensionsLockedMessage(); |
1000 return may_not_uninstall; | 1073 return may_not_uninstall; |
1001 } | 1074 } |
1002 | 1075 |
1076 bool SupervisedUserService::MustRemainDisabled(const Extension* extension, | |
1077 Extension::DisableReason* reason, | |
1078 base::string16* error) const { | |
1079 DCHECK(ProfileIsSupervised()); | |
1080 ExtensionState state = GetExtensionState(*extension); | |
1081 // Only extensions that requires approval should be disabled. | |
Marc Treib
2016/06/27 14:32:59
s/requires/require
mamir
2016/06/27 14:58:13
Done.
| |
1082 // Blocked extensions should be loaded all together, and are taken care of | |
Marc Treib
2016/06/27 14:32:59
should NOT be loaded AT ALL
mamir
2016/06/27 14:58:13
Done.
Marc Treib
2016/06/27 15:05:46
I didn't mean you should write in all caps, just h
| |
1083 // at "UserMayLoad". | |
Marc Treib
2016/06/27 14:32:59
nit: no quotes
mamir
2016/06/27 14:58:13
Done.
| |
1084 bool must_remain_disabled = state == ExtensionState::REQUIRE_APPROVAL; | |
1085 | |
1086 if (must_remain_disabled) { | |
1087 if (error) | |
1088 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER); | |
1089 // If the extension must remain disabled due to permission increase, | |
1090 // then the update request has been already sent at update time. | |
1091 // We do nothing and we don't add an extra disable reason. | |
1092 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); | |
1093 if (extension_prefs->HasDisableReason( | |
1094 extension->id(), Extension::DISABLE_PERMISSIONS_INCREASE)) { | |
1095 if (reason) | |
1096 *reason = Extension::DISABLE_PERMISSIONS_INCREASE; | |
1097 return true; | |
1098 } | |
1099 if (reason) | |
1100 *reason = Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED; | |
1101 if (base::FeatureList::IsEnabled( | |
1102 supervised_users::kSupervisedUserInitiatedExtensionInstall)) { | |
1103 // If the Extension isn't pending a custodian approval already, send | |
1104 // an approval request. | |
1105 if (!extension_prefs->HasDisableReason( | |
1106 extension->id(), | |
1107 Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED)) { | |
1108 // MustRemainDisabled is a const method and hence cannot call | |
1109 // AddExtensionInstallRequest directly. | |
1110 SupervisedUserService* supervised_user_service = | |
1111 SupervisedUserServiceFactory::GetForProfile(profile_); | |
1112 supervised_user_service->AddExtensionInstallRequest( | |
1113 extension->id(), *extension->version()); | |
1114 } | |
1115 } | |
1116 } | |
1117 return must_remain_disabled; | |
1118 } | |
1119 | |
1120 void SupervisedUserService::OnExtensionInstalled( | |
1121 content::BrowserContext* browser_context, | |
1122 const extensions::Extension* extension, | |
1123 bool is_update) { | |
1124 // This callback method is responsible for updating extension state and | |
1125 // approved_extensions_map_ upon extension updates. | |
1126 if (!is_update) | |
1127 return; | |
1128 | |
1129 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); | |
1130 const std::string& id = extension->id(); | |
1131 const base::Version& version = *extension->version(); | |
1132 | |
1133 // If an already approved extension is updated without requiring | |
1134 // new permissions, we update the approved_version. | |
1135 if (!extension_prefs->HasDisableReason( | |
1136 id, Extension::DISABLE_PERMISSIONS_INCREASE) && | |
1137 approved_extensions_map_.count(id) > 0 && | |
1138 approved_extensions_map_[id] < version) { | |
1139 approved_extensions_map_[id] = version; | |
1140 | |
1141 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey( | |
1142 supervised_users::kApprovedExtensions, id); | |
1143 std::unique_ptr<base::Value> version_value( | |
1144 new base::StringValue(version.GetString())); | |
1145 GetSettingsService()->UpdateSetting(key, std::move(version_value)); | |
1146 } | |
1147 // Upon extension update, the approved version may (or may not) match the | |
1148 // installed one. Therefore, a change in extension state might be required. | |
1149 ChangeExtensionStateIfNecessary(id); | |
1150 } | |
1151 | |
1152 void SupervisedUserService::UpdateApprovedExtensions() { | |
1153 const base::DictionaryValue* dict = profile_->GetPrefs()->GetDictionary( | |
1154 prefs::kSupervisedUserApprovedExtensions); | |
1155 // Keep track of currently approved extensions. We may need to disable them if | |
1156 // they are not in the approved map anymore. | |
1157 std::set<std::string> extensions_to_be_checked; | |
1158 for (const auto& extension : approved_extensions_map_) | |
1159 extensions_to_be_checked.insert(extension.first); | |
1160 | |
1161 approved_extensions_map_.clear(); | |
1162 | |
1163 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | |
1164 std::string version_str; | |
1165 bool result = it.value().GetAsString(&version_str); | |
1166 DCHECK(result); | |
1167 base::Version version(version_str); | |
1168 if (version.IsValid()) { | |
1169 approved_extensions_map_[it.key()] = version; | |
1170 extensions_to_be_checked.insert(it.key()); | |
1171 } else { | |
1172 LOG(WARNING) << "Invalid version number " << version_str; | |
1173 } | |
1174 } | |
1175 | |
1176 for (const auto& extension_id : extensions_to_be_checked) { | |
1177 ChangeExtensionStateIfNecessary(extension_id); | |
1178 } | |
1179 } | |
1180 | |
1181 void SupervisedUserService::ChangeExtensionStateIfNecessary( | |
1182 const std::string& extension_id) { | |
1183 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | |
1184 const Extension* extension = registry->GetInstalledExtension(extension_id); | |
1185 // If the extension is not installed (yet), do nothing. | |
1186 // Things will be handled after installation. | |
1187 if (!extension) | |
1188 return; | |
1189 | |
1190 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); | |
1191 ExtensionService* service = | |
1192 ExtensionSystem::Get(profile_)->extension_service(); | |
1193 | |
1194 ExtensionState state = GetExtensionState(*extension); | |
1195 switch (state) { | |
1196 // BLOCKED/FORCED extensions should be already disabled/enabled | |
1197 // and we don't need to change their state here. | |
1198 case ExtensionState::BLOCKED: | |
1199 case ExtensionState::FORCED: | |
1200 break; | |
1201 case ExtensionState::REQUIRE_APPROVAL: | |
1202 service->DisableExtension(extension_id, | |
1203 Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED); | |
1204 break; | |
1205 case ExtensionState::ALLOWED: | |
1206 extension_prefs->RemoveDisableReason( | |
1207 extension_id, Extension::DISABLE_CUSTODIAN_APPROVAL_REQUIRED); | |
1208 extension_prefs->RemoveDisableReason( | |
1209 extension_id, Extension::DISABLE_PERMISSIONS_INCREASE); | |
1210 // If not disabled for other reasons, enable it. | |
1211 if (extension_prefs->GetDisableReasons(extension_id) == | |
1212 Extension::DISABLE_NONE) { | |
1213 service->EnableExtension(extension_id); | |
1214 } | |
1215 break; | |
1216 } | |
1217 } | |
1218 | |
1003 void SupervisedUserService::SetExtensionsActive() { | 1219 void SupervisedUserService::SetExtensionsActive() { |
1004 extensions::ExtensionSystem* extension_system = | 1220 extensions::ExtensionSystem* extension_system = |
1005 extensions::ExtensionSystem::Get(profile_); | 1221 extensions::ExtensionSystem::Get(profile_); |
1006 extensions::ManagementPolicy* management_policy = | 1222 extensions::ManagementPolicy* management_policy = |
1007 extension_system->management_policy(); | 1223 extension_system->management_policy(); |
1008 | 1224 |
1009 if (management_policy) { | 1225 if (management_policy) { |
1010 if (active_) | 1226 if (active_) |
1011 management_policy->RegisterProvider(this); | 1227 management_policy->RegisterProvider(this); |
1012 else | 1228 else |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1058 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 1274 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
1059 | 1275 |
1060 is_profile_active_ = profile_became_active; | 1276 is_profile_active_ = profile_became_active; |
1061 } | 1277 } |
1062 #endif // !defined(OS_ANDROID) | 1278 #endif // !defined(OS_ANDROID) |
1063 | 1279 |
1064 void SupervisedUserService::OnSiteListUpdated() { | 1280 void SupervisedUserService::OnSiteListUpdated() { |
1065 FOR_EACH_OBSERVER( | 1281 FOR_EACH_OBSERVER( |
1066 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 1282 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
1067 } | 1283 } |
OLD | NEW |