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" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/lifetime/keep_alive_types.h" | 12 #include "chrome/browser/lifetime/keep_alive_types.h" |
13 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 13 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
14 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 14 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
16 #include "chrome/browser/profiles/profile_metrics.h" | 16 #include "chrome/browser/profiles/profile_metrics.h" |
17 #include "chrome/browser/profiles/profile_window.h" | 17 #include "chrome/browser/profiles/profile_window.h" |
18 #include "chrome/browser/profiles/profiles_state.h" | 18 #include "chrome/browser/profiles/profiles_state.h" |
19 #include "chrome/browser/signin/signin_promo.h" | 19 #include "chrome/browser/signin/signin_promo.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_dialogs.h" | 21 #include "chrome/browser/ui/browser_dialogs.h" |
22 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
23 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/user_manager.h" | 24 #include "chrome/browser/ui/user_manager.h" |
| 25 #include "chrome/common/url_constants.h" |
25 #include "chrome/grit/chromium_strings.h" | 26 #include "chrome/grit/chromium_strings.h" |
26 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
27 #include "components/guest_view/browser/guest_view_manager.h" | 28 #include "components/guest_view/browser/guest_view_manager.h" |
28 #include "components/signin/core/common/profile_management_switches.h" | 29 #include "components/signin/core/common/profile_management_switches.h" |
29 #include "content/public/browser/navigation_details.h" | 30 #include "content/public/browser/navigation_details.h" |
30 #include "content/public/browser/render_widget_host_view.h" | 31 #include "content/public/browser/render_widget_host_view.h" |
31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
32 #include "google_apis/gaia/gaia_urls.h" | 33 #include "google_apis/gaia/gaia_urls.h" |
33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
34 #include "ui/display/display.h" | 35 #include "ui/display/display.h" |
(...skipping 24 matching lines...) Expand all Loading... |
59 ReauthDelegate::ReauthDelegate(UserManagerView* parent, | 60 ReauthDelegate::ReauthDelegate(UserManagerView* parent, |
60 views::WebView* web_view, | 61 views::WebView* web_view, |
61 const std::string& email_address, | 62 const std::string& email_address, |
62 signin_metrics::Reason reason) | 63 signin_metrics::Reason reason) |
63 : parent_(parent), | 64 : parent_(parent), |
64 web_view_(web_view), | 65 web_view_(web_view), |
65 email_address_(email_address) { | 66 email_address_(email_address) { |
66 AddChildView(web_view_); | 67 AddChildView(web_view_); |
67 SetLayoutManager(new views::FillLayout()); | 68 SetLayoutManager(new views::FillLayout()); |
68 | 69 |
69 web_view->GetWebContents()->SetDelegate(this); | 70 web_view_->GetWebContents()->SetDelegate(this); |
70 | 71 |
71 // Load the re-auth URL, prepopulated with the user's email address. | 72 // Load the re-auth URL, prepopulated with the user's email address. |
72 // Add the index of the profile to the URL so that the inline login page | 73 // Add the index of the profile to the URL so that the inline login page |
73 // knows which profile to load and update the credentials. | 74 // knows which profile to load and update the credentials. |
74 GURL url = signin::GetReauthURLWithEmail( | 75 GURL url = signin::GetReauthURLWithEmail( |
75 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason, | 76 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason, |
76 email_address_); | 77 email_address_); |
77 web_view_->LoadInitialURL(url); | 78 web_view_->LoadInitialURL(url); |
78 } | 79 } |
79 | 80 |
80 ReauthDelegate::~ReauthDelegate() {} | 81 ReauthDelegate::~ReauthDelegate() {} |
81 | 82 |
82 gfx::Size ReauthDelegate::GetPreferredSize() const { | 83 gfx::Size ReauthDelegate::GetPreferredSize() const { |
83 return switches::UsePasswordSeparatedSigninFlow() ? | 84 return switches::UsePasswordSeparatedSigninFlow() ? |
84 gfx::Size(UserManager::kReauthDialogWidth, | 85 gfx::Size(UserManager::kReauthDialogWidth, |
85 UserManager::kReauthDialogHeight) : | 86 UserManager::kReauthDialogHeight) : |
86 gfx::Size(UserManager::kPasswordCombinedReauthDialogWidth, | 87 gfx::Size(UserManager::kPasswordCombinedReauthDialogWidth, |
87 UserManager::kPasswordCombinedReauthDialogHeight); | 88 UserManager::kPasswordCombinedReauthDialogHeight); |
88 } | 89 } |
89 | 90 |
| 91 void ReauthDelegate::DisplayErrorMessage() { |
| 92 web_view_->LoadInitialURL(GURL(chrome::kChromeUISigninErrorURL)); |
| 93 } |
| 94 |
90 bool ReauthDelegate::CanResize() const { | 95 bool ReauthDelegate::CanResize() const { |
91 return true; | 96 return true; |
92 } | 97 } |
93 | 98 |
94 bool ReauthDelegate::CanMaximize() const { | 99 bool ReauthDelegate::CanMaximize() const { |
95 return true; | 100 return true; |
96 } | 101 } |
97 | 102 |
98 bool ReauthDelegate::CanMinimize() const { | 103 bool ReauthDelegate::CanMinimize() const { |
99 return true; | 104 return true; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 208 } |
204 } | 209 } |
205 | 210 |
206 // static | 211 // static |
207 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, | 212 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, |
208 const std::string& email, | 213 const std::string& email, |
209 signin_metrics::Reason reason) { | 214 signin_metrics::Reason reason) { |
210 // This method should only be called if the user manager is already showing. | 215 // This method should only be called if the user manager is already showing. |
211 if (!IsShowing()) | 216 if (!IsShowing()) |
212 return; | 217 return; |
213 | |
214 instance_->ShowReauthDialog(browser_context, email, reason); | 218 instance_->ShowReauthDialog(browser_context, email, reason); |
215 } | 219 } |
216 | 220 |
217 // static | 221 // static |
218 void UserManager::HideReauthDialog() { | 222 void UserManager::HideReauthDialog() { |
219 // This method should only be called if the user manager is already showing. | 223 // This method should only be called if the user manager is already showing. |
220 if (!IsShowing()) | 224 if (instance_ && !instance_->GetWidget()->IsClosed()) |
221 return; | 225 instance_->HideReauthDialog(); |
222 | |
223 instance_->HideReauthDialog(); | |
224 } | 226 } |
225 | 227 |
226 // static | 228 // static |
227 void UserManager::AddOnUserManagerShownCallbackForTesting( | 229 void UserManager::AddOnUserManagerShownCallbackForTesting( |
228 const base::Closure& callback) { | 230 const base::Closure& callback) { |
229 DCHECK(!user_manager_shown_callback_for_testing_); | 231 DCHECK(!user_manager_shown_callback_for_testing_); |
230 user_manager_shown_callback_for_testing_ = new base::Closure(callback); | 232 user_manager_shown_callback_for_testing_ = new base::Closure(callback); |
231 } | 233 } |
232 | 234 |
| 235 // static |
| 236 void UserManager::ShowSigninDialog(content::BrowserContext* browser_context, |
| 237 const base::FilePath& profile_path) { |
| 238 if (!IsShowing()) |
| 239 return; |
| 240 instance_->SetSigninProfilePath(profile_path); |
| 241 ShowReauthDialog(browser_context, std::string(), |
| 242 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT); |
| 243 } |
| 244 |
| 245 // static |
| 246 void UserManager::DisplayErrorMessage() { |
| 247 // This method should only be called if the user manager is already showing. |
| 248 if (instance_) |
| 249 instance_->DisplayErrorMessage(); |
| 250 } |
| 251 |
| 252 // static |
| 253 base::FilePath UserManager::GetSigninProfilePath() { |
| 254 return instance_->GetSigninProfilePath(); |
| 255 } |
| 256 |
233 // UserManagerView ------------------------------------------------------------- | 257 // UserManagerView ------------------------------------------------------------- |
234 | 258 |
235 UserManagerView::UserManagerView() | 259 UserManagerView::UserManagerView() |
236 : web_view_(nullptr), | 260 : web_view_(nullptr), |
237 delegate_(nullptr), | 261 delegate_(nullptr), |
238 user_manager_started_showing_(base::Time()) { | 262 user_manager_started_showing_(base::Time()) { |
239 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW, | 263 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW, |
240 KeepAliveRestartOption::DISABLED)); | 264 KeepAliveRestartOption::DISABLED)); |
241 } | 265 } |
242 | 266 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // Now that the window is closed, we can allow a new one to be opened. | 425 // Now that the window is closed, we can allow a new one to be opened. |
402 // (WindowClosing comes in asynchronously from the call to Close() and we | 426 // (WindowClosing comes in asynchronously from the call to Close() and we |
403 // may have already opened a new instance). | 427 // may have already opened a new instance). |
404 if (instance_ == this) | 428 if (instance_ == this) |
405 instance_ = NULL; | 429 instance_ = NULL; |
406 } | 430 } |
407 | 431 |
408 bool UserManagerView::ShouldUseCustomFrame() const { | 432 bool UserManagerView::ShouldUseCustomFrame() const { |
409 return false; | 433 return false; |
410 } | 434 } |
| 435 |
| 436 void UserManagerView::DisplayErrorMessage() { |
| 437 if (delegate_) |
| 438 delegate_->DisplayErrorMessage(); |
| 439 } |
| 440 |
| 441 void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) { |
| 442 signin_profile_path_ = profile_path; |
| 443 } |
| 444 |
| 445 base::FilePath UserManagerView::GetSigninProfilePath() { |
| 446 return signin_profile_path_; |
| 447 } |
OLD | NEW |