Commit ea923596 authored by estade's avatar estade Committed by Commit bot

Handle re-issued cards in unmasking prompt.

BUG=487866

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

Cr-Commit-Position: refs/heads/master@{#329982}
parent 4f93cf66
...@@ -11278,6 +11278,9 @@ Dead Jim feedback. ...@@ -11278,6 +11278,9 @@ Dead Jim feedback.
<message name="IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR" desc="Separator for a credit card expiration date, e.g. the slash in 05/16." formatter_data="android_java"> <message name="IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR" desc="Separator for a credit card expiration date, e.g. the slash in 05/16." formatter_data="android_java">
/ /
</message> </message>
<message name="IDS_AUTOFILL_CARD_UNMASK_NEW_CARD_LINK" desc="Text for link that prompts user to update their credit card after it may have been re-issued." formatter_data="android_java">
New card?
</message>
<message name="IDS_AUTOFILL_FROM_GOOGLE_ACCOUNT" desc="The name of the Google product that stores user addresses or credit cards in the cloud." formatter_data="android_java"> <message name="IDS_AUTOFILL_FROM_GOOGLE_ACCOUNT" desc="The name of the Google product that stores user addresses or credit cards in the cloud." formatter_data="android_java">
Google Wallet Google Wallet
</message> </message>
...@@ -25,6 +25,7 @@ class CardUnmaskPromptController { ...@@ -25,6 +25,7 @@ class CardUnmaskPromptController {
const base::string16& exp_month, const base::string16& exp_month,
const base::string16& exp_year, const base::string16& exp_year,
bool should_store_pan) = 0; bool should_store_pan) = 0;
virtual void NewCardLinkClicked() = 0;
// State. // State.
virtual content::WebContents* GetWebContents() = 0; virtual content::WebContents* GetWebContents() = 0;
......
...@@ -28,6 +28,7 @@ CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( ...@@ -28,6 +28,7 @@ CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl(
: web_contents_(web_contents), : web_contents_(web_contents),
risk_data_callback_(risk_data_callback), risk_data_callback_(risk_data_callback),
pref_service_(pref_service), pref_service_(pref_service),
new_card_link_clicked_(false),
is_off_the_record_(is_off_the_record), is_off_the_record_(is_off_the_record),
card_unmask_view_(nullptr), card_unmask_view_(nullptr),
unmasking_result_(AutofillClient::NONE), unmasking_result_(AutofillClient::NONE),
...@@ -209,6 +210,10 @@ void CardUnmaskPromptControllerImpl::OnUnmaskResponse( ...@@ -209,6 +210,10 @@ void CardUnmaskPromptControllerImpl::OnUnmaskResponse(
delegate_->OnUnmaskResponse(pending_response_); delegate_->OnUnmaskResponse(pending_response_);
} }
void CardUnmaskPromptControllerImpl::NewCardLinkClicked() {
new_card_link_clicked_ = true;
}
content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() { content::WebContents* CardUnmaskPromptControllerImpl::GetWebContents() {
return web_contents_; return web_contents_;
} }
...@@ -240,7 +245,8 @@ int CardUnmaskPromptControllerImpl::GetCvcImageRid() const { ...@@ -240,7 +245,8 @@ int CardUnmaskPromptControllerImpl::GetCvcImageRid() const {
} }
bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const { bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const {
return card_.GetServerStatus() == CreditCard::EXPIRED; return card_.GetServerStatus() == CreditCard::EXPIRED ||
new_card_link_clicked_;
} }
bool CardUnmaskPromptControllerImpl::CanStoreLocally() const { bool CardUnmaskPromptControllerImpl::CanStoreLocally() const {
......
...@@ -42,7 +42,7 @@ class CardUnmaskPromptControllerImpl : public CardUnmaskPromptController { ...@@ -42,7 +42,7 @@ class CardUnmaskPromptControllerImpl : public CardUnmaskPromptController {
const base::string16& exp_month, const base::string16& exp_month,
const base::string16& exp_year, const base::string16& exp_year,
bool should_store_pan) override; bool should_store_pan) override;
void NewCardLinkClicked() override;
content::WebContents* GetWebContents() override; content::WebContents* GetWebContents() override;
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
base::string16 GetInstructionsMessage() const override; base::string16 GetInstructionsMessage() const override;
...@@ -74,6 +74,7 @@ class CardUnmaskPromptControllerImpl : public CardUnmaskPromptController { ...@@ -74,6 +74,7 @@ class CardUnmaskPromptControllerImpl : public CardUnmaskPromptController {
content::WebContents* web_contents_; content::WebContents* web_contents_;
RiskDataCallback risk_data_callback_; RiskDataCallback risk_data_callback_;
PrefService* pref_service_; PrefService* pref_service_;
bool new_card_link_clicked_;
bool is_off_the_record_; bool is_off_the_record_;
CreditCard card_; CreditCard card_;
base::WeakPtr<CardUnmaskDelegate> delegate_; base::WeakPtr<CardUnmaskDelegate> delegate_;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "ui/views/controls/combobox/combobox.h" #include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/throbber.h" #include "ui/views/controls/throbber.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -57,6 +58,7 @@ CardUnmaskPromptViews::CardUnmaskPromptViews( ...@@ -57,6 +58,7 @@ CardUnmaskPromptViews::CardUnmaskPromptViews(
cvc_input_(nullptr), cvc_input_(nullptr),
month_input_(nullptr), month_input_(nullptr),
year_input_(nullptr), year_input_(nullptr),
new_card_link_(nullptr),
error_icon_(nullptr), error_icon_(nullptr),
error_label_(nullptr), error_label_(nullptr),
storage_row_(nullptr), storage_row_(nullptr),
...@@ -116,11 +118,16 @@ void CardUnmaskPromptViews::GotVerificationResult( ...@@ -116,11 +118,16 @@ void CardUnmaskPromptViews::GotVerificationResult(
if (allow_retry) { if (allow_retry) {
SetInputsEnabled(true); SetInputsEnabled(true);
// If there is more than one input showing, don't mark anything as if (!controller_->ShouldRequestExpirationDate()) {
// invalid since we don't know the location of the problem. // If there is more than one input showing, don't mark anything as
if (!controller_->ShouldRequestExpirationDate()) // invalid since we don't know the location of the problem.
cvc_input_->SetInvalid(true); cvc_input_->SetInvalid(true);
// Show a "New card?" link, which when clicked will cause us to ask
// for expiration date.
ShowNewCardLink();
}
// TODO(estade): When do we hide |error_label_|? // TODO(estade): When do we hide |error_label_|?
SetRetriableErrorMessage(error_message); SetRetriableErrorMessage(error_message);
} else { } else {
...@@ -134,6 +141,21 @@ void CardUnmaskPromptViews::GotVerificationResult( ...@@ -134,6 +141,21 @@ void CardUnmaskPromptViews::GotVerificationResult(
Layout(); Layout();
} }
void CardUnmaskPromptViews::LinkClicked(views::Link* source, int event_flags) {
DCHECK_EQ(source, new_card_link_);
controller_->NewCardLinkClicked();
for (int i = 0; i < input_row_->child_count(); ++i)
input_row_->child_at(i)->SetVisible(true);
new_card_link_->SetVisible(false);
input_row_->InvalidateLayout();
cvc_input_->SetInvalid(false);
cvc_input_->SetText(base::string16());
GetDialogClientView()->UpdateDialogButtons();
GetWidget()->UpdateWindowTitle();
SetRetriableErrorMessage(base::string16());
}
void CardUnmaskPromptViews::SetRetriableErrorMessage( void CardUnmaskPromptViews::SetRetriableErrorMessage(
const base::string16& message) { const base::string16& message) {
if (message.empty()) { if (message.empty()) {
...@@ -162,10 +184,20 @@ void CardUnmaskPromptViews::SetInputsEnabled(bool enabled) { ...@@ -162,10 +184,20 @@ void CardUnmaskPromptViews::SetInputsEnabled(bool enabled) {
cvc_input_->SetEnabled(enabled); cvc_input_->SetEnabled(enabled);
if (storage_checkbox_) if (storage_checkbox_)
storage_checkbox_->SetEnabled(enabled); storage_checkbox_->SetEnabled(enabled);
if (month_input_) month_input_->SetEnabled(enabled);
month_input_->SetEnabled(enabled); year_input_->SetEnabled(enabled);
if (year_input_) }
year_input_->SetEnabled(enabled);
void CardUnmaskPromptViews::ShowNewCardLink() {
if (new_card_link_)
return;
new_card_link_ = new views::Link(
l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_NEW_CARD_LINK));
new_card_link_->SetBorder(views::Border::CreateEmptyBorder(0, 7, 0, 0));
new_card_link_->SetUnderline(false);
new_card_link_->set_listener(this);
input_row_->AddChildView(new_card_link_);
} }
views::View* CardUnmaskPromptViews::GetContentsView() { views::View* CardUnmaskPromptViews::GetContentsView() {
...@@ -290,10 +322,12 @@ bool CardUnmaskPromptViews::Accept() { ...@@ -290,10 +322,12 @@ bool CardUnmaskPromptViews::Accept() {
controller_->OnUnmaskResponse( controller_->OnUnmaskResponse(
cvc_input_->text(), cvc_input_->text(),
month_input_ ? month_input_->GetTextForRow(month_input_->selected_index()) month_input_->visible()
: base::string16(), ? month_input_->GetTextForRow(month_input_->selected_index())
year_input_ ? year_input_->GetTextForRow(year_input_->selected_index()) : base::string16(),
: base::string16(), year_input_->visible()
? year_input_->GetTextForRow(year_input_->selected_index())
: base::string16(),
storage_checkbox_ ? storage_checkbox_->checked() : false); storage_checkbox_ ? storage_checkbox_->checked() : false);
return false; return false;
} }
...@@ -377,18 +411,21 @@ void CardUnmaskPromptViews::InitIfNecessary() { ...@@ -377,18 +411,21 @@ void CardUnmaskPromptViews::InitIfNecessary() {
new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5)); new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5));
controls_container->AddChildView(input_row_); controls_container->AddChildView(input_row_);
if (controller_->ShouldRequestExpirationDate()) { month_input_ = new views::Combobox(&month_combobox_model_);
month_input_ = new views::Combobox(&month_combobox_model_); month_input_->set_listener(this);
month_input_->set_listener(this); input_row_->AddChildView(month_input_);
input_row_->AddChildView(month_input_); views::Label* separator = new views::Label(l10n_util::GetStringUTF16(
views::Label* separator = new views::Label(l10n_util::GetStringUTF16( IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR));
IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_DATE_SEPARATOR)); separator->SetEnabledColor(kGreyTextColor);
separator->SetEnabledColor(kGreyTextColor); input_row_->AddChildView(separator);
input_row_->AddChildView(separator); year_input_ = new views::Combobox(&year_combobox_model_);
year_input_ = new views::Combobox(&year_combobox_model_); year_input_->set_listener(this);
year_input_->set_listener(this); input_row_->AddChildView(year_input_);
input_row_->AddChildView(year_input_); input_row_->AddChildView(new views::Label(base::ASCIIToUTF16(" ")));
input_row_->AddChildView(new views::Label(base::ASCIIToUTF16(" "))); // Hide all of the above as appropriate.
if (!controller_->ShouldRequestExpirationDate()) {
for (int i = 0; i < input_row_->child_count(); ++i)
input_row_->child_at(i)->SetVisible(false);
} }
cvc_input_ = new DecoratedTextfield( cvc_input_ = new DecoratedTextfield(
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ui/gfx/animation/animation_delegate.h" #include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h" #include "ui/gfx/animation/slide_animation.h"
#include "ui/views/controls/combobox/combobox_listener.h" #include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/controls/link_listener.h"
#include "ui/views/controls/textfield/textfield_controller.h" #include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/window/dialog_delegate.h"
...@@ -17,6 +18,7 @@ namespace views { ...@@ -17,6 +18,7 @@ namespace views {
class Checkbox; class Checkbox;
class ImageView; class ImageView;
class Label; class Label;
class Link;
class Throbber; class Throbber;
} }
...@@ -28,6 +30,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView, ...@@ -28,6 +30,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
views::ComboboxListener, views::ComboboxListener,
views::DialogDelegateView, views::DialogDelegateView,
views::TextfieldController, views::TextfieldController,
views::LinkListener,
gfx::AnimationDelegate { gfx::AnimationDelegate {
public: public:
explicit CardUnmaskPromptViews(CardUnmaskPromptController* controller); explicit CardUnmaskPromptViews(CardUnmaskPromptController* controller);
...@@ -65,9 +68,13 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView, ...@@ -65,9 +68,13 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
// views::TextfieldController // views::TextfieldController
void ContentsChanged(views::Textfield* sender, void ContentsChanged(views::Textfield* sender,
const base::string16& new_contents) override; const base::string16& new_contents) override;
// views::ComboboxListener // views::ComboboxListener
void OnPerformAction(views::Combobox* combobox) override; void OnPerformAction(views::Combobox* combobox) override;
// views::LinkListener
void LinkClicked(views::Link* source, int event_flags) override;
// gfx::AnimationDelegate // gfx::AnimationDelegate
void AnimationProgressed(const gfx::Animation* animation) override; void AnimationProgressed(const gfx::Animation* animation) override;
...@@ -106,6 +113,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView, ...@@ -106,6 +113,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
void SetRetriableErrorMessage(const base::string16& message); void SetRetriableErrorMessage(const base::string16& message);
bool ExpirationDateIsValid() const; bool ExpirationDateIsValid() const;
void SetInputsEnabled(bool enabled); void SetInputsEnabled(bool enabled);
void ShowNewCardLink();
void ClosePrompt(); void ClosePrompt();
CardUnmaskPromptController* controller_; CardUnmaskPromptController* controller_;
...@@ -120,13 +128,14 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView, ...@@ -120,13 +128,14 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
DecoratedTextfield* cvc_input_; DecoratedTextfield* cvc_input_;
// These will be null when expiration date is not required.
views::Combobox* month_input_; views::Combobox* month_input_;
views::Combobox* year_input_; views::Combobox* year_input_;
MonthComboboxModel month_combobox_model_; MonthComboboxModel month_combobox_model_;
YearComboboxModel year_combobox_model_; YearComboboxModel year_combobox_model_;
views::Link* new_card_link_;
// The error icon and label for most errors, which live beneath the inputs. // The error icon and label for most errors, which live beneath the inputs.
views::ImageView* error_icon_; views::ImageView* error_icon_;
views::Label* error_label_; views::Label* error_label_;
......
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