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

Side by Side Diff: chrome/browser/ui/webui/options/managed_user_settings_handler.cc

Issue 13119011: Enable WebContents elevation for managed users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Put ScopedExtensionElevation in its own file. 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/options/managed_user_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/managed_user_settings_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/first_run/first_run.h" 14 #include "chrome/browser/first_run/first_run.h"
15 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/user_metrics.h" 19 #include "content/public/browser/user_metrics.h"
19 #include "content/public/browser/web_ui.h" 20 #include "content/public/browser/web_ui.h"
20 #include "grit/chromium_strings.h" 21 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
22 #include "grit/google_chrome_strings.h" 23 #include "grit/google_chrome_strings.h"
23 #include "grit/locale_settings.h" 24 #include "grit/locale_settings.h"
24 25
25 using content::UserMetricsAction; 26 using content::UserMetricsAction;
26 27
27 namespace options { 28 namespace options {
28 29
29 ManagedUserSettingsHandler::ManagedUserSettingsHandler() { 30 ManagedUserSettingsHandler::ManagedUserSettingsHandler() {
30 } 31 }
31 32
32 ManagedUserSettingsHandler::~ManagedUserSettingsHandler() { 33 ManagedUserSettingsHandler::~ManagedUserSettingsHandler() {
33 } 34 }
34 35
35 void ManagedUserSettingsHandler::InitializeHandler() { 36 void ManagedUserSettingsHandler::InitializeHandler() {
36 pref_change_registrar_.Init(Profile::FromWebUI(web_ui())->GetPrefs()); 37 pref_change_registrar_.Init(Profile::FromWebUI(web_ui())->GetPrefs());
37 pref_change_registrar_.Add( 38 pref_change_registrar_.Add(
38 prefs::kManagedModeLocalPassphrase, 39 prefs::kManagedModeLocalPassphrase,
39 base::Bind(&ManagedUserSettingsHandler::OnLocalPassphraseChanged, 40 base::Bind(&ManagedUserSettingsHandler::OnLocalPassphraseChanged,
40 base::Unretained(this))); 41 base::Unretained(this)));
41 } 42 }
42 43
43 void ManagedUserSettingsHandler::InitializePage() { 44 void ManagedUserSettingsHandler::InitializePage() {
44 if (CommandLine::ForCurrentProcess()->HasSwitch( 45 if (!CommandLine::ForCurrentProcess()->HasSwitch(
45 switches::kEnableManagedUsers)) { 46 switches::kEnableManagedUsers)) {
46 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 47 return;
47 base::FundamentalValue is_passphrase_set(!pref_service->GetString( 48 }
48 prefs::kManagedModeLocalPassphrase).empty()); 49 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
49 web_ui()->CallJavascriptFunction( 50 base::FundamentalValue is_passphrase_set(!pref_service->GetString(
50 "ManagedUserSettings.passphraseChanged", 51 prefs::kManagedModeLocalPassphrase).empty());
51 is_passphrase_set); 52 web_ui()->CallJavascriptFunction(
53 "ManagedUserSettings.passphraseChanged",
54 is_passphrase_set);
55 if ((first_run::IsChromeFirstRun() &&
56 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoFirstRun)) ||
57 CommandLine::ForCurrentProcess()->HasSwitch(
58 switches::kResetLocalPassphrase)) {
59 ManagedModeNavigationObserver::FromWebContents(
60 web_ui()->GetWebContents())->set_elevated(true);
52 } 61 }
53 } 62 }
54 63
55 void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) { 64 void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) {
56 start_time_ = base::TimeTicks::Now(); 65 start_time_ = base::TimeTicks::Now();
57 content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings")); 66 content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings"));
67 if (ManagedModeNavigationObserver::FromWebContents(
68 web_ui()->GetWebContents())->is_elevated()) {
69 web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated",
70 base::FundamentalValue(true));
71 }
58 } 72 }
59 73
60 void ManagedUserSettingsHandler::GetLocalizedValues( 74 void ManagedUserSettingsHandler::GetLocalizedValues(
61 base::DictionaryValue* localized_strings) { 75 base::DictionaryValue* localized_strings) {
62 DCHECK(localized_strings); 76 DCHECK(localized_strings);
63 77
64 static OptionsStringResource resources[] = { 78 static OptionsStringResource resources[] = {
65 // Unlock the settings page to allow editing. 79 // Unlock the settings page to allow editing.
66 { "unlockSettings", IDS_UNLOCK_PASSPHRASE_BUTTON }, 80 { "unlockSettings", IDS_UNLOCK_PASSPHRASE_BUTTON },
67 { "lockSettings", IDS_LOCK_MANAGED_USER_BUTTON }, 81 { "lockSettings", IDS_LOCK_MANAGED_USER_BUTTON },
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 130
117 void ManagedUserSettingsHandler::OnLocalPassphraseChanged() { 131 void ManagedUserSettingsHandler::OnLocalPassphraseChanged() {
118 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 132 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
119 base::FundamentalValue is_passphrase_set(!pref_service->GetString( 133 base::FundamentalValue is_passphrase_set(!pref_service->GetString(
120 prefs::kManagedModeLocalPassphrase).empty()); 134 prefs::kManagedModeLocalPassphrase).empty());
121 web_ui()->CallJavascriptFunction("ManagedUserSettings.passphraseChanged", 135 web_ui()->CallJavascriptFunction("ManagedUserSettings.passphraseChanged",
122 is_passphrase_set); 136 is_passphrase_set);
123 } 137 }
124 138
125 } // namespace options 139 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698