Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/passwords/manage_passwords_bubble_view.h" | 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/timer/timer.h" | 7 #include "base/timer/timer.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "ui/views/controls/link_listener.h" | 29 #include "ui/views/controls/link_listener.h" |
| 30 #include "ui/views/controls/separator.h" | 30 #include "ui/views/controls/separator.h" |
| 31 #include "ui/views/controls/styled_label.h" | 31 #include "ui/views/controls/styled_label.h" |
| 32 #include "ui/views/controls/styled_label_listener.h" | 32 #include "ui/views/controls/styled_label_listener.h" |
| 33 #include "ui/views/event_monitor.h" | 33 #include "ui/views/event_monitor.h" |
| 34 #include "ui/views/layout/fill_layout.h" | 34 #include "ui/views/layout/fill_layout.h" |
| 35 #include "ui/views/layout/grid_layout.h" | 35 #include "ui/views/layout/grid_layout.h" |
| 36 #include "ui/views/layout/layout_constants.h" | 36 #include "ui/views/layout/layout_constants.h" |
| 37 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
| 38 | 38 |
| 39 int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; | |
| 39 | 40 |
| 40 // Helpers -------------------------------------------------------------------- | 41 // Helpers -------------------------------------------------------------------- |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 const int kAutoSigninToastTimeout = 3; | |
| 45 const int kDesiredBubbleWidth = 370; | 45 const int kDesiredBubbleWidth = 370; |
| 46 | 46 |
| 47 enum ColumnSetType { | 47 enum ColumnSetType { |
| 48 // | | (FILL, FILL) | | | 48 // | | (FILL, FILL) | | |
| 49 // Used for the bubble's header, the credentials list, and for simple | 49 // Used for the bubble's header, the credentials list, and for simple |
| 50 // messages like "No passwords". | 50 // messages like "No passwords". |
| 51 SINGLE_VIEW_COLUMN_SET = 0, | 51 SINGLE_VIEW_COLUMN_SET = 0, |
| 52 | 52 |
| 53 // | | (TRAILING, CENTER) | | (TRAILING, CENTER) | | | 53 // | | (TRAILING, CENTER) | | (TRAILING, CENTER) | | |
| 54 // Used for buttons at the bottom of the bubble which should nest at the | 54 // Used for buttons at the bottom of the bubble which should nest at the |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 } | 238 } |
| 239 parent_->Close(); | 239 parent_->Close(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 // ManagePasswordsBubbleView::AutoSigninView ---------------------------------- | 242 // ManagePasswordsBubbleView::AutoSigninView ---------------------------------- |
| 243 | 243 |
| 244 // A view containing just one credential that was used for for automatic signing | 244 // A view containing just one credential that was used for for automatic signing |
| 245 // in. | 245 // in. |
| 246 class ManagePasswordsBubbleView::AutoSigninView | 246 class ManagePasswordsBubbleView::AutoSigninView |
| 247 : public views::View, | 247 : public views::View, |
| 248 public views::ButtonListener { | 248 public views::ButtonListener, |
| 249 public views::WidgetObserver { | |
| 249 public: | 250 public: |
| 250 explicit AutoSigninView(ManagePasswordsBubbleView* parent); | 251 explicit AutoSigninView(ManagePasswordsBubbleView* parent); |
| 251 | 252 |
| 252 private: | 253 private: |
| 253 // views::ButtonListener: | 254 // views::ButtonListener: |
| 254 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 255 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 255 | 256 |
| 257 // views::WidgetObserver: | |
| 258 // Tracks the state of the browser window. | |
| 259 void OnWidgetActivationChanged(views::Widget* widget, bool active) override; | |
| 260 void OnWidgetClosing(views::Widget* widget) override; | |
| 261 | |
| 256 void OnTimer(); | 262 void OnTimer(); |
| 263 static base::TimeDelta GetTimeout() { | |
| 264 return base::TimeDelta::FromSeconds( | |
| 265 ManagePasswordsBubbleView::auto_signin_toast_timeout_); | |
| 266 } | |
| 257 | 267 |
| 258 base::OneShotTimer<AutoSigninView> timer_; | 268 base::OneShotTimer<AutoSigninView> timer_; |
| 259 ManagePasswordsBubbleView* parent_; | 269 ManagePasswordsBubbleView* parent_; |
| 270 ScopedObserver<views::Widget, views::WidgetObserver> observed_browser_; | |
| 260 }; | 271 }; |
|
sky
2015/03/20 19:52:26
niT: DISALLOW...
vasilii
2015/03/23 09:27:51
Done.
| |
| 261 | 272 |
| 262 ManagePasswordsBubbleView::AutoSigninView::AutoSigninView( | 273 ManagePasswordsBubbleView::AutoSigninView::AutoSigninView( |
| 263 ManagePasswordsBubbleView* parent) | 274 ManagePasswordsBubbleView* parent) |
| 264 : parent_(parent) { | 275 : parent_(parent), |
| 276 observed_browser_(this) { | |
| 265 SetLayoutManager(new views::FillLayout); | 277 SetLayoutManager(new views::FillLayout); |
| 266 CredentialsItemView* credential = new CredentialsItemView( | 278 CredentialsItemView* credential = new CredentialsItemView( |
| 267 this, | 279 this, |
| 268 &parent_->model()->pending_password(), | 280 &parent_->model()->pending_password(), |
| 269 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL, | 281 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL, |
| 270 CredentialsItemView::AUTO_SIGNIN, | 282 CredentialsItemView::AUTO_SIGNIN, |
| 271 parent_->model()->GetProfile()->GetRequestContext()); | 283 parent_->model()->GetProfile()->GetRequestContext()); |
| 272 AddChildView(credential); | 284 AddChildView(credential); |
| 273 parent_->set_initially_focused_view(credential); | 285 parent_->set_initially_focused_view(credential); |
| 274 | 286 |
| 275 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kAutoSigninToastTimeout), | 287 Browser* browser = |
|
sky
2015/03/20 19:52:26
Because this is all async is it possible browser i
vasilii
2015/03/23 09:27:51
I don't think so. If it happens then everything cr
| |
| 276 this, &AutoSigninView::OnTimer); | 288 chrome::FindBrowserWithWebContents(parent_->web_contents()); |
| 289 DCHECK(browser); | |
| 290 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | |
| 291 observed_browser_.Add(browser_view->GetWidget()); | |
| 292 | |
| 293 if (browser_view->IsActive()) | |
| 294 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); | |
| 277 } | 295 } |
| 278 | 296 |
| 279 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( | 297 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( |
| 280 views::Button* sender, const ui::Event& event) { | 298 views::Button* sender, const ui::Event& event) { |
| 281 parent_->model()->OnAutoSignInClicked(); | 299 parent_->model()->OnAutoSignInClicked(); |
| 282 parent_->Close(); | 300 parent_->Close(); |
| 283 } | 301 } |
| 284 | 302 |
| 303 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( | |
| 304 views::Widget* widget, bool active) { | |
| 305 if (active) | |
|
sky
2015/03/20 19:52:26
if (active && !timer_.IsRunning()) ?
vasilii
2015/03/23 09:27:51
Done.
| |
| 306 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); | |
| 307 } | |
| 308 | |
| 309 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetClosing( | |
| 310 views::Widget* widget) { | |
| 311 observed_browser_.RemoveAll(); | |
| 312 } | |
| 313 | |
| 285 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { | 314 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { |
| 286 parent_->model()->OnAutoSignInToastTimeout(); | 315 parent_->model()->OnAutoSignInToastTimeout(); |
| 287 parent_->Close(); | 316 parent_->Close(); |
| 288 } | 317 } |
| 289 | 318 |
| 290 // ManagePasswordsBubbleView::PendingView ------------------------------------- | 319 // ManagePasswordsBubbleView::PendingView ------------------------------------- |
| 291 | 320 |
| 292 // A view offering the user the ability to save credentials. Contains a | 321 // A view offering the user the ability to save credentials. Contains a |
| 293 // single ManagePasswordItemsView, along with a "Save Passwords" button | 322 // single ManagePasswordItemsView, along with a "Save Passwords" button |
| 294 // and a rejection combobox. | 323 // and a rejection combobox. |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 | 1045 |
| 1017 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { | 1046 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { |
| 1018 if (model()->local_credentials().empty()) { | 1047 if (model()->local_credentials().empty()) { |
| 1019 // Skip confirmation if there are no existing passwords for this site. | 1048 // Skip confirmation if there are no existing passwords for this site. |
| 1020 NotifyConfirmedNeverForThisSite(); | 1049 NotifyConfirmedNeverForThisSite(); |
| 1021 } else { | 1050 } else { |
| 1022 model()->OnConfirmationForNeverForThisSite(); | 1051 model()->OnConfirmationForNeverForThisSite(); |
| 1023 Refresh(); | 1052 Refresh(); |
| 1024 } | 1053 } |
| 1025 } | 1054 } |
| OLD | NEW |