blob: 2dbf8d1b9369a99c6522c1caf146f4165907abc2 [file] [log] [blame]
mlermane29d0032014-09-24 19:31:261// Copyright (c) 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_USER_MANAGER_H_
6#define CHROME_BROWSER_UI_USER_MANAGER_H_
7
lwchkgc9caa8e2016-03-13 17:26:438#include "base/callback_forward.h"
avi655876a2015-12-25 07:18:159#include "base/macros.h"
mlermane29d0032014-09-24 19:31:2610#include "chrome/browser/profiles/profile_window.h"
mahmadi3784f9b2016-06-09 13:29:2111#include "components/signin/core/browser/signin_metrics.h"
mahmadi181eb2132016-08-02 20:40:5312#include "content/public/browser/web_contents_delegate.h"
mlermane29d0032014-09-24 19:31:2613
14namespace base {
15class FilePath;
16}
17
18// Cross-platform methods for displaying the user manager.
19class UserManager {
20 public:
zminc105747d2016-09-23 20:19:0621 // TODO(noms): Figure out if this size can be computed dynamically or adjusted
22 // for smaller screens.
23 static constexpr int kWindowWidth = 800;
24 static constexpr int kWindowHeight = 600;
25
mlermane29d0032014-09-24 19:31:2626 // Shows the User Manager or re-activates an existing one, focusing the
27 // profile given by |profile_path_to_focus|; passing an empty base::FilePath
28 // focuses no user pod. Based on the value of |tutorial_mode|, a tutorial
mahmadiaedff8da2016-09-30 20:12:3529 // could be shown, in which case |profile_path_to_focus| is ignored. Depending
30 // on the value of |user_manager_action|, executes an action once the user
31 // manager displays or after a profile is opened.
mlermane29d0032014-09-24 19:31:2632 static void Show(const base::FilePath& profile_path_to_focus,
33 profiles::UserManagerTutorialMode tutorial_mode,
mahmadiaedff8da2016-09-30 20:12:3534 profiles::UserManagerAction user_manager_action);
mlermane29d0032014-09-24 19:31:2635
36 // Hides the User Manager.
37 static void Hide();
38
zminc105747d2016-09-23 20:19:0639 // Returns whether the User Manager is showing and active.
40 // TODO(zmin): Rename the function to something less confusing.
41 // https://crbug.com/649380.
mlermane29d0032014-09-24 19:31:2642 static bool IsShowing();
43
mlerman07aaf752015-03-20 22:04:2544 // To be called once the User Manager's contents are showing.
45 static void OnUserManagerShown();
46
lwchkgc9caa8e2016-03-13 17:26:4347 // Add a callback that will be called when OnUserManagerShown is called.
48 static void AddOnUserManagerShownCallbackForTesting(
49 const base::Closure& callback);
50
zminfe95cd62016-12-09 22:08:1651 // Get the path of profile that is being signed in.
52 static base::FilePath GetSigninProfilePath();
53
54 private:
55 DISALLOW_IMPLICIT_CONSTRUCTORS(UserManager);
56};
57
58// Dialog that will be displayed when a profile is selected in UserManager.
59class UserManagerProfileDialog {
60 public:
61 // Dimensions of the reauth dialog displaying the old-style signin flow with
62 // the username and password challenge on the same form.
63 static constexpr int kPasswordCombinedDialogHeight = 440;
64 static constexpr int kPasswordCombinedDialogWidth = 360;
65
66 // Dimensions of the reauth dialog displaying the password-separated signin
67 // flow.
68 static constexpr int kDialogHeight = 512;
69 static constexpr int kDialogWidth = 448;
70
mahmadi3784f9b2016-06-09 13:29:2171 // Shows a dialog where the user can re-authenticate the profile with the
72 // given |email|. This is called in the following scenarios:
73 // -From the user manager when a profile is locked and the user's password is
74 // detected to have been changed.
75 // -From the user manager when a custodian account needs to be
76 // reauthenticated.
77 // |reason| can be REASON_UNLOCK or REASON_REAUTHENTICATION to indicate
78 // whether this is a reauth or unlock scenario.
rogertace8820c2015-07-25 14:47:2979 static void ShowReauthDialog(content::BrowserContext* browser_context,
mahmadi3784f9b2016-06-09 13:29:2180 const std::string& email,
81 signin_metrics::Reason reason);
82
benwellse3496e12016-10-14 20:14:2483 // Shows a dialog where the user logs into their profile for the first time
84 // via the user manager.
zminc105747d2016-09-23 20:19:0685 static void ShowSigninDialog(content::BrowserContext* browser_context,
86 const base::FilePath& profile_path);
mlermancf2a33b2014-09-25 16:13:4087
zminfe95cd62016-12-09 22:08:1688 // Show the dialog and display local sign in error message without browser.
89 static void ShowDialogAndDisplayErrorMessage(
90 content::BrowserContext* browser_context);
91
zminc105747d2016-09-23 20:19:0692 // Display local sign in error message without browser.
93 static void DisplayErrorMessage();
mahmadi05aabc62016-06-16 17:50:2294
zminfe95cd62016-12-09 22:08:1695 // Hides the dialog if it is showing.
96 static void HideDialog();
rogertace8820c2015-07-25 14:47:2997
mahmadi181eb2132016-08-02 20:40:5398 // Abstract base class for performing online reauthentication of profiles in
99 // the User Manager. It is concretely implemented in UserManagerMac and
100 // UserManagerView to specialize the closing of the UI's dialog widgets.
zminfe95cd62016-12-09 22:08:16101 class BaseDialogDelegate : public content::WebContentsDelegate {
anthonyvdb857f9d2015-08-12 22:21:55102 public:
zminfe95cd62016-12-09 22:08:16103 BaseDialogDelegate();
mahmadi181eb2132016-08-02 20:40:53104
105 // content::WebContentsDelegate:
106 bool HandleContextMenu(const content::ContextMenuParams& params) override;
107
108 // content::WebContentsDelegate:
109 void LoadingStateChanged(content::WebContents* source,
110 bool to_different_document) override;
anthonyvdb857f9d2015-08-12 22:21:55111
zminfe95cd62016-12-09 22:08:16112 protected:
113 virtual void CloseDialog() = 0;
anthonyvdb857f9d2015-08-12 22:21:55114
mahmadi181eb2132016-08-02 20:40:53115 // WebContents of the embedded WebView.
116 content::WebContents* guest_web_contents_;
anthonyvdb857f9d2015-08-12 22:21:55117
zminfe95cd62016-12-09 22:08:16118 DISALLOW_COPY_AND_ASSIGN(BaseDialogDelegate);
anthonyvdb857f9d2015-08-12 22:21:55119 };
mlermane29d0032014-09-24 19:31:26120};
121
122#endif // CHROME_BROWSER_UI_USER_MANAGER_H_