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

Side by Side Diff: chrome/browser/ui/views/autofill/card_unmask_prompt_views.cc

Issue 969223002: Autofill wallet -- handle several classes of error in unmasking prompt. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: local 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 7 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
8 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" 8 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
9 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" 9 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h"
10 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h"
11 #include "chrome/browser/ui/views/autofill/decorated_textfield.h" 11 #include "chrome/browser/ui/views/autofill/decorated_textfield.h"
12 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
13 #include "components/constrained_window/constrained_window_views.h" 13 #include "components/constrained_window/constrained_window_views.h"
14 #include "components/web_modal/web_contents_modal_dialog_host.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager.h"
16 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
14 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
15 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/views/background.h" 21 #include "ui/views/background.h"
19 #include "ui/views/controls/button/checkbox.h" 22 #include "ui/views/controls/button/checkbox.h"
20 #include "ui/views/controls/combobox/combobox.h" 23 #include "ui/views/controls/combobox/combobox.h"
21 #include "ui/views/controls/combobox/combobox_listener.h" 24 #include "ui/views/controls/combobox/combobox_listener.h"
22 #include "ui/views/controls/image_view.h" 25 #include "ui/views/controls/image_view.h"
23 #include "ui/views/controls/label.h" 26 #include "ui/views/controls/label.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 ClosePrompt(); 66 ClosePrompt();
64 } 67 }
65 68
66 void DisableAndWaitForVerification() override { 69 void DisableAndWaitForVerification() override {
67 SetInputsEnabled(false); 70 SetInputsEnabled(false);
68 progress_overlay_->SetVisible(true); 71 progress_overlay_->SetVisible(true);
69 GetDialogClientView()->UpdateDialogButtons(); 72 GetDialogClientView()->UpdateDialogButtons();
70 Layout(); 73 Layout();
71 } 74 }
72 75
73 void GotVerificationResult(bool success) override { 76 void GotVerificationResult(const base::string16& error_message,
74 if (success) { 77 bool allow_retry) override {
78 if (!error_message.empty()) {
75 progress_label_->SetText(base::ASCIIToUTF16("Success!")); 79 progress_label_->SetText(base::ASCIIToUTF16("Success!"));
76 base::MessageLoop::current()->PostDelayedTask( 80 base::MessageLoop::current()->PostDelayedTask(
77 FROM_HERE, base::Bind(&CardUnmaskPromptViews::ClosePrompt, 81 FROM_HERE, base::Bind(&CardUnmaskPromptViews::ClosePrompt,
78 base::Unretained(this)), 82 base::Unretained(this)),
79 base::TimeDelta::FromSeconds(1)); 83 base::TimeDelta::FromSeconds(1));
80 } else { 84 } else {
81 SetInputsEnabled(true); 85 SetInputsEnabled(allow_retry);
82 SetInputsInvalid(true); 86
87 // If there is more than one input showing, don't mark anything as invalid
88 // since we don't know the location of the problem.
89 if (controller_->ShouldRequestExpirationDate())
90 cvc_input_->SetInvalid(true);
91
83 // TODO(estade): it's somewhat jarring when the error comes back too 92 // TODO(estade): it's somewhat jarring when the error comes back too
84 // quickly. 93 // quickly.
85 progress_overlay_->SetVisible(false); 94 progress_overlay_->SetVisible(false);
86 // TODO(estade): When do we hide |error_label_|? 95 // TODO(estade): When do we hide |error_label_|?
87 error_label_->SetText( 96 error_label_->SetMultiLine(true);
88 base::ASCIIToUTF16("Verification error. Please try again.")); 97 error_label_->SetText(error_message);
98
99 // Update the dialog's size, which may change depending on
100 // |error_message|.
101 if (GetWidget() && controller_->GetWebContents()) {
102 constrained_window::UpdateWebContentsModalDialogPosition(
103 GetWidget(),
104 web_modal::WebContentsModalDialogManager::FromWebContents(
105 controller_->GetWebContents())
106 ->delegate()
107 ->GetWebContentsModalDialogHost());
108 }
89 GetDialogClientView()->UpdateDialogButtons(); 109 GetDialogClientView()->UpdateDialogButtons();
90 } 110 }
111
91 Layout(); 112 Layout();
92 } 113 }
93 114
94 void SetInputsEnabled(bool enabled) { 115 void SetInputsEnabled(bool enabled) {
95 cvc_input_->SetEnabled(enabled); 116 cvc_input_->SetEnabled(enabled);
117 storage_checkbox_->SetEnabled(enabled);
96 118
97 if (month_input_) 119 if (month_input_)
98 month_input_->SetEnabled(enabled); 120 month_input_->SetEnabled(enabled);
99 if (year_input_) 121 if (year_input_)
100 year_input_->SetEnabled(enabled); 122 year_input_->SetEnabled(enabled);
101 } 123 }
102 124
103 void SetInputsInvalid(bool invalid) {
104 cvc_input_->SetInvalid(invalid);
105
106 if (month_input_)
107 month_input_->SetInvalid(invalid);
108 if (year_input_)
109 year_input_->SetInvalid(invalid);
110 }
111
112 // views::DialogDelegateView 125 // views::DialogDelegateView
113 View* GetContentsView() override { 126 View* GetContentsView() override {
114 InitIfNecessary(); 127 InitIfNecessary();
115 return this; 128 return this;
116 } 129 }
117 130
118 // views::View 131 // views::View
119 gfx::Size GetPreferredSize() const override { 132 gfx::Size GetPreferredSize() const override {
120 // Must hardcode a width so the label knows where to wrap. TODO(estade): 133 // Must hardcode a width so the label knows where to wrap. TODO(estade):
121 // This can lead to a weird looking dialog if we end up getting allocated 134 // This can lead to a weird looking dialog if we end up getting allocated
122 // more width than we ask for, e.g. if the title is super long. 135 // more width than we ask for, e.g. if the title is super long.
123 const int kWidth = 250; 136 const int kWidth = 450;
124 return gfx::Size(kWidth, GetHeightForWidth(kWidth)); 137 return gfx::Size(kWidth, GetHeightForWidth(kWidth));
125 } 138 }
126 139
127 void Layout() override { 140 void Layout() override {
128 for (int i = 0; i < child_count(); ++i) { 141 for (int i = 0; i < child_count(); ++i) {
129 child_at(i)->SetBoundsRect(GetContentsBounds()); 142 child_at(i)->SetBoundsRect(GetContentsBounds());
130 } 143 }
131 } 144 }
132 145
133 int GetHeightForWidth(int width) const override { 146 int GetHeightForWidth(int width) const override {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 year_input_ 215 year_input_
203 ? year_combobox_model_.GetItemAt(year_input_->selected_index()) 216 ? year_combobox_model_.GetItemAt(year_input_->selected_index())
204 : base::string16(), 217 : base::string16(),
205 storage_checkbox_ ? storage_checkbox_->checked() : false); 218 storage_checkbox_ ? storage_checkbox_->checked() : false);
206 return false; 219 return false;
207 } 220 }
208 221
209 // views::TextfieldController 222 // views::TextfieldController
210 void ContentsChanged(views::Textfield* sender, 223 void ContentsChanged(views::Textfield* sender,
211 const base::string16& new_contents) override { 224 const base::string16& new_contents) override {
212 // Sets all inputs back to valid since we don't know which one was 225 cvc_input_->SetInvalid(false);
213 // actually invalid to begin with.
214 SetInputsInvalid(false);
215 GetDialogClientView()->UpdateDialogButtons(); 226 GetDialogClientView()->UpdateDialogButtons();
216 } 227 }
217 228
218 // views::ComboboxListener 229 // views::ComboboxListener
219 void OnPerformAction(views::Combobox* combobox) override { 230 void OnPerformAction(views::Combobox* combobox) override {
220 // Sets all inputs back to valid since we don't know which one was 231 combobox->SetInvalid(false);
221 // actually invalid to begin with.
222 SetInputsInvalid(false);
223 GetDialogClientView()->UpdateDialogButtons(); 232 GetDialogClientView()->UpdateDialogButtons();
224 } 233 }
225 234
226 private: 235 private:
227 void InitIfNecessary() { 236 void InitIfNecessary() {
228 if (has_children()) 237 if (has_children())
229 return; 238 return;
230 239
231 controls_container_ = new views::View(); 240 controls_container_ = new views::View();
232 controls_container_->SetLayoutManager( 241 controls_container_->SetLayoutManager(
(...skipping 28 matching lines...) Expand all
261 cvc_input_->set_default_width_in_chars(10); 270 cvc_input_->set_default_width_in_chars(10);
262 input_row->AddChildView(cvc_input_); 271 input_row->AddChildView(cvc_input_);
263 272
264 views::ImageView* cvc_image = new views::ImageView(); 273 views::ImageView* cvc_image = new views::ImageView();
265 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 274 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
266 275
267 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid())); 276 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid()));
268 277
269 input_row->AddChildView(cvc_image); 278 input_row->AddChildView(cvc_image);
270 279
271 // Reserve vertical space. 280 // Reserve vertical space for the error label, assuming it's one line.
272 error_label_ = new views::Label(base::ASCIIToUTF16(" ")); 281 error_label_ = new views::Label(base::ASCIIToUTF16(" "));
273 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 282 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
274 error_label_->SetEnabledColor(kWarningColor); 283 error_label_->SetEnabledColor(kWarningColor);
275 controls_container_->AddChildView(error_label_); 284 controls_container_->AddChildView(error_label_);
276 285
277 storage_checkbox_ = new views::Checkbox(l10n_util::GetStringUTF16( 286 storage_checkbox_ = new views::Checkbox(l10n_util::GetStringUTF16(
278 IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_CHECKBOX)); 287 IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_CHECKBOX));
279 storage_checkbox_->SetChecked(controller_->GetStoreLocallyStartState()); 288 storage_checkbox_->SetChecked(controller_->GetStoreLocallyStartState());
280 controls_container_->AddChildView(storage_checkbox_); 289 controls_container_->AddChildView(storage_checkbox_);
281 290
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 333
325 // static 334 // static
326 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( 335 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow(
327 CardUnmaskPromptController* controller) { 336 CardUnmaskPromptController* controller) {
328 CardUnmaskPromptViews* view = new CardUnmaskPromptViews(controller); 337 CardUnmaskPromptViews* view = new CardUnmaskPromptViews(controller);
329 view->Show(); 338 view->Show();
330 return view; 339 return view;
331 } 340 }
332 341
333 } // namespace autofill 342 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.mm ('k') | components/autofill/core/browser/autofill_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698