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

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

Issue 2610373002: cros: Only preload the lock screen; do not reuse it. (Closed)
Patch Set: Address comments Created 3 years, 11 months 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/preloaded_web_view.h"
25 #include "chrome/browser/chromeos/login/ui/preloaded_web_view_factory.h"
24 #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h" 26 #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"
27 #include "chrome/browser/chromeos/login/ui/web_contents_forced_title.h" 27 #include "chrome/browser/chromeos/login/ui/web_contents_forced_title.h"
28 #include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h" 28 #include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h"
29 #include "chrome/browser/chromeos/login/ui/web_view_handle.h"
30 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" 29 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
31 #include "chrome/browser/chromeos/profiles/profile_helper.h" 30 #include "chrome/browser/chromeos/profiles/profile_helper.h"
32 #include "chrome/browser/chromeos/settings/cros_settings.h" 31 #include "chrome/browser/chromeos/settings/cros_settings.h"
33 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 32 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
34 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 33 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
35 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" 34 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h"
36 #include "chrome/browser/password_manager/chrome_password_manager_client.h" 35 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
37 #include "chrome/browser/renderer_preferences_util.h" 36 #include "chrome/browser/renderer_preferences_util.h"
38 #include "chrome/browser/sessions/session_tab_helper.h" 37 #include "chrome/browser/sessions/session_tab_helper.h"
39 #include "chrome/browser/ui/ash/ash_util.h" 38 #include "chrome/browser/ui/ash/ash_util.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget(); 250 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget();
252 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = 251 ash::StatusAreaWidgetDelegate* status_area_widget_delegate =
253 static_cast<ash::StatusAreaWidgetDelegate*>( 252 static_cast<ash::StatusAreaWidgetDelegate*>(
254 tray_widget->GetContentsView()); 253 tray_widget->GetContentsView());
255 status_area_widget_delegate->set_custom_focus_traversable(nullptr); 254 status_area_widget_delegate->set_custom_focus_traversable(nullptr);
256 status_area_widget_delegate->set_default_last_focusable_child(false); 255 status_area_widget_delegate->set_default_last_focusable_child(false);
257 } else { 256 } else {
258 NOTIMPLEMENTED(); 257 NOTIMPLEMENTED();
259 } 258 }
260 259
261 // If the WebView is going to be reused, make sure we call teardown.
262 if (!webui_login_->HasOneRef())
263 GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.teardown");
264
265 // Clear any delegates we have set on the WebView. 260 // Clear any delegates we have set on the WebView.
266 WebContents* web_contents = web_view()->GetWebContents(); 261 WebContents* web_contents = web_view()->GetWebContents();
267 WebContentsModalDialogManager::FromWebContents(web_contents) 262 WebContentsModalDialogManager::FromWebContents(web_contents)
268 ->SetDelegate(nullptr); 263 ->SetDelegate(nullptr);
269 web_contents->SetDelegate(nullptr); 264 web_contents->SetDelegate(nullptr);
270 } 265 }
271 266
272 // static 267 // static
273 void WebUILoginView::InitializeWebView(views::WebView* web_view, 268 void WebUILoginView::InitializeWebView(views::WebView* web_view,
274 const base::string16& title) { 269 const base::string16& title) {
(...skipping 22 matching lines...) Expand all
297 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( 292 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
298 web_contents); 293 web_contents);
299 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); 294 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs();
300 renderer_preferences_util::UpdateFromSystemSettings( 295 renderer_preferences_util::UpdateFromSystemSettings(
301 prefs, ProfileHelper::GetSigninProfile(), web_contents); 296 prefs, ProfileHelper::GetSigninProfile(), web_contents);
302 } 297 }
303 298
304 void WebUILoginView::Init() { 299 void WebUILoginView::Init() {
305 Profile* signin_profile = ProfileHelper::GetSigninProfile(); 300 Profile* signin_profile = ProfileHelper::GetSigninProfile();
306 301
307 if (!settings_.preloaded_url.is_empty()) { 302 if (settings_.check_for_preload) {
308 SharedWebView* shared_web_view = 303 PreloadedWebView* preloaded_web_view =
309 SharedWebViewFactory::GetForProfile(signin_profile); 304 PreloadedWebViewFactory::GetForProfile(signin_profile);
310 is_reusing_webview_ = 305 // webui_login_ may still be null after this call if there is no preloaded
311 shared_web_view->Get(settings_.preloaded_url, &webui_login_); 306 // instance.
312 } else { 307 webui_login_ = preloaded_web_view->TryTake();
313 webui_login_ = new WebViewHandle(signin_profile); 308 is_reusing_webview_ = true;
309 }
310
311 if (!webui_login_) {
312 webui_login_ = base::MakeUnique<views::WebView>(signin_profile);
313 webui_login_->set_owned_by_client();
314 is_reusing_webview_ = false; 314 is_reusing_webview_ = false;
315 } 315 }
316 316
317 WebContents* web_contents = web_view()->GetWebContents(); 317 WebContents* web_contents = web_view()->GetWebContents();
318 if (!is_reusing_webview_) 318 if (!is_reusing_webview_)
319 InitializeWebView(web_view(), settings_.web_view_title); 319 InitializeWebView(web_view(), settings_.web_view_title);
320 320
321 web_view()->set_allow_accelerators(true); 321 web_view()->set_allow_accelerators(true);
322 AddChildView(web_view()); 322 AddChildView(web_view());
323 323
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 385 }
386 386
387 return true; 387 return true;
388 } 388 }
389 389
390 gfx::NativeWindow WebUILoginView::GetNativeWindow() const { 390 gfx::NativeWindow WebUILoginView::GetNativeWindow() const {
391 return GetWidget()->GetNativeWindow(); 391 return GetWidget()->GetNativeWindow();
392 } 392 }
393 393
394 void WebUILoginView::LoadURL(const GURL& url) { 394 void WebUILoginView::LoadURL(const GURL& url) {
395 // If a preloaded_url is provided then |url| must match it. 395 if (!is_reusing_webview_)
396 DCHECK(settings_.preloaded_url.is_empty() || url == settings_.preloaded_url);
397
398 if (is_reusing_webview_ && !settings_.preloaded_url.is_empty())
399 GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.reload");
400 else
401 web_view()->LoadInitialURL(url); 396 web_view()->LoadInitialURL(url);
402 web_view()->RequestFocus(); 397 web_view()->RequestFocus();
403 398
404 // There is no Shell instance while running in mash. 399 // There is no Shell instance while running in mash.
405 if (chrome::IsRunningInMash()) 400 if (chrome::IsRunningInMash())
406 return; 401 return;
407 402
408 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = 403 ash::StatusAreaWidgetDelegate* status_area_widget_delegate =
409 GetStatusAreaWidgetDelegate(); 404 GetStatusAreaWidgetDelegate();
410 DCHECK(status_area_widget_delegate); 405 DCHECK(status_area_widget_delegate);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 OnLoginPromptVisible(); 514 OnLoginPromptVisible();
520 registrar_.RemoveAll(); 515 registrar_.RemoveAll();
521 break; 516 break;
522 } 517 }
523 default: 518 default:
524 NOTREACHED() << "Unexpected notification " << type; 519 NOTREACHED() << "Unexpected notification " << type;
525 } 520 }
526 } 521 }
527 522
528 views::WebView* WebUILoginView::web_view() { 523 views::WebView* WebUILoginView::web_view() {
529 return webui_login_->web_view(); 524 return webui_login_.get();
530 } 525 }
531 526
532 // WebUILoginView private: ----------------------------------------------------- 527 // WebUILoginView private: -----------------------------------------------------
533 528
534 bool WebUILoginView::HandleContextMenu( 529 bool WebUILoginView::HandleContextMenu(
535 const content::ContextMenuParams& params) { 530 const content::ContextMenuParams& params) {
536 // Do not show the context menu. 531 // Do not show the context menu.
537 #ifndef NDEBUG 532 #ifndef NDEBUG
538 return false; 533 return false;
539 #else 534 #else
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 if (should_emit_login_prompt_visible_) { 657 if (should_emit_login_prompt_visible_) {
663 VLOG(1) << "Login WebUI >> login-prompt-visible"; 658 VLOG(1) << "Login WebUI >> login-prompt-visible";
664 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> 659 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
665 EmitLoginPromptVisible(); 660 EmitLoginPromptVisible();
666 } 661 }
667 662
668 webui_visible_ = true; 663 webui_visible_ = true;
669 } 664 }
670 665
671 } // namespace chromeos 666 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698