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 "base/logging.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h"
12 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
13 #include "chrome/browser/chromeos/login/webui_login_view.h"
14 #include "chrome/browser/chromeos/net/network_portal_detector.h"
15 #include "chrome/browser/ui/webui/chromeos/login/native_window_delegate.h"
16 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/power_manager_client.h"
19 #include "chromeos/dbus/session_manager_client.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
25 const char kJsScreenPath
[] = "login.ErrorMessageScreen";
31 ErrorScreenHandler::ErrorScreenHandler(
32 const scoped_refptr
<NetworkStateInformer
>& network_state_informer
)
33 : BaseScreenHandler(kJsScreenPath
),
34 network_state_informer_(network_state_informer
),
35 show_on_init_(false) {
36 DCHECK(network_state_informer_
.get());
39 ErrorScreenHandler::~ErrorScreenHandler() {
42 void ErrorScreenHandler::Show(OobeDisplay::Screen parent_screen
,
43 base::DictionaryValue
* params
) {
44 if (!page_is_ready()) {
48 parent_screen_
= parent_screen
;
49 ShowScreen(OobeUI::kScreenErrorMessage
, params
);
51 NetworkPortalDetector::Get()->EnableLazyDetection();
52 LOG(WARNING
) << "Offline message is displayed";
55 void ErrorScreenHandler::Hide() {
56 if (parent_screen_
== OobeUI::SCREEN_UNKNOWN
)
58 std::string screen_name
;
59 if (GetScreenName(parent_screen_
, &screen_name
))
60 ShowScreen(screen_name
.c_str(), NULL
);
61 NetworkPortalDetector::Get()->DisableLazyDetection();
62 LOG(WARNING
) << "Offline message is hidden";
65 void ErrorScreenHandler::FixCaptivePortal() {
66 if (!captive_portal_window_proxy_
.get()) {
67 content::WebContents
* web_contents
=
68 LoginDisplayHostImpl::default_host()->GetWebUILoginView()->
70 captive_portal_window_proxy_
.reset(
71 new CaptivePortalWindowProxy(network_state_informer_
.get(),
74 captive_portal_window_proxy_
->ShowIfRedirected();
77 void ErrorScreenHandler::ShowCaptivePortal() {
78 // This call is an explicit user action
79 // i.e. clicking on link so force dialog show.
81 captive_portal_window_proxy_
->Show();
84 void ErrorScreenHandler::HideCaptivePortal() {
85 if (captive_portal_window_proxy_
.get())
86 captive_portal_window_proxy_
->Close();
89 void ErrorScreenHandler::SetUIState(ErrorScreen::UIState ui_state
) {
92 CallJS("setUIState", static_cast<int>(ui_state_
));
95 void ErrorScreenHandler::SetErrorState(ErrorScreen::ErrorState error_state
,
96 const std::string
& network
) {
97 error_state_
= error_state
;
100 CallJS("setErrorState", static_cast<int>(error_state_
), network
);
103 void ErrorScreenHandler::AllowGuestSignin(bool allowed
) {
104 guest_signin_allowed_
= allowed
;
106 CallJS("allowGuestSignin", allowed
);
109 void ErrorScreenHandler::AllowOfflineLogin(bool allowed
) {
110 offline_login_allowed_
= allowed
;
112 CallJS("allowOfflineLogin", allowed
);
115 void ErrorScreenHandler::NetworkErrorShown() {
116 content::NotificationService::current()->Notify(
117 chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN
,
118 content::NotificationService::AllSources(),
119 content::NotificationService::NoDetails());
122 bool ErrorScreenHandler::GetScreenName(OobeUI::Screen screen
,
123 std::string
* name
) const {
124 OobeUI
* oobe_ui
= static_cast<OobeUI
*>(web_ui()->GetController());
127 *name
= oobe_ui
->GetScreenName(screen
);
131 void ErrorScreenHandler::HandleShowCaptivePortal() {
135 void ErrorScreenHandler::HandleHideCaptivePortal() {
139 void ErrorScreenHandler::HandleLocalStateErrorPowerwashButtonClicked() {
140 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
144 void ErrorScreenHandler::HandleRebootButtonClicked() {
145 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
148 void ErrorScreenHandler::RegisterMessages() {
149 AddCallback("showCaptivePortal",
150 &ErrorScreenHandler::HandleShowCaptivePortal
);
151 AddCallback("hideCaptivePortal",
152 &ErrorScreenHandler::HandleHideCaptivePortal
);
153 AddCallback("localStateErrorPowerwashButtonClicked",
154 &ErrorScreenHandler::HandleLocalStateErrorPowerwashButtonClicked
);
155 AddCallback("rebootButtonClicked",
156 &ErrorScreenHandler::HandleRebootButtonClicked
);
159 void ErrorScreenHandler::DeclareLocalizedValues(
160 LocalizedValuesBuilder
* builder
) {
161 builder
->Add("loginErrorTitle", IDS_LOGIN_ERROR_TITLE
);
162 builder
->Add("signinOfflineMessageBody", IDS_LOGIN_OFFLINE_MESSAGE
);
163 builder
->Add("kioskOfflineMessageBody", IDS_KIOSK_OFFLINE_MESSAGE
);
164 builder
->Add("captivePortalTitle", IDS_LOGIN_MAYBE_CAPTIVE_PORTAL_TITLE
);
165 builder
->Add("captivePortalMessage", IDS_LOGIN_MAYBE_CAPTIVE_PORTAL
);
166 builder
->Add("captivePortalProxyMessage",
167 IDS_LOGIN_MAYBE_CAPTIVE_PORTAL_PROXY
);
168 builder
->Add("captivePortalNetworkSelect",
169 IDS_LOGIN_MAYBE_CAPTIVE_PORTAL_NETWORK_SELECT
);
170 builder
->Add("signinProxyMessageText", IDS_LOGIN_PROXY_ERROR_MESSAGE
);
171 builder
->Add("updateOfflineMessageBody", IDS_UPDATE_OFFLINE_MESSAGE
);
172 builder
->Add("updateProxyMessageText", IDS_UPDATE_PROXY_ERROR_MESSAGE
);
173 builder
->AddF("localStateErrorText0", IDS_LOCAL_STATE_ERROR_TEXT_0
,
174 IDS_SHORT_PRODUCT_NAME
);
175 builder
->Add("localStateErrorText1", IDS_LOCAL_STATE_ERROR_TEXT_1
);
176 builder
->Add("localStateErrorPowerwashButton",
177 IDS_LOCAL_STATE_ERROR_POWERWASH_BUTTON
);
178 builder
->Add("rebootButton", IDS_RELAUNCH_BUTTON
);
181 void ErrorScreenHandler::Initialize() {
182 if (!page_is_ready())
185 base::DictionaryValue params
;
186 params
.SetInteger("uiState", static_cast<int>(ui_state_
));
187 params
.SetInteger("errorState", static_cast<int>(error_state_
));
188 params
.SetString("network", network_
);
189 params
.SetBoolean("guestSigninAllowed", guest_signin_allowed_
);
190 params
.SetBoolean("offlineLoginAllowed", offline_login_allowed_
);
191 Show(parent_screen_
, ¶ms
);
192 show_on_init_
= false;
196 } // namespace chromeos