Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc

Issue 512683003: Password bubble should close if user clicks on the web page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a test Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h" 9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
15 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" 15 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" 16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "components/password_manager/core/common/password_manager_ui.h" 18 #include "components/password_manager/core/common/password_manager_ui.h"
19 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/web_contents.h"
21 #include "ui/aura/window.h"
20 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/models/combobox_model.h" 23 #include "ui/base/models/combobox_model.h"
22 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/text_utils.h" 25 #include "ui/gfx/text_utils.h"
24 #include "ui/views/controls/button/blue_button.h" 26 #include "ui/views/controls/button/blue_button.h"
25 #include "ui/views/controls/button/label_button.h" 27 #include "ui/views/controls/button/label_button.h"
26 #include "ui/views/controls/combobox/combobox.h" 28 #include "ui/views/controls/combobox/combobox.h"
27 #include "ui/views/controls/styled_label.h" 29 #include "ui/views/controls/styled_label.h"
28 #include "ui/views/layout/fill_layout.h" 30 #include "ui/views/layout/fill_layout.h"
29 #include "ui/views/layout/grid_layout.h" 31 #include "ui/views/layout/grid_layout.h"
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 parent_->Close(); 507 parent_->Close();
506 } 508 }
507 509
508 void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed( 510 void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed(
509 views::Button* sender, const ui::Event& event) { 511 views::Button* sender, const ui::Event& event) {
510 DCHECK_EQ(sender, ok_button_); 512 DCHECK_EQ(sender, ok_button_);
511 parent_->model()->OnOKClicked(); 513 parent_->model()->OnOKClicked();
512 parent_->Close(); 514 parent_->Close();
513 } 515 }
514 516
517 // ManagePasswordsBubbleView::WebContentMouseHandler --------------------------
518
519 // The class listens for WebContentsView events and notifies the bubble if the
520 // view was clicked on.
521 class ManagePasswordsBubbleView::WebContentMouseHandler
522 : public ui::EventHandler {
523 public:
524 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble)
525 : bubble_(bubble) {
526 GetWebContentsWindow()->AddPreTargetHandler(this);
527 }
528
529 virtual ~WebContentMouseHandler() {
530 aura::Window* window = GetWebContentsWindow();
531 if (window)
532 window->RemovePreTargetHandler(this);
533 }
534
535 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
536 if (event->type() == ui::ET_MOUSE_PRESSED)
537 bubble_->OnWebContentClicked();
538 }
539
540 private:
541 aura::Window* GetWebContentsWindow() {
542 content::WebContents* web_contents = bubble_->model()->web_contents();
543 return web_contents ? web_contents->GetNativeView() : NULL;
544 }
545
546 ManagePasswordsBubbleView* bubble_;
547
548 DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler);
549 };
550
515 // ManagePasswordsBubbleView -------------------------------------------------- 551 // ManagePasswordsBubbleView --------------------------------------------------
516 552
517 // static 553 // static
518 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 554 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
519 NULL; 555 NULL;
520 556
521 // static 557 // static
522 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, 558 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
523 DisplayReason reason) { 559 DisplayReason reason) {
524 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 560 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 anchor_view ? views::BubbleBorder::TOP_RIGHT 622 anchor_view ? views::BubbleBorder::TOP_RIGHT
587 : views::BubbleBorder::NONE), 623 : views::BubbleBorder::NONE),
588 anchor_view_(anchor_view), 624 anchor_view_(anchor_view),
589 never_save_passwords_(false), 625 never_save_passwords_(false),
590 initially_focused_view_(NULL) { 626 initially_focused_view_(NULL) {
591 // Compensate for built-in vertical padding in the anchor view's image. 627 // Compensate for built-in vertical padding in the anchor view's image.
592 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); 628 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
593 set_notify_enter_exit_on_child(true); 629 set_notify_enter_exit_on_child(true);
594 if (anchor_view) 630 if (anchor_view)
595 anchor_view->SetActive(true); 631 anchor_view->SetActive(true);
632 mouse_handler_.reset(new WebContentMouseHandler(this));
596 } 633 }
597 634
598 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { 635 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {
599 if (anchor_view_) 636 if (anchor_view_)
600 anchor_view_->SetActive(false); 637 anchor_view_->SetActive(false);
601 } 638 }
602 639
603 void ManagePasswordsBubbleView::AdjustForFullscreen( 640 void ManagePasswordsBubbleView::AdjustForFullscreen(
604 const gfx::Rect& screen_bounds) { 641 const gfx::Rect& screen_bounds) {
605 if (GetAnchorView()) 642 if (GetAnchorView())
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 731
695 void ManagePasswordsBubbleView::StartTimerIfNecessary() { 732 void ManagePasswordsBubbleView::StartTimerIfNecessary() {
696 // Active bubble will stay visible until it loses focus. 733 // Active bubble will stay visible until it loses focus.
697 if (GetWidget()->IsActive()) 734 if (GetWidget()->IsActive())
698 return; 735 return;
699 timer_.Start(FROM_HERE, 736 timer_.Start(FROM_HERE,
700 base::TimeDelta::FromSeconds(kBubbleCloseDelay), 737 base::TimeDelta::FromSeconds(kBubbleCloseDelay),
701 this, 738 this,
702 &ManagePasswordsBubbleView::Close); 739 &ManagePasswordsBubbleView::Close);
703 } 740 }
741
742 void ManagePasswordsBubbleView::OnWebContentClicked() {
743 Close();
744 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698