| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 345 |
| 346 parent_->set_initially_focused_view(save_button_); | 346 parent_->set_initially_focused_view(save_button_); |
| 347 } | 347 } |
| 348 | 348 |
| 349 ManagePasswordsBubbleView::PendingView::~PendingView() { | 349 ManagePasswordsBubbleView::PendingView::~PendingView() { |
| 350 } | 350 } |
| 351 | 351 |
| 352 void ManagePasswordsBubbleView::PendingView::ButtonPressed( | 352 void ManagePasswordsBubbleView::PendingView::ButtonPressed( |
| 353 views::Button* sender, | 353 views::Button* sender, |
| 354 const ui::Event& event) { | 354 const ui::Event& event) { |
| 355 if (sender == save_button_) | 355 if (sender == save_button_) { |
| 356 parent_->model()->OnSaveClicked(); | 356 parent_->model()->OnSaveClicked(); |
| 357 else if (sender == never_button_) | 357 if (parent_->model()->ReplaceToShowSignInPromoIfNeeded()) { |
| 358 parent_->Refresh(); |
| 359 return; |
| 360 } |
| 361 } else if (sender == never_button_) { |
| 358 parent_->model()->OnNeverForThisSiteClicked(); | 362 parent_->model()->OnNeverForThisSiteClicked(); |
| 359 else | 363 } else { |
| 360 NOTREACHED(); | 364 NOTREACHED(); |
| 365 } |
| 361 | 366 |
| 362 parent_->CloseBubble(); | 367 parent_->CloseBubble(); |
| 363 } | 368 } |
| 364 | 369 |
| 365 void ManagePasswordsBubbleView::PendingView::StyledLabelLinkClicked( | 370 void ManagePasswordsBubbleView::PendingView::StyledLabelLinkClicked( |
| 366 views::StyledLabel* label, | 371 views::StyledLabel* label, |
| 367 const gfx::Range& range, | 372 const gfx::Range& range, |
| 368 int event_flags) { | 373 int event_flags) { |
| 369 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); | 374 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); |
| 370 parent_->model()->OnBrandLinkClicked(); | 375 parent_->model()->OnBrandLinkClicked(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 parent_->CloseBubble(); | 546 parent_->CloseBubble(); |
| 542 } | 547 } |
| 543 | 548 |
| 544 void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed( | 549 void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed( |
| 545 views::Button* sender, const ui::Event& event) { | 550 views::Button* sender, const ui::Event& event) { |
| 546 DCHECK_EQ(sender, ok_button_); | 551 DCHECK_EQ(sender, ok_button_); |
| 547 parent_->model()->OnOKClicked(); | 552 parent_->model()->OnOKClicked(); |
| 548 parent_->CloseBubble(); | 553 parent_->CloseBubble(); |
| 549 } | 554 } |
| 550 | 555 |
| 556 // ManagePasswordsBubbleView::SignInPromoView --------------------------------- |
| 557 |
| 558 // A view that offers user to sign in to Chrome. |
| 559 class ManagePasswordsBubbleView::SignInPromoView |
| 560 : public views::View, |
| 561 public views::ButtonListener { |
| 562 public: |
| 563 explicit SignInPromoView(ManagePasswordsBubbleView* parent); |
| 564 |
| 565 private: |
| 566 // views::ButtonListener: |
| 567 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 568 |
| 569 ManagePasswordsBubbleView* parent_; |
| 570 |
| 571 views::Button* signin_button_; |
| 572 views::Button* no_button_; |
| 573 |
| 574 DISALLOW_COPY_AND_ASSIGN(SignInPromoView); |
| 575 }; |
| 576 |
| 577 ManagePasswordsBubbleView::SignInPromoView::SignInPromoView( |
| 578 ManagePasswordsBubbleView* parent) |
| 579 : parent_(parent) { |
| 580 views::GridLayout* layout = new views::GridLayout(this); |
| 581 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
| 582 SetLayoutManager(layout); |
| 583 |
| 584 signin_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( |
| 585 this, |
| 586 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SIGNIN_PROMO_SIGN_IN)); |
| 587 no_button_ = views::MdTextButton::CreateSecondaryUiButton( |
| 588 this, |
| 589 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SIGNIN_PROMO_NO_THANKS)); |
| 590 |
| 591 // Button row. |
| 592 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); |
| 593 layout->StartRow(0, DOUBLE_BUTTON_COLUMN_SET); |
| 594 layout->AddView(signin_button_); |
| 595 layout->AddView(no_button_); |
| 596 |
| 597 parent_->set_initially_focused_view(signin_button_); |
| 598 } |
| 599 |
| 600 void ManagePasswordsBubbleView::SignInPromoView::ButtonPressed( |
| 601 views::Button* sender, |
| 602 const ui::Event& event) { |
| 603 if (sender == signin_button_) |
| 604 parent_->model()->OnSignInToChromeClicked(); |
| 605 else if (sender == no_button_) |
| 606 parent_->model()->OnSkipSignInClicked(); |
| 607 else |
| 608 NOTREACHED(); |
| 609 |
| 610 parent_->CloseBubble(); |
| 611 } |
| 612 |
| 551 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- | 613 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- |
| 552 | 614 |
| 553 // The class listens for WebContentsView events and notifies the bubble if the | 615 // The class listens for WebContentsView events and notifies the bubble if the |
| 554 // view was clicked on or received keystrokes. | 616 // view was clicked on or received keystrokes. |
| 555 class ManagePasswordsBubbleView::WebContentMouseHandler | 617 class ManagePasswordsBubbleView::WebContentMouseHandler |
| 556 : public ui::EventHandler { | 618 : public ui::EventHandler { |
| 557 public: | 619 public: |
| 558 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); | 620 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); |
| 559 | 621 |
| 560 void OnKeyEvent(ui::KeyEvent* event) override; | 622 void OnKeyEvent(ui::KeyEvent* event) override; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 838 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
| 777 if (manage_passwords_bubble_ == this) | 839 if (manage_passwords_bubble_ == this) |
| 778 manage_passwords_bubble_ = NULL; | 840 manage_passwords_bubble_ = NULL; |
| 779 } | 841 } |
| 780 | 842 |
| 781 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 843 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
| 782 return initially_focused_view_; | 844 return initially_focused_view_; |
| 783 } | 845 } |
| 784 | 846 |
| 785 void ManagePasswordsBubbleView::Init() { | 847 void ManagePasswordsBubbleView::Init() { |
| 786 views::FillLayout* layout = new views::FillLayout(); | 848 SetLayoutManager(new views::FillLayout); |
| 787 SetLayoutManager(layout); | |
| 788 | 849 |
| 789 Refresh(); | 850 CreateChild(); |
| 790 } | 851 } |
| 791 | 852 |
| 792 void ManagePasswordsBubbleView::CloseBubble() { | 853 void ManagePasswordsBubbleView::CloseBubble() { |
| 793 mouse_handler_.reset(); | 854 mouse_handler_.reset(); |
| 794 LocationBarBubbleDelegateView::CloseBubble(); | 855 LocationBarBubbleDelegateView::CloseBubble(); |
| 795 } | 856 } |
| 796 | 857 |
| 797 base::string16 ManagePasswordsBubbleView::GetWindowTitle() const { | 858 base::string16 ManagePasswordsBubbleView::GetWindowTitle() const { |
| 798 return model_.title(); | 859 return model_.title(); |
| 799 } | 860 } |
| 800 | 861 |
| 801 bool ManagePasswordsBubbleView::ShouldShowWindowTitle() const { | 862 bool ManagePasswordsBubbleView::ShouldShowWindowTitle() const { |
| 802 // Since bubble titles don't support links, fall back to a custom title view | 863 // Since bubble titles don't support links, fall back to a custom title view |
| 803 // if we need to show a link. Only use the normal title path if there's no | 864 // if we need to show a link. Only use the normal title path if there's no |
| 804 // link. | 865 // link. |
| 805 return model_.title_brand_link_range().is_empty(); | 866 return model_.title_brand_link_range().is_empty(); |
| 806 } | 867 } |
| 807 | 868 |
| 808 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const { | 869 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const { |
| 809 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE; | 870 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE; |
| 810 } | 871 } |
| 811 | 872 |
| 812 void ManagePasswordsBubbleView::Refresh() { | 873 void ManagePasswordsBubbleView::Refresh() { |
| 813 RemoveAllChildViews(true); | 874 RemoveAllChildViews(true); |
| 814 initially_focused_view_ = NULL; | 875 initially_focused_view_ = NULL; |
| 876 CreateChild(); |
| 877 |
| 878 // Show/hide the close button. |
| 879 GetWidget()->non_client_view()->ResetWindowControls(); |
| 880 GetWidget()->UpdateWindowTitle(); |
| 881 SizeToContents(); |
| 882 } |
| 883 |
| 884 void ManagePasswordsBubbleView::CreateChild() { |
| 815 if (model_.state() == password_manager::ui::PENDING_PASSWORD_STATE) { | 885 if (model_.state() == password_manager::ui::PENDING_PASSWORD_STATE) { |
| 816 AddChildView(new PendingView(this)); | 886 AddChildView(new PendingView(this)); |
| 817 } else if (model_.state() == | 887 } else if (model_.state() == |
| 818 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { | 888 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { |
| 819 AddChildView(new UpdatePendingView(this)); | 889 AddChildView(new UpdatePendingView(this)); |
| 820 } else if (model_.state() == password_manager::ui::CONFIRMATION_STATE) { | 890 } else if (model_.state() == password_manager::ui::CONFIRMATION_STATE) { |
| 821 AddChildView(new SaveConfirmationView(this)); | 891 AddChildView(new SaveConfirmationView(this)); |
| 822 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) { | 892 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 823 AddChildView(new AutoSigninView(this)); | 893 AddChildView(new AutoSigninView(this)); |
| 894 } else if (model_.state() == |
| 895 password_manager::ui::CHROME_SIGN_IN_PROMO_STATE) { |
| 896 AddChildView(new SignInPromoView(this)); |
| 824 } else { | 897 } else { |
| 825 AddChildView(new ManageView(this)); | 898 AddChildView(new ManageView(this)); |
| 826 } | 899 } |
| 827 if (GetWidget()) | |
| 828 GetWidget()->UpdateWindowTitle(); | |
| 829 GetLayoutManager()->Layout(this); | |
| 830 } | 900 } |
| OLD | NEW |