Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/ui/views/profiles/user_manager_view.cc

Issue 2351173004: Display local signin error without browser and record the path of selected profile in user manager. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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())
sky 2016/09/20 23:30:19 Can you motivate why this change is needed?
zmin 2016/09/21 00:09:35 IsShowing will check the activate of User Manager
sky 2016/09/21 23:00:02 I think you are arguing for checking IsVisible(),
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 instance_->SetSigninProfilePath(profile_path);
sky 2016/09/20 23:30:19 How do you know instance_ is non-null at the time
zmin 2016/09/21 00:09:35 Good catch, I shall add a check here.
zmin 2016/09/21 16:40:04 Done.
239 ShowReauthDialog(browser_context, std::string(),
sky 2016/09/20 23:30:19 As someone not intimitely familiar with this code
zmin 2016/09/21 00:09:35 User manager only has ShowReauthDialog before beca
zmin 2016/09/21 02:56:08 I think it's more clear for the API or it will bec
240 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT);
241 }
242
243 // static
244 void UserManager::DisplayErrorMessage() {
245 // This method should only be called if the user manager is already showing.
246 if (instance_)
247 instance_->DisplayErrorMessage();
248 }
249
250 // static
251 base::FilePath UserManager::GetSigninProfilePath() {
252 return instance_->GetSigninProfilePath();
253 }
254
233 // UserManagerView ------------------------------------------------------------- 255 // UserManagerView -------------------------------------------------------------
234 256
235 UserManagerView::UserManagerView() 257 UserManagerView::UserManagerView()
236 : web_view_(nullptr), 258 : web_view_(nullptr),
237 delegate_(nullptr), 259 delegate_(nullptr),
238 user_manager_started_showing_(base::Time()) { 260 user_manager_started_showing_(base::Time()),
261 signin_profile_path_(base::FilePath()) {
sky 2016/09/20 23:30:19 This is the default, so you don't need it.
zmin 2016/09/21 16:40:04 Done.
239 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW, 262 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW,
240 KeepAliveRestartOption::DISABLED)); 263 KeepAliveRestartOption::DISABLED));
241 } 264 }
242 265
243 UserManagerView::~UserManagerView() { 266 UserManagerView::~UserManagerView() {
244 HideReauthDialog(); 267 HideReauthDialog();
245 } 268 }
246 269
247 // static 270 // static
248 void UserManagerView::OnSystemProfileCreated( 271 void UserManagerView::OnSystemProfileCreated(
(...skipping 25 matching lines...) Expand all
274 delegate_->GetWidget()->Show(); 297 delegate_->GetWidget()->Show();
275 } 298 }
276 299
277 void UserManagerView::HideReauthDialog() { 300 void UserManagerView::HideReauthDialog() {
278 if (delegate_) { 301 if (delegate_) {
279 delegate_->CloseReauthDialog(); 302 delegate_->CloseReauthDialog();
280 DCHECK(!delegate_); 303 DCHECK(!delegate_);
281 } 304 }
282 } 305 }
283 306
307 void UserManagerView::DisplayErrorMessage() {
sky 2016/09/20 23:30:19 Style guide says declaration and definition order
zmin 2016/09/21 16:40:04 Done.
308 if (delegate_) {
sky 2016/09/20 23:30:19 no {}
zmin 2016/09/21 16:40:04 Done.
309 delegate_->DisplayErrorMessage();
310 }
311 }
312
284 void UserManagerView::OnReauthDialogDestroyed() { 313 void UserManagerView::OnReauthDialogDestroyed() {
285 delegate_ = nullptr; 314 delegate_ = nullptr;
286 } 315 }
287 316
288 void UserManagerView::Init(Profile* system_profile, const GURL& url) { 317 void UserManagerView::Init(Profile* system_profile, const GURL& url) {
289 web_view_ = new views::WebView(system_profile); 318 web_view_ = new views::WebView(system_profile);
290 web_view_->set_allow_accelerators(true); 319 web_view_->set_allow_accelerators(true);
291 AddChildView(web_view_); 320 AddChildView(web_view_);
292 SetLayoutManager(new views::FillLayout); 321 SetLayoutManager(new views::FillLayout);
293 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN)); 322 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // Now that the window is closed, we can allow a new one to be opened. 430 // 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 431 // (WindowClosing comes in asynchronously from the call to Close() and we
403 // may have already opened a new instance). 432 // may have already opened a new instance).
404 if (instance_ == this) 433 if (instance_ == this)
405 instance_ = NULL; 434 instance_ = NULL;
406 } 435 }
407 436
408 bool UserManagerView::ShouldUseCustomFrame() const { 437 bool UserManagerView::ShouldUseCustomFrame() const {
409 return false; 438 return false;
410 } 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698