Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / host_pairing_screen_handler.cc
blob6646526bd64963462ea8b10643704f4a1d21ec15
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"
12 namespace chromeos {
14 namespace {
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";
25 } // namespace
27 HostPairingScreenHandler::HostPairingScreenHandler()
28 : BaseScreenHandler(kJsScreenPath),
29 delegate_(NULL),
30 show_on_init_(false),
31 js_context_ready_(false) {
34 HostPairingScreenHandler::~HostPairingScreenHandler() {
35 if (delegate_)
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_)
46 return;
48 if (show_on_init_) {
49 Show();
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
57 // migration.
58 std::string prefix;
59 base::ReplaceChars(kJsScreenPath, ".", "_", &prefix);
60 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()) {
86 show_on_init_ = true;
87 return;
89 ShowScreen(OobeUI::kScreenHostPairing, NULL);
92 void HostPairingScreenHandler::Hide() {
95 void HostPairingScreenHandler::SetDelegate(Delegate* delegate) {
96 delegate_ = delegate;
97 if (page_is_ready())
98 Initialize();
101 void HostPairingScreenHandler::OnContextChanged(
102 const base::DictionaryValue& diff) {
103 if (!js_context_ready_) {
104 context_cache_.ApplyChanges(diff, NULL);
105 return;
107 CallJS(kMethodContextChanged, diff);
110 } // namespace chromeos