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 "grit/generated_resources.h"
15 const char kJsScreenPath[] = "login.HostPairingScreen";
17 const char kMethodContextChanged[] = "contextChanged";
19 // Sent from JS when screen is ready to receive context updates.
20 // TODO(dzhioev): Move 'contextReady' logic to the base screen handler when
21 // all screens migrate to context-based communications.
22 const char kCallbackContextReady[] = "contextReady";
26 HostPairingScreenHandler::HostPairingScreenHandler()
27 : BaseScreenHandler(kJsScreenPath),
30 js_context_ready_(false) {
33 HostPairingScreenHandler::~HostPairingScreenHandler() {
35 delegate_->OnActorDestroyed(this);
38 void HostPairingScreenHandler::HandleContextReady() {
39 js_context_ready_ = true;
40 OnContextChanged(context_cache_.storage());
43 void HostPairingScreenHandler::Initialize() {
44 if (!page_is_ready() || !delegate_)
49 show_on_init_ = false;
53 void HostPairingScreenHandler::DeclareLocalizedValues(
54 LocalizedValuesBuilder* builder) {
55 // TODO(dzhioev): Move the prefix logic to the base screen handler after
58 base::ReplaceChars(kJsScreenPath, ".", "_", &prefix);
61 builder->Add(prefix + "welcomeTitle", IDS_PAIRING_HOST_WELCOME_TITLE);
62 builder->Add(prefix + "welcomeText", IDS_PAIRING_HOST_WELCOME_TEXT);
63 builder->Add(prefix + "confirmationTitle",
64 IDS_PAIRING_HOST_CONFIRMATION_TITLE);
65 builder->Add(prefix + "updatingTitle", IDS_PAIRING_HOST_UPDATING_TITLE);
66 builder->Add(prefix + "updatingText", IDS_PAIRING_HOST_UPDATING_TEXT);
67 builder->Add(prefix + "enrollTitle", IDS_PAIRING_ENROLL_TITLE);
68 builder->Add(prefix + "enrollingTitle",
69 IDS_PAIRING_ENROLLMENT_IN_PROGRESS);
70 builder->Add(prefix + "doneTitle", IDS_PAIRING_HOST_DONE_TITLE);
71 builder->Add(prefix + "doneText", IDS_PAIRING_HOST_DONE_TEXT);
72 builder->Add(prefix + "enrollmentErrorTitle",
73 IDS_PAIRING_ENROLLMENT_ERROR_TITLE);
74 builder->Add(prefix + "errorNeedsRestart",
75 IDS_PAIRING_HOST_EROLLMENT_ERROR_NEEDS_RESTART);
78 void HostPairingScreenHandler::RegisterMessages() {
79 AddPrefixedCallback(kCallbackContextReady,
80 &HostPairingScreenHandler::HandleContextReady);
83 void HostPairingScreenHandler::Show() {
84 if (!page_is_ready()) {
88 ShowScreen(OobeUI::kScreenHostPairing, NULL);
91 void HostPairingScreenHandler::Hide() {
94 void HostPairingScreenHandler::SetDelegate(Delegate* delegate) {
100 void HostPairingScreenHandler::OnContextChanged(
101 const base::DictionaryValue& diff) {
102 if (!js_context_ready_) {
103 context_cache_.ApplyChanges(diff, NULL);
106 CallJS(kMethodContextChanged, diff);
109 } // namespace chromeos