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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/user_manager_mac.mm
diff --git a/chrome/browser/ui/cocoa/user_manager_mac.mm b/chrome/browser/ui/cocoa/user_manager_mac.mm
index 07818f33ff8d69615ef679d3fb33e91002e72208..d54fa3c7042e57ce13eb074674f4729b59b10ba2 100644
--- a/chrome/browser/ui/cocoa/user_manager_mac.mm
+++ b/chrome/browser/ui/cocoa/user_manager_mac.mm
@@ -2,20 +2,190 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#import <Cocoa/Cocoa.h>
+#include "chrome/browser/ui/cocoa/user_manager_mac.h"
+#include "base/strings/string_number_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_dialogs.h"
+#include "chrome/common/url_constants.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util_mac.h"
+
+namespace {
+
groby-ooo-7-16 2013/12/04 01:59:48 No need for anon namespaces if it's constants only
+// Default window size. Taken from the views implementation in
+// chrome/browser/ui/views/user_manager_view.cc.
+const int kWindowWidth = 900;
+const int kWindowHeight = 700;
groby-ooo-7-16 2013/12/04 01:59:48 Hm. You might want to dynamically size this, maybe
+
+} // namespace
namespace chrome {
// Declared in browser_dialogs.h so others don't have to depend on this header.
-// TODO(noms): Add implementation when the User Manager dialog is implemented.
void ShowUserManager(const base::FilePath& profile_path_to_focus) {
- NOTIMPLEMENTED();
+ UserManagerMac::Show(profile_path_to_focus);
}
void HideUserManager() {
- NOTIMPLEMENTED();
+ UserManagerMac::Hide();
}
} // namespace chrome
+
+@interface UserManagerWindowController (Private)
+- (void)windowWillClose:(NSNotification*)notification;
+- (void)windowDidResize:(NSNotification*)notification;
+@end
+
+@implementation UserManagerWindowController
+
+- (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.
+ withObserver:(UserManagerMac*) userManagerObserver {
+
+ userManagerObserver_ = userManagerObserver;
+ NSWindow* window = [[NSWindow alloc]
+ 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
+ styleMask:NSTitledWindowMask |
+ NSClosableWindowMask |
+ NSResizableWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO];
+ [window setTitle:l10n_util::GetNSString(IDS_USER_MANAGER_SCREEN_TITLE)];
+
+ // Initialize the web view.
+ webContents_.reset(content::WebContents::Create(
+ content::WebContents::CreateParams(profile)));
+ NSView* webContentView = webContents_->GetView()->GetNativeView();
+ DCHECK(webContentView);
+
+ 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
+ [webContentView setFrameSize:[contentView frame].size];
+ [contentView addSubview:webContentView];
+
+ // Initialize, but don't show the window until the web contents have loaded.
+ self = [super initWithWindow:window];
+
+ [[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.
+ selector:@selector(windowWillClose:)
+ name:NSWindowWillCloseNotification
+ object:self.window];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(windowDidResize:)
+ name:NSWindowDidResizeNotification
+ object:self.window];
+ return self;
+}
+
+- (void)showURL:(GURL)url {
+ webContents_->GetController().LoadURL(url, content::Referrer(),
+ content::PAGE_TRANSITION_AUTO_TOPLEVEL,
+ std::string());
+ [self show];
+}
+
+- (void)show {
+ [[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
+}
+
+- (void)hide {
+ [[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
+}
+
+-(BOOL)isVisible {
+ return [[self window] isVisible];
+}
+
+- (void)windowWillClose:(NSNotification*)notification {
+ 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
+ userManagerObserver_->WindowWasClosed();
+ userManagerObserver_ = nil;
+ }
+ // Reset the web contents so that the guest profile doesn't have any
+ // renderer hosts, so that the profile can be destroyed cleanly in case the
+ // process is force-killed.
+ webContents_.reset();
+ [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.
+}
+
+- (void)windowDidResize:(NSNotification*)notification {
+ NSView* webContentView = webContents_->GetView()->GetNativeView();
+ DCHECK(webContentView);
+ [webContentView setFrameSize:[[[self window] contentView] frame].size];
+}
+
+@end
+
+// static
+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
+
+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:
+ window_controller_ = [[UserManagerWindowController alloc]
+ initWithProfile: profile withObserver:this];
+}
+
+UserManagerMac::~UserManagerMac() {
+}
+
+// static
+void UserManagerMac::Show(const base::FilePath& profile_path_to_focus) {
+ if (instance_) {
+ [instance_->window_controller_ show];
+ return;
+ }
+
+ // Create the guest profile, if necessary, and open the User Manager
+ // from the guest profile.
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ profile_manager->CreateProfileAsync(
+ ProfileManager::GetGuestProfilePath(),
+ base::Bind(&UserManagerMac::OnGuestProfileCreated,
+ profile_path_to_focus),
+ string16(),
+ string16(),
+ std::string());
+}
+
+// static
+void UserManagerMac::Hide() {
+ if (instance_)
+ [instance_->window_controller_ hide];
+}
+
+// static
+bool UserManagerMac::IsShowing() {
+ 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.
+}
+
+void UserManagerMac::WindowWasClosed() {
+ delete this;
+ instance_ = NULL;
+}
+
+void UserManagerMac::OnGuestProfileCreated(
+ const base::FilePath& profile_path_to_focus,
+ Profile* guest_profile,
+ Profile::CreateStatus status) {
+ if (status != Profile::CREATE_STATUS_INITIALIZED)
+ return;
+
+ instance_ = new UserManagerMac(guest_profile);
+
+ // Tell the webui which user pod should be focused.
+ std::string page = chrome::kChromeUIUserManagerURL;
+
+ if (!profile_path_to_focus.empty()) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus);
+ 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
+ page += "#";
+ page += base::IntToString(index);
+ }
+ }
+ [instance_->window_controller_ showURL:GURL(page)];
+}
+

Powered by Google App Engine
This is Rietveld 408576698