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

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

Issue 11742033: requestAutocomplete: only menu-suggest "complete" profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_split.h" 8 #include "base/string_split.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 FilterInputs(form_structure_, 185 FilterInputs(form_structure_,
186 kBillingInputs, 186 kBillingInputs,
187 arraysize(kBillingInputs), 187 arraysize(kBillingInputs),
188 &requested_billing_fields_); 188 &requested_billing_fields_);
189 189
190 FilterInputs(form_structure_, 190 FilterInputs(form_structure_,
191 kShippingInputs, 191 kShippingInputs,
192 arraysize(kShippingInputs), 192 arraysize(kShippingInputs),
193 &requested_shipping_fields_); 193 &requested_shipping_fields_);
194 194
195 // TODO(estade): make this actually check if it's a first run. 195 GenerateComboboxModels();
196 bool first_run = true;
197 if (!first_run)
198 GenerateComboboxModels();
199 196
200 // TODO(estade): don't show the dialog if the site didn't specify the right 197 // TODO(estade): don't show the dialog if the site didn't specify the right
201 // fields. First we must figure out what the "right" fields are. 198 // fields. First we must figure out what the "right" fields are.
202 view_.reset(AutofillDialogView::Create(this)); 199 view_.reset(AutofillDialogView::Create(this));
203 view_->Show(); 200 view_->Show();
204 } 201 }
205 202
206 string16 AutofillDialogController::DialogTitle() const { 203 string16 AutofillDialogController::DialogTitle() const {
207 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE); 204 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE);
208 } 205 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 PersonalDataManager* manager = GetManager(); 432 PersonalDataManager* manager = GetManager();
436 const std::vector<CreditCard*>& cards = manager->credit_cards(); 433 const std::vector<CreditCard*>& cards = manager->credit_cards();
437 for (size_t i = 0; i < cards.size(); ++i) { 434 for (size_t i = 0; i < cards.size(); ++i) {
438 suggested_cc_.AddItem(cards[i]->guid(), cards[i]->Label()); 435 suggested_cc_.AddItem(cards[i]->guid(), cards[i]->Label());
439 } 436 }
440 suggested_cc_.AddItem("", ASCIIToUTF16("Enter new card")); 437 suggested_cc_.AddItem("", ASCIIToUTF16("Enter new card"));
441 438
442 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); 439 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles();
443 const std::string app_locale = AutofillCountry::ApplicationLocale(); 440 const std::string app_locale = AutofillCountry::ApplicationLocale();
444 for (size_t i = 0; i < profiles.size(); ++i) { 441 for (size_t i = 0; i < profiles.size(); ++i) {
442 // TODO(estade): deal with variants.
443 if (!IsCompleteProfile(*profiles[i]))
444 continue;
445
445 string16 email = profiles[i]->GetInfo(EMAIL_ADDRESS, app_locale); 446 string16 email = profiles[i]->GetInfo(EMAIL_ADDRESS, app_locale);
446 if (!email.empty()) 447 if (!email.empty())
447 suggested_email_.AddItem(profiles[i]->guid(), email); 448 suggested_email_.AddItem(profiles[i]->guid(), email);
448 suggested_billing_.AddItem(profiles[i]->guid(), profiles[i]->Label()); 449 suggested_billing_.AddItem(profiles[i]->guid(), profiles[i]->Label());
449 suggested_shipping_.AddItem(profiles[i]->guid(), profiles[i]->Label()); 450 suggested_shipping_.AddItem(profiles[i]->guid(), profiles[i]->Label());
450 } 451 }
451 suggested_billing_.AddItem("", ASCIIToUTF16("Enter new billing")); 452 suggested_billing_.AddItem("", ASCIIToUTF16("Enter new billing"));
452 suggested_email_.AddItem("", ASCIIToUTF16("Enter new email")); 453 suggested_email_.AddItem("", ASCIIToUTF16("Enter new email"));
453 suggested_shipping_.AddItem("", ASCIIToUTF16("Enter new shipping")); 454 suggested_shipping_.AddItem("", ASCIIToUTF16("Enter new shipping"));
454 } 455 }
455 456
457
458 bool AutofillDialogController::IsCompleteProfile(
459 const AutofillProfile& profile) {
460 const std::string app_locale = AutofillCountry::ApplicationLocale();
461 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) {
462 if (profile.GetInfo(requested_shipping_fields_[i].type,
463 app_locale).empty()) {
464 return false;
465 }
466 }
467
468 return true;
469 }
470
456 void AutofillDialogController::FillOutputForSectionWithComparator( 471 void AutofillDialogController::FillOutputForSectionWithComparator(
457 DialogSection section, const InputFieldComparator& compare) { 472 DialogSection section, const InputFieldComparator& compare) {
458 int suggestion_selection = view_->GetSuggestionSelection(section); 473 int suggestion_selection = view_->GetSuggestionSelection(section);
459 SuggestionsComboboxModel* model = SuggestionsModelForSection(section); 474 SuggestionsComboboxModel* model = SuggestionsModelForSection(section);
460 PersonalDataManager* manager = GetManager(); 475 PersonalDataManager* manager = GetManager();
461 if (suggestion_selection < model->GetItemCount() - 1) { 476 if (suggestion_selection < model->GetItemCount() - 1) {
462 std::string guid = model->GetItemKeyAt(suggestion_selection); 477 std::string guid = model->GetItemKeyAt(suggestion_selection);
463 FormGroup* form_group = section == SECTION_CC ? 478 FormGroup* form_group = section == SECTION_CC ?
464 static_cast<FormGroup*>(manager->GetCreditCardByGUID(guid)) : 479 static_cast<FormGroup*>(manager->GetCreditCardByGUID(guid)) :
465 static_cast<FormGroup*>(manager->GetProfileByGUID(guid)); 480 static_cast<FormGroup*>(manager->GetProfileByGUID(guid));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 556
542 NOTREACHED(); 557 NOTREACHED();
543 return NULL; 558 return NULL;
544 } 559 }
545 560
546 PersonalDataManager* AutofillDialogController::GetManager() { 561 PersonalDataManager* AutofillDialogController::GetManager() {
547 return PersonalDataManagerFactory::GetForProfile(profile_); 562 return PersonalDataManagerFactory::GetForProfile(profile_);
548 } 563 }
549 564
550 } // namespace autofill 565 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698