Commit cb29305b authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Delete ManagePasswordsBubbleModel

Since all Password views now have their own controller, let's get rid
of the ManagePasswordsBubbleModel.

Bug: 1044034
Change-Id: Id90d288d2bea3439dc251651185054242630b528
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2030767
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737315}
parent 49d0dd31
......@@ -1079,8 +1079,6 @@ jumbo_static_library("ui") {
"passwords/credential_manager_dialog_controller_impl.h",
"passwords/google_password_manager_navigation_throttle.cc",
"passwords/google_password_manager_navigation_throttle.h",
"passwords/manage_passwords_bubble_model.cc",
"passwords/manage_passwords_bubble_model.h",
"passwords/manage_passwords_icon_view.h",
"passwords/manage_passwords_ui_controller.cc",
"passwords/manage_passwords_ui_controller.h",
......
......@@ -13,11 +13,10 @@ namespace metrics_util = password_manager::metrics_util;
GenerationConfirmationBubbleController::GenerationConfirmationBubbleController(
base::WeakPtr<PasswordsModelDelegate> delegate,
ManagePasswordsBubbleModel::DisplayReason display_reason)
DisplayReason display_reason)
: PasswordBubbleControllerBase(
std::move(delegate),
/*display_disposition=*/display_reason ==
ManagePasswordsBubbleModel::AUTOMATIC
/*display_disposition=*/display_reason == DisplayReason::kAutomatic
? metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION
: metrics_util::MANUAL_GENERATED_PASSWORD_CONFIRMATION),
dismissal_reason_(metrics_util::NO_DIRECT_INTERACTION) {
......
......@@ -6,8 +6,6 @@
#define CHROME_BROWSER_UI_PASSWORDS_BUBBLE_CONTROLLERS_GENERATION_CONFIRMATION_BUBBLE_CONTROLLER_H_
#include "chrome/browser/ui/passwords/bubble_controllers/password_bubble_controller_base.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "components/password_manager/core/browser/manage_passwords_referrer.h"
#include "ui/gfx/range/range.h"
......@@ -18,7 +16,7 @@ class GenerationConfirmationBubbleController
public:
GenerationConfirmationBubbleController(
base::WeakPtr<PasswordsModelDelegate> delegate,
ManagePasswordsBubbleModel::DisplayReason display_reason);
DisplayReason display_reason);
~GenerationConfirmationBubbleController() override;
// Called by the view code when the navigate to passwords.google.com link is
......
......@@ -46,7 +46,8 @@ class GenerationConfirmationBubbleControllerTest : public ::testing::Test {
void GenerationConfirmationBubbleControllerTest::Init() {
EXPECT_CALL(*delegate(), OnBubbleShown());
controller_.reset(new GenerationConfirmationBubbleController(
mock_delegate_->AsWeakPtr(), ManagePasswordsBubbleModel::AUTOMATIC));
mock_delegate_->AsWeakPtr(),
PasswordBubbleControllerBase::DisplayReason::kAutomatic));
ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(delegate()));
}
......
......@@ -56,7 +56,7 @@ void ItemsBubbleController::OnManageClicked(
void ItemsBubbleController::OnPasswordAction(
const autofill::PasswordForm& password_form,
ManagePasswordsBubbleModel::PasswordAction action) {
PasswordAction action) {
Profile* profile = GetProfile();
if (!profile)
return;
......@@ -64,7 +64,7 @@ void ItemsBubbleController::OnPasswordAction(
GetPasswordStore(profile, password_form.IsUsingAccountStore()).get();
DCHECK(password_store);
if (action == ManagePasswordsBubbleModel::REMOVE_PASSWORD)
if (action == PasswordAction::kRemovePassword)
password_store->RemoveLogin(password_form);
else
password_store->AddLogin(password_form);
......
......@@ -8,7 +8,6 @@
#include "chrome/browser/ui/passwords/bubble_controllers/password_bubble_controller_base.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "components/password_manager/core/browser/manage_passwords_referrer.h"
class PasswordsModelDelegate;
......@@ -26,7 +25,7 @@ class ItemsBubbleController : public PasswordBubbleControllerBase {
// Called by the view code to delete or add a password form to the
// PasswordStore.
void OnPasswordAction(const autofill::PasswordForm& password_form,
ManagePasswordsBubbleModel::PasswordAction action);
PasswordAction action);
// Returns the available credentials which match the current site.
const std::vector<autofill::PasswordForm>& local_credentials() const {
......
......@@ -150,8 +150,8 @@ TEST_F(ItemsBubbleControllerTest, OnPasswordActionAddPassword) {
EXPECT_CALL(*GetStore(), AddLogin(form));
controller()->OnPasswordAction(form,
ManagePasswordsBubbleModel::ADD_PASSWORD);
controller()->OnPasswordAction(
form, PasswordBubbleControllerBase::PasswordAction::kAddPassword);
}
TEST_F(ItemsBubbleControllerTest, OnPasswordActionRemovePassword) {
......@@ -165,8 +165,8 @@ TEST_F(ItemsBubbleControllerTest, OnPasswordActionRemovePassword) {
EXPECT_CALL(*GetStore(), RemoveLogin(form));
controller()->OnPasswordAction(form,
ManagePasswordsBubbleModel::REMOVE_PASSWORD);
controller()->OnPasswordAction(
form, PasswordBubbleControllerBase::PasswordAction::kRemovePassword);
}
TEST_F(ItemsBubbleControllerTest, ShouldReturnLocalCredentials) {
......
......@@ -24,6 +24,8 @@ class Profile;
// password management actions for the coressponding view.
class PasswordBubbleControllerBase {
public:
enum class PasswordAction { kRemovePassword, kAddPassword };
enum class DisplayReason { kAutomatic, kUserAction };
PasswordBubbleControllerBase(
base::WeakPtr<PasswordsModelDelegate> delegate,
password_manager::metrics_util::UIDisplayDisposition display_disposition);
......
......@@ -9,7 +9,6 @@
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate.h"
#include "chrome/grit/generated_resources.h"
......@@ -35,9 +34,10 @@ namespace metrics_util = password_manager::metrics_util;
using Store = autofill::PasswordForm::Store;
password_manager::metrics_util::UIDisplayDisposition ComputeDisplayDisposition(
ManagePasswordsBubbleModel::DisplayReason display_reason,
PasswordBubbleControllerBase::DisplayReason display_reason,
password_manager::ui::State state) {
if (display_reason == ManagePasswordsBubbleModel::USER_ACTION) {
if (display_reason ==
PasswordBubbleControllerBase::DisplayReason::kUserAction) {
switch (state) {
case password_manager::ui::PENDING_PASSWORD_STATE:
return metrics_util::MANUAL_WITH_PASSWORD_PENDING;
......@@ -90,7 +90,7 @@ bool IsSyncUser(Profile* profile) {
PendingBubbleController::PendingBubbleController(
base::WeakPtr<PasswordsModelDelegate> delegate,
ManagePasswordsBubbleModel::DisplayReason display_reason)
PasswordBubbleControllerBase::DisplayReason display_reason)
: PasswordBubbleControllerBase(
delegate,
ComputeDisplayDisposition(display_reason, delegate->GetState())),
......@@ -134,7 +134,8 @@ PendingBubbleController::PendingBubbleController(
!are_passwords_revealed_when_bubble_is_opened_ &&
(pending_password_.form_has_autofilled_value ||
(!delegate_->BubbleIsManualFallbackForSaving() &&
display_reason == ManagePasswordsBubbleModel::USER_ACTION));
display_reason ==
PasswordBubbleControllerBase::DisplayReason::kUserAction));
enable_editing_ = delegate_->GetCredentialSource() !=
password_manager::metrics_util::CredentialSourceType::
kCredentialManagementAPI;
......
......@@ -7,17 +7,21 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/passwords/bubble_controllers/password_bubble_controller_base.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "components/password_manager/core/browser/manage_passwords_referrer.h"
#include "components/password_manager/core/browser/statistics_table.h"
#include "components/password_manager/core/common/password_manager_ui.h"
class PasswordsModelDelegate;
namespace base {
class Clock;
}
// This controller provides data and actions for the PasswordPendingView.
class PendingBubbleController : public PasswordBubbleControllerBase {
public:
explicit PendingBubbleController(
base::WeakPtr<PasswordsModelDelegate> delegate,
ManagePasswordsBubbleModel::DisplayReason display_reason);
DisplayReason display_reason);
~PendingBubbleController() override;
// Called by the view code when the save/update button is clicked by the user.
......
......@@ -113,9 +113,10 @@ class PendingBubbleControllerTest : public ::testing::Test {
}
void SetUpWithState(password_manager::ui::State state,
ManagePasswordsBubbleModel::DisplayReason reason);
void PretendPasswordWaiting(ManagePasswordsBubbleModel::DisplayReason reason =
ManagePasswordsBubbleModel::AUTOMATIC);
PasswordBubbleControllerBase::DisplayReason reason);
void PretendPasswordWaiting(
PasswordBubbleControllerBase::DisplayReason reason =
PasswordBubbleControllerBase::DisplayReason::kAutomatic);
void PretendUpdatePasswordWaiting();
void DestroyModelAndVerifyControllerExpectations();
......@@ -137,7 +138,7 @@ class PendingBubbleControllerTest : public ::testing::Test {
void PendingBubbleControllerTest::SetUpWithState(
password_manager::ui::State state,
ManagePasswordsBubbleModel::DisplayReason reason) {
PasswordBubbleControllerBase::DisplayReason reason) {
GURL origin(kSiteOrigin);
EXPECT_CALL(*delegate(), GetOrigin()).WillOnce(ReturnRef(origin));
EXPECT_CALL(*delegate(), GetState()).WillRepeatedly(Return(state));
......@@ -152,7 +153,7 @@ void PendingBubbleControllerTest::SetUpWithState(
}
void PendingBubbleControllerTest::PretendPasswordWaiting(
ManagePasswordsBubbleModel::DisplayReason reason) {
PasswordBubbleControllerBase::DisplayReason reason) {
EXPECT_CALL(*delegate(), GetPendingPassword())
.WillOnce(ReturnRef(pending_password()));
password_manager::InteractionsStats stats = GetTestStats();
......@@ -175,7 +176,7 @@ void PendingBubbleControllerTest::PretendUpdatePasswordWaiting() {
forms.push_back(std::move(current_form));
EXPECT_CALL(*delegate(), GetCurrentForms()).WillOnce(ReturnRef(forms));
SetUpWithState(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE,
ManagePasswordsBubbleModel::AUTOMATIC);
PasswordBubbleControllerBase::DisplayReason::kAutomatic);
}
void PendingBubbleControllerTest::
......@@ -527,27 +528,29 @@ class PendingBubbleControllerPasswordRevealingTest
std::tuple<bool /*is manual fallback*/,
bool /*form has autofilled value*/,
bool /*does os support user authentication*/,
ManagePasswordsBubbleModel::DisplayReason>> {};
PasswordBubbleControllerBase::DisplayReason>> {};
TEST_P(PendingBubbleControllerPasswordRevealingTest,
EyeIcon_ReauthForPasswordsRevealing) {
bool is_manual_fallback_for_saving = std::get<0>(GetParam());
bool form_has_autofilled_value = std::get<1>(GetParam());
bool does_os_support_user_auth = std::get<2>(GetParam());
ManagePasswordsBubbleModel::DisplayReason display_reason =
PasswordBubbleControllerBase::DisplayReason display_reason =
std::get<3>(GetParam());
// That state is impossible.
if (is_manual_fallback_for_saving &&
(display_reason == ManagePasswordsBubbleModel::AUTOMATIC))
(display_reason ==
PasswordBubbleControllerBase::DisplayReason::kAutomatic))
SUCCEED();
SCOPED_TRACE(testing::Message()
<< "is_manual_fallback_for_saving = "
<< is_manual_fallback_for_saving
SCOPED_TRACE(
testing::Message()
<< "is_manual_fallback_for_saving = " << is_manual_fallback_for_saving
<< " form_has_autofilled_value = " << form_has_autofilled_value
<< " display_reason = "
<< (display_reason == ManagePasswordsBubbleModel::AUTOMATIC
<< (display_reason ==
PasswordBubbleControllerBase::DisplayReason::kAutomatic
? "AUTOMATIC"
: "USER_ACTION"));
......@@ -560,8 +563,10 @@ TEST_P(PendingBubbleControllerPasswordRevealingTest,
PretendPasswordWaiting(display_reason);
bool reauth_expected = form_has_autofilled_value;
if (!reauth_expected) {
reauth_expected = !is_manual_fallback_for_saving &&
display_reason == ManagePasswordsBubbleModel::USER_ACTION;
reauth_expected =
!is_manual_fallback_for_saving &&
display_reason ==
PasswordBubbleControllerBase::DisplayReason::kUserAction;
}
EXPECT_EQ(reauth_expected,
controller()->password_revealing_requires_reauth());
......@@ -581,11 +586,13 @@ TEST_P(PendingBubbleControllerPasswordRevealingTest,
INSTANTIATE_TEST_SUITE_P(
PendingBubbleController,
PendingBubbleControllerPasswordRevealingTest,
testing::Combine(testing::Bool(),
testing::Combine(
testing::Bool(),
testing::Bool(),
testing::Bool(),
testing::Values(ManagePasswordsBubbleModel::AUTOMATIC,
ManagePasswordsBubbleModel::USER_ACTION)));
testing::Values(
PasswordBubbleControllerBase::DisplayReason::kAutomatic,
PasswordBubbleControllerBase::DisplayReason::kUserAction)));
TEST_F(PendingBubbleControllerTest, EyeIcon_BubbleReopenedAfterAuth) {
// Checks re-authentication is not needed if the bubble is opened right after
......@@ -594,7 +601,8 @@ TEST_F(PendingBubbleControllerTest, EyeIcon_BubbleReopenedAfterAuth) {
// After successful authentication this value is set to true.
EXPECT_CALL(*delegate(), ArePasswordsRevealedWhenBubbleIsOpened())
.WillOnce(Return(true));
PretendPasswordWaiting(ManagePasswordsBubbleModel::USER_ACTION);
PretendPasswordWaiting(
PasswordBubbleControllerBase::DisplayReason::kUserAction);
EXPECT_FALSE(controller()->password_revealing_requires_reauth());
EXPECT_TRUE(controller()->RevealPasswords());
......@@ -614,7 +622,8 @@ TEST_F(PendingBubbleControllerTest, PasswordsRevealedReportedAfterReauth) {
EXPECT_CALL(*delegate(), ArePasswordsRevealedWhenBubbleIsOpened())
.WillOnce(Return(true));
EXPECT_CALL(*delegate(), OnPasswordsRevealed());
PretendPasswordWaiting(ManagePasswordsBubbleModel::USER_ACTION);
PretendPasswordWaiting(
PasswordBubbleControllerBase::DisplayReason::kUserAction);
}
TEST_F(PendingBubbleControllerTest, DisableEditing) {
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include <stddef.h>
#include <algorithm>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include "base/metrics/field_trial_params.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/default_clock.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/password_manager/password_store_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_feature_manager.h"
#include "components/password_manager/core/browser/password_form_metrics_recorder.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_service.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
namespace metrics_util = password_manager::metrics_util;
ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
base::WeakPtr<PasswordsModelDelegate> delegate,
DisplayReason display_reason)
: delegate_(std::move(delegate)),
interaction_reported_(false),
are_passwords_revealed_when_bubble_is_opened_(false),
metrics_recorder_(delegate_->GetPasswordFormMetricsRecorder()) {
password_manager::metrics_util::UIDisplayDisposition display_disposition =
metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING;
if (display_reason == USER_ACTION) {
switch (state_) {
case password_manager::ui::PENDING_PASSWORD_STATE:
case password_manager::ui::PENDING_PASSWORD_UPDATE_STATE:
case password_manager::ui::MANAGE_STATE:
case password_manager::ui::CONFIRMATION_STATE:
case password_manager::ui::CREDENTIAL_REQUEST_STATE:
case password_manager::ui::AUTO_SIGNIN_STATE:
case password_manager::ui::CHROME_SIGN_IN_PROMO_STATE:
case password_manager::ui::INACTIVE_STATE:
NOTREACHED();
break;
}
} else {
switch (state_) {
case password_manager::ui::PENDING_PASSWORD_STATE:
case password_manager::ui::PENDING_PASSWORD_UPDATE_STATE:
case password_manager::ui::CONFIRMATION_STATE:
case password_manager::ui::AUTO_SIGNIN_STATE:
case password_manager::ui::MANAGE_STATE:
case password_manager::ui::CREDENTIAL_REQUEST_STATE:
case password_manager::ui::CHROME_SIGN_IN_PROMO_STATE:
case password_manager::ui::INACTIVE_STATE:
NOTREACHED();
break;
}
}
if (metrics_recorder_) {
metrics_recorder_->RecordPasswordBubbleShown(
delegate_->GetCredentialSource(), display_disposition);
}
metrics_util::LogUIDisplayDisposition(display_disposition);
delegate_->OnBubbleShown();
}
ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {
if (!interaction_reported_)
OnBubbleClosing();
}
void ManagePasswordsBubbleModel::OnBubbleClosing() {
if (delegate_)
delegate_->OnBubbleHidden();
delegate_.reset();
interaction_reported_ = true;
}
Profile* ManagePasswordsBubbleModel::GetProfile() const {
content::WebContents* web_contents = GetWebContents();
if (!web_contents)
return nullptr;
return Profile::FromBrowserContext(web_contents->GetBrowserContext());
}
content::WebContents* ManagePasswordsBubbleModel::GetWebContents() const {
return delegate_ ? delegate_->GetWebContents() : nullptr;
}
void ManagePasswordsBubbleModel::SetClockForTesting(base::Clock* clock) {}
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
#include <utility>
#include <vector>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/time/clock.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/manage_passwords_referrer.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/statistics_table.h"
#include "components/password_manager/core/common/password_manager_ui.h"
namespace content {
class WebContents;
}
namespace password_manager {
class PasswordFormMetricsRecorder;
}
class PasswordsModelDelegate;
class Profile;
// This model provides data for the ManagePasswordsBubble and controls the
// password management actions.
class ManagePasswordsBubbleModel {
public:
enum PasswordAction { REMOVE_PASSWORD, ADD_PASSWORD };
enum DisplayReason { AUTOMATIC, USER_ACTION };
// Creates a ManagePasswordsBubbleModel, which holds a weak pointer to the
// delegate. Construction implies that the bubble is shown. The bubble's state
// is updated from the ManagePasswordsUIController associated with |delegate|.
ManagePasswordsBubbleModel(base::WeakPtr<PasswordsModelDelegate> delegate,
DisplayReason reason);
~ManagePasswordsBubbleModel();
// The method MAY BE called to record the statistics while the bubble is being
// closed. Otherwise, it is called later on when the model is destroyed.
void OnBubbleClosing();
password_manager::ui::State state() const { return state_; }
const base::string16& title() const { return title_; }
const autofill::PasswordForm& pending_password() const {
return pending_password_;
}
bool are_passwords_revealed_when_bubble_is_opened() const {
return are_passwords_revealed_when_bubble_is_opened_;
}
bool enable_editing() const { return enable_editing_; }
Profile* GetProfile() const;
content::WebContents* GetWebContents() const;
void SetClockForTesting(base::Clock* clock);
private:
class InteractionKeeper;
// URL of the page from where this bubble was triggered.
GURL origin_;
password_manager::ui::State state_;
base::string16 title_;
autofill::PasswordForm pending_password_;
std::vector<autofill::PasswordForm> local_credentials_;
// A bridge to ManagePasswordsUIController instance.
base::WeakPtr<PasswordsModelDelegate> delegate_;
// True if the model has already recorded all the necessary statistics when
// the bubble is closing.
bool interaction_reported_;
// True iff bubble should pop up with revealed password value.
bool are_passwords_revealed_when_bubble_is_opened_;
// True iff username/password editing should be enabled.
bool enable_editing_;
// Reference to metrics recorder of the PasswordForm presented to the user by
// |this|. We hold on to this because |delegate_| may not be able to provide
// the reference anymore when we need it.
scoped_refptr<password_manager::PasswordFormMetricsRecorder>
metrics_recorder_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleModel);
};
#endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
......@@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_ICON_VIEWS_H_
#include "base/macros.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
......
......@@ -28,11 +28,9 @@ PasswordAutoSignInView::~PasswordAutoSignInView() = default;
PasswordAutoSignInView::PasswordAutoSignInView(
content::WebContents* web_contents,
views::View* anchor_view,
DisplayReason reason)
views::View* anchor_view)
: PasswordBubbleViewBase(web_contents,
anchor_view,
reason,
/*easily_dismissable=*/false),
controller_(PasswordsModelDelegateFromWebContents(web_contents)) {
SetLayoutManager(std::make_unique<views::FillLayout>());
......
......@@ -19,8 +19,7 @@ class PasswordAutoSignInView : public PasswordBubbleViewBase,
public views::ButtonListener {
public:
PasswordAutoSignInView(content::WebContents* web_contents,
views::View* anchor_view,
DisplayReason reason);
views::View* anchor_view);
#if defined(UNIT_TEST)
static void set_auto_signin_toast_timeout(int seconds) {
......
......@@ -62,9 +62,9 @@ PasswordBubbleViewBase* PasswordBubbleViewBase::CreateBubble(
password_manager::ui::State model_state =
PasswordsModelDelegateFromWebContents(web_contents)->GetState();
if (model_state == password_manager::ui::MANAGE_STATE) {
view = new PasswordItemsView(web_contents, anchor_view, reason);
view = new PasswordItemsView(web_contents, anchor_view);
} else if (model_state == password_manager::ui::AUTO_SIGNIN_STATE) {
view = new PasswordAutoSignInView(web_contents, anchor_view, reason);
view = new PasswordAutoSignInView(web_contents, anchor_view);
} else if (model_state == password_manager::ui::CONFIRMATION_STATE) {
view = new PasswordGenerationConfirmationView(web_contents, anchor_view,
reason);
......@@ -95,56 +95,30 @@ void PasswordBubbleViewBase::ActivateBubble() {
const content::WebContents* PasswordBubbleViewBase::GetWebContents() const {
const PasswordBubbleControllerBase* controller = GetController();
if (controller) {
DCHECK(controller);
return controller->GetWebContents();
}
DCHECK(model_);
return model_->GetWebContents();
}
base::string16 PasswordBubbleViewBase::GetWindowTitle() const {
const PasswordBubbleControllerBase* controller = GetController();
if (controller) {
DCHECK(controller);
return controller->GetTitle();
}
DCHECK(model_);
return model_->title();
}
bool PasswordBubbleViewBase::ShouldShowWindowTitle() const {
const PasswordBubbleControllerBase* controller = GetController();
if (controller) {
DCHECK(controller);
return !controller->GetTitle().empty();
}
DCHECK(model_);
return !model_->title().empty();
}
PasswordBubbleViewBase::PasswordBubbleViewBase(
content::WebContents* web_contents,
views::View* anchor_view,
DisplayReason reason,
bool easily_dismissable)
: LocationBarBubbleDelegateView(anchor_view, web_contents) {
base::WeakPtr<PasswordsModelDelegate> delegate =
PasswordsModelDelegateFromWebContents(web_contents);
// Create the model only for the states that hasn't been migrated to using the
// bubble controllers.
if (delegate->GetState() != password_manager::ui::AUTO_SIGNIN_STATE &&
delegate->GetState() != password_manager::ui::CONFIRMATION_STATE &&
delegate->GetState() != password_manager::ui::MANAGE_STATE &&
delegate->GetState() != password_manager::ui::PENDING_PASSWORD_STATE &&
delegate->GetState() !=
password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) {
model_ = std::make_unique<ManagePasswordsBubbleModel>(
delegate, reason == AUTOMATIC
? ManagePasswordsBubbleModel::AUTOMATIC
: ManagePasswordsBubbleModel::USER_ACTION);
}
// The |mouse_handler| closes the bubble if a keyboard or mouse
// interactions happens outside of the bubble. By this the bubble becomes
// 'easily-dissmisable' and this behavior can be enforced by the
// 'easily-dismissable' and this behavior can be enforced by the
// corresponding flag.
if (easily_dismissable) {
mouse_handler_ =
......@@ -168,10 +142,6 @@ void PasswordBubbleViewBase::OnWidgetClosing(views::Widget* widget) {
// Therefore, we reset the model early (before the bubble destructor) to get
// the following sequence of events [open1, close1, open2, close2].
PasswordBubbleControllerBase* controller = GetController();
if (controller) {
DCHECK(controller);
controller->OnBubbleClosing();
return;
}
DCHECK(model_);
model_->OnBubbleClosing();
}
......@@ -9,7 +9,6 @@
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view.h"
namespace content {
......@@ -62,16 +61,11 @@ class PasswordBubbleViewBase : public LocationBarBubbleDelegateView {
base::string16 GetWindowTitle() const override;
bool ShouldShowWindowTitle() const override;
// These model-accessor methods are public for testing.
ManagePasswordsBubbleModel* model() { return model_.get(); }
const ManagePasswordsBubbleModel* model() const { return model_.get(); }
protected:
// The |easily_dismissable| flag indicates if the bubble should close upon
// a click in the content area of the browser.
PasswordBubbleViewBase(content::WebContents* web_contents,
views::View* anchor_view,
DisplayReason reason,
bool easily_dismissable);
~PasswordBubbleViewBase() override;
......@@ -84,8 +78,6 @@ class PasswordBubbleViewBase : public LocationBarBubbleDelegateView {
// Bubble and will be deleted when the bubble closes.
static PasswordBubbleViewBase* g_manage_passwords_bubble_;
std::unique_ptr<ManagePasswordsBubbleModel> model_;
// Listens for WebContentsView events and closes the bubble so the bubble gets
// dismissed when users keep using the web page.
std::unique_ptr<WebContentMouseHandler> mouse_handler_;
......
......@@ -22,12 +22,12 @@ PasswordGenerationConfirmationView::PasswordGenerationConfirmationView(
DisplayReason reason)
: PasswordBubbleViewBase(web_contents,
anchor_view,
reason,
/*auto_dismissable=*/false),
controller_(PasswordsModelDelegateFromWebContents(web_contents),
controller_(
PasswordsModelDelegateFromWebContents(web_contents),
reason == AUTOMATIC
? ManagePasswordsBubbleModel::AUTOMATIC
: ManagePasswordsBubbleModel::USER_ACTION) {
? PasswordBubbleControllerBase::DisplayReason::kAutomatic
: PasswordBubbleControllerBase::DisplayReason::kUserAction) {
SetLayoutManager(std::make_unique<views::FillLayout>());
DialogDelegate::set_buttons(ui::DIALOG_BUTTON_NONE);
......
......@@ -11,7 +11,6 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
......@@ -237,16 +236,15 @@ void PasswordItemsView::PasswordRow::ButtonPressed(views::Button* sender,
DCHECK(sender->tag() == kDeleteButtonTag || sender->tag() == kUndoButtonTag);
deleted_ = sender->tag() == kDeleteButtonTag;
parent_->NotifyPasswordFormAction(
*password_form_, deleted_ ? ManagePasswordsBubbleModel::REMOVE_PASSWORD
: ManagePasswordsBubbleModel::ADD_PASSWORD);
*password_form_,
deleted_ ? PasswordBubbleControllerBase::PasswordAction::kRemovePassword
: PasswordBubbleControllerBase::PasswordAction::kAddPassword);
}
PasswordItemsView::PasswordItemsView(content::WebContents* web_contents,
views::View* anchor_view,
DisplayReason reason)
views::View* anchor_view)
: PasswordBubbleViewBase(web_contents,
anchor_view,
reason,
/*easily_dismissable=*/true),
controller_(PasswordsModelDelegateFromWebContents(web_contents)) {
DialogDelegate::set_buttons(ui::DIALOG_BUTTON_OK);
......@@ -305,7 +303,7 @@ void PasswordItemsView::RecreateLayout() {
void PasswordItemsView::NotifyPasswordFormAction(
const autofill::PasswordForm& password_form,
ManagePasswordsBubbleModel::PasswordAction action) {
PasswordBubbleControllerBase::PasswordAction action) {
RecreateLayout();
// After the view is consistent, notify the model that the password needs to
// be updated (either removed or put back into the store, as appropriate.
......
......@@ -10,7 +10,6 @@
#include "base/macros.h"
#include "chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/views/passwords/password_bubble_view_base.h"
#include "components/autofill/core/common/password_form.h"
#include "ui/views/controls/button/button.h"
......@@ -38,8 +37,7 @@ class PasswordItemsView : public PasswordBubbleViewBase,
public views::ButtonListener {
public:
PasswordItemsView(content::WebContents* web_contents,
views::View* anchor_view,
DisplayReason reason);
views::View* anchor_view);
~PasswordItemsView() override;
private:
......@@ -51,7 +49,7 @@ class PasswordItemsView : public PasswordBubbleViewBase,
void NotifyPasswordFormAction(
const autofill::PasswordForm& password_form,
ManagePasswordsBubbleModel::PasswordAction action);
PasswordBubbleControllerBase::PasswordAction action);
void RecreateLayout();
// LocationBarBubbleDelegateView:
......
......@@ -252,15 +252,16 @@ PasswordPendingView::PasswordPendingView(content::WebContents* web_contents,
DisplayReason reason)
: PasswordBubbleViewBase(web_contents,
anchor_view,
reason,
/*auto_dismissable=*/false),
controller_(PasswordsModelDelegateFromWebContents(web_contents),
controller_(
PasswordsModelDelegateFromWebContents(web_contents),
reason == AUTOMATIC
? ManagePasswordsBubbleModel::AUTOMATIC
: ManagePasswordsBubbleModel::USER_ACTION),
? PasswordBubbleControllerBase::DisplayReason::kAutomatic
: PasswordBubbleControllerBase::DisplayReason::kUserAction),
is_update_bubble_(controller_.state() ==
password_manager::ui::PENDING_PASSWORD_UPDATE_STATE),
sign_in_promo_(nullptr),
username_dropdown_(nullptr),
password_view_button_(nullptr),
password_dropdown_(nullptr),
......
......@@ -8,7 +8,6 @@
#include <utility>
#include "build/build_config.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/views/collected_cookies_views.h"
#include "chrome/browser/ui/views/hung_renderer_view.h"
#include "chrome/browser/ui/views/passwords/password_bubble_view_base.h"
......@@ -32,8 +31,7 @@ TabDialogsViews::TabDialogsViews(content::WebContents* contents)
DCHECK(contents);
}
TabDialogsViews::~TabDialogsViews() {
}
TabDialogsViews::~TabDialogsViews() = default;
gfx::NativeView TabDialogsViews::GetDialogParentView() const {
return web_contents_->GetNativeView();
......
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