OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/android/autofill/autofill_dialog_result.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/bind.h" |
| 12 #include "base/logging.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| 15 #include "components/autofill/content/browser/wallet/full_wallet.h" |
| 16 #include "components/autofill/core/browser/credit_card.h" |
| 17 #include "components/autofill/core/common/form_data.h" |
| 18 #include "jni/AutofillDialogResult_jni.h" |
| 19 #include "ui/base/l10n/l10n_util.h" |
| 20 |
| 21 namespace autofill { |
| 22 |
| 23 namespace { |
| 24 |
| 25 #define FETCH_JFIELD(env, jobj, getter) \ |
| 26 (Java_AutofillDialogResult_get##getter((env), (jobj))) |
| 27 |
| 28 #define FETCH_JSTRING(utf, env, jobj, getter) \ |
| 29 (base::android::ConvertJavaStringTo##utf( \ |
| 30 (env), FETCH_JFIELD((env), (jobj), getter).obj())) |
| 31 |
| 32 scoped_ptr<wallet::Address> ParseJavaWalletAddress( |
| 33 JNIEnv* env, jobject address) { |
| 34 const base::string16 recipient_name = |
| 35 FETCH_JSTRING(UTF16, env, address, WalletAddressFullName); |
| 36 const base::string16 address_line_1 = |
| 37 FETCH_JSTRING(UTF16, env, address, WalletAddressLine1); |
| 38 const base::string16 address_line_2 = |
| 39 FETCH_JSTRING(UTF16, env, address, WalletAddressLine2); |
| 40 const base::string16 locality_name = |
| 41 FETCH_JSTRING(UTF16, env, address, WalletAddressCity); |
| 42 const base::string16 administrative_area_name = |
| 43 FETCH_JSTRING(UTF16, env, address, WalletAddressState); |
| 44 const base::string16 postal_code_number = |
| 45 FETCH_JSTRING(UTF16, env, address, WalletAddressPostalCode); |
| 46 const base::string16 phone_number = |
| 47 FETCH_JSTRING(UTF16, env, address, WalletAddressPhoneNumber); |
| 48 |
| 49 std::string country_name_code = |
| 50 FETCH_JSTRING(UTF8, env, address, WalletAddressCountryCode); |
| 51 DCHECK(!country_name_code.empty()); |
| 52 |
| 53 return scoped_ptr<wallet::Address>(new wallet::Address( |
| 54 country_name_code, |
| 55 recipient_name, |
| 56 address_line_1, |
| 57 address_line_2, |
| 58 locality_name, |
| 59 administrative_area_name, |
| 60 postal_code_number, |
| 61 phone_number, |
| 62 std::string())); |
| 63 } |
| 64 |
| 65 scoped_ptr<wallet::FullWallet> ParseJavaWallet(JNIEnv* env, jobject wallet) { |
| 66 const ScopedJavaLocalRef<jobject> billing_address( |
| 67 FETCH_JFIELD(env, wallet, WalletBillingAddress)); |
| 68 const ScopedJavaLocalRef<jobject> shipping_address( |
| 69 FETCH_JFIELD(env, wallet, WalletShippingAddress)); |
| 70 const ScopedJavaLocalRef<jobject> card( |
| 71 FETCH_JFIELD(env, wallet, WalletCardInformation)); |
| 72 |
| 73 const int expiration_month = |
| 74 FETCH_JFIELD(env, card.obj(), WalletCardExpirationMonth); |
| 75 const int expiration_year = |
| 76 FETCH_JFIELD(env, card.obj(), WalletCardExpirationYear); |
| 77 const std::string pan = |
| 78 FETCH_JSTRING(UTF8, env, card.obj(), WalletCardPan); |
| 79 const std::string cvn = |
| 80 FETCH_JSTRING(UTF8, env, card.obj(), WalletCardCvn); |
| 81 |
| 82 return wallet::FullWallet::CreateFullWallet( |
| 83 expiration_month, |
| 84 expiration_year, |
| 85 pan, |
| 86 cvn, |
| 87 ParseJavaWalletAddress(env, billing_address.obj()), |
| 88 ParseJavaWalletAddress(env, shipping_address.obj())); |
| 89 } |
| 90 |
| 91 #undef FETCH_JSTRING |
| 92 #undef FETCH_FIELD |
| 93 } // namespace |
| 94 |
| 95 // static |
| 96 scoped_ptr<wallet::FullWallet> AutofillDialogResult::ConvertFromJava( |
| 97 JNIEnv* env, jobject wallet) { |
| 98 return ParseJavaWallet(env, wallet); |
| 99 } |
| 100 |
| 101 // static |
| 102 base::string16 AutofillDialogResult::GetWalletEmail( |
| 103 JNIEnv* env, jobject wallet) { |
| 104 return |
| 105 base::android::ConvertJavaStringToUTF16( |
| 106 env, |
| 107 Java_AutofillDialogResult_getWalletEmail(env, wallet).obj()); |
| 108 } |
| 109 |
| 110 // static |
| 111 std::string AutofillDialogResult::GetWalletGoogleTransactionId( |
| 112 JNIEnv* env, jobject wallet) { |
| 113 return |
| 114 base::android::ConvertJavaStringToUTF8( |
| 115 env, |
| 116 Java_AutofillDialogResult_getWalletGoogleTransactionId(env, wallet).obj(
)); |
| 117 } |
| 118 |
| 119 // static |
| 120 bool AutofillDialogResult::RegisterAutofillDialogResult(JNIEnv* env) { |
| 121 return RegisterNativesImpl(env); |
| 122 } |
| 123 |
| 124 } // namespace autofill |
OLD | NEW |