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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
102 bool ManagedUserService::IsElevated() const { | 103 bool ManagedUserService::IsElevated() const { |
103 return is_elevated_; | 104 return is_elevated_; |
104 } | 105 } |
105 | 106 |
107 bool ManagedUserService::IsElevatedForWebContents( | |
108 const content::WebContents* web_contents) const { | |
109 const ManagedModeNavigationObserver* observer = | |
110 ManagedModeNavigationObserver::FromWebContents(web_contents); | |
111 return observer->is_elevated(); | |
112 } | |
113 | |
114 bool ManagedUserService::IsPassphraseEmpty() const { | |
115 PrefService* pref_service = profile_->GetPrefs(); | |
116 return pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty(); | |
117 } | |
118 | |
119 // TODO(akuegel): This should be deprecated. | |
Bernhard Bauer
2013/03/20 15:08:30
Why don't you just go ahead and mark it as depreca
Adrian Kuegel
2013/03/20 15:51:16
Done.
Bernhard Bauer
2013/03/20 15:57:17
Ideally, add "Use Foo() instead".
| |
106 bool ManagedUserService::CanSkipPassphraseDialog() { | 120 bool ManagedUserService::CanSkipPassphraseDialog() { |
107 // If the profile is already elevated or there is no passphrase set, no | 121 // If the profile is already elevated or there is no passphrase set, no |
108 // authentication is needed. | 122 // authentication is needed. |
109 PrefService* pref_service = profile_->GetPrefs(); | 123 return IsElevated() || IsPassphraseEmpty(); |
124 } | |
125 | |
126 bool ManagedUserService::CanSkipPassphraseDialog( | |
127 const content::WebContents* web_contents) const { | |
110 return IsElevated() || | 128 return IsElevated() || |
111 pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty(); | 129 IsElevatedForWebContents(web_contents) || |
130 IsPassphraseEmpty(); | |
112 } | 131 } |
113 | 132 |
114 void ManagedUserService::RequestAuthorization( | 133 void ManagedUserService::RequestAuthorization( |
115 content::WebContents* web_contents, | 134 content::WebContents* web_contents, |
116 const PassphraseCheckedCallback& callback) { | 135 const PassphraseCheckedCallback& callback) { |
117 if (CanSkipPassphraseDialog()) { | 136 if (CanSkipPassphraseDialog(web_contents)) { |
118 callback.Run(true); | 137 callback.Run(true); |
119 return; | 138 return; |
120 } | 139 } |
121 | 140 |
122 // Is deleted automatically when the dialog is closed. | 141 // Is deleted automatically when the dialog is closed. |
123 new ManagedUserPassphraseDialog(web_contents, callback); | 142 new ManagedUserPassphraseDialog(web_contents, callback); |
124 } | 143 } |
125 | 144 |
126 void ManagedUserService::RequestAuthorizationUsingActiveWebContents( | 145 void ManagedUserService::RequestAuthorizationUsingActiveWebContents( |
127 Browser* browser, | 146 Browser* browser, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 } | 389 } |
371 } | 390 } |
372 | 391 |
373 UpdateManualURLs(); | 392 UpdateManualURLs(); |
374 } | 393 } |
375 | 394 |
376 void ManagedUserService::SetElevated(bool is_elevated) { | 395 void ManagedUserService::SetElevated(bool is_elevated) { |
377 is_elevated_ = is_elevated; | 396 is_elevated_ = is_elevated; |
378 } | 397 } |
379 | 398 |
399 void ManagedUserService::SetElevatedForWebContents( | |
Bernhard Bauer
2013/03/20 15:08:30
I'm not convinced that adding this method is very
Adrian Kuegel
2013/03/20 15:51:16
True, that would work, too. The only (very) small
| |
400 bool is_elevated, | |
401 content::WebContents* web_contents) { | |
402 ManagedModeNavigationObserver::FromWebContents(web_contents)->SetElevated( | |
403 is_elevated); | |
404 } | |
405 | |
380 void ManagedUserService::AddElevationForExtension( | 406 void ManagedUserService::AddElevationForExtension( |
381 const std::string& extension_id) { | 407 const std::string& extension_id) { |
382 elevated_for_extensions_.insert(extension_id); | 408 elevated_for_extensions_.insert(extension_id); |
383 } | 409 } |
384 | 410 |
385 void ManagedUserService::RemoveElevationForExtension( | 411 void ManagedUserService::RemoveElevationForExtension( |
386 const std::string& extension_id) { | 412 const std::string& extension_id) { |
387 elevated_for_extensions_.erase(extension_id); | 413 elevated_for_extensions_.erase(extension_id); |
388 } | 414 } |
389 | 415 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 467 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
442 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 468 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
443 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 469 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
444 bool allow = false; | 470 bool allow = false; |
445 bool result = it.value().GetAsBoolean(&allow); | 471 bool result = it.value().GetAsBoolean(&allow); |
446 DCHECK(result); | 472 DCHECK(result); |
447 (*url_map)[GURL(it.key())] = allow; | 473 (*url_map)[GURL(it.key())] = allow; |
448 } | 474 } |
449 url_filter_context_.SetManualURLs(url_map.Pass()); | 475 url_filter_context_.SetManualURLs(url_map.Pass()); |
450 } | 476 } |
OLD | NEW |