| 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_avatar_icon_util.h" | 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/profiles/profiles_state.h" | 13 #include "chrome/browser/profiles/profiles_state.h" |
| 14 #include "chrome/browser/ui/browser_dialogs.h" | 14 #include "chrome/browser/ui/browser_dialogs.h" |
| 15 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 15 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 16 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 16 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 17 #include "chrome/browser/ui/user_manager.h" | 17 #include "chrome/browser/ui/user_manager.h" |
| 18 #include "chrome/grit/chromium_strings.h" | 18 #include "chrome/grit/chromium_strings.h" |
| 19 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
| 20 #include "content/public/browser/render_widget_host_view.h" | 20 #include "content/public/browser/render_widget_host_view.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_contents_delegate.h" | 22 #include "content/public/browser/web_contents_delegate.h" |
| 23 #include "ui/base/l10n/l10n_util_mac.h" | 23 #include "ui/base/l10n/l10n_util_mac.h" |
| 24 #include "ui/events/keycodes/keyboard_codes.h" | 24 #include "ui/events/keycodes/keyboard_codes.h" |
| 25 | 25 |
| 26 namespace { |
| 27 |
| 28 // Update the App Controller with a new Profile. Used when a Profile is locked |
| 29 // to set the Controller to the Guest Profile so the old Profile's bookmarks, |
| 30 // etc... cannot be accessed. |
| 31 void ChangeAppControllerForProfile(Profile* profile, |
| 32 Profile::CreateStatus status) { |
| 33 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
| 34 AppController* controller = |
| 35 base::mac::ObjCCast<AppController>([NSApp delegate]); |
| 36 [controller windowChangedToProfile:profile]; |
| 37 } |
| 38 } |
| 39 |
| 40 } // namespace |
| 26 | 41 |
| 27 // An open User Manager window. There can only be one open at a time. This | 42 // An open User Manager window. There can only be one open at a time. This |
| 28 // is reset to NULL when the window is closed. | 43 // is reset to NULL when the window is closed. |
| 29 UserManagerMac* instance_ = NULL; // Weak. | 44 UserManagerMac* instance_ = NULL; // Weak. |
| 30 | 45 |
| 31 // Custom WebContentsDelegate that allows handling of hotkeys. | 46 // Custom WebContentsDelegate that allows handling of hotkeys. |
| 32 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { | 47 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { |
| 33 public: | 48 public: |
| 34 UserManagerWebContentsDelegate() {} | 49 UserManagerWebContentsDelegate() {} |
| 35 | 50 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if (rwhv) | 149 if (rwhv) |
| 135 rwhv->SetBackgroundColor(profiles::kUserManagerBackgroundColor); | 150 rwhv->SetBackgroundColor(profiles::kUserManagerBackgroundColor); |
| 136 [self show]; | 151 [self show]; |
| 137 } | 152 } |
| 138 | 153 |
| 139 - (void)show { | 154 - (void)show { |
| 140 // Because the User Manager isn't a BrowserWindowController, activating it | 155 // Because the User Manager isn't a BrowserWindowController, activating it |
| 141 // will not trigger a -windowChangedToProfile and update the menu bar. | 156 // will not trigger a -windowChangedToProfile and update the menu bar. |
| 142 // This is only important if the active profile is Guest, which may have | 157 // This is only important if the active profile is Guest, which may have |
| 143 // happened after locking a profile. | 158 // happened after locking a profile. |
| 144 Profile* guestProfile = profiles::SetActiveProfileToGuestIfLocked(); | 159 if (profiles::SetActiveProfileToGuestIfLocked()) { |
| 145 if (guestProfile && guestProfile->IsGuestSession()) { | 160 g_browser_process->profile_manager()->CreateProfileAsync( |
| 146 AppController* controller = | 161 ProfileManager::GetGuestProfilePath(), |
| 147 base::mac::ObjCCast<AppController>([NSApp delegate]); | 162 base::Bind(&ChangeAppControllerForProfile), |
| 148 [controller windowChangedToProfile:guestProfile]; | 163 base::string16(), |
| 164 base::string16(), |
| 165 std::string()); |
| 149 } | 166 } |
| 150 [[self window] makeKeyAndOrderFront:self]; | 167 [[self window] makeKeyAndOrderFront:self]; |
| 151 } | 168 } |
| 152 | 169 |
| 153 - (void)close { | 170 - (void)close { |
| 154 [[self window] close]; | 171 [[self window] close]; |
| 155 } | 172 } |
| 156 | 173 |
| 157 -(BOOL)isVisible { | 174 -(BOOL)isVisible { |
| 158 return [[self window] isVisible]; | 175 return [[self window] isVisible]; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 const std::string& url) { | 228 const std::string& url) { |
| 212 DCHECK(!instance_); | 229 DCHECK(!instance_); |
| 213 instance_ = new UserManagerMac(system_profile); | 230 instance_ = new UserManagerMac(system_profile); |
| 214 [instance_->window_controller() showURL:GURL(url)]; | 231 [instance_->window_controller() showURL:GURL(url)]; |
| 215 } | 232 } |
| 216 | 233 |
| 217 void UserManagerMac::WindowWasClosed() { | 234 void UserManagerMac::WindowWasClosed() { |
| 218 instance_ = NULL; | 235 instance_ = NULL; |
| 219 delete this; | 236 delete this; |
| 220 } | 237 } |
| OLD | NEW |