| 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 profiles::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 // profiles::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 : profiles::ReauthDialogObserver(web_view->GetWebContents(), email_address), |
| 91 web_view_(web_view), |
| 91 email_address_(email_address) { | 92 email_address_(email_address) { |
| 92 web_view_ = new views::WebView(browser_context_); | |
| 93 AddChildView(web_view_); | 93 AddChildView(web_view_); |
| 94 SetLayoutManager(new views::FillLayout()); | 94 SetLayoutManager(new views::FillLayout()); |
| 95 | 95 |
| 96 // Observe navigations of the web contents so that the dialog can close itself | 96 // Observe navigations of the web contents so that the dialog can close itself |
| 97 // when the sign in process is done. | 97 // when the sign in process is done. |
| 98 Observe(web_view_->GetWebContents()); | 98 Observe(web_view_->GetWebContents()); |
| 99 | 99 |
| 100 // Load the re-auth URL, prepopulated with the user's email address. | 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 | 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. | 102 // knows which profile to load and update the credentials. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 | 135 |
| 136 base::string16 ReauthDelegate::GetWindowTitle() const { | 136 base::string16 ReauthDelegate::GetWindowTitle() const { |
| 137 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE); | 137 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE); |
| 138 } | 138 } |
| 139 | 139 |
| 140 int ReauthDelegate::GetDialogButtons() const { | 140 int ReauthDelegate::GetDialogButtons() const { |
| 141 return ui::DIALOG_BUTTON_NONE; | 141 return ui::DIALOG_BUTTON_NONE; |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool AddToSet(std::set<content::WebContents*>* content_set, | 144 void ReauthDelegate::CloseReauthDialog() { |
| 145 content::WebContents* web_contents) { | 145 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 } | 146 } |
| 183 | 147 |
| 184 } // namespace | 148 } // namespace |
| 185 | 149 |
| 186 // UserManager ----------------------------------------------------------------- | 150 // UserManager ----------------------------------------------------------------- |
| 187 | 151 |
| 188 // static | 152 // static |
| 189 void UserManager::Show( | 153 void UserManager::Show( |
| 190 const base::FilePath& profile_path_to_focus, | 154 const base::FilePath& profile_path_to_focus, |
| 191 profiles::UserManagerTutorialMode tutorial_mode, | 155 profiles::UserManagerTutorialMode tutorial_mode, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 instance_->LogTimeToOpen(); | 208 instance_->LogTimeToOpen(); |
| 245 } | 209 } |
| 246 | 210 |
| 247 // static | 211 // static |
| 248 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, | 212 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, |
| 249 const std::string& email) { | 213 const std::string& email) { |
| 250 // This method should only be called if the user manager is already showing. | 214 // This method should only be called if the user manager is already showing. |
| 251 if (!IsShowing()) | 215 if (!IsShowing()) |
| 252 return; | 216 return; |
| 253 | 217 |
| 254 // The dialog delegate will be deleted when the dialog closes. | 218 // The dialog delegate will be deleted when the dialog closes and the created |
| 219 // WebView's lifetime is managed by the delegate. |
| 255 views::DialogDelegate* delegate = | 220 views::DialogDelegate* delegate = |
| 256 new ReauthDelegate(browser_context, email); | 221 new ReauthDelegate(new views::WebView(browser_context), email); |
| 257 gfx::NativeView parent = instance_->GetWidget()->GetNativeView(); | 222 gfx::NativeView parent = instance_->GetWidget()->GetNativeView(); |
| 258 views::DialogDelegate::CreateDialogWidget(delegate, nullptr, parent); | 223 views::DialogDelegate::CreateDialogWidget(delegate, nullptr, parent); |
| 259 delegate->GetWidget()->Show(); | 224 delegate->GetWidget()->Show(); |
| 260 } | 225 } |
| 261 | 226 |
| 262 // UserManagerView ------------------------------------------------------------- | 227 // UserManagerView ------------------------------------------------------------- |
| 263 | 228 |
| 264 UserManagerView::UserManagerView() | 229 UserManagerView::UserManagerView() |
| 265 : web_view_(NULL), | 230 : web_view_(NULL), |
| 266 keep_alive_(new AutoKeepAlive(NULL)), | 231 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. | 370 // 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 | 371 // (WindowClosing comes in asynchronously from the call to Close() and we |
| 407 // may have already opened a new instance). | 372 // may have already opened a new instance). |
| 408 if (instance_ == this) | 373 if (instance_ == this) |
| 409 instance_ = NULL; | 374 instance_ = NULL; |
| 410 } | 375 } |
| 411 | 376 |
| 412 bool UserManagerView::UseNewStyleForThisDialog() const { | 377 bool UserManagerView::UseNewStyleForThisDialog() const { |
| 413 return false; | 378 return false; |
| 414 } | 379 } |
| OLD | NEW |