| 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/views/profiles/user_manager_view.h" | 5 #include "chrome/browser/ui/views/profiles/user_manager_view.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 UserManagerView* instance_ = nullptr; | 53 UserManagerView* instance_ = nullptr; |
| 54 base::Closure* user_manager_shown_callback_for_testing_ = nullptr; | 54 base::Closure* user_manager_shown_callback_for_testing_ = nullptr; |
| 55 bool instance_under_construction_ = false; | 55 bool instance_under_construction_ = false; |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 // ReauthDelegate--------------------------------------------------------------- | 58 // ReauthDelegate--------------------------------------------------------------- |
| 59 | 59 |
| 60 ReauthDelegate::ReauthDelegate(UserManagerView* parent, | 60 ReauthDelegate::ReauthDelegate(UserManagerView* parent, |
| 61 views::WebView* web_view, | 61 views::WebView* web_view, |
| 62 const std::string& email_address, | 62 const std::string& email_address, |
| 63 signin_metrics::Reason reason) | 63 const GURL& url) |
| 64 : parent_(parent), | 64 : parent_(parent), web_view_(web_view), email_address_(email_address) { |
| 65 web_view_(web_view), | |
| 66 email_address_(email_address) { | |
| 67 AddChildView(web_view_); | 65 AddChildView(web_view_); |
| 68 SetLayoutManager(new views::FillLayout()); | 66 SetLayoutManager(new views::FillLayout()); |
| 69 | 67 |
| 70 web_view_->GetWebContents()->SetDelegate(this); | 68 web_view_->GetWebContents()->SetDelegate(this); |
| 71 | |
| 72 // Load the re-auth URL, prepopulated with the user's email address. | |
| 73 // Add the index of the profile to the URL so that the inline login page | |
| 74 // knows which profile to load and update the credentials. | |
| 75 GURL url = signin::GetReauthURLWithEmail( | |
| 76 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason, | |
| 77 email_address_); | |
| 78 web_view_->LoadInitialURL(url); | 69 web_view_->LoadInitialURL(url); |
| 79 } | 70 } |
| 80 | 71 |
| 81 ReauthDelegate::~ReauthDelegate() {} | 72 ReauthDelegate::~ReauthDelegate() {} |
| 82 | 73 |
| 83 gfx::Size ReauthDelegate::GetPreferredSize() const { | 74 gfx::Size ReauthDelegate::GetPreferredSize() const { |
| 84 return switches::UsePasswordSeparatedSigninFlow() ? | 75 return switches::UsePasswordSeparatedSigninFlow() ? |
| 85 gfx::Size(UserManager::kReauthDialogWidth, | 76 gfx::Size(UserManager::kReauthDialogWidth, |
| 86 UserManager::kReauthDialogHeight) : | 77 UserManager::kReauthDialogHeight) : |
| 87 gfx::Size(UserManager::kPasswordCombinedReauthDialogWidth, | 78 gfx::Size(UserManager::kPasswordCombinedReauthDialogWidth, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 199 } |
| 209 } | 200 } |
| 210 | 201 |
| 211 // static | 202 // static |
| 212 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, | 203 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, |
| 213 const std::string& email, | 204 const std::string& email, |
| 214 signin_metrics::Reason reason) { | 205 signin_metrics::Reason reason) { |
| 215 // This method should only be called if the user manager is already showing. | 206 // This method should only be called if the user manager is already showing. |
| 216 if (!IsShowing()) | 207 if (!IsShowing()) |
| 217 return; | 208 return; |
| 218 instance_->ShowReauthDialog(browser_context, email, reason); | 209 // Load the re-auth URL, prepopulated with the user's email address. |
| 210 // Add the index of the profile to the URL so that the inline login page |
| 211 // knows which profile to load and update the credentials. |
| 212 GURL url = signin::GetReauthURLWithEmail( |
| 213 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason, email); |
| 214 instance_->ShowDialog(browser_context, email, url); |
| 219 } | 215 } |
| 220 | 216 |
| 221 // static | 217 // static |
| 222 void UserManager::HideReauthDialog() { | 218 void UserManager::HideDialog() { |
| 223 // This method should only be called if the user manager is already showing. | |
| 224 if (instance_ && instance_->GetWidget()->IsVisible()) | 219 if (instance_ && instance_->GetWidget()->IsVisible()) |
| 225 instance_->HideReauthDialog(); | 220 instance_->HideDialog(); |
| 226 } | 221 } |
| 227 | 222 |
| 228 // static | 223 // static |
| 229 void UserManager::AddOnUserManagerShownCallbackForTesting( | 224 void UserManager::AddOnUserManagerShownCallbackForTesting( |
| 230 const base::Closure& callback) { | 225 const base::Closure& callback) { |
| 231 DCHECK(!user_manager_shown_callback_for_testing_); | 226 DCHECK(!user_manager_shown_callback_for_testing_); |
| 232 user_manager_shown_callback_for_testing_ = new base::Closure(callback); | 227 user_manager_shown_callback_for_testing_ = new base::Closure(callback); |
| 233 } | 228 } |
| 234 | 229 |
| 235 // static | 230 // static |
| 236 void UserManager::ShowSigninDialog(content::BrowserContext* browser_context, | 231 void UserManager::ShowSigninDialog(content::BrowserContext* browser_context, |
| 237 const base::FilePath& profile_path) { | 232 const base::FilePath& profile_path) { |
| 238 if (!IsShowing()) | 233 if (!IsShowing()) |
| 239 return; | 234 return; |
| 240 instance_->SetSigninProfilePath(profile_path); | 235 instance_->SetSigninProfilePath(profile_path); |
| 241 ShowReauthDialog(browser_context, std::string(), | 236 GURL url = signin::GetPromoURL( |
| 242 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT); | 237 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, |
| 238 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, true, true); |
| 239 instance_->ShowDialog(browser_context, std::string(), url); |
| 243 } | 240 } |
| 244 | 241 |
| 245 // static | 242 // static |
| 246 void UserManager::DisplayErrorMessage() { | 243 void UserManager::DisplayErrorMessage() { |
| 247 // This method should only be called if the user manager is already showing. | 244 // This method should only be called if the user manager is already showing. |
| 248 DCHECK(instance_); | 245 DCHECK(instance_); |
| 249 instance_->DisplayErrorMessage(); | 246 instance_->DisplayErrorMessage(); |
| 250 } | 247 } |
| 251 | 248 |
| 249 void UserManager::ShowDialogAndDisplayErrorMessage( |
| 250 content::BrowserContext* browser_context) { |
| 251 DCHECK(instance_); |
| 252 instance_->ShowDialog(browser_context, std::string(), |
| 253 GURL(chrome::kChromeUISigninErrorURL)); |
| 254 } |
| 255 |
| 252 // static | 256 // static |
| 253 base::FilePath UserManager::GetSigninProfilePath() { | 257 base::FilePath UserManager::GetSigninProfilePath() { |
| 254 return instance_->GetSigninProfilePath(); | 258 return instance_->GetSigninProfilePath(); |
| 255 } | 259 } |
| 256 | 260 |
| 257 // UserManagerView ------------------------------------------------------------- | 261 // UserManagerView ------------------------------------------------------------- |
| 258 | 262 |
| 259 UserManagerView::UserManagerView() | 263 UserManagerView::UserManagerView() |
| 260 : web_view_(nullptr), | 264 : web_view_(nullptr), |
| 261 delegate_(nullptr), | 265 delegate_(nullptr), |
| 262 user_manager_started_showing_(base::Time()) { | 266 user_manager_started_showing_(base::Time()) { |
| 263 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW, | 267 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW, |
| 264 KeepAliveRestartOption::DISABLED)); | 268 KeepAliveRestartOption::DISABLED)); |
| 265 } | 269 } |
| 266 | 270 |
| 267 UserManagerView::~UserManagerView() { | 271 UserManagerView::~UserManagerView() { |
| 268 HideReauthDialog(); | 272 HideDialog(); |
| 269 } | 273 } |
| 270 | 274 |
| 271 // static | 275 // static |
| 272 void UserManagerView::OnSystemProfileCreated( | 276 void UserManagerView::OnSystemProfileCreated( |
| 273 std::unique_ptr<UserManagerView> instance, | 277 std::unique_ptr<UserManagerView> instance, |
| 274 base::AutoReset<bool>* pending, | 278 base::AutoReset<bool>* pending, |
| 275 Profile* system_profile, | 279 Profile* system_profile, |
| 276 const std::string& url) { | 280 const std::string& url) { |
| 277 // If we are showing the User Manager after locking a profile, change the | 281 // If we are showing the User Manager after locking a profile, change the |
| 278 // active profile to Guest. | 282 // active profile to Guest. |
| 279 profiles::SetActiveProfileToGuestIfLocked(); | 283 profiles::SetActiveProfileToGuestIfLocked(); |
| 280 | 284 |
| 281 DCHECK(!instance_); | 285 DCHECK(!instance_); |
| 282 instance_ = instance.release(); // |instance_| takes over ownership. | 286 instance_ = instance.release(); // |instance_| takes over ownership. |
| 283 instance_->Init(system_profile, GURL(url)); | 287 instance_->Init(system_profile, GURL(url)); |
| 284 } | 288 } |
| 285 | 289 |
| 286 void UserManagerView::ShowReauthDialog(content::BrowserContext* browser_context, | 290 void UserManagerView::ShowDialog(content::BrowserContext* browser_context, |
| 287 const std::string& email, | 291 const std::string& email, |
| 288 signin_metrics::Reason reason) { | 292 const GURL& url) { |
| 289 HideReauthDialog(); | 293 HideDialog(); |
| 290 // The dialog delegate will be deleted when the widget closes. The created | 294 // The dialog delegate will be deleted when the widget closes. The created |
| 291 // WebView's lifetime is managed by the delegate. | 295 // WebView's lifetime is managed by the delegate. |
| 292 delegate_ = new ReauthDelegate(this, | 296 delegate_ = |
| 293 new views::WebView(browser_context), | 297 new ReauthDelegate(this, new views::WebView(browser_context), email, url); |
| 294 email, | |
| 295 reason); | |
| 296 gfx::NativeView parent = instance_->GetWidget()->GetNativeView(); | 298 gfx::NativeView parent = instance_->GetWidget()->GetNativeView(); |
| 297 views::DialogDelegate::CreateDialogWidget(delegate_, nullptr, parent); | 299 views::DialogDelegate::CreateDialogWidget(delegate_, nullptr, parent); |
| 298 delegate_->GetWidget()->Show(); | 300 delegate_->GetWidget()->Show(); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void UserManagerView::HideReauthDialog() { | 303 void UserManagerView::HideDialog() { |
| 302 if (delegate_) { | 304 if (delegate_) { |
| 303 delegate_->CloseReauthDialog(); | 305 delegate_->CloseReauthDialog(); |
| 304 DCHECK(!delegate_); | 306 DCHECK(!delegate_); |
| 305 } | 307 } |
| 306 } | 308 } |
| 307 | 309 |
| 308 void UserManagerView::OnReauthDialogDestroyed() { | 310 void UserManagerView::OnReauthDialogDestroyed() { |
| 309 delegate_ = nullptr; | 311 delegate_ = nullptr; |
| 310 } | 312 } |
| 311 | 313 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 delegate_->DisplayErrorMessage(); | 440 delegate_->DisplayErrorMessage(); |
| 439 } | 441 } |
| 440 | 442 |
| 441 void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) { | 443 void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) { |
| 442 signin_profile_path_ = profile_path; | 444 signin_profile_path_ = profile_path; |
| 443 } | 445 } |
| 444 | 446 |
| 445 base::FilePath UserManagerView::GetSigninProfilePath() { | 447 base::FilePath UserManagerView::GetSigninProfilePath() { |
| 446 return signin_profile_path_; | 448 return signin_profile_path_; |
| 447 } | 449 } |
| OLD | NEW |