OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handle
r.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handle
r.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 7 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 8 #include "chrome/browser/chromeos/login/screens/error_screen_actor.h" |
8 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 9 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 10 #include "chromeos/network/network_state.h" |
| 11 #include "chromeos/network/network_state_handler.h" |
9 #include "grit/browser_resources.h" | 12 #include "grit/browser_resources.h" |
10 #include "grit/chrome_unscaled_resources.h" | 13 #include "grit/chrome_unscaled_resources.h" |
11 #include "grit/chromium_strings.h" | 14 #include "grit/chromium_strings.h" |
12 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
13 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/base/webui/web_ui_util.h" | 18 #include "ui/base/webui/web_ui_util.h" |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 const char kJsScreenPath[] = "login.AppLaunchSplashScreen"; | 22 const char kJsScreenPath[] = "login.AppLaunchSplashScreen"; |
20 | 23 |
| 24 // Returns network name by service path. |
| 25 std::string GetNetworkName(const std::string& service_path) { |
| 26 const chromeos::NetworkState* network = |
| 27 chromeos::NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
| 28 service_path); |
| 29 if (!network) |
| 30 return std::string(); |
| 31 return network->name(); |
| 32 } |
| 33 |
21 } // namespace | 34 } // namespace |
22 | 35 |
23 namespace chromeos { | 36 namespace chromeos { |
24 | 37 |
25 AppLaunchSplashScreenHandler::AppLaunchSplashScreenHandler() | 38 AppLaunchSplashScreenHandler::AppLaunchSplashScreenHandler( |
| 39 const scoped_refptr<NetworkStateInformer>& network_state_informer, |
| 40 ErrorScreenActor* error_screen_actor) |
26 : BaseScreenHandler(kJsScreenPath), | 41 : BaseScreenHandler(kJsScreenPath), |
27 delegate_(NULL), | 42 delegate_(NULL), |
28 show_on_init_(false), | 43 show_on_init_(false), |
29 state_(APP_LAUNCH_STATE_LOADING_AUTH_FILE) { | 44 state_(APP_LAUNCH_STATE_LOADING_AUTH_FILE), |
| 45 network_state_informer_(network_state_informer), |
| 46 error_screen_actor_(error_screen_actor) { |
| 47 network_state_informer_->AddObserver(this); |
30 } | 48 } |
31 | 49 |
32 AppLaunchSplashScreenHandler::~AppLaunchSplashScreenHandler() { | 50 AppLaunchSplashScreenHandler::~AppLaunchSplashScreenHandler() { |
| 51 network_state_informer_->RemoveObserver(this); |
33 } | 52 } |
34 | 53 |
35 void AppLaunchSplashScreenHandler::DeclareLocalizedValues( | 54 void AppLaunchSplashScreenHandler::DeclareLocalizedValues( |
36 LocalizedValuesBuilder* builder) { | 55 LocalizedValuesBuilder* builder) { |
37 | 56 |
38 builder->Add("appStartMessage", IDS_APP_START_NETWORK_WAIT_MESSAGE); | 57 builder->Add("appStartMessage", IDS_APP_START_NETWORK_WAIT_MESSAGE); |
39 builder->Add("configureNetwork", IDS_APP_START_CONFIGURE_NETWORK); | 58 builder->Add("configureNetwork", IDS_APP_START_CONFIGURE_NETWORK); |
40 | 59 |
41 const string16 product_os_name = | 60 const string16 product_os_name = |
42 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME); | 61 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 115 |
97 void AppLaunchSplashScreenHandler::UpdateAppLaunchState(AppLaunchState state) { | 116 void AppLaunchSplashScreenHandler::UpdateAppLaunchState(AppLaunchState state) { |
98 if (state == state_) | 117 if (state == state_) |
99 return; | 118 return; |
100 | 119 |
101 state_ = state; | 120 state_ = state; |
102 if (page_is_ready()) { | 121 if (page_is_ready()) { |
103 SetLaunchText( | 122 SetLaunchText( |
104 l10n_util::GetStringUTF8(GetProgressMessageFromState(state_))); | 123 l10n_util::GetStringUTF8(GetProgressMessageFromState(state_))); |
105 } | 124 } |
| 125 UpdateState(ErrorScreenActor::ERROR_REASON_UPDATE); |
106 } | 126 } |
107 | 127 |
108 void AppLaunchSplashScreenHandler::SetDelegate( | 128 void AppLaunchSplashScreenHandler::SetDelegate( |
109 AppLaunchSplashScreenHandler::Delegate* delegate) { | 129 AppLaunchSplashScreenHandler::Delegate* delegate) { |
110 delegate_ = delegate; | 130 delegate_ = delegate; |
111 } | 131 } |
112 | 132 |
| 133 void AppLaunchSplashScreenHandler::ShowNetworkConfigureUI() { |
| 134 NetworkStateInformer::State state = network_state_informer_->state(); |
| 135 if (state == NetworkStateInformer::ONLINE) { |
| 136 delegate_->OnNetworkStateChanged(true); |
| 137 return; |
| 138 } |
| 139 |
| 140 const std::string network_path = network_state_informer_->network_path(); |
| 141 const std::string network_name = GetNetworkName(network_path); |
| 142 |
| 143 error_screen_actor_->SetUIState(ErrorScreen::UI_STATE_KIOSK_MODE); |
| 144 error_screen_actor_->AllowGuestSignin(false); |
| 145 error_screen_actor_->AllowOfflineLogin(false); |
| 146 |
| 147 switch (state) { |
| 148 case NetworkStateInformer::CAPTIVE_PORTAL: { |
| 149 error_screen_actor_->SetErrorState( |
| 150 ErrorScreen::ERROR_STATE_PORTAL, network_name); |
| 151 error_screen_actor_->FixCaptivePortal(); |
| 152 |
| 153 break; |
| 154 } |
| 155 case NetworkStateInformer::PROXY_AUTH_REQUIRED: { |
| 156 error_screen_actor_->SetErrorState( |
| 157 ErrorScreen::ERROR_STATE_PROXY, network_name); |
| 158 break; |
| 159 } |
| 160 case NetworkStateInformer::OFFLINE: { |
| 161 error_screen_actor_->SetErrorState( |
| 162 ErrorScreen::ERROR_STATE_OFFLINE, network_name); |
| 163 break; |
| 164 } |
| 165 default: |
| 166 error_screen_actor_->SetErrorState( |
| 167 ErrorScreen::ERROR_STATE_OFFLINE, network_name); |
| 168 NOTREACHED(); |
| 169 break; |
| 170 }; |
| 171 |
| 172 error_screen_actor_->Show(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH, NULL); |
| 173 } |
| 174 |
| 175 void AppLaunchSplashScreenHandler::OnNetworkReady() { |
| 176 // Purposely leave blank because the online case is handled in UpdateState |
| 177 // call below. |
| 178 } |
| 179 |
| 180 void AppLaunchSplashScreenHandler::UpdateState( |
| 181 ErrorScreenActor::ErrorReason reason) { |
| 182 if (!delegate_ || |
| 183 (state_ != APP_LAUNCH_STATE_PREPARING_NETWORK && |
| 184 state_ != APP_LAUNCH_STATE_NETWORK_WAIT_TIMEOUT)) { |
| 185 return; |
| 186 } |
| 187 |
| 188 NetworkStateInformer::State state = network_state_informer_->state(); |
| 189 delegate_->OnNetworkStateChanged(state == NetworkStateInformer::ONLINE); |
| 190 } |
| 191 |
113 void AppLaunchSplashScreenHandler::PopulateAppInfo( | 192 void AppLaunchSplashScreenHandler::PopulateAppInfo( |
114 base::DictionaryValue* out_info) { | 193 base::DictionaryValue* out_info) { |
115 KioskAppManager::App app; | 194 KioskAppManager::App app; |
116 KioskAppManager::Get()->GetApp(app_id_, &app); | 195 KioskAppManager::Get()->GetApp(app_id_, &app); |
117 | 196 |
118 if (app.name.empty()) | 197 if (app.name.empty()) |
119 app.name = l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME); | 198 app.name = l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME); |
120 | 199 |
121 if (app.icon.isNull()) { | 200 if (app.icon.isNull()) { |
122 app.icon = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 201 app.icon = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 237 } |
159 | 238 |
160 void AppLaunchSplashScreenHandler::HandleCancelAppLaunch() { | 239 void AppLaunchSplashScreenHandler::HandleCancelAppLaunch() { |
161 if (delegate_) | 240 if (delegate_) |
162 delegate_->OnCancelAppLaunch(); | 241 delegate_->OnCancelAppLaunch(); |
163 else | 242 else |
164 LOG(WARNING) << "No delegate set to handle cancel app launch"; | 243 LOG(WARNING) << "No delegate set to handle cancel app launch"; |
165 } | 244 } |
166 | 245 |
167 } // namespace chromeos | 246 } // namespace chromeos |
OLD | NEW |