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

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: nit 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
« no previous file with comments | « chrome/browser/ui/cocoa/user_manager_mac.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f78abfd0e9058d69c7fd60fd0fb85426bb3471bd 100644
--- a/chrome/browser/ui/cocoa/user_manager_mac.mm
+++ b/chrome/browser/ui/cocoa/user_manager_mac.mm
@@ -2,20 +2,194 @@
// 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"
+
+// Default window size. Taken from the views implementation in
+// chrome/browser/ui/views/user_manager_view.cc.
+// TODO(noms): Figure out if this size can be computed dynamically or adjusted
+// for smaller screens.
+const int kWindowWidth = 900;
+const int kWindowHeight = 700;
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
+
+// Window controller for the User Manager view.
+@interface UserManagerWindowController : NSWindowController <NSWindowDelegate> {
+ @private
+ scoped_ptr<content::WebContents> webContents_;
+ UserManagerMac* userManagerObserver_; // Weak.
+}
+- (void)windowWillClose:(NSNotification*)notification;
+- (void)dealloc;
+- (id)initWithProfile:(Profile*)profile
+ withObserver:(UserManagerMac*)userManagerObserver;
+- (void)showURL:(const GURL&)url;
+- (void)show;
+- (void)close;
+- (BOOL)isVisible;
+@end
+
+@implementation UserManagerWindowController
+
+- (id)initWithProfile:(Profile*)profile
+ withObserver:(UserManagerMac*)userManagerObserver {
+
+ // Center the window on the primary screen.
+ CGFloat screenHeight =
+ [[[NSScreen screens] objectAtIndex:0] frame].size.height;
+ CGFloat screenWidth =
+ [[[NSScreen screens] objectAtIndex:0] frame].size.width;
+
+ NSRect contentRect = NSMakeRect((screenWidth - kWindowWidth) / 2,
+ (screenHeight - kWindowHeight) / 2,
+ kWindowWidth, kWindowHeight);
+ NSWindow* window = [[NSWindow alloc]
+ initWithContentRect:contentRect
+ styleMask:NSTitledWindowMask |
+ NSClosableWindowMask |
+ NSResizableWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO];
+ [window setTitle:l10n_util::GetNSString(IDS_USER_MANAGER_SCREEN_TITLE)];
+
+ if ((self = [super initWithWindow:window])) {
+ userManagerObserver_ = userManagerObserver;
+
+ // Initialize the web view.
+ webContents_.reset(content::WebContents::Create(
+ content::WebContents::CreateParams(profile)));
+ window.contentView = webContents_->GetView()->GetNativeView();
+ DCHECK(window.contentView);
+
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(windowWillClose:)
+ name:NSWindowWillCloseNotification
+ object:self.window];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [super dealloc];
+}
+
+- (void)showURL:(const GURL&)url {
+ webContents_->GetController().LoadURL(url, content::Referrer(),
+ content::PAGE_TRANSITION_AUTO_TOPLEVEL,
+ std::string());
+ [self show];
+}
+
+- (void)show {
+ [[self window] makeKeyAndOrderFront:self];
+}
+
+- (void)close {
+ [[self window] close];
+}
+
+-(BOOL)isVisible {
+ return [[self window] isVisible];
+}
+
+- (void)windowWillClose:(NSNotification*)notification {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ DCHECK(userManagerObserver_);
+ userManagerObserver_->WindowWasClosed();
+}
+
+@end
+
+// static
+UserManagerMac* UserManagerMac::instance_ = NULL;
+
+UserManagerMac::UserManagerMac(Profile* profile) {
+ window_controller_.reset([[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_ close];
+}
+
+// static
+bool UserManagerMac::IsShowing() {
+ return instance_ ? [instance_->window_controller_ isVisible]: false;
+}
+
+void UserManagerMac::WindowWasClosed() {
+ instance_ = NULL;
+ delete this;
+}
+
+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) {
+ page += "#";
+ page += base::IntToString(index);
+ }
+ }
+ [instance_->window_controller_ showURL:GURL(page)];
+}
+
« no previous file with comments | « chrome/browser/ui/cocoa/user_manager_mac.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698