1 // Copyright 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_VIEWS_PROFILES_USER_MANAGER_VIEW_H_ 6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_VIEW_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "base/auto_reset.h" 12 #include "base/macros.h" 13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile_window.h" 15 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h" 16 #include "chrome/browser/ui/user_manager.h" 17 #include "components/signin/public/base/signin_metrics.h" 18 #include "components/web_modal/web_contents_modal_dialog_host.h" 19 #include "ui/views/controls/webview/webview.h" 20 #include "ui/views/window/dialog_delegate.h" 21 22 class ScopedKeepAlive; 23 class UserManagerView; 24 25 class UserManagerProfileDialogDelegate 26 : public views::DialogDelegateView, 27 public UserManagerProfileDialog::BaseDialogDelegate, 28 public ChromeWebModalDialogManagerDelegate, 29 public web_modal::WebContentsModalDialogHost { 30 public: 31 UserManagerProfileDialogDelegate(UserManagerView* parent, 32 views::WebView* web_view, 33 const std::string& email_address, 34 const GURL& url); 35 ~UserManagerProfileDialogDelegate() override; 36 37 // UserManagerProfileDialog::BaseDialogDelegate 38 void CloseDialog() override; 39 40 // Display the local error message inside login window. 41 void DisplayErrorMessage(); 42 43 // ChromeWebModalDialogManagerDelegate 44 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost() 45 override; 46 47 // web_modal::WebContentsModalDialogHost 48 gfx::NativeView GetHostView() const override; 49 gfx::Point GetDialogPosition(const gfx::Size& size) override; 50 gfx::Size GetMaximumDialogSize() override; 51 void AddObserver(web_modal::ModalDialogHostObserver* observer) override; 52 void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override; 53 54 private: 55 UserManagerProfileDialogDelegate(); 56 57 // Before its destruction, tells its parent container to reset its reference 58 // to the UserManagerProfileDialogDelegate. 59 void OnDialogDestroyed(); 60 61 // views::DialogDelegate: 62 gfx::Size CalculatePreferredSize() const override; 63 ui::ModalType GetModalType() const override; 64 void DeleteDelegate() override; 65 views::View* GetInitiallyFocusedView() override; 66 67 UserManagerView* parent_; // Not owned. 68 views::WebView* web_view_; 69 const std::string email_address_; 70 71 DISALLOW_COPY_AND_ASSIGN(UserManagerProfileDialogDelegate); 72 }; 73 74 namespace views { 75 class WebView; 76 } 77 78 // Dialog widget that contains the Desktop User Manager webui. 79 class UserManagerView : public views::DialogDelegateView { 80 public: 81 // Do not call directly. To display the User Manager, use UserManager::Show(). 82 UserManagerView(); 83 84 // Creates a new UserManagerView instance for the |system_profile| and shows 85 // the |url|. 86 static void OnSystemProfileCreated(std::unique_ptr<UserManagerView> instance, 87 base::AutoReset<bool>* pending, 88 Profile* system_profile, 89 const std::string& url); 90 set_user_manager_started_showing(const base::Time & user_manager_started_showing)91 void set_user_manager_started_showing( 92 const base::Time& user_manager_started_showing) { 93 user_manager_started_showing_ = user_manager_started_showing; 94 } 95 96 // Logs how long it took the UserManager to open. 97 void LogTimeToOpen(); 98 99 // Hides the reauth dialog if it is showing. 100 void HideDialog(); 101 102 // Show a dialog where the user can auth the profile or see the auth error 103 // message. 104 void ShowDialog(content::BrowserContext* browser_context, 105 const std::string& email, 106 const GURL& url); 107 108 // Display sign in error message that is created by Chrome but not GAIA 109 // without browser window. 110 void DisplayErrorMessage(); 111 112 // Setter and getter of the path of profile which is selected in user manager 113 // for first time signin. 114 void SetSigninProfilePath(const base::FilePath& profile_path); 115 base::FilePath GetSigninProfilePath(); 116 117 private: 118 friend class UserManagerProfileDialogDelegate; 119 friend std::default_delete<UserManagerView>; 120 121 ~UserManagerView() override; 122 123 // Resets delegate_ to nullptr when delegate_ is no longer alive. 124 void OnDialogDestroyed(); 125 126 // Creates dialog and initializes UI. 127 void Init(Profile* guest_profile, const GURL& url); 128 129 // views::View: 130 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; 131 gfx::Size CalculatePreferredSize() const override; 132 133 // views::DialogDelegateView: 134 void WindowClosing() override; 135 136 views::WebView* web_view_; 137 138 UserManagerProfileDialogDelegate* delegate_; 139 140 std::unique_ptr<ScopedKeepAlive> keep_alive_; 141 base::Time user_manager_started_showing_; 142 143 base::FilePath signin_profile_path_; 144 145 DISALLOW_COPY_AND_ASSIGN(UserManagerView); 146 }; 147 148 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_USER_MANAGER_VIEW_H_ 149