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

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

Issue 1931043002: Remove requestAutocomplete (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h"
6
7 #include <stddef.h>
8
9 #include "base/macros.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h"
13 #include "components/autofill/core/browser/address_i18n.h"
14 #include "components/autofill/core/browser/autofill_profile.h"
15 #include "components/autofill/core/browser/credit_card.h"
16 #include "components/autofill/core/browser/field_types.h"
17 #include "grit/components_strings.h"
18 #include "third_party/libaddressinput/chromium/addressinput_util.h"
19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h"
20 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi eld.h"
21 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h"
22 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui _component.h"
23 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati on.h"
24 #include "ui/base/l10n/l10n_util.h"
25
26 namespace autofill {
27 namespace i18ninput {
28
29 namespace {
30
31 using base::UTF16ToUTF8;
32 using ::i18n::addressinput::AddressField;
33 using ::i18n::addressinput::AddressUiComponent;
34 using ::i18n::addressinput::Localization;
35
36 std::vector<AddressUiComponent> BuildComponents(const std::string& country_code,
37 std::string* language_code) {
38 Localization localization;
39 localization.SetGetter(l10n_util::GetStringUTF8);
40 std::string not_used;
41 return ::i18n::addressinput::BuildComponents(
42 country_code, localization, g_browser_process->GetApplicationLocale(),
43 language_code == NULL ? &not_used : language_code);
44 }
45
46 DetailInput::Length LengthFromHint(AddressUiComponent::LengthHint hint) {
47 if (hint == AddressUiComponent::HINT_SHORT)
48 return DetailInput::SHORT;
49 DCHECK_EQ(hint, AddressUiComponent::HINT_LONG);
50 return DetailInput::LONG;
51 }
52
53 } // namespace
54
55 void BuildAddressInputs(common::AddressType address_type,
56 const std::string& country_code,
57 DetailInputs* inputs,
58 std::string* language_code) {
59 const std::vector<AddressUiComponent>& components(
60 BuildComponents(country_code, language_code));
61
62 const bool billing = address_type == common::ADDRESS_TYPE_BILLING;
63
64 for (size_t i = 0; i < components.size(); ++i) {
65 const AddressUiComponent& component = components[i];
66 // Interactive autofill dialog does not display organization.
67 if (component.field == ::i18n::addressinput::ORGANIZATION)
68 continue;
69 ServerFieldType server_type = i18n::TypeForField(component.field, billing);
70 DetailInput::Length length = LengthFromHint(component.length_hint);
71 base::string16 placeholder = base::UTF8ToUTF16(component.name);
72 DetailInput input = { length, server_type, placeholder };
73 inputs->push_back(input);
74 }
75
76 ServerFieldType server_type =
77 billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY;
78 base::string16 placeholder_text =
79 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY);
80 DetailInput input = { DetailInput::LONG, server_type, placeholder_text };
81 inputs->push_back(input);
82 }
83
84 bool CardHasCompleteAndVerifiedData(const CreditCard& card) {
85 if (!card.IsVerified())
86 return false;
87
88 const ServerFieldType required_fields[] = {
89 CREDIT_CARD_NUMBER,
90 CREDIT_CARD_EXP_MONTH,
91 CREDIT_CARD_EXP_4_DIGIT_YEAR,
92 };
93
94 for (size_t i = 0; i < arraysize(required_fields); ++i) {
95 if (card.GetRawInfo(required_fields[i]).empty())
96 return false;
97 }
98
99 return true;
100 }
101
102 bool AddressHasCompleteAndVerifiedData(const AutofillProfile& profile,
103 const std::string& app_locale) {
104 if (!profile.IsVerified())
105 return false;
106
107 if (!addressinput::HasAllRequiredFields(
108 *i18n::CreateAddressDataFromAutofillProfile(profile, app_locale))) {
109 return false;
110 }
111
112 const ServerFieldType more_required_fields[] = {
113 NAME_FULL,
114 PHONE_HOME_WHOLE_NUMBER
115 };
116
117 for (size_t i = 0; i < arraysize(more_required_fields); ++i) {
118 if (profile.GetInfo(AutofillType(more_required_fields[i]),
119 app_locale).empty()) {
120 return false;
121 }
122 }
123
124 return true;
125 }
126
127 } // namespace i18ninput
128 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698