| OLD | NEW |
| 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 #include "ui/events/keycodes/keyboard_codes.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 namespace chrome { |
| 27 | 28 |
| 28 // Declared in browser_dialogs.h so others don't have to depend on this header. | 29 // Declared in browser_dialogs.h so others don't have to depend on this header. |
| 29 void ShowUserManager(const base::FilePath& profile_path_to_focus) { | 30 void ShowUserManager(const base::FilePath& profile_path_to_focus) { |
| 30 UserManagerMac::Show( | 31 UserManagerMac::Show( |
| 31 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); | 32 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { | 35 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { |
| 35 UserManagerMac::Show(base::FilePath(), tutorial); | 36 UserManagerMac::Show(base::FilePath(), tutorial); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void HideUserManager() { | 39 void HideUserManager() { |
| 39 UserManagerMac::Hide(); | 40 UserManagerMac::Hide(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 } // namespace chrome | 43 } // namespace chrome |
| 43 | 44 |
| 44 // Custom WebContentsDelegate that allows handling of hotkeys. | 45 // Custom WebContentsDelegate that allows handling of hotkeys. |
| 45 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { | 46 class UserManagerWebContentsDelegate : public content::WebContentsDelegate { |
| 46 public: | 47 public: |
| 47 UserManagerWebContentsDelegate(ChromeEventProcessingWindow* window) | 48 UserManagerWebContentsDelegate() {} |
| 48 : window_(window) {} | |
| 49 | 49 |
| 50 // WebContentsDelegate implementation. Forwards all unhandled keyboard events | 50 // WebContentsDelegate implementation. Forwards all unhandled keyboard events |
| 51 // to the current window. | 51 // to the current window. |
| 52 virtual void HandleKeyboardEvent( | 52 virtual void HandleKeyboardEvent( |
| 53 content::WebContents* source, | 53 content::WebContents* source, |
| 54 const content::NativeWebKeyboardEvent& event) OVERRIDE { | 54 const content::NativeWebKeyboardEvent& event) OVERRIDE { |
| 55 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) | 55 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 int commandId = [BrowserWindowUtils getCommandId:event]; | 58 // -getCommandId returns -1 if the event isn't a chrome accelerator. |
| 59 int chromeCommandId = [BrowserWindowUtils getCommandId:event]; |
| 59 | 60 |
| 60 // Since the User Manager is a "top level" window, only handle close events. | 61 // Check for Cmd+A and Cmd+V events that could come from a password field. |
| 61 if (commandId == IDC_CLOSE_WINDOW || commandId == IDC_EXIT) { | 62 bool isTextEditingCommand = |
| 62 // Not invoking +[BrowserWindowUtils handleKeyboardEvent here], since the | 63 (event.modifiers & blink::WebInputEvent::MetaKey) && |
| 63 // window in question is a ConstrainedWindowCustomWindow, not a | 64 (event.windowsKeyCode == ui::VKEY_A || |
| 64 // BrowserWindow. | 65 event.windowsKeyCode == ui::VKEY_V); |
| 65 [window_ redispatchKeyEvent:event.os_event]; | 66 |
| 67 // Only handle close window Chrome accelerators and text editing ones. |
| 68 if (chromeCommandId == IDC_CLOSE_WINDOW || chromeCommandId == IDC_EXIT || |
| 69 isTextEditingCommand) { |
| 70 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; |
| 66 } | 71 } |
| 67 } | 72 } |
| 68 | |
| 69 private: | |
| 70 ChromeEventProcessingWindow* window_; // Used to redispatch key events. | |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 // Window controller for the User Manager view. | 75 // Window controller for the User Manager view. |
| 74 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { | 76 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { |
| 75 @private | 77 @private |
| 76 scoped_ptr<content::WebContents> webContents_; | 78 scoped_ptr<content::WebContents> webContents_; |
| 77 scoped_ptr<UserManagerWebContentsDelegate> webContentsDelegate_; | 79 scoped_ptr<UserManagerWebContentsDelegate> webContentsDelegate_; |
| 78 UserManagerMac* userManagerObserver_; // Weak. | 80 UserManagerMac* userManagerObserver_; // Weak. |
| 79 } | 81 } |
| 80 - (void)windowWillClose:(NSNotification*)notification; | 82 - (void)windowWillClose:(NSNotification*)notification; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 111 [window setTitle:l10n_util::GetNSString(IDS_PRODUCT_NAME)]; | 113 [window setTitle:l10n_util::GetNSString(IDS_PRODUCT_NAME)]; |
| 112 [window setMinSize:NSMakeSize(kWindowWidth, kWindowHeight)]; | 114 [window setMinSize:NSMakeSize(kWindowWidth, kWindowHeight)]; |
| 113 | 115 |
| 114 if ((self = [super initWithWindow:window])) { | 116 if ((self = [super initWithWindow:window])) { |
| 115 userManagerObserver_ = userManagerObserver; | 117 userManagerObserver_ = userManagerObserver; |
| 116 | 118 |
| 117 // Initialize the web view. | 119 // Initialize the web view. |
| 118 webContents_.reset(content::WebContents::Create( | 120 webContents_.reset(content::WebContents::Create( |
| 119 content::WebContents::CreateParams(profile))); | 121 content::WebContents::CreateParams(profile))); |
| 120 window.contentView = webContents_->GetNativeView(); | 122 window.contentView = webContents_->GetNativeView(); |
| 121 webContentsDelegate_.reset(new UserManagerWebContentsDelegate(window)); | 123 webContentsDelegate_.reset(new UserManagerWebContentsDelegate()); |
| 122 webContents_->SetDelegate(webContentsDelegate_.get()); | 124 webContents_->SetDelegate(webContentsDelegate_.get()); |
| 123 DCHECK(window.contentView); | 125 DCHECK(window.contentView); |
| 124 | 126 |
| 125 [[NSNotificationCenter defaultCenter] | 127 [[NSNotificationCenter defaultCenter] |
| 126 addObserver:self | 128 addObserver:self |
| 127 selector:@selector(windowWillClose:) | 129 selector:@selector(windowWillClose:) |
| 128 name:NSWindowWillCloseNotification | 130 name:NSWindowWillCloseNotification |
| 129 object:self.window]; | 131 object:self.window]; |
| 130 } | 132 } |
| 131 return self; | 133 return self; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| OLD | NEW |