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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_common.cc

Issue 974323002: Componentize autofill dialog common code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add missing includes 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 2013 The Chromium Authors. All rights reserved. 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 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/autofill/autofill_dialog_common.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_common.h"
6 6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h"
9 #include "components/autofill/core/browser/autofill_country.h"
10 #include "components/autofill/core/browser/autofill_field.h"
11 #include "components/autofill/core/browser/autofill_type.h"
12
13 namespace autofill { 7 namespace autofill {
14 namespace common { 8 namespace common {
15 9
16 bool ServerTypeEncompassesFieldType(ServerFieldType type,
17 const AutofillType& field_type) {
18 // If any credit card expiration info is asked for, show both month and year
19 // inputs.
20 ServerFieldType server_type = field_type.GetStorableType();
21 if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
22 server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
23 server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR ||
24 server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR ||
25 server_type == CREDIT_CARD_EXP_MONTH) {
26 return type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
27 type == CREDIT_CARD_EXP_MONTH;
28 }
29
30 if (server_type == CREDIT_CARD_TYPE)
31 return type == CREDIT_CARD_NUMBER;
32
33 // Check the groups to distinguish billing types from shipping ones.
34 AutofillType autofill_type = AutofillType(type);
35 if (autofill_type.group() != field_type.group())
36 return false;
37
38 // The page may ask for individual address lines; this roughly matches the
39 // street address blob.
40 if (server_type == ADDRESS_HOME_LINE1 ||
41 server_type == ADDRESS_HOME_LINE2 ||
42 server_type == ADDRESS_HOME_LINE3) {
43 return autofill_type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS;
44 }
45
46 // First, middle and last name are parsed from full name.
47 if (field_type.group() == NAME || field_type.group() == NAME_BILLING)
48 return autofill_type.GetStorableType() == NAME_FULL;
49
50 return autofill_type.GetStorableType() == server_type;
51 }
52
53 bool ServerTypeMatchesField(DialogSection section,
54 ServerFieldType type,
55 const AutofillField& field) {
56 AutofillType field_type = field.Type();
57
58 // The credit card name is filled from the billing section's data.
59 if (field_type.GetStorableType() == CREDIT_CARD_NAME &&
60 (section == SECTION_BILLING || section == SECTION_CC_BILLING)) {
61 return type == NAME_BILLING_FULL;
62 }
63
64 return ServerTypeEncompassesFieldType(type, field_type);
65 }
66
67 bool IsCreditCardType(ServerFieldType type) {
68 return AutofillType(type).group() == CREDIT_CARD;
69 }
70
71 void BuildInputs(const DetailInput* input_template,
72 size_t template_size,
73 DetailInputs* inputs) {
74 for (size_t i = 0; i < template_size; ++i) {
75 const DetailInput* input = &input_template[i];
76 inputs->push_back(*input);
77 }
78 }
79
80 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( 10 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent(
81 DialogSection section) { 11 DialogSection section) {
82 switch (section) { 12 switch (section) {
83 case SECTION_BILLING: 13 case SECTION_BILLING:
84 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; 14 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED;
85 15
86 case SECTION_CC_BILLING: 16 case SECTION_CC_BILLING:
87 return AutofillMetrics::DIALOG_UI_CC_BILLING_ITEM_ADDED; 17 return AutofillMetrics::DIALOG_UI_CC_BILLING_ITEM_ADDED;
88 18
89 case SECTION_SHIPPING: 19 case SECTION_SHIPPING:
(...skipping 20 matching lines...) Expand all
110 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED; 40 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED;
111 41
112 case SECTION_CC: 42 case SECTION_CC:
113 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; 43 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED;
114 } 44 }
115 45
116 NOTREACHED(); 46 NOTREACHED();
117 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 47 return AutofillMetrics::NUM_DIALOG_UI_EVENTS;
118 } 48 }
119 49
120 std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs) {
121 std::vector<ServerFieldType> types;
122 for (size_t i = 0; i < inputs.size(); ++i) {
123 types.push_back(inputs[i].type);
124 }
125 return types;
126 }
127
128 } // namespace common 50 } // namespace common
129 } // namespace autofill 51 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_common.h ('k') | chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698