Commit 6163c552 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] Hide Bubble when showing Leak Dialog

This change implements hiding the bubble when the leak dialog is about
to be shown.

Bug: 986317
Change-Id: Ie53dd100d11d3e9015f9d9c0cc948d54ea430982
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768531
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690413}
parent b378dadb
...@@ -85,7 +85,6 @@ const password_manager::InteractionsStats* FindStatsByUsername( ...@@ -85,7 +85,6 @@ const password_manager::InteractionsStats* FindStatsByUsername(
ManagePasswordsUIController::ManagePasswordsUIController( ManagePasswordsUIController::ManagePasswordsUIController(
content::WebContents* web_contents) content::WebContents* web_contents)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
bubble_status_(NOT_SHOWN),
are_passwords_revealed_when_next_bubble_is_opened_(false) { are_passwords_revealed_when_next_bubble_is_opened_(false) {
passwords_data_.set_client( passwords_data_.set_client(
ChromePasswordManagerClient::FromWebContents(web_contents)); ChromePasswordManagerClient::FromWebContents(web_contents));
...@@ -101,7 +100,7 @@ void ManagePasswordsUIController::OnPasswordSubmitted( ...@@ -101,7 +100,7 @@ void ManagePasswordsUIController::OnPasswordSubmitted(
std::unique_ptr<PasswordFormManagerForUI> form_manager) { std::unique_ptr<PasswordFormManagerForUI> form_manager) {
// If the save bubble is already shown (possibly manual fallback for saving) // If the save bubble is already shown (possibly manual fallback for saving)
// then ignore the changes because the user may interact with it right now. // then ignore the changes because the user may interact with it right now.
if (bubble_status_ == SHOWN && if (bubble_status_ == BubbleStatus::SHOWN &&
GetState() == password_manager::ui::PENDING_PASSWORD_STATE) GetState() == password_manager::ui::PENDING_PASSWORD_STATE)
return; return;
bool show_bubble = !form_manager->IsBlacklisted(); bool show_bubble = !form_manager->IsBlacklisted();
...@@ -117,7 +116,7 @@ void ManagePasswordsUIController::OnPasswordSubmitted( ...@@ -117,7 +116,7 @@ void ManagePasswordsUIController::OnPasswordSubmitted(
show_bubble = false; show_bubble = false;
} }
if (show_bubble) if (show_bubble)
bubble_status_ = SHOULD_POP_UP; bubble_status_ = BubbleStatus::SHOULD_POP_UP;
UpdateBubbleAndIconVisibility(); UpdateBubbleAndIconVisibility();
} }
...@@ -126,7 +125,7 @@ void ManagePasswordsUIController::OnUpdatePasswordSubmitted( ...@@ -126,7 +125,7 @@ void ManagePasswordsUIController::OnUpdatePasswordSubmitted(
DestroyAccountChooser(); DestroyAccountChooser();
save_fallback_timer_.Stop(); save_fallback_timer_.Stop();
passwords_data_.OnUpdatePassword(std::move(form_manager)); passwords_data_.OnUpdatePassword(std::move(form_manager));
bubble_status_ = SHOULD_POP_UP; bubble_status_ = BubbleStatus::SHOULD_POP_UP;
UpdateBubbleAndIconVisibility(); UpdateBubbleAndIconVisibility();
} }
...@@ -155,7 +154,7 @@ void ManagePasswordsUIController::OnHideManualFallbackForSaving() { ...@@ -155,7 +154,7 @@ void ManagePasswordsUIController::OnHideManualFallbackForSaving() {
return; return;
} }
// Don't hide the fallback if the bubble is open. // Don't hide the fallback if the bubble is open.
if (bubble_status_ == SHOWN || bubble_status_ == SHOWN_PENDING_ICON_UPDATE) if (IsShowingBubble())
return; return;
save_fallback_timer_.Stop(); save_fallback_timer_.Stop();
...@@ -200,7 +199,7 @@ void ManagePasswordsUIController::OnAutoSignin( ...@@ -200,7 +199,7 @@ void ManagePasswordsUIController::OnAutoSignin(
DCHECK(!local_forms.empty()); DCHECK(!local_forms.empty());
DestroyAccountChooser(); DestroyAccountChooser();
passwords_data_.OnAutoSignin(std::move(local_forms), origin); passwords_data_.OnAutoSignin(std::move(local_forms), origin);
bubble_status_ = SHOULD_POP_UP; bubble_status_ = BubbleStatus::SHOULD_POP_UP;
UpdateBubbleAndIconVisibility(); UpdateBubbleAndIconVisibility();
} }
...@@ -219,7 +218,7 @@ void ManagePasswordsUIController::OnAutomaticPasswordSave( ...@@ -219,7 +218,7 @@ void ManagePasswordsUIController::OnAutomaticPasswordSave(
DestroyAccountChooser(); DestroyAccountChooser();
save_fallback_timer_.Stop(); save_fallback_timer_.Stop();
passwords_data_.OnAutomaticPasswordSave(std::move(form_manager)); passwords_data_.OnAutomaticPasswordSave(std::move(form_manager));
bubble_status_ = SHOULD_POP_UP; bubble_status_ = BubbleStatus::SHOULD_POP_UP;
UpdateBubbleAndIconVisibility(); UpdateBubbleAndIconVisibility();
} }
...@@ -236,9 +235,9 @@ void ManagePasswordsUIController::OnPasswordAutofilled( ...@@ -236,9 +235,9 @@ void ManagePasswordsUIController::OnPasswordAutofilled(
passwords_data_.OnPasswordAutofilled(password_form_map, origin, passwords_data_.OnPasswordAutofilled(password_form_map, origin,
federated_matches); federated_matches);
// Don't close the existing bubble. Update the icon later. // Don't close the existing bubble. Update the icon later.
if (bubble_status_ == SHOWN) if (bubble_status_ == BubbleStatus::SHOWN)
bubble_status_ = SHOWN_PENDING_ICON_UPDATE; bubble_status_ = BubbleStatus::SHOWN_PENDING_ICON_UPDATE;
if (bubble_status_ != SHOWN_PENDING_ICON_UPDATE) if (bubble_status_ != BubbleStatus::SHOWN_PENDING_ICON_UPDATE)
UpdateBubbleAndIconVisibility(); UpdateBubbleAndIconVisibility();
} }
} }
...@@ -247,9 +246,15 @@ void ManagePasswordsUIController::OnCredentialLeak( ...@@ -247,9 +246,15 @@ void ManagePasswordsUIController::OnCredentialLeak(
const password_manager::CredentialLeakType leak_type, const password_manager::CredentialLeakType leak_type,
const GURL& origin) { const GURL& origin) {
// Existing dialog shouldn't be closed. // Existing dialog shouldn't be closed.
if (dialog_controller_) { if (dialog_controller_)
return; return;
}
// Hide the manage passwords bubble if currently shown.
if (IsShowingBubble())
TabDialogs::FromWebContents(web_contents())->HideManagePasswordsBubble();
else
ClearPopUpFlagForBubble();
auto* raw_controller = auto* raw_controller =
new CredentialLeakDialogControllerImpl(this, leak_type, origin); new CredentialLeakDialogControllerImpl(this, leak_type, origin);
dialog_controller_.reset(raw_controller); dialog_controller_.reset(raw_controller);
...@@ -359,12 +364,13 @@ bool ManagePasswordsUIController::BubbleIsManualFallbackForSaving() const { ...@@ -359,12 +364,13 @@ bool ManagePasswordsUIController::BubbleIsManualFallbackForSaving() const {
void ManagePasswordsUIController::OnBubbleShown() { void ManagePasswordsUIController::OnBubbleShown() {
are_passwords_revealed_when_next_bubble_is_opened_ = false; are_passwords_revealed_when_next_bubble_is_opened_ = false;
bubble_status_ = SHOWN; bubble_status_ = BubbleStatus::SHOWN;
} }
void ManagePasswordsUIController::OnBubbleHidden() { void ManagePasswordsUIController::OnBubbleHidden() {
bool update_icon = (bubble_status_ == SHOWN_PENDING_ICON_UPDATE); bool update_icon =
bubble_status_ = NOT_SHOWN; (bubble_status_ == BubbleStatus::SHOWN_PENDING_ICON_UPDATE);
bubble_status_ = BubbleStatus::NOT_SHOWN;
if (GetState() == password_manager::ui::CONFIRMATION_STATE || if (GetState() == password_manager::ui::CONFIRMATION_STATE ||
GetState() == password_manager::ui::AUTO_SIGNIN_STATE) { GetState() == password_manager::ui::AUTO_SIGNIN_STATE) {
passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE);
...@@ -430,7 +436,7 @@ void ManagePasswordsUIController::SavePassword(const base::string16& username, ...@@ -430,7 +436,7 @@ void ManagePasswordsUIController::SavePassword(const base::string16& username,
passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE); passwords_data_.TransitionToState(password_manager::ui::MANAGE_STATE);
// The icon is to be updated after the bubble (either "Save password" or "Sign // The icon is to be updated after the bubble (either "Save password" or "Sign
// in to Chrome") is closed. // in to Chrome") is closed.
bubble_status_ = SHOWN_PENDING_ICON_UPDATE; bubble_status_ = BubbleStatus::SHOWN_PENDING_ICON_UPDATE;
} }
void ManagePasswordsUIController::ChooseCredential( void ManagePasswordsUIController::ChooseCredential(
...@@ -565,8 +571,7 @@ void ManagePasswordsUIController::DidFinishNavigation( ...@@ -565,8 +571,7 @@ void ManagePasswordsUIController::DidFinishNavigation(
// Keep the state if the bubble is currently open or the fallback for saving // Keep the state if the bubble is currently open or the fallback for saving
// should be still available. // should be still available.
if (bubble_status_ == SHOWN || bubble_status_ == SHOWN_PENDING_ICON_UPDATE || if (IsShowingBubble() || save_fallback_timer_.IsRunning()) {
save_fallback_timer_.IsRunning()) {
return; return;
} }
...@@ -601,7 +606,7 @@ void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { ...@@ -601,7 +606,7 @@ void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() {
void ManagePasswordsUIController::ClearPopUpFlagForBubble() { void ManagePasswordsUIController::ClearPopUpFlagForBubble() {
if (ShouldBubblePopUp()) if (ShouldBubblePopUp())
bubble_status_ = NOT_SHOWN; bubble_status_ = BubbleStatus::NOT_SHOWN;
} }
void ManagePasswordsUIController::DestroyAccountChooser() { void ManagePasswordsUIController::DestroyAccountChooser() {
...@@ -638,7 +643,7 @@ void ManagePasswordsUIController::ReopenBubbleAfterAuth( ...@@ -638,7 +643,7 @@ void ManagePasswordsUIController::ReopenBubbleAfterAuth(
return; return;
if (auth_is_successful) if (auth_is_successful)
are_passwords_revealed_when_next_bubble_is_opened_ = true; are_passwords_revealed_when_next_bubble_is_opened_ = true;
bubble_status_ = SHOULD_POP_UP_AFTER_REAUTH; bubble_status_ = BubbleStatus::SHOULD_POP_UP_AFTER_REAUTH;
UpdateBubbleAndIconVisibility(); UpdateBubbleAndIconVisibility();
} }
......
...@@ -102,7 +102,7 @@ class ManagePasswordsUIController ...@@ -102,7 +102,7 @@ class ManagePasswordsUIController
// True iff the bubble is to be opened automatically. // True iff the bubble is to be opened automatically.
bool IsAutomaticallyOpeningBubble() const { bool IsAutomaticallyOpeningBubble() const {
return bubble_status_ == SHOULD_POP_UP; return bubble_status_ == BubbleStatus::SHOULD_POP_UP;
} }
base::WeakPtr<PasswordsModelDelegate> GetModelDelegateProxy(); base::WeakPtr<PasswordsModelDelegate> GetModelDelegateProxy();
...@@ -181,13 +181,11 @@ class ManagePasswordsUIController ...@@ -181,13 +181,11 @@ class ManagePasswordsUIController
// True if the bubble is to be opened automatically or after re-auth. // True if the bubble is to be opened automatically or after re-auth.
bool ShouldBubblePopUp() const { bool ShouldBubblePopUp() const {
return IsAutomaticallyOpeningBubble() || return IsAutomaticallyOpeningBubble() ||
bubble_status_ == SHOULD_POP_UP_AFTER_REAUTH; bubble_status_ == BubbleStatus::SHOULD_POP_UP_AFTER_REAUTH;
} }
// Returns whether the bubble is currently open. // Returns whether the bubble is currently open.
bool IsShowingBubbleForTest() const { bool IsShowingBubbleForTest() const { return IsShowingBubble(); }
return bubble_status_ != BubbleStatus::NOT_SHOWN;
}
// content::WebContentsObserver: // content::WebContentsObserver:
void DidFinishNavigation( void DidFinishNavigation(
...@@ -201,7 +199,7 @@ class ManagePasswordsUIController ...@@ -201,7 +199,7 @@ class ManagePasswordsUIController
void NavigateToPasswordCheckup() override; void NavigateToPasswordCheckup() override;
void OnLeakDialogHidden() override; void OnLeakDialogHidden() override;
enum BubbleStatus { enum class BubbleStatus {
NOT_SHOWN, NOT_SHOWN,
// The bubble is to be popped up in the next call to // The bubble is to be popped up in the next call to
// UpdateBubbleAndIconVisibility(). // UpdateBubbleAndIconVisibility().
...@@ -213,6 +211,11 @@ class ManagePasswordsUIController ...@@ -213,6 +211,11 @@ class ManagePasswordsUIController
SHOWN_PENDING_ICON_UPDATE, SHOWN_PENDING_ICON_UPDATE,
}; };
bool IsShowingBubble() const {
return bubble_status_ == BubbleStatus::SHOWN ||
bubble_status_ == BubbleStatus::SHOWN_PENDING_ICON_UPDATE;
}
// Returns the timeout for the manual save fallback. // Returns the timeout for the manual save fallback.
static base::TimeDelta GetTimeoutForSaveFallback(); static base::TimeDelta GetTimeoutForSaveFallback();
...@@ -250,7 +253,7 @@ class ManagePasswordsUIController ...@@ -250,7 +253,7 @@ class ManagePasswordsUIController
// The controller for the blocking dialogs. // The controller for the blocking dialogs.
std::unique_ptr<PasswordBaseDialogController> dialog_controller_; std::unique_ptr<PasswordBaseDialogController> dialog_controller_;
BubbleStatus bubble_status_; BubbleStatus bubble_status_ = BubbleStatus::NOT_SHOWN;
// The timer that controls whether the fallback for saving should be // The timer that controls whether the fallback for saving should be
// available. Should be reset once the fallback is not needed (an automatic // available. Should be reset once the fallback is not needed (an automatic
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/passwords/manage_passwords_test.h" #include "chrome/browser/ui/passwords/manage_passwords_test.h"
#include "chrome/browser/ui/passwords/passwords_client_ui_delegate.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate.h" #include "chrome/browser/ui/passwords/passwords_model_delegate.h"
#include "chrome/browser/ui/tab_dialogs.h" #include "chrome/browser/ui/tab_dialogs.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
...@@ -382,3 +383,16 @@ IN_PROC_BROWSER_TEST_F(PasswordBubbleInteractiveUiTest, AutoSigninNoFocus) { ...@@ -382,3 +383,16 @@ IN_PROC_BROWSER_TEST_F(PasswordBubbleInteractiveUiTest, AutoSigninNoFocus) {
EXPECT_FALSE(IsBubbleShowing()); EXPECT_FALSE(IsBubbleShowing());
} }
// Test that triggering the leak detection dialog successfully hides a showing
// bubble.
IN_PROC_BROWSER_TEST_F(PasswordBubbleInteractiveUiTest, LeakPromptHidesBubble) {
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
SetupPendingPassword();
EXPECT_TRUE(IsBubbleShowing());
GetController()->OnCredentialLeak(
password_manager::CredentialLeakFlags::kPasswordSaved,
GURL("https://example.com"));
EXPECT_FALSE(IsBubbleShowing());
}
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