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

Side by Side Diff: chrome/browser/ui/webui/options/autofill_options_handler.cc

Issue 12052059: requestAutocomplete - more elaborate suggestion labels (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: isherman 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
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_dialog_views.cc ('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/webui/options/autofill_options_handler.h" 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/string16.h" 13 #include "base/string16.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/autofill/autofill_country.h" 17 #include "chrome/browser/autofill/autofill_country.h"
18 #include "chrome/browser/autofill/autofill_profile.h" 18 #include "chrome/browser/autofill/autofill_profile.h"
19 #include "chrome/browser/autofill/credit_card.h" 19 #include "chrome/browser/autofill/credit_card.h"
20 #include "chrome/browser/autofill/personal_data_manager.h" 20 #include "chrome/browser/autofill/personal_data_manager.h"
21 #include "chrome/browser/autofill/personal_data_manager_factory.h" 21 #include "chrome/browser/autofill/personal_data_manager_factory.h"
22 #include "chrome/browser/autofill/phone_number_i18n.h" 22 #include "chrome/browser/autofill/phone_number_i18n.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
26 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 #include "grit/webkit_resources.h"
28 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/webui/web_ui_util.h" 28 #include "ui/webui/web_ui_util.h"
30 29
31 namespace { 30 namespace {
32 31
33 // Converts a credit card type to the appropriate resource ID of the CC icon.
34 int CreditCardTypeToResourceID(const std::string& type) {
35 if (type == kAmericanExpressCard)
36 return IDR_AUTOFILL_CC_AMEX;
37 else if (type == kDinersCard)
38 return IDR_AUTOFILL_CC_DINERS;
39 else if (type == kDiscoverCard)
40 return IDR_AUTOFILL_CC_DISCOVER;
41 else if (type == kGenericCard)
42 return IDR_AUTOFILL_CC_GENERIC;
43 else if (type == kJCBCard)
44 return IDR_AUTOFILL_CC_JCB;
45 else if (type == kMasterCard)
46 return IDR_AUTOFILL_CC_MASTERCARD;
47 else if (type == kSoloCard)
48 return IDR_AUTOFILL_CC_SOLO;
49 else if (type == kVisaCard)
50 return IDR_AUTOFILL_CC_VISA;
51
52 NOTREACHED();
53 return 0;
54 }
55
56 // Converts a credit card type to the appropriate localized card type.
57 string16 LocalizedCreditCardType(const std::string& type) {
58 if (type == kAmericanExpressCard)
59 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX);
60 else if (type == kDinersCard)
61 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS);
62 else if (type == kDiscoverCard)
63 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER);
64 else if (type == kGenericCard)
65 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_GENERIC);
66 else if (type == kJCBCard)
67 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB);
68 else if (type == kMasterCard)
69 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD);
70 else if (type == kSoloCard)
71 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_SOLO);
72 else if (type == kVisaCard)
73 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA);
74
75 NOTREACHED();
76 return string16();
77 }
78
79 // Returns a dictionary that maps country codes to data for the country. 32 // Returns a dictionary that maps country codes to data for the country.
80 DictionaryValue* GetCountryData() { 33 DictionaryValue* GetCountryData() {
81 std::string app_locale = AutofillCountry::ApplicationLocale(); 34 std::string app_locale = AutofillCountry::ApplicationLocale();
82 std::vector<std::string> country_codes; 35 std::vector<std::string> country_codes;
83 AutofillCountry::GetAvailableCountries(&country_codes); 36 AutofillCountry::GetAvailableCountries(&country_codes);
84 37
85 DictionaryValue* country_data = new DictionaryValue(); 38 DictionaryValue* country_data = new DictionaryValue();
86 for (size_t i = 0; i < country_codes.size(); ++i) { 39 for (size_t i = 0; i < country_codes.size(); ++i) {
87 const AutofillCountry country(country_codes[i], app_locale); 40 const AutofillCountry country(country_codes[i], app_locale);
88 41
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 entry->Append(new StringValue((*i)->Label())); 368 entry->Append(new StringValue((*i)->Label()));
416 addresses.Append(entry); 369 addresses.Append(entry);
417 } 370 }
418 371
419 web_ui()->CallJavascriptFunction("AutofillOptions.setAddressList", addresses); 372 web_ui()->CallJavascriptFunction("AutofillOptions.setAddressList", addresses);
420 373
421 ListValue credit_cards; 374 ListValue credit_cards;
422 for (std::vector<CreditCard*>::const_iterator i = 375 for (std::vector<CreditCard*>::const_iterator i =
423 personal_data_->credit_cards().begin(); 376 personal_data_->credit_cards().begin();
424 i != personal_data_->credit_cards().end(); ++i) { 377 i != personal_data_->credit_cards().end(); ++i) {
378 const CreditCard* card = *i;
379 // TODO(estade): this should be a dictionary.
425 ListValue* entry = new ListValue(); 380 ListValue* entry = new ListValue();
426 entry->Append(new StringValue((*i)->guid())); 381 entry->Append(new StringValue(card->guid()));
427 entry->Append(new StringValue((*i)->Label())); 382 entry->Append(new StringValue(card->Label()));
428 int res = CreditCardTypeToResourceID((*i)->type()); 383 entry->Append(new StringValue(
429 entry->Append( 384 webui::GetBitmapDataUrlFromResource(card->IconResourceId())));
430 new StringValue(webui::GetBitmapDataUrlFromResource(res))); 385 entry->Append(new StringValue(card->TypeForDisplay()));
431 entry->Append(new StringValue(LocalizedCreditCardType((*i)->type())));
432 credit_cards.Append(entry); 386 credit_cards.Append(entry);
433 } 387 }
434 388
435 web_ui()->CallJavascriptFunction("AutofillOptions.setCreditCardList", 389 web_ui()->CallJavascriptFunction("AutofillOptions.setCreditCardList",
436 credit_cards); 390 credit_cards);
437 } 391 }
438 392
439 void AutofillOptionsHandler::RemoveData(const ListValue* args) { 393 void AutofillOptionsHandler::RemoveData(const ListValue* args) {
440 DCHECK(IsPersonalDataLoaded()); 394 DCHECK(IsPersonalDataLoaded());
441 395
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 570
617 web_ui()->CallJavascriptFunction( 571 web_ui()->CallJavascriptFunction(
618 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); 572 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value);
619 } 573 }
620 574
621 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { 575 bool AutofillOptionsHandler::IsPersonalDataLoaded() const {
622 return personal_data_ && personal_data_->IsDataLoaded(); 576 return personal_data_ && personal_data_->IsDataLoaded();
623 } 577 }
624 578
625 } // namespace options 579 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_dialog_views.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698