OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" | 5 #include "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/ui/browser_dialogs.h" | 10 #include "chrome/browser/ui/browser_dialogs.h" |
11 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 11 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
12 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 12 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 13 #include "chrome/browser/ui/user_manager.h" |
13 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
14 #include "content/public/browser/native_web_keyboard_event.h" | 15 #include "content/public/browser/native_web_keyboard_event.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
17 #include "ui/base/l10n/l10n_util_mac.h" | 18 #include "ui/base/l10n/l10n_util_mac.h" |
18 #include "ui/events/keycodes/keyboard_codes.h" | 19 #include "ui/events/keycodes/keyboard_codes.h" |
19 | 20 |
20 // Default window size. Taken from the views implementation in | 21 // Default window size. Taken from the views implementation in |
21 // chrome/browser/ui/views/user_manager_view.cc. | 22 // chrome/browser/ui/views/user_manager_view.cc. |
22 // TODO(noms): Figure out if this size can be computed dynamically or adjusted | 23 // TODO(noms): Figure out if this size can be computed dynamically or adjusted |
23 // for smaller screens. | 24 // for smaller screens. |
24 const int kWindowWidth = 900; | 25 const int kWindowWidth = 900; |
25 const int kWindowHeight = 700; | 26 const int kWindowHeight = 700; |
26 | 27 |
27 namespace chrome { | 28 // An open User Manager window. There can only be one open at a time. This |
28 | 29 // is reset to NULL when the window is closed. |
29 // Declared in browser_dialogs.h so others don't have to depend on this header. | 30 UserManagerMac* instance_ = NULL; // Weak. |
30 void ShowUserManager(const base::FilePath& profile_path_to_focus) { | |
31 UserManagerMac::Show( | |
32 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); | |
33 } | |
34 | |
35 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { | |
36 UserManagerMac::Show(base::FilePath(), tutorial); | |
37 } | |
38 | |
39 void HideUserManager() { | |
40 UserManagerMac::Hide(); | |
41 } | |
42 | |
43 } // namespace chrome | |
44 | 31 |
45 // Custom WebContentsDelegate that allows handling of hotkeys. | 32 // Custom WebContentsDelegate that allows handling of hotkeys. |
46 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { | 33 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { |
47 public: | 34 public: |
48 UserManagerWebContentsDelegate() {} | 35 UserManagerWebContentsDelegate() {} |
49 | 36 |
50 // WebContentsDelegate implementation. Forwards all unhandled keyboard events | 37 // WebContentsDelegate implementation. Forwards all unhandled keyboard events |
51 // to the current window. | 38 // to the current window. |
52 virtual void HandleKeyboardEvent( | 39 virtual void HandleKeyboardEvent( |
53 content::WebContents* source, | 40 content::WebContents* source, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 145 } |
159 | 146 |
160 - (void)windowWillClose:(NSNotification*)notification { | 147 - (void)windowWillClose:(NSNotification*)notification { |
161 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 148 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
162 DCHECK(userManagerObserver_); | 149 DCHECK(userManagerObserver_); |
163 userManagerObserver_->WindowWasClosed(); | 150 userManagerObserver_->WindowWasClosed(); |
164 } | 151 } |
165 | 152 |
166 @end | 153 @end |
167 | 154 |
168 // static | |
169 UserManagerMac* UserManagerMac::instance_ = NULL; | |
170 | 155 |
171 UserManagerMac::UserManagerMac(Profile* profile) { | 156 void UserManager::Show( |
172 window_controller_.reset([[UserManagerWindowController alloc] | 157 const base::FilePath& profile_path_to_focus, |
173 initWithProfile:profile withObserver:this]); | 158 profiles::UserManagerTutorialMode tutorial_mode, |
174 } | 159 profiles::UserManagerProfileSelected profile_open_action) { |
175 | |
176 UserManagerMac::~UserManagerMac() { | |
177 } | |
178 | |
179 // static | |
180 void UserManagerMac::Show(const base::FilePath& profile_path_to_focus, | |
181 profiles::UserManagerTutorialMode tutorial_mode) { | |
182 if (instance_) { | 160 if (instance_) { |
183 // If there's a user manager window open already, just activate it. | 161 // If there's a user manager window open already, just activate it. |
184 [instance_->window_controller_ show]; | 162 [instance_->window_controller() show]; |
185 return; | 163 return; |
186 } | 164 } |
187 | 165 |
188 // Create the guest profile, if necessary, and open the User Manager | 166 // Create the guest profile, if necessary, and open the User Manager |
189 // from the guest profile. | 167 // from the guest profile. |
190 profiles::CreateGuestProfileForUserManager( | 168 profiles::CreateGuestProfileForUserManager( |
191 profile_path_to_focus, | 169 profile_path_to_focus, |
192 tutorial_mode, | 170 tutorial_mode, |
| 171 profile_open_action, |
193 base::Bind(&UserManagerMac::OnGuestProfileCreated)); | 172 base::Bind(&UserManagerMac::OnGuestProfileCreated)); |
194 } | 173 } |
195 | 174 |
196 // static | 175 void UserManager::Hide() { |
197 void UserManagerMac::Hide() { | |
198 if (instance_) | 176 if (instance_) |
199 [instance_->window_controller_ close]; | 177 [instance_->window_controller() close]; |
200 } | 178 } |
201 | 179 |
202 // static | 180 bool UserManager::IsShowing() { |
203 bool UserManagerMac::IsShowing() { | 181 return instance_ ? [instance_->window_controller() isVisible]: false; |
204 return instance_ ? [instance_->window_controller_ isVisible]: false; | 182 } |
| 183 |
| 184 UserManagerMac::UserManagerMac(Profile* profile) { |
| 185 window_controller_.reset([[UserManagerWindowController alloc] |
| 186 initWithProfile:profile withObserver:this]); |
| 187 } |
| 188 |
| 189 UserManagerMac::~UserManagerMac() { |
205 } | 190 } |
206 | 191 |
207 // static | 192 // static |
208 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, | 193 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, |
209 const std::string& url) { | 194 const std::string& url) { |
| 195 DCHECK(!instance_); |
210 instance_ = new UserManagerMac(guest_profile); | 196 instance_ = new UserManagerMac(guest_profile); |
211 [instance_->window_controller_ showURL:GURL(url)]; | 197 [instance_->window_controller() showURL:GURL(url)]; |
212 } | 198 } |
213 | 199 |
214 void UserManagerMac::WindowWasClosed() { | 200 void UserManagerMac::WindowWasClosed() { |
215 instance_ = NULL; | 201 instance_ = NULL; |
216 delete this; | 202 delete this; |
217 } | 203 } |
OLD | NEW |