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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
12 #include "chrome/browser/chromeos/login/helper.h"
13 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
14 #include "chrome/browser/chromeos/login/wizard_controller.h"
15 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
16 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
17 #include "chrome/browser/chromeos/system/input_device_settings.h"
18 #include "chrome/browser/lifetime/application_lifetime.h"
19 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
20 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
21 #include "chrome/common/chrome_constants.h"
22 #include "chrome/common/chrome_version_info.h"
23 #include "chrome/grit/chromium_strings.h"
24 #include "chrome/grit/generated_resources.h"
25 #include "chromeos/chromeos_constants.h"
26 #include "grit/components_strings.h"
27 #include "ui/chromeos/accessibility_types.h"
28 #include "ui/gfx/display.h"
29 #include "ui/gfx/screen.h"
30 #include "ui/gfx/size.h"
31 #include "ui/keyboard/keyboard_controller.h"
33 #if !defined(USE_ATHENA)
34 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
39 const char kJsScreenPath[] = "cr.ui.Oobe";
41 // JS API callbacks names.
42 const char kJsApiEnableHighContrast[] = "enableHighContrast";
43 const char kJsApiEnableVirtualKeyboard[] = "enableVirtualKeyboard";
44 const char kJsApiEnableScreenMagnifier[] = "enableScreenMagnifier";
45 const char kJsApiEnableLargeCursor[] = "enableLargeCursor";
46 const char kJsApiEnableSpokenFeedback[] = "enableSpokenFeedback";
47 const char kJsApiScreenStateInitialize[] = "screenStateInitialize";
48 const char kJsApiSkipUpdateEnrollAfterEula[] = "skipUpdateEnrollAfterEula";
49 const char kJsApiScreenAssetsLoaded[] = "screenAssetsLoaded";
50 const char kJsApiHeaderBarVisible[] = "headerBarVisible";
56 // Note that show_oobe_ui_ defaults to false because WizardController assumes
57 // OOBE UI is not visible by default.
58 CoreOobeHandler::CoreOobeHandler(OobeUI* oobe_ui)
59 : BaseScreenHandler(kJsScreenPath),
62 version_info_updater_(this),
64 AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
65 CHECK(accessibility_manager);
66 accessibility_subscription_ = accessibility_manager->RegisterCallback(
67 base::Bind(&CoreOobeHandler::OnAccessibilityStatusChanged,
68 base::Unretained(this)));
71 CoreOobeHandler::~CoreOobeHandler() {
74 void CoreOobeHandler::SetDelegate(Delegate* delegate) {
78 void CoreOobeHandler::DeclareLocalizedValues(LocalizedValuesBuilder* builder) {
79 builder->Add("title", IDS_SHORT_PRODUCT_NAME);
80 builder->Add("productName", IDS_SHORT_PRODUCT_NAME);
81 builder->Add("learnMore", IDS_LEARN_MORE);
83 // OOBE accessibility options menu strings shown on each screen.
84 builder->Add("accessibilityLink", IDS_OOBE_ACCESSIBILITY_LINK);
85 builder->Add("spokenFeedbackOption", IDS_OOBE_SPOKEN_FEEDBACK_OPTION);
86 builder->Add("largeCursorOption", IDS_OOBE_LARGE_CURSOR_OPTION);
87 builder->Add("highContrastOption", IDS_OOBE_HIGH_CONTRAST_MODE_OPTION);
88 builder->Add("screenMagnifierOption", IDS_OOBE_SCREEN_MAGNIFIER_OPTION);
89 builder->Add("virtualKeyboardOption", IDS_OOBE_VIRTUAL_KEYBOARD_OPTION);
90 builder->Add("closeAccessibilityMenu", IDS_OOBE_CLOSE_ACCESSIBILITY_MENU);
92 // Strings for the device requisition prompt.
93 builder->Add("deviceRequisitionPromptCancel",
94 IDS_ENTERPRISE_DEVICE_REQUISITION_PROMPT_CANCEL);
95 builder->Add("deviceRequisitionPromptOk",
96 IDS_ENTERPRISE_DEVICE_REQUISITION_PROMPT_OK);
97 builder->Add("deviceRequisitionPromptText",
98 IDS_ENTERPRISE_DEVICE_REQUISITION_PROMPT_TEXT);
99 builder->Add("deviceRequisitionRemoraPromptCancel",
100 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
101 builder->Add("deviceRequisitionRemoraPromptOk",
102 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
103 builder->Add("deviceRequisitionRemoraPromptText",
104 IDS_ENTERPRISE_DEVICE_REQUISITION_REMORA_PROMPT_TEXT);
105 builder->Add("deviceRequisitionSharkPromptText",
106 IDS_ENTERPRISE_DEVICE_REQUISITION_SHARK_PROMPT_TEXT);
109 void CoreOobeHandler::Initialize() {
111 UpdateOobeUIVisibility();
112 #if defined(OFFICIAL_BUILD)
113 version_info_updater_.StartUpdate(true);
115 version_info_updater_.StartUpdate(false);
117 UpdateDeviceRequisition();
118 UpdateKeyboardState();
119 UpdateClientAreaSize();
122 void CoreOobeHandler::RegisterMessages() {
123 AddCallback(kJsApiScreenStateInitialize,
124 &CoreOobeHandler::HandleInitialized);
125 AddCallback(kJsApiSkipUpdateEnrollAfterEula,
126 &CoreOobeHandler::HandleSkipUpdateEnrollAfterEula);
127 AddCallback("updateCurrentScreen",
128 &CoreOobeHandler::HandleUpdateCurrentScreen);
129 AddCallback(kJsApiEnableHighContrast,
130 &CoreOobeHandler::HandleEnableHighContrast);
131 AddCallback(kJsApiEnableLargeCursor,
132 &CoreOobeHandler::HandleEnableLargeCursor);
133 AddCallback(kJsApiEnableVirtualKeyboard,
134 &CoreOobeHandler::HandleEnableVirtualKeyboard);
135 AddCallback(kJsApiEnableScreenMagnifier,
136 &CoreOobeHandler::HandleEnableScreenMagnifier);
137 AddCallback(kJsApiEnableSpokenFeedback,
138 &CoreOobeHandler::HandleEnableSpokenFeedback);
139 AddCallback("setDeviceRequisition",
140 &CoreOobeHandler::HandleSetDeviceRequisition);
141 AddCallback(kJsApiScreenAssetsLoaded,
142 &CoreOobeHandler::HandleScreenAssetsLoaded);
143 AddRawCallback("skipToLoginForTesting",
144 &CoreOobeHandler::HandleSkipToLoginForTesting);
145 AddCallback("launchHelpApp",
146 &CoreOobeHandler::HandleLaunchHelpApp);
147 AddCallback("toggleResetScreen", &CoreOobeHandler::HandleToggleResetScreen);
148 AddCallback(kJsApiHeaderBarVisible,
149 &CoreOobeHandler::HandleHeaderBarVisible);
152 void CoreOobeHandler::ShowSignInError(
154 const std::string& error_text,
155 const std::string& help_link_text,
156 HelpAppLauncher::HelpTopic help_topic_id) {
157 LOG(ERROR) << "CoreOobeHandler::ShowSignInError: error_text=" << error_text;
158 CallJS("showSignInError", login_attempts, error_text,
159 help_link_text, static_cast<int>(help_topic_id));
162 void CoreOobeHandler::ShowTpmError() {
163 CallJS("showTpmError");
166 void CoreOobeHandler::ShowDeviceResetScreen() {
167 policy::BrowserPolicyConnectorChromeOS* connector =
168 g_browser_process->platform_part()->browser_policy_connector_chromeos();
169 if (!connector->IsEnterpriseManaged()) {
170 // Don't recreate WizardController if it already exists.
171 WizardController* wizard_controller =
172 WizardController::default_controller();
173 if (wizard_controller && !wizard_controller->login_screen_started()) {
174 wizard_controller->AdvanceToScreen(WizardController::kResetScreenName);
176 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue());
177 DCHECK(LoginDisplayHostImpl::default_host());
178 if (LoginDisplayHostImpl::default_host()) {
179 LoginDisplayHostImpl::default_host()->StartWizard(
180 WizardController::kResetScreenName, params.Pass());
186 void CoreOobeHandler::ShowSignInUI(const std::string& email) {
187 CallJS("showSigninUI", email);
190 void CoreOobeHandler::ResetSignInUI(bool force_online) {
191 CallJS("resetSigninUI", force_online);
194 void CoreOobeHandler::ClearUserPodPassword() {
195 CallJS("clearUserPodPassword");
198 void CoreOobeHandler::RefocusCurrentPod() {
199 CallJS("refocusCurrentPod");
202 void CoreOobeHandler::ShowPasswordChangedScreen(bool show_password_error) {
203 CallJS("showPasswordChangedScreen", show_password_error);
206 void CoreOobeHandler::SetUsageStats(bool checked) {
207 CallJS("setUsageStats", checked);
210 void CoreOobeHandler::SetOemEulaUrl(const std::string& oem_eula_url) {
211 CallJS("setOemEulaUrl", oem_eula_url);
214 void CoreOobeHandler::SetTpmPassword(const std::string& tpm_password) {
215 CallJS("setTpmPassword", tpm_password);
218 void CoreOobeHandler::ClearErrors() {
219 CallJS("clearErrors");
222 void CoreOobeHandler::ReloadContent(const base::DictionaryValue& dictionary) {
223 CallJS("reloadContent", dictionary);
226 void CoreOobeHandler::ShowControlBar(bool show) {
227 CallJS("showControlBar", show);
230 void CoreOobeHandler::SetKeyboardState(bool shown, const gfx::Rect& bounds) {
231 CallJS("setKeyboardState", shown, bounds.width(), bounds.height());
234 void CoreOobeHandler::SetClientAreaSize(int width, int height) {
235 CallJS("setClientAreaSize", width, height);
238 void CoreOobeHandler::HandleInitialized() {
239 oobe_ui_->InitializeHandlers();
242 void CoreOobeHandler::HandleSkipUpdateEnrollAfterEula() {
243 WizardController* controller = WizardController::default_controller();
246 controller->SkipUpdateEnrollAfterEula();
249 void CoreOobeHandler::HandleUpdateCurrentScreen(const std::string& screen) {
251 delegate_->OnCurrentScreenChanged(screen);
254 void CoreOobeHandler::HandleEnableHighContrast(bool enabled) {
255 AccessibilityManager::Get()->EnableHighContrast(enabled);
258 void CoreOobeHandler::HandleEnableLargeCursor(bool enabled) {
259 AccessibilityManager::Get()->EnableLargeCursor(enabled);
262 void CoreOobeHandler::HandleEnableVirtualKeyboard(bool enabled) {
263 AccessibilityManager::Get()->EnableVirtualKeyboard(enabled);
266 void CoreOobeHandler::HandleEnableScreenMagnifier(bool enabled) {
267 #if !defined(USE_ATHENA)
268 // TODO(nkostylev): Add support for partial screen magnifier.
269 DCHECK(MagnificationManager::Get());
270 MagnificationManager::Get()->SetMagnifierEnabled(enabled);
274 void CoreOobeHandler::HandleEnableSpokenFeedback(bool /* enabled */) {
275 // Checkbox is initialized on page init and updates when spoken feedback
276 // setting is changed so just toggle spoken feedback here.
277 AccessibilityManager::Get()->ToggleSpokenFeedback(
278 ui::A11Y_NOTIFICATION_NONE);
281 void CoreOobeHandler::HandleSetDeviceRequisition(
282 const std::string& requisition) {
283 policy::BrowserPolicyConnectorChromeOS* connector =
284 g_browser_process->platform_part()->browser_policy_connector_chromeos();
285 std::string initial_requisition =
286 connector->GetDeviceCloudPolicyManager()->GetDeviceRequisition();
287 connector->GetDeviceCloudPolicyManager()->SetDeviceRequisition(requisition);
288 // Exit Chrome to force the restart as soon as a new requisition is set.
289 if (initial_requisition !=
290 connector->GetDeviceCloudPolicyManager()->GetDeviceRequisition()) {
291 chrome::AttemptRestart();
295 void CoreOobeHandler::HandleScreenAssetsLoaded(
296 const std::string& screen_async_load_id) {
297 oobe_ui_->OnScreenAssetsLoaded(screen_async_load_id);
300 void CoreOobeHandler::HandleSkipToLoginForTesting(
301 const base::ListValue* args) {
302 LoginScreenContext context(args);
303 if (WizardController::default_controller())
304 WizardController::default_controller()->SkipToLoginForTesting(context);
307 void CoreOobeHandler::HandleToggleResetScreen() { ShowDeviceResetScreen(); }
309 void CoreOobeHandler::ShowOobeUI(bool show) {
310 if (show == show_oobe_ui_)
313 show_oobe_ui_ = show;
316 UpdateOobeUIVisibility();
319 void CoreOobeHandler::UpdateA11yState() {
320 #if !defined(USE_ATHENA)
321 // TODO(dpolukhin): crbug.com/412891
322 DCHECK(MagnificationManager::Get());
323 base::DictionaryValue a11y_info;
324 a11y_info.SetBoolean("highContrastEnabled",
325 AccessibilityManager::Get()->IsHighContrastEnabled());
326 a11y_info.SetBoolean("largeCursorEnabled",
327 AccessibilityManager::Get()->IsLargeCursorEnabled());
328 a11y_info.SetBoolean("spokenFeedbackEnabled",
329 AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
330 a11y_info.SetBoolean("screenMagnifierEnabled",
331 MagnificationManager::Get()->IsMagnifierEnabled());
332 a11y_info.SetBoolean("virtualKeyboardEnabled",
333 AccessibilityManager::Get()->IsVirtualKeyboardEnabled());
334 CallJS("refreshA11yInfo", a11y_info);
338 void CoreOobeHandler::UpdateOobeUIVisibility() {
339 #if defined(USE_ATHENA)
340 // Athena builds have their own way to display version so hide ours.
341 bool should_show_version = false;
343 // Don't show version label on the stable channel by default.
344 bool should_show_version = true;
345 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
346 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
347 channel == chrome::VersionInfo::CHANNEL_BETA) {
348 should_show_version = false;
351 CallJS("showVersion", should_show_version);
352 CallJS("showOobeUI", show_oobe_ui_);
353 if (system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation())
354 CallJS("enableKeyboardFlow", true);
357 void CoreOobeHandler::OnOSVersionLabelTextUpdated(
358 const std::string& os_version_label_text) {
359 UpdateLabel("version", os_version_label_text);
362 void CoreOobeHandler::OnEnterpriseInfoUpdated(
363 const std::string& message_text) {
364 CallJS("setEnterpriseInfo", message_text);
367 void CoreOobeHandler::UpdateLabel(const std::string& id,
368 const std::string& text) {
369 CallJS("setLabelText", id, text);
372 void CoreOobeHandler::UpdateDeviceRequisition() {
373 policy::BrowserPolicyConnectorChromeOS* connector =
374 g_browser_process->platform_part()->browser_policy_connector_chromeos();
375 CallJS("updateDeviceRequisition",
376 connector->GetDeviceCloudPolicyManager()->GetDeviceRequisition());
379 void CoreOobeHandler::UpdateKeyboardState() {
380 if (!login::LoginScrollIntoViewEnabled())
383 keyboard::KeyboardController* keyboard_controller =
384 keyboard::KeyboardController::GetInstance();
385 if (keyboard_controller) {
386 gfx::Rect bounds = keyboard_controller->current_keyboard_bounds();
387 SetKeyboardState(!bounds.IsEmpty(), bounds);
391 void CoreOobeHandler::UpdateClientAreaSize() {
392 const gfx::Size& size =
393 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().size();
394 SetClientAreaSize(size.width(), size.height());
397 void CoreOobeHandler::OnAccessibilityStatusChanged(
398 const AccessibilityStatusEventDetails& details) {
399 if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN)
400 accessibility_subscription_.reset();
405 void CoreOobeHandler::HandleLaunchHelpApp(double help_topic_id) {
406 if (!help_app_.get())
407 help_app_ = new HelpAppLauncher(GetNativeWindow());
408 help_app_->ShowHelpTopic(
409 static_cast<HelpAppLauncher::HelpTopic>(help_topic_id));
412 void CoreOobeHandler::HandleHeaderBarVisible() {
413 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
414 if (login_display_host)
415 login_display_host->SetStatusAreaVisible(true);
418 void CoreOobeHandler::InitDemoModeDetection() {
419 demo_mode_detector_.InitDetection();
422 void CoreOobeHandler::StopDemoModeDetection() {
423 demo_mode_detector_.StopDetection();
426 } // namespace chromeos