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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/ui/webui_login_view.cc
diff --git a/chrome/browser/chromeos/login/ui/webui_login_view.cc b/chrome/browser/chromeos/login/ui/webui_login_view.cc
index a83d5c8f085fa1988a18c71af55731a1cad655cd..c54a61153e1bc98cceba932d216e7ffb6fb6eb98 100644
--- a/chrome/browser/chromeos/login/ui/webui_login_view.cc
+++ b/chrome/browser/chromeos/login/ui/webui_login_view.cc
@@ -21,6 +21,8 @@
#include "chrome/browser/chromeos/accessibility/accessibility_util.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h"
+#include "chrome/browser/chromeos/login/ui/shared_web_view.h"
+#include "chrome/browser/chromeos/login/ui/shared_web_view_factory.h"
#include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h"
#include "chrome/browser/chromeos/login/ui/webui_login_display.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
@@ -175,7 +177,8 @@ class WebUILoginView::StatusAreaFocusTraversable
// WebUILoginView public: ------------------------------------------------------
-WebUILoginView::WebUILoginView() {
+WebUILoginView::WebUILoginView(const WebViewSettings& settings)
+ : settings_(settings) {
registrar_.Add(this,
chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
content::NotificationService::AllSources());
@@ -249,15 +252,17 @@ WebUILoginView::~WebUILoginView() {
} else {
NOTIMPLEMENTED();
}
+
+ 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.
+ GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.teardown");
}
-void WebUILoginView::Init() {
- Profile* signin_profile = ProfileHelper::GetSigninProfile();
- webui_login_ = new views::WebView(signin_profile);
- webui_login_->set_allow_accelerators(true);
- AddChildView(webui_login_);
+// static
+void WebUILoginView::InitializeWebView(views::WebView* web_view) {
+ WebContents* web_contents = web_view->GetWebContents();
- WebContents* web_contents = webui_login_->GetWebContents();
+ WebContentsSetBackgroundColor::CreateForWebContentsWithColor(
+ web_contents, SK_ColorTRANSPARENT);
// Ensure that the login UI has a tab ID, which will allow the GAIA auth
// extension's background script to tell it apart from a captive portal window
@@ -271,16 +276,40 @@ void WebUILoginView::Init() {
// LoginHandlerViews uses a constrained window for the password manager view.
WebContentsModalDialogManager::CreateForWebContents(web_contents);
- WebContentsModalDialogManager::FromWebContents(web_contents)->
- SetDelegate(this);
- web_contents->SetDelegate(this);
extensions::SetViewType(web_contents, extensions::VIEW_TYPE_COMPONENT);
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
web_contents);
content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs();
renderer_preferences_util::UpdateFromSystemSettings(
- prefs, signin_profile, web_contents);
+ prefs, ProfileHelper::GetSigninProfile(), web_contents);
+}
+
+void WebUILoginView::Init() {
+ Profile* signin_profile = ProfileHelper::GetSigninProfile();
+
+ if (!settings_.preloaded_url.is_empty()) {
+ SharedWebView* shared_web_view =
+ SharedWebViewFactory::GetForProfile(signin_profile);
+ webview_usage_handle_ =
+ base::MakeUnique<SharedWebViewUsageHandle>(shared_web_view);
+ is_reusing_webview_ =
+ shared_web_view->Get(settings_.preloaded_url, &webui_login_);
+ } else {
+ webui_login_ = new views::WebView(signin_profile);
+ is_reusing_webview_ = false;
+ }
+
+ WebContents* web_contents = webui_login_->GetWebContents();
+ if (!is_reusing_webview_)
+ InitializeWebView(webui_login_);
+
+ webui_login_->set_allow_accelerators(true);
+ AddChildView(webui_login_);
+
+ WebContentsModalDialogManager::FromWebContents(web_contents)
+ ->SetDelegate(this);
+ 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.
status_area_widget_host_ = new views::View;
AddChildView(status_area_widget_host_);
@@ -348,12 +377,15 @@ gfx::NativeWindow WebUILoginView::GetNativeWindow() const {
return GetWidget()->GetNativeWindow();
}
-void WebUILoginView::LoadURL(const GURL & url) {
- webui_login_->LoadInitialURL(url);
- webui_login_->RequestFocus();
+void WebUILoginView::LoadURL(const GURL& url) {
+ // If a preloaded_url is provided then |url| must match it.
+ DCHECK(settings_.preloaded_url.is_empty() || url == settings_.preloaded_url);
- WebContentsSetBackgroundColor::CreateForWebContentsWithColor(
- GetWebContents(), SK_ColorTRANSPARENT);
+ if (is_reusing_webview_ && !settings_.preloaded_url.is_empty())
+ GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.reload");
+ else
+ webui_login_->LoadInitialURL(url);
+ webui_login_->RequestFocus();
// There is no Shell instance while running in mash.
if (chrome::IsRunningInMash())
@@ -370,6 +402,9 @@ void WebUILoginView::LoadURL(const GURL & url) {
}
content::WebUI* WebUILoginView::GetWebUI() {
+ if (!webui_login_->web_contents())
+ 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.
+
return webui_login_->web_contents()->GetWebUI();
}
@@ -378,6 +413,9 @@ content::WebContents* WebUILoginView::GetWebContents() {
}
OobeUI* WebUILoginView::GetOobeUI() {
+ if (!GetWebUI())
+ return nullptr;
+
return static_cast<OobeUI*>(GetWebUI()->GetController());
}

Powered by Google App Engine
This is Rietveld 408576698