Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/browser/chromeos/login/ui/webui_login_view.cc

Issue 2512473004: cros: Enable WebUILoginView reuse. (Closed)
Patch Set: Address comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/login/ui/webui_login_view.h" 5 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
6 6
7 #include "ash/common/focus_cycler.h" 7 #include "ash/common/focus_cycler.h"
8 #include "ash/common/system/status_area_widget_delegate.h" 8 #include "ash/common/system/status_area_widget_delegate.h"
9 #include "ash/common/system/tray/system_tray.h" 9 #include "ash/common/system/tray/system_tray.h"
10 #include "ash/common/wm_shell.h" 10 #include "ash/common/wm_shell.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" 21 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
22 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
23 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" 23 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
24 #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h" 24 #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h"
25 #include "chrome/browser/chromeos/login/ui/shared_web_view.h"
26 #include "chrome/browser/chromeos/login/ui/shared_web_view_factory.h"
25 #include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h" 27 #include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h"
28 #include "chrome/browser/chromeos/login/ui/web_view_handle.h"
26 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" 29 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
27 #include "chrome/browser/chromeos/profiles/profile_helper.h" 30 #include "chrome/browser/chromeos/profiles/profile_helper.h"
28 #include "chrome/browser/chromeos/settings/cros_settings.h" 31 #include "chrome/browser/chromeos/settings/cros_settings.h"
29 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 32 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
30 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 33 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
31 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" 34 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h"
32 #include "chrome/browser/password_manager/chrome_password_manager_client.h" 35 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
33 #include "chrome/browser/renderer_preferences_util.h" 36 #include "chrome/browser/renderer_preferences_util.h"
34 #include "chrome/browser/sessions/session_tab_helper.h" 37 #include "chrome/browser/sessions/session_tab_helper.h"
35 #include "chrome/browser/ui/ash/ash_util.h" 38 #include "chrome/browser/ui/ash/ash_util.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 172
170 private: 173 private:
171 WebUILoginView* const webui_login_view_; 174 WebUILoginView* const webui_login_view_;
172 views::FocusSearch status_area_focus_search_; 175 views::FocusSearch status_area_focus_search_;
173 176
174 DISALLOW_COPY_AND_ASSIGN(StatusAreaFocusTraversable); 177 DISALLOW_COPY_AND_ASSIGN(StatusAreaFocusTraversable);
175 }; 178 };
176 179
177 // WebUILoginView public: ------------------------------------------------------ 180 // WebUILoginView public: ------------------------------------------------------
178 181
179 WebUILoginView::WebUILoginView() { 182 WebUILoginView::WebUILoginView(const WebViewSettings& settings)
183 : settings_(settings) {
180 registrar_.Add(this, 184 registrar_.Add(this,
181 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, 185 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
182 content::NotificationService::AllSources()); 186 content::NotificationService::AllSources());
183 registrar_.Add(this, 187 registrar_.Add(this,
184 chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN, 188 chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN,
185 content::NotificationService::AllSources()); 189 content::NotificationService::AllSources());
186 190
187 accel_map_[ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)] = 191 accel_map_[ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)] =
188 kAccelNameCancel; 192 kAccelNameCancel;
189 accel_map_[ui::Accelerator(ui::VKEY_E, 193 accel_map_[ui::Accelerator(ui::VKEY_E,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 views::Widget* tray_widget = 249 views::Widget* tray_widget =
246 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget(); 250 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget();
247 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = 251 ash::StatusAreaWidgetDelegate* status_area_widget_delegate =
248 static_cast<ash::StatusAreaWidgetDelegate*>( 252 static_cast<ash::StatusAreaWidgetDelegate*>(
249 tray_widget->GetContentsView()); 253 tray_widget->GetContentsView());
250 status_area_widget_delegate->set_custom_focus_traversable(nullptr); 254 status_area_widget_delegate->set_custom_focus_traversable(nullptr);
251 status_area_widget_delegate->set_default_last_focusable_child(false); 255 status_area_widget_delegate->set_default_last_focusable_child(false);
252 } else { 256 } else {
253 NOTIMPLEMENTED(); 257 NOTIMPLEMENTED();
254 } 258 }
259
260 // If the WebView is going to be reused, make sure we call teardown.
261 if (!webui_login_->HasOneRef())
262 GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.teardown");
263
264 // Clear any delegates we have set on the WebView.
265 WebContents* web_contents = web_view()->GetWebContents();
266 WebContentsModalDialogManager::FromWebContents(web_contents)
267 ->SetDelegate(nullptr);
268 web_contents->SetDelegate(nullptr);
255 } 269 }
256 270
257 void WebUILoginView::Init() { 271 // static
258 Profile* signin_profile = ProfileHelper::GetSigninProfile(); 272 void WebUILoginView::InitializeWebView(views::WebView* web_view) {
259 webui_login_ = new views::WebView(signin_profile); 273 WebContents* web_contents = web_view->GetWebContents();
260 webui_login_->set_allow_accelerators(true);
261 AddChildView(webui_login_);
262 274
263 WebContents* web_contents = webui_login_->GetWebContents(); 275 WebContentsSetBackgroundColor::CreateForWebContentsWithColor(
276 web_contents, SK_ColorTRANSPARENT);
264 277
265 // Ensure that the login UI has a tab ID, which will allow the GAIA auth 278 // Ensure that the login UI has a tab ID, which will allow the GAIA auth
266 // extension's background script to tell it apart from a captive portal window 279 // extension's background script to tell it apart from a captive portal window
267 // that may be opened on top of this UI. 280 // that may be opened on top of this UI.
268 SessionTabHelper::CreateForWebContents(web_contents); 281 SessionTabHelper::CreateForWebContents(web_contents);
269 282
270 // Create the password manager that is needed for the proxy. 283 // Create the password manager that is needed for the proxy.
271 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( 284 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
272 web_contents, 285 web_contents,
273 autofill::ChromeAutofillClient::FromWebContents(web_contents)); 286 autofill::ChromeAutofillClient::FromWebContents(web_contents));
274 287
275 // LoginHandlerViews uses a constrained window for the password manager view. 288 // LoginHandlerViews uses a constrained window for the password manager view.
276 WebContentsModalDialogManager::CreateForWebContents(web_contents); 289 WebContentsModalDialogManager::CreateForWebContents(web_contents);
277 WebContentsModalDialogManager::FromWebContents(web_contents)->
278 SetDelegate(this);
279 290
280 web_contents->SetDelegate(this);
281 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT); 291 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT);
282 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( 292 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
283 web_contents); 293 web_contents);
284 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); 294 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs();
285 renderer_preferences_util::UpdateFromSystemSettings( 295 renderer_preferences_util::UpdateFromSystemSettings(
286 prefs, signin_profile, web_contents); 296 prefs, ProfileHelper::GetSigninProfile(), web_contents);
297 }
298
299 void WebUILoginView::Init() {
300 Profile* signin_profile = ProfileHelper::GetSigninProfile();
301
302 if (!settings_.preloaded_url.is_empty()) {
303 SharedWebView* shared_web_view =
304 SharedWebViewFactory::GetForProfile(signin_profile);
305 is_reusing_webview_ =
306 shared_web_view->Get(settings_.preloaded_url, &webui_login_);
307 } else {
308 webui_login_ = new WebViewHandle(signin_profile);
309 is_reusing_webview_ = false;
310 }
311
312 WebContents* web_contents = web_view()->GetWebContents();
313 if (!is_reusing_webview_)
314 InitializeWebView(web_view());
315
316 web_view()->set_allow_accelerators(true);
317 AddChildView(web_view());
318
319 WebContentsModalDialogManager::FromWebContents(web_contents)
320 ->SetDelegate(this);
321 web_contents->SetDelegate(this);
287 322
288 status_area_widget_host_ = new views::View; 323 status_area_widget_host_ = new views::View;
289 AddChildView(status_area_widget_host_); 324 AddChildView(status_area_widget_host_);
290 } 325 }
291 326
292 const char* WebUILoginView::GetClassName() const { 327 const char* WebUILoginView::GetClassName() const {
293 return kViewClassName; 328 return kViewClassName;
294 } 329 }
295 330
296 void WebUILoginView::RequestFocus() { 331 void WebUILoginView::RequestFocus() {
297 webui_login_->RequestFocus(); 332 web_view()->RequestFocus();
298 } 333 }
299 334
300 web_modal::WebContentsModalDialogHost* 335 web_modal::WebContentsModalDialogHost*
301 WebUILoginView::GetWebContentsModalDialogHost() { 336 WebUILoginView::GetWebContentsModalDialogHost() {
302 return this; 337 return this;
303 } 338 }
304 339
305 gfx::NativeView WebUILoginView::GetHostView() const { 340 gfx::NativeView WebUILoginView::GetHostView() const {
306 return GetWidget()->GetNativeView(); 341 return GetWidget()->GetNativeView();
307 } 342 }
(...skipping 19 matching lines...) Expand all
327 web_modal::ModalDialogHostObserver* observer) { 362 web_modal::ModalDialogHostObserver* observer) {
328 observer_list_.RemoveObserver(observer); 363 observer_list_.RemoveObserver(observer);
329 } 364 }
330 365
331 bool WebUILoginView::AcceleratorPressed( 366 bool WebUILoginView::AcceleratorPressed(
332 const ui::Accelerator& accelerator) { 367 const ui::Accelerator& accelerator) {
333 AccelMap::const_iterator entry = accel_map_.find(accelerator); 368 AccelMap::const_iterator entry = accel_map_.find(accelerator);
334 if (entry == accel_map_.end()) 369 if (entry == accel_map_.end())
335 return false; 370 return false;
336 371
337 if (!webui_login_) 372 if (!web_view())
338 return true; 373 return true;
339 374
340 content::WebUI* web_ui = GetWebUI(); 375 content::WebUI* web_ui = GetWebUI();
341 if (web_ui) { 376 if (web_ui) {
342 base::StringValue accel_name(entry->second); 377 base::StringValue accel_name(entry->second);
343 web_ui->CallJavascriptFunctionUnsafe("cr.ui.Oobe.handleAccelerator", 378 web_ui->CallJavascriptFunctionUnsafe("cr.ui.Oobe.handleAccelerator",
344 accel_name); 379 accel_name);
345 } 380 }
346 381
347 return true; 382 return true;
348 } 383 }
349 384
350 gfx::NativeWindow WebUILoginView::GetNativeWindow() const { 385 gfx::NativeWindow WebUILoginView::GetNativeWindow() const {
351 return GetWidget()->GetNativeWindow(); 386 return GetWidget()->GetNativeWindow();
352 } 387 }
353 388
354 void WebUILoginView::LoadURL(const GURL & url) { 389 void WebUILoginView::LoadURL(const GURL& url) {
355 webui_login_->LoadInitialURL(url); 390 // If a preloaded_url is provided then |url| must match it.
356 webui_login_->RequestFocus(); 391 DCHECK(settings_.preloaded_url.is_empty() || url == settings_.preloaded_url);
357 392
358 WebContentsSetBackgroundColor::CreateForWebContentsWithColor( 393 if (is_reusing_webview_ && !settings_.preloaded_url.is_empty())
359 GetWebContents(), SK_ColorTRANSPARENT); 394 GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.reload");
395 else
396 web_view()->LoadInitialURL(url);
397 web_view()->RequestFocus();
360 398
361 // There is no Shell instance while running in mash. 399 // There is no Shell instance while running in mash.
362 if (chrome::IsRunningInMash()) 400 if (chrome::IsRunningInMash())
363 return; 401 return;
364 402
365 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = 403 ash::StatusAreaWidgetDelegate* status_area_widget_delegate =
366 GetStatusAreaWidgetDelegate(); 404 GetStatusAreaWidgetDelegate();
367 DCHECK(status_area_widget_delegate); 405 DCHECK(status_area_widget_delegate);
368 cycle_focus_traversable_.reset(new CycleFocusTraversable(this)); 406 cycle_focus_traversable_.reset(new CycleFocusTraversable(this));
369 status_area_focus_traversable_.reset( 407 status_area_focus_traversable_.reset(
370 new StatusAreaFocusTraversable(status_area_widget_delegate, this)); 408 new StatusAreaFocusTraversable(status_area_widget_delegate, this));
371 status_area_widget_delegate->set_custom_focus_traversable( 409 status_area_widget_delegate->set_custom_focus_traversable(
372 status_area_focus_traversable_.get()); 410 status_area_focus_traversable_.get());
373 } 411 }
374 412
375 content::WebUI* WebUILoginView::GetWebUI() { 413 content::WebUI* WebUILoginView::GetWebUI() {
376 return webui_login_->web_contents()->GetWebUI(); 414 return web_view()->web_contents()->GetWebUI();
377 } 415 }
378 416
379 content::WebContents* WebUILoginView::GetWebContents() { 417 content::WebContents* WebUILoginView::GetWebContents() {
380 return webui_login_->web_contents(); 418 return web_view()->web_contents();
381 } 419 }
382 420
383 OobeUI* WebUILoginView::GetOobeUI() { 421 OobeUI* WebUILoginView::GetOobeUI() {
422 if (!GetWebUI())
423 return nullptr;
424
384 return static_cast<OobeUI*>(GetWebUI()->GetController()); 425 return static_cast<OobeUI*>(GetWebUI()->GetController());
385 } 426 }
386 427
387 void WebUILoginView::OpenProxySettings() { 428 void WebUILoginView::OpenProxySettings() {
388 const NetworkState* network = 429 const NetworkState* network =
389 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 430 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
390 if (!network) { 431 if (!network) {
391 LOG(ERROR) << "No default network found!"; 432 LOG(ERROR) << "No default network found!";
392 return; 433 return;
393 } 434 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // until the UI is enabled again. 476 // until the UI is enabled again.
436 if (!enabled && tray->HasSystemBubble()) 477 if (!enabled && tray->HasSystemBubble())
437 tray->CloseSystemBubble(); 478 tray->CloseSystemBubble();
438 479
439 tray->SetEnabled(enabled); 480 tray->SetEnabled(enabled);
440 } 481 }
441 482
442 // WebUILoginView protected: --------------------------------------------------- 483 // WebUILoginView protected: ---------------------------------------------------
443 484
444 void WebUILoginView::Layout() { 485 void WebUILoginView::Layout() {
445 DCHECK(webui_login_); 486 DCHECK(web_view());
446 webui_login_->SetBoundsRect(bounds()); 487 web_view()->SetBoundsRect(bounds());
447 488
448 for (auto& observer : observer_list_) 489 for (auto& observer : observer_list_)
449 observer.OnPositionRequiresUpdate(); 490 observer.OnPositionRequiresUpdate();
450 } 491 }
451 492
452 void WebUILoginView::OnLocaleChanged() { 493 void WebUILoginView::OnLocaleChanged() {
453 } 494 }
454 495
455 void WebUILoginView::ChildPreferredSizeChanged(View* child) { 496 void WebUILoginView::ChildPreferredSizeChanged(View* child) {
456 Layout(); 497 Layout();
457 SchedulePaint(); 498 SchedulePaint();
458 } 499 }
459 500
460 void WebUILoginView::AboutToRequestFocusFromTabTraversal(bool reverse) { 501 void WebUILoginView::AboutToRequestFocusFromTabTraversal(bool reverse) {
461 // Return the focus to the web contents. 502 // Return the focus to the web contents.
462 webui_login_->web_contents()->FocusThroughTabTraversal(reverse); 503 web_view()->web_contents()->FocusThroughTabTraversal(reverse);
463 GetWidget()->Activate(); 504 GetWidget()->Activate();
464 webui_login_->web_contents()->Focus(); 505 web_view()->web_contents()->Focus();
465 } 506 }
466 507
467 void WebUILoginView::Observe(int type, 508 void WebUILoginView::Observe(int type,
468 const content::NotificationSource& source, 509 const content::NotificationSource& source,
469 const content::NotificationDetails& details) { 510 const content::NotificationDetails& details) {
470 switch (type) { 511 switch (type) {
471 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: 512 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE:
472 case chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN: { 513 case chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN: {
473 OnLoginPromptVisible(); 514 OnLoginPromptVisible();
474 registrar_.RemoveAll(); 515 registrar_.RemoveAll();
475 break; 516 break;
476 } 517 }
477 default: 518 default:
478 NOTREACHED() << "Unexpected notification " << type; 519 NOTREACHED() << "Unexpected notification " << type;
479 } 520 }
480 } 521 }
481 522
523 views::WebView* WebUILoginView::web_view() {
524 return webui_login_->web_view();
525 }
526
482 // WebUILoginView private: ----------------------------------------------------- 527 // WebUILoginView private: -----------------------------------------------------
483 528
484 bool WebUILoginView::HandleContextMenu( 529 bool WebUILoginView::HandleContextMenu(
485 const content::ContextMenuParams& params) { 530 const content::ContextMenuParams& params) {
486 // Do not show the context menu. 531 // Do not show the context menu.
487 #ifndef NDEBUG 532 #ifndef NDEBUG
488 return false; 533 return false;
489 #else 534 #else
490 return true; 535 return true;
491 #endif 536 #endif
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 if (should_emit_login_prompt_visible_) { 657 if (should_emit_login_prompt_visible_) {
613 VLOG(1) << "Login WebUI >> login-prompt-visible"; 658 VLOG(1) << "Login WebUI >> login-prompt-visible";
614 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> 659 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
615 EmitLoginPromptVisible(); 660 EmitLoginPromptVisible();
616 } 661 }
617 662
618 webui_visible_ = true; 663 webui_visible_ = true;
619 } 664 }
620 665
621 } // namespace chromeos 666 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/ui/webui_login_view.h ('k') | chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698