Commit 1577ff02 authored by Alex Ilin's avatar Alex Ilin Committed by Chromium LUCI CQ

[profiles] Add dialog support to ProfilePicker

This CL adds several methods to ProfilePicker and ProfilePickerView that
allow the profile picker to display UserManagerProfileDialogs.

Bug: 1156096
Change-Id: I28e4ac97ea878e69b760f32a3e1afb828049d498
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2582060Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835682}
parent defaf22f
...@@ -12,8 +12,15 @@ ...@@ -12,8 +12,15 @@
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "url/gurl.h" #include "url/gurl.h"
class GURL;
namespace base { namespace base {
class CommandLine; class CommandLine;
class FilePath;
} // namespace base
namespace content {
class BrowserContext;
} }
namespace views { namespace views {
...@@ -64,6 +71,25 @@ class ProfilePicker { ...@@ -64,6 +71,25 @@ class ProfilePicker {
// uses the same new profile created by `SwitchToSignIn()`. // uses the same new profile created by `SwitchToSignIn()`.
static void SwitchToSyncConfirmation(); static void SwitchToSyncConfirmation();
// 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.
static void ShowDialog(content::BrowserContext* browser_context,
const GURL& url,
const base::FilePath& profile_path);
// Hides the dialog if it is showing.
static void HideDialog();
// Displays 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.
static void DisplayErrorMessage();
// Getter of the path of profile which is selected in profile picker for force
// signin.
static base::FilePath GetForceSigninProfilePath();
// Hides the profile picker. // Hides the profile picker.
static void Hide(); static void Hide();
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -39,6 +40,7 @@ ...@@ -39,6 +40,7 @@
#include "components/keep_alive_registry/keep_alive_types.h" #include "components/keep_alive_registry/keep_alive_types.h"
#include "components/signin/public/identity_manager/account_info.h" #include "components/signin/public/identity_manager/account_info.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h" #include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/context_menu_params.h" #include "content/public/browser/context_menu_params.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
...@@ -50,6 +52,7 @@ ...@@ -50,6 +52,7 @@
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/view_class_properties.h" #include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "url/gurl.h"
#include "url/url_constants.h" #include "url/url_constants.h"
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -120,6 +123,38 @@ void ProfilePicker::SwitchToSyncConfirmation() { ...@@ -120,6 +123,38 @@ void ProfilePicker::SwitchToSyncConfirmation() {
} }
} }
// static
void ProfilePicker::ShowDialog(content::BrowserContext* browser_context,
const GURL& url,
const base::FilePath& profile_path) {
if (g_profile_picker_view) {
g_profile_picker_view->ShowDialog(browser_context, url, profile_path);
}
}
// static
void ProfilePicker::HideDialog() {
if (g_profile_picker_view) {
g_profile_picker_view->HideDialog();
}
}
// static
void ProfilePicker::DisplayErrorMessage() {
if (g_profile_picker_view) {
g_profile_picker_view->DisplayErrorMessage();
}
}
// static
base::FilePath ProfilePicker::GetForceSigninProfilePath() {
if (g_profile_picker_view) {
return g_profile_picker_view->GetForceSigninProfilePath();
}
return base::FilePath();
}
// static // static
void ProfilePicker::Hide() { void ProfilePicker::Hide() {
if (g_profile_picker_view) if (g_profile_picker_view)
...@@ -658,3 +693,22 @@ void ProfilePickerView::ConfigureAccelerators() { ...@@ -658,3 +693,22 @@ void ProfilePickerView::ConfigureAccelerators() {
} }
#endif // OS_MAC #endif // OS_MAC
} }
void ProfilePickerView::ShowDialog(content::BrowserContext* browser_context,
const GURL& url,
const base::FilePath& profile_path) {
gfx::NativeView parent = GetWidget()->GetNativeView();
dialog_host_.ShowDialog(browser_context, url, profile_path, parent);
}
void ProfilePickerView::HideDialog() {
dialog_host_.HideDialog();
}
void ProfilePickerView::DisplayErrorMessage() {
dialog_host_.DisplayErrorMessage();
}
base::FilePath ProfilePickerView::GetForceSigninProfilePath() {
return dialog_host_.GetForceSigninProfilePath();
}
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/profile_picker.h" #include "chrome/browser/ui/profile_picker.h"
#include "chrome/browser/ui/views/profiles/user_manager_profile_dialog_host.h"
#include "components/keep_alive_registry/scoped_keep_alive.h" #include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
...@@ -18,6 +19,10 @@ ...@@ -18,6 +19,10 @@
struct AccountInfo; struct AccountInfo;
class Browser; class Browser;
namespace base {
class FilePath;
}
namespace content { namespace content {
struct ContextMenuParams; struct ContextMenuParams;
class RenderFrameHost; class RenderFrameHost;
...@@ -122,6 +127,25 @@ class ProfilePickerView : public views::DialogDelegateView, ...@@ -122,6 +127,25 @@ class ProfilePickerView : public views::DialogDelegateView,
// on Windows). // on Windows).
void ConfigureAccelerators(); void ConfigureAccelerators();
// 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,
const base::FilePath& profile_path);
// Hides the dialog if it is showing.
void HideDialog();
// Displays 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();
// Getter of the path of profile which is selected in profile picker for force
// signin.
base::FilePath GetForceSigninProfilePath();
ScopedKeepAlive keep_alive_; ScopedKeepAlive keep_alive_;
State state_ = State::kNotStarted; State state_ = State::kNotStarted;
...@@ -160,6 +184,9 @@ class ProfilePickerView : public views::DialogDelegateView, ...@@ -160,6 +184,9 @@ class ProfilePickerView : public views::DialogDelegateView,
// when the picker is shown on startup. // when the picker is shown on startup.
base::TimeTicks creation_time_on_startup_; base::TimeTicks creation_time_on_startup_;
// Hosts dialog displayed when a locked profile is selected in ProfilePicker.
UserManagerProfileDialogHost dialog_host_;
base::WeakPtrFactory<ProfilePickerView> weak_ptr_factory_{this}; base::WeakPtrFactory<ProfilePickerView> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ProfilePickerView); DISALLOW_COPY_AND_ASSIGN(ProfilePickerView);
......
...@@ -14,8 +14,10 @@ UserManagerProfileDialogHost::UserManagerProfileDialogHost() = default; ...@@ -14,8 +14,10 @@ UserManagerProfileDialogHost::UserManagerProfileDialogHost() = default;
void UserManagerProfileDialogHost::ShowDialog( void UserManagerProfileDialogHost::ShowDialog(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const GURL& url, const GURL& url,
const base::FilePath& profile_path,
gfx::NativeView parent) { gfx::NativeView parent) {
HideDialog(); HideDialog();
force_signin_profile_path_ = profile_path;
auto delegate = std::make_unique<UserManagerProfileDialogDelegate>( auto delegate = std::make_unique<UserManagerProfileDialogDelegate>(
this, std::make_unique<views::WebView>(browser_context), url); this, std::make_unique<views::WebView>(browser_context), url);
delegate_ = delegate.get(); delegate_ = delegate.get();
...@@ -29,10 +31,16 @@ void UserManagerProfileDialogHost::HideDialog() { ...@@ -29,10 +31,16 @@ void UserManagerProfileDialogHost::HideDialog() {
delegate_->CloseDialog(); delegate_->CloseDialog();
DCHECK(!delegate_); DCHECK(!delegate_);
} }
force_signin_profile_path_.clear();
}
base::FilePath UserManagerProfileDialogHost::GetForceSigninProfilePath() {
return force_signin_profile_path_;
} }
void UserManagerProfileDialogHost::OnDialogDestroyed() { void UserManagerProfileDialogHost::OnDialogDestroyed() {
delegate_ = nullptr; delegate_ = nullptr;
force_signin_profile_path_.clear();
} }
void UserManagerProfileDialogHost::DisplayErrorMessage() { void UserManagerProfileDialogHost::DisplayErrorMessage() {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_HOST_H_ #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_HOST_H_
#define CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_HOST_H_ #define CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_HOST_H_
#include "base/files/file_path.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
class GURL; class GURL;
...@@ -29,6 +30,7 @@ class UserManagerProfileDialogHost { ...@@ -29,6 +30,7 @@ class UserManagerProfileDialogHost {
// creates a new one. // creates a new one.
void ShowDialog(content::BrowserContext* browser_context, void ShowDialog(content::BrowserContext* browser_context,
const GURL& url, const GURL& url,
const base::FilePath& profile_path,
gfx::NativeView parent); gfx::NativeView parent);
// Hides the reauth dialog if it is showing. // Hides the reauth dialog if it is showing.
...@@ -39,6 +41,10 @@ class UserManagerProfileDialogHost { ...@@ -39,6 +41,10 @@ class UserManagerProfileDialogHost {
// nothing. // nothing.
void DisplayErrorMessage(); void DisplayErrorMessage();
// Getter of the path of profile which is selected in profile picker for force
// signin.
base::FilePath GetForceSigninProfilePath();
private: private:
friend class UserManagerProfileDialogDelegate; friend class UserManagerProfileDialogDelegate;
...@@ -47,6 +53,9 @@ class UserManagerProfileDialogHost { ...@@ -47,6 +53,9 @@ class UserManagerProfileDialogHost {
// Owned by the view hierarchy. // Owned by the view hierarchy.
UserManagerProfileDialogDelegate* delegate_ = nullptr; UserManagerProfileDialogDelegate* delegate_ = nullptr;
// The path of profile that is being force signed in.
base::FilePath force_signin_profile_path_;
}; };
#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_HOST_H_ #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_PROFILE_DIALOG_HOST_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -199,8 +200,7 @@ void UserManagerProfileDialog::ShowUnlockDialogWithProfilePath( ...@@ -199,8 +200,7 @@ void UserManagerProfileDialog::ShowUnlockDialogWithProfilePath(
GURL url = signin::GetEmbeddedReauthURLWithEmail( GURL url = signin::GetEmbeddedReauthURLWithEmail(
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->ShowDialog(browser_context, url, profile_path);
g_user_manager_view->ShowDialog(browser_context, url);
} }
// static // static
...@@ -209,23 +209,21 @@ void UserManagerProfileDialog::ShowForceSigninDialog( ...@@ -209,23 +209,21 @@ void UserManagerProfileDialog::ShowForceSigninDialog(
const base::FilePath& profile_path) { const base::FilePath& profile_path) {
if (!UserManager::IsShowing()) if (!UserManager::IsShowing())
return; return;
g_user_manager_view->SetSigninProfilePath(profile_path);
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, url); g_user_manager_view->ShowDialog(browser_context, url, profile_path);
} }
void UserManagerProfileDialog::ShowDialogAndDisplayErrorMessage( void UserManagerProfileDialog::ShowDialogAndDisplayErrorMessage(
content::BrowserContext* browser_context) { content::BrowserContext* browser_context) {
if (!UserManager::IsShowing()) if (!UserManager::IsShowing())
return; return;
// The error occurred before sign in happened, reset |signin_profile_path_| // The error occurred before sign in happened, use an empty profile path
// 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->ShowDialog(
g_user_manager_view->ShowDialog(browser_context, browser_context, GURL(chrome::kChromeUISigninErrorURL), base::FilePath());
GURL(chrome::kChromeUISigninErrorURL));
} }
// static // static
...@@ -280,9 +278,10 @@ void UserManagerView::OnSystemProfileCreated( ...@@ -280,9 +278,10 @@ void UserManagerView::OnSystemProfileCreated(
} }
void UserManagerView::ShowDialog(content::BrowserContext* browser_context, void UserManagerView::ShowDialog(content::BrowserContext* browser_context,
const GURL& url) { const GURL& url,
const base::FilePath& profile_path) {
gfx::NativeView parent = GetWidget()->GetNativeView(); gfx::NativeView parent = GetWidget()->GetNativeView();
dialog_host_.ShowDialog(browser_context, url, parent); dialog_host_.ShowDialog(browser_context, url, profile_path, parent);
} }
void UserManagerView::HideDialog() { void UserManagerView::HideDialog() {
...@@ -399,10 +398,6 @@ void UserManagerView::WindowClosing() { ...@@ -399,10 +398,6 @@ void UserManagerView::WindowClosing() {
g_user_manager_view = nullptr; g_user_manager_view = nullptr;
} }
void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) {
signin_profile_path_ = profile_path;
}
base::FilePath UserManagerView::GetSigninProfilePath() { base::FilePath UserManagerView::GetSigninProfilePath() {
return signin_profile_path_; return dialog_host_.GetForceSigninProfilePath();
} }
...@@ -22,6 +22,10 @@ class ScopedKeepAlive; ...@@ -22,6 +22,10 @@ class ScopedKeepAlive;
class UserManagerView; class UserManagerView;
class UserManagerProfileDialogDelegate; class UserManagerProfileDialogDelegate;
namespace base {
class FilePath;
}
namespace views { namespace views {
class WebView; class WebView;
} }
...@@ -53,16 +57,17 @@ class UserManagerView : public views::DialogDelegateView { ...@@ -53,16 +57,17 @@ class UserManagerView : public views::DialogDelegateView {
// Shows 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. If a dialog is already shown, this destroys the current dialog and // message. If a dialog is already shown, this destroys the current dialog and
// creates a new one. // creates a new one.
void ShowDialog(content::BrowserContext* browser_context, const GURL& url); void ShowDialog(content::BrowserContext* browser_context,
const GURL& url,
const base::FilePath& profile_path);
// Displays 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. If the dialog is not currently shown, this does // without browser window. If the dialog is not currently shown, this does
// nothing. // nothing.
void DisplayErrorMessage(); void DisplayErrorMessage();
// Setter and getter of the path of profile which is selected in user manager // Getter of the path of profile which is selected in user manager for first
// for first time signin. // time signin.
void SetSigninProfilePath(const base::FilePath& profile_path);
base::FilePath GetSigninProfilePath(); base::FilePath GetSigninProfilePath();
private: private:
...@@ -86,8 +91,6 @@ class UserManagerView : public views::DialogDelegateView { ...@@ -86,8 +91,6 @@ class UserManagerView : public views::DialogDelegateView {
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_;
UserManagerProfileDialogHost dialog_host_; 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