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/host_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 "grit/generated_resources.h"
16 const char kJsScreenPath
[] = "login.HostPairingScreen";
18 const char kMethodContextChanged
[] = "contextChanged";
20 // Sent from JS when screen is ready to receive context updates.
21 // TODO(dzhioev): Move 'contextReady' logic to the base screen handler when
22 // all screens migrate to context-based communications.
23 const char kCallbackContextReady
[] = "contextReady";
27 HostPairingScreenHandler::HostPairingScreenHandler()
28 : BaseScreenHandler(kJsScreenPath
),
31 js_context_ready_(false) {
34 HostPairingScreenHandler::~HostPairingScreenHandler() {
36 delegate_
->OnActorDestroyed(this);
39 void HostPairingScreenHandler::HandleContextReady() {
40 js_context_ready_
= true;
41 OnContextChanged(context_cache_
.storage());
44 void HostPairingScreenHandler::Initialize() {
45 if (!page_is_ready() || !delegate_
)
50 show_on_init_
= false;
54 void HostPairingScreenHandler::DeclareLocalizedValues(
55 ::login::LocalizedValuesBuilder
* builder
) {
56 // TODO(dzhioev): Move the prefix logic to the base screen handler after
59 base::ReplaceChars(kJsScreenPath
, ".", "_", &prefix
);
62 builder
->Add(prefix
+ "welcomeTitle", IDS_PAIRING_HOST_WELCOME_TITLE
);
63 builder
->Add(prefix
+ "welcomeText", IDS_PAIRING_HOST_WELCOME_TEXT
);
64 builder
->Add(prefix
+ "confirmationTitle",
65 IDS_PAIRING_HOST_CONFIRMATION_TITLE
);
66 builder
->Add(prefix
+ "updatingTitle", IDS_PAIRING_HOST_UPDATING_TITLE
);
67 builder
->Add(prefix
+ "updatingText", IDS_PAIRING_HOST_UPDATING_TEXT
);
68 builder
->Add(prefix
+ "enrollTitle", IDS_PAIRING_ENROLL_TITLE
);
69 builder
->Add(prefix
+ "enrollingTitle",
70 IDS_PAIRING_ENROLLMENT_IN_PROGRESS
);
71 builder
->Add(prefix
+ "doneTitle", IDS_PAIRING_HOST_DONE_TITLE
);
72 builder
->Add(prefix
+ "doneText", IDS_PAIRING_HOST_DONE_TEXT
);
73 builder
->Add(prefix
+ "enrollmentErrorTitle",
74 IDS_PAIRING_ENROLLMENT_ERROR_TITLE
);
75 builder
->Add(prefix
+ "errorNeedsRestart",
76 IDS_PAIRING_HOST_EROLLMENT_ERROR_NEEDS_RESTART
);
79 void HostPairingScreenHandler::RegisterMessages() {
80 AddPrefixedCallback(kCallbackContextReady
,
81 &HostPairingScreenHandler::HandleContextReady
);
84 void HostPairingScreenHandler::Show() {
85 if (!page_is_ready()) {
89 ShowScreen(OobeUI::kScreenHostPairing
, NULL
);
92 void HostPairingScreenHandler::Hide() {
95 void HostPairingScreenHandler::SetDelegate(Delegate
* delegate
) {
101 void HostPairingScreenHandler::OnContextChanged(
102 const base::DictionaryValue
& diff
) {
103 if (!js_context_ready_
) {
104 context_cache_
.ApplyChanges(diff
, NULL
);
107 CallJS(kMethodContextChanged
, diff
);
110 } // namespace chromeos