NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / error_screen_handler.cc
blobfd4906ababb77936b4062caa4d69cc48a491f95e
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/app_mode/app_session_lifetime.h"
12 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h"
13 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
14 #include "chrome/browser/chromeos/login/webui_login_view.h"
15 #include "chrome/browser/chromeos/net/network_portal_detector.h"
16 #include "chrome/browser/extensions/component_loader.h"
17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/ui/extensions/application_launch.h"
19 #include "chrome/browser/ui/webui/chromeos/login/native_window_delegate.h"
20 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
21 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/dbus/power_manager_client.h"
23 #include "chromeos/dbus/session_manager_client.h"
24 #include "extensions/browser/extension_system.h"
25 #include "grit/browser_resources.h"
26 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h"
29 namespace {
31 const char kJsScreenPath[] = "login.ErrorMessageScreen";
33 } // namespace
35 namespace chromeos {
37 ErrorScreenHandler::ErrorScreenHandler(
38 const scoped_refptr<NetworkStateInformer>& network_state_informer)
39 : BaseScreenHandler(kJsScreenPath),
40 network_state_informer_(network_state_informer),
41 show_on_init_(false) {
42 DCHECK(network_state_informer_.get());
45 ErrorScreenHandler::~ErrorScreenHandler() {
48 void ErrorScreenHandler::Show(OobeDisplay::Screen parent_screen,
49 base::DictionaryValue* params) {
50 if (!page_is_ready()) {
51 show_on_init_ = true;
52 return;
54 parent_screen_ = parent_screen;
55 ShowScreen(OobeUI::kScreenErrorMessage, params);
56 NetworkErrorShown();
57 NetworkPortalDetector::Get()->EnableLazyDetection();
58 LOG(WARNING) << "Offline message is displayed";
61 void ErrorScreenHandler::Hide() {
62 if (parent_screen_ == OobeUI::SCREEN_UNKNOWN)
63 return;
64 std::string screen_name;
65 if (GetScreenName(parent_screen_, &screen_name))
66 ShowScreen(screen_name.c_str(), NULL);
67 NetworkPortalDetector::Get()->DisableLazyDetection();
68 LOG(WARNING) << "Offline message is hidden";
71 void ErrorScreenHandler::FixCaptivePortal() {
72 if (!captive_portal_window_proxy_.get()) {
73 content::WebContents* web_contents =
74 LoginDisplayHostImpl::default_host()->GetWebUILoginView()->
75 GetWebContents();
76 captive_portal_window_proxy_.reset(
77 new CaptivePortalWindowProxy(network_state_informer_.get(),
78 web_contents));
80 captive_portal_window_proxy_->ShowIfRedirected();
83 void ErrorScreenHandler::ShowCaptivePortal() {
84 // This call is an explicit user action
85 // i.e. clicking on link so force dialog show.
86 FixCaptivePortal();
87 captive_portal_window_proxy_->Show();
90 void ErrorScreenHandler::HideCaptivePortal() {
91 if (captive_portal_window_proxy_.get())
92 captive_portal_window_proxy_->Close();
95 void ErrorScreenHandler::SetUIState(ErrorScreen::UIState ui_state) {
96 ui_state_ = ui_state;
97 if (page_is_ready())
98 CallJS("setUIState", static_cast<int>(ui_state_));
101 void ErrorScreenHandler::SetErrorState(ErrorScreen::ErrorState error_state,
102 const std::string& network) {
103 error_state_ = error_state;
104 network_ = network;
105 if (page_is_ready())
106 CallJS("setErrorState", static_cast<int>(error_state_), network);
109 void ErrorScreenHandler::AllowGuestSignin(bool allowed) {
110 guest_signin_allowed_ = allowed;
111 if (page_is_ready())
112 CallJS("allowGuestSignin", allowed);
115 void ErrorScreenHandler::AllowOfflineLogin(bool allowed) {
116 offline_login_allowed_ = allowed;
117 if (page_is_ready())
118 CallJS("allowOfflineLogin", allowed);
121 void ErrorScreenHandler::NetworkErrorShown() {
122 content::NotificationService::current()->Notify(
123 chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN,
124 content::NotificationService::AllSources(),
125 content::NotificationService::NoDetails());
128 bool ErrorScreenHandler::GetScreenName(OobeUI::Screen screen,
129 std::string* name) const {
130 OobeUI* oobe_ui = static_cast<OobeUI*>(web_ui()->GetController());
131 if (!oobe_ui)
132 return false;
133 *name = oobe_ui->GetScreenName(screen);
134 return true;
137 void ErrorScreenHandler::HandleShowCaptivePortal() {
138 ShowCaptivePortal();
141 void ErrorScreenHandler::HandleHideCaptivePortal() {
142 HideCaptivePortal();
145 void ErrorScreenHandler::HandleLocalStateErrorPowerwashButtonClicked() {
146 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
147 StartDeviceWipe();
150 void ErrorScreenHandler::HandleRebootButtonClicked() {
151 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
154 void ErrorScreenHandler::HandleDiagnoseButtonClicked() {
155 UserManager* user_manager = UserManager::Get();
156 User* user = user_manager->GetActiveUser();
157 Profile* profile = user_manager->GetProfileByUser(user);
159 ExtensionService* extension_service =
160 extensions::ExtensionSystem::Get(profile)->extension_service();
162 std::string extension_id =
163 extension_service->component_loader()->Add(
164 IDR_CONNECTIVITY_DIAGNOSTICS_MANIFEST,
165 base::FilePath(extension_misc::kConnectivityDiagnosticsPath));
167 const extensions::Extension* extension = extension_service->
168 GetExtensionById(extension_id, true);
169 OpenApplication(AppLaunchParams(profile, extension,
170 extensions::LAUNCH_CONTAINER_WINDOW,
171 NEW_WINDOW));
172 InitAppSession(profile, extension_id);
174 user_manager->SessionStarted();
176 LoginDisplayHostImpl::default_host()->Finalize();
179 void ErrorScreenHandler::RegisterMessages() {
180 AddCallback("showCaptivePortal",
181 &ErrorScreenHandler::HandleShowCaptivePortal);
182 AddCallback("hideCaptivePortal",
183 &ErrorScreenHandler::HandleHideCaptivePortal);
184 AddCallback("localStateErrorPowerwashButtonClicked",
185 &ErrorScreenHandler::HandleLocalStateErrorPowerwashButtonClicked);
186 AddCallback("rebootButtonClicked",
187 &ErrorScreenHandler::HandleRebootButtonClicked);
188 AddCallback("diagnoseButtonClicked",
189 &ErrorScreenHandler::HandleDiagnoseButtonClicked);
192 void ErrorScreenHandler::DeclareLocalizedValues(
193 LocalizedValuesBuilder* builder) {
194 builder->Add("loginErrorTitle", IDS_LOGIN_ERROR_TITLE);
195 builder->Add("signinOfflineMessageBody", IDS_LOGIN_OFFLINE_MESSAGE);
196 builder->Add("kioskOfflineMessageBody", IDS_KIOSK_OFFLINE_MESSAGE);
197 builder->Add("captivePortalTitle", IDS_LOGIN_MAYBE_CAPTIVE_PORTAL_TITLE);
198 builder->Add("captivePortalMessage", IDS_LOGIN_MAYBE_CAPTIVE_PORTAL);
199 builder->Add("captivePortalProxyMessage",
200 IDS_LOGIN_MAYBE_CAPTIVE_PORTAL_PROXY);
201 builder->Add("captivePortalNetworkSelect",
202 IDS_LOGIN_MAYBE_CAPTIVE_PORTAL_NETWORK_SELECT);
203 builder->Add("signinProxyMessageText", IDS_LOGIN_PROXY_ERROR_MESSAGE);
204 builder->Add("updateOfflineMessageBody", IDS_UPDATE_OFFLINE_MESSAGE);
205 builder->Add("updateProxyMessageText", IDS_UPDATE_PROXY_ERROR_MESSAGE);
206 builder->AddF("localStateErrorText0", IDS_LOCAL_STATE_ERROR_TEXT_0,
207 IDS_SHORT_PRODUCT_NAME);
208 builder->Add("localStateErrorText1", IDS_LOCAL_STATE_ERROR_TEXT_1);
209 builder->Add("localStateErrorPowerwashButton",
210 IDS_LOCAL_STATE_ERROR_POWERWASH_BUTTON);
211 builder->Add("rebootButton", IDS_RELAUNCH_BUTTON);
212 builder->Add("diagnoseButton", IDS_DIAGNOSE_BUTTON);
215 void ErrorScreenHandler::Initialize() {
216 if (!page_is_ready())
217 return;
218 if (show_on_init_) {
219 base::DictionaryValue params;
220 params.SetInteger("uiState", static_cast<int>(ui_state_));
221 params.SetInteger("errorState", static_cast<int>(error_state_));
222 params.SetString("network", network_);
223 params.SetBoolean("guestSigninAllowed", guest_signin_allowed_);
224 params.SetBoolean("offlineLoginAllowed", offline_login_allowed_);
225 Show(parent_screen_, &params);
226 show_on_init_ = false;
230 } // namespace chromeos