OLD | NEW |
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 Loading... |
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 Loading... |
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(); |
334 } else { | 335 |
335 // TODO(estade): This doesn't display as much info as it should (for | 336 return card->TypeAndLastFourDigits(); |
336 // example, it should show full addresses rather than just a summary). | |
337 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); | |
338 if (profile) | |
339 return profile->Label(); | |
340 } | 337 } |
341 | 338 |
342 // TODO(estade): The FormGroup was likely deleted while menu was showing. We | 339 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); |
343 // should not let this happen. | 340 if (!profile) |
344 return string16(); | 341 return string16(); |
| 342 |
| 343 const std::string app_locale = AutofillCountry::ApplicationLocale(); |
| 344 string16 comma = ASCIIToUTF16(", "); |
| 345 string16 label = profile->GetInfo(NAME_FULL, app_locale) + |
| 346 comma + profile->GetInfo(ADDRESS_HOME_LINE1, app_locale); |
| 347 string16 address2 = profile->GetInfo(ADDRESS_HOME_LINE2, app_locale); |
| 348 if (!address2.empty()) |
| 349 label += comma + address2; |
| 350 label += ASCIIToUTF16("\n") + |
| 351 profile->GetInfo(ADDRESS_HOME_CITY, app_locale) + comma + |
| 352 profile->GetInfo(ADDRESS_HOME_STATE, app_locale) + ASCIIToUTF16(" ") + |
| 353 profile->GetInfo(ADDRESS_HOME_ZIP, app_locale); |
| 354 return label; |
| 355 } |
| 356 |
| 357 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( |
| 358 DialogSection section) { |
| 359 if (section != SECTION_CC) |
| 360 return gfx::Image(); |
| 361 |
| 362 std::string item_key = |
| 363 suggested_cc_.GetItemKeyAt(suggested_cc_.checked_item()); |
| 364 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); |
| 365 if (!card) |
| 366 return gfx::Image(); |
| 367 |
| 368 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 369 return rb.GetImageNamed(card->IconResourceId()); |
345 } | 370 } |
346 | 371 |
347 void AutofillDialogControllerImpl::EditClickedForSection( | 372 void AutofillDialogControllerImpl::EditClickedForSection( |
348 DialogSection section) { | 373 DialogSection section) { |
349 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 374 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
350 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 375 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
351 | 376 |
352 if (section == SECTION_EMAIL) { | 377 if (section == SECTION_EMAIL) { |
353 // TODO(estade): shouldn't need to make this check. | 378 // TODO(estade): shouldn't need to make this check. |
354 if (inputs->empty()) | 379 if (inputs->empty()) |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 } | 800 } |
776 | 801 |
777 void AutofillDialogControllerImpl::HidePopup() { | 802 void AutofillDialogControllerImpl::HidePopup() { |
778 if (popup_controller_) { | 803 if (popup_controller_) { |
779 popup_controller_->Hide(); | 804 popup_controller_->Hide(); |
780 ControllerDestroyed(); | 805 ControllerDestroyed(); |
781 } | 806 } |
782 } | 807 } |
783 | 808 |
784 } // namespace autofill | 809 } // namespace autofill |
OLD | NEW |