| 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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 parent_->CloseBubble(); | 539 parent_->CloseBubble(); |
| 542 } | 540 } |
| 543 | 541 |
| 544 void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed( | 542 void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed( |
| 545 views::Button* sender, const ui::Event& event) { | 543 views::Button* sender, const ui::Event& event) { |
| 546 DCHECK_EQ(sender, ok_button_); | 544 DCHECK_EQ(sender, ok_button_); |
| 547 parent_->model()->OnOKClicked(); | 545 parent_->model()->OnOKClicked(); |
| 548 parent_->CloseBubble(); | 546 parent_->CloseBubble(); |
| 549 } | 547 } |
| 550 | 548 |
| 551 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- | |
| 552 | |
| 553 // The class listens for WebContentsView events and notifies the bubble if the | |
| 554 // view was clicked on or received keystrokes. | |
| 555 class ManagePasswordsBubbleView::WebContentMouseHandler | |
| 556 : public ui::EventHandler { | |
| 557 public: | |
| 558 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); | |
| 559 | |
| 560 void OnKeyEvent(ui::KeyEvent* event) override; | |
| 561 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 562 void OnTouchEvent(ui::TouchEvent* event) override; | |
| 563 | |
| 564 private: | |
| 565 ManagePasswordsBubbleView* bubble_; | |
| 566 std::unique_ptr<views::EventMonitor> event_monitor_; | |
| 567 | |
| 568 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler); | |
| 569 }; | |
| 570 | |
| 571 ManagePasswordsBubbleView::WebContentMouseHandler::WebContentMouseHandler( | |
| 572 ManagePasswordsBubbleView* bubble) | |
| 573 : bubble_(bubble) { | |
| 574 content::WebContents* web_contents = bubble_->web_contents(); | |
| 575 DCHECK(web_contents); | |
| 576 event_monitor_ = views::EventMonitor::CreateWindowMonitor( | |
| 577 this, web_contents->GetTopLevelNativeWindow()); | |
| 578 } | |
| 579 | |
| 580 void ManagePasswordsBubbleView::WebContentMouseHandler::OnKeyEvent( | |
| 581 ui::KeyEvent* event) { | |
| 582 content::WebContents* web_contents = bubble_->web_contents(); | |
| 583 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); | |
| 584 if ((event->key_code() == ui::VKEY_ESCAPE || | |
| 585 rvh->IsFocusedElementEditable()) && event->type() == ui::ET_KEY_PRESSED) | |
| 586 bubble_->CloseBubble(); | |
| 587 } | |
| 588 | |
| 589 void ManagePasswordsBubbleView::WebContentMouseHandler::OnMouseEvent( | |
| 590 ui::MouseEvent* event) { | |
| 591 if (event->type() == ui::ET_MOUSE_PRESSED) | |
| 592 bubble_->CloseBubble(); | |
| 593 } | |
| 594 | |
| 595 void ManagePasswordsBubbleView::WebContentMouseHandler::OnTouchEvent( | |
| 596 ui::TouchEvent* event) { | |
| 597 if (event->type() == ui::ET_TOUCH_PRESSED) | |
| 598 bubble_->CloseBubble(); | |
| 599 } | |
| 600 | |
| 601 // ManagePasswordsBubbleView::UpdatePendingView ------------------------------- | 549 // ManagePasswordsBubbleView::UpdatePendingView ------------------------------- |
| 602 | 550 |
| 603 // A view offering the user the ability to update credentials. Contains a | 551 // A view offering the user the ability to update credentials. Contains a |
| 604 // single ManagePasswordItemsView (in case of one credentials) or | 552 // single ManagePasswordItemsView (in case of one credentials) or |
| 605 // CredentialsSelectionView otherwise, along with a "Update Passwords" button | 553 // CredentialsSelectionView otherwise, along with a "Update Passwords" button |
| 606 // and a rejection button. | 554 // and a rejection button. |
| 607 class ManagePasswordsBubbleView::UpdatePendingView | 555 class ManagePasswordsBubbleView::UpdatePendingView |
| 608 : public views::View, | 556 : public views::View, |
| 609 public views::ButtonListener, | 557 public views::ButtonListener, |
| 610 public views::StyledLabelListener { | 558 public views::StyledLabelListener { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 711 |
| 764 ManagePasswordsBubbleView::ManagePasswordsBubbleView( | 712 ManagePasswordsBubbleView::ManagePasswordsBubbleView( |
| 765 content::WebContents* web_contents, | 713 content::WebContents* web_contents, |
| 766 views::View* anchor_view, | 714 views::View* anchor_view, |
| 767 DisplayReason reason) | 715 DisplayReason reason) |
| 768 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 716 : LocationBarBubbleDelegateView(anchor_view, web_contents), |
| 769 model_(web_contents, | 717 model_(web_contents, |
| 770 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC | 718 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC |
| 771 : ManagePasswordsBubbleModel::USER_ACTION), | 719 : ManagePasswordsBubbleModel::USER_ACTION), |
| 772 initially_focused_view_(nullptr) { | 720 initially_focused_view_(nullptr) { |
| 773 mouse_handler_.reset(new WebContentMouseHandler(this)); | 721 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); |
| 774 } | 722 } |
| 775 | 723 |
| 776 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 724 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
| 777 if (manage_passwords_bubble_ == this) | 725 if (manage_passwords_bubble_ == this) |
| 778 manage_passwords_bubble_ = NULL; | 726 manage_passwords_bubble_ = NULL; |
| 779 } | 727 } |
| 780 | 728 |
| 781 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 729 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
| 782 return initially_focused_view_; | 730 return initially_focused_view_; |
| 783 } | 731 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 AddChildView(new SaveConfirmationView(this)); | 769 AddChildView(new SaveConfirmationView(this)); |
| 822 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) { | 770 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 823 AddChildView(new AutoSigninView(this)); | 771 AddChildView(new AutoSigninView(this)); |
| 824 } else { | 772 } else { |
| 825 AddChildView(new ManageView(this)); | 773 AddChildView(new ManageView(this)); |
| 826 } | 774 } |
| 827 if (GetWidget()) | 775 if (GetWidget()) |
| 828 GetWidget()->UpdateWindowTitle(); | 776 GetWidget()->UpdateWindowTitle(); |
| 829 GetLayoutManager()->Layout(this); | 777 GetLayoutManager()->Layout(this); |
| 830 } | 778 } |
| OLD | NEW |