Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: chrome/browser/managed_mode/managed_user_service.cc

Issue 12413028: Add elevation to the managed mode navigation observer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/managed_mode/managed_user_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 dict->RemoveWithoutPathExpansion(url.spec(), NULL); 385 dict->RemoveWithoutPathExpansion(url.spec(), NULL);
368 } else { 386 } else {
369 dict->SetBooleanWithoutPathExpansion(url.spec(), 387 dict->SetBooleanWithoutPathExpansion(url.spec(),
370 behavior == MANUAL_ALLOW); 388 behavior == MANUAL_ALLOW);
371 } 389 }
372 } 390 }
373 391
374 UpdateManualURLs(); 392 UpdateManualURLs();
375 } 393 }
376 394
395 // TODO(akuegel): Rename to SetElevatedForTesting when all callers are changed
396 // to set elevation on the ManagedModeNavigationObserver.
377 void ManagedUserService::SetElevated(bool is_elevated) { 397 void ManagedUserService::SetElevated(bool is_elevated) {
378 is_elevated_ = is_elevated; 398 is_elevated_ = is_elevated;
379 } 399 }
380 400
381 void ManagedUserService::AddElevationForExtension( 401 void ManagedUserService::AddElevationForExtension(
382 const std::string& extension_id) { 402 const std::string& extension_id) {
383 elevated_for_extensions_.insert(extension_id); 403 elevated_for_extensions_.insert(extension_id);
384 } 404 }
385 405
386 void ManagedUserService::RemoveElevationForExtension( 406 void ManagedUserService::RemoveElevationForExtension(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); 462 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs);
443 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); 463 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>());
444 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { 464 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
445 bool allow = false; 465 bool allow = false;
446 bool result = it.value().GetAsBoolean(&allow); 466 bool result = it.value().GetAsBoolean(&allow);
447 DCHECK(result); 467 DCHECK(result);
448 (*url_map)[GURL(it.key())] = allow; 468 (*url_map)[GURL(it.key())] = allow;
449 } 469 }
450 url_filter_context_.SetManualURLs(url_map.Pass()); 470 url_filter_context_.SetManualURLs(url_map.Pass());
451 } 471 }
OLDNEW
« no previous file with comments | « chrome/browser/managed_mode/managed_user_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698