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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 #endif | 50 #endif |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 // 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 |
55 // is reset to NULL when the window is closed. | 55 // is reset to NULL when the window is closed. |
56 UserManagerView* instance_ = NULL; | 56 UserManagerView* instance_ = NULL; |
57 bool instance_under_construction_ = false; | 57 bool instance_under_construction_ = false; |
58 | 58 |
59 class ReauthDelegate : public views::DialogDelegateView, | 59 class ReauthDelegate : public views::DialogDelegateView, |
60 public content::WebContentsObserver { | 60 public UserManager::ReauthDialogObserver { |
61 public: | 61 public: |
62 ReauthDelegate(content::BrowserContext* browser_context, | 62 ReauthDelegate(views::WebView* web_view, |
63 const std::string& email_address); | 63 const std::string& email_address); |
64 ~ReauthDelegate() override {} | 64 ~ReauthDelegate() override {} |
65 | 65 |
66 private: | 66 private: |
| 67 ReauthDelegate(); |
67 // views::DialogDelegate: | 68 // views::DialogDelegate: |
68 gfx::Size GetPreferredSize() const override; | 69 gfx::Size GetPreferredSize() const override; |
69 bool CanResize() const override; | 70 bool CanResize() const override; |
70 bool CanMaximize() const override; | 71 bool CanMaximize() const override; |
71 bool CanMinimize() const override; | 72 bool CanMinimize() const override; |
72 bool UseNewStyleForThisDialog() const override; | 73 bool UseNewStyleForThisDialog() const override; |
73 ui::ModalType GetModalType() const override; | 74 ui::ModalType GetModalType() const override; |
74 void DeleteDelegate() override; | 75 void DeleteDelegate() override; |
75 base::string16 GetWindowTitle() const override; | 76 base::string16 GetWindowTitle() const override; |
76 int GetDialogButtons() const override; | 77 int GetDialogButtons() const override; |
77 | 78 |
78 // content::WebContentsObserver: | 79 // UserManager::ReauthObserver: |
79 void DidStopLoading() override; | 80 void CloseReauthDialog() override; |
80 | 81 |
81 content::BrowserContext* browser_context_; | |
82 views::WebView* web_view_; | 82 views::WebView* web_view_; |
83 const std::string email_address_; | 83 const std::string email_address_; |
84 | 84 |
85 DISALLOW_COPY_AND_ASSIGN(ReauthDelegate); | 85 DISALLOW_COPY_AND_ASSIGN(ReauthDelegate); |
86 }; | 86 }; |
87 | 87 |
88 ReauthDelegate::ReauthDelegate(content::BrowserContext* browser_context, | 88 ReauthDelegate::ReauthDelegate(views::WebView* web_view, |
89 const std::string& email_address) | 89 const std::string& email_address) |
90 : browser_context_(browser_context), | 90 : UserManager::ReauthDialogObserver( |
| 91 web_view->GetWebContents(), email_address), |
| 92 web_view_(web_view), |
91 email_address_(email_address) { | 93 email_address_(email_address) { |
92 web_view_ = new views::WebView(browser_context_); | |
93 AddChildView(web_view_); | 94 AddChildView(web_view_); |
94 SetLayoutManager(new views::FillLayout()); | 95 SetLayoutManager(new views::FillLayout()); |
95 | 96 |
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. | 97 // 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 | 98 // 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. | 99 // knows which profile to load and update the credentials. |
103 GURL url = signin::GetReauthURLWithEmail(email_address_); | 100 GURL url = signin::GetReauthURLWithEmail(email_address_); |
104 web_view_->LoadInitialURL(url); | 101 web_view_->LoadInitialURL(url); |
105 } | 102 } |
106 | 103 |
107 gfx::Size ReauthDelegate::GetPreferredSize() const { | 104 gfx::Size ReauthDelegate::GetPreferredSize() const { |
108 return gfx::Size(UserManager::kReauthDialogWidth, | 105 return gfx::Size(UserManager::kReauthDialogWidth, |
109 UserManager::kReauthDialogHeight); | 106 UserManager::kReauthDialogHeight); |
(...skipping 24 matching lines...) Expand all Loading... |
134 } | 131 } |
135 | 132 |
136 base::string16 ReauthDelegate::GetWindowTitle() const { | 133 base::string16 ReauthDelegate::GetWindowTitle() const { |
137 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE); | 134 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE); |
138 } | 135 } |
139 | 136 |
140 int ReauthDelegate::GetDialogButtons() const { | 137 int ReauthDelegate::GetDialogButtons() const { |
141 return ui::DIALOG_BUTTON_NONE; | 138 return ui::DIALOG_BUTTON_NONE; |
142 } | 139 } |
143 | 140 |
144 bool AddToSet(std::set<content::WebContents*>* content_set, | 141 void ReauthDelegate::CloseReauthDialog() { |
145 content::WebContents* web_contents) { | 142 GetWidget()->Close(); |
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 } | 143 } |
183 | 144 |
184 } // namespace | 145 } // namespace |
185 | 146 |
186 // UserManager ----------------------------------------------------------------- | 147 // UserManager ----------------------------------------------------------------- |
187 | 148 |
188 // static | 149 // static |
189 void UserManager::Show( | 150 void UserManager::Show( |
190 const base::FilePath& profile_path_to_focus, | 151 const base::FilePath& profile_path_to_focus, |
191 profiles::UserManagerTutorialMode tutorial_mode, | 152 profiles::UserManagerTutorialMode tutorial_mode, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 instance_->LogTimeToOpen(); | 205 instance_->LogTimeToOpen(); |
245 } | 206 } |
246 | 207 |
247 // static | 208 // static |
248 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, | 209 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, |
249 const std::string& email) { | 210 const std::string& email) { |
250 // This method should only be called if the user manager is already showing. | 211 // This method should only be called if the user manager is already showing. |
251 if (!IsShowing()) | 212 if (!IsShowing()) |
252 return; | 213 return; |
253 | 214 |
254 // The dialog delegate will be deleted when the dialog closes. | 215 // The dialog delegate will be deleted when the dialog closes and the created |
| 216 // WebView's lifetime is managed by the delegate. |
255 views::DialogDelegate* delegate = | 217 views::DialogDelegate* delegate = |
256 new ReauthDelegate(browser_context, email); | 218 new ReauthDelegate(new views::WebView(browser_context), email); |
257 gfx::NativeView parent = instance_->GetWidget()->GetNativeView(); | 219 gfx::NativeView parent = instance_->GetWidget()->GetNativeView(); |
258 views::DialogDelegate::CreateDialogWidget(delegate, nullptr, parent); | 220 views::DialogDelegate::CreateDialogWidget(delegate, nullptr, parent); |
259 delegate->GetWidget()->Show(); | 221 delegate->GetWidget()->Show(); |
260 } | 222 } |
261 | 223 |
262 // UserManagerView ------------------------------------------------------------- | 224 // UserManagerView ------------------------------------------------------------- |
263 | 225 |
264 UserManagerView::UserManagerView() | 226 UserManagerView::UserManagerView() |
265 : web_view_(NULL), | 227 : web_view_(NULL), |
266 keep_alive_(new AutoKeepAlive(NULL)), | 228 keep_alive_(new AutoKeepAlive(NULL)), |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // Now that the window is closed, we can allow a new one to be opened. | 367 // Now that the window is closed, we can allow a new one to be opened. |
406 // (WindowClosing comes in asynchronously from the call to Close() and we | 368 // (WindowClosing comes in asynchronously from the call to Close() and we |
407 // may have already opened a new instance). | 369 // may have already opened a new instance). |
408 if (instance_ == this) | 370 if (instance_ == this) |
409 instance_ = NULL; | 371 instance_ = NULL; |
410 } | 372 } |
411 | 373 |
412 bool UserManagerView::UseNewStyleForThisDialog() const { | 374 bool UserManagerView::UseNewStyleForThisDialog() const { |
413 return false; | 375 return false; |
414 } | 376 } |
OLD | NEW |