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/controller_pairing_screen_handler.h"
7 #include "base/strings/string_util.h"
8 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
9 #include "components/login/localized_values_builder.h"
10 #include "content/public/browser/web_contents.h"
11 #include "grit/generated_resources.h"
17 const char kJsScreenPath
[] = "login.ControllerPairingScreen";
19 const char kMethodContextChanged
[] = "contextChanged";
21 const char kCallbackUserActed
[] = "userActed";
22 const char kCallbackContextChanged
[] = "contextChanged";
26 ControllerPairingScreenHandler::ControllerPairingScreenHandler()
27 : BaseScreenHandler(kJsScreenPath
), delegate_(NULL
), show_on_init_(false) {
30 ControllerPairingScreenHandler::~ControllerPairingScreenHandler() {
32 delegate_
->OnActorDestroyed(this);
35 void ControllerPairingScreenHandler::HandleUserActed(
36 const std::string
& action
) {
39 delegate_
->OnUserActed(action
);
42 void ControllerPairingScreenHandler::HandleContextChanged(
43 const base::DictionaryValue
* diff
) {
46 delegate_
->OnScreenContextChanged(*diff
);
49 void ControllerPairingScreenHandler::Initialize() {
50 if (!page_is_ready() || !delegate_
)
55 show_on_init_
= false;
59 void ControllerPairingScreenHandler::DeclareLocalizedValues(
60 ::login::LocalizedValuesBuilder
* builder
) {
61 // TODO(dzhioev): Move the prefix logic to the base screen handler after
64 base::ReplaceChars(kJsScreenPath
, ".", "_", &prefix
);
67 builder
->Add(prefix
+ "welcomeTitle", IDS_PAIRING_CONTROLLER_WELCOME
);
68 builder
->Add(prefix
+ "searching", IDS_PAIRING_CONTROLLER_SEARCHING
);
69 builder
->Add(prefix
+ "helpBtn", IDS_PAIRING_NEED_HELP
);
70 builder
->Add(prefix
+ "troubleConnectingTitle",
71 IDS_PAIRING_CONTROLLER_TROUBLE_CONNECTING
);
72 builder
->Add(prefix
+ "connectingAdvice",
73 IDS_PAIRING_CONTROLLER_CONNECTING_ADVICE
);
74 builder
->Add(prefix
+ "adviceGotItBtn", IDS_PAIRING_CONTROLLER_ADVICE_GOT_IT
);
75 builder
->Add(prefix
+ "selectTitle", IDS_PAIRING_CONTROLLER_SELECT_TITLE
);
76 builder
->Add(prefix
+ "connectBtn", IDS_PAIRING_CONTROLLER_CONNECT
);
77 builder
->Add(prefix
+ "connecting", IDS_PAIRING_CONTROLLER_CONNECTING
);
78 builder
->Add(prefix
+ "confirmationTitle",
79 IDS_PAIRING_CONTROLLER_CONFIRMATION_TITLE
);
80 builder
->Add(prefix
+ "confirmationQuestion",
81 IDS_PAIRING_CONTROLLER_CONFIRMATION_QUESTION
);
82 builder
->Add(prefix
+ "rejectCodeBtn", IDS_PAIRING_CONTROLLER_REJECT_CODE
);
83 builder
->Add(prefix
+ "acceptCodeBtn", IDS_PAIRING_CONTROLLER_ACCEPT_CODE
);
84 builder
->Add(prefix
+ "updateTitle", IDS_PAIRING_CONTROLLER_UPDATE_TITLE
);
85 builder
->Add(prefix
+ "updateText", IDS_PAIRING_CONTROLLER_UPDATE_TEXT
);
86 builder
->Add(prefix
+ "connectionLostTitle",
87 IDS_PAIRING_CONTROLLER_CONNECTION_LOST_TITLE
);
88 builder
->Add(prefix
+ "connectionLostText",
89 IDS_PAIRING_CONTROLLER_CONNECTION_LOST_TEXT
);
90 builder
->Add(prefix
+ "enrollTitle", IDS_PAIRING_ENROLL_TITLE
);
91 builder
->Add(prefix
+ "enrollText1", IDS_PAIRING_CONTROLLER_ENROLL_TEXT_1
);
92 builder
->Add(prefix
+ "enrollText2", IDS_PAIRING_CONTROLLER_ENROLL_TEXT_2
);
93 builder
->Add(prefix
+ "continueBtn", IDS_PAIRING_CONTROLLER_CONTINUE
);
94 builder
->Add(prefix
+ "enrollmentInProgress",
95 IDS_PAIRING_ENROLLMENT_IN_PROGRESS
);
96 builder
->Add(prefix
+ "enrollmentErrorTitle",
97 IDS_PAIRING_ENROLLMENT_ERROR_TITLE
);
98 builder
->Add(prefix
+ "enrollmentErrorHostRestarts",
99 IDS_PAIRING_CONTROLLER_ENROLLMENT_ERROR_HOST_RESTARTS
);
100 builder
->Add(prefix
+ "successTitle", IDS_PAIRING_CONTROLLER_SUCCESS_TITLE
);
101 builder
->Add(prefix
+ "successText", IDS_PAIRING_CONTROLLER_SUCCESS_TEXT
);
102 builder
->Add(prefix
+ "continueToHangoutsBtn",
103 IDS_PAIRING_CONTROLLER_CONTINUE_TO_HANGOUTS
);
106 void ControllerPairingScreenHandler::RegisterMessages() {
107 AddPrefixedCallback(kCallbackUserActed
,
108 &ControllerPairingScreenHandler::HandleUserActed
);
109 AddPrefixedCallback(kCallbackContextChanged
,
110 &ControllerPairingScreenHandler::HandleContextChanged
);
113 void ControllerPairingScreenHandler::Show() {
114 if (!page_is_ready()) {
115 show_on_init_
= true;
118 ShowScreen(OobeUI::kScreenControllerPairing
, NULL
);
121 void ControllerPairingScreenHandler::Hide() {
124 void ControllerPairingScreenHandler::SetDelegate(Delegate
* delegate
) {
125 delegate_
= delegate
;
130 void ControllerPairingScreenHandler::OnContextChanged(
131 const base::DictionaryValue
& diff
) {
132 CallJS(kMethodContextChanged
, diff
);
135 content::BrowserContext
* ControllerPairingScreenHandler::GetBrowserContext() {
136 return web_ui()->GetWebContents()->GetBrowserContext();
139 } // namespace chromeos