Commit 0503199a authored by Alex Ilin's avatar Alex Ilin Committed by Chromium LUCI CQ

[profiles] Extract logic for hosting a dialog from UserManagerView

This refactor removes dependency on UserManagerView from
UserManagerProfileDialogDelegate. This will allow the ProfilePickerView
to host a UserManagerProfileDialog as well.

The dependency is removed by introducing a new
UserManagerProfileDialogHostBase class that also holds common logic for
managing dialogs. ProfilePickerView is going to add
UserManagerProfileDialogHostBase as a base class in a follow-up CL.

Bug: 1156096
Change-Id: Ib9e2a4e5c0c4060c96ab083aca1af71706a25e61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575024
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835137}
parent d4eeecad
...@@ -2868,6 +2868,8 @@ static_library("ui") { ...@@ -2868,6 +2868,8 @@ static_library("ui") {
"views/profiles/profile_picker_view_sync_delegate.h", "views/profiles/profile_picker_view_sync_delegate.h",
"views/profiles/user_manager_profile_dialog_delegate.cc", "views/profiles/user_manager_profile_dialog_delegate.cc",
"views/profiles/user_manager_profile_dialog_delegate.h", "views/profiles/user_manager_profile_dialog_delegate.h",
"views/profiles/user_manager_profile_dialog_host.cc",
"views/profiles/user_manager_profile_dialog_host.h",
"views/profiles/user_manager_view.cc", "views/profiles/user_manager_view.cc",
"views/profiles/user_manager_view.h", "views/profiles/user_manager_view.h",
"webui/app_launcher_page_ui.cc", "webui/app_launcher_page_ui.cc",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "chrome/browser/password_manager/chrome_password_manager_client.h" #include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h" #include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/browser/ui/views/profiles/user_manager_profile_dialog_host.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/web_modal/modal_dialog_host.h" #include "components/web_modal/modal_dialog_host.h"
...@@ -17,10 +18,10 @@ ...@@ -17,10 +18,10 @@
#include "ui/views/view.h" #include "ui/views/view.h"
UserManagerProfileDialogDelegate::UserManagerProfileDialogDelegate( UserManagerProfileDialogDelegate::UserManagerProfileDialogDelegate(
UserManagerView* parent, UserManagerProfileDialogHost* host,
std::unique_ptr<views::WebView> web_view, std::unique_ptr<views::WebView> web_view,
const GURL& url) const GURL& url)
: parent_(parent) { : host_(host) {
SetHasWindowSizeControls(true); SetHasWindowSizeControls(true);
SetTitle(IDS_PROFILES_GAIA_SIGNIN_TITLE); SetTitle(IDS_PROFILES_GAIA_SIGNIN_TITLE);
SetButtons(ui::DIALOG_BUTTON_NONE); SetButtons(ui::DIALOG_BUTTON_NONE);
...@@ -103,8 +104,8 @@ void UserManagerProfileDialogDelegate::CloseDialog() { ...@@ -103,8 +104,8 @@ void UserManagerProfileDialogDelegate::CloseDialog() {
} }
void UserManagerProfileDialogDelegate::OnDialogDestroyed() { void UserManagerProfileDialogDelegate::OnDialogDestroyed() {
if (parent_) { if (host_) {
parent_->OnDialogDestroyed(); host_->OnDialogDestroyed();
parent_ = nullptr; host_ = nullptr;
} }
} }
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
#define CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_DELEGATE_H_ #define CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_DELEGATE_H_
#include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h" #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
#include "chrome/browser/ui/views/profiles/user_manager_view.h" #include "chrome/browser/ui/user_manager.h"
#include "components/web_modal/web_contents_modal_dialog_host.h" #include "components/web_modal/web_contents_modal_dialog_host.h"
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/window/dialog_delegate.h"
class GURL; class GURL;
class UserManagerProfileDialogHost;
namespace views { namespace views {
class WebView; class WebView;
...@@ -34,7 +35,7 @@ class UserManagerProfileDialogDelegate ...@@ -34,7 +35,7 @@ class UserManagerProfileDialogDelegate
public ChromeWebModalDialogManagerDelegate, public ChromeWebModalDialogManagerDelegate,
public web_modal::WebContentsModalDialogHost { public web_modal::WebContentsModalDialogHost {
public: public:
UserManagerProfileDialogDelegate(UserManagerView* parent, UserManagerProfileDialogDelegate(UserManagerProfileDialogHost* host,
std::unique_ptr<views::WebView> web_view, std::unique_ptr<views::WebView> web_view,
const GURL& url); const GURL& url);
~UserManagerProfileDialogDelegate() override; ~UserManagerProfileDialogDelegate() override;
...@@ -72,7 +73,7 @@ class UserManagerProfileDialogDelegate ...@@ -72,7 +73,7 @@ class UserManagerProfileDialogDelegate
void DeleteDelegate() override; void DeleteDelegate() override;
views::View* GetInitiallyFocusedView() override; views::View* GetInitiallyFocusedView() override;
UserManagerView* parent_; // Not owned. UserManagerProfileDialogHost* host_; // Not owned.
views::WebView* web_view_; // Owned by the view hierarchy. views::WebView* web_view_; // Owned by the view hierarchy.
}; };
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/profiles/user_manager_profile_dialog_host.h"
#include "chrome/browser/ui/views/profiles/user_manager_profile_dialog_delegate.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/window/dialog_delegate.h"
#include "url/gurl.h"
UserManagerProfileDialogHost::UserManagerProfileDialogHost() = default;
void UserManagerProfileDialogHost::ShowDialog(
content::BrowserContext* browser_context,
const GURL& url,
gfx::NativeView parent) {
HideDialog();
auto delegate = std::make_unique<UserManagerProfileDialogDelegate>(
this, std::make_unique<views::WebView>(browser_context), url);
delegate_ = delegate.get();
views::DialogDelegate::CreateDialogWidget(std::move(delegate), nullptr,
parent);
delegate_->GetWidget()->Show();
}
void UserManagerProfileDialogHost::HideDialog() {
if (delegate_) {
delegate_->CloseDialog();
DCHECK(!delegate_);
}
}
void UserManagerProfileDialogHost::OnDialogDestroyed() {
delegate_ = nullptr;
}
void UserManagerProfileDialogHost::DisplayErrorMessage() {
if (delegate_)
delegate_->DisplayErrorMessage();
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_HOST_H_
#define CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_HOST_H_
#include "ui/gfx/native_widget_types.h"
class GURL;
class UserManagerProfileDialogDelegate;
namespace content {
class BrowserContext;
}
// Class encapsulating logic for views willing to host
// UserManagerProfileDialogDelegate.
class UserManagerProfileDialogHost {
public:
UserManagerProfileDialogHost();
UserManagerProfileDialogHost(const UserManagerProfileDialogHost&) = delete;
UserManagerProfileDialogHost& operator=(const UserManagerProfileDialogHost&) =
delete;
// Shows a dialog where the user can auth the profile or see the auth error
// message. If a dialog is already shown, this destroys the current dialog and
// creates a new one.
void ShowDialog(content::BrowserContext* browser_context,
const GURL& url,
gfx::NativeView parent);
// Hides the reauth dialog if it is showing.
void HideDialog();
// Displays a sign in error message that is created by Chrome but not GAIA
// without browser window. If the dialog is not currently shown, this does
// nothing.
void DisplayErrorMessage();
private:
friend class UserManagerProfileDialogDelegate;
// Resets delegate_ to nullptr when delegate_ is no longer alive.
void OnDialogDestroyed();
// Owned by the view hierarchy.
UserManagerProfileDialogDelegate* delegate_ = nullptr;
};
#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_HOST_H_
...@@ -200,7 +200,7 @@ void UserManagerProfileDialog::ShowUnlockDialogWithProfilePath( ...@@ -200,7 +200,7 @@ void UserManagerProfileDialog::ShowUnlockDialogWithProfilePath(
signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER,
signin_metrics::Reason::REASON_UNLOCK, email); signin_metrics::Reason::REASON_UNLOCK, email);
g_user_manager_view->SetSigninProfilePath(profile_path); g_user_manager_view->SetSigninProfilePath(profile_path);
g_user_manager_view->ShowDialog(browser_context, email, url); g_user_manager_view->ShowDialog(browser_context, url);
} }
// static // static
...@@ -213,7 +213,7 @@ void UserManagerProfileDialog::ShowForceSigninDialog( ...@@ -213,7 +213,7 @@ void UserManagerProfileDialog::ShowForceSigninDialog(
GURL url = signin::GetEmbeddedPromoURL( GURL url = signin::GetEmbeddedPromoURL(
signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER,
signin_metrics::Reason::REASON_FORCED_SIGNIN_PRIMARY_ACCOUNT, true); signin_metrics::Reason::REASON_FORCED_SIGNIN_PRIMARY_ACCOUNT, true);
g_user_manager_view->ShowDialog(browser_context, std::string(), url); g_user_manager_view->ShowDialog(browser_context, url);
} }
void UserManagerProfileDialog::ShowDialogAndDisplayErrorMessage( void UserManagerProfileDialog::ShowDialogAndDisplayErrorMessage(
...@@ -224,7 +224,7 @@ void UserManagerProfileDialog::ShowDialogAndDisplayErrorMessage( ...@@ -224,7 +224,7 @@ void UserManagerProfileDialog::ShowDialogAndDisplayErrorMessage(
// so that the error page will show the error message that is assoicated with // so that the error page will show the error message that is assoicated with
// the system profile. // the system profile.
g_user_manager_view->SetSigninProfilePath(base::FilePath()); g_user_manager_view->SetSigninProfilePath(base::FilePath());
g_user_manager_view->ShowDialog(browser_context, std::string(), g_user_manager_view->ShowDialog(browser_context,
GURL(chrome::kChromeUISigninErrorURL)); GURL(chrome::kChromeUISigninErrorURL));
} }
...@@ -245,7 +245,6 @@ void UserManagerProfileDialog::HideDialog() { ...@@ -245,7 +245,6 @@ void UserManagerProfileDialog::HideDialog() {
UserManagerView::UserManagerView() UserManagerView::UserManagerView()
: web_view_(nullptr), : web_view_(nullptr),
delegate_(nullptr),
user_manager_started_showing_(base::Time()) { user_manager_started_showing_(base::Time()) {
SetButtons(ui::DIALOG_BUTTON_NONE); SetButtons(ui::DIALOG_BUTTON_NONE);
SetHasWindowSizeControls(true); SetHasWindowSizeControls(true);
...@@ -281,27 +280,17 @@ void UserManagerView::OnSystemProfileCreated( ...@@ -281,27 +280,17 @@ void UserManagerView::OnSystemProfileCreated(
} }
void UserManagerView::ShowDialog(content::BrowserContext* browser_context, void UserManagerView::ShowDialog(content::BrowserContext* browser_context,
const std::string& email,
const GURL& url) { const GURL& url) {
HideDialog(); gfx::NativeView parent = GetWidget()->GetNativeView();
// The dialog delegate will be deleted when the widget closes. The created dialog_host_.ShowDialog(browser_context, url, parent);
// WebView's lifetime is managed by the delegate.
delegate_ = new UserManagerProfileDialogDelegate(
this, std::make_unique<views::WebView>(browser_context), url);
gfx::NativeView parent = g_user_manager_view->GetWidget()->GetNativeView();
views::DialogDelegate::CreateDialogWidget(delegate_, nullptr, parent);
delegate_->GetWidget()->Show();
} }
void UserManagerView::HideDialog() { void UserManagerView::HideDialog() {
if (delegate_) { dialog_host_.HideDialog();
delegate_->CloseDialog();
DCHECK(!delegate_);
}
} }
void UserManagerView::OnDialogDestroyed() { void UserManagerView::DisplayErrorMessage() {
delegate_ = nullptr; dialog_host_.DisplayErrorMessage();
} }
void UserManagerView::Init(Profile* system_profile, const GURL& url) { void UserManagerView::Init(Profile* system_profile, const GURL& url) {
...@@ -410,11 +399,6 @@ void UserManagerView::WindowClosing() { ...@@ -410,11 +399,6 @@ void UserManagerView::WindowClosing() {
g_user_manager_view = nullptr; g_user_manager_view = nullptr;
} }
void UserManagerView::DisplayErrorMessage() {
if (delegate_)
delegate_->DisplayErrorMessage();
}
void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) { void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) {
signin_profile_path_ = profile_path; signin_profile_path_ = profile_path;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_window.h" #include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/ui/user_manager.h" #include "chrome/browser/ui/user_manager.h"
#include "chrome/browser/ui/views/profiles/user_manager_profile_dialog_host.h"
#include "components/signin/public/base/signin_metrics.h" #include "components/signin/public/base/signin_metrics.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/window/dialog_delegate.h"
...@@ -49,14 +50,14 @@ class UserManagerView : public views::DialogDelegateView { ...@@ -49,14 +50,14 @@ class UserManagerView : public views::DialogDelegateView {
// Hides the reauth dialog if it is showing. // Hides the reauth dialog if it is showing.
void HideDialog(); void HideDialog();
// Show a dialog where the user can auth the profile or see the auth error // Shows a dialog where the user can auth the profile or see the auth error
// message. // message. If a dialog is already shown, this destroys the current dialog and
void ShowDialog(content::BrowserContext* browser_context, // creates a new one.
const std::string& email, void ShowDialog(content::BrowserContext* browser_context, const GURL& url);
const GURL& url);
// Display sign in error message that is created by Chrome but not GAIA // Displays sign in error message that is created by Chrome but not GAIA
// without browser window. // without browser window. If the dialog is not currently shown, this does
// nothing.
void DisplayErrorMessage(); void DisplayErrorMessage();
// Setter and getter of the path of profile which is selected in user manager // Setter and getter of the path of profile which is selected in user manager
...@@ -70,9 +71,6 @@ class UserManagerView : public views::DialogDelegateView { ...@@ -70,9 +71,6 @@ class UserManagerView : public views::DialogDelegateView {
~UserManagerView() override; ~UserManagerView() override;
// Resets delegate_ to nullptr when delegate_ is no longer alive.
void OnDialogDestroyed();
// Creates dialog and initializes UI. // Creates dialog and initializes UI.
void Init(Profile* guest_profile, const GURL& url); void Init(Profile* guest_profile, const GURL& url);
...@@ -85,13 +83,13 @@ class UserManagerView : public views::DialogDelegateView { ...@@ -85,13 +83,13 @@ class UserManagerView : public views::DialogDelegateView {
views::WebView* web_view_; views::WebView* web_view_;
UserManagerProfileDialogDelegate* delegate_;
std::unique_ptr<ScopedKeepAlive> keep_alive_; std::unique_ptr<ScopedKeepAlive> keep_alive_;
base::Time user_manager_started_showing_; base::Time user_manager_started_showing_;
base::FilePath signin_profile_path_; base::FilePath signin_profile_path_;
UserManagerProfileDialogHost dialog_host_;
DISALLOW_COPY_AND_ASSIGN(UserManagerView); DISALLOW_COPY_AND_ASSIGN(UserManagerView);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment