| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/login/hid_detection_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chromeos/login/oobe_screen.h" | 13 #include "chrome/browser/chromeos/login/oobe_screen.h" |
| 14 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h" | 14 #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h" |
| 15 #include "chrome/browser/chromeos/login/screens/hid_detection_model.h" | 15 #include "chrome/browser/chromeos/login/screens/hid_detection_screen.h" |
| 16 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 16 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 19 #include "chromeos/chromeos_switches.h" | 19 #include "chromeos/chromeos_switches.h" |
| 20 #include "components/login/localized_values_builder.h" | 20 #include "components/login/localized_values_builder.h" |
| 21 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kJsScreenPath[] = "login.HIDDetectionScreen"; | 25 const char kJsScreenPath[] = "login.HIDDetectionScreen"; |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 namespace chromeos { | 29 namespace chromeos { |
| 30 | 30 |
| 31 HIDDetectionScreenHandler::HIDDetectionScreenHandler( | 31 HIDDetectionScreenHandler::HIDDetectionScreenHandler( |
| 32 CoreOobeActor* core_oobe_actor) | 32 CoreOobeActor* core_oobe_actor) |
| 33 : BaseScreenHandler(kJsScreenPath), | 33 : BaseScreenHandler(kJsScreenPath), core_oobe_actor_(core_oobe_actor) {} |
| 34 model_(NULL), | |
| 35 core_oobe_actor_(core_oobe_actor), | |
| 36 show_on_init_(false) { | |
| 37 } | |
| 38 | 34 |
| 39 HIDDetectionScreenHandler::~HIDDetectionScreenHandler() { | 35 HIDDetectionScreenHandler::~HIDDetectionScreenHandler() { |
| 40 if (model_) | 36 if (screen_) |
| 41 model_->OnViewDestroyed(this); | 37 screen_->OnViewDestroyed(this); |
| 42 } | 38 } |
| 43 | 39 |
| 44 void HIDDetectionScreenHandler::Show() { | 40 void HIDDetectionScreenHandler::Show() { |
| 45 if (!page_is_ready()) { | 41 if (!page_is_ready()) { |
| 46 show_on_init_ = true; | 42 show_on_init_ = true; |
| 47 return; | 43 return; |
| 48 } | 44 } |
| 49 core_oobe_actor_->InitDemoModeDetection(); | 45 core_oobe_actor_->InitDemoModeDetection(); |
| 50 | 46 |
| 51 PrefService* local_state = g_browser_process->local_state(); | 47 PrefService* local_state = g_browser_process->local_state(); |
| 52 int num_of_times_dialog_was_shown = local_state->GetInteger( | 48 int num_of_times_dialog_was_shown = local_state->GetInteger( |
| 53 prefs::kTimesHIDDialogShown); | 49 prefs::kTimesHIDDialogShown); |
| 54 local_state->SetInteger(prefs::kTimesHIDDialogShown, | 50 local_state->SetInteger(prefs::kTimesHIDDialogShown, |
| 55 num_of_times_dialog_was_shown + 1); | 51 num_of_times_dialog_was_shown + 1); |
| 56 | 52 |
| 57 ShowScreen(OobeScreen::SCREEN_OOBE_HID_DETECTION); | 53 ShowScreen(OobeScreen::SCREEN_OOBE_HID_DETECTION); |
| 58 } | 54 } |
| 59 | 55 |
| 60 void HIDDetectionScreenHandler::Hide() { | 56 void HIDDetectionScreenHandler::Hide() { |
| 61 } | 57 } |
| 62 | 58 |
| 63 void HIDDetectionScreenHandler::Bind(HIDDetectionModel& model) { | 59 void HIDDetectionScreenHandler::Bind(HIDDetectionScreen* screen) { |
| 64 model_ = &model; | 60 screen_ = screen; |
| 65 BaseScreenHandler::SetBaseScreen(model_); | 61 BaseScreenHandler::SetBaseScreen(screen_); |
| 66 if (page_is_ready()) | 62 if (page_is_ready()) |
| 67 Initialize(); | 63 Initialize(); |
| 68 } | 64 } |
| 69 | 65 |
| 70 void HIDDetectionScreenHandler::Unbind() { | 66 void HIDDetectionScreenHandler::Unbind() { |
| 71 model_ = nullptr; | 67 screen_ = nullptr; |
| 72 BaseScreenHandler::SetBaseScreen(nullptr); | 68 BaseScreenHandler::SetBaseScreen(nullptr); |
| 73 } | 69 } |
| 74 | 70 |
| 75 void HIDDetectionScreenHandler::CheckIsScreenRequired( | 71 void HIDDetectionScreenHandler::CheckIsScreenRequired( |
| 76 const base::Callback<void(bool)>& on_check_done) { | 72 const base::Callback<void(bool)>& on_check_done) { |
| 77 model_->CheckIsScreenRequired(on_check_done); | 73 screen_->CheckIsScreenRequired(on_check_done); |
| 78 } | 74 } |
| 79 | 75 |
| 80 void HIDDetectionScreenHandler::DeclareLocalizedValues( | 76 void HIDDetectionScreenHandler::DeclareLocalizedValues( |
| 81 ::login::LocalizedValuesBuilder* builder) { | 77 ::login::LocalizedValuesBuilder* builder) { |
| 82 builder->Add("hidDetectionContinue", IDS_HID_DETECTION_CONTINUE_BUTTON); | 78 builder->Add("hidDetectionContinue", IDS_HID_DETECTION_CONTINUE_BUTTON); |
| 83 builder->Add("hidDetectionInvitation", IDS_HID_DETECTION_INVITATION_TEXT); | 79 builder->Add("hidDetectionInvitation", IDS_HID_DETECTION_INVITATION_TEXT); |
| 84 builder->Add("hidDetectionPrerequisites", | 80 builder->Add("hidDetectionPrerequisites", |
| 85 IDS_HID_DETECTION_PRECONDITION_TEXT); | 81 IDS_HID_DETECTION_PRECONDITION_TEXT); |
| 86 builder->Add("hidDetectionMouseSearching", IDS_HID_DETECTION_SEARCHING_MOUSE); | 82 builder->Add("hidDetectionMouseSearching", IDS_HID_DETECTION_SEARCHING_MOUSE); |
| 87 builder->Add("hidDetectionKeyboardSearching", | 83 builder->Add("hidDetectionKeyboardSearching", |
| (...skipping 17 matching lines...) Expand all Loading... |
| 105 void HIDDetectionScreenHandler::Initialize() { | 101 void HIDDetectionScreenHandler::Initialize() { |
| 106 if (show_on_init_) { | 102 if (show_on_init_) { |
| 107 Show(); | 103 Show(); |
| 108 show_on_init_ = false; | 104 show_on_init_ = false; |
| 109 } | 105 } |
| 110 } | 106 } |
| 111 | 107 |
| 112 void HIDDetectionScreenHandler::HandleOnContinue() { | 108 void HIDDetectionScreenHandler::HandleOnContinue() { |
| 113 // Continue button pressed. | 109 // Continue button pressed. |
| 114 core_oobe_actor_->StopDemoModeDetection(); | 110 core_oobe_actor_->StopDemoModeDetection(); |
| 115 if (model_) | 111 if (screen_) |
| 116 model_->OnContinueButtonClicked(); | 112 screen_->OnContinueButtonClicked(); |
| 117 } | 113 } |
| 118 | 114 |
| 119 // static | 115 // static |
| 120 void HIDDetectionScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { | 116 void HIDDetectionScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
| 121 registry->RegisterIntegerPref(prefs::kTimesHIDDialogShown, 0); | 117 registry->RegisterIntegerPref(prefs::kTimesHIDDialogShown, 0); |
| 122 } | 118 } |
| 123 | 119 |
| 124 } // namespace chromeos | 120 } // namespace chromeos |
| OLD | NEW |