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

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

Issue 102913002: [Mac] User manager should show up as a standalone window. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #import <Cocoa/Cocoa.h> 5 #include "chrome/browser/ui/cocoa/user_manager_mac.h"
6 6
7 #include "base/strings/string_number_conversions.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile_manager.h"
7 #include "chrome/browser/ui/browser_dialogs.h" 10 #include "chrome/browser/ui/browser_dialogs.h"
11 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_view.h"
14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util_mac.h"
16
17 namespace {
18
groby-ooo-7-16 2013/12/04 01:59:48 No need for anon namespaces if it's constants only
19 // Default window size. Taken from the views implementation in
20 // chrome/browser/ui/views/user_manager_view.cc.
21 const int kWindowWidth = 900;
22 const int kWindowHeight = 700;
groby-ooo-7-16 2013/12/04 01:59:48 Hm. You might want to dynamically size this, maybe
23
24 } // namespace
8 25
9 namespace chrome { 26 namespace chrome {
10 27
11 // Declared in browser_dialogs.h so others don't have to depend on this header. 28 // Declared in browser_dialogs.h so others don't have to depend on this header.
12 // TODO(noms): Add implementation when the User Manager dialog is implemented.
13 void ShowUserManager(const base::FilePath& profile_path_to_focus) { 29 void ShowUserManager(const base::FilePath& profile_path_to_focus) {
14 NOTIMPLEMENTED(); 30 UserManagerMac::Show(profile_path_to_focus);
15 } 31 }
16 32
17 void HideUserManager() { 33 void HideUserManager() {
18 NOTIMPLEMENTED(); 34 UserManagerMac::Hide();
19 } 35 }
20 36
21 } // namespace chrome 37 } // namespace chrome
38
39 @interface UserManagerWindowController (Private)
40 - (void)windowWillClose:(NSNotification*)notification;
41 - (void)windowDidResize:(NSNotification*)notification;
42 @end
43
44 @implementation UserManagerWindowController
45
46 - (id)initWithProfile:(Profile*) profile
groby-ooo-7-16 2013/12/04 01:59:48 No space after (Profile*) and other types in metho
noms (inactive) 2013/12/05 17:55:06 Done.
47 withObserver:(UserManagerMac*) userManagerObserver {
48
49 userManagerObserver_ = userManagerObserver;
50 NSWindow* window = [[NSWindow alloc]
51 initWithContentRect:NSMakeRect(0, 0, kWindowWidth, kWindowHeight)
noms (inactive) 2013/12/03 21:58:28 I think this shouldn't be 0, but I don't know what
groby-ooo-7-16 2013/12/04 01:59:48 This sounds oddly like a constrained dialog. (Like
noms (inactive) 2013/12/05 17:55:06 Addressed by separate reply. On 2013/12/04 01:59
52 styleMask:NSTitledWindowMask |
53 NSClosableWindowMask |
54 NSResizableWindowMask
55 backing:NSBackingStoreBuffered
56 defer:NO];
57 [window setTitle:l10n_util::GetNSString(IDS_USER_MANAGER_SCREEN_TITLE)];
58
59 // Initialize the web view.
60 webContents_.reset(content::WebContents::Create(
61 content::WebContents::CreateParams(profile)));
62 NSView* webContentView = webContents_->GetView()->GetNativeView();
63 DCHECK(webContentView);
64
65 NSView* contentView = [window contentView];
groby-ooo-7-16 2013/12/04 01:59:48 Why not make the webContentView the contentView? T
noms (inactive) 2013/12/05 17:55:06 Oh cool. Done! On 2013/12/04 01:59:48, groby wrote
66 [webContentView setFrameSize:[contentView frame].size];
67 [contentView addSubview:webContentView];
68
69 // Initialize, but don't show the window until the web contents have loaded.
70 self = [super initWithWindow:window];
71
72 [[NSNotificationCenter defaultCenter] addObserver:self
groby-ooo-7-16 2013/12/04 01:59:48 Missing cleanup - if you register yourself as an o
noms (inactive) 2013/12/05 17:55:06 Done.
73 selector:@selector(windowWillClose:)
74 name:NSWindowWillCloseNotification
75 object:self.window];
76 [[NSNotificationCenter defaultCenter] addObserver:self
77 selector:@selector(windowDidResize:)
78 name:NSWindowDidResizeNotification
79 object:self.window];
80 return self;
81 }
82
83 - (void)showURL:(GURL)url {
84 webContents_->GetController().LoadURL(url, content::Referrer(),
85 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
86 std::string());
87 [self show];
88 }
89
90 - (void)show {
91 [[self window] makeKeyAndOrderFront:self];
groby-ooo-7-16 2013/12/04 01:59:48 Just inline this into showURL
noms (inactive) 2013/12/05 17:55:06 Hmm, it's also used on line 135 (to focus a window
92 }
93
94 - (void)hide {
95 [[self window] close];
groby-ooo-7-16 2013/12/04 01:59:48 Be aware that -close can delete the window. You mi
noms (inactive) 2013/12/05 17:55:06 Renamed to -close. On 2013/12/04 01:59:48, groby w
96 }
97
98 -(BOOL)isVisible {
99 return [[self window] isVisible];
100 }
101
102 - (void)windowWillClose:(NSNotification*)notification {
103 if (userManagerObserver_) {
groby-ooo-7-16 2013/12/04 01:59:48 all WindowWasClosed will do is delete the UserMana
noms (inactive) 2013/12/05 17:55:06 Addressed with separate reply. On 2013/12/04 01:59
104 userManagerObserver_->WindowWasClosed();
105 userManagerObserver_ = nil;
106 }
107 // Reset the web contents so that the guest profile doesn't have any
108 // renderer hosts, so that the profile can be destroyed cleanly in case the
109 // process is force-killed.
110 webContents_.reset();
111 [self autorelease];
groby-ooo-7-16 2013/12/04 01:59:48 Oy. Self-deleting is never fun. Can you have UserM
noms (inactive) 2013/12/05 17:55:06 Done.
112 }
113
114 - (void)windowDidResize:(NSNotification*)notification {
115 NSView* webContentView = webContents_->GetView()->GetNativeView();
116 DCHECK(webContentView);
117 [webContentView setFrameSize:[[[self window] contentView] frame].size];
118 }
119
120 @end
121
122 // static
123 UserManagerMac* UserManagerMac::instance_ = NULL;
groby-ooo-7-16 2013/12/04 01:59:48 If you _must_ do the instance_ thing (see below re
noms (inactive) 2013/12/05 17:55:06 instance_ is in the UserManagerMac namespace (it's
124
125 UserManagerMac::UserManagerMac(Profile* profile) {
groby-ooo-7-16 2013/12/04 01:59:48 I assume the user manager is tied to a specific br
noms (inactive) 2013/12/05 17:55:06 Addressed by separate reply. On 2013/12/04 01:59:
126 window_controller_ = [[UserManagerWindowController alloc]
127 initWithProfile: profile withObserver:this];
128 }
129
130 UserManagerMac::~UserManagerMac() {
131 }
132
133 // static
134 void UserManagerMac::Show(const base::FilePath& profile_path_to_focus) {
135 if (instance_) {
136 [instance_->window_controller_ show];
137 return;
138 }
139
140 // Create the guest profile, if necessary, and open the User Manager
141 // from the guest profile.
142 ProfileManager* profile_manager = g_browser_process->profile_manager();
143 profile_manager->CreateProfileAsync(
144 ProfileManager::GetGuestProfilePath(),
145 base::Bind(&UserManagerMac::OnGuestProfileCreated,
146 profile_path_to_focus),
147 string16(),
148 string16(),
149 std::string());
150 }
151
152 // static
153 void UserManagerMac::Hide() {
154 if (instance_)
155 [instance_->window_controller_ hide];
156 }
157
158 // static
159 bool UserManagerMac::IsShowing() {
160 return instance_ ? [instance_->window_controller_ isVisible]: false;
groby-ooo-7-16 2013/12/04 01:59:48 Seems like this is not called anywhere.
noms (inactive) 2013/12/05 17:55:06 Done.
161 }
162
163 void UserManagerMac::WindowWasClosed() {
164 delete this;
165 instance_ = NULL;
166 }
167
168 void UserManagerMac::OnGuestProfileCreated(
169 const base::FilePath& profile_path_to_focus,
170 Profile* guest_profile,
171 Profile::CreateStatus status) {
172 if (status != Profile::CREATE_STATUS_INITIALIZED)
173 return;
174
175 instance_ = new UserManagerMac(guest_profile);
176
177 // Tell the webui which user pod should be focused.
178 std::string page = chrome::kChromeUIUserManagerURL;
179
180 if (!profile_path_to_focus.empty()) {
181 ProfileInfoCache& cache =
182 g_browser_process->profile_manager()->GetProfileInfoCache();
183 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus);
184 if (index != std::string::npos) {
groby-ooo-7-16 2013/12/04 01:59:48 Personal nit: I prefer building GURLs via GURLs, n
noms (inactive) 2013/12/05 17:55:06 I'll leave it like this, for now, to be consistent
185 page += "#";
186 page += base::IntToString(index);
187 }
188 }
189 [instance_->window_controller_ showURL:GURL(page)];
190 }
191
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698