Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: chrome/browser/ui/cocoa/profiles/user_manager_mac.mm

Issue 564453003: Access to Chrome via the System Tray should go through the User Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify UserManager View/Mac Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
28 // is reset to NULL when the window is closed.
29 static UserManagerMac* instance_ = NULL; // Weak.
27 30
28 // Declared in browser_dialogs.h so others don't have to depend on this header. 31 void UserManager::Show(
29 void ShowUserManager(const base::FilePath& profile_path_to_focus) { 32 const base::FilePath& profile_path_to_focus,
30 UserManagerMac::Show( 33 profiles::UserManagerTutorialMode tutorial_mode,
31 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); 34 profiles::UserManagerProfileSelected profile_open_action) {
35 if (instance_) {
36 // If there's a user manager window open already, just activate it.
37 [instance_->window_controller_ show];
38 return;
39 }
40
41 // Create the guest profile, if necessary, and open the User Manager
42 // from the guest profile.
43 profiles::CreateGuestProfileForUserManager(
44 profile_path_to_focus,
45 tutorial_mode,
46 profile_open_action,
47 base::Bind(&UserManagerMac::OnGuestProfileCreated));
32 } 48 }
33 49
34 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { 50 void UserManager::Hide() {
35 UserManagerMac::Show(base::FilePath(), tutorial); 51 if (instance_)
52 [instance_->window_controller_ close];
36 } 53 }
37 54
38 void HideUserManager() { 55 bool UserManager::IsShowing() {
39 UserManagerMac::Hide(); 56 return instance_ ? [instance_->window_controller_ isVisible]: false;
40 } 57 }
41 58
42 } // namespace chrome
43
44 // Custom WebContentsDelegate that allows handling of hotkeys. 59 // Custom WebContentsDelegate that allows handling of hotkeys.
45 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { 60 class UserManagerWebContentsDelegate : public content::WebContentsDelegate {
46 public: 61 public:
47 UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window) 62 UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window)
48 : window_(window) {} 63 : window_(window) {}
49 64
50 // WebContentsDelegate implementation. Forwards all unhandled keyboard events 65 // WebContentsDelegate implementation. Forwards all unhandled keyboard events
51 // to the current window. 66 // to the current window.
52 virtual void HandleKeyboardEvent( 67 virtual void HandleKeyboardEvent(
53 content::WebContents* source, 68 content::WebContents* source,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 183
169 UserManagerMac::UserManagerMac(Profile* profile) { 184 UserManagerMac::UserManagerMac(Profile* profile) {
170 window_controller_.reset([[UserManagerWindowController alloc] 185 window_controller_.reset([[UserManagerWindowController alloc]
171 initWithProfile:profile withObserver:this]); 186 initWithProfile:profile withObserver:this]);
172 } 187 }
173 188
174 UserManagerMac::~UserManagerMac() { 189 UserManagerMac::~UserManagerMac() {
175 } 190 }
176 191
177 // static 192 // static
178 void UserManagerMac::Show(const base::FilePath& profile_path_to_focus,
179 profiles::UserManagerTutorialMode tutorial_mode) {
180 if (instance_) {
181 // If there's a user manager window open already, just activate it.
182 [instance_->window_controller_ show];
183 return;
184 }
185
186 // Create the guest profile, if necessary, and open the User Manager
187 // from the guest profile.
188 profiles::CreateGuestProfileForUserManager(
189 profile_path_to_focus,
190 tutorial_mode,
191 base::Bind(&UserManagerMac::OnGuestProfileCreated));
192 }
193
194 // static
195 void UserManagerMac::Hide() {
196 if (instance_)
197 [instance_->window_controller_ close];
198 }
199
200 // static
201 bool UserManagerMac::IsShowing() {
202 return instance_ ? [instance_->window_controller_ isVisible]: false;
203 }
204
205 // static
206 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, 193 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile,
207 const std::string& url) { 194 const std::string& url) {
208 instance_ = new UserManagerMac(guest_profile); 195 instance_ = new UserManagerMac(guest_profile);
209 [instance_->window_controller_ showURL:GURL(url)]; 196 [instance_->window_controller_ showURL:GURL(url)];
210 } 197 }
211 198
212 void UserManagerMac::WindowWasClosed() { 199 void UserManagerMac::WindowWasClosed() {
213 instance_ = NULL; 200 instance_ = NULL;
214 delete this; 201 delete this;
215 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698