| 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" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 13 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 14 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 15 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 15 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
| 16 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" | 16 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" |
| 17 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" | 17 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" |
| 18 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" | 18 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" |
| 19 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "content/public/browser/render_view_host.h" | |
| 21 #include "grit/components_strings.h" | 20 #include "grit/components_strings.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/material_design/material_design_controller.h" | 22 #include "ui/base/material_design/material_design_controller.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/views/controls/button/blue_button.h" | 24 #include "ui/views/controls/button/blue_button.h" |
| 26 #include "ui/views/controls/button/md_text_button.h" | 25 #include "ui/views/controls/button/md_text_button.h" |
| 27 #include "ui/views/controls/link.h" | 26 #include "ui/views/controls/link.h" |
| 28 #include "ui/views/controls/link_listener.h" | 27 #include "ui/views/controls/link_listener.h" |
| 29 #include "ui/views/controls/separator.h" | 28 #include "ui/views/controls/separator.h" |
| 30 #include "ui/views/controls/styled_label.h" | 29 #include "ui/views/controls/styled_label.h" |
| 31 #include "ui/views/controls/styled_label_listener.h" | 30 #include "ui/views/controls/styled_label_listener.h" |
| 32 #include "ui/views/event_monitor.h" | |
| 33 #include "ui/views/layout/fill_layout.h" | 31 #include "ui/views/layout/fill_layout.h" |
| 34 #include "ui/views/layout/grid_layout.h" | 32 #include "ui/views/layout/grid_layout.h" |
| 35 #include "ui/views/layout/layout_constants.h" | 33 #include "ui/views/layout/layout_constants.h" |
| 36 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
| 37 | 35 |
| 38 int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; | 36 int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; |
| 39 | 37 |
| 40 // Helpers -------------------------------------------------------------------- | 38 // Helpers -------------------------------------------------------------------- |
| 41 | 39 |
| 42 namespace { | 40 namespace { |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 if (sender == signin_button_) | 601 if (sender == signin_button_) |
| 604 parent_->model()->OnSignInToChromeClicked(); | 602 parent_->model()->OnSignInToChromeClicked(); |
| 605 else if (sender == no_button_) | 603 else if (sender == no_button_) |
| 606 parent_->model()->OnSkipSignInClicked(); | 604 parent_->model()->OnSkipSignInClicked(); |
| 607 else | 605 else |
| 608 NOTREACHED(); | 606 NOTREACHED(); |
| 609 | 607 |
| 610 parent_->CloseBubble(); | 608 parent_->CloseBubble(); |
| 611 } | 609 } |
| 612 | 610 |
| 613 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- | |
| 614 | |
| 615 // The class listens for WebContentsView events and notifies the bubble if the | |
| 616 // view was clicked on or received keystrokes. | |
| 617 class ManagePasswordsBubbleView::WebContentMouseHandler | |
| 618 : public ui::EventHandler { | |
| 619 public: | |
| 620 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); | |
| 621 | |
| 622 void OnKeyEvent(ui::KeyEvent* event) override; | |
| 623 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 624 void OnTouchEvent(ui::TouchEvent* event) override; | |
| 625 | |
| 626 private: | |
| 627 ManagePasswordsBubbleView* bubble_; | |
| 628 std::unique_ptr<views::EventMonitor> event_monitor_; | |
| 629 | |
| 630 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler); | |
| 631 }; | |
| 632 | |
| 633 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler( | |
| 634 ManagePasswordsBubbleView* bubble) | |
| 635 : bubble_(bubble) { | |
| 636 content::WebContents* web_contents = bubble_->web_contents(); | |
| 637 DCHECK(web_contents); | |
| 638 event_monitor_ = views::EventMonitor::CreateWindowMonitor( | |
| 639 this, web_contents->GetTopLevelNativeWindow()); | |
| 640 } | |
| 641 | |
| 642 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent( | |
| 643 ui::KeyEvent* event) { | |
| 644 content::WebContents* web_contents = bubble_->web_contents(); | |
| 645 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); | |
| 646 if ((event->key_code() == ui::VKEY_ESCAPE || | |
| 647 rvh->IsFocusedElementEditable()) && event->type() == ui::ET_KEY_PRESSED) | |
| 648 bubble_->CloseBubble(); | |
| 649 } | |
| 650 | |
| 651 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent( | |
| 652 ui::MouseEvent* event) { | |
| 653 if (event->type() == ui::ET_MOUSE_PRESSED) | |
| 654 bubble_->CloseBubble(); | |
| 655 } | |
| 656 | |
| 657 void ManagePasswordsBubbleView::WebContentMouseHandler::OnTouchEvent( | |
| 658 ui::TouchEvent* event) { | |
| 659 if (event->type() == ui::ET_TOUCH_PRESSED) | |
| 660 bubble_->CloseBubble(); | |
| 661 } | |
| 662 | |
| 663 // ManagePasswordsBubbleView::UpdatePendingView ------------------------------- | 611 // ManagePasswordsBubbleView::UpdatePendingView ------------------------------- |
| 664 | 612 |
| 665 // A view offering the user the ability to update credentials. Contains a | 613 // A view offering the user the ability to update credentials. Contains a |
| 666 // single ManagePasswordItemsView (in case of one credentials) or | 614 // single ManagePasswordItemsView (in case of one credentials) or |
| 667 // CredentialsSelectionView otherwise, along with a "Update Passwords" button | 615 // CredentialsSelectionView otherwise, along with a "Update Passwords" button |
| 668 // and a rejection button. | 616 // and a rejection button. |
| 669 class ManagePasswordsBubbleView::UpdatePendingView | 617 class ManagePasswordsBubbleView::UpdatePendingView |
| 670 : public views::View, | 618 : public views::View, |
| 671 public views::ButtonListener, | 619 public views::ButtonListener, |
| 672 public views::StyledLabelListener { | 620 public views::StyledLabelListener { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 773 |
| 826 ManagePasswordsBubbleView::ManagePasswordsBubbleView( | 774 ManagePasswordsBubbleView::ManagePasswordsBubbleView( |
| 827 content::WebContents* web_contents, | 775 content::WebContents* web_contents, |
| 828 views::View* anchor_view, | 776 views::View* anchor_view, |
| 829 DisplayReason reason) | 777 DisplayReason reason) |
| 830 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 778 : LocationBarBubbleDelegateView(anchor_view, web_contents), |
| 831 model_(web_contents, | 779 model_(web_contents, |
| 832 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC | 780 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC |
| 833 : ManagePasswordsBubbleModel::USER_ACTION), | 781 : ManagePasswordsBubbleModel::USER_ACTION), |
| 834 initially_focused_view_(nullptr) { | 782 initially_focused_view_(nullptr) { |
| 835 mouse_handler_.reset(new WebContentMouseHandler(this)); | 783 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); |
| 836 } | 784 } |
| 837 | 785 |
| 838 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 786 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
| 839 if (manage_passwords_bubble_ == this) | 787 if (manage_passwords_bubble_ == this) |
| 840 manage_passwords_bubble_ = NULL; | 788 manage_passwords_bubble_ = NULL; |
| 841 } | 789 } |
| 842 | 790 |
| 843 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 791 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
| 844 return initially_focused_view_; | 792 return initially_focused_view_; |
| 845 } | 793 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 AddChildView(new SaveConfirmationView(this)); | 839 AddChildView(new SaveConfirmationView(this)); |
| 892 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) { | 840 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 893 AddChildView(new AutoSigninView(this)); | 841 AddChildView(new AutoSigninView(this)); |
| 894 } else if (model_.state() == | 842 } else if (model_.state() == |
| 895 password_manager::ui::CHROME_SIGN_IN_PROMO_STATE) { | 843 password_manager::ui::CHROME_SIGN_IN_PROMO_STATE) { |
| 896 AddChildView(new SignInPromoView(this)); | 844 AddChildView(new SignInPromoView(this)); |
| 897 } else { | 845 } else { |
| 898 AddChildView(new ManageView(this)); | 846 AddChildView(new ManageView(this)); |
| 899 } | 847 } |
| 900 } | 848 } |
| OLD | NEW |