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

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

Issue 12052059: requestAutocomplete - more elaborate suggestion labels (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: self review 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
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_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
(...skipping 12 matching lines...) Expand all
23 #include "content/public/browser/navigation_details.h" 23 #include "content/public/browser/navigation_details.h"
24 #include "content/public/browser/navigation_entry.h" 24 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_types.h" 26 #include "content/public/browser/notification_types.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/common/url_constants.h" 28 #include "content/public/common/url_constants.h"
29 #include "grit/chromium_strings.h" 29 #include "grit/chromium_strings.h"
30 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "net/base/cert_status_flags.h" 31 #include "net/base/cert_status_flags.h"
32 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/base/resource/resource_bundle.h"
33 34
34 namespace autofill { 35 namespace autofill {
35 36
36 namespace { 37 namespace {
37 38
38 // Returns true if |input| should be shown when |field| has been requested. 39 // Returns true if |input| should be shown when |field| has been requested.
39 bool InputTypeMatchesFieldType(const DetailInput& input, 40 bool InputTypeMatchesFieldType(const DetailInput& input,
40 const AutofillField& field) { 41 const AutofillField& field) {
41 // If any credit card expiration info is asked for, show both month and year 42 // If any credit card expiration info is asked for, show both month and year
42 // inputs. 43 // inputs.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 323 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
323 std::string item_key = model->GetItemKeyAt(model->checked_item()); 324 std::string item_key = model->GetItemKeyAt(model->checked_item());
324 if (item_key.empty()) 325 if (item_key.empty())
325 return string16(); 326 return string16();
326 327
327 if (section == SECTION_EMAIL) 328 if (section == SECTION_EMAIL)
328 return model->GetLabelAt(model->checked_item()); 329 return model->GetLabelAt(model->checked_item());
329 330
330 if (section == SECTION_CC) { 331 if (section == SECTION_CC) {
331 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); 332 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key);
332 if (card) 333 if (!card)
333 return card->Label(); 334 return string16();
Ilya Sherman 2013/01/24 04:27:27 When would card be null? The TODO on line 356 mak
Evan Stade 2013/01/24 23:34:25 same reason. I just get tired of repeating the sam
335
336 return card->TypeAndLastFourDigits();
334 } else { 337 } else {
335 // TODO(estade): This doesn't display as much info as it should (for
336 // example, it should show full addresses rather than just a summary).
337 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); 338 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key);
338 if (profile) 339 if (!profile)
339 return profile->Label(); 340 return string16();
341
342 const std::string app_locale = AutofillCountry::ApplicationLocale();
343 string16 comma = ASCIIToUTF16(", ");
344 string16 label = profile->GetInfo(NAME_FULL, app_locale) +
345 comma + profile->GetInfo(ADDRESS_HOME_LINE1, app_locale);
346 string16 address2 = profile->GetInfo(ADDRESS_HOME_LINE2, app_locale);
347 if (!address2.empty())
348 label += comma + address2;
349 label += ASCIIToUTF16("\n") +
350 profile->GetInfo(ADDRESS_HOME_CITY, app_locale) + comma +
351 profile->GetInfo(ADDRESS_HOME_STATE, app_locale) + ASCIIToUTF16(" ") +
352 profile->GetInfo(ADDRESS_HOME_ZIP, app_locale);
Ilya Sherman 2013/01/24 04:27:27 This code is very US-centric. That's fine for now
Evan Stade 2013/01/24 23:34:25 the entire dialog needs localization, so this fits
353 return label;
340 } 354 }
341 355
342 // TODO(estade): The FormGroup was likely deleted while menu was showing. We 356 // TODO(estade): The FormGroup was likely deleted while menu was showing. We
343 // should not let this happen. 357 // should not let this happen.
344 return string16(); 358 return string16();
Ilya Sherman 2013/01/24 04:27:27 This code doesn't seem to be reachable anymore...
Evan Stade 2013/01/24 23:34:25 good catch, wonder why the compiler doesn't warn.
345 } 359 }
346 360
361 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection(
362 DialogSection section) {
363 if (section != SECTION_CC)
364 return gfx::Image();
365
366 std::string item_key =
367 suggested_cc_.GetItemKeyAt(suggested_cc_.checked_item());
368 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key);
369 if (!card)
Ilya Sherman 2013/01/24 04:27:27 When is this case reachable? Can it be a DCHECK i
Evan Stade 2013/01/24 23:34:25 it's potentially reachable if the credit card is d
370 return gfx::Image();
371
372 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
373 return rb.GetImageNamed(card->IconResourceId());
374 }
375
347 void AutofillDialogControllerImpl::EditClickedForSection( 376 void AutofillDialogControllerImpl::EditClickedForSection(
348 DialogSection section) { 377 DialogSection section) {
349 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 378 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
350 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 379 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
351 380
352 if (section == SECTION_EMAIL) { 381 if (section == SECTION_EMAIL) {
353 // TODO(estade): shouldn't need to make this check. 382 // TODO(estade): shouldn't need to make this check.
354 if (inputs->empty()) 383 if (inputs->empty())
355 return; 384 return;
356 385
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 } 804 }
776 805
777 void AutofillDialogControllerImpl::HidePopup() { 806 void AutofillDialogControllerImpl::HidePopup() {
778 if (popup_controller_) { 807 if (popup_controller_) {
779 popup_controller_->Hide(); 808 popup_controller_->Hide();
780 ControllerDestroyed(); 809 ControllerDestroyed();
781 } 810 }
782 } 811 }
783 812
784 } // namespace autofill 813 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698