Commit e891c323 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

cbuiv payments: remove two GetDialogButtons overrides

This makes it hopefully more clear which events can cause the dialog
buttons to change visibility. For CardUnmaskPromptViews, whether the Ok
button is visible or not depends on whether the autofill client is in a
persistent error state. For LocalCardMigrationDialogView, the existing
code never calls DialogModelChanged, so presumably the value of
`controller_->AllCardsInvalid()` is constant across the lifetime of that
dialog.

Bug: 1011446
Change-Id: I5921f086b3078e68aa417945560ad73a357fe190
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067874Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744659}
parent 972423dd
...@@ -89,7 +89,7 @@ CardUnmaskPromptViews::CardUnmaskPromptViews( ...@@ -89,7 +89,7 @@ CardUnmaskPromptViews::CardUnmaskPromptViews(
CreateSaveCheckbox(controller_->GetStoreLocallyStartState())); CreateSaveCheckbox(controller_->GetStoreLocallyStartState()));
} }
UpdateButtonLabels(); UpdateButtons();
} }
CardUnmaskPromptViews::~CardUnmaskPromptViews() { CardUnmaskPromptViews::~CardUnmaskPromptViews() {
...@@ -111,7 +111,7 @@ void CardUnmaskPromptViews::DisableAndWaitForVerification() { ...@@ -111,7 +111,7 @@ void CardUnmaskPromptViews::DisableAndWaitForVerification() {
controls_container_->SetVisible(false); controls_container_->SetVisible(false);
overlay_->SetVisible(true); overlay_->SetVisible(true);
progress_throbber_->Start(); progress_throbber_->Start();
UpdateButtonLabels(); UpdateButtons();
DialogModelChanged(); DialogModelChanged();
Layout(); Layout();
} }
...@@ -173,7 +173,7 @@ void CardUnmaskPromptViews::GotVerificationResult( ...@@ -173,7 +173,7 @@ void CardUnmaskPromptViews::GotVerificationResult(
layout->AddView(std::move(error_icon)); layout->AddView(std::move(error_icon));
layout->AddView(std::move(error_label)); layout->AddView(std::move(error_label));
} }
UpdateButtonLabels(); UpdateButtons();
DialogModelChanged(); DialogModelChanged();
} }
...@@ -261,18 +261,6 @@ void CardUnmaskPromptViews::DeleteDelegate() { ...@@ -261,18 +261,6 @@ void CardUnmaskPromptViews::DeleteDelegate() {
delete this; delete this;
} }
int CardUnmaskPromptViews::GetDialogButtons() const {
// In permanent error state, only the "close" button is shown.
AutofillClient::PaymentsRpcResult result =
controller_->GetVerificationResult();
if (result == AutofillClient::PERMANENT_FAILURE ||
result == AutofillClient::NETWORK_ERROR) {
return ui::DIALOG_BUTTON_CANCEL;
}
return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
}
bool CardUnmaskPromptViews::IsDialogButtonEnabled( bool CardUnmaskPromptViews::IsDialogButtonEnabled(
ui::DialogButton button) const { ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_CANCEL) if (button == ui::DIALOG_BUTTON_CANCEL)
...@@ -320,7 +308,7 @@ void CardUnmaskPromptViews::ContentsChanged( ...@@ -320,7 +308,7 @@ void CardUnmaskPromptViews::ContentsChanged(
if (controller_->InputCvcIsValid(new_contents)) if (controller_->InputCvcIsValid(new_contents))
cvc_input_->SetInvalid(false); cvc_input_->SetInvalid(false);
UpdateButtonLabels(); UpdateButtons();
DialogModelChanged(); DialogModelChanged();
} }
...@@ -341,7 +329,7 @@ void CardUnmaskPromptViews::OnPerformAction(views::Combobox* combobox) { ...@@ -341,7 +329,7 @@ void CardUnmaskPromptViews::OnPerformAction(views::Combobox* combobox) {
IDS_AUTOFILL_CARD_UNMASK_INVALID_EXPIRATION_DATE)); IDS_AUTOFILL_CARD_UNMASK_INVALID_EXPIRATION_DATE));
} }
UpdateButtonLabels(); UpdateButtons();
DialogModelChanged(); DialogModelChanged();
} }
...@@ -474,7 +462,15 @@ void CardUnmaskPromptViews::ClosePrompt() { ...@@ -474,7 +462,15 @@ void CardUnmaskPromptViews::ClosePrompt() {
GetWidget()->Close(); GetWidget()->Close();
} }
void CardUnmaskPromptViews::UpdateButtonLabels() { void CardUnmaskPromptViews::UpdateButtons() {
// In permanent error state, only the "close" button is shown.
AutofillClient::PaymentsRpcResult result =
controller_->GetVerificationResult();
bool has_ok = result != AutofillClient::PERMANENT_FAILURE &&
result != AutofillClient::NETWORK_ERROR;
DialogDelegate::set_buttons(has_ok ? ui::DIALOG_BUTTON_OK |
ui::DIALOG_BUTTON_CANCEL
: ui::DIALOG_BUTTON_CANCEL);
DialogDelegate::set_button_label(ui::DIALOG_BUTTON_OK, DialogDelegate::set_button_label(ui::DIALOG_BUTTON_OK,
controller_->GetOkButtonLabel()); controller_->GetOkButtonLabel());
} }
...@@ -488,7 +484,7 @@ void CardUnmaskPromptViews::LinkClicked() { ...@@ -488,7 +484,7 @@ void CardUnmaskPromptViews::LinkClicked() {
input_row_->InvalidateLayout(); input_row_->InvalidateLayout();
cvc_input_->SetInvalid(false); cvc_input_->SetInvalid(false);
cvc_input_->SetText(base::string16()); cvc_input_->SetText(base::string16());
UpdateButtonLabels(); UpdateButtons();
DialogModelChanged(); DialogModelChanged();
GetWidget()->UpdateWindowTitle(); GetWidget()->UpdateWindowTitle();
instructions_->SetText(controller_->GetInstructionsMessage()); instructions_->SetText(controller_->GetInstructionsMessage());
......
...@@ -56,7 +56,6 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView, ...@@ -56,7 +56,6 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
void DeleteDelegate() override; void DeleteDelegate() override;
int GetDialogButtons() const override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override; bool IsDialogButtonEnabled(ui::DialogButton button) const override;
View* GetInitiallyFocusedView() override; View* GetInitiallyFocusedView() override;
bool ShouldShowCloseButton() const override; bool ShouldShowCloseButton() const override;
...@@ -80,7 +79,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView, ...@@ -80,7 +79,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
void ShowNewCardLink(); void ShowNewCardLink();
void ClosePrompt(); void ClosePrompt();
void UpdateButtonLabels(); void UpdateButtons();
void LinkClicked(); void LinkClicked();
......
...@@ -351,6 +351,10 @@ LocalCardMigrationDialogView::LocalCardMigrationDialogView( ...@@ -351,6 +351,10 @@ LocalCardMigrationDialogView::LocalCardMigrationDialogView(
LocalCardMigrationDialogController* controller, LocalCardMigrationDialogController* controller,
content::WebContents* web_contents) content::WebContents* web_contents)
: controller_(controller), web_contents_(web_contents) { : controller_(controller), web_contents_(web_contents) {
DialogDelegate::set_buttons(controller_->AllCardsInvalid()
? ui::DIALOG_BUTTON_OK
: ui::DIALOG_BUTTON_OK |
ui::DIALOG_BUTTON_CANCEL);
DialogDelegate::set_button_label(ui::DIALOG_BUTTON_OK, GetOkButtonLabel()); DialogDelegate::set_button_label(ui::DIALOG_BUTTON_OK, GetOkButtonLabel());
DialogDelegate::set_button_label(ui::DIALOG_BUTTON_CANCEL, DialogDelegate::set_button_label(ui::DIALOG_BUTTON_CANCEL,
GetCancelButtonLabel()); GetCancelButtonLabel());
...@@ -394,14 +398,6 @@ bool LocalCardMigrationDialogView::ShouldShowCloseButton() const { ...@@ -394,14 +398,6 @@ bool LocalCardMigrationDialogView::ShouldShowCloseButton() const {
return false; return false;
} }
int LocalCardMigrationDialogView::GetDialogButtons() const {
// Don't show the "View cards" button if all cards are invalid.
if (controller_->AllCardsInvalid())
return ui::DIALOG_BUTTON_OK;
return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
}
// TODO(crbug.com/867194): Update this method when adding feedback. // TODO(crbug.com/867194): Update this method when adding feedback.
bool LocalCardMigrationDialogView::IsDialogButtonEnabled( bool LocalCardMigrationDialogView::IsDialogButtonEnabled(
ui::DialogButton button) const { ui::DialogButton button) const {
......
...@@ -37,7 +37,6 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog, ...@@ -37,7 +37,6 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog,
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
bool ShouldShowCloseButton() const override; bool ShouldShowCloseButton() const override;
int GetDialogButtons() const override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override; bool IsDialogButtonEnabled(ui::DialogButton button) const override;
void WindowClosing() override; void WindowClosing() override;
......
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