OLD | NEW |
---|---|
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 case SECTION_BILLING: | 252 case SECTION_BILLING: |
253 return "billing"; | 253 return "billing"; |
254 | 254 |
255 case SECTION_CC_BILLING: | 255 case SECTION_CC_BILLING: |
256 // The SECTION_CC_BILLING section isn't active when using Autofill. | 256 // The SECTION_CC_BILLING section isn't active when using Autofill. |
257 NOTREACHED(); | 257 NOTREACHED(); |
258 return std::string(); | 258 return std::string(); |
259 | 259 |
260 case SECTION_SHIPPING: | 260 case SECTION_SHIPPING: |
261 return "shipping"; | 261 return "shipping"; |
262 | |
263 case SECTION_EMAIL: | |
264 return "email"; | |
265 } | 262 } |
266 | 263 |
267 NOTREACHED(); | 264 NOTREACHED(); |
268 return std::string(); | 265 return std::string(); |
269 } | 266 } |
270 | 267 |
271 // Check if a given MaskedInstrument is allowed for the purchase. | 268 // Check if a given MaskedInstrument is allowed for the purchase. |
272 bool IsInstrumentAllowed( | 269 bool IsInstrumentAllowed( |
273 const wallet::WalletItems::MaskedInstrument& instrument) { | 270 const wallet::WalletItems::MaskedInstrument& instrument) { |
274 switch (instrument.status()) { | 271 switch (instrument.status()) { |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 form_structure_.ParseFieldTypesFromAutocompleteAttributes( | 583 form_structure_.ParseFieldTypesFromAutocompleteAttributes( |
587 &has_types, &has_sections); | 584 &has_types, &has_sections); |
588 | 585 |
589 // Fail if the author didn't specify autocomplete types. | 586 // Fail if the author didn't specify autocomplete types. |
590 if (!has_types) { | 587 if (!has_types) { |
591 callback_.Run(NULL, std::string()); | 588 callback_.Run(NULL, std::string()); |
592 delete this; | 589 delete this; |
593 return; | 590 return; |
594 } | 591 } |
595 | 592 |
596 common::BuildInputsForSection(SECTION_EMAIL, | |
597 &requested_email_fields_); | |
598 common::BuildInputsForSection(SECTION_CC, | 593 common::BuildInputsForSection(SECTION_CC, |
599 &requested_cc_fields_); | 594 &requested_cc_fields_); |
600 common::BuildInputsForSection(SECTION_BILLING, | 595 common::BuildInputsForSection(SECTION_BILLING, |
601 &requested_billing_fields_); | 596 &requested_billing_fields_); |
602 common::BuildInputsForSection(SECTION_CC_BILLING, | 597 common::BuildInputsForSection(SECTION_CC_BILLING, |
603 &requested_cc_billing_fields_); | 598 &requested_cc_billing_fields_); |
604 common::BuildInputsForSection(SECTION_SHIPPING, | 599 common::BuildInputsForSection(SECTION_SHIPPING, |
605 &requested_shipping_fields_); | 600 &requested_shipping_fields_); |
606 | 601 |
607 // Test whether we need to show the shipping section. If filling that section | 602 // Test whether we need to show the shipping section. If filling that section |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1103 } | 1098 } |
1104 } | 1099 } |
1105 | 1100 |
1106 if (should_update) | 1101 if (should_update) |
1107 view_->UpdateForErrors(); | 1102 view_->UpdateForErrors(); |
1108 } | 1103 } |
1109 | 1104 |
1110 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( | 1105 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( |
1111 DialogSection section) const { | 1106 DialogSection section) const { |
1112 switch (section) { | 1107 switch (section) { |
1113 case SECTION_EMAIL: | |
1114 return requested_email_fields_; | |
1115 case SECTION_CC: | 1108 case SECTION_CC: |
1116 return requested_cc_fields_; | 1109 return requested_cc_fields_; |
1117 case SECTION_BILLING: | 1110 case SECTION_BILLING: |
1118 return requested_billing_fields_; | 1111 return requested_billing_fields_; |
1119 case SECTION_CC_BILLING: | 1112 case SECTION_CC_BILLING: |
1120 return requested_cc_billing_fields_; | 1113 return requested_cc_billing_fields_; |
1121 case SECTION_SHIPPING: | 1114 case SECTION_SHIPPING: |
1122 return requested_shipping_fields_; | 1115 return requested_shipping_fields_; |
1123 } | 1116 } |
1124 | 1117 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1196 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 1189 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
1197 IDR_WALLET_LOGO); | 1190 IDR_WALLET_LOGO); |
1198 } | 1191 } |
1199 | 1192 |
1200 return gfx::Image(); | 1193 return gfx::Image(); |
1201 } | 1194 } |
1202 | 1195 |
1203 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) | 1196 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) |
1204 const { | 1197 const { |
1205 switch (section) { | 1198 switch (section) { |
1206 case SECTION_EMAIL: | |
1207 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_EMAIL); | |
1208 case SECTION_CC: | 1199 case SECTION_CC: |
1209 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC); | 1200 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC); |
1210 case SECTION_BILLING: | 1201 case SECTION_BILLING: |
1211 case SECTION_CC_BILLING: | 1202 case SECTION_CC_BILLING: |
1212 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_BILLING); | 1203 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_BILLING); |
1213 case SECTION_SHIPPING: | 1204 case SECTION_SHIPPING: |
1214 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); | 1205 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); |
1215 default: | |
1216 NOTREACHED(); | |
1217 return string16(); | |
1218 } | 1206 } |
1207 NOTREACHED(); | |
1208 return string16(); | |
1219 } | 1209 } |
1220 | 1210 |
1221 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( | 1211 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( |
1222 DialogSection section) { | 1212 DialogSection section) { |
1223 string16 vertically_compact, horizontally_compact; | 1213 string16 vertically_compact, horizontally_compact; |
1224 bool show_suggestion = SuggestionTextForSection(section, | 1214 bool show_suggestion = SuggestionTextForSection(section, |
1225 &vertically_compact, | 1215 &vertically_compact, |
1226 &horizontally_compact); | 1216 &horizontally_compact); |
1227 return SuggestionState(show_suggestion, | 1217 return SuggestionState(show_suggestion, |
1228 vertically_compact, | 1218 vertically_compact, |
(...skipping 23 matching lines...) Expand all Loading... | |
1252 std::string item_key = model->GetItemKeyForCheckedItem(); | 1242 std::string item_key = model->GetItemKeyForCheckedItem(); |
1253 if (item_key == kSameAsBillingKey) { | 1243 if (item_key == kSameAsBillingKey) { |
1254 *vertically_compact = *horizontally_compact = l10n_util::GetStringUTF16( | 1244 *vertically_compact = *horizontally_compact = l10n_util::GetStringUTF16( |
1255 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); | 1245 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); |
1256 return true; | 1246 return true; |
1257 } | 1247 } |
1258 | 1248 |
1259 if (!IsASuggestionItemKey(item_key)) | 1249 if (!IsASuggestionItemKey(item_key)) |
1260 return false; | 1250 return false; |
1261 | 1251 |
1262 if (section == SECTION_EMAIL) { | |
1263 *vertically_compact = *horizontally_compact = | |
1264 model->GetLabelAt(model->checked_item()); | |
1265 return true; | |
1266 } | |
1267 | |
1268 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1252 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
1269 return wrapper->GetDisplayText(vertically_compact, horizontally_compact); | 1253 return wrapper->GetDisplayText(vertically_compact, horizontally_compact); |
1270 } | 1254 } |
1271 | 1255 |
1272 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( | 1256 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( |
1273 DialogSection section) const { | 1257 DialogSection section) const { |
1274 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1258 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1275 const wallet::WalletItems::MaskedInstrument* current_instrument = | 1259 const wallet::WalletItems::MaskedInstrument* current_instrument = |
1276 wallet_items_->GetInstrumentById(active_instrument_id_); | 1260 wallet_items_->GetInstrumentById(active_instrument_id_); |
1277 if (current_instrument) | 1261 if (current_instrument) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1374 | 1358 |
1375 if (section == SECTION_CC) { | 1359 if (section == SECTION_CC) { |
1376 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); | 1360 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); |
1377 DCHECK(card); | 1361 DCHECK(card); |
1378 return scoped_ptr<DataModelWrapper>(new AutofillCreditCardWrapper(card)); | 1362 return scoped_ptr<DataModelWrapper>(new AutofillCreditCardWrapper(card)); |
1379 } | 1363 } |
1380 | 1364 |
1381 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); | 1365 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); |
1382 DCHECK(profile); | 1366 DCHECK(profile); |
1383 size_t variant = GetSelectedVariantForModel(*model); | 1367 size_t variant = GetSelectedVariantForModel(*model); |
1368 if (section == SECTION_SHIPPING) { | |
1369 return scoped_ptr<DataModelWrapper>( | |
1370 new AutofillShippingAddressWrapper(profile, variant)); | |
1371 } | |
Evan Stade
2013/09/05 16:54:09
DCHECK_EQ(SECTION_BILLING, section)?
Ilya Sherman
2013/09/06 04:16:05
Done.
| |
1384 return scoped_ptr<DataModelWrapper>( | 1372 return scoped_ptr<DataModelWrapper>( |
1385 new AutofillProfileWrapper(profile, variant)); | 1373 new AutofillProfileWrapper(profile, variant)); |
1386 } | 1374 } |
1387 | 1375 |
1388 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( | 1376 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( |
1389 DialogSection section) { | 1377 DialogSection section) { |
1390 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); | 1378 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
1391 if (!model.get()) | 1379 if (!model.get()) |
1392 return gfx::Image(); | 1380 return gfx::Image(); |
1393 | 1381 |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2232 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2220 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
2233 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2221 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
2234 dialog_type_(dialog_type), | 2222 dialog_type_(dialog_type), |
2235 form_structure_(form_structure), | 2223 form_structure_(form_structure), |
2236 invoked_from_same_origin_(true), | 2224 invoked_from_same_origin_(true), |
2237 source_url_(source_url), | 2225 source_url_(source_url), |
2238 callback_(callback), | 2226 callback_(callback), |
2239 account_chooser_model_(this, profile_->GetPrefs(), metric_logger_, | 2227 account_chooser_model_(this, profile_->GetPrefs(), metric_logger_, |
2240 dialog_type), | 2228 dialog_type), |
2241 wallet_client_(profile_->GetRequestContext(), this), | 2229 wallet_client_(profile_->GetRequestContext(), this), |
2242 suggested_email_(this), | |
2243 suggested_cc_(this), | 2230 suggested_cc_(this), |
2244 suggested_billing_(this), | 2231 suggested_billing_(this), |
2245 suggested_cc_billing_(this), | 2232 suggested_cc_billing_(this), |
2246 suggested_shipping_(this), | 2233 suggested_shipping_(this), |
2247 cares_about_shipping_(true), | 2234 cares_about_shipping_(true), |
2248 input_showing_popup_(NULL), | 2235 input_showing_popup_(NULL), |
2249 weak_ptr_factory_(this), | 2236 weak_ptr_factory_(this), |
2250 should_show_wallet_promo_(!profile_->GetPrefs()->GetBoolean( | 2237 should_show_wallet_promo_(!profile_->GetPrefs()->GetBoolean( |
2251 ::prefs::kAutofillDialogHasPaidWithWallet)), | 2238 ::prefs::kAutofillDialogHasPaidWithWallet)), |
2252 has_shown_wallet_usage_confirmation_(false), | 2239 has_shown_wallet_usage_confirmation_(false), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2352 SetIsSubmitting(false); | 2339 SetIsSubmitting(false); |
2353 wallet_error_notification_ = GetWalletError(error_type); | 2340 wallet_error_notification_ = GetWalletError(error_type); |
2354 account_chooser_model_.SetHadWalletError(); | 2341 account_chooser_model_.SetHadWalletError(); |
2355 } | 2342 } |
2356 | 2343 |
2357 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 2344 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
2358 ScopedViewUpdates updates(view_.get()); | 2345 ScopedViewUpdates updates(view_.get()); |
2359 | 2346 |
2360 const DetailOutputMap snapshot = TakeUserInputSnapshot(); | 2347 const DetailOutputMap snapshot = TakeUserInputSnapshot(); |
2361 | 2348 |
2362 suggested_email_.Reset(); | |
2363 suggested_cc_.Reset(); | 2349 suggested_cc_.Reset(); |
2364 suggested_billing_.Reset(); | 2350 suggested_billing_.Reset(); |
2365 suggested_cc_billing_.Reset(); | 2351 suggested_cc_billing_.Reset(); |
2366 suggested_shipping_.Reset(); | 2352 suggested_shipping_.Reset(); |
2367 HidePopup(); | 2353 HidePopup(); |
2368 | 2354 |
2369 suggested_shipping_.AddKeyedItem( | 2355 suggested_shipping_.AddKeyedItem( |
2370 kSameAsBillingKey, | 2356 kSameAsBillingKey, |
2371 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); | 2357 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); |
2372 | 2358 |
2373 if (IsPayingWithWallet()) { | 2359 if (IsPayingWithWallet()) { |
2374 if (!account_chooser_model_.active_wallet_account_name().empty()) { | |
2375 suggested_email_.AddKeyedItem( | |
2376 base::IntToString(0), | |
2377 account_chooser_model_.active_wallet_account_name()); | |
2378 } | |
2379 | |
2380 const std::vector<wallet::Address*>& addresses = | 2360 const std::vector<wallet::Address*>& addresses = |
2381 wallet_items_->addresses(); | 2361 wallet_items_->addresses(); |
2382 for (size_t i = 0; i < addresses.size(); ++i) { | 2362 for (size_t i = 0; i < addresses.size(); ++i) { |
2383 std::string key = base::IntToString(i); | 2363 std::string key = base::IntToString(i); |
2384 suggested_shipping_.AddKeyedItemWithSublabel( | 2364 suggested_shipping_.AddKeyedItemWithSublabel( |
2385 key, | 2365 key, |
2386 addresses[i]->DisplayName(), | 2366 addresses[i]->DisplayName(), |
2387 addresses[i]->DisplayNameDetail()); | 2367 addresses[i]->DisplayNameDetail()); |
2388 | 2368 |
2389 const std::string default_shipping_address_id = | 2369 const std::string default_shipping_address_id = |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2464 cards[i]->guid(), | 2444 cards[i]->guid(), |
2465 cards[i]->Label(), | 2445 cards[i]->Label(), |
2466 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); | 2446 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); |
2467 } | 2447 } |
2468 | 2448 |
2469 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); | 2449 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
2470 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 2450 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
2471 for (size_t i = 0; i < profiles.size(); ++i) { | 2451 for (size_t i = 0; i < profiles.size(); ++i) { |
2472 if (!HasCompleteAndVerifiedData(*profiles[i], | 2452 if (!HasCompleteAndVerifiedData(*profiles[i], |
2473 requested_shipping_fields_) || | 2453 requested_shipping_fields_) || |
2454 profiles[i]->GetRawInfo(EMAIL_ADDRESS).empty() || | |
Evan Stade
2013/09/05 16:54:09
I feel like this should be covered in one of the o
Ilya Sherman
2013/09/06 04:16:05
Moved to only affect the billing section.
| |
2474 HasInvalidAddress(*profiles[i])) { | 2455 HasInvalidAddress(*profiles[i])) { |
2475 continue; | 2456 continue; |
2476 } | 2457 } |
2477 | 2458 |
2478 // Add all email addresses. | 2459 // Don't add variants for addresses: name is part of credit card and we'll |
2479 std::vector<string16> values; | 2460 // just ignore email and phone number variants. |
Evan Stade
2013/09/05 16:54:09
:/
Ilya Sherman
2013/09/06 04:16:05
I dunno, are email addresses more important than p
Evan Stade
2013/09/06 21:41:00
I'd rather not drop either, but only dropping one
| |
2480 profiles[i]->GetMultiInfo( | |
2481 AutofillType(EMAIL_ADDRESS), app_locale, &values); | |
2482 for (size_t j = 0; j < values.size(); ++j) { | |
2483 if (IsValidEmailAddress(values[j])) | |
2484 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]); | |
2485 } | |
2486 | |
2487 // Don't add variants for addresses: the email variants are handled above, | |
2488 // name is part of credit card and we'll just ignore phone number | |
2489 // variants. | |
2490 suggested_billing_.AddKeyedItem(profiles[i]->guid(), | 2461 suggested_billing_.AddKeyedItem(profiles[i]->guid(), |
2491 profiles[i]->Label()); | 2462 profiles[i]->Label()); |
2492 suggested_shipping_.AddKeyedItem(profiles[i]->guid(), | 2463 suggested_shipping_.AddKeyedItem(profiles[i]->guid(), |
2493 profiles[i]->Label()); | 2464 profiles[i]->Label()); |
2494 } | 2465 } |
2495 | 2466 |
2496 suggested_cc_.AddKeyedItem( | 2467 suggested_cc_.AddKeyedItem( |
2497 kAddNewItemKey, | 2468 kAddNewItemKey, |
2498 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD)); | 2469 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD)); |
2499 suggested_cc_.AddKeyedItem( | 2470 suggested_cc_.AddKeyedItem( |
2500 kManageItemsKey, | 2471 kManageItemsKey, |
2501 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_CREDIT_CARD)); | 2472 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_CREDIT_CARD)); |
2502 suggested_billing_.AddKeyedItem( | 2473 suggested_billing_.AddKeyedItem( |
2503 kAddNewItemKey, | 2474 kAddNewItemKey, |
2504 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS)); | 2475 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS)); |
2505 suggested_billing_.AddKeyedItem( | 2476 suggested_billing_.AddKeyedItem( |
2506 kManageItemsKey, | 2477 kManageItemsKey, |
2507 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_BILLING_ADDRESS)); | 2478 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_BILLING_ADDRESS)); |
2508 } | 2479 } |
2509 | 2480 |
2510 suggested_email_.AddKeyedItem( | |
2511 kAddNewItemKey, | |
2512 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS)); | |
2513 if (!IsPayingWithWallet()) { | |
2514 suggested_email_.AddKeyedItem( | |
2515 kManageItemsKey, | |
2516 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_EMAIL_ADDRESS)); | |
2517 } | |
2518 | |
2519 suggested_shipping_.AddKeyedItem( | 2481 suggested_shipping_.AddKeyedItem( |
2520 kAddNewItemKey, | 2482 kAddNewItemKey, |
2521 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); | 2483 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); |
2522 if (!IsPayingWithWallet()) { | 2484 if (!IsPayingWithWallet()) { |
2523 suggested_shipping_.AddKeyedItem( | 2485 suggested_shipping_.AddKeyedItem( |
2524 kManageItemsKey, | 2486 kManageItemsKey, |
2525 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); | 2487 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); |
2526 } else if (!wallet_items_->HasRequiredAction(wallet::SETUP_WALLET)) { | 2488 } else if (!wallet_items_->HasRequiredAction(wallet::SETUP_WALLET)) { |
2527 suggested_shipping_.AddKeyedItemWithSublabel( | 2489 suggested_shipping_.AddKeyedItemWithSublabel( |
2528 kManageItemsKey, | 2490 kManageItemsKey, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2564 } | 2526 } |
2565 | 2527 |
2566 UpdateForErrors(); | 2528 UpdateForErrors(); |
2567 } | 2529 } |
2568 | 2530 |
2569 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 2531 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
2570 DialogSection section, | 2532 DialogSection section, |
2571 const InputFieldComparator& compare) { | 2533 const InputFieldComparator& compare) { |
2572 const DetailInputs& inputs = RequestedFieldsForSection(section); | 2534 const DetailInputs& inputs = RequestedFieldsForSection(section); |
2573 | 2535 |
2574 // Email is hidden while using Wallet, special case it. | |
2575 if (section == SECTION_EMAIL && IsPayingWithWallet()) { | |
2576 AutofillProfile profile; | |
2577 profile.SetRawInfo(EMAIL_ADDRESS, | |
2578 account_chooser_model_.active_wallet_account_name()); | |
2579 AutofillProfileWrapper profile_wrapper(&profile, 0); | |
2580 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); | |
2581 return; | |
2582 } | |
2583 | |
2584 if (!SectionIsActive(section)) | 2536 if (!SectionIsActive(section)) |
2585 return; | 2537 return; |
2586 | 2538 |
2587 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 2539 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
2588 if (wrapper) { | 2540 if (wrapper) { |
2589 // Only fill in data that is associated with this section. | 2541 // Only fill in data that is associated with this section. |
2590 const DetailInputs& inputs = RequestedFieldsForSection(section); | 2542 const DetailInputs& inputs = RequestedFieldsForSection(section); |
2591 wrapper->FillFormStructure(inputs, compare, &form_structure_); | 2543 wrapper->FillFormStructure(inputs, compare, &form_structure_); |
2592 | 2544 |
2593 // CVC needs special-casing because the CreditCard class doesn't store or | 2545 // CVC needs special-casing because the CreditCard class doesn't store or |
2594 // handle them. This isn't necessary when filling the combined CC and | 2546 // handle them. This isn't necessary when filling the combined CC and |
2595 // billing section as CVC comes from |full_wallet_| in this case. | 2547 // billing section as CVC comes from |full_wallet_| in this case. |
2596 if (section == SECTION_CC) | 2548 if (section == SECTION_CC) |
2597 SetCvcResult(view_->GetCvc()); | 2549 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc()); |
2550 | |
2551 // When filling from Wallet data, use the email address associated with the | |
2552 // account. There is no other email address stored as part of a Wallet | |
2553 // address. | |
2554 if (section == SECTION_CC_BILLING) { | |
2555 SetOutputForFieldsOfType( | |
2556 EMAIL_ADDRESS, account_chooser_model_.active_wallet_account_name()); | |
2557 } | |
2598 } else { | 2558 } else { |
2599 // The user manually input data. If using Autofill, save the info as new or | 2559 // The user manually input data. If using Autofill, save the info as new or |
2600 // edited data. Always fill local data into |form_structure_|. | 2560 // edited data. Always fill local data into |form_structure_|. |
2601 DetailOutputMap output; | 2561 DetailOutputMap output; |
2602 view_->GetUserInput(section, &output); | 2562 view_->GetUserInput(section, &output); |
2603 | 2563 |
2604 if (section == SECTION_CC) { | 2564 if (section == SECTION_CC) { |
2605 CreditCard card; | 2565 CreditCard card; |
2606 card.set_origin(kAutofillDialogOrigin); | 2566 card.set_origin(kAutofillDialogOrigin); |
2607 FillFormGroupFromOutputs(output, &card); | 2567 FillFormGroupFromOutputs(output, &card); |
2608 | 2568 |
2609 // The card holder name comes from the billing address section. | 2569 // The card holder name comes from the billing address section. |
2610 card.SetRawInfo(CREDIT_CARD_NAME, | 2570 card.SetRawInfo(CREDIT_CARD_NAME, |
2611 GetValueFromSection(SECTION_BILLING, NAME_FULL)); | 2571 GetValueFromSection(SECTION_BILLING, NAME_FULL)); |
2612 | 2572 |
2613 if (ShouldSaveDetailsLocally()) { | 2573 if (ShouldSaveDetailsLocally()) { |
2614 GetManager()->SaveImportedCreditCard(card); | 2574 GetManager()->SaveImportedCreditCard(card); |
2615 DCHECK(!profile()->IsOffTheRecord()); | 2575 DCHECK(!profile()->IsOffTheRecord()); |
2616 newly_saved_card_.reset(new CreditCard(card)); | 2576 newly_saved_card_.reset(new CreditCard(card)); |
2617 } | 2577 } |
2618 | 2578 |
2619 AutofillCreditCardWrapper card_wrapper(&card); | 2579 AutofillCreditCardWrapper card_wrapper(&card); |
2620 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2580 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
2621 | 2581 |
2622 // Again, CVC needs special-casing. Fill it in directly from |output|. | 2582 // Again, CVC needs special-casing. Fill it in directly from |output|. |
2623 SetCvcResult(GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); | 2583 SetOutputForFieldsOfType( |
2584 CREDIT_CARD_VERIFICATION_CODE, | |
2585 GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); | |
2624 } else { | 2586 } else { |
2625 AutofillProfile profile; | 2587 AutofillProfile profile; |
2626 profile.set_origin(kAutofillDialogOrigin); | 2588 profile.set_origin(kAutofillDialogOrigin); |
2627 FillFormGroupFromOutputs(output, &profile); | 2589 FillFormGroupFromOutputs(output, &profile); |
2628 | 2590 |
2629 // For billing, the email address comes from the separate email section. | |
2630 if (section == SECTION_BILLING) { | |
2631 profile.SetRawInfo(EMAIL_ADDRESS, | |
2632 GetValueFromSection(SECTION_EMAIL, EMAIL_ADDRESS)); | |
2633 } | |
2634 | |
2635 if (ShouldSaveDetailsLocally()) | 2591 if (ShouldSaveDetailsLocally()) |
2636 SaveProfileGleanedFromSection(profile, section); | 2592 SaveProfileGleanedFromSection(profile, section); |
2637 | 2593 |
2638 AutofillProfileWrapper profile_wrapper(&profile, 0); | 2594 AutofillProfileWrapper profile_wrapper(&profile, 0); |
2639 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2595 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
2640 } | 2596 } |
2641 } | 2597 } |
2642 } | 2598 } |
2643 | 2599 |
2644 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 2600 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
2645 FillOutputForSectionWithComparator( | 2601 FillOutputForSectionWithComparator( |
2646 section, base::Bind(common::DetailInputMatchesField, section)); | 2602 section, base::Bind(common::DetailInputMatchesField, section)); |
2647 } | 2603 } |
2648 | 2604 |
2649 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( | 2605 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( |
2650 DialogSection section) const { | 2606 DialogSection section) const { |
2651 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for | 2607 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for |
2652 // any of the fields. | 2608 // any of the fields. |
2653 if (section == SECTION_SHIPPING) | 2609 if (section == SECTION_SHIPPING) |
2654 return cares_about_shipping_; | 2610 return cares_about_shipping_; |
2655 | 2611 |
2656 return true; | 2612 return true; |
2657 } | 2613 } |
2658 | 2614 |
2659 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { | 2615 void AutofillDialogControllerImpl::SetOutputForFieldsOfType( |
2616 ServerFieldType type, | |
2617 const base::string16& output) { | |
2660 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 2618 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
2661 AutofillField* field = form_structure_.field(i); | 2619 AutofillField* field = form_structure_.field(i); |
2662 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE) { | 2620 if (field->Type().GetStorableType() == type) |
2663 field->value = cvc; | 2621 field->value = output; |
2664 break; | |
2665 } | |
2666 } | 2622 } |
2667 } | 2623 } |
2668 | 2624 |
2669 string16 AutofillDialogControllerImpl::GetValueFromSection( | 2625 string16 AutofillDialogControllerImpl::GetValueFromSection( |
2670 DialogSection section, | 2626 DialogSection section, |
2671 ServerFieldType type) { | 2627 ServerFieldType type) { |
2672 DCHECK(SectionIsActive(section)); | 2628 DCHECK(SectionIsActive(section)); |
2673 | 2629 |
2674 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 2630 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
2675 if (wrapper) | 2631 if (wrapper) |
2676 return wrapper->GetInfo(AutofillType(type)); | 2632 return wrapper->GetInfo(AutofillType(type)); |
2677 | 2633 |
2678 DetailOutputMap output; | 2634 DetailOutputMap output; |
2679 view_->GetUserInput(section, &output); | 2635 view_->GetUserInput(section, &output); |
2680 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); | 2636 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); |
2681 ++iter) { | 2637 ++iter) { |
2682 if (iter->first->type == type) | 2638 if (iter->first->type == type) |
2683 return iter->second; | 2639 return iter->second; |
2684 } | 2640 } |
2685 | 2641 |
2686 return string16(); | 2642 return string16(); |
2687 } | 2643 } |
2688 | 2644 |
2689 void AutofillDialogControllerImpl::SaveProfileGleanedFromSection( | 2645 void AutofillDialogControllerImpl::SaveProfileGleanedFromSection( |
2690 const AutofillProfile& profile, | 2646 const AutofillProfile& profile, |
2691 DialogSection section) { | 2647 DialogSection section) { |
2692 if (section == SECTION_EMAIL) { | 2648 GetManager()->SaveImportedProfile(profile); |
2693 // Save the email address to the existing (suggested) billing profile. If | |
2694 // there is no existing profile, the newly created one will pick up this | |
2695 // email, so in that case do nothing. | |
2696 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(SECTION_BILLING); | |
2697 if (wrapper) { | |
2698 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> | |
2699 GetItemKeyForCheckedItem(); | |
2700 AutofillProfile* billing_profile = | |
2701 GetManager()->GetProfileByGUID(item_key); | |
2702 billing_profile->OverwriteWithOrAddTo( | |
2703 profile, | |
2704 g_browser_process->GetApplicationLocale()); | |
2705 } | |
2706 } else { | |
2707 GetManager()->SaveImportedProfile(profile); | |
2708 } | |
2709 } | 2649 } |
2710 | 2650 |
2711 SuggestionsMenuModel* AutofillDialogControllerImpl:: | 2651 SuggestionsMenuModel* AutofillDialogControllerImpl:: |
2712 SuggestionsMenuModelForSection(DialogSection section) { | 2652 SuggestionsMenuModelForSection(DialogSection section) { |
2713 switch (section) { | 2653 switch (section) { |
2714 case SECTION_EMAIL: | |
2715 return &suggested_email_; | |
2716 case SECTION_CC: | 2654 case SECTION_CC: |
2717 return &suggested_cc_; | 2655 return &suggested_cc_; |
2718 case SECTION_BILLING: | 2656 case SECTION_BILLING: |
2719 return &suggested_billing_; | 2657 return &suggested_billing_; |
2720 case SECTION_SHIPPING: | 2658 case SECTION_SHIPPING: |
2721 return &suggested_shipping_; | 2659 return &suggested_shipping_; |
2722 case SECTION_CC_BILLING: | 2660 case SECTION_CC_BILLING: |
2723 return &suggested_cc_billing_; | 2661 return &suggested_cc_billing_; |
2724 } | 2662 } |
2725 | 2663 |
2726 NOTREACHED(); | 2664 NOTREACHED(); |
2727 return NULL; | 2665 return NULL; |
2728 } | 2666 } |
2729 | 2667 |
2730 const SuggestionsMenuModel* AutofillDialogControllerImpl:: | 2668 const SuggestionsMenuModel* AutofillDialogControllerImpl:: |
2731 SuggestionsMenuModelForSection(DialogSection section) const { | 2669 SuggestionsMenuModelForSection(DialogSection section) const { |
2732 return const_cast<AutofillDialogControllerImpl*>(this)-> | 2670 return const_cast<AutofillDialogControllerImpl*>(this)-> |
2733 SuggestionsMenuModelForSection(section); | 2671 SuggestionsMenuModelForSection(section); |
2734 } | 2672 } |
2735 | 2673 |
2736 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel( | 2674 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel( |
2737 const SuggestionsMenuModel& model) { | 2675 const SuggestionsMenuModel& model) { |
2738 if (&model == &suggested_email_) | |
2739 return SECTION_EMAIL; | |
2740 | |
2741 if (&model == &suggested_cc_) | 2676 if (&model == &suggested_cc_) |
2742 return SECTION_CC; | 2677 return SECTION_CC; |
2743 | 2678 |
2744 if (&model == &suggested_billing_) | 2679 if (&model == &suggested_billing_) |
2745 return SECTION_BILLING; | 2680 return SECTION_BILLING; |
2746 | 2681 |
2747 if (&model == &suggested_cc_billing_) | 2682 if (&model == &suggested_cc_billing_) |
2748 return SECTION_CC_BILLING; | 2683 return SECTION_CC_BILLING; |
2749 | 2684 |
2750 DCHECK_EQ(&model, &suggested_shipping_); | 2685 DCHECK_EQ(&model, &suggested_shipping_); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3052 // TODO(estade): implement overlays on other platforms. | 2987 // TODO(estade): implement overlays on other platforms. |
3053 OverlayButtonPressed(); | 2988 OverlayButtonPressed(); |
3054 #endif | 2989 #endif |
3055 return; | 2990 return; |
3056 } else { | 2991 } else { |
3057 profile_->GetPrefs()->SetBoolean( | 2992 profile_->GetPrefs()->SetBoolean( |
3058 ::prefs::kAutofillDialogHasPaidWithWallet, true); | 2993 ::prefs::kAutofillDialogHasPaidWithWallet, true); |
3059 } | 2994 } |
3060 } | 2995 } |
3061 | 2996 |
3062 FillOutputForSection(SECTION_EMAIL); | |
3063 FillOutputForSection(SECTION_CC); | 2997 FillOutputForSection(SECTION_CC); |
3064 FillOutputForSection(SECTION_BILLING); | 2998 FillOutputForSection(SECTION_BILLING); |
3065 FillOutputForSection(SECTION_CC_BILLING); | 2999 FillOutputForSection(SECTION_CC_BILLING); |
3066 | 3000 |
3067 if (ShouldUseBillingForShipping()) { | 3001 if (ShouldUseBillingForShipping()) { |
3068 FillOutputForSectionWithComparator( | 3002 FillOutputForSectionWithComparator( |
3069 SECTION_BILLING, | 3003 SECTION_BILLING, |
3070 base::Bind(DetailInputMatchesShippingField)); | 3004 base::Bind(DetailInputMatchesShippingField)); |
3071 FillOutputForSectionWithComparator( | 3005 FillOutputForSectionWithComparator( |
3072 SECTION_CC, | 3006 SECTION_CC, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3297 billing_profile.reset(new AutofillProfile); | 3231 billing_profile.reset(new AutofillProfile); |
3298 FillFormGroupFromOutputs(outputs, billing_profile.get()); | 3232 FillFormGroupFromOutputs(outputs, billing_profile.get()); |
3299 } else { | 3233 } else { |
3300 // Just snag the currently suggested profile. | 3234 // Just snag the currently suggested profile. |
3301 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> | 3235 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> |
3302 GetItemKeyForCheckedItem(); | 3236 GetItemKeyForCheckedItem(); |
3303 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); | 3237 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); |
3304 billing_profile.reset(new AutofillProfile(*profile)); | 3238 billing_profile.reset(new AutofillProfile(*profile)); |
3305 } | 3239 } |
3306 | 3240 |
3307 // The bubble also needs the associated email address. | |
3308 billing_profile->SetRawInfo( | |
3309 EMAIL_ADDRESS, | |
3310 GetValueFromSection(SECTION_EMAIL, EMAIL_ADDRESS)); | |
3311 | |
3312 ShowNewCreditCardBubble(newly_saved_card_.Pass(), | 3241 ShowNewCreditCardBubble(newly_saved_card_.Pass(), |
3313 billing_profile.Pass()); | 3242 billing_profile.Pass()); |
3314 return; | 3243 return; |
3315 } | 3244 } |
3316 | 3245 |
3317 if (!full_wallet_ || !full_wallet_->billing_address()) | 3246 if (!full_wallet_ || !full_wallet_->billing_address()) |
3318 return; | 3247 return; |
3319 | 3248 |
3320 base::string16 backing_last_four; | 3249 base::string16 backing_last_four; |
3321 if (ActiveInstrument()) { | 3250 if (ActiveInstrument()) { |
3322 backing_last_four = ActiveInstrument()->TypeAndLastFourDigits(); | 3251 backing_last_four = ActiveInstrument()->TypeAndLastFourDigits(); |
3323 } else { | 3252 } else { |
3324 DetailOutputMap output; | 3253 DetailOutputMap output; |
3325 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3254 view_->GetUserInput(SECTION_CC_BILLING, &output); |
3326 CreditCard card; | 3255 CreditCard card; |
3327 GetBillingInfoFromOutputs(output, &card, NULL, NULL); | 3256 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
3328 backing_last_four = card.TypeAndLastFourDigits(); | 3257 backing_last_four = card.TypeAndLastFourDigits(); |
3329 } | 3258 } |
3330 #if !defined(OS_ANDROID) | 3259 #if !defined(OS_ANDROID) |
3331 GeneratedCreditCardBubbleController::Show( | 3260 GeneratedCreditCardBubbleController::Show( |
3332 web_contents(), | 3261 web_contents(), |
3333 full_wallet_->TypeAndLastFourDigits(), | 3262 full_wallet_->TypeAndLastFourDigits(), |
3334 backing_last_four); | 3263 backing_last_four); |
3335 #endif | 3264 #endif |
3336 } | 3265 } |
3337 | 3266 |
3338 } // namespace autofill | 3267 } // namespace autofill |
OLD | NEW |