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

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

Issue 2512473004: cros: Enable WebUILoginView reuse. (Closed)
Patch Set: Initial upload 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/login/ui/login_display_host_impl.h" 22 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
23 #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h" 23 #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h"
24 #include "chrome/browser/chromeos/login/ui/shared_web_view.h"
25 #include "chrome/browser/chromeos/login/ui/shared_web_view_factory.h"
24 #include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h" 26 #include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h"
25 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" 27 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
26 #include "chrome/browser/chromeos/profiles/profile_helper.h" 28 #include "chrome/browser/chromeos/profiles/profile_helper.h"
27 #include "chrome/browser/chromeos/settings/cros_settings.h" 29 #include "chrome/browser/chromeos/settings/cros_settings.h"
28 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 30 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
29 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 31 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
30 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" 32 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h"
31 #include "chrome/browser/password_manager/chrome_password_manager_client.h" 33 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
32 #include "chrome/browser/renderer_preferences_util.h" 34 #include "chrome/browser/renderer_preferences_util.h"
33 #include "chrome/browser/sessions/session_tab_helper.h" 35 #include "chrome/browser/sessions/session_tab_helper.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 170
169 private: 171 private:
170 WebUILoginView* const webui_login_view_; 172 WebUILoginView* const webui_login_view_;
171 views::FocusSearch status_area_focus_search_; 173 views::FocusSearch status_area_focus_search_;
172 174
173 DISALLOW_COPY_AND_ASSIGN(StatusAreaFocusTraversable); 175 DISALLOW_COPY_AND_ASSIGN(StatusAreaFocusTraversable);
174 }; 176 };
175 177
176 // WebUILoginView public: ------------------------------------------------------ 178 // WebUILoginView public: ------------------------------------------------------
177 179
178 WebUILoginView::WebUILoginView() { 180 WebUILoginView::WebUILoginView(const WebViewSettings& settings)
181 : settings_(settings) {
179 registrar_.Add(this, 182 registrar_.Add(this,
180 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, 183 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
181 content::NotificationService::AllSources()); 184 content::NotificationService::AllSources());
182 registrar_.Add(this, 185 registrar_.Add(this,
183 chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN, 186 chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN,
184 content::NotificationService::AllSources()); 187 content::NotificationService::AllSources());
185 188
186 accel_map_[ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)] = 189 accel_map_[ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)] =
187 kAccelNameCancel; 190 kAccelNameCancel;
188 accel_map_[ui::Accelerator(ui::VKEY_E, 191 accel_map_[ui::Accelerator(ui::VKEY_E,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 views::Widget* tray_widget = 245 views::Widget* tray_widget =
243 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget(); 246 ash::Shell::GetInstance()->GetPrimarySystemTray()->GetWidget();
244 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = 247 ash::StatusAreaWidgetDelegate* status_area_widget_delegate =
245 static_cast<ash::StatusAreaWidgetDelegate*>( 248 static_cast<ash::StatusAreaWidgetDelegate*>(
246 tray_widget->GetContentsView()); 249 tray_widget->GetContentsView());
247 status_area_widget_delegate->set_custom_focus_traversable(nullptr); 250 status_area_widget_delegate->set_custom_focus_traversable(nullptr);
248 status_area_widget_delegate->set_default_last_focusable_child(false); 251 status_area_widget_delegate->set_default_last_focusable_child(false);
249 } else { 252 } else {
250 NOTIMPLEMENTED(); 253 NOTIMPLEMENTED();
251 } 254 }
255
256 if (is_reusing_webview_)
xiyuan 2016/12/09 22:37:30 We would skip Oobe.teardown if |webui_login_| is c
jdufault 2016/12/12 18:23:09 Good catch, thanks.
257 GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.teardown");
252 } 258 }
253 259
254 void WebUILoginView::Init() { 260 // static
255 Profile* signin_profile = ProfileHelper::GetSigninProfile(); 261 void WebUILoginView::InitializeWebView(views::WebView* web_view) {
256 webui_login_ = new views::WebView(signin_profile); 262 WebContents* web_contents = web_view->GetWebContents();
257 webui_login_->set_allow_accelerators(true);
258 AddChildView(webui_login_);
259 263
260 WebContents* web_contents = webui_login_->GetWebContents(); 264 WebContentsSetBackgroundColor::CreateForWebContentsWithColor(
265 web_contents, SK_ColorTRANSPARENT);
261 266
262 // Ensure that the login UI has a tab ID, which will allow the GAIA auth 267 // Ensure that the login UI has a tab ID, which will allow the GAIA auth
263 // extension's background script to tell it apart from a captive portal window 268 // extension's background script to tell it apart from a captive portal window
264 // that may be opened on top of this UI. 269 // that may be opened on top of this UI.
265 SessionTabHelper::CreateForWebContents(web_contents); 270 SessionTabHelper::CreateForWebContents(web_contents);
266 271
267 // Create the password manager that is needed for the proxy. 272 // Create the password manager that is needed for the proxy.
268 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( 273 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
269 web_contents, 274 web_contents,
270 autofill::ChromeAutofillClient::FromWebContents(web_contents)); 275 autofill::ChromeAutofillClient::FromWebContents(web_contents));
271 276
272 // LoginHandlerViews uses a constrained window for the password manager view. 277 // LoginHandlerViews uses a constrained window for the password manager view.
273 WebContentsModalDialogManager::CreateForWebContents(web_contents); 278 WebContentsModalDialogManager::CreateForWebContents(web_contents);
274 WebContentsModalDialogManager::FromWebContents(web_contents)->
275 SetDelegate(this);
276 279
277 web_contents->SetDelegate(this);
278 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT); 280 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT);
279 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( 281 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
280 web_contents); 282 web_contents);
281 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); 283 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs();
282 renderer_preferences_util::UpdateFromSystemSettings( 284 renderer_preferences_util::UpdateFromSystemSettings(
283 prefs, signin_profile, web_contents); 285 prefs, ProfileHelper::GetSigninProfile(), web_contents);
286 }
287
288 void WebUILoginView::Init() {
289 Profile* signin_profile = ProfileHelper::GetSigninProfile();
290
291 if (!settings_.preloaded_url.is_empty()) {
292 SharedWebView* shared_web_view =
293 SharedWebViewFactory::GetForProfile(signin_profile);
294 webview_usage_handle_ =
295 base::MakeUnique<SharedWebViewUsageHandle>(shared_web_view);
296 is_reusing_webview_ =
297 shared_web_view->Get(settings_.preloaded_url, &webui_login_);
298 } else {
299 webui_login_ = new views::WebView(signin_profile);
300 is_reusing_webview_ = false;
301 }
302
303 WebContents* web_contents = webui_login_->GetWebContents();
304 if (!is_reusing_webview_)
305 InitializeWebView(webui_login_);
306
307 webui_login_->set_allow_accelerators(true);
308 AddChildView(webui_login_);
309
310 WebContentsModalDialogManager::FromWebContents(web_contents)
311 ->SetDelegate(this);
312 web_contents->SetDelegate(this);
xiyuan 2016/12/09 22:37:30 Clear these two delegate in dtor just in case?
jdufault 2016/12/12 18:23:09 Done.
284 313
285 status_area_widget_host_ = new views::View; 314 status_area_widget_host_ = new views::View;
286 AddChildView(status_area_widget_host_); 315 AddChildView(status_area_widget_host_);
287 } 316 }
288 317
289 const char* WebUILoginView::GetClassName() const { 318 const char* WebUILoginView::GetClassName() const {
290 return kViewClassName; 319 return kViewClassName;
291 } 320 }
292 321
293 void WebUILoginView::RequestFocus() { 322 void WebUILoginView::RequestFocus() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 accel_name); 370 accel_name);
342 } 371 }
343 372
344 return true; 373 return true;
345 } 374 }
346 375
347 gfx::NativeWindow WebUILoginView::GetNativeWindow() const { 376 gfx::NativeWindow WebUILoginView::GetNativeWindow() const {
348 return GetWidget()->GetNativeWindow(); 377 return GetWidget()->GetNativeWindow();
349 } 378 }
350 379
351 void WebUILoginView::LoadURL(const GURL & url) { 380 void WebUILoginView::LoadURL(const GURL& url) {
352 webui_login_->LoadInitialURL(url); 381 // If a preloaded_url is provided then |url| must match it.
382 DCHECK(settings_.preloaded_url.is_empty() || url == settings_.preloaded_url);
383
384 if (is_reusing_webview_ && !settings_.preloaded_url.is_empty())
385 GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.reload");
386 else
387 webui_login_->LoadInitialURL(url);
353 webui_login_->RequestFocus(); 388 webui_login_->RequestFocus();
354 389
355 WebContentsSetBackgroundColor::CreateForWebContentsWithColor(
356 GetWebContents(), SK_ColorTRANSPARENT);
357
358 // There is no Shell instance while running in mash. 390 // There is no Shell instance while running in mash.
359 if (chrome::IsRunningInMash()) 391 if (chrome::IsRunningInMash())
360 return; 392 return;
361 393
362 ash::StatusAreaWidgetDelegate* status_area_widget_delegate = 394 ash::StatusAreaWidgetDelegate* status_area_widget_delegate =
363 GetStatusAreaWidgetDelegate(); 395 GetStatusAreaWidgetDelegate();
364 DCHECK(status_area_widget_delegate); 396 DCHECK(status_area_widget_delegate);
365 cycle_focus_traversable_.reset(new CycleFocusTraversable(this)); 397 cycle_focus_traversable_.reset(new CycleFocusTraversable(this));
366 status_area_focus_traversable_.reset( 398 status_area_focus_traversable_.reset(
367 new StatusAreaFocusTraversable(status_area_widget_delegate, this)); 399 new StatusAreaFocusTraversable(status_area_widget_delegate, this));
368 status_area_widget_delegate->set_custom_focus_traversable( 400 status_area_widget_delegate->set_custom_focus_traversable(
369 status_area_focus_traversable_.get()); 401 status_area_focus_traversable_.get());
370 } 402 }
371 403
372 content::WebUI* WebUILoginView::GetWebUI() { 404 content::WebUI* WebUILoginView::GetWebUI() {
405 if (!webui_login_->web_contents())
406 return nullptr;
xiyuan 2016/12/09 22:37:30 Out of curiosity, this is needed now because we re
jdufault 2016/12/12 18:23:09 Yep.
407
373 return webui_login_->web_contents()->GetWebUI(); 408 return webui_login_->web_contents()->GetWebUI();
374 } 409 }
375 410
376 content::WebContents* WebUILoginView::GetWebContents() { 411 content::WebContents* WebUILoginView::GetWebContents() {
377 return webui_login_->web_contents(); 412 return webui_login_->web_contents();
378 } 413 }
379 414
380 OobeUI* WebUILoginView::GetOobeUI() { 415 OobeUI* WebUILoginView::GetOobeUI() {
416 if (!GetWebUI())
417 return nullptr;
418
381 return static_cast<OobeUI*>(GetWebUI()->GetController()); 419 return static_cast<OobeUI*>(GetWebUI()->GetController());
382 } 420 }
383 421
384 void WebUILoginView::OpenProxySettings() { 422 void WebUILoginView::OpenProxySettings() {
385 const NetworkState* network = 423 const NetworkState* network =
386 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 424 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
387 if (!network) { 425 if (!network) {
388 LOG(ERROR) << "No default network found!"; 426 LOG(ERROR) << "No default network found!";
389 return; 427 return;
390 } 428 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 if (should_emit_login_prompt_visible_) { 647 if (should_emit_login_prompt_visible_) {
610 VLOG(1) << "Login WebUI >> login-prompt-visible"; 648 VLOG(1) << "Login WebUI >> login-prompt-visible";
611 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> 649 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
612 EmitLoginPromptVisible(); 650 EmitLoginPromptVisible();
613 } 651 }
614 652
615 webui_visible_ = true; 653 webui_visible_ = true;
616 } 654 }
617 655
618 } // namespace chromeos 656 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698