Commit 5db647c6 authored by vasilii's avatar vasilii Committed by Commit bot

Password bubble should close if user clicks on the web page.

BUG=394287

Review URL: https://codereview.chromium.org/512683003

Cr-Commit-Position: refs/heads/master@{#292381}
parent 6dc7551d
......@@ -86,6 +86,9 @@ class ManagePasswordsBubbleModel : public content::WebContentsObserver {
return save_confirmation_link_range_;
}
// Make the accessor public.
using WebContentsObserver::web_contents;
#if defined(UNIT_TEST)
// Gets and sets the reason the bubble was displayed.
password_manager::metrics_util::UIDisplayDisposition display_disposition()
......
......@@ -17,6 +17,8 @@
#include "chrome/grit/generated_resources.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/combobox_model.h"
#include "ui/base/resource/resource_bundle.h"
......@@ -512,6 +514,40 @@ void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed(
parent_->Close();
}
// ManagePasswordsBubbleView::WebContentMouseHandler --------------------------
// The class listens for WebContentsView events and notifies the bubble if the
// view was clicked on.
class ManagePasswordsBubbleView::WebContentMouseHandler
: public ui::EventHandler {
public:
explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble)
: bubble_(bubble) {
GetWebContentsWindow()->AddPreTargetHandler(this);
}
virtual ~WebContentMouseHandler() {
aura::Window* window = GetWebContentsWindow();
if (window)
window->RemovePreTargetHandler(this);
}
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
if (event->type() == ui::ET_MOUSE_PRESSED)
bubble_->OnWebContentClicked();
}
private:
aura::Window* GetWebContentsWindow() {
content::WebContents* web_contents = bubble_->model()->web_contents();
return web_contents ? web_contents->GetNativeView() : NULL;
}
ManagePasswordsBubbleView* bubble_;
DISALLOW_COPY_AND_ASSIGN(WebContentMouseHandler);
};
// ManagePasswordsBubbleView --------------------------------------------------
// static
......@@ -593,6 +629,7 @@ ManagePasswordsBubbleView::ManagePasswordsBubbleView(
set_notify_enter_exit_on_child(true);
if (anchor_view)
anchor_view->SetActive(true);
mouse_handler_.reset(new WebContentMouseHandler(this));
}
ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {
......@@ -701,3 +738,7 @@ void ManagePasswordsBubbleView::StartTimerIfNecessary() {
this,
&ManagePasswordsBubbleView::Close);
}
void ManagePasswordsBubbleView::OnWebContentClicked() {
Close();
}
......@@ -226,6 +226,9 @@ class ManagePasswordsBubbleView : public ManagePasswordsBubble,
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
// Called from WebContentMouseHandler when user clicks the web view.
void OnWebContentClicked();
void set_initially_focused_view(views::View* view) {
DCHECK(!initially_focused_view_);
initially_focused_view_ = view;
......@@ -248,6 +251,9 @@ class ManagePasswordsBubbleView : public ManagePasswordsBubble,
// Timer used to close the bubble after timeout.
base::OneShotTimer<ManagePasswordsBubbleView> timer_;
class WebContentMouseHandler;
scoped_ptr<WebContentMouseHandler> mouse_handler_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleView);
};
......
......@@ -8,6 +8,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_view_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -159,3 +160,14 @@ IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest,
samples->GetCount(
metrics_util::MANUAL_MANAGE_PASSWORDS));
}
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, CloseOnClick) {
ManagePasswordsBubbleView::ShowBubble(
browser()->tab_strip_model()->GetActiveWebContents(),
ManagePasswordsBubble::AUTOMATIC);
EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing());
EXPECT_FALSE(ManagePasswordsBubbleView::manage_password_bubble()->
GetFocusManager()->GetFocusedView());
ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment