Chromium Code Reviews| 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/android/autofill/autofill_dialog_controller_android. h" | 5 #include "chrome/browser/ui/android/autofill/autofill_dialog_controller_android. h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/prefs/scoped_user_pref_update.h" | 14 #include "base/prefs/scoped_user_pref_update.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 16 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/ui/android/autofill/autofill_dialog_result.h" | 20 #include "chrome/browser/ui/android/autofill/autofill_dialog_result.h" |
| 21 #include "chrome/browser/ui/android/window_android_helper.h" | 21 #include "chrome/browser/ui/android/window_android_helper.h" |
| 22 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" | 22 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
| 23 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | |
| 24 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 26 #include "components/autofill/content/browser/wallet/full_wallet.h" | 25 #include "components/autofill/content/browser/wallet/full_wallet.h" |
| 27 #include "components/autofill/core/browser/autofill_metrics.h" | 26 #include "components/autofill/core/browser/autofill_metrics.h" |
| 28 #include "components/autofill/core/browser/autofill_profile.h" | 27 #include "components/autofill/core/browser/autofill_profile.h" |
| 29 #include "components/autofill/core/browser/autofill_type.h" | 28 #include "components/autofill/core/browser/autofill_type.h" |
| 30 #include "components/autofill/core/browser/credit_card.h" | 29 #include "components/autofill/core/browser/credit_card.h" |
| 31 #include "components/autofill/core/browser/personal_data_manager.h" | 30 #include "components/autofill/core/browser/personal_data_manager.h" |
| 32 #include "components/autofill/core/common/form_data.h" | 31 #include "components/autofill/core/common/form_data.h" |
| 33 #include "components/user_prefs/pref_registry_syncable.h" | 32 #include "components/user_prefs/pref_registry_syncable.h" |
| 34 #include "content/public/browser/navigation_controller.h" | 33 #include "content/public/browser/navigation_controller.h" |
| 35 #include "content/public/browser/navigation_details.h" | 34 #include "content/public/browser/navigation_details.h" |
| 36 #include "content/public/browser/navigation_entry.h" | 35 #include "content/public/browser/navigation_entry.h" |
| 37 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 38 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
| 39 #include "jni/AutofillDialogControllerAndroid_jni.h" | 38 #include "jni/AutofillDialogControllerAndroid_jni.h" |
| 40 #include "ui/base/android/window_android.h" | 39 #include "ui/base/android/window_android.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 42 #include "ui/base/models/combobox_model.h" | 41 #include "ui/base/models/combobox_model.h" |
| 43 #include "ui/base/models/menu_model.h" | 42 #include "ui/base/models/menu_model.h" |
| 44 #include "ui/gfx/android/java_bitmap.h" | 43 #include "ui/gfx/android/java_bitmap.h" |
| 45 #include "ui/gfx/rect.h" | 44 #include "ui/gfx/rect.h" |
| 46 #include "url/gurl.h" | 45 #include "url/gurl.h" |
| 47 | 46 |
| 48 namespace autofill { | 47 namespace autofill { |
| 49 | 48 |
| 50 namespace { | 49 namespace { |
| 51 | 50 |
| 51 using wallet::FullWallet; | |
| 52 | |
| 52 // Keys in kAutofillDialogDefaults pref dictionary (do not change these values). | 53 // Keys in kAutofillDialogDefaults pref dictionary (do not change these values). |
| 53 const char kLastUsedAccountName[] = "last_used_account_name"; | 54 const char kLastUsedAccountName[] = "last_used_account_name"; |
| 54 const char kLastUsedChoiceIsAutofill[] = "last_used_choice_is_autofill"; | 55 const char kLastUsedChoiceIsAutofill[] = "last_used_choice_is_autofill"; |
| 55 const char kLastUsedBillingAddressGuid[] = "last_used_billing"; | 56 const char kLastUsedBillingAddressGuid[] = "last_used_billing"; |
| 56 const char kLastUsedShippingAddressGuid[] = "last_used_shipping"; | 57 const char kLastUsedShippingAddressGuid[] = "last_used_shipping"; |
| 57 const char kLastUsedCreditCardGuid[] = "last_used_card"; | 58 const char kLastUsedCreditCardGuid[] = "last_used_card"; |
| 58 | 59 |
| 59 scoped_ptr<DataModelWrapper> CreateWrapper( | 60 base::string16 NullGetInfo(const AutofillType& type) { |
| 60 DialogSection section, wallet::FullWallet* full_wallet) { | 61 return base::string16(); |
| 61 if (section == SECTION_CC_BILLING) { | |
| 62 if (!full_wallet->billing_address()) | |
| 63 return scoped_ptr<DataModelWrapper>(); | |
| 64 | |
| 65 return scoped_ptr<DataModelWrapper>( | |
| 66 new FullWalletBillingWrapper(full_wallet)); | |
| 67 } | |
| 68 if (section == SECTION_SHIPPING) { | |
| 69 if (!full_wallet->shipping_address()) | |
| 70 return scoped_ptr<DataModelWrapper>(); | |
| 71 | |
| 72 return scoped_ptr<DataModelWrapper>( | |
| 73 new FullWalletShippingWrapper(full_wallet)); | |
| 74 } | |
| 75 NOTREACHED(); | |
| 76 return scoped_ptr<DataModelWrapper>(); | |
| 77 } | 62 } |
| 78 | 63 |
| 79 void FillOutputForSectionWithComparator( | 64 void FillOutputForSectionWithComparator( |
| 80 DialogSection section, | 65 DialogSection section, |
| 81 const DetailInputs& inputs, | 66 const DetailInputs& inputs, |
| 82 const InputFieldComparator& compare, | 67 const FormStructure::InputFieldComparator& compare, |
| 83 FormStructure& form_structure, | 68 FormStructure& form_structure, |
| 84 wallet::FullWallet* full_wallet, | 69 FullWallet* full_wallet, |
| 85 const base::string16& email_address) { | 70 const base::string16& email_address) { |
| 86 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section, full_wallet); | 71 base::Callback<base::string16(const AutofillType&)> get_info; |
| 87 if (wrapper) | 72 if (section == SECTION_CC_BILLING && full_wallet->billing_address()) { |
| 88 wrapper->FillFormStructure(inputs, compare, &form_structure); | 73 get_info = base::Bind(&FullWallet::GetBillingInfo, |
| 74 base::Unretained(full_wallet), | |
| 75 g_browser_process->GetApplicationLocale()); | |
| 76 } else if (section == SECTION_SHIPPING && full_wallet->shipping_address()) { | |
| 77 get_info = base::Bind(&FullWallet::GetShippingInfo, | |
| 78 base::Unretained(full_wallet), | |
| 79 g_browser_process->GetApplicationLocale()); | |
| 80 } | |
|
Dan Beam
2014/01/27 20:51:40
i don't currently see how GetBillingInfo() could b
| |
| 81 | |
| 82 if (!get_info.is_null()) { | |
| 83 std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); | |
| 84 form_structure.FillFields( | |
| 85 types, | |
| 86 compare, | |
| 87 get_info, | |
| 88 g_browser_process->GetApplicationLocale()); | |
|
Dan Beam
2014/01/27 20:51:40
nit:
form_structure.FillFields(types,
Dan Beam
2014/01/27 23:11:27
this
Evan Stade
2014/01/28 00:07:59
Done.
| |
| 89 } | |
| 89 } | 90 } |
| 90 | 91 |
| 91 void FillOutputForSection( | 92 void FillOutputForSection( |
| 92 DialogSection section, | 93 DialogSection section, |
| 93 FormStructure& form_structure, | 94 FormStructure& form_structure, |
| 94 wallet::FullWallet* full_wallet, | 95 FullWallet* full_wallet, |
| 95 const base::string16& email_address) { | 96 const base::string16& email_address) { |
| 96 DetailInputs inputs; | 97 DetailInputs inputs; |
| 97 common::BuildInputsForSection(section, "US", &inputs); | 98 common::BuildInputsForSection(section, "US", &inputs); |
| 98 | 99 |
| 99 FillOutputForSectionWithComparator( | 100 FillOutputForSectionWithComparator( |
| 100 section, inputs, | 101 section, inputs, |
| 101 base::Bind(common::ServerTypeMatchesField, section), | 102 base::Bind(common::ServerTypeMatchesField, section), |
| 102 form_structure, full_wallet, email_address); | 103 form_structure, full_wallet, email_address); |
| 103 | 104 |
| 104 if (section == SECTION_CC_BILLING) { | 105 if (section == SECTION_CC_BILLING) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 form_structure_) || | 246 form_structure_) || |
| 246 IsSectionInputUsedInFormStructure( | 247 IsSectionInputUsedInFormStructure( |
| 247 SECTION_SHIPPING, | 248 SECTION_SHIPPING, |
| 248 PHONE_HOME_WHOLE_NUMBER, | 249 PHONE_HOME_WHOLE_NUMBER, |
| 249 form_structure_); | 250 form_structure_); |
| 250 | 251 |
| 251 bool request_shipping_address = false; | 252 bool request_shipping_address = false; |
| 252 { | 253 { |
| 253 DetailInputs inputs; | 254 DetailInputs inputs; |
| 254 common::BuildInputsForSection(SECTION_SHIPPING, "US", &inputs); | 255 common::BuildInputsForSection(SECTION_SHIPPING, "US", &inputs); |
| 255 EmptyDataModelWrapper empty_wrapper; | 256 request_shipping_address = form_structure_.FillFields( |
| 256 request_shipping_address = empty_wrapper.FillFormStructure( | 257 common::TypesFromInputs(inputs), |
| 257 inputs, | |
| 258 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), | 258 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), |
| 259 &form_structure_); | 259 base::Bind(NullGetInfo), |
| 260 g_browser_process->GetApplicationLocale()); | |
| 260 } | 261 } |
| 261 | 262 |
| 262 const bool incognito_mode = profile_->IsOffTheRecord(); | 263 const bool incognito_mode = profile_->IsOffTheRecord(); |
| 263 | 264 |
| 264 bool last_used_choice_is_autofill = false; | 265 bool last_used_choice_is_autofill = false; |
| 265 base::string16 last_used_account_name; | 266 base::string16 last_used_account_name; |
| 266 std::string last_used_billing; | 267 std::string last_used_billing; |
| 267 std::string last_used_shipping; | 268 std::string last_used_shipping; |
| 268 std::string last_used_credit_card; | 269 std::string last_used_credit_card; |
| 269 { | 270 { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 | 347 |
| 347 const base::string16 last_used_account_name = | 348 const base::string16 last_used_account_name = |
| 348 base::android::ConvertJavaStringToUTF16(env, jlast_used_account_name); | 349 base::android::ConvertJavaStringToUTF16(env, jlast_used_account_name); |
| 349 const std::string last_used_billing = | 350 const std::string last_used_billing = |
| 350 base::android::ConvertJavaStringToUTF8(env, jlast_used_billing); | 351 base::android::ConvertJavaStringToUTF8(env, jlast_used_billing); |
| 351 const std::string last_used_shipping = | 352 const std::string last_used_shipping = |
| 352 base::android::ConvertJavaStringToUTF8(env, jlast_used_shipping); | 353 base::android::ConvertJavaStringToUTF8(env, jlast_used_shipping); |
| 353 const std::string last_used_card = | 354 const std::string last_used_card = |
| 354 base::android::ConvertJavaStringToUTF8(env, jlast_used_card); | 355 base::android::ConvertJavaStringToUTF8(env, jlast_used_card); |
| 355 | 356 |
| 356 scoped_ptr<wallet::FullWallet> full_wallet = | 357 scoped_ptr<FullWallet> full_wallet = |
| 357 AutofillDialogResult::ConvertFromJava(env, wallet); | 358 AutofillDialogResult::ConvertFromJava(env, wallet); |
| 358 FillOutputForSection( | 359 FillOutputForSection( |
| 359 SECTION_CC_BILLING, form_structure_, full_wallet.get(), email); | 360 SECTION_CC_BILLING, form_structure_, full_wallet.get(), email); |
| 360 FillOutputForSection( | 361 FillOutputForSection( |
| 361 SECTION_SHIPPING, form_structure_, full_wallet.get(), email); | 362 SECTION_SHIPPING, form_structure_, full_wallet.get(), email); |
|
Dan Beam
2014/01/27 20:51:40
where is "Use billing for shipping" on Android imp
| |
| 362 | 363 |
| 363 { | 364 { |
| 364 DictionaryPrefUpdate updater(profile_->GetPrefs(), | 365 DictionaryPrefUpdate updater(profile_->GetPrefs(), |
| 365 ::prefs::kAutofillDialogDefaults); | 366 ::prefs::kAutofillDialogDefaults); |
| 366 base::DictionaryValue* defaults = updater.Get(); | 367 base::DictionaryValue* defaults = updater.Get(); |
| 367 if (defaults) { | 368 if (defaults) { |
| 368 const bool last_used_choice_is_autofill = !!jlast_used_choice_is_autofill; | 369 const bool last_used_choice_is_autofill = !!jlast_used_choice_is_autofill; |
| 369 defaults->SetString(kLastUsedAccountName, last_used_account_name); | 370 defaults->SetString(kLastUsedAccountName, last_used_account_name); |
| 370 defaults->SetBoolean(kLastUsedChoiceIsAutofill, | 371 defaults->SetBoolean(kLastUsedChoiceIsAutofill, |
| 371 last_used_choice_is_autofill); | 372 last_used_choice_is_autofill); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 | 418 |
| 418 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { | 419 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { |
| 419 GetMetricLogger().LogDialogUiDuration( | 420 GetMetricLogger().LogDialogUiDuration( |
| 420 base::Time::Now() - dialog_shown_timestamp_, | 421 base::Time::Now() - dialog_shown_timestamp_, |
| 421 AutofillMetrics::DIALOG_CANCELED); | 422 AutofillMetrics::DIALOG_CANCELED); |
| 422 | 423 |
| 423 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED); | 424 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED); |
| 424 } | 425 } |
| 425 | 426 |
| 426 } // namespace autofill | 427 } // namespace autofill |
| OLD | NEW |