1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_COMMON_H_
6#define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_COMMON_H_
7
8#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
9#include "components/autofill/core/browser/autofill_type.h"
10#include "components/autofill/core/browser/field_types.h"
11
12namespace autofill {
13class AutofillProfile;
14}
15
16namespace wallet {
17class Address;
18}
19
20namespace autofill {
21namespace common {
22
23// The types of addresses this class supports building.
24enum AddressType {
25  ADDRESS_TYPE_BILLING,
26  ADDRESS_TYPE_SHIPPING,
27};
28
29// Returns true if |type| should be shown when |field_type| has been requested.
30// This filters the types that we fill into the page to match the ones the
31// dialog actually cares about, preventing rAc from giving away data that an
32// AutofillProfile or other data source might know about the user which isn't
33// represented in the dialog.
34bool ServerTypeEncompassesFieldType(ServerFieldType type,
35                                    const AutofillType& field_type);
36
37// Returns true if |type| in the given |section| should be used for a
38// site-requested |field|.
39bool ServerTypeMatchesField(DialogSection section,
40                            ServerFieldType type,
41                            const AutofillField& field);
42
43// Returns true if the |type| belongs to the CREDIT_CARD field type group.
44bool IsCreditCardType(ServerFieldType type);
45
46// Constructs |inputs| from the array of inputs in |input_template|.
47void BuildInputs(const DetailInput input_template[],
48                 size_t template_size,
49                 DetailInputs* inputs);
50
51// Returns the AutofillMetrics::DIALOG_UI_*_ITEM_ADDED metric corresponding
52// to the |section|.
53AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent(
54    DialogSection section);
55
56// Returns the AutofillMetrics::DIALOG_UI_*_ITEM_ADDED metric corresponding
57// to the |section|.
58AutofillMetrics::DialogUiEvent DialogSectionToUiSelectionChangedEvent(
59    DialogSection section);
60
61// Gets just the |type| attributes from each DetailInput.
62std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs);
63
64}  // namespace common
65}  // namespace autofill
66
67#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_COMMON_H_
68