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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 161 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
162 | 162 |
163 // Adds |password_forms| to the layout remembering their |type|. | 163 // Adds |password_forms| to the layout remembering their |type|. |
164 void AddCredentialItemsWithType( | 164 void AddCredentialItemsWithType( |
165 views::GridLayout* layout, | 165 views::GridLayout* layout, |
166 const ScopedVector<const autofill::PasswordForm>& password_forms, | 166 const ScopedVector<const autofill::PasswordForm>& password_forms, |
167 password_manager::CredentialType type); | 167 password_manager::CredentialType type); |
168 | 168 |
169 ManagePasswordsBubbleView* parent_; | 169 ManagePasswordsBubbleView* parent_; |
170 views::LabelButton* cancel_button_; | 170 views::LabelButton* cancel_button_; |
| 171 |
| 172 DISALLOW_COPY_AND_ASSIGN(AccountChooserView); |
171 }; | 173 }; |
172 | 174 |
173 ManagePasswordsBubbleView::AccountChooserView::AccountChooserView( | 175 ManagePasswordsBubbleView::AccountChooserView::AccountChooserView( |
174 ManagePasswordsBubbleView* parent) | 176 ManagePasswordsBubbleView* parent) |
175 : parent_(parent) { | 177 : parent_(parent) { |
176 views::GridLayout* layout = new views::GridLayout(this); | 178 views::GridLayout* layout = new views::GridLayout(this); |
177 SetLayoutManager(layout); | 179 SetLayoutManager(layout); |
178 | 180 |
179 cancel_button_ = | 181 cancel_button_ = |
180 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_CANCEL)); | 182 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_CANCEL)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 240 } |
239 parent_->Close(); | 241 parent_->Close(); |
240 } | 242 } |
241 | 243 |
242 // ManagePasswordsBubbleView::AutoSigninView ---------------------------------- | 244 // ManagePasswordsBubbleView::AutoSigninView ---------------------------------- |
243 | 245 |
244 // A view containing just one credential that was used for for automatic signing | 246 // A view containing just one credential that was used for for automatic signing |
245 // in. | 247 // in. |
246 class ManagePasswordsBubbleView::AutoSigninView | 248 class ManagePasswordsBubbleView::AutoSigninView |
247 : public views::View, | 249 : public views::View, |
248 public views::ButtonListener { | 250 public views::ButtonListener, |
| 251 public views::WidgetObserver { |
249 public: | 252 public: |
250 explicit AutoSigninView(ManagePasswordsBubbleView* parent); | 253 explicit AutoSigninView(ManagePasswordsBubbleView* parent); |
251 | 254 |
252 private: | 255 private: |
253 // views::ButtonListener: | 256 // views::ButtonListener: |
254 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 257 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
255 | 258 |
| 259 // views::WidgetObserver: |
| 260 // Tracks the state of the browser window. |
| 261 void OnWidgetActivationChanged(views::Widget* widget, bool active) override; |
| 262 void OnWidgetClosing(views::Widget* widget) override; |
| 263 |
256 void OnTimer(); | 264 void OnTimer(); |
| 265 static base::TimeDelta GetTimeout() { |
| 266 return base::TimeDelta::FromSeconds( |
| 267 ManagePasswordsBubbleView::auto_signin_toast_timeout_); |
| 268 } |
257 | 269 |
258 base::OneShotTimer<AutoSigninView> timer_; | 270 base::OneShotTimer<AutoSigninView> timer_; |
259 ManagePasswordsBubbleView* parent_; | 271 ManagePasswordsBubbleView* parent_; |
| 272 ScopedObserver<views::Widget, views::WidgetObserver> observed_browser_; |
| 273 |
| 274 DISALLOW_COPY_AND_ASSIGN(AutoSigninView); |
260 }; | 275 }; |
261 | 276 |
262 ManagePasswordsBubbleView::AutoSigninView::AutoSigninView( | 277 ManagePasswordsBubbleView::AutoSigninView::AutoSigninView( |
263 ManagePasswordsBubbleView* parent) | 278 ManagePasswordsBubbleView* parent) |
264 : parent_(parent) { | 279 : parent_(parent), |
| 280 observed_browser_(this) { |
265 SetLayoutManager(new views::FillLayout); | 281 SetLayoutManager(new views::FillLayout); |
266 CredentialsItemView* credential = new CredentialsItemView( | 282 CredentialsItemView* credential = new CredentialsItemView( |
267 this, | 283 this, |
268 &parent_->model()->pending_password(), | 284 &parent_->model()->pending_password(), |
269 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL, | 285 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL, |
270 CredentialsItemView::AUTO_SIGNIN, | 286 CredentialsItemView::AUTO_SIGNIN, |
271 parent_->model()->GetProfile()->GetRequestContext()); | 287 parent_->model()->GetProfile()->GetRequestContext()); |
272 AddChildView(credential); | 288 AddChildView(credential); |
273 parent_->set_initially_focused_view(credential); | 289 parent_->set_initially_focused_view(credential); |
274 | 290 |
275 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kAutoSigninToastTimeout), | 291 Browser* browser = |
276 this, &AutoSigninView::OnTimer); | 292 chrome::FindBrowserWithWebContents(parent_->web_contents()); |
| 293 DCHECK(browser); |
| 294 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
| 295 observed_browser_.Add(browser_view->GetWidget()); |
| 296 |
| 297 if (browser_view->IsActive()) |
| 298 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); |
277 } | 299 } |
278 | 300 |
279 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( | 301 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( |
280 views::Button* sender, const ui::Event& event) { | 302 views::Button* sender, const ui::Event& event) { |
281 parent_->model()->OnAutoSignInClicked(); | 303 parent_->model()->OnAutoSignInClicked(); |
282 parent_->Close(); | 304 parent_->Close(); |
283 } | 305 } |
284 | 306 |
| 307 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( |
| 308 views::Widget* widget, bool active) { |
| 309 if (active && !timer_.IsRunning()) |
| 310 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); |
| 311 } |
| 312 |
| 313 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetClosing( |
| 314 views::Widget* widget) { |
| 315 observed_browser_.RemoveAll(); |
| 316 } |
| 317 |
285 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { | 318 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { |
286 parent_->model()->OnAutoSignInToastTimeout(); | 319 parent_->model()->OnAutoSignInToastTimeout(); |
287 parent_->Close(); | 320 parent_->Close(); |
288 } | 321 } |
289 | 322 |
290 // ManagePasswordsBubbleView::PendingView ------------------------------------- | 323 // ManagePasswordsBubbleView::PendingView ------------------------------------- |
291 | 324 |
292 // A view offering the user the ability to save credentials. Contains a | 325 // A view offering the user the ability to save credentials. Contains a |
293 // single ManagePasswordItemsView, along with a "Save Passwords" button | 326 // single ManagePasswordItemsView, along with a "Save Passwords" button |
294 // and a rejection combobox. | 327 // and a rejection combobox. |
(...skipping 14 matching lines...) Expand all Loading... |
309 ManagePasswordsBubbleView* parent_; | 342 ManagePasswordsBubbleView* parent_; |
310 | 343 |
311 views::BlueButton* save_button_; | 344 views::BlueButton* save_button_; |
312 | 345 |
313 // The combobox doesn't take ownership of its model. If we created a | 346 // The combobox doesn't take ownership of its model. If we created a |
314 // combobox we need to ensure that we delete the model here, and because the | 347 // combobox we need to ensure that we delete the model here, and because the |
315 // combobox uses the model in it's destructor, we need to make sure we | 348 // combobox uses the model in it's destructor, we need to make sure we |
316 // delete the model _after_ the combobox itself is deleted. | 349 // delete the model _after_ the combobox itself is deleted. |
317 scoped_ptr<SavePasswordRefusalComboboxModel> combobox_model_; | 350 scoped_ptr<SavePasswordRefusalComboboxModel> combobox_model_; |
318 scoped_ptr<views::Combobox> refuse_combobox_; | 351 scoped_ptr<views::Combobox> refuse_combobox_; |
| 352 |
| 353 DISALLOW_COPY_AND_ASSIGN(PendingView); |
319 }; | 354 }; |
320 | 355 |
321 ManagePasswordsBubbleView::PendingView::PendingView( | 356 ManagePasswordsBubbleView::PendingView::PendingView( |
322 ManagePasswordsBubbleView* parent) | 357 ManagePasswordsBubbleView* parent) |
323 : parent_(parent) { | 358 : parent_(parent) { |
324 views::GridLayout* layout = new views::GridLayout(this); | 359 views::GridLayout* layout = new views::GridLayout(this); |
325 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 360 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
326 SetLayoutManager(layout); | 361 SetLayoutManager(layout); |
327 | 362 |
328 std::vector<const autofill::PasswordForm*> credentials( | 363 std::vector<const autofill::PasswordForm*> credentials( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 ~ConfirmNeverView() override; | 434 ~ConfirmNeverView() override; |
400 | 435 |
401 private: | 436 private: |
402 // views::ButtonListener: | 437 // views::ButtonListener: |
403 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 438 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
404 | 439 |
405 ManagePasswordsBubbleView* parent_; | 440 ManagePasswordsBubbleView* parent_; |
406 | 441 |
407 views::LabelButton* confirm_button_; | 442 views::LabelButton* confirm_button_; |
408 views::LabelButton* undo_button_; | 443 views::LabelButton* undo_button_; |
| 444 |
| 445 DISALLOW_COPY_AND_ASSIGN(ConfirmNeverView); |
409 }; | 446 }; |
410 | 447 |
411 ManagePasswordsBubbleView::ConfirmNeverView::ConfirmNeverView( | 448 ManagePasswordsBubbleView::ConfirmNeverView::ConfirmNeverView( |
412 ManagePasswordsBubbleView* parent) | 449 ManagePasswordsBubbleView* parent) |
413 : parent_(parent) { | 450 : parent_(parent) { |
414 views::GridLayout* layout = new views::GridLayout(this); | 451 views::GridLayout* layout = new views::GridLayout(this); |
415 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 452 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
416 SetLayoutManager(layout); | 453 SetLayoutManager(layout); |
417 | 454 |
418 // Title row. | 455 // Title row. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 // views::ButtonListener: | 524 // views::ButtonListener: |
488 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 525 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
489 | 526 |
490 // views::LinkListener: | 527 // views::LinkListener: |
491 void LinkClicked(views::Link* source, int event_flags) override; | 528 void LinkClicked(views::Link* source, int event_flags) override; |
492 | 529 |
493 ManagePasswordsBubbleView* parent_; | 530 ManagePasswordsBubbleView* parent_; |
494 | 531 |
495 views::Link* manage_link_; | 532 views::Link* manage_link_; |
496 views::LabelButton* done_button_; | 533 views::LabelButton* done_button_; |
| 534 |
| 535 DISALLOW_COPY_AND_ASSIGN(ManageView); |
497 }; | 536 }; |
498 | 537 |
499 ManagePasswordsBubbleView::ManageView::ManageView( | 538 ManagePasswordsBubbleView::ManageView::ManageView( |
500 ManagePasswordsBubbleView* parent) | 539 ManagePasswordsBubbleView* parent) |
501 : parent_(parent) { | 540 : parent_(parent) { |
502 views::GridLayout* layout = new views::GridLayout(this); | 541 views::GridLayout* layout = new views::GridLayout(this); |
503 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 542 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
504 SetLayoutManager(layout); | 543 SetLayoutManager(layout); |
505 | 544 |
506 // Add the title. | 545 // Add the title. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 // views::ButtonListener: | 627 // views::ButtonListener: |
589 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 628 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
590 | 629 |
591 // views::LinkListener: | 630 // views::LinkListener: |
592 void LinkClicked(views::Link* source, int event_flags) override; | 631 void LinkClicked(views::Link* source, int event_flags) override; |
593 | 632 |
594 ManagePasswordsBubbleView* parent_; | 633 ManagePasswordsBubbleView* parent_; |
595 | 634 |
596 views::Link* manage_link_; | 635 views::Link* manage_link_; |
597 views::LabelButton* done_button_; | 636 views::LabelButton* done_button_; |
| 637 |
| 638 DISALLOW_COPY_AND_ASSIGN(ManageAccountsView); |
598 }; | 639 }; |
599 | 640 |
600 ManagePasswordsBubbleView::ManageAccountsView::ManageAccountsView( | 641 ManagePasswordsBubbleView::ManageAccountsView::ManageAccountsView( |
601 ManagePasswordsBubbleView* parent) | 642 ManagePasswordsBubbleView* parent) |
602 : parent_(parent) { | 643 : parent_(parent) { |
603 views::GridLayout* layout = new views::GridLayout(this); | 644 views::GridLayout* layout = new views::GridLayout(this); |
604 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 645 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
605 SetLayoutManager(layout); | 646 SetLayoutManager(layout); |
606 | 647 |
607 // Add the title. | 648 // Add the title. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 ~BlacklistedView() override; | 720 ~BlacklistedView() override; |
680 | 721 |
681 private: | 722 private: |
682 // views::ButtonListener: | 723 // views::ButtonListener: |
683 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 724 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
684 | 725 |
685 ManagePasswordsBubbleView* parent_; | 726 ManagePasswordsBubbleView* parent_; |
686 | 727 |
687 views::BlueButton* unblacklist_button_; | 728 views::BlueButton* unblacklist_button_; |
688 views::LabelButton* done_button_; | 729 views::LabelButton* done_button_; |
| 730 |
| 731 DISALLOW_COPY_AND_ASSIGN(BlacklistedView); |
689 }; | 732 }; |
690 | 733 |
691 ManagePasswordsBubbleView::BlacklistedView::BlacklistedView( | 734 ManagePasswordsBubbleView::BlacklistedView::BlacklistedView( |
692 ManagePasswordsBubbleView* parent) | 735 ManagePasswordsBubbleView* parent) |
693 : parent_(parent) { | 736 : parent_(parent) { |
694 views::GridLayout* layout = new views::GridLayout(this); | 737 views::GridLayout* layout = new views::GridLayout(this); |
695 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 738 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
696 SetLayoutManager(layout); | 739 SetLayoutManager(layout); |
697 | 740 |
698 // Add the title. | 741 // Add the title. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 | 806 |
764 private: | 807 private: |
765 // views::ButtonListener: | 808 // views::ButtonListener: |
766 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 809 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
767 | 810 |
768 // views::StyledLabelListener implementation | 811 // views::StyledLabelListener implementation |
769 void StyledLabelLinkClicked(const gfx::Range& range, | 812 void StyledLabelLinkClicked(const gfx::Range& range, |
770 int event_flags) override; | 813 int event_flags) override; |
771 | 814 |
772 ManagePasswordsBubbleView* parent_; | 815 ManagePasswordsBubbleView* parent_; |
| 816 views::LabelButton* ok_button_; |
773 | 817 |
774 views::LabelButton* ok_button_; | 818 DISALLOW_COPY_AND_ASSIGN(SaveConfirmationView); |
775 }; | 819 }; |
776 | 820 |
777 ManagePasswordsBubbleView::SaveConfirmationView::SaveConfirmationView( | 821 ManagePasswordsBubbleView::SaveConfirmationView::SaveConfirmationView( |
778 ManagePasswordsBubbleView* parent) | 822 ManagePasswordsBubbleView* parent) |
779 : parent_(parent) { | 823 : parent_(parent) { |
780 views::GridLayout* layout = new views::GridLayout(this); | 824 views::GridLayout* layout = new views::GridLayout(this); |
781 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 825 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
782 SetLayoutManager(layout); | 826 SetLayoutManager(layout); |
783 | 827 |
784 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | 828 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 | 1060 |
1017 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { | 1061 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { |
1018 if (model()->local_credentials().empty()) { | 1062 if (model()->local_credentials().empty()) { |
1019 // Skip confirmation if there are no existing passwords for this site. | 1063 // Skip confirmation if there are no existing passwords for this site. |
1020 NotifyConfirmedNeverForThisSite(); | 1064 NotifyConfirmedNeverForThisSite(); |
1021 } else { | 1065 } else { |
1022 model()->OnConfirmationForNeverForThisSite(); | 1066 model()->OnConfirmationForNeverForThisSite(); |
1023 Refresh(); | 1067 Refresh(); |
1024 } | 1068 } |
1025 } | 1069 } |
OLD | NEW |