1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/autofill/autofill_dialog_common.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "components/autofill/core/browser/autofill_country.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_type.h"
namespace autofill {
namespace common {
bool ServerTypeEncompassesFieldType(ServerFieldType type,
const AutofillType& field_type) {
// If any credit card expiration info is asked for, show both month and year
// inputs.
ServerFieldType server_type = field_type.GetStorableType();
if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR ||
server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR ||
server_type == CREDIT_CARD_EXP_MONTH) {
return type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
type == CREDIT_CARD_EXP_MONTH;
}
if (server_type == CREDIT_CARD_TYPE)
return type == CREDIT_CARD_NUMBER;
// Check the groups to distinguish billing types from shipping ones.
AutofillType autofill_type = AutofillType(type);
if (autofill_type.group() != field_type.group())
return false;
// The page may ask for individual address lines; this roughly matches the
// street address blob.
if (server_type == ADDRESS_HOME_LINE1 ||
server_type == ADDRESS_HOME_LINE2 ||
server_type == ADDRESS_HOME_LINE3) {
return autofill_type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS;
}
// First, middle and last name are parsed from full name.
if (field_type.group() == NAME || field_type.group() == NAME_BILLING)
return autofill_type.GetStorableType() == NAME_FULL;
return autofill_type.GetStorableType() == server_type;
}
bool ServerTypeMatchesField(DialogSection section,
ServerFieldType type,
const AutofillField& field) {
AutofillType field_type = field.Type();
// The credit card name is filled from the billing section's data.
if (field_type.GetStorableType() == CREDIT_CARD_NAME &&
(section == SECTION_BILLING || section == SECTION_CC_BILLING)) {
return type == NAME_BILLING_FULL;
}
return ServerTypeEncompassesFieldType(type, field_type);
}
bool IsCreditCardType(ServerFieldType type) {
return AutofillType(type).group() == CREDIT_CARD;
}
void BuildInputs(const DetailInput* input_template,
size_t template_size,
DetailInputs* inputs) {
for (size_t i = 0; i < template_size; ++i) {
const DetailInput* input = &input_template[i];
inputs->push_back(*input);
}
}
AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent(
DialogSection section) {
switch (section) {
case SECTION_BILLING:
return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED;
case SECTION_CC_BILLING:
return AutofillMetrics::DIALOG_UI_CC_BILLING_ITEM_ADDED;
case SECTION_SHIPPING:
return AutofillMetrics::DIALOG_UI_SHIPPING_ITEM_ADDED;
case SECTION_CC:
return AutofillMetrics::DIALOG_UI_CC_ITEM_ADDED;
}
NOTREACHED();
return AutofillMetrics::NUM_DIALOG_UI_EVENTS;
}
AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent(
DialogSection section) {
switch (section) {
case SECTION_BILLING:
return AutofillMetrics::DIALOG_UI_BILLING_SELECTED_SUGGESTION_CHANGED;
case SECTION_CC_BILLING:
return AutofillMetrics::DIALOG_UI_CC_BILLING_SELECTED_SUGGESTION_CHANGED;
case SECTION_SHIPPING:
return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED;
case SECTION_CC:
return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED;
}
NOTREACHED();
return AutofillMetrics::NUM_DIALOG_UI_EVENTS;
}
std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs) {
std::vector<ServerFieldType> types;
for (size_t i = 0; i < inputs.size(); ++i) {
types.push_back(inputs[i].type);
}
return types;
}
} // namespace common
} // namespace autofill
|