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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 case SECTION_BILLING: | 254 case SECTION_BILLING: |
255 return "billing"; | 255 return "billing"; |
256 | 256 |
257 case SECTION_CC_BILLING: | 257 case SECTION_CC_BILLING: |
258 // The SECTION_CC_BILLING section isn't active when using Autofill. | 258 // The SECTION_CC_BILLING section isn't active when using Autofill. |
259 NOTREACHED(); | 259 NOTREACHED(); |
260 return std::string(); | 260 return std::string(); |
261 | 261 |
262 case SECTION_SHIPPING: | 262 case SECTION_SHIPPING: |
263 return "shipping"; | 263 return "shipping"; |
264 | |
265 case SECTION_EMAIL: | |
266 return "email"; | |
267 } | 264 } |
268 | 265 |
269 NOTREACHED(); | 266 NOTREACHED(); |
270 return std::string(); | 267 return std::string(); |
271 } | 268 } |
272 | 269 |
273 // Check if a given MaskedInstrument is allowed for the purchase. | 270 // Check if a given MaskedInstrument is allowed for the purchase. |
274 bool IsInstrumentAllowed( | 271 bool IsInstrumentAllowed( |
275 const wallet::WalletItems::MaskedInstrument& instrument) { | 272 const wallet::WalletItems::MaskedInstrument& instrument) { |
276 switch (instrument.status()) { | 273 switch (instrument.status()) { |
(...skipping 17 matching lines...) Expand all Loading... |
294 | 291 |
295 // Returns whether |data_model| is complete, i.e. can fill out all the | 292 // Returns whether |data_model| is complete, i.e. can fill out all the |
296 // |requested_fields|, and verified, i.e. not just automatically aggregated. | 293 // |requested_fields|, and verified, i.e. not just automatically aggregated. |
297 // Incomplete or unverifed data will not be displayed in the dropdown menu. | 294 // Incomplete or unverifed data will not be displayed in the dropdown menu. |
298 bool HasCompleteAndVerifiedData(const AutofillDataModel& data_model, | 295 bool HasCompleteAndVerifiedData(const AutofillDataModel& data_model, |
299 const DetailInputs& requested_fields) { | 296 const DetailInputs& requested_fields) { |
300 if (!data_model.IsVerified()) | 297 if (!data_model.IsVerified()) |
301 return false; | 298 return false; |
302 | 299 |
303 for (size_t i = 0; i < requested_fields.size(); ++i) { | 300 for (size_t i = 0; i < requested_fields.size(); ++i) { |
304 ServerFieldType type = requested_fields[i].type; | 301 ServerFieldType type = |
| 302 AutofillType(requested_fields[i].type).GetStorableType(); |
305 if (type != ADDRESS_HOME_LINE2 && | 303 if (type != ADDRESS_HOME_LINE2 && |
306 type != CREDIT_CARD_VERIFICATION_CODE && | 304 type != CREDIT_CARD_VERIFICATION_CODE && |
307 data_model.GetRawInfo(AutofillType(type).GetStorableType()).empty()) { | 305 data_model.GetRawInfo(type).empty()) { |
308 return false; | 306 return false; |
309 } | 307 } |
310 } | 308 } |
311 | 309 |
312 return true; | 310 return true; |
313 } | 311 } |
314 | 312 |
315 // Returns true if |profile| has an invalid address, i.e. an invalid state, zip | 313 // Returns true if |profile| has an invalid address, i.e. an invalid state, zip |
316 // code, or phone number. Otherwise returns false. Profiles with invalid | 314 // code, phone number, or email address. Otherwise returns false. Profiles with |
317 // addresses are not suggested in the dropdown menu for billing and shipping | 315 // invalid addresses are not suggested in the dropdown menu for billing and |
318 // addresses. | 316 // shipping addresses. |
319 bool HasInvalidAddress(const AutofillProfile& profile) { | 317 bool HasInvalidAddress(const AutofillProfile& profile) { |
320 return profile.IsPresentButInvalid(ADDRESS_HOME_STATE) || | 318 return profile.IsPresentButInvalid(ADDRESS_HOME_STATE) || |
321 profile.IsPresentButInvalid(ADDRESS_HOME_ZIP) || | 319 profile.IsPresentButInvalid(ADDRESS_HOME_ZIP) || |
322 profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER); | 320 profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER); |
323 } | 321 } |
324 | 322 |
325 // Loops through |addresses_| comparing to |address| ignoring ID. If a match | 323 // Loops through |addresses_| comparing to |address| ignoring ID. If a match |
326 // is not found, NULL is returned. | 324 // is not found, NULL is returned. |
327 const wallet::Address* FindDuplicateAddress( | 325 const wallet::Address* FindDuplicateAddress( |
328 const std::vector<wallet::Address*>& addresses, | 326 const std::vector<wallet::Address*>& addresses, |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 form_structure_.ParseFieldTypesFromAutocompleteAttributes( | 592 form_structure_.ParseFieldTypesFromAutocompleteAttributes( |
595 &has_types, &has_sections); | 593 &has_types, &has_sections); |
596 | 594 |
597 // Fail if the author didn't specify autocomplete types. | 595 // Fail if the author didn't specify autocomplete types. |
598 if (!has_types) { | 596 if (!has_types) { |
599 callback_.Run(NULL, std::string()); | 597 callback_.Run(NULL, std::string()); |
600 delete this; | 598 delete this; |
601 return; | 599 return; |
602 } | 600 } |
603 | 601 |
604 common::BuildInputsForSection(SECTION_EMAIL, | |
605 &requested_email_fields_); | |
606 common::BuildInputsForSection(SECTION_CC, | 602 common::BuildInputsForSection(SECTION_CC, |
607 &requested_cc_fields_); | 603 &requested_cc_fields_); |
608 common::BuildInputsForSection(SECTION_BILLING, | 604 common::BuildInputsForSection(SECTION_BILLING, |
609 &requested_billing_fields_); | 605 &requested_billing_fields_); |
610 common::BuildInputsForSection(SECTION_CC_BILLING, | 606 common::BuildInputsForSection(SECTION_CC_BILLING, |
611 &requested_cc_billing_fields_); | 607 &requested_cc_billing_fields_); |
612 common::BuildInputsForSection(SECTION_SHIPPING, | 608 common::BuildInputsForSection(SECTION_SHIPPING, |
613 &requested_shipping_fields_); | 609 &requested_shipping_fields_); |
614 | 610 |
615 // Test whether we need to show the shipping section. If filling that section | 611 // Test whether we need to show the shipping section. If filling that section |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 } | 1117 } |
1122 } | 1118 } |
1123 | 1119 |
1124 if (should_update) | 1120 if (should_update) |
1125 view_->UpdateForErrors(); | 1121 view_->UpdateForErrors(); |
1126 } | 1122 } |
1127 | 1123 |
1128 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( | 1124 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( |
1129 DialogSection section) const { | 1125 DialogSection section) const { |
1130 switch (section) { | 1126 switch (section) { |
1131 case SECTION_EMAIL: | |
1132 return requested_email_fields_; | |
1133 case SECTION_CC: | 1127 case SECTION_CC: |
1134 return requested_cc_fields_; | 1128 return requested_cc_fields_; |
1135 case SECTION_BILLING: | 1129 case SECTION_BILLING: |
1136 return requested_billing_fields_; | 1130 return requested_billing_fields_; |
1137 case SECTION_CC_BILLING: | 1131 case SECTION_CC_BILLING: |
1138 return requested_cc_billing_fields_; | 1132 return requested_cc_billing_fields_; |
1139 case SECTION_SHIPPING: | 1133 case SECTION_SHIPPING: |
1140 return requested_shipping_fields_; | 1134 return requested_shipping_fields_; |
1141 } | 1135 } |
1142 | 1136 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 1208 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
1215 IDR_WALLET_LOGO); | 1209 IDR_WALLET_LOGO); |
1216 } | 1210 } |
1217 | 1211 |
1218 return gfx::Image(); | 1212 return gfx::Image(); |
1219 } | 1213 } |
1220 | 1214 |
1221 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) | 1215 string16 AutofillDialogControllerImpl::LabelForSection(DialogSection section) |
1222 const { | 1216 const { |
1223 switch (section) { | 1217 switch (section) { |
1224 case SECTION_EMAIL: | |
1225 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_EMAIL); | |
1226 case SECTION_CC: | 1218 case SECTION_CC: |
1227 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC); | 1219 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_CC); |
1228 case SECTION_BILLING: | 1220 case SECTION_BILLING: |
1229 case SECTION_CC_BILLING: | 1221 case SECTION_CC_BILLING: |
1230 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_BILLING); | 1222 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_BILLING); |
1231 case SECTION_SHIPPING: | 1223 case SECTION_SHIPPING: |
1232 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); | 1224 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); |
1233 default: | |
1234 NOTREACHED(); | |
1235 return string16(); | |
1236 } | 1225 } |
| 1226 NOTREACHED(); |
| 1227 return string16(); |
1237 } | 1228 } |
1238 | 1229 |
1239 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( | 1230 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( |
1240 DialogSection section) { | 1231 DialogSection section) { |
1241 string16 vertically_compact, horizontally_compact; | 1232 string16 vertically_compact, horizontally_compact; |
1242 bool show_suggestion = SuggestionTextForSection(section, | 1233 bool show_suggestion = SuggestionTextForSection(section, |
1243 &vertically_compact, | 1234 &vertically_compact, |
1244 &horizontally_compact); | 1235 &horizontally_compact); |
1245 return SuggestionState(show_suggestion, | 1236 return SuggestionState(show_suggestion, |
1246 vertically_compact, | 1237 vertically_compact, |
(...skipping 23 matching lines...) Expand all Loading... |
1270 std::string item_key = model->GetItemKeyForCheckedItem(); | 1261 std::string item_key = model->GetItemKeyForCheckedItem(); |
1271 if (item_key == kSameAsBillingKey) { | 1262 if (item_key == kSameAsBillingKey) { |
1272 *vertically_compact = *horizontally_compact = l10n_util::GetStringUTF16( | 1263 *vertically_compact = *horizontally_compact = l10n_util::GetStringUTF16( |
1273 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); | 1264 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); |
1274 return true; | 1265 return true; |
1275 } | 1266 } |
1276 | 1267 |
1277 if (!IsASuggestionItemKey(item_key)) | 1268 if (!IsASuggestionItemKey(item_key)) |
1278 return false; | 1269 return false; |
1279 | 1270 |
1280 if (section == SECTION_EMAIL) { | |
1281 *vertically_compact = *horizontally_compact = | |
1282 model->GetLabelAt(model->checked_item()); | |
1283 return true; | |
1284 } | |
1285 | |
1286 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1271 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
1287 return wrapper->GetDisplayText(vertically_compact, horizontally_compact); | 1272 return wrapper->GetDisplayText(vertically_compact, horizontally_compact); |
1288 } | 1273 } |
1289 | 1274 |
1290 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( | 1275 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( |
1291 DialogSection section) const { | 1276 DialogSection section) const { |
1292 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1277 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1293 const wallet::WalletItems::MaskedInstrument* current_instrument = | 1278 const wallet::WalletItems::MaskedInstrument* current_instrument = |
1294 wallet_items_->GetInstrumentById(active_instrument_id_); | 1279 wallet_items_->GetInstrumentById(active_instrument_id_); |
1295 if (current_instrument) | 1280 if (current_instrument) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 | 1377 |
1393 if (section == SECTION_CC) { | 1378 if (section == SECTION_CC) { |
1394 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); | 1379 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); |
1395 DCHECK(card); | 1380 DCHECK(card); |
1396 return scoped_ptr<DataModelWrapper>(new AutofillCreditCardWrapper(card)); | 1381 return scoped_ptr<DataModelWrapper>(new AutofillCreditCardWrapper(card)); |
1397 } | 1382 } |
1398 | 1383 |
1399 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); | 1384 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); |
1400 DCHECK(profile); | 1385 DCHECK(profile); |
1401 size_t variant = GetSelectedVariantForModel(*model); | 1386 size_t variant = GetSelectedVariantForModel(*model); |
| 1387 if (section == SECTION_SHIPPING) { |
| 1388 return scoped_ptr<DataModelWrapper>( |
| 1389 new AutofillShippingAddressWrapper(profile, variant)); |
| 1390 } |
| 1391 DCHECK_EQ(SECTION_BILLING, section); |
1402 return scoped_ptr<DataModelWrapper>( | 1392 return scoped_ptr<DataModelWrapper>( |
1403 new AutofillProfileWrapper(profile, variant)); | 1393 new AutofillProfileWrapper(profile, variant)); |
1404 } | 1394 } |
1405 | 1395 |
1406 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( | 1396 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( |
1407 DialogSection section) { | 1397 DialogSection section) { |
1408 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); | 1398 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
1409 if (!model.get()) | 1399 if (!model.get()) |
1410 return gfx::Image(); | 1400 return gfx::Image(); |
1411 | 1401 |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2234 const std::string&)>& callback) | 2224 const std::string&)>& callback) |
2235 : WebContentsObserver(contents), | 2225 : WebContentsObserver(contents), |
2236 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2226 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
2237 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2227 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
2238 form_structure_(form_structure), | 2228 form_structure_(form_structure), |
2239 invoked_from_same_origin_(true), | 2229 invoked_from_same_origin_(true), |
2240 source_url_(source_url), | 2230 source_url_(source_url), |
2241 callback_(callback), | 2231 callback_(callback), |
2242 account_chooser_model_(this, profile_->GetPrefs(), metric_logger_), | 2232 account_chooser_model_(this, profile_->GetPrefs(), metric_logger_), |
2243 wallet_client_(profile_->GetRequestContext(), this), | 2233 wallet_client_(profile_->GetRequestContext(), this), |
2244 suggested_email_(this), | |
2245 suggested_cc_(this), | 2234 suggested_cc_(this), |
2246 suggested_billing_(this), | 2235 suggested_billing_(this), |
2247 suggested_cc_billing_(this), | 2236 suggested_cc_billing_(this), |
2248 suggested_shipping_(this), | 2237 suggested_shipping_(this), |
2249 cares_about_shipping_(true), | 2238 cares_about_shipping_(true), |
2250 input_showing_popup_(NULL), | 2239 input_showing_popup_(NULL), |
2251 weak_ptr_factory_(this), | 2240 weak_ptr_factory_(this), |
2252 should_show_wallet_promo_(!profile_->GetPrefs()->GetBoolean( | 2241 should_show_wallet_promo_(!profile_->GetPrefs()->GetBoolean( |
2253 ::prefs::kAutofillDialogHasPaidWithWallet)), | 2242 ::prefs::kAutofillDialogHasPaidWithWallet)), |
2254 has_shown_wallet_usage_confirmation_(false), | 2243 has_shown_wallet_usage_confirmation_(false), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2354 SetIsSubmitting(false); | 2343 SetIsSubmitting(false); |
2355 wallet_error_notification_ = GetWalletError(error_type); | 2344 wallet_error_notification_ = GetWalletError(error_type); |
2356 account_chooser_model_.SetHadWalletError(); | 2345 account_chooser_model_.SetHadWalletError(); |
2357 } | 2346 } |
2358 | 2347 |
2359 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 2348 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
2360 ScopedViewUpdates updates(view_.get()); | 2349 ScopedViewUpdates updates(view_.get()); |
2361 | 2350 |
2362 const DetailOutputMap snapshot = TakeUserInputSnapshot(); | 2351 const DetailOutputMap snapshot = TakeUserInputSnapshot(); |
2363 | 2352 |
2364 suggested_email_.Reset(); | |
2365 suggested_cc_.Reset(); | 2353 suggested_cc_.Reset(); |
2366 suggested_billing_.Reset(); | 2354 suggested_billing_.Reset(); |
2367 suggested_cc_billing_.Reset(); | 2355 suggested_cc_billing_.Reset(); |
2368 suggested_shipping_.Reset(); | 2356 suggested_shipping_.Reset(); |
2369 HidePopup(); | 2357 HidePopup(); |
2370 | 2358 |
2371 suggested_shipping_.AddKeyedItem( | 2359 suggested_shipping_.AddKeyedItem( |
2372 kSameAsBillingKey, | 2360 kSameAsBillingKey, |
2373 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); | 2361 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); |
2374 | 2362 |
2375 if (IsPayingWithWallet()) { | 2363 if (IsPayingWithWallet()) { |
2376 if (!account_chooser_model_.active_wallet_account_name().empty()) { | |
2377 suggested_email_.AddKeyedItem( | |
2378 base::IntToString(0), | |
2379 account_chooser_model_.active_wallet_account_name()); | |
2380 } | |
2381 | |
2382 const std::vector<wallet::Address*>& addresses = | 2364 const std::vector<wallet::Address*>& addresses = |
2383 wallet_items_->addresses(); | 2365 wallet_items_->addresses(); |
2384 for (size_t i = 0; i < addresses.size(); ++i) { | 2366 for (size_t i = 0; i < addresses.size(); ++i) { |
2385 std::string key = base::IntToString(i); | 2367 std::string key = base::IntToString(i); |
2386 suggested_shipping_.AddKeyedItemWithMinorText( | 2368 suggested_shipping_.AddKeyedItemWithMinorText( |
2387 key, | 2369 key, |
2388 addresses[i]->DisplayName(), | 2370 addresses[i]->DisplayName(), |
2389 addresses[i]->DisplayNameDetail()); | 2371 addresses[i]->DisplayNameDetail()); |
2390 | 2372 |
2391 const std::string default_shipping_address_id = | 2373 const std::string default_shipping_address_id = |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2464 | 2446 |
2465 suggested_cc_.AddKeyedItemWithIcon( | 2447 suggested_cc_.AddKeyedItemWithIcon( |
2466 cards[i]->guid(), | 2448 cards[i]->guid(), |
2467 cards[i]->Label(), | 2449 cards[i]->Label(), |
2468 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); | 2450 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); |
2469 } | 2451 } |
2470 | 2452 |
2471 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); | 2453 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
2472 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 2454 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
2473 for (size_t i = 0; i < profiles.size(); ++i) { | 2455 for (size_t i = 0; i < profiles.size(); ++i) { |
2474 if (!HasCompleteAndVerifiedData(*profiles[i], | 2456 const AutofillProfile& profile = *profiles[i]; |
2475 requested_shipping_fields_) || | 2457 if (!HasCompleteAndVerifiedData(profile, requested_shipping_fields_) || |
2476 HasInvalidAddress(*profiles[i])) { | 2458 HasInvalidAddress(*profiles[i])) { |
2477 continue; | 2459 continue; |
2478 } | 2460 } |
2479 | 2461 |
2480 // Add all email addresses. | 2462 // Don't add variants for addresses: name is part of credit card and we'll |
2481 std::vector<string16> values; | 2463 // just ignore email and phone number variants. |
2482 profiles[i]->GetMultiInfo( | 2464 suggested_shipping_.AddKeyedItem(profile.guid(), profile.Label()); |
2483 AutofillType(EMAIL_ADDRESS), app_locale, &values); | 2465 if (!profile.GetRawInfo(EMAIL_ADDRESS).empty() && |
2484 for (size_t j = 0; j < values.size(); ++j) { | 2466 !profile.IsPresentButInvalid(EMAIL_ADDRESS)) { |
2485 if (IsValidEmailAddress(values[j])) | 2467 suggested_billing_.AddKeyedItem(profile.guid(), profile.Label()); |
2486 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]); | |
2487 } | 2468 } |
2488 | |
2489 // Don't add variants for addresses: the email variants are handled above, | |
2490 // name is part of credit card and we'll just ignore phone number | |
2491 // variants. | |
2492 suggested_billing_.AddKeyedItem(profiles[i]->guid(), | |
2493 profiles[i]->Label()); | |
2494 suggested_shipping_.AddKeyedItem(profiles[i]->guid(), | |
2495 profiles[i]->Label()); | |
2496 } | 2469 } |
2497 | 2470 |
2498 suggested_cc_.AddKeyedItem( | 2471 suggested_cc_.AddKeyedItem( |
2499 kAddNewItemKey, | 2472 kAddNewItemKey, |
2500 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD)); | 2473 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD)); |
2501 suggested_cc_.AddKeyedItem( | 2474 suggested_cc_.AddKeyedItem( |
2502 kManageItemsKey, | 2475 kManageItemsKey, |
2503 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_CREDIT_CARD)); | 2476 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_CREDIT_CARD)); |
2504 suggested_billing_.AddKeyedItem( | 2477 suggested_billing_.AddKeyedItem( |
2505 kAddNewItemKey, | 2478 kAddNewItemKey, |
2506 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS)); | 2479 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS)); |
2507 suggested_billing_.AddKeyedItem( | 2480 suggested_billing_.AddKeyedItem( |
2508 kManageItemsKey, | 2481 kManageItemsKey, |
2509 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_BILLING_ADDRESS)); | 2482 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_BILLING_ADDRESS)); |
2510 } | 2483 } |
2511 | 2484 |
2512 suggested_email_.AddKeyedItem( | |
2513 kAddNewItemKey, | |
2514 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS)); | |
2515 if (!IsPayingWithWallet()) { | |
2516 suggested_email_.AddKeyedItem( | |
2517 kManageItemsKey, | |
2518 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_EMAIL_ADDRESS)); | |
2519 } | |
2520 | |
2521 suggested_shipping_.AddKeyedItem( | 2485 suggested_shipping_.AddKeyedItem( |
2522 kAddNewItemKey, | 2486 kAddNewItemKey, |
2523 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); | 2487 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); |
2524 if (!IsPayingWithWallet()) { | 2488 if (!IsPayingWithWallet()) { |
2525 suggested_shipping_.AddKeyedItem( | 2489 suggested_shipping_.AddKeyedItem( |
2526 kManageItemsKey, | 2490 kManageItemsKey, |
2527 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); | 2491 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); |
2528 } else if (!wallet_items_->HasRequiredAction(wallet::SETUP_WALLET)) { | 2492 } else if (!wallet_items_->HasRequiredAction(wallet::SETUP_WALLET)) { |
2529 suggested_shipping_.AddKeyedItemWithMinorText( | 2493 suggested_shipping_.AddKeyedItemWithMinorText( |
2530 kManageItemsKey, | 2494 kManageItemsKey, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2566 } | 2530 } |
2567 | 2531 |
2568 UpdateForErrors(); | 2532 UpdateForErrors(); |
2569 } | 2533 } |
2570 | 2534 |
2571 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 2535 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
2572 DialogSection section, | 2536 DialogSection section, |
2573 const InputFieldComparator& compare) { | 2537 const InputFieldComparator& compare) { |
2574 const DetailInputs& inputs = RequestedFieldsForSection(section); | 2538 const DetailInputs& inputs = RequestedFieldsForSection(section); |
2575 | 2539 |
2576 // Email is hidden while using Wallet, special case it. | |
2577 if (section == SECTION_EMAIL && IsPayingWithWallet()) { | |
2578 AutofillProfile profile; | |
2579 profile.SetRawInfo(EMAIL_ADDRESS, | |
2580 account_chooser_model_.active_wallet_account_name()); | |
2581 AutofillProfileWrapper profile_wrapper(&profile, 0); | |
2582 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); | |
2583 return; | |
2584 } | |
2585 | |
2586 if (!SectionIsActive(section)) | 2540 if (!SectionIsActive(section)) |
2587 return; | 2541 return; |
2588 | 2542 |
2589 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 2543 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
2590 if (wrapper) { | 2544 if (wrapper) { |
2591 // Only fill in data that is associated with this section. | 2545 // Only fill in data that is associated with this section. |
2592 const DetailInputs& inputs = RequestedFieldsForSection(section); | 2546 const DetailInputs& inputs = RequestedFieldsForSection(section); |
2593 wrapper->FillFormStructure(inputs, compare, &form_structure_); | 2547 wrapper->FillFormStructure(inputs, compare, &form_structure_); |
2594 | 2548 |
2595 // CVC needs special-casing because the CreditCard class doesn't store or | 2549 // CVC needs special-casing because the CreditCard class doesn't store or |
2596 // handle them. This isn't necessary when filling the combined CC and | 2550 // handle them. This isn't necessary when filling the combined CC and |
2597 // billing section as CVC comes from |full_wallet_| in this case. | 2551 // billing section as CVC comes from |full_wallet_| in this case. |
2598 if (section == SECTION_CC) | 2552 if (section == SECTION_CC) |
2599 SetCvcResult(view_->GetCvc()); | 2553 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc()); |
| 2554 |
| 2555 // When filling from Wallet data, use the email address associated with the |
| 2556 // account. There is no other email address stored as part of a Wallet |
| 2557 // address. |
| 2558 if (section == SECTION_CC_BILLING) { |
| 2559 SetOutputForFieldsOfType( |
| 2560 EMAIL_ADDRESS, account_chooser_model_.active_wallet_account_name()); |
| 2561 } |
2600 } else { | 2562 } else { |
2601 // The user manually input data. If using Autofill, save the info as new or | 2563 // The user manually input data. If using Autofill, save the info as new or |
2602 // edited data. Always fill local data into |form_structure_|. | 2564 // edited data. Always fill local data into |form_structure_|. |
2603 DetailOutputMap output; | 2565 DetailOutputMap output; |
2604 view_->GetUserInput(section, &output); | 2566 view_->GetUserInput(section, &output); |
2605 | 2567 |
2606 if (section == SECTION_CC) { | 2568 if (section == SECTION_CC) { |
2607 CreditCard card; | 2569 CreditCard card; |
2608 card.set_origin(kAutofillDialogOrigin); | 2570 card.set_origin(kAutofillDialogOrigin); |
2609 FillFormGroupFromOutputs(output, &card); | 2571 FillFormGroupFromOutputs(output, &card); |
2610 | 2572 |
2611 // The card holder name comes from the billing address section. | 2573 // The card holder name comes from the billing address section. |
2612 card.SetRawInfo(CREDIT_CARD_NAME, | 2574 card.SetRawInfo(CREDIT_CARD_NAME, |
2613 GetValueFromSection(SECTION_BILLING, NAME_FULL)); | 2575 GetValueFromSection(SECTION_BILLING, NAME_FULL)); |
2614 | 2576 |
2615 if (ShouldSaveDetailsLocally()) { | 2577 if (ShouldSaveDetailsLocally()) { |
2616 GetManager()->SaveImportedCreditCard(card); | 2578 GetManager()->SaveImportedCreditCard(card); |
2617 DCHECK(!profile()->IsOffTheRecord()); | 2579 DCHECK(!profile()->IsOffTheRecord()); |
2618 newly_saved_card_.reset(new CreditCard(card)); | 2580 newly_saved_card_.reset(new CreditCard(card)); |
2619 } | 2581 } |
2620 | 2582 |
2621 AutofillCreditCardWrapper card_wrapper(&card); | 2583 AutofillCreditCardWrapper card_wrapper(&card); |
2622 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2584 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
2623 | 2585 |
2624 // Again, CVC needs special-casing. Fill it in directly from |output|. | 2586 // Again, CVC needs special-casing. Fill it in directly from |output|. |
2625 SetCvcResult(GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); | 2587 SetOutputForFieldsOfType( |
| 2588 CREDIT_CARD_VERIFICATION_CODE, |
| 2589 GetValueForType(output, CREDIT_CARD_VERIFICATION_CODE)); |
2626 } else { | 2590 } else { |
2627 AutofillProfile profile; | 2591 AutofillProfile profile; |
2628 profile.set_origin(kAutofillDialogOrigin); | 2592 profile.set_origin(kAutofillDialogOrigin); |
2629 FillFormGroupFromOutputs(output, &profile); | 2593 FillFormGroupFromOutputs(output, &profile); |
2630 | 2594 |
2631 // For billing, the email address comes from the separate email section. | |
2632 if (section == SECTION_BILLING) { | |
2633 profile.SetRawInfo(EMAIL_ADDRESS, | |
2634 GetValueFromSection(SECTION_EMAIL, EMAIL_ADDRESS)); | |
2635 } | |
2636 | |
2637 if (ShouldSaveDetailsLocally()) | 2595 if (ShouldSaveDetailsLocally()) |
2638 SaveProfileGleanedFromSection(profile, section); | 2596 SaveProfileGleanedFromSection(profile, section); |
2639 | 2597 |
2640 AutofillProfileWrapper profile_wrapper(&profile, 0); | 2598 AutofillProfileWrapper profile_wrapper(&profile, 0); |
2641 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2599 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
2642 } | 2600 } |
2643 } | 2601 } |
2644 } | 2602 } |
2645 | 2603 |
2646 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 2604 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
2647 FillOutputForSectionWithComparator( | 2605 FillOutputForSectionWithComparator( |
2648 section, base::Bind(common::DetailInputMatchesField, section)); | 2606 section, base::Bind(common::DetailInputMatchesField, section)); |
2649 } | 2607 } |
2650 | 2608 |
2651 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( | 2609 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( |
2652 DialogSection section) const { | 2610 DialogSection section) const { |
2653 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for | 2611 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for |
2654 // any of the fields. | 2612 // any of the fields. |
2655 if (section == SECTION_SHIPPING) | 2613 if (section == SECTION_SHIPPING) |
2656 return cares_about_shipping_; | 2614 return cares_about_shipping_; |
2657 | 2615 |
2658 return true; | 2616 return true; |
2659 } | 2617 } |
2660 | 2618 |
2661 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { | 2619 void AutofillDialogControllerImpl::SetOutputForFieldsOfType( |
| 2620 ServerFieldType type, |
| 2621 const base::string16& output) { |
2662 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 2622 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
2663 AutofillField* field = form_structure_.field(i); | 2623 AutofillField* field = form_structure_.field(i); |
2664 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE) { | 2624 if (field->Type().GetStorableType() == type) |
2665 field->value = cvc; | 2625 field->value = output; |
2666 break; | |
2667 } | |
2668 } | 2626 } |
2669 } | 2627 } |
2670 | 2628 |
2671 string16 AutofillDialogControllerImpl::GetValueFromSection( | 2629 string16 AutofillDialogControllerImpl::GetValueFromSection( |
2672 DialogSection section, | 2630 DialogSection section, |
2673 ServerFieldType type) { | 2631 ServerFieldType type) { |
2674 DCHECK(SectionIsActive(section)); | 2632 DCHECK(SectionIsActive(section)); |
2675 | 2633 |
2676 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 2634 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
2677 if (wrapper) | 2635 if (wrapper) |
2678 return wrapper->GetInfo(AutofillType(type)); | 2636 return wrapper->GetInfo(AutofillType(type)); |
2679 | 2637 |
2680 DetailOutputMap output; | 2638 DetailOutputMap output; |
2681 view_->GetUserInput(section, &output); | 2639 view_->GetUserInput(section, &output); |
2682 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); | 2640 for (DetailOutputMap::iterator iter = output.begin(); iter != output.end(); |
2683 ++iter) { | 2641 ++iter) { |
2684 if (iter->first->type == type) | 2642 if (iter->first->type == type) |
2685 return iter->second; | 2643 return iter->second; |
2686 } | 2644 } |
2687 | 2645 |
2688 return string16(); | 2646 return string16(); |
2689 } | 2647 } |
2690 | 2648 |
2691 void AutofillDialogControllerImpl::SaveProfileGleanedFromSection( | 2649 void AutofillDialogControllerImpl::SaveProfileGleanedFromSection( |
2692 const AutofillProfile& profile, | 2650 const AutofillProfile& profile, |
2693 DialogSection section) { | 2651 DialogSection section) { |
2694 if (section == SECTION_EMAIL) { | 2652 GetManager()->SaveImportedProfile(profile); |
2695 // Save the email address to the existing (suggested) billing profile. If | |
2696 // there is no existing profile, the newly created one will pick up this | |
2697 // email, so in that case do nothing. | |
2698 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(SECTION_BILLING); | |
2699 if (wrapper) { | |
2700 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> | |
2701 GetItemKeyForCheckedItem(); | |
2702 AutofillProfile* billing_profile = | |
2703 GetManager()->GetProfileByGUID(item_key); | |
2704 billing_profile->OverwriteWithOrAddTo( | |
2705 profile, | |
2706 g_browser_process->GetApplicationLocale()); | |
2707 } | |
2708 } else { | |
2709 GetManager()->SaveImportedProfile(profile); | |
2710 } | |
2711 } | 2653 } |
2712 | 2654 |
2713 SuggestionsMenuModel* AutofillDialogControllerImpl:: | 2655 SuggestionsMenuModel* AutofillDialogControllerImpl:: |
2714 SuggestionsMenuModelForSection(DialogSection section) { | 2656 SuggestionsMenuModelForSection(DialogSection section) { |
2715 switch (section) { | 2657 switch (section) { |
2716 case SECTION_EMAIL: | |
2717 return &suggested_email_; | |
2718 case SECTION_CC: | 2658 case SECTION_CC: |
2719 return &suggested_cc_; | 2659 return &suggested_cc_; |
2720 case SECTION_BILLING: | 2660 case SECTION_BILLING: |
2721 return &suggested_billing_; | 2661 return &suggested_billing_; |
2722 case SECTION_SHIPPING: | 2662 case SECTION_SHIPPING: |
2723 return &suggested_shipping_; | 2663 return &suggested_shipping_; |
2724 case SECTION_CC_BILLING: | 2664 case SECTION_CC_BILLING: |
2725 return &suggested_cc_billing_; | 2665 return &suggested_cc_billing_; |
2726 } | 2666 } |
2727 | 2667 |
2728 NOTREACHED(); | 2668 NOTREACHED(); |
2729 return NULL; | 2669 return NULL; |
2730 } | 2670 } |
2731 | 2671 |
2732 const SuggestionsMenuModel* AutofillDialogControllerImpl:: | 2672 const SuggestionsMenuModel* AutofillDialogControllerImpl:: |
2733 SuggestionsMenuModelForSection(DialogSection section) const { | 2673 SuggestionsMenuModelForSection(DialogSection section) const { |
2734 return const_cast<AutofillDialogControllerImpl*>(this)-> | 2674 return const_cast<AutofillDialogControllerImpl*>(this)-> |
2735 SuggestionsMenuModelForSection(section); | 2675 SuggestionsMenuModelForSection(section); |
2736 } | 2676 } |
2737 | 2677 |
2738 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel( | 2678 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel( |
2739 const SuggestionsMenuModel& model) { | 2679 const SuggestionsMenuModel& model) { |
2740 if (&model == &suggested_email_) | |
2741 return SECTION_EMAIL; | |
2742 | |
2743 if (&model == &suggested_cc_) | 2680 if (&model == &suggested_cc_) |
2744 return SECTION_CC; | 2681 return SECTION_CC; |
2745 | 2682 |
2746 if (&model == &suggested_billing_) | 2683 if (&model == &suggested_billing_) |
2747 return SECTION_BILLING; | 2684 return SECTION_BILLING; |
2748 | 2685 |
2749 if (&model == &suggested_cc_billing_) | 2686 if (&model == &suggested_cc_billing_) |
2750 return SECTION_CC_BILLING; | 2687 return SECTION_CC_BILLING; |
2751 | 2688 |
2752 DCHECK_EQ(&model, &suggested_shipping_); | 2689 DCHECK_EQ(&model, &suggested_shipping_); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3060 | 2997 |
3061 DoFinishSubmit(); | 2998 DoFinishSubmit(); |
3062 } | 2999 } |
3063 | 3000 |
3064 void AutofillDialogControllerImpl::DoFinishSubmit() { | 3001 void AutofillDialogControllerImpl::DoFinishSubmit() { |
3065 if (IsPayingWithWallet()) { | 3002 if (IsPayingWithWallet()) { |
3066 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, | 3003 profile_->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, |
3067 true); | 3004 true); |
3068 } | 3005 } |
3069 | 3006 |
3070 FillOutputForSection(SECTION_EMAIL); | |
3071 FillOutputForSection(SECTION_CC); | 3007 FillOutputForSection(SECTION_CC); |
3072 FillOutputForSection(SECTION_BILLING); | 3008 FillOutputForSection(SECTION_BILLING); |
3073 FillOutputForSection(SECTION_CC_BILLING); | 3009 FillOutputForSection(SECTION_CC_BILLING); |
3074 | 3010 |
3075 if (ShouldUseBillingForShipping()) { | 3011 if (ShouldUseBillingForShipping()) { |
3076 FillOutputForSectionWithComparator( | 3012 FillOutputForSectionWithComparator( |
3077 SECTION_BILLING, | 3013 SECTION_BILLING, |
3078 base::Bind(DetailInputMatchesShippingField)); | 3014 base::Bind(DetailInputMatchesShippingField)); |
3079 FillOutputForSectionWithComparator( | 3015 FillOutputForSectionWithComparator( |
3080 SECTION_CC, | 3016 SECTION_CC, |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3302 billing_profile.reset(new AutofillProfile); | 3238 billing_profile.reset(new AutofillProfile); |
3303 FillFormGroupFromOutputs(outputs, billing_profile.get()); | 3239 FillFormGroupFromOutputs(outputs, billing_profile.get()); |
3304 } else { | 3240 } else { |
3305 // Just snag the currently suggested profile. | 3241 // Just snag the currently suggested profile. |
3306 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> | 3242 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> |
3307 GetItemKeyForCheckedItem(); | 3243 GetItemKeyForCheckedItem(); |
3308 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); | 3244 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); |
3309 billing_profile.reset(new AutofillProfile(*profile)); | 3245 billing_profile.reset(new AutofillProfile(*profile)); |
3310 } | 3246 } |
3311 | 3247 |
3312 // The bubble also needs the associated email address. | |
3313 billing_profile->SetRawInfo( | |
3314 EMAIL_ADDRESS, | |
3315 GetValueFromSection(SECTION_EMAIL, EMAIL_ADDRESS)); | |
3316 | |
3317 ShowNewCreditCardBubble(newly_saved_card_.Pass(), | 3248 ShowNewCreditCardBubble(newly_saved_card_.Pass(), |
3318 billing_profile.Pass()); | 3249 billing_profile.Pass()); |
3319 return; | 3250 return; |
3320 } | 3251 } |
3321 | 3252 |
3322 if (!full_wallet_ || !full_wallet_->billing_address()) | 3253 if (!full_wallet_ || !full_wallet_->billing_address()) |
3323 return; | 3254 return; |
3324 | 3255 |
3325 base::string16 backing_last_four; | 3256 base::string16 backing_last_four; |
3326 if (ActiveInstrument()) { | 3257 if (ActiveInstrument()) { |
3327 backing_last_four = ActiveInstrument()->TypeAndLastFourDigits(); | 3258 backing_last_four = ActiveInstrument()->TypeAndLastFourDigits(); |
3328 } else { | 3259 } else { |
3329 DetailOutputMap output; | 3260 DetailOutputMap output; |
3330 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3261 view_->GetUserInput(SECTION_CC_BILLING, &output); |
3331 CreditCard card; | 3262 CreditCard card; |
3332 GetBillingInfoFromOutputs(output, &card, NULL, NULL); | 3263 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
3333 backing_last_four = card.TypeAndLastFourDigits(); | 3264 backing_last_four = card.TypeAndLastFourDigits(); |
3334 } | 3265 } |
3335 #if !defined(OS_ANDROID) | 3266 #if !defined(OS_ANDROID) |
3336 GeneratedCreditCardBubbleController::Show( | 3267 GeneratedCreditCardBubbleController::Show( |
3337 web_contents(), | 3268 web_contents(), |
3338 full_wallet_->TypeAndLastFourDigits(), | 3269 full_wallet_->TypeAndLastFourDigits(), |
3339 backing_last_four); | 3270 backing_last_four); |
3340 #endif | 3271 #endif |
3341 } | 3272 } |
3342 | 3273 |
3343 } // namespace autofill | 3274 } // namespace autofill |
OLD | NEW |