OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/chromeos/login/enable_debugging_screen_handler .h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/metrics/histogram.h" | |
xiyuan
2014/10/30 03:52:09
nit: seems not used.
zel
2014/10/31 01:22:26
Done.
| |
11 #include "base/prefs/pref_registry_simple.h" | |
12 #include "base/prefs/pref_service.h" | |
13 #include "base/values.h" | |
14 #include "chrome/browser/browser_process.h" | |
15 #include "chrome/browser/chromeos/login/help_app_launcher.h" | |
16 #include "chrome/browser/chromeos/reset/metrics.h" | |
xiyuan
2014/10/30 03:52:09
nit: seems not needed.
zel
2014/10/31 01:22:26
Done.
| |
17 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | |
18 #include "chrome/common/pref_names.h" | |
19 #include "chrome/grit/chromium_strings.h" | |
20 #include "chrome/grit/generated_resources.h" | |
21 #include "chromeos/chromeos_switches.h" | |
22 #include "chromeos/dbus/dbus_thread_manager.h" | |
23 #include "chromeos/dbus/debug_daemon_client.h" | |
24 #include "chromeos/dbus/power_manager_client.h" | |
25 #include "chromeos/dbus/session_manager_client.h" | |
xiyuan
2014/10/30 03:52:09
nit: seems not used
zel
2014/10/31 01:22:26
Done.
| |
26 #include "content/public/browser/browser_thread.h" | |
xiyuan
2014/10/30 03:52:08
nit: seems not used.
zel
2014/10/31 01:22:26
Done.
| |
27 | |
28 namespace { | |
29 | |
30 const char kJsScreenPath[] = "login.EnableDebuggingScreen"; | |
31 | |
32 // Reset screen id. | |
xiyuan
2014/10/30 03:52:08
nit: update comment or just get rid of it.
zel
2014/10/31 01:22:26
Done.
| |
33 const char kEnableDebuggingScreen[] = "debugging"; | |
34 | |
35 } // namespace | |
36 | |
37 namespace chromeos { | |
38 | |
39 EnableDebuggingScreenHandler::EnableDebuggingScreenHandler() | |
40 : BaseScreenHandler(kJsScreenPath), | |
41 delegate_(NULL), | |
42 show_on_init_(false), | |
43 ready_for_setup_(false), | |
44 weak_ptr_factory_(this) { | |
45 } | |
46 | |
47 EnableDebuggingScreenHandler::~EnableDebuggingScreenHandler() { | |
48 if (delegate_) | |
49 delegate_->OnActorDestroyed(this); | |
50 } | |
51 | |
52 void EnableDebuggingScreenHandler::PrepareToShow() { | |
53 } | |
54 | |
55 void EnableDebuggingScreenHandler::ShowWithParams() { | |
56 PrefService* prefs = g_browser_process->local_state(); | |
57 prefs->SetBoolean(prefs::kDebuggingFeaturesRequested, false); | |
xiyuan
2014/10/30 03:52:08
nit: how about call ClearPref()?
zel
2014/10/31 01:22:26
Done.
| |
58 prefs->CommitPendingWrite(); | |
59 base::DictionaryValue debugging_screen_params; | |
60 debugging_screen_params.SetBoolean("needsRootfsRemoval", | |
61 !ready_for_setup_); | |
62 #if defined(OFFICIAL_BUILD) | |
63 debugging_screen_params.SetBoolean("isOfficialBuild", true); | |
64 #endif | |
65 ShowScreen(kEnableDebuggingScreen, &debugging_screen_params); | |
66 } | |
67 | |
68 void EnableDebuggingScreenHandler::Show() { | |
69 if (!page_is_ready()) { | |
70 show_on_init_ = true; | |
71 return; | |
72 } | |
73 | |
74 ChooseAndApplyShowScenario(); | |
75 } | |
76 | |
77 void EnableDebuggingScreenHandler::ChooseAndApplyShowScenario() { | |
78 PrefService* prefs = g_browser_process->local_state(); | |
79 bool fresh_start = !CommandLine::ForCurrentProcess()->HasSwitch( | |
80 switches::kFirstExecAfterBoot); | |
81 | |
82 // TODO: Check if we have permission to show anything here. | |
83 if (fresh_start) { // First exec after boot. | |
84 ready_for_setup_ = prefs->GetBoolean(prefs::kDebuggingFeaturesRequested); | |
85 } | |
86 ShowWithParams(); | |
87 } | |
88 | |
89 void EnableDebuggingScreenHandler::Hide() { | |
90 } | |
91 | |
92 void EnableDebuggingScreenHandler::SetDelegate(Delegate* delegate) { | |
93 delegate_ = delegate; | |
94 if (page_is_ready()) | |
95 Initialize(); | |
96 } | |
97 | |
98 void EnableDebuggingScreenHandler::DeclareLocalizedValues( | |
99 LocalizedValuesBuilder* builder) { | |
100 builder->Add("enableDebuggingScreenTitle", | |
101 IDS_ENABLE_DEBUGGING_SCREEN_TITLE); | |
102 builder->Add("enableDebuggingScreenAccessibleTitle", | |
103 IDS_ENABLE_DEBUGGING_SCREEN_TITLE); | |
104 builder->Add("enableDebuggingScreenIconTitle", IDS_EXCLAMATION_ICON_TITLE); | |
105 builder->Add("enableDebuggingCancelButton", IDS_CANCEL); | |
106 builder->Add("enableDebuggingOKButton", IDS_OK); | |
107 builder->Add("enableDebuggingRemoveButton", | |
108 IDS_ENABLE_DEBUGGING_REMOVE_ROOTFS_BUTTON); | |
109 builder->Add("enableDebuggingEnableButton", | |
110 IDS_ENABLE_DEBUGGING_ENABLE_BUTTON); | |
111 builder->Add("enableDebuggingRemveRootfsMessage", | |
112 IDS_ENABLE_DEBUGGING_SCREEN_ROOTFS_REMOVE_MSG); | |
113 builder->Add("enableDebuggingSetupMessage", | |
114 IDS_ENABLE_DEBUGGING_SETUP_MESSAGE); | |
115 builder->Add("enableDebuggingWaitMessage", | |
116 IDS_ENABLE_DEBUGGING_WAIT_MESSAGE); | |
117 builder->AddF("enableDebuggingWarningTitle", | |
118 IDS_ENABLE_DEBUGGING_SCREEN_WARNING_MSG, | |
119 IDS_SHORT_PRODUCT_NAME); | |
120 builder->AddF("enableDebuggingDoneMessage", | |
121 IDS_ENABLE_DEBUGGING_DONE_MESSAGE, | |
122 IDS_SHORT_PRODUCT_NAME); | |
123 builder->Add("enableDebuggingPasswordLabel", | |
124 IDS_ENABLE_DEBUGGING_ROOT_PASSWORD_LABEL); | |
125 builder->Add("enableDebuggingConfirmPasswordLabel", | |
126 IDS_ENABLE_DEBUGGING_CONFIRM_PASSWORD_LABEL); | |
127 builder->Add("enableDebuggingPasswordLengthNote", | |
128 IDS_ENABLE_DEBUGGING_EMPTY_ROOT_PASSWORD_LABEL); | |
129 } | |
130 | |
131 // static | |
132 void EnableDebuggingScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { | |
133 registry->RegisterBooleanPref(prefs::kDebuggingFeaturesRequested, false); | |
134 } | |
135 | |
136 void EnableDebuggingScreenHandler::Initialize() { | |
137 if (!page_is_ready() || !delegate_) | |
138 return; | |
139 | |
140 if (show_on_init_) { | |
141 Show(); | |
142 show_on_init_ = false; | |
143 } | |
144 } | |
145 | |
146 void EnableDebuggingScreenHandler::RegisterMessages() { | |
147 AddCallback("enableDebuggingOnCancel", | |
148 &EnableDebuggingScreenHandler::HandleOnCancel); | |
149 AddCallback("enableDebuggingOnDone", | |
150 &EnableDebuggingScreenHandler::HandleOnDone); | |
151 AddCallback("enableDebuggingOnLearnMore", | |
152 &EnableDebuggingScreenHandler::HandleOnLearnMore); | |
153 AddCallback("enableDebuggingOnRemoveRootFSProtection", | |
154 &EnableDebuggingScreenHandler::HandleOnRemoveRootFSProtection); | |
155 AddCallback("enableDebuggingOnSetup", | |
156 &EnableDebuggingScreenHandler::HandleOnSetup); | |
157 } | |
158 | |
159 void EnableDebuggingScreenHandler::HandleOnCancel() { | |
160 if (delegate_) | |
161 delegate_->OnExit(false); | |
162 } | |
163 | |
164 void EnableDebuggingScreenHandler::HandleOnDone() { | |
165 if (delegate_) | |
166 delegate_->OnExit(true); | |
167 } | |
168 | |
169 void EnableDebuggingScreenHandler::HandleOnRemoveRootFSProtection() { | |
170 UpdateUIState(UI_STATE_WAIT); | |
171 chromeos::DebugDaemonClient* client = | |
172 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | |
173 client->RemoveRootfsVerification( | |
174 base::Bind(&EnableDebuggingScreenHandler::OnRemoveRootfsVerification, | |
175 weak_ptr_factory_.GetWeakPtr())); | |
176 } | |
177 | |
178 void EnableDebuggingScreenHandler::HandleOnSetup( | |
179 const std::string& password) { | |
180 UpdateUIState(UI_STATE_WAIT); | |
181 chromeos::DebugDaemonClient* client = | |
182 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | |
183 client->EnableDebuggingFeatures( | |
184 password, | |
185 base::Bind(&EnableDebuggingScreenHandler::OnEnableDebuggingFeatures, | |
186 weak_ptr_factory_.GetWeakPtr())); | |
187 } | |
188 | |
189 // Removes rootfs verification, add flag to start with enable debugging features | |
190 // screen and reboots the machine. | |
191 void EnableDebuggingScreenHandler::OnRemoveRootfsVerification(bool success) { | |
192 if (!success) { | |
193 UpdateUIState(UI_STATE_ERROR); | |
194 return; | |
195 } | |
196 | |
197 PrefService* prefs = g_browser_process->local_state(); | |
198 prefs->SetBoolean(prefs::kDebuggingFeaturesRequested, true); | |
199 prefs->CommitPendingWrite(); | |
200 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | |
201 } | |
202 | |
203 | |
204 void EnableDebuggingScreenHandler::OnEnableDebuggingFeatures(bool success) { | |
205 if (!success) { | |
206 UpdateUIState(UI_STATE_ERROR); | |
207 return; | |
208 } | |
209 | |
210 UpdateUIState(UI_STATE_DONE); | |
211 } | |
212 | |
213 void EnableDebuggingScreenHandler::UpdateUIState( | |
214 EnableDebuggingScreenHandler::UIState state) { | |
215 web_ui()->CallJavascriptFunction( | |
216 "login.EnableDebuggingScreen.updateState", | |
217 base::FundamentalValue(static_cast<int>(state))); | |
218 } | |
219 | |
220 void EnableDebuggingScreenHandler::HandleOnLearnMore() { | |
221 VLOG(1) << "Trying to view the help article about debugging features."; | |
222 if (!help_app_.get()) | |
223 help_app_ = new HelpAppLauncher(GetNativeWindow()); | |
224 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_ENABLE_DEBUGGING); | |
225 } | |
226 | |
227 } // namespace chromeos | |
OLD | NEW |