| 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 if ((section == SECTION_CC_BILLING && !full_wallet->billing_address()) || |
| 87 if (wrapper) | 72 (section == SECTION_SHIPPING && !full_wallet->shipping_address())) { |
| 88 wrapper->FillFormStructure(inputs, compare, &form_structure); | 73 return; |
| 74 } |
| 75 |
| 76 base::Callback<base::string16(const AutofillType&)> get_info = |
| 77 base::Bind(&FullWallet::GetInfo, |
| 78 base::Unretained(full_wallet), |
| 79 g_browser_process->GetApplicationLocale()); |
| 80 |
| 81 std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); |
| 82 form_structure.FillFields(types, |
| 83 compare, |
| 84 get_info, |
| 85 g_browser_process->GetApplicationLocale()); |
| 89 } | 86 } |
| 90 | 87 |
| 91 void FillOutputForSection( | 88 void FillOutputForSection( |
| 92 DialogSection section, | 89 DialogSection section, |
| 93 FormStructure& form_structure, | 90 FormStructure& form_structure, |
| 94 wallet::FullWallet* full_wallet, | 91 FullWallet* full_wallet, |
| 95 const base::string16& email_address) { | 92 const base::string16& email_address) { |
| 96 DetailInputs inputs; | 93 DetailInputs inputs; |
| 97 common::BuildInputsForSection(section, "US", &inputs); | 94 common::BuildInputsForSection(section, "US", &inputs); |
| 98 | 95 |
| 99 FillOutputForSectionWithComparator( | 96 FillOutputForSectionWithComparator( |
| 100 section, inputs, | 97 section, inputs, |
| 101 base::Bind(common::ServerTypeMatchesField, section), | 98 base::Bind(common::ServerTypeMatchesField, section), |
| 102 form_structure, full_wallet, email_address); | 99 form_structure, full_wallet, email_address); |
| 103 | 100 |
| 104 if (section == SECTION_CC_BILLING) { | 101 if (section == SECTION_CC_BILLING) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 form_structure_) || | 242 form_structure_) || |
| 246 IsSectionInputUsedInFormStructure( | 243 IsSectionInputUsedInFormStructure( |
| 247 SECTION_SHIPPING, | 244 SECTION_SHIPPING, |
| 248 PHONE_HOME_WHOLE_NUMBER, | 245 PHONE_HOME_WHOLE_NUMBER, |
| 249 form_structure_); | 246 form_structure_); |
| 250 | 247 |
| 251 bool request_shipping_address = false; | 248 bool request_shipping_address = false; |
| 252 { | 249 { |
| 253 DetailInputs inputs; | 250 DetailInputs inputs; |
| 254 common::BuildInputsForSection(SECTION_SHIPPING, "US", &inputs); | 251 common::BuildInputsForSection(SECTION_SHIPPING, "US", &inputs); |
| 255 EmptyDataModelWrapper empty_wrapper; | 252 request_shipping_address = form_structure_.FillFields( |
| 256 request_shipping_address = empty_wrapper.FillFormStructure( | 253 common::TypesFromInputs(inputs), |
| 257 inputs, | |
| 258 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), | 254 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), |
| 259 &form_structure_); | 255 base::Bind(NullGetInfo), |
| 256 g_browser_process->GetApplicationLocale()); |
| 260 } | 257 } |
| 261 | 258 |
| 262 const bool incognito_mode = profile_->IsOffTheRecord(); | 259 const bool incognito_mode = profile_->IsOffTheRecord(); |
| 263 | 260 |
| 264 bool last_used_choice_is_autofill = false; | 261 bool last_used_choice_is_autofill = false; |
| 265 base::string16 last_used_account_name; | 262 base::string16 last_used_account_name; |
| 266 std::string last_used_billing; | 263 std::string last_used_billing; |
| 267 std::string last_used_shipping; | 264 std::string last_used_shipping; |
| 268 std::string last_used_credit_card; | 265 std::string last_used_credit_card; |
| 269 { | 266 { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 343 |
| 347 const base::string16 last_used_account_name = | 344 const base::string16 last_used_account_name = |
| 348 base::android::ConvertJavaStringToUTF16(env, jlast_used_account_name); | 345 base::android::ConvertJavaStringToUTF16(env, jlast_used_account_name); |
| 349 const std::string last_used_billing = | 346 const std::string last_used_billing = |
| 350 base::android::ConvertJavaStringToUTF8(env, jlast_used_billing); | 347 base::android::ConvertJavaStringToUTF8(env, jlast_used_billing); |
| 351 const std::string last_used_shipping = | 348 const std::string last_used_shipping = |
| 352 base::android::ConvertJavaStringToUTF8(env, jlast_used_shipping); | 349 base::android::ConvertJavaStringToUTF8(env, jlast_used_shipping); |
| 353 const std::string last_used_card = | 350 const std::string last_used_card = |
| 354 base::android::ConvertJavaStringToUTF8(env, jlast_used_card); | 351 base::android::ConvertJavaStringToUTF8(env, jlast_used_card); |
| 355 | 352 |
| 356 scoped_ptr<wallet::FullWallet> full_wallet = | 353 scoped_ptr<FullWallet> full_wallet = |
| 357 AutofillDialogResult::ConvertFromJava(env, wallet); | 354 AutofillDialogResult::ConvertFromJava(env, wallet); |
| 358 FillOutputForSection( | 355 FillOutputForSection( |
| 359 SECTION_CC_BILLING, form_structure_, full_wallet.get(), email); | 356 SECTION_CC_BILLING, form_structure_, full_wallet.get(), email); |
| 360 FillOutputForSection( | 357 FillOutputForSection( |
| 361 SECTION_SHIPPING, form_structure_, full_wallet.get(), email); | 358 SECTION_SHIPPING, form_structure_, full_wallet.get(), email); |
| 362 | 359 |
| 363 { | 360 { |
| 364 DictionaryPrefUpdate updater(profile_->GetPrefs(), | 361 DictionaryPrefUpdate updater(profile_->GetPrefs(), |
| 365 ::prefs::kAutofillDialogDefaults); | 362 ::prefs::kAutofillDialogDefaults); |
| 366 base::DictionaryValue* defaults = updater.Get(); | 363 base::DictionaryValue* defaults = updater.Get(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 414 |
| 418 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { | 415 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { |
| 419 GetMetricLogger().LogDialogUiDuration( | 416 GetMetricLogger().LogDialogUiDuration( |
| 420 base::Time::Now() - dialog_shown_timestamp_, | 417 base::Time::Now() - dialog_shown_timestamp_, |
| 421 AutofillMetrics::DIALOG_CANCELED); | 418 AutofillMetrics::DIALOG_CANCELED); |
| 422 | 419 |
| 423 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED); | 420 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED); |
| 424 } | 421 } |
| 425 | 422 |
| 426 } // namespace autofill | 423 } // namespace autofill |
| OLD | NEW |