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 | 19 |
19 // Default window size. Taken from the views implementation in | 20 // Default window size. Taken from the views implementation in |
20 // chrome/browser/ui/views/user_manager_view.cc. | 21 // chrome/browser/ui/views/user_manager_view.cc. |
21 // TODO(noms): Figure out if this size can be computed dynamically or adjusted | 22 // TODO(noms): Figure out if this size can be computed dynamically or adjusted |
22 // for smaller screens. | 23 // for smaller screens. |
23 const int kWindowWidth = 900; | 24 const int kWindowWidth = 900; |
24 const int kWindowHeight = 700; | 25 const int kWindowHeight = 700; |
25 | 26 |
26 namespace chrome { | 27 // An open User Manager window. There can only be one open at a time. This |
27 | 28 // is reset to NULL when the window is closed. |
28 // Declared in browser_dialogs.h so others don't have to depend on this header. | 29 UserManagerMac* instance_ = NULL; // Weak. |
Alexei Svitkine (slow)
2014/09/18 20:54:04
Why not make it a static member of the class?
Peter Kasting
2014/09/18 21:33:47
Being file-scoped in the .mm file is even more loc
| |
29 void ShowUserManager(const base::FilePath& profile_path_to_focus) { | |
30 UserManagerMac::Show( | |
31 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); | |
32 } | |
33 | |
34 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { | |
35 UserManagerMac::Show(base::FilePath(), tutorial); | |
36 } | |
37 | |
38 void HideUserManager() { | |
39 UserManagerMac::Hide(); | |
40 } | |
41 | |
42 } // namespace chrome | |
43 | 30 |
44 // Custom WebContentsDelegate that allows handling of hotkeys. | 31 // Custom WebContentsDelegate that allows handling of hotkeys. |
45 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { | 32 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { |
46 public: | 33 public: |
47 UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window) | 34 UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window) |
48 : window_(window) {} | 35 : window_(window) {} |
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( |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 } | 143 } |
157 | 144 |
158 - (void)windowWillClose:(NSNotification*)notification { | 145 - (void)windowWillClose:(NSNotification*)notification { |
159 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 146 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
160 DCHECK(userManagerObserver_); | 147 DCHECK(userManagerObserver_); |
161 userManagerObserver_->WindowWasClosed(); | 148 userManagerObserver_->WindowWasClosed(); |
162 } | 149 } |
163 | 150 |
164 @end | 151 @end |
165 | 152 |
166 // static | |
167 UserManagerMac* UserManagerMac::instance_ = NULL; | |
168 | 153 |
169 UserManagerMac::UserManagerMac(Profile* profile) { | 154 void UserManager::Show( |
170 window_controller_.reset([[UserManagerWindowController alloc] | 155 const base::FilePath& profile_path_to_focus, |
171 initWithProfile:profile withObserver:this]); | 156 profiles::UserManagerTutorialMode tutorial_mode, |
172 } | 157 profiles::UserManagerProfileSelected profile_open_action) { |
173 | |
174 UserManagerMac::~UserManagerMac() { | |
175 } | |
176 | |
177 // static | |
178 void UserManagerMac::Show(const base::FilePath& profile_path_to_focus, | |
179 profiles::UserManagerTutorialMode tutorial_mode) { | |
180 if (instance_) { | 158 if (instance_) { |
181 // If there's a user manager window open already, just activate it. | 159 // If there's a user manager window open already, just activate it. |
182 [instance_->window_controller_ show]; | 160 [instance_->get_window_controller() show]; |
183 return; | 161 return; |
184 } | 162 } |
185 | 163 |
186 // Create the guest profile, if necessary, and open the User Manager | 164 // Create the guest profile, if necessary, and open the User Manager |
187 // from the guest profile. | 165 // from the guest profile. |
188 profiles::CreateGuestProfileForUserManager( | 166 profiles::CreateGuestProfileForUserManager( |
189 profile_path_to_focus, | 167 profile_path_to_focus, |
190 tutorial_mode, | 168 tutorial_mode, |
169 profile_open_action, | |
191 base::Bind(&UserManagerMac::OnGuestProfileCreated)); | 170 base::Bind(&UserManagerMac::OnGuestProfileCreated)); |
192 } | 171 } |
193 | 172 |
194 // static | 173 void UserManager::Hide() { |
195 void UserManagerMac::Hide() { | |
196 if (instance_) | 174 if (instance_) |
197 [instance_->window_controller_ close]; | 175 [instance_->get_window_controller() close]; |
198 } | 176 } |
199 | 177 |
200 // static | 178 bool UserManager::IsShowing() { |
201 bool UserManagerMac::IsShowing() { | 179 return instance_ ? [instance_->get_window_controller() isVisible]: false; |
202 return instance_ ? [instance_->window_controller_ isVisible]: false; | 180 } |
181 | |
182 UserManagerMac::UserManagerMac(Profile* profile) { | |
183 window_controller_.reset([[UserManagerWindowController alloc] | |
184 initWithProfile:profile withObserver:this]); | |
185 } | |
186 | |
187 UserManagerMac::~UserManagerMac() { | |
203 } | 188 } |
204 | 189 |
205 // static | 190 // static |
206 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, | 191 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, |
207 const std::string& url) { | 192 const std::string& url) { |
193 DCHECK(!instance_); | |
208 instance_ = new UserManagerMac(guest_profile); | 194 instance_ = new UserManagerMac(guest_profile); |
209 [instance_->window_controller_ showURL:GURL(url)]; | 195 [instance_->get_window_controller() showURL:GURL(url)]; |
210 } | 196 } |
211 | 197 |
212 void UserManagerMac::WindowWasClosed() { | 198 void UserManagerMac::WindowWasClosed() { |
213 instance_ = NULL; | 199 instance_ = NULL; |
214 delete this; | 200 delete this; |
215 } | 201 } |
OLD | NEW |