mlerman | e29d003 | 2014-09-24 19:31:26 | [diff] [blame] | 1 | // 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 | |
lwchkg | c9caa8e | 2016-03-13 17:26:43 | [diff] [blame] | 8 | #include "base/callback_forward.h" |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 9 | #include "base/macros.h" |
mlerman | e29d003 | 2014-09-24 19:31:26 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile_window.h" |
mahmadi | 3784f9b | 2016-06-09 13:29:21 | [diff] [blame] | 11 | #include "components/signin/core/browser/signin_metrics.h" |
mahmadi | 181eb213 | 2016-08-02 20:40:53 | [diff] [blame] | 12 | #include "content/public/browser/web_contents_delegate.h" |
mlerman | e29d003 | 2014-09-24 19:31:26 | [diff] [blame] | 13 | |
| 14 | namespace base { |
| 15 | class FilePath; |
| 16 | } |
| 17 | |
| 18 | // Cross-platform methods for displaying the user manager. |
| 19 | class UserManager { |
| 20 | public: |
zmin | c105747d | 2016-09-23 20:19:06 | [diff] [blame] | 21 | // 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 | |
mlerman | e29d003 | 2014-09-24 19:31:26 | [diff] [blame] | 26 | // 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 |
mahmadi | aedff8da | 2016-09-30 20:12:35 | [diff] [blame] | 29 | // 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. |
mlerman | e29d003 | 2014-09-24 19:31:26 | [diff] [blame] | 32 | static void Show(const base::FilePath& profile_path_to_focus, |
| 33 | profiles::UserManagerTutorialMode tutorial_mode, |
mahmadi | aedff8da | 2016-09-30 20:12:35 | [diff] [blame] | 34 | profiles::UserManagerAction user_manager_action); |
mlerman | e29d003 | 2014-09-24 19:31:26 | [diff] [blame] | 35 | |
| 36 | // Hides the User Manager. |
| 37 | static void Hide(); |
| 38 | |
zmin | c105747d | 2016-09-23 20:19:06 | [diff] [blame] | 39 | // Returns whether the User Manager is showing and active. |
| 40 | // TODO(zmin): Rename the function to something less confusing. |
| 41 | // https://crbug.com/649380. |
mlerman | e29d003 | 2014-09-24 19:31:26 | [diff] [blame] | 42 | static bool IsShowing(); |
| 43 | |
mlerman | 07aaf75 | 2015-03-20 22:04:25 | [diff] [blame] | 44 | // To be called once the User Manager's contents are showing. |
| 45 | static void OnUserManagerShown(); |
| 46 | |
lwchkg | c9caa8e | 2016-03-13 17:26:43 | [diff] [blame] | 47 | // Add a callback that will be called when OnUserManagerShown is called. |
| 48 | static void AddOnUserManagerShownCallbackForTesting( |
| 49 | const base::Closure& callback); |
| 50 | |
zmin | fe95cd6 | 2016-12-09 22:08:16 | [diff] [blame] | 51 | // 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. |
| 59 | class 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 | |
mahmadi | 3784f9b | 2016-06-09 13:29:21 | [diff] [blame] | 71 | // 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. |
rogerta | ce8820c | 2015-07-25 14:47:29 | [diff] [blame] | 79 | static void ShowReauthDialog(content::BrowserContext* browser_context, |
mahmadi | 3784f9b | 2016-06-09 13:29:21 | [diff] [blame] | 80 | const std::string& email, |
| 81 | signin_metrics::Reason reason); |
| 82 | |
benwells | e3496e1 | 2016-10-14 20:14:24 | [diff] [blame] | 83 | // Shows a dialog where the user logs into their profile for the first time |
| 84 | // via the user manager. |
zmin | c105747d | 2016-09-23 20:19:06 | [diff] [blame] | 85 | static void ShowSigninDialog(content::BrowserContext* browser_context, |
| 86 | const base::FilePath& profile_path); |
mlerman | cf2a33b | 2014-09-25 16:13:40 | [diff] [blame] | 87 | |
zmin | fe95cd6 | 2016-12-09 22:08:16 | [diff] [blame] | 88 | // Show the dialog and display local sign in error message without browser. |
| 89 | static void ShowDialogAndDisplayErrorMessage( |
| 90 | content::BrowserContext* browser_context); |
| 91 | |
zmin | c105747d | 2016-09-23 20:19:06 | [diff] [blame] | 92 | // Display local sign in error message without browser. |
| 93 | static void DisplayErrorMessage(); |
mahmadi | 05aabc6 | 2016-06-16 17:50:22 | [diff] [blame] | 94 | |
zmin | fe95cd6 | 2016-12-09 22:08:16 | [diff] [blame] | 95 | // Hides the dialog if it is showing. |
| 96 | static void HideDialog(); |
rogerta | ce8820c | 2015-07-25 14:47:29 | [diff] [blame] | 97 | |
mahmadi | 181eb213 | 2016-08-02 20:40:53 | [diff] [blame] | 98 | // 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. |
zmin | fe95cd6 | 2016-12-09 22:08:16 | [diff] [blame] | 101 | class BaseDialogDelegate : public content::WebContentsDelegate { |
anthonyvd | b857f9d | 2015-08-12 22:21:55 | [diff] [blame] | 102 | public: |
zmin | fe95cd6 | 2016-12-09 22:08:16 | [diff] [blame] | 103 | BaseDialogDelegate(); |
mahmadi | 181eb213 | 2016-08-02 20:40:53 | [diff] [blame] | 104 | |
| 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; |
anthonyvd | b857f9d | 2015-08-12 22:21:55 | [diff] [blame] | 111 | |
zmin | fe95cd6 | 2016-12-09 22:08:16 | [diff] [blame] | 112 | protected: |
| 113 | virtual void CloseDialog() = 0; |
anthonyvd | b857f9d | 2015-08-12 22:21:55 | [diff] [blame] | 114 | |
mahmadi | 181eb213 | 2016-08-02 20:40:53 | [diff] [blame] | 115 | // WebContents of the embedded WebView. |
| 116 | content::WebContents* guest_web_contents_; |
anthonyvd | b857f9d | 2015-08-12 22:21:55 | [diff] [blame] | 117 | |
zmin | fe95cd6 | 2016-12-09 22:08:16 | [diff] [blame] | 118 | DISALLOW_COPY_AND_ASSIGN(BaseDialogDelegate); |
anthonyvd | b857f9d | 2015-08-12 22:21:55 | [diff] [blame] | 119 | }; |
mlerman | e29d003 | 2014-09-24 19:31:26 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | #endif // CHROME_BROWSER_UI_USER_MANAGER_H_ |