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 |
106 bool ManagedUserService::CanSkipPassphraseDialog() { | 119 bool ManagedUserService::CanSkipPassphraseDialog() { |
107 // If the profile is already elevated or there is no passphrase set, no | 120 // If the profile is already elevated or there is no passphrase set, no |
108 // authentication is needed. | 121 // authentication is needed. |
109 PrefService* pref_service = profile_->GetPrefs(); | 122 return IsElevated() || IsPassphraseEmpty(); |
| 123 } |
| 124 |
| 125 bool ManagedUserService::CanSkipPassphraseDialog( |
| 126 const content::WebContents* web_contents) const { |
110 return IsElevated() || | 127 return IsElevated() || |
111 pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty(); | 128 IsElevatedForWebContents(web_contents) || |
| 129 IsPassphraseEmpty(); |
112 } | 130 } |
113 | 131 |
114 void ManagedUserService::RequestAuthorization( | 132 void ManagedUserService::RequestAuthorization( |
115 content::WebContents* web_contents, | 133 content::WebContents* web_contents, |
116 const PassphraseCheckedCallback& callback) { | 134 const PassphraseCheckedCallback& callback) { |
117 if (CanSkipPassphraseDialog()) { | 135 if (CanSkipPassphraseDialog(web_contents)) { |
118 callback.Run(true); | 136 callback.Run(true); |
119 return; | 137 return; |
120 } | 138 } |
121 | 139 |
122 // Is deleted automatically when the dialog is closed. | 140 // Is deleted automatically when the dialog is closed. |
123 new ManagedUserPassphraseDialog(web_contents, callback); | 141 new ManagedUserPassphraseDialog(web_contents, callback); |
124 } | 142 } |
125 | 143 |
126 void ManagedUserService::RequestAuthorizationUsingActiveWebContents( | 144 void ManagedUserService::RequestAuthorizationUsingActiveWebContents( |
127 Browser* browser, | 145 Browser* browser, |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 dict->RemoveWithoutPathExpansion(url.spec(), NULL); | 384 dict->RemoveWithoutPathExpansion(url.spec(), NULL); |
367 } else { | 385 } else { |
368 dict->SetBooleanWithoutPathExpansion(url.spec(), | 386 dict->SetBooleanWithoutPathExpansion(url.spec(), |
369 behavior == MANUAL_ALLOW); | 387 behavior == MANUAL_ALLOW); |
370 } | 388 } |
371 } | 389 } |
372 | 390 |
373 UpdateManualURLs(); | 391 UpdateManualURLs(); |
374 } | 392 } |
375 | 393 |
| 394 // TODO(akuegel): Rename to SetElevatedForTesting when all callers are changed |
| 395 // to set elevation on the ManagedModeNavigationObserver. |
376 void ManagedUserService::SetElevated(bool is_elevated) { | 396 void ManagedUserService::SetElevated(bool is_elevated) { |
377 is_elevated_ = is_elevated; | 397 is_elevated_ = is_elevated; |
378 } | 398 } |
379 | 399 |
380 void ManagedUserService::AddElevationForExtension( | 400 void ManagedUserService::AddElevationForExtension( |
381 const std::string& extension_id) { | 401 const std::string& extension_id) { |
382 elevated_for_extensions_.insert(extension_id); | 402 elevated_for_extensions_.insert(extension_id); |
383 } | 403 } |
384 | 404 |
385 void ManagedUserService::RemoveElevationForExtension( | 405 void ManagedUserService::RemoveElevationForExtension( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 461 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
442 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 462 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
443 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 463 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
444 bool allow = false; | 464 bool allow = false; |
445 bool result = it.value().GetAsBoolean(&allow); | 465 bool result = it.value().GetAsBoolean(&allow); |
446 DCHECK(result); | 466 DCHECK(result); |
447 (*url_map)[GURL(it.key())] = allow; | 467 (*url_map)[GURL(it.key())] = allow; |
448 } | 468 } |
449 url_filter_context_.SetManualURLs(url_map.Pass()); | 469 url_filter_context_.SetManualURLs(url_map.Pass()); |
450 } | 470 } |
OLD | NEW |