Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1220)

Unified Diff: chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc

Issue 1020013003: Add a regression test for the CardUnmaskPrompt. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git add Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc
diff --git a/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc b/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc
index f6487bfc3bc6b505e562a511af166cb7fc79574a..bdb01c149822ed88caa50d741215708ba9729fa2 100644
--- a/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc
+++ b/chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/ui/views/autofill/card_unmask_prompt_views.h"
+
#include "base/basictypes.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/ui/autofill/autofill_dialog_models.h"
#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
#include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h"
-#include "chrome/browser/ui/autofill/card_unmask_prompt_view.h"
#include "chrome/browser/ui/views/autofill/decorated_textfield.h"
#include "chrome/browser/ui/views/autofill/tooltip_icon.h"
#include "chrome/grit/generated_resources.h"
@@ -22,19 +22,14 @@
#include "ui/views/background.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/combobox/combobox.h"
-#include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
-#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_client_view.h"
-#include "ui/views/window/dialog_delegate.h"
namespace autofill {
-namespace {
-
// The number of pixels of blank space on the outer horizontal edges of the
// dialog.
const int kEdgePadding = 19;
@@ -43,55 +38,61 @@ const int kEdgePadding = 19;
SkColor kShadingColor = SkColorSetARGB(7, 0, 0, 0);
SkColor kSubtleBorderColor = SkColorSetARGB(10, 0, 0, 0);
-class CardUnmaskPromptViews : public CardUnmaskPromptView,
- views::ComboboxListener,
- views::DialogDelegateView,
- views::TextfieldController {
- public:
- explicit CardUnmaskPromptViews(CardUnmaskPromptController* controller)
- : controller_(controller),
- main_contents_(nullptr),
- permanent_error_label_(nullptr),
- cvc_input_(nullptr),
- month_input_(nullptr),
- year_input_(nullptr),
- error_label_(nullptr),
- storage_checkbox_(nullptr),
- progress_overlay_(nullptr),
- progress_label_(nullptr) {}
-
- ~CardUnmaskPromptViews() override {
+// static
+CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow(
+ CardUnmaskPromptController* controller) {
+ CardUnmaskPromptViews* view = new CardUnmaskPromptViews(controller);
+ view->Show();
+ return view;
+}
+
+CardUnmaskPromptViews::CardUnmaskPromptViews(
+ CardUnmaskPromptController* controller)
+ : controller_(controller),
+ main_contents_(nullptr),
+ permanent_error_label_(nullptr),
+ cvc_input_(nullptr),
+ month_input_(nullptr),
+ year_input_(nullptr),
+ error_label_(nullptr),
+ storage_checkbox_(nullptr),
+ progress_overlay_(nullptr),
+ progress_label_(nullptr),
+ weak_ptr_factory_(this) {
+}
+
+CardUnmaskPromptViews::~CardUnmaskPromptViews() {
if (controller_)
controller_->OnUnmaskDialogClosed();
}
- void Show() {
+ void CardUnmaskPromptViews::Show() {
constrained_window::ShowWebModalDialogViews(this,
controller_->GetWebContents());
}
- // CardUnmaskPromptView
- void ControllerGone() override {
+ void CardUnmaskPromptViews::ControllerGone() {
controller_ = nullptr;
ClosePrompt();
}
- void DisableAndWaitForVerification() override {
+ void CardUnmaskPromptViews::DisableAndWaitForVerification() {
SetInputsEnabled(false);
progress_overlay_->SetVisible(true);
GetDialogClientView()->UpdateDialogButtons();
Layout();
}
- void GotVerificationResult(const base::string16& error_message,
- bool allow_retry) override {
+ void CardUnmaskPromptViews::GotVerificationResult(
+ const base::string16& error_message,
+ bool allow_retry) {
if (error_message.empty()) {
progress_label_->SetText(l10n_util::GetStringUTF16(
IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS));
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE, base::Bind(&CardUnmaskPromptViews::ClosePrompt,
- base::Unretained(this)),
- base::TimeDelta::FromSeconds(1));
+ weak_ptr_factory_.GetWeakPtr()),
+ controller_->GetSuccessMessageDuration());
} else {
// TODO(estade): it's somewhat jarring when the error comes back too
// quickly.
@@ -119,7 +120,8 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
Layout();
}
- void SetRetriableErrorMessage(const base::string16& message) {
+ void CardUnmaskPromptViews::SetRetriableErrorMessage(
+ const base::string16& message) {
if (message.empty()) {
error_label_->SetMultiLine(false);
error_label_->SetText(base::ASCIIToUTF16(" "));
@@ -139,7 +141,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
}
}
- void SetInputsEnabled(bool enabled) {
+ void CardUnmaskPromptViews::SetInputsEnabled(bool enabled) {
cvc_input_->SetEnabled(enabled);
storage_checkbox_->SetEnabled(enabled);
@@ -149,13 +151,12 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
year_input_->SetEnabled(enabled);
}
- // views::DialogDelegateView
- View* GetContentsView() override {
+ views::View* CardUnmaskPromptViews::GetContentsView() {
InitIfNecessary();
return this;
}
- views::View* CreateFootnoteView() override {
+ views::View* CardUnmaskPromptViews::CreateFootnoteView() {
// Local storage checkbox and (?) tooltip.
views::View* storage_row = new views::View();
views::BoxLayout* storage_row_layout = new views::BoxLayout(
@@ -178,8 +179,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
return storage_row;
}
- // views::View
- gfx::Size GetPreferredSize() const override {
+ gfx::Size CardUnmaskPromptViews::GetPreferredSize() const {
// Must hardcode a width so the label knows where to wrap. TODO(estade):
// This can lead to a weird looking dialog if we end up getting allocated
// more width than we ask for, e.g. if the title is super long.
@@ -187,13 +187,13 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
return gfx::Size(kWidth, GetHeightForWidth(kWidth));
}
- void Layout() override {
+ void CardUnmaskPromptViews::Layout() {
for (int i = 0; i < child_count(); ++i) {
child_at(i)->SetBoundsRect(GetContentsBounds());
}
}
- int GetHeightForWidth(int width) const override {
+ int CardUnmaskPromptViews::GetHeightForWidth(int width) const {
if (!has_children())
return 0;
const gfx::Insets insets = GetInsets();
@@ -201,7 +201,8 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
insets.height();
}
- void OnNativeThemeChanged(const ui::NativeTheme* theme) override {
+ void CardUnmaskPromptViews::OnNativeThemeChanged(
+ const ui::NativeTheme* theme) {
SkColor bg_color =
theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground);
bg_color = SkColorSetA(bg_color, 0xDD);
@@ -209,28 +210,36 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
views::Background::CreateSolidBackground(bg_color));
}
- ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; }
+ ui::ModalType CardUnmaskPromptViews::GetModalType() const {
+ return ui::MODAL_TYPE_CHILD;
+ }
- base::string16 GetWindowTitle() const override {
+ base::string16 CardUnmaskPromptViews::GetWindowTitle() const {
return controller_->GetWindowTitle();
}
- void DeleteDelegate() override { delete this; }
+ void CardUnmaskPromptViews::DeleteDelegate() {
+ delete this;
+ }
- int GetDialogButtons() const override {
+ int CardUnmaskPromptViews::GetDialogButtons() const {
return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
}
- base::string16 GetDialogButtonLabel(ui::DialogButton button) const override {
+ base::string16 CardUnmaskPromptViews::GetDialogButtonLabel(
+ ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_OK)
return l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_CONFIRM_BUTTON);
return DialogDelegateView::GetDialogButtonLabel(button);
}
- bool ShouldDefaultButtonBeBlue() const override { return true; }
+ bool CardUnmaskPromptViews::ShouldDefaultButtonBeBlue() const {
+ return true;
+ }
- bool IsDialogButtonEnabled(ui::DialogButton button) const override {
+ bool CardUnmaskPromptViews::IsDialogButtonEnabled(
+ ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_CANCEL)
return true;
@@ -241,13 +250,15 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
ExpirationDateIsValid();
}
- views::View* GetInitiallyFocusedView() override { return cvc_input_; }
+ views::View* CardUnmaskPromptViews::GetInitiallyFocusedView() {
+ return cvc_input_;
+ }
- bool Cancel() override {
+ bool CardUnmaskPromptViews::Cancel() {
return true;
}
- bool Accept() override {
+ bool CardUnmaskPromptViews::Accept() {
if (!controller_)
return true;
@@ -262,17 +273,16 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
return false;
}
- // views::TextfieldController
- void ContentsChanged(views::Textfield* sender,
- const base::string16& new_contents) override {
+ void CardUnmaskPromptViews::ContentsChanged(
+ views::Textfield* sender,
+ const base::string16& new_contents) {
if (controller_->InputCvcIsValid(new_contents))
cvc_input_->SetInvalid(false);
GetDialogClientView()->UpdateDialogButtons();
}
- // views::ComboboxListener
- void OnPerformAction(views::Combobox* combobox) override {
+ void CardUnmaskPromptViews::OnPerformAction(views::Combobox* combobox) {
if (ExpirationDateIsValid()) {
if (month_input_->invalid()) {
month_input_->SetInvalid(false);
@@ -294,8 +304,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
GetDialogClientView()->UpdateDialogButtons();
}
- private:
- void InitIfNecessary() {
+ void CardUnmaskPromptViews::InitIfNecessary() {
if (has_children())
return;
@@ -384,9 +393,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
progress_overlay_->AddChildView(progress_label_);
}
- void ClosePrompt() { GetWidget()->Close(); }
-
- bool ExpirationDateIsValid() const {
+ bool CardUnmaskPromptViews::ExpirationDateIsValid() const {
if (!controller_->ShouldRequestExpirationDate())
return true;
@@ -395,41 +402,8 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
year_input_->GetTextForRow(year_input_->selected_index()));
}
- CardUnmaskPromptController* controller_;
-
- views::View* main_contents_;
-
- // The error label for permanent errors (where the user can't retry).
- views::Label* permanent_error_label_;
-
- DecoratedTextfield* cvc_input_;
-
- // These will be null when expiration date is not required.
- views::Combobox* month_input_;
- views::Combobox* year_input_;
-
- MonthComboboxModel month_combobox_model_;
- YearComboboxModel year_combobox_model_;
-
- // The error label for most errors, which lives beneath the inputs.
- views::Label* error_label_;
-
- views::Checkbox* storage_checkbox_;
-
- views::View* progress_overlay_;
- views::Label* progress_label_;
-
- DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViews);
-};
-
-} // namespace
-
-// static
-CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow(
- CardUnmaskPromptController* controller) {
- CardUnmaskPromptViews* view = new CardUnmaskPromptViews(controller);
- view->Show();
- return view;
-}
+ void CardUnmaskPromptViews::ClosePrompt() {
+ GetWidget()->Close();
+ }
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698