| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/webui_login_display_host.h" | |
| 6 | |
| 7 #include "ash/ash_switches.h" | |
| 8 #include "ash/desktop_background/user_wallpaper_delegate.h" | |
| 9 #include "ash/shell.h" | |
| 10 #include "ash/shell_window_ids.h" | |
| 11 #include "ash/wm/window_animations.h" | |
| 12 #include "ash/wm/window_properties.h" | |
| 13 #include "base/command_line.h" | |
| 14 #include "base/logging.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/time.h" | |
| 17 #include "base/values.h" | |
| 18 #include "chrome/browser/browser_shutdown.h" | |
| 19 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | |
| 20 #include "chrome/browser/chromeos/login/oobe_display.h" | |
| 21 #include "chrome/browser/chromeos/login/startup_utils.h" | |
| 22 #include "chrome/browser/chromeos/login/webui_login_display.h" | |
| 23 #include "chrome/browser/chromeos/login/webui_login_view.h" | |
| 24 #include "chrome/browser/chromeos/login/wizard_controller.h" | |
| 25 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | |
| 26 #include "chrome/common/chrome_notification_types.h" | |
| 27 #include "chrome/common/chrome_switches.h" | |
| 28 #include "content/public/browser/notification_service.h" | |
| 29 #include "content/public/browser/web_contents.h" | |
| 30 #include "content/public/browser/web_contents_view.h" | |
| 31 #include "content/public/browser/web_ui.h" | |
| 32 #include "ui/aura/env.h" | |
| 33 #include "ui/aura/root_window.h" | |
| 34 #include "ui/aura/window.h" | |
| 35 #include "ui/views/widget/widget.h" | |
| 36 | |
| 37 namespace chromeos { | |
| 38 | |
| 39 namespace { | |
| 40 | |
| 41 // URL which corresponds to the login WebUI. | |
| 42 const char kLoginURL[] = "chrome://oobe/login"; | |
| 43 // URL which corresponds to the OOBE WebUI. | |
| 44 const char kOobeURL[] = "chrome://oobe"; | |
| 45 | |
| 46 // Duration of sign-in transition animation. | |
| 47 const int kLoginFadeoutTransitionDurationMs = 700; | |
| 48 | |
| 49 // Number of times we try to reload OOBE/login WebUI if it crashes. | |
| 50 const int kCrashCountLimit = 5; | |
| 51 | |
| 52 // Whether to enable tnitializing WebUI in hidden state (see | |
| 53 // |initialize_webui_hidden_|) by default. | |
| 54 const bool kHiddenWebUIInitializationDefault = true; | |
| 55 | |
| 56 // Switch values that might be used to override WebUI init type. | |
| 57 const char kWebUIInitParallel[] = "parallel"; | |
| 58 const char kWebUIInitPostpone[] = "postpone"; | |
| 59 | |
| 60 } // namespace | |
| 61 | |
| 62 // WebUILoginDisplayHost ------------------------------------------------------- | |
| 63 | |
| 64 WebUILoginDisplayHost::WebUILoginDisplayHost(const gfx::Rect& background_bounds) | |
| 65 : LoginDisplayHostImpl(background_bounds), | |
| 66 login_window_(NULL), | |
| 67 login_view_(NULL), | |
| 68 webui_login_display_(NULL), | |
| 69 is_showing_login_(false), | |
| 70 is_wallpaper_loaded_(false), | |
| 71 status_area_saved_visibility_(false), | |
| 72 crash_count_(0), | |
| 73 restore_path_(RESTORE_UNKNOWN), | |
| 74 old_ignore_solo_window_frame_painter_policy_value_(false) { | |
| 75 bool is_registered = StartupUtils::IsDeviceRegistered(); | |
| 76 bool zero_delay_enabled = WizardController::IsZeroDelayEnabled(); | |
| 77 bool disable_boot_animation = CommandLine::ForCurrentProcess()-> | |
| 78 HasSwitch(switches::kDisableBootAnimation); | |
| 79 bool disable_oobe_animation = CommandLine::ForCurrentProcess()-> | |
| 80 HasSwitch(switches::kDisableOobeAnimation); | |
| 81 | |
| 82 waiting_for_wallpaper_load_ = | |
| 83 !zero_delay_enabled && | |
| 84 (is_registered || !disable_oobe_animation) && | |
| 85 (!is_registered || !disable_boot_animation); | |
| 86 | |
| 87 // For slower hardware we have boot animation disabled so | |
| 88 // we'll be initializing WebUI hidden, waiting for user pods to load and then | |
| 89 // show WebUI at once. | |
| 90 waiting_for_user_pods_ = !zero_delay_enabled && !waiting_for_wallpaper_load_; | |
| 91 | |
| 92 initialize_webui_hidden_ = | |
| 93 kHiddenWebUIInitializationDefault && !zero_delay_enabled; | |
| 94 | |
| 95 is_boot_animation2_enabled_ = waiting_for_wallpaper_load_ && | |
| 96 !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 97 ash::switches::kAshDisableBootAnimation2); | |
| 98 | |
| 99 // Prevents white flashing on OOBE (http://crbug.com/131569). | |
| 100 aura::Env::GetInstance()->set_render_white_bg(false); | |
| 101 | |
| 102 // Check if WebUI init type is overriden. | |
| 103 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshWebUIInit)) { | |
| 104 const std::string override_type = CommandLine::ForCurrentProcess()-> | |
| 105 GetSwitchValueASCII(switches::kAshWebUIInit); | |
| 106 if (override_type == kWebUIInitParallel) | |
| 107 initialize_webui_hidden_ = true; | |
| 108 else if (override_type == kWebUIInitPostpone) | |
| 109 initialize_webui_hidden_ = false; | |
| 110 } | |
| 111 | |
| 112 // Always postpone WebUI initialization on first boot, otherwise we miss | |
| 113 // initial animation. | |
| 114 if (!StartupUtils::IsOobeCompleted()) | |
| 115 initialize_webui_hidden_ = false; | |
| 116 | |
| 117 // There is no wallpaper for KioskMode, don't initialize the webui hidden. | |
| 118 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) | |
| 119 initialize_webui_hidden_ = false; | |
| 120 | |
| 121 if (waiting_for_wallpaper_load_) { | |
| 122 registrar_.Add(this, chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | |
| 123 content::NotificationService::AllSources()); | |
| 124 } | |
| 125 | |
| 126 // In boot-animation2 we want to show login WebUI as soon as possible. | |
| 127 if ((waiting_for_user_pods_ || is_boot_animation2_enabled_) | |
| 128 && initialize_webui_hidden_) { | |
| 129 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, | |
| 130 content::NotificationService::AllSources()); | |
| 131 } | |
| 132 LOG(INFO) << "Login WebUI >> " | |
| 133 << "zero_delay: " << zero_delay_enabled | |
| 134 << " wait_for_wp_load_: " << waiting_for_wallpaper_load_ | |
| 135 << " wait_for_pods_: " << waiting_for_user_pods_ | |
| 136 << " init_webui_hidden_: " << initialize_webui_hidden_; | |
| 137 } | |
| 138 | |
| 139 WebUILoginDisplayHost::~WebUILoginDisplayHost() { | |
| 140 ResetLoginWindowAndView(); | |
| 141 } | |
| 142 | |
| 143 // LoginDisplayHost implementation --------------------------------------------- | |
| 144 | |
| 145 LoginDisplay* WebUILoginDisplayHost::CreateLoginDisplay( | |
| 146 LoginDisplay::Delegate* delegate) { | |
| 147 webui_login_display_ = new WebUILoginDisplay(delegate); | |
| 148 webui_login_display_->set_background_bounds(background_bounds()); | |
| 149 return webui_login_display_; | |
| 150 } | |
| 151 | |
| 152 gfx::NativeWindow WebUILoginDisplayHost::GetNativeWindow() const { | |
| 153 return login_window_ ? login_window_->GetNativeWindow() : NULL; | |
| 154 } | |
| 155 | |
| 156 views::Widget* WebUILoginDisplayHost::GetWidget() const { | |
| 157 return login_window_; | |
| 158 } | |
| 159 | |
| 160 void WebUILoginDisplayHost::OpenProxySettings() { | |
| 161 if (login_view_) | |
| 162 login_view_->OpenProxySettings(); | |
| 163 } | |
| 164 | |
| 165 void WebUILoginDisplayHost::SetOobeProgressBarVisible(bool visible) { | |
| 166 GetOobeUI()->ShowOobeUI(visible); | |
| 167 } | |
| 168 | |
| 169 void WebUILoginDisplayHost::SetShutdownButtonEnabled(bool enable) { | |
| 170 } | |
| 171 | |
| 172 void WebUILoginDisplayHost::SetStatusAreaVisible(bool visible) { | |
| 173 if (initialize_webui_hidden_) | |
| 174 status_area_saved_visibility_ = visible; | |
| 175 else if (login_view_) | |
| 176 login_view_->SetStatusAreaVisible(visible); | |
| 177 } | |
| 178 | |
| 179 void WebUILoginDisplayHost::StartWizard(const std::string& first_screen_name, | |
| 180 DictionaryValue* screen_parameters) { | |
| 181 // Keep parameters to restore if renderer crashes. | |
| 182 restore_path_ = RESTORE_WIZARD; | |
| 183 wizard_first_screen_name_ = first_screen_name; | |
| 184 if (screen_parameters) | |
| 185 wizard_screen_parameters_.reset(screen_parameters->DeepCopy()); | |
| 186 else | |
| 187 wizard_screen_parameters_.reset(NULL); | |
| 188 is_showing_login_ = false; | |
| 189 scoped_ptr<DictionaryValue> scoped_parameters(screen_parameters); | |
| 190 | |
| 191 if (waiting_for_wallpaper_load_ && !initialize_webui_hidden_) { | |
| 192 LOG(INFO) << "Login WebUI >> wizard postponed"; | |
| 193 return; | |
| 194 } | |
| 195 LOG(INFO) << "Login WebUI >> wizard"; | |
| 196 | |
| 197 if (!login_window_) | |
| 198 LoadURL(GURL(kOobeURL)); | |
| 199 | |
| 200 LoginDisplayHostImpl::StartWizard(first_screen_name, | |
| 201 scoped_parameters.release()); | |
| 202 } | |
| 203 | |
| 204 void WebUILoginDisplayHost::StartSignInScreen() { | |
| 205 restore_path_ = RESTORE_SIGN_IN; | |
| 206 is_showing_login_ = true; | |
| 207 | |
| 208 if (waiting_for_wallpaper_load_ && !initialize_webui_hidden_) { | |
| 209 LOG(INFO) << "Login WebUI >> sign in postponed"; | |
| 210 return; | |
| 211 } | |
| 212 LOG(INFO) << "Login WebUI >> sign in"; | |
| 213 | |
| 214 if (!login_window_) | |
| 215 LoadURL(GURL(kLoginURL)); | |
| 216 | |
| 217 LoginDisplayHostImpl::StartSignInScreen(); | |
| 218 CHECK(webui_login_display_); | |
| 219 GetOobeUI()->ShowSigninScreen(webui_login_display_, webui_login_display_); | |
| 220 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) | |
| 221 SetStatusAreaVisible(false); | |
| 222 } | |
| 223 | |
| 224 void WebUILoginDisplayHost::OnPreferencesChanged() { | |
| 225 if (is_showing_login_) | |
| 226 webui_login_display_->OnPreferencesChanged(); | |
| 227 } | |
| 228 | |
| 229 void WebUILoginDisplayHost::OnBrowserCreated() { | |
| 230 // Close lock window now so that the launched browser can receive focus. | |
| 231 ResetLoginWindowAndView(); | |
| 232 } | |
| 233 | |
| 234 void WebUILoginDisplayHost::Observe( | |
| 235 int type, | |
| 236 const content::NotificationSource& source, | |
| 237 const content::NotificationDetails& details) { | |
| 238 if (chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED == type) { | |
| 239 LOG(INFO) << "Login WebUI >> wp animation done"; | |
| 240 is_wallpaper_loaded_ = true; | |
| 241 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | |
| 242 OnWallpaperBootAnimationFinished(); | |
| 243 if (waiting_for_wallpaper_load_) { | |
| 244 // StartWizard / StartSignInScreen could be called multiple times through | |
| 245 // the lifetime of host. | |
| 246 // Make sure that subsequent calls are not postponed. | |
| 247 waiting_for_wallpaper_load_ = false; | |
| 248 if (initialize_webui_hidden_) | |
| 249 ShowWebUI(); | |
| 250 else | |
| 251 StartPostponedWebUI(); | |
| 252 } | |
| 253 registrar_.Remove(this, | |
| 254 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | |
| 255 content::NotificationService::AllSources()); | |
| 256 } else if (chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE == type) { | |
| 257 LOG(INFO) << "Login WebUI >> WEBUI_VISIBLE"; | |
| 258 if (waiting_for_user_pods_ && initialize_webui_hidden_) { | |
| 259 waiting_for_user_pods_ = false; | |
| 260 ShowWebUI(); | |
| 261 } else if (waiting_for_wallpaper_load_ && initialize_webui_hidden_) { | |
| 262 // Reduce time till login UI is shown - show it as soon as possible. | |
| 263 waiting_for_wallpaper_load_ = false; | |
| 264 ShowWebUI(); | |
| 265 } | |
| 266 registrar_.Remove(this, | |
| 267 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, | |
| 268 content::NotificationService::AllSources()); | |
| 269 } else { | |
| 270 LoginDisplayHostImpl::Observe(type, source, details); | |
| 271 } | |
| 272 } | |
| 273 | |
| 274 void WebUILoginDisplayHost::LoadURL(const GURL& url) { | |
| 275 InitLoginWindowAndView(); | |
| 276 // Subscribe to crash events. | |
| 277 content::WebContentsObserver::Observe(login_view_->GetWebContents()); | |
| 278 login_view_->LoadURL(url); | |
| 279 } | |
| 280 | |
| 281 void WebUILoginDisplayHost::RenderViewGone(base::TerminationStatus status) { | |
| 282 // Do not try to restore on shutdown | |
| 283 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) | |
| 284 return; | |
| 285 | |
| 286 crash_count_++; | |
| 287 if (crash_count_ > kCrashCountLimit) | |
| 288 return; | |
| 289 | |
| 290 if (status != base::TERMINATION_STATUS_NORMAL_TERMINATION) { | |
| 291 // Render with login screen crashed. Let's crash browser process to let | |
| 292 // session manager restart it properly. It is hard to reload the page | |
| 293 // and get to controlled state that is fully functional. | |
| 294 // If you see check, search for renderer crash for the same client. | |
| 295 LOG(FATAL) << "Renderer crash on login window"; | |
| 296 } | |
| 297 } | |
| 298 | |
| 299 OobeUI* WebUILoginDisplayHost::GetOobeUI() const { | |
| 300 if (!login_view_) | |
| 301 return NULL; | |
| 302 return static_cast<OobeUI*>(login_view_->GetWebUI()->GetController()); | |
| 303 } | |
| 304 | |
| 305 WizardController* WebUILoginDisplayHost::CreateWizardController() { | |
| 306 // TODO(altimofeev): ensure that WebUI is ready. | |
| 307 OobeDisplay* oobe_display = GetOobeUI(); | |
| 308 return new WizardController(this, oobe_display); | |
| 309 } | |
| 310 | |
| 311 void WebUILoginDisplayHost::ShowWebUI() { | |
| 312 if (!login_window_ || !login_view_) { | |
| 313 NOTREACHED(); | |
| 314 return; | |
| 315 } | |
| 316 LOG(INFO) << "Login WebUI >> Show already initialized UI"; | |
| 317 login_window_->Show(); | |
| 318 login_view_->GetWebContents()->GetView()->Focus(); | |
| 319 login_view_->SetStatusAreaVisible(status_area_saved_visibility_); | |
| 320 login_view_->OnPostponedShow(); | |
| 321 // We should reset this flag to allow changing of status area visibility. | |
| 322 initialize_webui_hidden_ = false; | |
| 323 } | |
| 324 | |
| 325 void WebUILoginDisplayHost::StartPostponedWebUI() { | |
| 326 if (!is_wallpaper_loaded_) { | |
| 327 NOTREACHED(); | |
| 328 return; | |
| 329 } | |
| 330 LOG(INFO) << "Login WebUI >> Init postponed WebUI"; | |
| 331 | |
| 332 // Wallpaper has finished loading before StartWizard/StartSignInScreen has | |
| 333 // been called. In general this should not happen. | |
| 334 // Let go through normal code path when one of those will be called. | |
| 335 if (restore_path_ == RESTORE_UNKNOWN) { | |
| 336 NOTREACHED(); | |
| 337 return; | |
| 338 } | |
| 339 | |
| 340 switch (restore_path_) { | |
| 341 case RESTORE_WIZARD: | |
| 342 StartWizard(wizard_first_screen_name_, | |
| 343 wizard_screen_parameters_.release()); | |
| 344 break; | |
| 345 case RESTORE_SIGN_IN: | |
| 346 StartSignInScreen(); | |
| 347 break; | |
| 348 default: | |
| 349 NOTREACHED(); | |
| 350 break; | |
| 351 } | |
| 352 } | |
| 353 | |
| 354 void WebUILoginDisplayHost::InitLoginWindowAndView() { | |
| 355 if (login_window_) | |
| 356 return; | |
| 357 | |
| 358 views::Widget::InitParams params( | |
| 359 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 360 params.bounds = background_bounds(); | |
| 361 params.show_state = ui::SHOW_STATE_FULLSCREEN; | |
| 362 params.transparent = true; | |
| 363 params.parent = | |
| 364 ash::Shell::GetContainer( | |
| 365 ash::Shell::GetPrimaryRootWindow(), | |
| 366 ash::internal::kShellWindowId_LockScreenContainer); | |
| 367 | |
| 368 login_window_ = new views::Widget; | |
| 369 login_window_->Init(params); | |
| 370 if (login_window_->GetNativeWindow()) { | |
| 371 aura::RootWindow* root = login_window_->GetNativeWindow()->GetRootWindow(); | |
| 372 if (root) { | |
| 373 old_ignore_solo_window_frame_painter_policy_value_ = | |
| 374 root->GetProperty(ash::internal::kIgnoreSoloWindowFramePainterPolicy); | |
| 375 root->SetProperty(ash::internal::kIgnoreSoloWindowFramePainterPolicy, | |
| 376 true); | |
| 377 } | |
| 378 } | |
| 379 login_view_ = new WebUILoginView(); | |
| 380 | |
| 381 login_view_->Init(login_window_); | |
| 382 | |
| 383 views::corewm::SetWindowVisibilityAnimationDuration( | |
| 384 login_window_->GetNativeView(), | |
| 385 base::TimeDelta::FromMilliseconds(kLoginFadeoutTransitionDurationMs)); | |
| 386 views::corewm::SetWindowVisibilityAnimationTransition( | |
| 387 login_window_->GetNativeView(), | |
| 388 views::corewm::ANIMATE_HIDE); | |
| 389 | |
| 390 login_window_->SetContentsView(login_view_); | |
| 391 login_view_->UpdateWindowType(); | |
| 392 | |
| 393 // If WebUI is initialized in hidden state, show it only if we're no | |
| 394 // longer waiting for wallpaper animation/user images loading. Otherwise, | |
| 395 // always show it. | |
| 396 if (!initialize_webui_hidden_ || | |
| 397 (!waiting_for_wallpaper_load_ && !waiting_for_user_pods_)) { | |
| 398 LOG(INFO) << "Login WebUI >> show login wnd on create"; | |
| 399 login_window_->Show(); | |
| 400 } else { | |
| 401 LOG(INFO) << "Login WebUI >> login wnd is hidden on create"; | |
| 402 login_view_->set_is_hidden(true); | |
| 403 } | |
| 404 login_window_->GetNativeView()->SetName("WebUILoginView"); | |
| 405 login_view_->OnWindowCreated(); | |
| 406 } | |
| 407 | |
| 408 void WebUILoginDisplayHost::ResetLoginWindowAndView() { | |
| 409 if (!login_window_) | |
| 410 return; | |
| 411 | |
| 412 if (login_window_->GetNativeWindow()) { | |
| 413 aura::RootWindow* root = login_window_->GetNativeWindow()->GetRootWindow(); | |
| 414 if (root) { | |
| 415 root->SetProperty(ash::internal::kIgnoreSoloWindowFramePainterPolicy, | |
| 416 old_ignore_solo_window_frame_painter_policy_value_); | |
| 417 } | |
| 418 } | |
| 419 login_window_->Close(); | |
| 420 login_window_ = NULL; | |
| 421 login_view_ = NULL; | |
| 422 } | |
| 423 | |
| 424 } // namespace chromeos | |
| OLD | NEW |