Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / chromeos / login / core_oobe_handler.cc
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.
4
5 #include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h"
6
7 #include "ash/shell.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"
32
33 #if !defined(USE_ATHENA)
34 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
35 #endif
36
37 namespace {
38
39 const char kJsScreenPath[] = "cr.ui.Oobe";
40
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";
51
52 }  // namespace
53
54 namespace chromeos {
55
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),
60       oobe_ui_(oobe_ui),
61       show_oobe_ui_(false),
62       version_info_updater_(this),
63       delegate_(NULL) {
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)));
69 }
70
71 CoreOobeHandler::~CoreOobeHandler() {
72 }
73
74 void CoreOobeHandler::SetDelegate(Delegate* delegate) {
75   delegate_ = delegate;
76 }
77
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);
82
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);
91
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);
107 }
108
109 void CoreOobeHandler::Initialize() {
110   UpdateA11yState();
111   UpdateOobeUIVisibility();
112 #if defined(OFFICIAL_BUILD)
113   version_info_updater_.StartUpdate(true);
114 #else
115   version_info_updater_.StartUpdate(false);
116 #endif
117   UpdateDeviceRequisition();
118   UpdateKeyboardState();
119   UpdateClientAreaSize();
120 }
121
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);
150 }
151
152 void CoreOobeHandler::ShowSignInError(
153     int login_attempts,
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));
160 }
161
162 void CoreOobeHandler::ShowTpmError() {
163   CallJS("showTpmError");
164 }
165
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);
175     } else {
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());
181       }
182     }
183   }
184 }
185
186 void CoreOobeHandler::ShowSignInUI(const std::string& email) {
187   CallJS("showSigninUI", email);
188 }
189
190 void CoreOobeHandler::ResetSignInUI(bool force_online) {
191   CallJS("resetSigninUI", force_online);
192 }
193
194 void CoreOobeHandler::ClearUserPodPassword() {
195   CallJS("clearUserPodPassword");
196 }
197
198 void CoreOobeHandler::RefocusCurrentPod() {
199   CallJS("refocusCurrentPod");
200 }
201
202 void CoreOobeHandler::ShowPasswordChangedScreen(bool show_password_error) {
203   CallJS("showPasswordChangedScreen", show_password_error);
204 }
205
206 void CoreOobeHandler::SetUsageStats(bool checked) {
207   CallJS("setUsageStats", checked);
208 }
209
210 void CoreOobeHandler::SetOemEulaUrl(const std::string& oem_eula_url) {
211   CallJS("setOemEulaUrl", oem_eula_url);
212 }
213
214 void CoreOobeHandler::SetTpmPassword(const std::string& tpm_password) {
215   CallJS("setTpmPassword", tpm_password);
216 }
217
218 void CoreOobeHandler::ClearErrors() {
219   CallJS("clearErrors");
220 }
221
222 void CoreOobeHandler::ReloadContent(const base::DictionaryValue& dictionary) {
223   CallJS("reloadContent", dictionary);
224 }
225
226 void CoreOobeHandler::ShowControlBar(bool show) {
227   CallJS("showControlBar", show);
228 }
229
230 void CoreOobeHandler::SetKeyboardState(bool shown, const gfx::Rect& bounds) {
231   CallJS("setKeyboardState", shown, bounds.width(), bounds.height());
232 }
233
234 void CoreOobeHandler::SetClientAreaSize(int width, int height) {
235   CallJS("setClientAreaSize", width, height);
236 }
237
238 void CoreOobeHandler::HandleInitialized() {
239   oobe_ui_->InitializeHandlers();
240 }
241
242 void CoreOobeHandler::HandleSkipUpdateEnrollAfterEula() {
243   WizardController* controller = WizardController::default_controller();
244   DCHECK(controller);
245   if (controller)
246     controller->SkipUpdateEnrollAfterEula();
247 }
248
249 void CoreOobeHandler::HandleUpdateCurrentScreen(const std::string& screen) {
250   if (delegate_)
251     delegate_->OnCurrentScreenChanged(screen);
252 }
253
254 void CoreOobeHandler::HandleEnableHighContrast(bool enabled) {
255   AccessibilityManager::Get()->EnableHighContrast(enabled);
256 }
257
258 void CoreOobeHandler::HandleEnableLargeCursor(bool enabled) {
259   AccessibilityManager::Get()->EnableLargeCursor(enabled);
260 }
261
262 void CoreOobeHandler::HandleEnableVirtualKeyboard(bool enabled) {
263   AccessibilityManager::Get()->EnableVirtualKeyboard(enabled);
264 }
265
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);
271 #endif
272 }
273
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);
279 }
280
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();
292   }
293 }
294
295 void CoreOobeHandler::HandleScreenAssetsLoaded(
296     const std::string& screen_async_load_id) {
297   oobe_ui_->OnScreenAssetsLoaded(screen_async_load_id);
298 }
299
300 void CoreOobeHandler::HandleSkipToLoginForTesting(
301     const base::ListValue* args) {
302   LoginScreenContext context(args);
303   if (WizardController::default_controller())
304       WizardController::default_controller()->SkipToLoginForTesting(context);
305 }
306
307 void CoreOobeHandler::HandleToggleResetScreen() { ShowDeviceResetScreen(); }
308
309 void CoreOobeHandler::ShowOobeUI(bool show) {
310   if (show == show_oobe_ui_)
311     return;
312
313   show_oobe_ui_ = show;
314
315   if (page_is_ready())
316     UpdateOobeUIVisibility();
317 }
318
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);
335 #endif
336 }
337
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;
342 #else
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;
349   }
350 #endif
351   CallJS("showVersion", should_show_version);
352   CallJS("showOobeUI", show_oobe_ui_);
353   if (system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation())
354     CallJS("enableKeyboardFlow", true);
355 }
356
357 void CoreOobeHandler::OnOSVersionLabelTextUpdated(
358     const std::string& os_version_label_text) {
359   UpdateLabel("version", os_version_label_text);
360 }
361
362 void CoreOobeHandler::OnEnterpriseInfoUpdated(
363     const std::string& message_text) {
364   CallJS("setEnterpriseInfo", message_text);
365 }
366
367 void CoreOobeHandler::UpdateLabel(const std::string& id,
368                                   const std::string& text) {
369   CallJS("setLabelText", id, text);
370 }
371
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());
377 }
378
379 void CoreOobeHandler::UpdateKeyboardState() {
380   if (!login::LoginScrollIntoViewEnabled())
381     return;
382
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);
388   }
389 }
390
391 void CoreOobeHandler::UpdateClientAreaSize() {
392   const gfx::Size& size =
393       gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().size();
394   SetClientAreaSize(size.width(), size.height());
395 }
396
397 void CoreOobeHandler::OnAccessibilityStatusChanged(
398     const AccessibilityStatusEventDetails& details) {
399   if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN)
400     accessibility_subscription_.reset();
401   else
402     UpdateA11yState();
403 }
404
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));
410 }
411
412 void CoreOobeHandler::HandleHeaderBarVisible() {
413   LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
414   if (login_display_host)
415     login_display_host->SetStatusAreaVisible(true);
416 }
417
418 void CoreOobeHandler::InitDemoModeDetection() {
419   demo_mode_detector_.InitDetection();
420 }
421
422 void CoreOobeHandler::StopDemoModeDetection() {
423   demo_mode_detector_.StopDetection();
424 }
425
426 }  // namespace chromeos