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

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

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years 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_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 10
(...skipping 2107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2118 return; 2118 return;
2119 } 2119 }
2120 2120
2121 // If the user clicks while the popup is already showing, be sure to hide 2121 // If the user clicks while the popup is already showing, be sure to hide
2122 // it. 2122 // it.
2123 if (!was_edit && popup_controller_.get()) { 2123 if (!was_edit && popup_controller_.get()) {
2124 HidePopup(); 2124 HidePopup();
2125 return; 2125 return;
2126 } 2126 }
2127 2127
2128 std::vector<base::string16> popup_values, popup_labels, popup_icons; 2128 std::vector<autofill::Suggestion> popup_suggestions;
2129 popup_suggestion_ids_.clear();
2129 if (common::IsCreditCardType(type)) { 2130 if (common::IsCreditCardType(type)) {
2130 GetManager()->GetCreditCardSuggestions(AutofillType(type), 2131 popup_suggestions = GetManager()->GetCreditCardSuggestions(
2131 field_contents, 2132 AutofillType(type), field_contents);
2132 &popup_values, 2133 for (const auto& suggestion : popup_suggestions)
2133 &popup_labels, 2134 popup_suggestion_ids_.push_back(suggestion.backend_id);
2134 &popup_icons,
2135 &popup_guids_);
2136 } else { 2135 } else {
2137 GetManager()->GetProfileSuggestions( 2136 popup_suggestions = GetManager()->GetProfileSuggestions(
2138 AutofillType(type), 2137 AutofillType(type),
2139 field_contents, 2138 field_contents,
2140 false, 2139 false,
2141 RequestedTypesForSection(section), 2140 RequestedTypesForSection(section),
2142 base::Bind(&AutofillDialogControllerImpl::ShouldSuggestProfile, 2141 base::Bind(&AutofillDialogControllerImpl::ShouldSuggestProfile,
2143 base::Unretained(this), section), 2142 base::Unretained(this), section));
2144 &popup_values, 2143 for (const auto& suggestion : popup_suggestions)
2145 &popup_labels, 2144 popup_suggestion_ids_.push_back(suggestion.backend_id);
2146 &popup_icons,
2147 &popup_guids_);
2148 2145
2149 GetI18nValidatorSuggestions(section, type, &popup_values, &popup_labels, 2146 // This will append to the popup_suggestions but not the IDs since there
2150 &popup_icons); 2147 // are no backend IDs for the I18N validator suggestions.
2148 GetI18nValidatorSuggestions(section, type, &popup_suggestions);
2151 } 2149 }
2152 2150
2153 if (popup_values.empty()) { 2151 if (popup_suggestions.empty()) {
2154 HidePopup(); 2152 HidePopup();
2155 return; 2153 return;
2156 } 2154 }
2157 2155
2158 // |popup_input_type_| must be set before calling |Show()|. 2156 // |popup_input_type_| must be set before calling |Show()|.
2159 popup_input_type_ = type; 2157 popup_input_type_ = type;
2160 popup_section_ = section; 2158 popup_section_ = section;
2161 2159
2160 // Use our own 0-based IDs for the items.
2162 // TODO(estade): do we need separators and control rows like 'Clear 2161 // TODO(estade): do we need separators and control rows like 'Clear
2163 // Form'? 2162 // Form'?
2164 std::vector<int> popup_ids; 2163 for (size_t i = 0; i < popup_suggestions.size(); ++i) {
2165 for (size_t i = 0; i < popup_values.size(); ++i) { 2164 popup_suggestions[i].frontend_id = i;
2166 popup_ids.push_back(i);
2167 } 2165 }
2168 2166
2169 popup_controller_ = AutofillPopupControllerImpl::GetOrCreate( 2167 popup_controller_ = AutofillPopupControllerImpl::GetOrCreate(
2170 popup_controller_, 2168 popup_controller_,
2171 weak_ptr_factory_.GetWeakPtr(), 2169 weak_ptr_factory_.GetWeakPtr(),
2172 NULL, 2170 NULL,
2173 parent_view, 2171 parent_view,
2174 content_bounds, 2172 content_bounds,
2175 base::i18n::IsRTL() ? 2173 base::i18n::IsRTL() ?
2176 base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT); 2174 base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT);
2177 popup_controller_->Show(popup_values, 2175 popup_controller_->Show(popup_suggestions);
2178 popup_labels,
2179 popup_icons,
2180 popup_ids);
2181 } 2176 }
2182 2177
2183 void AutofillDialogControllerImpl::FocusMoved() { 2178 void AutofillDialogControllerImpl::FocusMoved() {
2184 HidePopup(); 2179 HidePopup();
2185 } 2180 }
2186 2181
2187 bool AutofillDialogControllerImpl::ShouldShowErrorBubble() const { 2182 bool AutofillDialogControllerImpl::ShouldShowErrorBubble() const {
2188 return popup_input_type_ == UNKNOWN_TYPE; 2183 return popup_input_type_ == UNKNOWN_TYPE;
2189 } 2184 }
2190 2185
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 const base::string16& value, 2398 const base::string16& value,
2404 int identifier) { 2399 int identifier) {
2405 DCHECK_NE(UNKNOWN_TYPE, popup_input_type_); 2400 DCHECK_NE(UNKNOWN_TYPE, popup_input_type_);
2406 // Because |HidePopup()| can be called from |UpdateSection()|, remember the 2401 // Because |HidePopup()| can be called from |UpdateSection()|, remember the
2407 // type of the input for later here. 2402 // type of the input for later here.
2408 const ServerFieldType popup_input_type = popup_input_type_; 2403 const ServerFieldType popup_input_type = popup_input_type_;
2409 2404
2410 ScopedViewUpdates updates(view_.get()); 2405 ScopedViewUpdates updates(view_.get());
2411 scoped_ptr<DataModelWrapper> wrapper; 2406 scoped_ptr<DataModelWrapper> wrapper;
2412 2407
2413 if (static_cast<size_t>(identifier) < popup_guids_.size()) { 2408 if (static_cast<size_t>(identifier) < popup_suggestion_ids_.size()) {
2414 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier]; 2409 const SuggestionBackendID& sid = popup_suggestion_ids_[identifier];
2415 if (common::IsCreditCardType(popup_input_type)) { 2410 if (common::IsCreditCardType(popup_input_type)) {
2416 wrapper.reset(new AutofillCreditCardWrapper( 2411 wrapper.reset(new AutofillCreditCardWrapper(
2417 GetManager()->GetCreditCardByGUID(pair.first))); 2412 GetManager()->GetCreditCardByGUID(sid.guid)));
2418 } else { 2413 } else {
2419 wrapper.reset(new AutofillProfileWrapper( 2414 wrapper.reset(new AutofillProfileWrapper(
2420 GetManager()->GetProfileByGUID(pair.first), 2415 GetManager()->GetProfileByGUID(sid.guid),
2421 AutofillType(popup_input_type), 2416 AutofillType(popup_input_type),
2422 pair.second)); 2417 sid.variant));
2423 } 2418 }
2424 } else { 2419 } else {
2425 wrapper.reset(new I18nAddressDataWrapper( 2420 wrapper.reset(new I18nAddressDataWrapper(
2426 &i18n_validator_suggestions_[identifier - popup_guids_.size()])); 2421 &i18n_validator_suggestions_[
2422 identifier - popup_suggestion_ids_.size()]));
2427 } 2423 }
2428 2424
2429 // If the user hasn't switched away from the default country and |wrapper|'s 2425 // If the user hasn't switched away from the default country and |wrapper|'s
2430 // country differs from the |view_|'s, rebuild inputs and restore user data. 2426 // country differs from the |view_|'s, rebuild inputs and restore user data.
2431 const FieldValueMap snapshot = TakeUserInputSnapshot(); 2427 const FieldValueMap snapshot = TakeUserInputSnapshot();
2432 bool billing_rebuilt = false, shipping_rebuilt = false; 2428 bool billing_rebuilt = false, shipping_rebuilt = false;
2433 2429
2434 base::string16 billing_country = 2430 base::string16 billing_country =
2435 wrapper->GetInfo(AutofillType(ADDRESS_BILLING_COUNTRY)); 2431 wrapper->GetInfo(AutofillType(ADDRESS_BILLING_COUNTRY));
2436 if (popup_section_ == ActiveBillingSection() && 2432 if (popup_section_ == ActiveBillingSection() &&
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
3378 3374
3379 if (section == SECTION_SHIPPING) 3375 if (section == SECTION_SHIPPING)
3380 return shipping_country_combobox_model_.get(); 3376 return shipping_country_combobox_model_.get();
3381 3377
3382 return NULL; 3378 return NULL;
3383 } 3379 }
3384 3380
3385 void AutofillDialogControllerImpl::GetI18nValidatorSuggestions( 3381 void AutofillDialogControllerImpl::GetI18nValidatorSuggestions(
3386 DialogSection section, 3382 DialogSection section,
3387 ServerFieldType type, 3383 ServerFieldType type,
3388 std::vector<base::string16>* popup_values, 3384 std::vector<autofill::Suggestion>* popup_suggestions) {
3389 std::vector<base::string16>* popup_labels,
3390 std::vector<base::string16>* popup_icons) {
3391 AddressField focused_field; 3385 AddressField focused_field;
3392 if (!i18n::FieldForType(type, &focused_field)) 3386 if (!i18n::FieldForType(type, &focused_field))
3393 return; 3387 return;
3394 3388
3395 FieldValueMap inputs; 3389 FieldValueMap inputs;
3396 view_->GetUserInput(section, &inputs); 3390 view_->GetUserInput(section, &inputs);
3397 3391
3398 AutofillProfile profile; 3392 AutofillProfile profile;
3399 FillFormGroupFromOutputs(inputs, &profile); 3393 FillFormGroupFromOutputs(inputs, &profile);
3400 3394
3401 scoped_ptr<AddressData> user_input = 3395 scoped_ptr<AddressData> user_input =
3402 i18n::CreateAddressDataFromAutofillProfile( 3396 i18n::CreateAddressDataFromAutofillProfile(
3403 profile, g_browser_process->GetApplicationLocale()); 3397 profile, g_browser_process->GetApplicationLocale());
3404 user_input->language_code = AddressLanguageCodeForSection(section); 3398 user_input->language_code = AddressLanguageCodeForSection(section);
3405 3399
3406 static const size_t kSuggestionsLimit = 10; 3400 static const size_t kSuggestionsLimit = 10;
3407 AddressValidator::Status status = GetValidator()->GetSuggestions( 3401 AddressValidator::Status status = GetValidator()->GetSuggestions(
3408 *user_input, focused_field, kSuggestionsLimit, 3402 *user_input, focused_field, kSuggestionsLimit,
3409 &i18n_validator_suggestions_); 3403 &i18n_validator_suggestions_);
3410 3404
3411 if (status != AddressValidator::SUCCESS) 3405 if (status != AddressValidator::SUCCESS)
3412 return; 3406 return;
3413 3407
3414 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { 3408 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) {
3415 popup_values->push_back(base::UTF8ToUTF16( 3409 popup_suggestions->push_back(autofill::Suggestion(
3416 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); 3410 base::UTF8ToUTF16(
3411 i18n_validator_suggestions_[i].GetFieldValue(focused_field))));
3417 3412
3418 // Disambiguate the suggestion by showing the smallest administrative 3413 // Disambiguate the suggestion by showing the smallest administrative
3419 // region of the suggested address: 3414 // region of the suggested address:
3420 // ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY 3415 // ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY
3421 popup_labels->push_back(base::string16());
3422 for (int field = DEPENDENT_LOCALITY; field >= ADMIN_AREA; --field) { 3416 for (int field = DEPENDENT_LOCALITY; field >= ADMIN_AREA; --field) {
3423 const std::string& field_value = 3417 const std::string& field_value =
3424 i18n_validator_suggestions_[i].GetFieldValue( 3418 i18n_validator_suggestions_[i].GetFieldValue(
3425 static_cast<AddressField>(field)); 3419 static_cast<AddressField>(field));
3426 if (focused_field != field && !field_value.empty()) { 3420 if (focused_field != field && !field_value.empty()) {
3427 popup_labels->back().assign(base::UTF8ToUTF16(field_value)); 3421 popup_suggestions->back().label = base::UTF8ToUTF16(field_value);
3428 break; 3422 break;
3429 } 3423 }
3430 } 3424 }
3431 } 3425 }
3432 popup_icons->resize(popup_values->size());
3433 } 3426 }
3434 3427
3435 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( 3428 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
3436 DialogSection section) { 3429 DialogSection section) {
3437 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); 3430 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
3438 } 3431 }
3439 3432
3440 std::string* AutofillDialogControllerImpl::MutableAddressLanguageCodeForSection( 3433 std::string* AutofillDialogControllerImpl::MutableAddressLanguageCodeForSection(
3441 DialogSection section) { 3434 DialogSection section) {
3442 switch (section) { 3435 switch (section) {
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
4147 view_->UpdateButtonStrip(); 4140 view_->UpdateButtonStrip();
4148 } 4141 }
4149 4142
4150 void AutofillDialogControllerImpl::FetchWalletCookie() { 4143 void AutofillDialogControllerImpl::FetchWalletCookie() {
4151 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); 4144 net::URLRequestContextGetter* request_context = profile_->GetRequestContext();
4152 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); 4145 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context));
4153 signin_helper_->StartWalletCookieValueFetch(); 4146 signin_helper_->StartWalletCookieValueFetch();
4154 } 4147 }
4155 4148
4156 } // namespace autofill 4149 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.h ('k') | chrome/browser/ui/autofill/autofill_popup_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698