| OLD | NEW |
| 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 #include "chrome/browser/ui/cocoa/user_manager_mac.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" | 7 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/ui/browser_dialogs.h" | 9 #include "chrome/browser/ui/browser_dialogs.h" |
| 11 #include "chrome/common/url_constants.h" | |
| 12 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_view.h" | 11 #include "content/public/browser/web_contents_view.h" |
| 14 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util_mac.h" | 13 #include "ui/base/l10n/l10n_util_mac.h" |
| 16 | 14 |
| 17 // Default window size. Taken from the views implementation in | 15 // Default window size. Taken from the views implementation in |
| 18 // chrome/browser/ui/views/user_manager_view.cc. | 16 // chrome/browser/ui/views/user_manager_view.cc. |
| 19 // TODO(noms): Figure out if this size can be computed dynamically or adjusted | 17 // TODO(noms): Figure out if this size can be computed dynamically or adjusted |
| 20 // for smaller screens. | 18 // for smaller screens. |
| 21 const int kWindowWidth = 900; | 19 const int kWindowWidth = 900; |
| 22 const int kWindowHeight = 700; | 20 const int kWindowHeight = 700; |
| 23 | 21 |
| 24 namespace chrome { | 22 namespace chrome { |
| 25 | 23 |
| 26 // Declared in browser_dialogs.h so others don't have to depend on this header. | 24 // Declared in browser_dialogs.h so others don't have to depend on this header. |
| 27 void ShowUserManager(const base::FilePath& profile_path_to_focus) { | 25 void ShowUserManager(const base::FilePath& profile_path_to_focus) { |
| 28 UserManagerMac::Show(profile_path_to_focus); | 26 UserManagerMac::Show( |
| 27 profile_path_to_focus, profiles::USER_MANAGER_NO_TUTORIAL); |
| 28 } |
| 29 |
| 30 void ShowUserManagerWithTutorial(profiles::UserManagerTutorialMode tutorial) { |
| 31 UserManagerMac::Show(base::FilePath(), tutorial); |
| 29 } | 32 } |
| 30 | 33 |
| 31 void HideUserManager() { | 34 void HideUserManager() { |
| 32 UserManagerMac::Hide(); | 35 UserManagerMac::Hide(); |
| 33 } | 36 } |
| 34 | 37 |
| 35 } // namespace chrome | 38 } // namespace chrome |
| 36 | 39 |
| 37 // Window controller for the User Manager view. | 40 // Window controller for the User Manager view. |
| 38 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { | 41 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 131 |
| 129 UserManagerMac::UserManagerMac(Profile* profile) { | 132 UserManagerMac::UserManagerMac(Profile* profile) { |
| 130 window_controller_.reset([[UserManagerWindowController alloc] | 133 window_controller_.reset([[UserManagerWindowController alloc] |
| 131 initWithProfile:profile withObserver:this]); | 134 initWithProfile:profile withObserver:this]); |
| 132 } | 135 } |
| 133 | 136 |
| 134 UserManagerMac::~UserManagerMac() { | 137 UserManagerMac::~UserManagerMac() { |
| 135 } | 138 } |
| 136 | 139 |
| 137 // static | 140 // static |
| 138 void UserManagerMac::Show(const base::FilePath& profile_path_to_focus) { | 141 void UserManagerMac::Show(const base::FilePath& profile_path_to_focus, |
| 142 profiles::UserManagerTutorialMode tutorial_mode) { |
| 139 if (instance_) { | 143 if (instance_) { |
| 144 // If there's a user manager window open already, just activate it. |
| 140 [instance_->window_controller_ show]; | 145 [instance_->window_controller_ show]; |
| 141 return; | 146 return; |
| 142 } | 147 } |
| 143 | 148 |
| 144 // Create the guest profile, if necessary, and open the User Manager | 149 // Create the guest profile, if necessary, and open the user manager |
| 145 // from the guest profile. | 150 // from the guest profile. |
| 146 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 151 profiles::CreateGuestProfileForUserManager( |
| 147 profile_manager->CreateProfileAsync( | 152 profile_path_to_focus, |
| 148 ProfileManager::GetGuestProfilePath(), | 153 tutorial_mode, |
| 149 base::Bind(&UserManagerMac::OnGuestProfileCreated, | 154 base::Bind(&UserManagerMac::OnGuestProfileCreated)); |
| 150 profile_path_to_focus), | |
| 151 base::string16(), | |
| 152 base::string16(), | |
| 153 std::string()); | |
| 154 } | 155 } |
| 155 | 156 |
| 156 // static | 157 // static |
| 157 void UserManagerMac::Hide() { | 158 void UserManagerMac::Hide() { |
| 158 if (instance_) | 159 if (instance_) |
| 159 [instance_->window_controller_ close]; | 160 [instance_->window_controller_ close]; |
| 160 } | 161 } |
| 161 | 162 |
| 162 // static | 163 // static |
| 163 bool UserManagerMac::IsShowing() { | 164 bool UserManagerMac::IsShowing() { |
| 164 return instance_ ? [instance_->window_controller_ isVisible]: false; | 165 return instance_ ? [instance_->window_controller_ isVisible]: false; |
| 165 } | 166 } |
| 166 | 167 |
| 168 // static |
| 169 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, |
| 170 const std::string& url) { |
| 171 instance_ = new UserManagerMac(guest_profile); |
| 172 [instance_->window_controller_ showURL:GURL(url)]; |
| 173 } |
| 174 |
| 167 void UserManagerMac::WindowWasClosed() { | 175 void UserManagerMac::WindowWasClosed() { |
| 168 instance_ = NULL; | 176 instance_ = NULL; |
| 169 delete this; | 177 delete this; |
| 170 } | 178 } |
| 171 | |
| 172 void UserManagerMac::OnGuestProfileCreated( | |
| 173 const base::FilePath& profile_path_to_focus, | |
| 174 Profile* guest_profile, | |
| 175 Profile::CreateStatus status) { | |
| 176 if (status != Profile::CREATE_STATUS_INITIALIZED) | |
| 177 return; | |
| 178 | |
| 179 instance_ = new UserManagerMac(guest_profile); | |
| 180 | |
| 181 // Tell the webui which user pod should be focused. | |
| 182 std::string page = chrome::kChromeUIUserManagerURL; | |
| 183 | |
| 184 if (!profile_path_to_focus.empty()) { | |
| 185 ProfileInfoCache& cache = | |
| 186 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 187 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus); | |
| 188 if (index != std::string::npos) { | |
| 189 page += "#"; | |
| 190 page += base::IntToString(index); | |
| 191 } | |
| 192 } | |
| 193 [instance_->window_controller_ showURL:GURL(page)]; | |
| 194 } | |
| 195 | |
| OLD | NEW |