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/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_; | |
sky
2015/07/23 16:56:04
nit: const on this and profile_index_.
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Done.
| |
86 size_t profile_index_; | |
87 }; | |
sky
2015/07/23 16:56:04
nit: DISALLOW_...
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Done.
| |
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_; | |
sky
2015/07/23 16:56:04
Is there a reason you're deleting web_view_ here a
Alexei Svitkine (slow)
2015/07/23 21:49:33
Also, why not use a scoped_ptr?
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Yup, that's what I did.
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Made it into a scoped_ptr<> so don't need to delet
| |
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::GetReauthURLWithEmail(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; | |
sky
2015/07/23 16:56:04
This part seems generic and not specific to views.
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Which part exactly? The call at line 172 is views
| |
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 | |
178 // initial page load since it loads asynchronously. | |
179 if (url.GetOrigin() != | |
180 signin::GetReauthURLWithEmail(profile_index_, email_address_) | |
181 .GetOrigin()) { | |
182 return; | |
183 } | |
184 | |
185 std::set<content::WebContents*> content_set; | |
sky
2015/07/23 16:56:04
This part doesn't seem specific to views either.
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Possibly, yes. When the mac portion of this chang
| |
186 content::WebContents* web_contents = web_view_->GetWebContents(); | |
187 guest_view::GuestViewManager* manager = | |
188 guest_view::GuestViewManager::FromBrowserContext( | |
189 web_view_->GetWebContents()->GetBrowserContext()); | |
Alexei Svitkine (slow)
2015/07/23 21:49:33
Nit: You have a pointer to web_contents on line 18
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Done.
| |
190 if (manager) | |
191 manager->ForEachGuest(web_contents, base::Bind(&AddToSet, &content_set)); | |
192 DCHECK_LE(content_set.size(), 1U); | |
193 if (content_set.size() > 0) | |
sky
2015/07/23 16:56:04
!empty
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Done.
| |
194 Observe(*content_set.begin()); | |
195 } | |
196 | |
51 } // namespace | 197 } // namespace |
52 | 198 |
53 // UserManager ----------------------------------------------------------------- | 199 // UserManager ----------------------------------------------------------------- |
54 | 200 |
201 // static | |
55 void UserManager::Show( | 202 void UserManager::Show( |
56 const base::FilePath& profile_path_to_focus, | 203 const base::FilePath& profile_path_to_focus, |
57 profiles::UserManagerTutorialMode tutorial_mode, | 204 profiles::UserManagerTutorialMode tutorial_mode, |
58 profiles::UserManagerProfileSelected profile_open_action) { | 205 profiles::UserManagerProfileSelected profile_open_action) { |
59 DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath()); | 206 DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath()); |
60 | 207 |
61 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER); | 208 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER); |
62 if (instance_) { | 209 if (instance_) { |
63 // If we are showing the User Manager after locking a profile, change the | 210 // If we are showing the User Manager after locking a profile, change the |
64 // active profile to Guest. | 211 // active profile to Guest. |
(...skipping 21 matching lines...) Expand all Loading... | |
86 profiles::CreateSystemProfileForUserManager( | 233 profiles::CreateSystemProfileForUserManager( |
87 profile_path_to_focus, | 234 profile_path_to_focus, |
88 tutorial_mode, | 235 tutorial_mode, |
89 profile_open_action, | 236 profile_open_action, |
90 base::Bind(&UserManagerView::OnSystemProfileCreated, | 237 base::Bind(&UserManagerView::OnSystemProfileCreated, |
91 base::Passed(make_scoped_ptr(user_manager)), | 238 base::Passed(make_scoped_ptr(user_manager)), |
92 base::Owned(new base::AutoReset<bool>( | 239 base::Owned(new base::AutoReset<bool>( |
93 &instance_under_construction_, true)))); | 240 &instance_under_construction_, true)))); |
94 } | 241 } |
95 | 242 |
243 // static | |
96 void UserManager::Hide() { | 244 void UserManager::Hide() { |
97 if (instance_) | 245 if (instance_) |
98 instance_->GetWidget()->Close(); | 246 instance_->GetWidget()->Close(); |
99 } | 247 } |
100 | 248 |
249 // static | |
101 bool UserManager::IsShowing() { | 250 bool UserManager::IsShowing() { |
102 return instance_ ? instance_->GetWidget()->IsActive() : false; | 251 return instance_ ? instance_->GetWidget()->IsActive() : false; |
103 } | 252 } |
104 | 253 |
254 // static | |
105 void UserManager::OnUserManagerShown() { | 255 void UserManager::OnUserManagerShown() { |
106 if (instance_) | 256 if (instance_) |
107 instance_->LogTimeToOpen(); | 257 instance_->LogTimeToOpen(); |
108 } | 258 } |
109 | 259 |
260 // static | |
261 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, | |
262 const std::string& email, | |
263 size_t profile_index) { | |
264 // This method should only be called if the user manager is already showing. | |
265 if (!IsShowing()) | |
266 return; | |
267 | |
268 views::DialogDelegate* delegate = | |
269 new ReauthDelegate(browser_context, email, profile_index); | |
Alexei Svitkine (slow)
2015/07/23 21:49:33
What's the ownership of this? Worth putting a comm
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Done.
| |
270 gfx::NativeView parent = instance_->GetWidget()->GetNativeView(); | |
271 views::DialogDelegate::CreateDialogWidget(delegate, NULL, parent); | |
sky
2015/07/23 16:56:04
nullptr
Roger Tawa OOO till Jul 10th
2015/07/24 16:15:12
Done.
| |
272 delegate->GetWidget()->Show(); | |
273 } | |
274 | |
110 // UserManagerView ------------------------------------------------------------- | 275 // UserManagerView ------------------------------------------------------------- |
111 | 276 |
112 UserManagerView::UserManagerView() | 277 UserManagerView::UserManagerView() |
113 : web_view_(NULL), | 278 : web_view_(NULL), |
114 keep_alive_(new AutoKeepAlive(NULL)), | 279 keep_alive_(new AutoKeepAlive(NULL)), |
115 user_manager_started_showing_(base::Time()) { | 280 user_manager_started_showing_(base::Time()) { |
116 } | 281 } |
117 | 282 |
118 UserManagerView::~UserManagerView() { | 283 UserManagerView::~UserManagerView() { |
119 } | 284 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 // Now that the window is closed, we can allow a new one to be opened. | 418 // 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 | 419 // (WindowClosing comes in asynchronously from the call to Close() and we |
255 // may have already opened a new instance). | 420 // may have already opened a new instance). |
256 if (instance_ == this) | 421 if (instance_ == this) |
257 instance_ = NULL; | 422 instance_ = NULL; |
258 } | 423 } |
259 | 424 |
260 bool UserManagerView::UseNewStyleForThisDialog() const { | 425 bool UserManagerView::UseNewStyleForThisDialog() const { |
261 return false; | 426 return false; |
262 } | 427 } |
OLD | NEW |