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

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

Powered by Google App Engine
This is Rietveld 408576698