Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / error_screen_handler.cc
blob03d5bfc538d765ffa2df0b562d7dc16f61d18ba3
1 // Copyright (c) 2012 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/error_screen_handler.h"
7 #include "ash/system/chromeos/devicetype_utils.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/chromeos/login/screens/network_error_model.h"
11 #include "chrome/grit/chromium_strings.h"
12 #include "chrome/grit/generated_resources.h"
13 #include "components/login/localized_values_builder.h"
14 #include "ui/strings/grit/ui_strings.h"
16 namespace {
18 const char kJsScreenPath[] = "login.ErrorMessageScreen";
20 } // namespace
22 namespace chromeos {
24 ErrorScreenHandler::ErrorScreenHandler()
25 : BaseScreenHandler(kJsScreenPath),
26 model_(nullptr),
27 show_on_init_(false),
28 showing_(false),
29 weak_ptr_factory_(this) {
32 ErrorScreenHandler::~ErrorScreenHandler() {
33 if (model_)
34 model_->OnViewDestroyed(this);
37 void ErrorScreenHandler::PrepareToShow() {
40 void ErrorScreenHandler::Show() {
41 if (!page_is_ready()) {
42 show_on_init_ = true;
43 return;
45 BaseScreenHandler::ShowScreen(OobeUI::kScreenErrorMessage, NULL);
46 if (model_)
47 model_->OnShow();
48 showing_ = true;
51 void ErrorScreenHandler::Hide() {
52 showing_ = false;
53 if (model_)
54 model_->OnHide();
57 void ErrorScreenHandler::Bind(NetworkErrorModel& model) {
58 model_ = &model;
59 BaseScreenHandler::SetBaseScreen(model_);
62 void ErrorScreenHandler::Unbind() {
63 model_ = nullptr;
64 BaseScreenHandler::SetBaseScreen(nullptr);
67 void ErrorScreenHandler::ShowScreen(OobeUI::Screen screen) {
68 std::string screen_name;
69 if (GetScreenName(screen, &screen_name))
70 BaseScreenHandler::ShowScreen(screen_name.c_str(), NULL);
73 bool ErrorScreenHandler::GetScreenName(OobeUI::Screen screen,
74 std::string* name) const {
75 OobeUI* oobe_ui = static_cast<OobeUI*>(web_ui()->GetController());
76 if (!oobe_ui)
77 return false;
78 *name = oobe_ui->GetScreenName(screen);
79 return true;
82 void ErrorScreenHandler::HandleHideCaptivePortal() {
83 if (model_)
84 model_->HideCaptivePortal();
87 void ErrorScreenHandler::RegisterMessages() {
88 AddCallback("hideCaptivePortal",
89 &ErrorScreenHandler::HandleHideCaptivePortal);
90 BaseScreenHandler::RegisterMessages();
93 void ErrorScreenHandler::DeclareLocalizedValues(
94 ::login::LocalizedValuesBuilder* builder) {
95 builder->Add("deviceType", ash::GetChromeOSDeviceName());
96 builder->Add("loginErrorTitle", IDS_LOGIN_ERROR_TITLE);
97 builder->Add("rollbackErrorTitle", IDS_RESET_SCREEN_REVERT_ERROR);
98 builder->Add("signinOfflineMessageBody",
99 ash::SubstituteChromeOSDeviceType(IDS_LOGIN_OFFLINE_MESSAGE));
100 builder->Add("kioskOfflineMessageBody", IDS_KIOSK_OFFLINE_MESSAGE);
101 builder->Add("kioskOnlineTitle", IDS_LOGIN_NETWORK_RESTORED_TITLE);
102 builder->Add("kioskOnlineMessageBody", IDS_KIOSK_ONLINE_MESSAGE);
103 builder->Add("autoEnrollmentOfflineMessageBody",
104 IDS_LOGIN_AUTO_ENROLLMENT_OFFLINE_MESSAGE);
105 builder->AddF("rollbackErrorMessageBody",
106 IDS_RESET_SCREEN_REVERT_ERROR_EXPLANATION,
107 IDS_SHORT_PRODUCT_NAME);
108 builder->Add("captivePortalTitle", IDS_LOGIN_MAYBE_CAPTIVE_PORTAL_TITLE);
109 builder->Add("captivePortalMessage", IDS_LOGIN_MAYBE_CAPTIVE_PORTAL);
110 builder->Add("captivePortalProxyMessage",
111 IDS_LOGIN_MAYBE_CAPTIVE_PORTAL_PROXY);
112 builder->Add("captivePortalNetworkSelect",
113 IDS_LOGIN_MAYBE_CAPTIVE_PORTAL_NETWORK_SELECT);
114 builder->Add("signinProxyMessageText", IDS_LOGIN_PROXY_ERROR_MESSAGE);
115 builder->Add("updateOfflineMessageBody",
116 ash::SubstituteChromeOSDeviceType(IDS_UPDATE_OFFLINE_MESSAGE));
117 builder->Add("updateProxyMessageText", IDS_UPDATE_PROXY_ERROR_MESSAGE);
118 builder->AddF("localStateErrorText0", IDS_LOCAL_STATE_ERROR_TEXT_0,
119 IDS_SHORT_PRODUCT_NAME);
120 builder->Add("localStateErrorText1", IDS_LOCAL_STATE_ERROR_TEXT_1);
121 builder->Add("localStateErrorPowerwashButton",
122 IDS_LOCAL_STATE_ERROR_POWERWASH_BUTTON);
123 builder->Add("connectingIndicatorText", IDS_LOGIN_CONNECTING_INDICATOR_TEXT);
124 builder->Add("guestSigninFixNetwork", IDS_LOGIN_GUEST_SIGNIN_FIX_NETWORK);
125 builder->Add("rebootButton", IDS_RELAUNCH_BUTTON);
126 builder->Add("diagnoseButton", IDS_DIAGNOSE_BUTTON);
127 builder->Add("configureCertsButton", IDS_MANAGE_CERTIFICATES);
128 builder->Add("continueButton", IDS_NETWORK_SELECTION_CONTINUE_BUTTON);
129 builder->Add("okButton", IDS_APP_OK);
132 void ErrorScreenHandler::Initialize() {
133 if (!page_is_ready())
134 return;
136 if (show_on_init_) {
137 // TODO(nkostylev): Check that context initial state is properly passed.
138 Show();
139 show_on_init_ = false;
143 void ErrorScreenHandler::OnConnectToNetworkRequested() {
144 if (showing_ && model_)
145 model_->OnUserAction(NetworkErrorModel::kUserActionConnectRequested);
148 } // namespace chromeos