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

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: Refactor ShowUserManager into a new static class 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/grit/chromium_strings.h" 13 #include "chrome/grit/chromium_strings.h"
14 #include "content/public/browser/native_web_keyboard_event.h" 14 #include "content/public/browser/native_web_keyboard_event.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_delegate.h" 16 #include "content/public/browser/web_contents_delegate.h"
17 #include "ui/base/l10n/l10n_util_mac.h" 17 #include "ui/base/l10n/l10n_util_mac.h"
18 18
19 // Default window size. Taken from the views implementation in 19 // Default window size. Taken from the views implementation in
20 // chrome/browser/ui/views/user_manager_view.cc. 20 // chrome/browser/ui/views/user_manager_view.cc.
21 // TODO(noms): Figure out if this size can be computed dynamically or adjusted 21 // TODO(noms): Figure out if this size can be computed dynamically or adjusted
22 // for smaller screens. 22 // for smaller screens.
23 const int kWindowWidth = 900; 23 const int kWindowWidth = 900;
24 const int kWindowHeight = 700; 24 const int kWindowHeight = 700;
25 25
26 namespace chrome { 26 void UserManager::Show(
27 27 const base::FilePath& profile_path_to_focus,
28 // Declared in browser_dialogs.h so others don't have to depend on this header. 28 profiles::UserManagerTutorialMode tutorial_mode,
29 void ShowUserManager(const base::FilePath& profile_path_to_focus) { 29 profiles::UserManagerProfileSelected profile_open_action) {
30 UserManagerMac::Show( 30 UserManagerMac::Show(profile_path_to_focus,
31 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); 31 tutorial_mode,
32 profile_open_action);
32 } 33 }
33 34
34 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { 35 void UserManager::Hide() {
35 UserManagerMac::Show(base::FilePath(), tutorial);
36 }
37
38 void HideUserManager() {
39 UserManagerMac::Hide(); 36 UserManagerMac::Hide();
40 } 37 }
41 38
42 } // namespace chrome 39 bool UserManager::IsShowing() {
40 return UserManagerMac::IsShowing();
41 }
43 42
44 // Custom WebContentsDelegate that allows handling of hotkeys. 43 // Custom WebContentsDelegate that allows handling of hotkeys.
45 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { 44 class UserManagerWebContentsDelegate : public content::WebContentsDelegate {
46 public: 45 public:
47 UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window) 46 UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window)
48 : window_(window) {} 47 : window_(window) {}
49 48
50 // WebContentsDelegate implementation. Forwards all unhandled keyboard events 49 // WebContentsDelegate implementation. Forwards all unhandled keyboard events
51 // to the current window. 50 // to the current window.
52 virtual void HandleKeyboardEvent( 51 virtual void HandleKeyboardEvent(
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 167
169 UserManagerMac::UserManagerMac(Profile* profile) { 168 UserManagerMac::UserManagerMac(Profile* profile) {
170 window_controller_.reset([[UserManagerWindowController alloc] 169 window_controller_.reset([[UserManagerWindowController alloc]
171 initWithProfile:profile withObserver:this]); 170 initWithProfile:profile withObserver:this]);
172 } 171 }
173 172
174 UserManagerMac::~UserManagerMac() { 173 UserManagerMac::~UserManagerMac() {
175 } 174 }
176 175
177 // static 176 // static
178 void UserManagerMac::Show(const base::FilePath& profile_path_to_focus, 177 void UserManagerMac::Show(
179 profiles::UserManagerTutorialMode tutorial_mode) { 178 const base::FilePath& profile_path_to_focus,
179 profiles::UserManagerTutorialMode tutorial_mode,
180 profiles::UserManagerProfileSelected profile_open_action) {
180 if (instance_) { 181 if (instance_) {
181 // If there's a user manager window open already, just activate it. 182 // If there's a user manager window open already, just activate it.
182 [instance_->window_controller_ show]; 183 [instance_->window_controller_ show];
183 return; 184 return;
184 } 185 }
185 186
186 // Create the guest profile, if necessary, and open the User Manager 187 // Create the guest profile, if necessary, and open the User Manager
187 // from the guest profile. 188 // from the guest profile.
188 profiles::CreateGuestProfileForUserManager( 189 profiles::CreateGuestProfileForUserManager(
189 profile_path_to_focus, 190 profile_path_to_focus,
190 tutorial_mode, 191 tutorial_mode,
192 profile_open_action,
191 base::Bind(&UserManagerMac::OnGuestProfileCreated)); 193 base::Bind(&UserManagerMac::OnGuestProfileCreated));
192 } 194 }
193 195
194 // static 196 // static
195 void UserManagerMac::Hide() { 197 void UserManagerMac::Hide() {
196 if (instance_) 198 if (instance_)
197 [instance_->window_controller_ close]; 199 [instance_->window_controller_ close];
198 } 200 }
199 201
200 // static 202 // static
201 bool UserManagerMac::IsShowing() { 203 bool UserManagerMac::IsShowing() {
202 return instance_ ? [instance_->window_controller_ isVisible]: false; 204 return instance_ ? [instance_->window_controller_ isVisible]: false;
203 } 205 }
204 206
205 // static 207 // static
206 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, 208 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile,
207 const std::string& url) { 209 const std::string& url) {
208 instance_ = new UserManagerMac(guest_profile); 210 instance_ = new UserManagerMac(guest_profile);
209 [instance_->window_controller_ showURL:GURL(url)]; 211 [instance_->window_controller_ showURL:GURL(url)];
210 } 212 }
211 213
212 void UserManagerMac::WindowWasClosed() { 214 void UserManagerMac::WindowWasClosed() {
213 instance_ = NULL; 215 instance_ = NULL;
214 delete this; 216 delete this;
215 } 217 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698