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