Chromium Code Reviews| 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 std::string ConvertNullOrJavaStringToUTF8(JNIEnv* env, jstring str) { | |
| 26 return str ? base::android::ConvertJavaStringToUTF8(env, str) : std::string(); | |
| 27 } | |
| 28 | |
| 29 base::string16 ConvertNullOrJavaStringToUTF16(JNIEnv* env, jstring str) { | |
| 30 return str ? base::android::ConvertJavaStringToUTF16(env, str) | |
| 31 : base::string16(); | |
| 32 } | |
| 33 | |
| 34 #define FETCH_JFIELD(env, jobj, getter) \ | |
| 35 (Java_AutofillDialogResult_get##getter((env), (jobj))) | |
| 36 | |
| 37 #define FETCH_JSTRING(utf, env, jobj, getter) \ | |
|
Ted C
2013/08/10 01:33:35
I don't see a lot of macros in Chromium code, but
aruslan
2013/08/10 03:00:08
Agreed, but it made my life much simpler.
git grep
| |
| 38 (ConvertNullOrJavaStringTo##utf( \ | |
| 39 (env), FETCH_JFIELD((env), (jobj), getter).obj())) | |
| 40 | |
| 41 scoped_ptr<wallet::Address> ParseJavaWalletAddress( | |
| 42 JNIEnv* env, jobject address) { | |
| 43 if (!address) | |
| 44 return scoped_ptr<wallet::Address>(); | |
| 45 | |
| 46 const base::string16 recipient_name = | |
| 47 FETCH_JSTRING(UTF16, env, address, WalletAddressFullName); | |
| 48 const base::string16 address_line_1 = | |
| 49 FETCH_JSTRING(UTF16, env, address, WalletAddressLine1); | |
| 50 const base::string16 address_line_2 = | |
| 51 FETCH_JSTRING(UTF16, env, address, WalletAddressLine2); | |
| 52 const base::string16 locality_name = | |
| 53 FETCH_JSTRING(UTF16, env, address, WalletAddressCity); | |
| 54 const base::string16 administrative_area_name = | |
| 55 FETCH_JSTRING(UTF16, env, address, WalletAddressState); | |
| 56 const base::string16 postal_code_number = | |
| 57 FETCH_JSTRING(UTF16, env, address, WalletAddressPostalCode); | |
| 58 const base::string16 phone_number = | |
| 59 FETCH_JSTRING(UTF16, env, address, WalletAddressPhoneNumber); | |
| 60 | |
| 61 std::string country_name_code = | |
| 62 FETCH_JSTRING(UTF8, env, address, WalletAddressCountryCode); | |
| 63 DCHECK(!country_name_code.empty()); | |
| 64 | |
| 65 return scoped_ptr<wallet::Address>(new wallet::Address( | |
| 66 country_name_code, | |
| 67 recipient_name, | |
| 68 address_line_1, | |
| 69 address_line_2, | |
| 70 locality_name, | |
| 71 administrative_area_name, | |
| 72 postal_code_number, | |
| 73 phone_number, | |
| 74 std::string())); | |
| 75 } | |
| 76 | |
| 77 scoped_ptr<wallet::FullWallet> ParseJavaWallet(JNIEnv* env, jobject wallet) { | |
| 78 const ScopedJavaLocalRef<jobject> billing_address( | |
| 79 FETCH_JFIELD(env, wallet, WalletBillingAddress)); | |
| 80 const ScopedJavaLocalRef<jobject> shipping_address( | |
| 81 FETCH_JFIELD(env, wallet, WalletShippingAddress)); | |
| 82 const ScopedJavaLocalRef<jobject> card( | |
| 83 FETCH_JFIELD(env, wallet, WalletCardInformation)); | |
| 84 | |
| 85 const int expiration_month = | |
| 86 FETCH_JFIELD(env, card.obj(), WalletCardExpirationMonth); | |
| 87 const int expiration_year = | |
| 88 FETCH_JFIELD(env, card.obj(), WalletCardExpirationYear); | |
| 89 const std::string pan = | |
| 90 FETCH_JSTRING(UTF8, env, card.obj(), WalletCardPan); | |
| 91 const std::string cvn = | |
| 92 FETCH_JSTRING(UTF8, env, card.obj(), WalletCardCvn); | |
| 93 | |
| 94 return wallet::FullWallet::CreateFullWalletFromClearText( | |
| 95 expiration_month, | |
| 96 expiration_year, | |
| 97 pan, | |
| 98 cvn, | |
| 99 ParseJavaWalletAddress(env, billing_address.obj()), | |
| 100 ParseJavaWalletAddress(env, shipping_address.obj())); | |
| 101 } | |
| 102 | |
| 103 base::string16 ParseWalletEmail(JNIEnv* env, jobject wallet) { | |
| 104 return FETCH_JSTRING(UTF16, env, wallet, WalletEmail); | |
| 105 } | |
| 106 | |
| 107 std::string ParseGoogleTransactionId(JNIEnv* env, jobject wallet) { | |
| 108 return FETCH_JSTRING(UTF8, env, wallet, WalletGoogleTransactionId); | |
| 109 } | |
| 110 | |
| 111 #undef FETCH_JSTRING | |
| 112 #undef FETCH_FIELD | |
| 113 | |
| 114 } // namespace | |
| 115 | |
| 116 // static | |
| 117 scoped_ptr<wallet::FullWallet> AutofillDialogResult::ConvertFromJava( | |
| 118 JNIEnv* env, jobject wallet) { | |
| 119 return ParseJavaWallet(env, wallet); | |
| 120 } | |
| 121 | |
| 122 // static | |
| 123 base::string16 AutofillDialogResult::GetWalletEmail( | |
| 124 JNIEnv* env, jobject wallet) { | |
| 125 return ParseWalletEmail(env, wallet); | |
| 126 } | |
| 127 | |
| 128 // static | |
| 129 std::string AutofillDialogResult::GetWalletGoogleTransactionId( | |
| 130 JNIEnv* env, jobject wallet) { | |
| 131 return ParseGoogleTransactionId(env, wallet); | |
| 132 } | |
| 133 | |
| 134 // static | |
| 135 bool AutofillDialogResult::RegisterAutofillDialogResult(JNIEnv* env) { | |
| 136 return RegisterNativesImpl(env); | |
| 137 } | |
| 138 | |
| 139 } // namespace autofill | |
| OLD | NEW |