1 // Copyright 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.
5 #include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h"
8 #include "base/command_line.h"
9 #include "base/compiler_specific.h"
10 #include "base/macros.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string16.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chromeos/login/screens/hid_detection_model.h"
15 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
16 #include "chrome/common/pref_names.h"
17 #include "chrome/grit/generated_resources.h"
18 #include "chromeos/chromeos_switches.h"
19 #include "components/login/localized_values_builder.h"
23 const char kJsScreenPath
[] = "login.HIDDetectionScreen";
29 HIDDetectionScreenHandler::HIDDetectionScreenHandler(
30 CoreOobeActor
* core_oobe_actor
)
31 : BaseScreenHandler(kJsScreenPath
),
33 core_oobe_actor_(core_oobe_actor
),
34 show_on_init_(false) {
37 HIDDetectionScreenHandler::~HIDDetectionScreenHandler() {
39 model_
->OnViewDestroyed(this);
42 void HIDDetectionScreenHandler::Show() {
43 if (!page_is_ready()) {
47 core_oobe_actor_
->InitDemoModeDetection();
49 PrefService
* local_state
= g_browser_process
->local_state();
50 int num_of_times_dialog_was_shown
= local_state
->GetInteger(
51 prefs::kTimesHIDDialogShown
);
52 local_state
->SetInteger(prefs::kTimesHIDDialogShown
,
53 num_of_times_dialog_was_shown
+ 1);
55 ShowScreen(OobeUI::kScreenHIDDetection
, NULL
);
58 void HIDDetectionScreenHandler::Hide() {
61 void HIDDetectionScreenHandler::Bind(HIDDetectionModel
& model
) {
63 BaseScreenHandler::SetBaseScreen(model_
);
68 void HIDDetectionScreenHandler::Unbind() {
70 BaseScreenHandler::SetBaseScreen(nullptr);
73 void HIDDetectionScreenHandler::PrepareToShow() {
76 void HIDDetectionScreenHandler::CheckIsScreenRequired(
77 const base::Callback
<void(bool)>& on_check_done
) {
78 model_
->CheckIsScreenRequired(on_check_done
);
81 void HIDDetectionScreenHandler::DeclareLocalizedValues(
82 ::login::LocalizedValuesBuilder
* builder
) {
83 builder
->Add("hidDetectionContinue", IDS_HID_DETECTION_CONTINUE_BUTTON
);
84 builder
->Add("hidDetectionInvitation", IDS_HID_DETECTION_INVITATION_TEXT
);
85 builder
->Add("hidDetectionPrerequisites",
86 IDS_HID_DETECTION_PRECONDITION_TEXT
);
87 builder
->Add("hidDetectionMouseSearching", IDS_HID_DETECTION_SEARCHING_MOUSE
);
88 builder
->Add("hidDetectionKeyboardSearching",
89 IDS_HID_DETECTION_SEARCHING_KEYBOARD
);
90 builder
->Add("hidDetectionUSBMouseConnected",
91 IDS_HID_DETECTION_CONNECTED_USB_MOUSE
);
92 builder
->Add("hidDetectionUSBKeyboardConnected",
93 IDS_HID_DETECTION_CONNECTED_USB_KEYBOARD
);
94 builder
->Add("hidDetectionBTMousePaired",
95 IDS_HID_DETECTION_PAIRED_BLUETOOTH_MOUSE
);
96 builder
->Add("hidDetectionBTEnterKey", IDS_HID_DETECTION_BLUETOOTH_ENTER_KEY
);
99 void HIDDetectionScreenHandler::DeclareJSCallbacks() {
101 "HIDDetectionOnContinue", &HIDDetectionScreenHandler::HandleOnContinue
);
104 void HIDDetectionScreenHandler::Initialize() {
107 show_on_init_
= false;
111 void HIDDetectionScreenHandler::HandleOnContinue() {
112 // Continue button pressed.
113 core_oobe_actor_
->StopDemoModeDetection();
115 model_
->OnContinueButtonClicked();
119 void HIDDetectionScreenHandler::RegisterPrefs(PrefRegistrySimple
* registry
) {
120 registry
->RegisterIntegerPref(prefs::kTimesHIDDialogShown
, 0);
123 } // namespace chromeos