OLD | NEW |
---|---|
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_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_split.h" | 25 #include "base/strings/string_split.h" |
26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
27 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
28 #include "base/thread_task_runner_handle.h" | 28 #include "base/thread_task_runner_handle.h" |
29 #include "base/time/time.h" | 29 #include "base/time/time.h" |
30 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 30 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
31 #include "chrome/browser/autofill/risk_util.h" | 31 #include "chrome/browser/autofill/risk_util.h" |
32 #include "chrome/browser/autofill/validation_rules_storage_factory.h" | 32 #include "chrome/browser/autofill/validation_rules_storage_factory.h" |
33 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
Ilya Sherman
2016/01/21 02:07:56
nit: Can this include be removed from this, or any
vabr (Chromium)
2016/01/22 17:36:41
It is still used by FormGroups (see, e.g., line 19
| |
34 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
35 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" | 35 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
36 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | 36 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
37 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 37 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
38 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 38 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
39 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h" | 39 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h" |
40 #include "chrome/browser/ui/browser.h" | 40 #include "chrome/browser/ui/browser.h" |
41 #include "chrome/browser/ui/browser_finder.h" | 41 #include "chrome/browser/ui/browser_finder.h" |
42 #include "chrome/browser/ui/browser_navigator.h" | 42 #include "chrome/browser/ui/browser_navigator.h" |
43 #include "chrome/browser/ui/browser_navigator_params.h" | 43 #include "chrome/browser/ui/browser_navigator_params.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 ServerFieldType field_type = type.GetStorableType(); | 154 ServerFieldType field_type = type.GetStorableType(); |
155 if (section != SECTION_SHIPPING) | 155 if (section != SECTION_SHIPPING) |
156 field_type = AutofillType::GetEquivalentBillingFieldType(field_type); | 156 field_type = AutofillType::GetEquivalentBillingFieldType(field_type); |
157 | 157 |
158 base::string16 info; | 158 base::string16 info; |
159 FieldValueMap::const_iterator it = inputs.find(field_type); | 159 FieldValueMap::const_iterator it = inputs.find(field_type); |
160 if (it != inputs.end()) | 160 if (it != inputs.end()) |
161 info = it->second; | 161 info = it->second; |
162 | 162 |
163 if (!info.empty() && type.html_type() == HTML_TYPE_COUNTRY_CODE) { | 163 if (!info.empty() && type.html_type() == HTML_TYPE_COUNTRY_CODE) { |
164 info = base::ASCIIToUTF16(CountryNames::GetInstance()->GetCountryCode( | 164 info = |
165 info, g_browser_process->GetApplicationLocale())); | 165 base::ASCIIToUTF16(CountryNames::GetInstance()->GetCountryCode(info)); |
166 } | 166 } |
167 | 167 |
168 return info; | 168 return info; |
169 } | 169 } |
170 | 170 |
171 // Returns true if |input| should be used to fill a site-requested |field| which | 171 // Returns true if |input| should be used to fill a site-requested |field| which |
172 // is notated with a "shipping" tag, for use when the user has decided to use | 172 // is notated with a "shipping" tag, for use when the user has decided to use |
173 // the billing address as the shipping address. | 173 // the billing address as the shipping address. |
174 bool ServerTypeMatchesShippingField(ServerFieldType type, | 174 bool ServerTypeMatchesShippingField(ServerFieldType type, |
175 const AutofillField& field) { | 175 const AutofillField& field) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); | 234 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); |
235 } | 235 } |
236 | 236 |
237 ServerFieldType CountryTypeForSection(DialogSection section) { | 237 ServerFieldType CountryTypeForSection(DialogSection section) { |
238 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : | 238 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : |
239 ADDRESS_BILLING_COUNTRY; | 239 ADDRESS_BILLING_COUNTRY; |
240 } | 240 } |
241 | 241 |
242 ValidityMessage GetPhoneValidityMessage(const base::string16& country_name, | 242 ValidityMessage GetPhoneValidityMessage(const base::string16& country_name, |
243 const base::string16& number) { | 243 const base::string16& number) { |
244 std::string region = CountryNames::GetInstance()->GetCountryCode( | 244 std::string region = |
245 country_name, g_browser_process->GetApplicationLocale()); | 245 CountryNames::GetInstance()->GetCountryCode(country_name); |
246 i18n::PhoneObject phone_object(number, region); | 246 i18n::PhoneObject phone_object(number, region); |
247 ValidityMessage phone_message(base::string16(), true); | 247 ValidityMessage phone_message(base::string16(), true); |
248 | 248 |
249 // Check if the phone number is invalid. Allow valid international | 249 // Check if the phone number is invalid. Allow valid international |
250 // numbers that don't match the address's country only if they have an | 250 // numbers that don't match the address's country only if they have an |
251 // international calling code. | 251 // international calling code. |
252 if (!phone_object.IsValidNumber() || | 252 if (!phone_object.IsValidNumber() || |
253 (phone_object.country_code().empty() && | 253 (phone_object.country_code().empty() && |
254 phone_object.region() != region)) { | 254 phone_object.region() != region)) { |
255 phone_message.text = l10n_util::GetStringUTF16( | 255 phone_message.text = l10n_util::GetStringUTF16( |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 } | 620 } |
621 | 621 |
622 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 622 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
623 for (DetailInputs::iterator it = inputs->begin(); | 623 for (DetailInputs::iterator it = inputs->begin(); |
624 it != inputs->end(); ++it) { | 624 it != inputs->end(); ++it) { |
625 if (it->length != DetailInput::NONE) { | 625 if (it->length != DetailInput::NONE) { |
626 it->initial_value.clear(); | 626 it->initial_value.clear(); |
627 } else if (!it->initial_value.empty() && | 627 } else if (!it->initial_value.empty() && |
628 (it->type == ADDRESS_BILLING_COUNTRY || | 628 (it->type == ADDRESS_BILLING_COUNTRY || |
629 it->type == ADDRESS_HOME_COUNTRY)) { | 629 it->type == ADDRESS_HOME_COUNTRY)) { |
630 GetValidator()->LoadRules(CountryNames::GetInstance()->GetCountryCode( | 630 GetValidator()->LoadRules( |
631 it->initial_value, g_browser_process->GetApplicationLocale())); | 631 CountryNames::GetInstance()->GetCountryCode(it->initial_value)); |
632 } | 632 } |
633 } | 633 } |
634 } | 634 } |
635 | 635 |
636 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( | 636 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( |
637 DialogSection section) { | 637 DialogSection section) { |
638 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so | 638 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so |
639 // get the wrapper before this potentially happens below. | 639 // get the wrapper before this potentially happens below. |
640 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 640 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
641 | 641 |
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1911 | 1911 |
1912 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1912 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
1913 if (wrapper) { | 1913 if (wrapper) { |
1914 country = wrapper->GetInfo(AutofillType(CountryTypeForSection(section))); | 1914 country = wrapper->GetInfo(AutofillType(CountryTypeForSection(section))); |
1915 } else { | 1915 } else { |
1916 FieldValueMap outputs; | 1916 FieldValueMap outputs; |
1917 view_->GetUserInput(section, &outputs); | 1917 view_->GetUserInput(section, &outputs); |
1918 country = outputs[CountryTypeForSection(section)]; | 1918 country = outputs[CountryTypeForSection(section)]; |
1919 } | 1919 } |
1920 | 1920 |
1921 return CountryNames::GetInstance()->GetCountryCode( | 1921 return CountryNames::GetInstance()->GetCountryCode(country); |
1922 country, g_browser_process->GetApplicationLocale()); | |
1923 } | 1922 } |
1924 | 1923 |
1925 bool AutofillDialogControllerImpl::RebuildInputsForCountry( | 1924 bool AutofillDialogControllerImpl::RebuildInputsForCountry( |
1926 DialogSection section, | 1925 DialogSection section, |
1927 const base::string16& country_name, | 1926 const base::string16& country_name, |
1928 bool should_clobber) { | 1927 bool should_clobber) { |
1929 CountryComboboxModel* model = CountryComboboxModelForSection(section); | 1928 CountryComboboxModel* model = CountryComboboxModelForSection(section); |
1930 if (!model) | 1929 if (!model) |
1931 return false; | 1930 return false; |
1932 | 1931 |
1933 std::string country_code = CountryNames::GetInstance()->GetCountryCode( | 1932 std::string country_code = |
1934 country_name, g_browser_process->GetApplicationLocale()); | 1933 CountryNames::GetInstance()->GetCountryCode(country_name); |
1935 DCHECK(CanAcceptCountry(section, country_code)); | 1934 DCHECK(CanAcceptCountry(section, country_code)); |
1936 | 1935 |
1937 if (view_ && !should_clobber) { | 1936 if (view_ && !should_clobber) { |
1938 FieldValueMap outputs; | 1937 FieldValueMap outputs; |
1939 view_->GetUserInput(section, &outputs); | 1938 view_->GetUserInput(section, &outputs); |
1940 | 1939 |
1941 // If |country_name| is the same as the view, no-op and let the caller know. | 1940 // If |country_name| is the same as the view, no-op and let the caller know. |
1942 if (outputs[CountryTypeForSection(section)] == country_name) | 1941 if (outputs[CountryTypeForSection(section)] == country_name) |
1943 return false; | 1942 return false; |
1944 } | 1943 } |
1945 | 1944 |
1946 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1945 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
1947 inputs->clear(); | 1946 inputs->clear(); |
1948 BuildInputsForSection(section, country_code, inputs, | 1947 BuildInputsForSection(section, country_code, inputs, |
1949 MutableAddressLanguageCodeForSection(section)); | 1948 MutableAddressLanguageCodeForSection(section)); |
1950 | 1949 |
1951 if (!country_code.empty()) { | 1950 if (!country_code.empty()) { |
1952 GetValidator()->LoadRules(CountryNames::GetInstance()->GetCountryCode( | 1951 GetValidator()->LoadRules( |
1953 country_name, g_browser_process->GetApplicationLocale())); | 1952 CountryNames::GetInstance()->GetCountryCode(country_name)); |
1954 } | 1953 } |
1955 | 1954 |
1956 return true; | 1955 return true; |
1957 } | 1956 } |
1958 | 1957 |
1959 void AutofillDialogControllerImpl::HidePopup() { | 1958 void AutofillDialogControllerImpl::HidePopup() { |
1960 if (popup_controller_) | 1959 if (popup_controller_) |
1961 popup_controller_->Hide(); | 1960 popup_controller_->Hide(); |
1962 popup_input_type_ = UNKNOWN_TYPE; | 1961 popup_input_type_ = UNKNOWN_TYPE; |
1963 } | 1962 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2309 } | 2308 } |
2310 | 2309 |
2311 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { | 2310 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { |
2312 if (!view_) | 2311 if (!view_) |
2313 return; | 2312 return; |
2314 ScopedViewUpdates updates(view_.get()); | 2313 ScopedViewUpdates updates(view_.get()); |
2315 view_->UpdateButtonStrip(); | 2314 view_->UpdateButtonStrip(); |
2316 } | 2315 } |
2317 | 2316 |
2318 } // namespace autofill | 2317 } // namespace autofill |
OLD | NEW |