| 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); |
| 29 } | 28 } |
| 30 | 29 |
| 31 void HideUserManager() { | 30 void HideUserManager() { |
| 32 UserManagerMac::Hide(); | 31 UserManagerMac::Hide(); |
| 33 } | 32 } |
| 34 | 33 |
| 35 } // namespace chrome | 34 } // namespace chrome |
| 36 | 35 |
| 37 // Window controller for the User Manager view. | 36 // Window controller for the User Manager view. |
| 38 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { | 37 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 127 |
| 129 UserManagerMac::UserManagerMac(Profile* profile) { | 128 UserManagerMac::UserManagerMac(Profile* profile) { |
| 130 window_controller_.reset([[UserManagerWindowController alloc] | 129 window_controller_.reset([[UserManagerWindowController alloc] |
| 131 initWithProfile:profile withObserver:this]); | 130 initWithProfile:profile withObserver:this]); |
| 132 } | 131 } |
| 133 | 132 |
| 134 UserManagerMac::~UserManagerMac() { | 133 UserManagerMac::~UserManagerMac() { |
| 135 } | 134 } |
| 136 | 135 |
| 137 // static | 136 // static |
| 138 void UserManagerMac::Show(const base::FilePath& profile_path_to_focus) { | 137 void UserManagerMac::Show(const base::FilePath& profile_path_to_focus, |
| 138 profiles::UserManagerTutorialMode tutorial_mode) { |
| 139 if (instance_) { | 139 if (instance_) { |
| 140 // If there's a user manager window open already, just activate it. |
| 140 [instance_->window_controller_ show]; | 141 [instance_->window_controller_ show]; |
| 141 return; | 142 return; |
| 142 } | 143 } |
| 143 | 144 |
| 144 // Create the guest profile, if necessary, and open the User Manager | 145 // Create the guest profile, if necessary, and open the user manager |
| 145 // from the guest profile. | 146 // from the guest profile. |
| 146 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 147 profiles::CreateGuestProfileForUserManager( |
| 147 profile_manager->CreateProfileAsync( | 148 profile_path_to_focus, |
| 148 ProfileManager::GetGuestProfilePath(), | 149 tutorial_mode, |
| 149 base::Bind(&UserManagerMac::OnGuestProfileCreated, | 150 base::Bind(&UserManagerMac::OnGuestProfileCreated)); |
| 150 profile_path_to_focus), | |
| 151 base::string16(), | |
| 152 base::string16(), | |
| 153 std::string()); | |
| 154 } | 151 } |
| 155 | 152 |
| 156 // static | 153 // static |
| 157 void UserManagerMac::Hide() { | 154 void UserManagerMac::Hide() { |
| 158 if (instance_) | 155 if (instance_) |
| 159 [instance_->window_controller_ close]; | 156 [instance_->window_controller_ close]; |
| 160 } | 157 } |
| 161 | 158 |
| 162 // static | 159 // static |
| 163 bool UserManagerMac::IsShowing() { | 160 bool UserManagerMac::IsShowing() { |
| 164 return instance_ ? [instance_->window_controller_ isVisible]: false; | 161 return instance_ ? [instance_->window_controller_ isVisible]: false; |
| 165 } | 162 } |
| 166 | 163 |
| 164 // static |
| 165 void UserManagerMac::OnGuestProfileCreated(Profile* guest_profile, |
| 166 const std::string& url) { |
| 167 instance_ = new UserManagerMac(guest_profile); |
| 168 [instance_->window_controller_ showURL:GURL(url)]; |
| 169 } |
| 170 |
| 167 void UserManagerMac::WindowWasClosed() { | 171 void UserManagerMac::WindowWasClosed() { |
| 168 instance_ = NULL; | 172 instance_ = NULL; |
| 169 delete this; | 173 delete this; |
| 170 } | 174 } |
| 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 |