OLD | NEW |
---|---|
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 |
(...skipping 10 matching lines...) Expand all Loading... | |
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)) { |
Bernhard Bauer
2013/03/27 15:48:14
Could you do some cleanup here and early-return if
Adrian Kuegel
2013/03/27 16:17:43
Done.
| |
46 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 47 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
47 base::FundamentalValue is_passphrase_set(!pref_service->GetString( | 48 base::FundamentalValue is_passphrase_set(!pref_service->GetString( |
48 prefs::kManagedModeLocalPassphrase).empty()); | 49 prefs::kManagedModeLocalPassphrase).empty()); |
49 web_ui()->CallJavascriptFunction( | 50 web_ui()->CallJavascriptFunction( |
50 "ManagedUserSettings.passphraseChanged", | 51 "ManagedUserSettings.passphraseChanged", |
51 is_passphrase_set); | 52 is_passphrase_set); |
53 if ((first_run::IsChromeFirstRun() && | |
54 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoFirstRun)) || | |
55 CommandLine::ForCurrentProcess()->HasSwitch( | |
56 switches::kResetLocalPassphrase)) { | |
57 ManagedModeNavigationObserver::FromWebContents( | |
58 web_ui()->GetWebContents())->set_elevated(true); | |
59 } | |
52 } | 60 } |
53 } | 61 } |
54 | 62 |
55 void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) { | 63 void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) { |
56 start_time_ = base::TimeTicks::Now(); | 64 start_time_ = base::TimeTicks::Now(); |
57 content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings")); | 65 content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings")); |
66 if (ManagedModeNavigationObserver::FromWebContents( | |
67 web_ui()->GetWebContents())->is_elevated()) { | |
68 web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated", | |
69 base::FundamentalValue(true)); | |
70 } | |
58 } | 71 } |
59 | 72 |
60 void ManagedUserSettingsHandler::GetLocalizedValues( | 73 void ManagedUserSettingsHandler::GetLocalizedValues( |
61 base::DictionaryValue* localized_strings) { | 74 base::DictionaryValue* localized_strings) { |
62 DCHECK(localized_strings); | 75 DCHECK(localized_strings); |
63 | 76 |
64 static OptionsStringResource resources[] = { | 77 static OptionsStringResource resources[] = { |
65 // Unlock the settings page to allow editing. | 78 // Unlock the settings page to allow editing. |
66 { "unlockSettings", IDS_UNLOCK_PASSPHRASE_BUTTON }, | 79 { "unlockSettings", IDS_UNLOCK_PASSPHRASE_BUTTON }, |
67 { "lockSettings", IDS_LOCK_MANAGED_USER_BUTTON }, | 80 { "lockSettings", IDS_LOCK_MANAGED_USER_BUTTON }, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 | 129 |
117 void ManagedUserSettingsHandler::OnLocalPassphraseChanged() { | 130 void ManagedUserSettingsHandler::OnLocalPassphraseChanged() { |
118 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 131 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
119 base::FundamentalValue is_passphrase_set(!pref_service->GetString( | 132 base::FundamentalValue is_passphrase_set(!pref_service->GetString( |
120 prefs::kManagedModeLocalPassphrase).empty()); | 133 prefs::kManagedModeLocalPassphrase).empty()); |
121 web_ui()->CallJavascriptFunction("ManagedUserSettings.passphraseChanged", | 134 web_ui()->CallJavascriptFunction("ManagedUserSettings.passphraseChanged", |
122 is_passphrase_set); | 135 is_passphrase_set); |
123 } | 136 } |
124 | 137 |
125 } // namespace options | 138 } // namespace options |
OLD | NEW |