OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/managed_mode/managed_user_service.h" | 5 #include "chrome/browser/managed_mode/managed_user_service.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" | |
12 #include "chrome/browser/managed_mode/managed_mode_site_list.h" | 13 #include "chrome/browser/managed_mode/managed_mode_site_list.h" |
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/extensions/extension_set.h" | 19 #include "chrome/common/extensions/extension_set.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 is_elevated_(false) { | 93 is_elevated_(false) { |
93 } | 94 } |
94 | 95 |
95 ManagedUserService::~ManagedUserService() { | 96 ManagedUserService::~ManagedUserService() { |
96 } | 97 } |
97 | 98 |
98 bool ManagedUserService::ProfileIsManaged() const { | 99 bool ManagedUserService::ProfileIsManaged() const { |
99 return profile_->GetPrefs()->GetBoolean(prefs::kProfileIsManaged); | 100 return profile_->GetPrefs()->GetBoolean(prefs::kProfileIsManaged); |
100 } | 101 } |
101 | 102 |
103 // Deprecated. Use IsElevatedForWebContents() instead. | |
Bernhard Bauer
2013/03/20 17:28:00
In the header please, that way people are more lik
Adrian Kuegel
2013/03/21 09:40:52
Done.
| |
102 bool ManagedUserService::IsElevated() const { | 104 bool ManagedUserService::IsElevated() const { |
103 return is_elevated_; | 105 return is_elevated_; |
104 } | 106 } |
105 | 107 |
108 bool ManagedUserService::IsElevatedForWebContents( | |
109 const content::WebContents* web_contents) const { | |
110 const ManagedModeNavigationObserver* observer = | |
111 ManagedModeNavigationObserver::FromWebContents(web_contents); | |
112 return observer->is_elevated(); | |
113 } | |
114 | |
115 bool ManagedUserService::IsPassphraseEmpty() const { | |
116 PrefService* pref_service = profile_->GetPrefs(); | |
117 return pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty(); | |
118 } | |
119 | |
120 // Deprecated. Use the CanSkipPassphraseDialog() method which requires a | |
121 // WebContents parameter instead. | |
106 bool ManagedUserService::CanSkipPassphraseDialog() { | 122 bool ManagedUserService::CanSkipPassphraseDialog() { |
107 // If the profile is already elevated or there is no passphrase set, no | 123 // If the profile is already elevated or there is no passphrase set, no |
108 // authentication is needed. | 124 // authentication is needed. |
109 PrefService* pref_service = profile_->GetPrefs(); | 125 return IsElevated() || IsPassphraseEmpty(); |
126 } | |
127 | |
128 bool ManagedUserService::CanSkipPassphraseDialog( | |
129 const content::WebContents* web_contents) const { | |
110 return IsElevated() || | 130 return IsElevated() || |
111 pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty(); | 131 IsElevatedForWebContents(web_contents) || |
132 IsPassphraseEmpty(); | |
112 } | 133 } |
113 | 134 |
114 void ManagedUserService::RequestAuthorization( | 135 void ManagedUserService::RequestAuthorization( |
115 content::WebContents* web_contents, | 136 content::WebContents* web_contents, |
116 const PassphraseCheckedCallback& callback) { | 137 const PassphraseCheckedCallback& callback) { |
117 if (CanSkipPassphraseDialog()) { | 138 if (CanSkipPassphraseDialog(web_contents)) { |
118 callback.Run(true); | 139 callback.Run(true); |
119 return; | 140 return; |
120 } | 141 } |
121 | 142 |
122 // Is deleted automatically when the dialog is closed. | 143 // Is deleted automatically when the dialog is closed. |
123 new ManagedUserPassphraseDialog(web_contents, callback); | 144 new ManagedUserPassphraseDialog(web_contents, callback); |
124 } | 145 } |
125 | 146 |
126 void ManagedUserService::RequestAuthorizationUsingActiveWebContents( | 147 void ManagedUserService::RequestAuthorizationUsingActiveWebContents( |
127 Browser* browser, | 148 Browser* browser, |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 dict->RemoveWithoutPathExpansion(url.spec(), NULL); | 387 dict->RemoveWithoutPathExpansion(url.spec(), NULL); |
367 } else { | 388 } else { |
368 dict->SetBooleanWithoutPathExpansion(url.spec(), | 389 dict->SetBooleanWithoutPathExpansion(url.spec(), |
369 behavior == MANUAL_ALLOW); | 390 behavior == MANUAL_ALLOW); |
370 } | 391 } |
371 } | 392 } |
372 | 393 |
373 UpdateManualURLs(); | 394 UpdateManualURLs(); |
374 } | 395 } |
375 | 396 |
397 // TODO(akuegel): Rename to SetElevatedForTesting when all callers are changed | |
398 // to set elevation on the ManagedModeNavigationObserver. | |
376 void ManagedUserService::SetElevated(bool is_elevated) { | 399 void ManagedUserService::SetElevated(bool is_elevated) { |
377 is_elevated_ = is_elevated; | 400 is_elevated_ = is_elevated; |
378 } | 401 } |
379 | 402 |
380 void ManagedUserService::AddElevationForExtension( | 403 void ManagedUserService::AddElevationForExtension( |
381 const std::string& extension_id) { | 404 const std::string& extension_id) { |
382 elevated_for_extensions_.insert(extension_id); | 405 elevated_for_extensions_.insert(extension_id); |
383 } | 406 } |
384 | 407 |
385 void ManagedUserService::RemoveElevationForExtension( | 408 void ManagedUserService::RemoveElevationForExtension( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 464 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
442 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 465 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
443 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 466 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
444 bool allow = false; | 467 bool allow = false; |
445 bool result = it.value().GetAsBoolean(&allow); | 468 bool result = it.value().GetAsBoolean(&allow); |
446 DCHECK(result); | 469 DCHECK(result); |
447 (*url_map)[GURL(it.key())] = allow; | 470 (*url_map)[GURL(it.key())] = allow; |
448 } | 471 } |
449 url_filter_context_.SetManualURLs(url_map.Pass()); | 472 url_filter_context_.SetManualURLs(url_map.Pass()); |
450 } | 473 } |
OLD | NEW |