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

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

Issue 14425010: Handle expired Autofill credit cards in autofill dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/autofill/autofill_dialog_views.h" 5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 ContentsPreferredSizeChanged(); 832 ContentsPreferredSizeChanged();
833 } 833 }
834 834
835 void AutofillDialogViews::UpdateProgressBar(double value) { 835 void AutofillDialogViews::UpdateProgressBar(double value) {
836 autocheckout_progress_bar_->SetValue(value); 836 autocheckout_progress_bar_->SetValue(value);
837 } 837 }
838 838
839 void AutofillDialogViews::ModelChanged() { 839 void AutofillDialogViews::ModelChanged() {
840 menu_runner_.reset(); 840 menu_runner_.reset();
841 841
842 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 842 for (DetailGroupMap::const_iterator iter = detail_groups_.begin();
843 iter != detail_groups_.end(); ++iter) { 843 iter != detail_groups_.end(); ++iter) {
844 UpdateDetailsGroupState(iter->second); 844 UpdateDetailsGroupState(iter->second);
845 } 845 }
846 } 846 }
847 847
848 TestableAutofillDialogView* AutofillDialogViews::GetTestableView() { 848 TestableAutofillDialogView* AutofillDialogViews::GetTestableView() {
849 return this; 849 return this;
850 } 850 }
851 851
852 void AutofillDialogViews::SubmitForTesting() { 852 void AutofillDialogViews::SubmitForTesting() {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 1058
1059 void AutofillDialogViews::OnDidChangeFocus( 1059 void AutofillDialogViews::OnDidChangeFocus(
1060 views::View* focused_before, 1060 views::View* focused_before,
1061 views::View* focused_now) { 1061 views::View* focused_now) {
1062 if (!focused_before) 1062 if (!focused_before)
1063 return; 1063 return;
1064 1064
1065 // If user leaves an edit-field, revalidate the group it belongs to. 1065 // If user leaves an edit-field, revalidate the group it belongs to.
1066 DetailsGroup* group = GroupForView(focused_before); 1066 DetailsGroup* group = GroupForView(focused_before);
1067 if (group && group->container->visible()) 1067 if (group && group->container->visible())
1068 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT); 1068 ValidateGroup(*group, AutofillDialogController::VALIDATE_EDIT);
1069 } 1069 }
1070 1070
1071 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { 1071 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) {
1072 // Edit links. 1072 // Edit links.
1073 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1073 for (DetailGroupMap::iterator iter = detail_groups_.begin();
1074 iter != detail_groups_.end(); ++iter) { 1074 iter != detail_groups_.end(); ++iter) {
1075 if (iter->second.suggested_info->Contains(source)) { 1075 if (iter->second.suggested_info->Contains(source)) {
1076 controller_->EditClickedForSection(iter->first); 1076 controller_->EditClickedForSection(iter->first);
1077 return; 1077 return;
1078 } 1078 }
1079 } 1079 }
1080 } 1080 }
1081 1081
1082 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) { 1082 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) {
1083 DetailsGroup* group = GroupForView(combobox); 1083 DetailsGroup* group = GroupForView(combobox);
1084 DCHECK(group); 1084 DCHECK(group);
Evan Stade 2013/05/01 21:54:31 no longer need the dcheck since you deref, err, "i
Dan Beam 2013/05/02 00:03:31 Done.
1085 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT); 1085 ValidateGroup(*group, AutofillDialogController::VALIDATE_EDIT);
1086 } 1086 }
1087 1087
1088 void AutofillDialogViews::StyledLabelLinkClicked(const ui::Range& range, 1088 void AutofillDialogViews::StyledLabelLinkClicked(const ui::Range& range,
1089 int event_flags) { 1089 int event_flags) {
1090 controller_->LegalDocumentLinkClicked(range); 1090 controller_->LegalDocumentLinkClicked(range);
1091 } 1091 }
1092 1092
1093 void AutofillDialogViews::InitChildViews() { 1093 void AutofillDialogViews::InitChildViews() {
1094 button_strip_extra_view_ = new views::View(); 1094 button_strip_extra_view_ = new views::View();
1095 button_strip_extra_view_->SetLayoutManager( 1095 button_strip_extra_view_->SetLayoutManager(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 for (int i = 0; i < combobox->model()->GetItemCount(); ++i) { 1333 for (int i = 0; i < combobox->model()->GetItemCount(); ++i) {
1334 if (input.initial_value == combobox->model()->GetItemAt(i)) { 1334 if (input.initial_value == combobox->model()->GetItemAt(i)) {
1335 combobox->SetSelectedIndex(i); 1335 combobox->SetSelectedIndex(i);
1336 break; 1336 break;
1337 } 1337 }
1338 } 1338 }
1339 } 1339 }
1340 } 1340 }
1341 1341
1342 UpdateDetailsGroupState(*group); 1342 UpdateDetailsGroupState(*group);
1343 if (group->container && group->container->visible())
1344 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT);
1345 } 1343 }
1346 1344
1347 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { 1345 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) {
1348 const SuggestionState& suggestion_state = 1346 const SuggestionState& suggestion_state =
1349 controller_->SuggestionStateForSection(group.section); 1347 controller_->SuggestionStateForSection(group.section);
1350 bool show_suggestions = !suggestion_state.text.empty(); 1348 bool show_suggestions = !suggestion_state.text.empty();
1351 group.suggested_info->SetVisible(show_suggestions); 1349 group.suggested_info->SetVisible(show_suggestions);
1352 group.suggested_info->SetSuggestionText(suggestion_state.text, 1350 group.suggested_info->SetSuggestionText(suggestion_state.text,
1353 suggestion_state.text_style); 1351 suggestion_state.text_style);
1354 group.suggested_info->SetSuggestionIcon(suggestion_state.icon); 1352 group.suggested_info->SetSuggestionIcon(suggestion_state.icon);
(...skipping 14 matching lines...) Expand all
1369 1367
1370 const bool has_suggestions = 1368 const bool has_suggestions =
1371 controller_->MenuModelForSection(group.section)->GetItemCount() > 0; 1369 controller_->MenuModelForSection(group.section)->GetItemCount() > 0;
1372 1370
1373 if (group.suggested_button) 1371 if (group.suggested_button)
1374 group.suggested_button->SetVisible(has_suggestions); 1372 group.suggested_button->SetVisible(has_suggestions);
1375 1373
1376 if (group.container) { 1374 if (group.container) {
1377 group.container->SetForwardMouseEvents(has_suggestions && show_suggestions); 1375 group.container->SetForwardMouseEvents(has_suggestions && show_suggestions);
1378 group.container->SetVisible(controller_->SectionIsActive(group.section)); 1376 group.container->SetVisible(controller_->SectionIsActive(group.section));
1377 if (group.container->visible())
1378 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT);
1379 } 1379 }
1380 1380
1381 ContentsPreferredSizeChanged(); 1381 ContentsPreferredSizeChanged();
1382 } 1382 }
1383 1383
1384 bool AutofillDialogViews::ValidateGroup( 1384 bool AutofillDialogViews::ValidateGroup(
1385 DetailsGroup* group, 1385 const DetailsGroup& group,
1386 AutofillDialogController::ValidationType validation_type) { 1386 AutofillDialogController::ValidationType validation_type) {
1387 DCHECK(group->container->visible()); 1387 DCHECK(group.container->visible());
1388 1388
1389 scoped_ptr<DetailInput> cvc_input; 1389 scoped_ptr<DetailInput> cvc_input;
1390 DetailOutputMap detail_outputs; 1390 DetailOutputMap detail_outputs;
1391 std::map<AutofillFieldType, base::Callback<void(bool)> > field_map; 1391 std::map<AutofillFieldType, base::Callback<void(bool)> > field_map;
1392 1392
1393 if (group->manual_input->visible()) { 1393 if (group.manual_input->visible()) {
1394 for (TextfieldMap::iterator iter = group->textfields.begin(); 1394 for (TextfieldMap::const_iterator iter = group.textfields.begin();
1395 iter != group->textfields.end(); ++iter) { 1395 iter != group.textfields.end(); ++iter) {
1396 detail_outputs[iter->first] = iter->second->textfield()->text(); 1396 detail_outputs[iter->first] = iter->second->textfield()->text();
1397 field_map[iter->first->type] = 1397 field_map[iter->first->type] =
1398 base::Bind(&DecoratedTextfield::SetInvalid, 1398 base::Bind(&DecoratedTextfield::SetInvalid,
1399 base::Unretained(iter->second)); 1399 base::Unretained(iter->second));
1400 } 1400 }
1401 for (ComboboxMap::iterator iter = group->comboboxes.begin(); 1401 for (ComboboxMap::const_iterator iter = group.comboboxes.begin();
1402 iter != group->comboboxes.end(); ++iter) { 1402 iter != group.comboboxes.end(); ++iter) {
1403 views::Combobox* combobox = iter->second; 1403 views::Combobox* combobox = iter->second;
1404 string16 item = 1404 string16 item =
1405 combobox->model()->GetItemAt(combobox->selected_index()); 1405 combobox->model()->GetItemAt(combobox->selected_index());
1406 detail_outputs[iter->first] = item; 1406 detail_outputs[iter->first] = item;
1407 field_map[iter->first->type] = 1407 field_map[iter->first->type] =
1408 base::Bind(&views::Combobox::SetInvalid, 1408 base::Bind(&views::Combobox::SetInvalid,
1409 base::Unretained(iter->second)); 1409 base::Unretained(iter->second));
1410 } 1410 }
1411 } else if (group->section == SECTION_CC) { 1411 } else if (group.section == SECTION_CC) {
1412 DecoratedTextfield* decorated_cvc = 1412 DecoratedTextfield* decorated_cvc =
1413 group->suggested_info->decorated_textfield(); 1413 group.suggested_info->decorated_textfield();
1414 cvc_input.reset(new DetailInput); 1414 cvc_input.reset(new DetailInput);
1415 cvc_input->type = CREDIT_CARD_VERIFICATION_CODE; 1415 cvc_input->type = CREDIT_CARD_VERIFICATION_CODE;
1416 detail_outputs[cvc_input.get()] = decorated_cvc->textfield()->text(); 1416 detail_outputs[cvc_input.get()] = decorated_cvc->textfield()->text();
1417 field_map[cvc_input->type] = 1417 field_map[cvc_input->type] =
1418 base::Bind(&DecoratedTextfield::SetInvalid, 1418 base::Bind(&DecoratedTextfield::SetInvalid,
1419 base::Unretained(decorated_cvc)); 1419 base::Unretained(decorated_cvc));
1420 } 1420 }
1421 1421
1422 std::vector<AutofillFieldType> invalid_inputs; 1422 std::vector<AutofillFieldType> invalid_inputs;
1423 invalid_inputs = controller_->InputsAreValid(detail_outputs, validation_type); 1423 invalid_inputs = controller_->InputsAreValid(detail_outputs, validation_type);
(...skipping 10 matching lines...) Expand all
1434 iter->second.Run(false); // Calls SetInvalid(false) for this field. 1434 iter->second.Run(false); // Calls SetInvalid(false) for this field.
1435 } 1435 }
1436 1436
1437 return invalid_inputs.empty(); 1437 return invalid_inputs.empty();
1438 } 1438 }
1439 1439
1440 bool AutofillDialogViews::ValidateForm() { 1440 bool AutofillDialogViews::ValidateForm() {
1441 bool all_valid = true; 1441 bool all_valid = true;
1442 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1442 for (DetailGroupMap::iterator iter = detail_groups_.begin();
1443 iter != detail_groups_.end(); ++iter) { 1443 iter != detail_groups_.end(); ++iter) {
1444 DetailsGroup* group = &iter->second; 1444 const DetailsGroup& group = iter->second;
1445 if (!group->container->visible()) 1445 if (!group.container->visible())
1446 continue; 1446 continue;
1447 1447
1448 if (!ValidateGroup(group, AutofillDialogController::VALIDATE_FINAL)) 1448 if (!ValidateGroup(group, AutofillDialogController::VALIDATE_FINAL))
1449 all_valid = false; 1449 all_valid = false;
1450 } 1450 }
1451 1451
1452 return all_valid; 1452 return all_valid;
1453 } 1453 }
1454 1454
1455 void AutofillDialogViews::TextfieldEditedOrActivated( 1455 void AutofillDialogViews::TextfieldEditedOrActivated(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 // Many fields (i.e. CC#) are invalid for most of the duration of editing, 1490 // Many fields (i.e. CC#) are invalid for most of the duration of editing,
1491 // so flagging them as invalid prematurely is not helpful. However, 1491 // so flagging them as invalid prematurely is not helpful. However,
1492 // correcting a minor mistake (i.e. a wrong CC digit) should immediately 1492 // correcting a minor mistake (i.e. a wrong CC digit) should immediately
1493 // result in validation - positive user feedback. 1493 // result in validation - positive user feedback.
1494 if (decorated->invalid() && was_edit) { 1494 if (decorated->invalid() && was_edit) {
1495 decorated->SetInvalid(!controller_->InputIsValid(type, textfield->text())); 1495 decorated->SetInvalid(!controller_->InputIsValid(type, textfield->text()));
1496 1496
1497 // If the field transitioned from invalid to valid, re-validate the group, 1497 // If the field transitioned from invalid to valid, re-validate the group,
1498 // since inter-field checks become meaningful with valid fields. 1498 // since inter-field checks become meaningful with valid fields.
1499 if (!decorated->invalid()) 1499 if (!decorated->invalid())
1500 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT); 1500 ValidateGroup(*group, AutofillDialogController::VALIDATE_EDIT);
1501 } 1501 }
1502 1502
1503 gfx::Image icon = controller_->IconForField(type, textfield->text()); 1503 gfx::Image icon = controller_->IconForField(type, textfield->text());
1504 textfield->SetIcon(icon.AsImageSkia()); 1504 textfield->SetIcon(icon.AsImageSkia());
1505 } 1505 }
1506 1506
1507 void AutofillDialogViews::ContentsPreferredSizeChanged() { 1507 void AutofillDialogViews::ContentsPreferredSizeChanged() {
1508 if (GetWidget()) { 1508 if (GetWidget()) {
1509 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); 1509 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
1510 // If the above line does not cause the dialog's size to change, |contents_| 1510 // If the above line does not cause the dialog's size to change, |contents_|
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 1573 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
1574 : section(section), 1574 : section(section),
1575 container(NULL), 1575 container(NULL),
1576 manual_input(NULL), 1576 manual_input(NULL),
1577 suggested_info(NULL), 1577 suggested_info(NULL),
1578 suggested_button(NULL) {} 1578 suggested_button(NULL) {}
1579 1579
1580 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 1580 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
1581 1581
1582 } // namespace autofill 1582 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698