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

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

Issue 1220843003: Perform online reauth when password is changed for a locked profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: polish Created 5 years, 5 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/time/time.h" 7 #include "base/time/time.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/lifetime/application_lifetime.h" 9 #include "chrome/browser/lifetime/application_lifetime.h"
10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/profiles/profile_metrics.h" 12 #include "chrome/browser/profiles/profile_metrics.h"
13 #include "chrome/browser/profiles/profile_window.h" 13 #include "chrome/browser/profiles/profile_window.h"
14 #include "chrome/browser/profiles/profiles_state.h" 14 #include "chrome/browser/profiles/profiles_state.h"
15 #include "chrome/browser/signin/signin_promo.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_dialogs.h" 17 #include "chrome/browser/ui/browser_dialogs.h"
17 #include "chrome/browser/ui/browser_finder.h" 18 #include "chrome/browser/ui/browser_finder.h"
18 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/user_manager.h" 20 #include "chrome/browser/ui/user_manager.h"
20 #include "chrome/browser/ui/views/auto_keep_alive.h" 21 #include "chrome/browser/ui/views/auto_keep_alive.h"
22 #include "chrome/browser/ui/views/browser_dialogs.h"
21 #include "chrome/grit/chromium_strings.h" 23 #include "chrome/grit/chromium_strings.h"
24 #include "chrome/grit/generated_resources.h"
25 #include "components/guest_view/browser/guest_view_manager.h"
26 #include "content/public/browser/navigation_details.h"
22 #include "content/public/browser/render_widget_host_view.h" 27 #include "content/public/browser/render_widget_host_view.h"
23 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "google_apis/gaia/gaia_urls.h"
24 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gfx/screen.h" 31 #include "ui/gfx/screen.h"
26 #include "ui/views/controls/webview/webview.h" 32 #include "ui/views/controls/webview/webview.h"
27 #include "ui/views/layout/fill_layout.h" 33 #include "ui/views/layout/fill_layout.h"
28 #include "ui/views/view.h" 34 #include "ui/views/view.h"
29 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
30 #include "ui/views/window/dialog_client_view.h" 36 #include "ui/views/window/dialog_client_view.h"
37 #include "ui/views/window/dialog_delegate.h"
31 38
32 #if defined(OS_WIN) 39 #if defined(OS_WIN)
33 #include "chrome/browser/shell_integration.h" 40 #include "chrome/browser/shell_integration.h"
34 #include "ui/base/win/shell.h" 41 #include "ui/base/win/shell.h"
35 #include "ui/views/win/hwnd_util.h" 42 #include "ui/views/win/hwnd_util.h"
36 #endif 43 #endif
37 44
38 #if defined(USE_ASH) 45 #if defined(USE_ASH)
39 #include "ash/shelf/shelf_util.h" 46 #include "ash/shelf/shelf_util.h"
40 #include "ash/wm/window_util.h" 47 #include "ash/wm/window_util.h"
41 #include "grit/ash_resources.h" 48 #include "grit/ash_resources.h"
42 #endif 49 #endif
43 50
44 namespace { 51 namespace {
45 52
46 // An open User Manager window. There can only be one open at a time. This 53 // An open User Manager window. There can only be one open at a time. This
47 // is reset to NULL when the window is closed. 54 // is reset to NULL when the window is closed.
48 UserManagerView* instance_ = NULL; 55 UserManagerView* instance_ = NULL;
49 bool instance_under_construction_ = false; 56 bool instance_under_construction_ = false;
50 57
58 class ReauthDelegate : public views::DialogDelegate,
59 public content::WebContentsObserver {
60 public:
61 ReauthDelegate(content::BrowserContext* browser_context,
62 const std::string& email_address,
63 size_t profile_index);
64 ~ReauthDelegate() override {}
65
66 private:
67 // Overridden from views::DialogDelegate:
68 bool CanResize() const override;
69 bool CanMaximize() const override;
70 bool CanMinimize() const override;
71 bool UseNewStyleForThisDialog() const override;
72 ui::ModalType GetModalType() const override;
73 void DeleteDelegate() override;
74 views::Widget* GetWidget() override;
75 const views::Widget* GetWidget() const override;
76 views::View* GetContentsView() override;
77 base::string16 GetWindowTitle() const override;
78 int GetDialogButtons() const override;
79
80 // Overridden from content::WebContentsObserver:
81 void DidStopLoading() override;
82
83 content::BrowserContext* browser_context_;
84 views::WebView* web_view_;
85 std::string email_address_;
86 size_t profile_index_;
87 };
88
89 ReauthDelegate::ReauthDelegate(content::BrowserContext* browser_context,
90 const std::string& email_address,
91 size_t profile_index)
92 : browser_context_(browser_context),
93 web_view_(nullptr),
94 email_address_(email_address),
95 profile_index_(profile_index) {}
96
97 bool ReauthDelegate::CanResize() const {
98 return true;
99 }
100
101 bool ReauthDelegate::CanMaximize() const {
102 return true;
103 }
104
105 bool ReauthDelegate::CanMinimize() const {
106 return true;
107 }
108
109 bool ReauthDelegate::UseNewStyleForThisDialog() const {
110 return false;
111 }
112
113 ui::ModalType ReauthDelegate::GetModalType() const {
114 return ui::MODAL_TYPE_WINDOW;
115 }
116
117 views::Widget* ReauthDelegate::GetWidget() {
118 return web_view_->GetWidget();
119 }
120
121 void ReauthDelegate::DeleteDelegate() {
122 delete web_view_;
123 delete this;
124 }
125
126 const views::Widget* ReauthDelegate::GetWidget() const {
127 return web_view_->GetWidget();
128 }
129
130 views::View* ReauthDelegate::GetContentsView() {
131 DCHECK(!web_view_);
132 web_view_ = new views::WebView(browser_context_);
133 web_view_->set_owned_by_client();
134
135 // Observe navigations of the web contents so that the dialog can close itself
136 // when the sign in process is done.
137 Observe(web_view_->GetWebContents());
138
139 // Load the re-auth URL, prepopulated with the user's email address.
140 // Add the index of the profile to the URL so that the inline login page
141 // knows which profile to load and update the credentials.
142 GURL url = signin::GetReauthURL(profile_index_, email_address_);
143 web_view_->LoadInitialURL(url);
144 web_view_->SetPreferredSize(gfx::Size(360, 440));
145 return web_view_;
146 }
147
148 base::string16 ReauthDelegate::GetWindowTitle() const {
149 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE);
150 }
151
152 int ReauthDelegate::GetDialogButtons() const {
153 return ui::DIALOG_BUTTON_NONE;
154 }
155
156 bool AddToSet(std::set<content::WebContents*>* content_set,
157 content::WebContents* web_contents) {
158 content_set->insert(web_contents);
159 return false;
160 }
161
162 void ReauthDelegate::DidStopLoading() {
163 // If the sign in process reaches the termination URL, close the dialog.
164 // Make sure to remove any parts of the URL that gaia might append during
165 // signin.
166 GURL url = web_contents()->GetURL();
167 url::Replacements<char> replacements;
168 replacements.ClearQuery();
169 replacements.ClearRef();
170 if (url.ReplaceComponents(replacements) ==
171 GaiaUrls::GetInstance()->signin_completed_continue_url()) {
172 GetWidget()->Close();
173 return;
174 }
175
176 // If still observing the top level web contents, try to find the embedded
177 // webview and observe it instead. The webview may not be found in the
bcwhite 2015/07/21 13:28:39 What URL will the embedded view have if not the Re
Roger Tawa OOO till Jul 10th 2015/07/22 00:12:33 ReauthDelegate first observes the WebContents of t
178 // initial page load since it loads asynchronously.
179 if (url.GetOrigin() !=
180 signin::GetReauthURL(profile_index_, email_address_).GetOrigin()) {
181 return;
182 }
183
184 std::set<content::WebContents*> content_set;
185 content::WebContents* web_contents = web_view_->GetWebContents();
186 guest_view::GuestViewManager* manager =
187 guest_view::GuestViewManager::FromBrowserContext(
188 web_view_->GetWebContents()->GetBrowserContext());
189 if (manager)
190 manager->ForEachGuest(web_contents, base::Bind(&AddToSet, &content_set));
191 if (content_set.size() > 0)
bcwhite 2015/07/21 13:28:39 DCHECK(content_set.size() <= 1)?
Roger Tawa OOO till Jul 10th 2015/07/22 00:12:32 The style guide says not to DCHECK if the code han
bcwhite 2015/07/22 13:42:21 Different conditions. The DCHECK was to validate
Roger Tawa OOO till Jul 10th 2015/07/22 15:29:54 Done.
192 Observe(*content_set.begin());
193 }
194
51 } // namespace 195 } // namespace
52 196
53 // UserManager ----------------------------------------------------------------- 197 // UserManager -----------------------------------------------------------------
54 198
199 // static
55 void UserManager::Show( 200 void UserManager::Show(
56 const base::FilePath& profile_path_to_focus, 201 const base::FilePath& profile_path_to_focus,
57 profiles::UserManagerTutorialMode tutorial_mode, 202 profiles::UserManagerTutorialMode tutorial_mode,
58 profiles::UserManagerProfileSelected profile_open_action) { 203 profiles::UserManagerProfileSelected profile_open_action) {
59 DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath()); 204 DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath());
60 205
61 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER); 206 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER);
62 if (instance_) { 207 if (instance_) {
63 // If we are showing the User Manager after locking a profile, change the 208 // If we are showing the User Manager after locking a profile, change the
64 // active profile to Guest. 209 // active profile to Guest.
(...skipping 21 matching lines...) Expand all
86 profiles::CreateSystemProfileForUserManager( 231 profiles::CreateSystemProfileForUserManager(
87 profile_path_to_focus, 232 profile_path_to_focus,
88 tutorial_mode, 233 tutorial_mode,
89 profile_open_action, 234 profile_open_action,
90 base::Bind(&UserManagerView::OnSystemProfileCreated, 235 base::Bind(&UserManagerView::OnSystemProfileCreated,
91 base::Passed(make_scoped_ptr(user_manager)), 236 base::Passed(make_scoped_ptr(user_manager)),
92 base::Owned(new base::AutoReset<bool>( 237 base::Owned(new base::AutoReset<bool>(
93 &instance_under_construction_, true)))); 238 &instance_under_construction_, true))));
94 } 239 }
95 240
241 // static
96 void UserManager::Hide() { 242 void UserManager::Hide() {
97 if (instance_) 243 if (instance_)
98 instance_->GetWidget()->Close(); 244 instance_->GetWidget()->Close();
99 } 245 }
100 246
247 // static
101 bool UserManager::IsShowing() { 248 bool UserManager::IsShowing() {
102 return instance_ ? instance_->GetWidget()->IsActive() : false; 249 return instance_ ? instance_->GetWidget()->IsActive() : false;
103 } 250 }
104 251
252 // static
105 void UserManager::OnUserManagerShown() { 253 void UserManager::OnUserManagerShown() {
106 if (instance_) 254 if (instance_)
107 instance_->LogTimeToOpen(); 255 instance_->LogTimeToOpen();
108 } 256 }
109 257
258 // static
259 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context,
260 const std::string& email,
261 size_t profile_index) {
262 // This method should only be called if the user manager is already showing.
263 if (!IsShowing())
264 return;
265
266 views::DialogDelegate* delegate =
267 new ReauthDelegate(browser_context, email, profile_index);
268 gfx::NativeView parent = instance_->GetWidget()->GetNativeView();
269 views::DialogDelegate::CreateDialogWidget(delegate, NULL, parent);
270 delegate->GetWidget()->Show();
271 }
272
110 // UserManagerView ------------------------------------------------------------- 273 // UserManagerView -------------------------------------------------------------
111 274
112 UserManagerView::UserManagerView() 275 UserManagerView::UserManagerView()
113 : web_view_(NULL), 276 : web_view_(NULL),
114 keep_alive_(new AutoKeepAlive(NULL)), 277 keep_alive_(new AutoKeepAlive(NULL)),
115 user_manager_started_showing_(base::Time()) { 278 user_manager_started_showing_(base::Time()) {
116 } 279 }
117 280
118 UserManagerView::~UserManagerView() { 281 UserManagerView::~UserManagerView() {
119 } 282 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // Now that the window is closed, we can allow a new one to be opened. 416 // Now that the window is closed, we can allow a new one to be opened.
254 // (WindowClosing comes in asynchronously from the call to Close() and we 417 // (WindowClosing comes in asynchronously from the call to Close() and we
255 // may have already opened a new instance). 418 // may have already opened a new instance).
256 if (instance_ == this) 419 if (instance_ == this)
257 instance_ = NULL; 420 instance_ = NULL;
258 } 421 }
259 422
260 bool UserManagerView::UseNewStyleForThisDialog() const { 423 bool UserManagerView::UseNewStyleForThisDialog() const {
261 return false; 424 return false;
262 } 425 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698