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

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: Use DialogDelegateView 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::DialogDelegateView,
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 // views::DialogDelegate:
68 gfx::Size GetPreferredSize() const override;
69 bool CanResize() const override;
70 bool CanMaximize() const override;
71 bool CanMinimize() const override;
72 bool UseNewStyleForThisDialog() const override;
73 ui::ModalType GetModalType() const override;
74 void DeleteDelegate() override;
75 base::string16 GetWindowTitle() const override;
76 int GetDialogButtons() const override;
77
78 // content::WebContentsObserver:
79 void DidStopLoading() override;
80
81 content::BrowserContext* browser_context_;
82 views::WebView* web_view_;
83 const std::string email_address_;
84
85 DISALLOW_COPY_AND_ASSIGN(ReauthDelegate);
86 };
87
88 ReauthDelegate::ReauthDelegate(content::BrowserContext* browser_context,
89 const std::string& email_address)
90 : browser_context_(browser_context),
91 email_address_(email_address) {
92 web_view_ = new views::WebView(browser_context_);
93 AddChildView(web_view_);
94 SetLayoutManager(new views::FillLayout());
95
96 // Observe navigations of the web contents so that the dialog can close itself
97 // when the sign in process is done.
98 Observe(web_view_->GetWebContents());
99
100 // Load the re-auth URL, prepopulated with the user's email address.
101 // Add the index of the profile to the URL so that the inline login page
102 // knows which profile to load and update the credentials.
103 GURL url = signin::GetReauthURLWithEmail(email_address_);
104 web_view_->LoadInitialURL(url);
105 }
106
107 gfx::Size ReauthDelegate::GetPreferredSize() const {
108 return gfx::Size(UserManager::kReauthDialogWidth,
109 UserManager::kReauthDialogHeight);
110 }
111
112 bool ReauthDelegate::CanResize() const {
113 return true;
114 }
115
116 bool ReauthDelegate::CanMaximize() const {
117 return true;
118 }
119
120 bool ReauthDelegate::CanMinimize() const {
121 return true;
122 }
123
124 bool ReauthDelegate::UseNewStyleForThisDialog() const {
125 return false;
126 }
127
128 ui::ModalType ReauthDelegate::GetModalType() const {
129 return ui::MODAL_TYPE_WINDOW;
130 }
131
132 void ReauthDelegate::DeleteDelegate() {
133 delete this;
134 }
135
136 base::string16 ReauthDelegate::GetWindowTitle() const {
137 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE);
138 }
139
140 int ReauthDelegate::GetDialogButtons() const {
141 return ui::DIALOG_BUTTON_NONE;
142 }
143
144 bool AddToSet(std::set<content::WebContents*>* content_set,
145 content::WebContents* web_contents) {
146 content_set->insert(web_contents);
147 return false;
148 }
149
150 void ReauthDelegate::DidStopLoading() {
151 // If the sign in process reaches the termination URL, close the dialog.
152 // Make sure to remove any parts of the URL that gaia might append during
153 // signin.
154 GURL url = web_contents()->GetURL();
155 url::Replacements<char> replacements;
156 replacements.ClearQuery();
157 replacements.ClearRef();
158 if (url.ReplaceComponents(replacements) ==
159 GaiaUrls::GetInstance()->signin_completed_continue_url()) {
160 GetWidget()->Close();
161 return;
162 }
163
164 // If still observing the top level web contents, try to find the embedded
165 // webview and observe it instead. The webview may not be found in the
166 // initial page load since it loads asynchronously.
167 if (url.GetOrigin() !=
168 signin::GetReauthURLWithEmail(email_address_).GetOrigin()) {
169 return;
170 }
171
172 std::set<content::WebContents*> content_set;
173 content::WebContents* web_contents = web_view_->GetWebContents();
174 guest_view::GuestViewManager* manager =
175 guest_view::GuestViewManager::FromBrowserContext(
176 web_contents->GetBrowserContext());
177 if (manager)
178 manager->ForEachGuest(web_contents, base::Bind(&AddToSet, &content_set));
179 DCHECK_LE(content_set.size(), 1U);
180 if (!content_set.empty())
181 Observe(*content_set.begin());
182 }
183
51 } // namespace 184 } // namespace
52 185
53 // UserManager ----------------------------------------------------------------- 186 // UserManager -----------------------------------------------------------------
54 187
188 // static
55 void UserManager::Show( 189 void UserManager::Show(
56 const base::FilePath& profile_path_to_focus, 190 const base::FilePath& profile_path_to_focus,
57 profiles::UserManagerTutorialMode tutorial_mode, 191 profiles::UserManagerTutorialMode tutorial_mode,
58 profiles::UserManagerProfileSelected profile_open_action) { 192 profiles::UserManagerProfileSelected profile_open_action) {
59 DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath()); 193 DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath());
60 194
61 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER); 195 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER);
62 if (instance_) { 196 if (instance_) {
63 // If we are showing the User Manager after locking a profile, change the 197 // If we are showing the User Manager after locking a profile, change the
64 // active profile to Guest. 198 // active profile to Guest.
(...skipping 21 matching lines...) Expand all
86 profiles::CreateSystemProfileForUserManager( 220 profiles::CreateSystemProfileForUserManager(
87 profile_path_to_focus, 221 profile_path_to_focus,
88 tutorial_mode, 222 tutorial_mode,
89 profile_open_action, 223 profile_open_action,
90 base::Bind(&UserManagerView::OnSystemProfileCreated, 224 base::Bind(&UserManagerView::OnSystemProfileCreated,
91 base::Passed(make_scoped_ptr(user_manager)), 225 base::Passed(make_scoped_ptr(user_manager)),
92 base::Owned(new base::AutoReset<bool>( 226 base::Owned(new base::AutoReset<bool>(
93 &instance_under_construction_, true)))); 227 &instance_under_construction_, true))));
94 } 228 }
95 229
230 // static
96 void UserManager::Hide() { 231 void UserManager::Hide() {
97 if (instance_) 232 if (instance_)
98 instance_->GetWidget()->Close(); 233 instance_->GetWidget()->Close();
99 } 234 }
100 235
236 // static
101 bool UserManager::IsShowing() { 237 bool UserManager::IsShowing() {
102 return instance_ ? instance_->GetWidget()->IsActive() : false; 238 return instance_ ? instance_->GetWidget()->IsActive() : false;
103 } 239 }
104 240
241 // static
105 void UserManager::OnUserManagerShown() { 242 void UserManager::OnUserManagerShown() {
106 if (instance_) 243 if (instance_)
107 instance_->LogTimeToOpen(); 244 instance_->LogTimeToOpen();
108 } 245 }
109 246
247 // static
248 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context,
249 const std::string& email) {
250 // This method should only be called if the user manager is already showing.
251 if (!IsShowing())
252 return;
253
254 // The dialog delegate will be deleted when the dialog closes.
255 views::DialogDelegate* delegate =
256 new ReauthDelegate(browser_context, email);
257 gfx::NativeView parent = instance_->GetWidget()->GetNativeView();
258 views::DialogDelegate::CreateDialogWidget(delegate, nullptr, parent);
259 delegate->GetWidget()->Show();
260 }
261
110 // UserManagerView ------------------------------------------------------------- 262 // UserManagerView -------------------------------------------------------------
111 263
112 UserManagerView::UserManagerView() 264 UserManagerView::UserManagerView()
113 : web_view_(NULL), 265 : web_view_(NULL),
114 keep_alive_(new AutoKeepAlive(NULL)), 266 keep_alive_(new AutoKeepAlive(NULL)),
115 user_manager_started_showing_(base::Time()) { 267 user_manager_started_showing_(base::Time()) {
116 } 268 }
117 269
118 UserManagerView::~UserManagerView() { 270 UserManagerView::~UserManagerView() {
119 } 271 }
(...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. 405 // 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 406 // (WindowClosing comes in asynchronously from the call to Close() and we
255 // may have already opened a new instance). 407 // may have already opened a new instance).
256 if (instance_ == this) 408 if (instance_ == this)
257 instance_ = NULL; 409 instance_ = NULL;
258 } 410 }
259 411
260 bool UserManagerView::UseNewStyleForThisDialog() const { 412 bool UserManagerView::UseNewStyleForThisDialog() const {
261 return false; 413 return false;
262 } 414 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/user_manager.h ('k') | chrome/browser/ui/webui/signin/inline_login_handler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698