Chromium Code Reviews| Index: chrome/browser/ui/android/autofill/autofill_dialog_result.cc |
| diff --git a/chrome/browser/ui/android/autofill/autofill_dialog_result.cc b/chrome/browser/ui/android/autofill/autofill_dialog_result.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..18a87340ddb4c577124e81b7a4bad19c8aeb5c76 |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/autofill/autofill_dialog_result.cc |
| @@ -0,0 +1,139 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/android/autofill/autofill_dialog_result.h" |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_array.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/android/scoped_java_ref.h" |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| +#include "components/autofill/content/browser/wallet/full_wallet.h" |
| +#include "components/autofill/core/browser/credit_card.h" |
| +#include "components/autofill/core/common/form_data.h" |
| +#include "jni/AutofillDialogResult_jni.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +namespace autofill { |
| + |
| +namespace { |
| + |
| +std::string ConvertNullOrJavaStringToUTF8(JNIEnv* env, jstring str) { |
| + return str ? base::android::ConvertJavaStringToUTF8(env, str) : std::string(); |
| +} |
| + |
| +base::string16 ConvertNullOrJavaStringToUTF16(JNIEnv* env, jstring str) { |
| + return str ? base::android::ConvertJavaStringToUTF16(env, str) |
| + : base::string16(); |
| +} |
| + |
| +#define FETCH_JFIELD(env, jobj, getter) \ |
| + (Java_AutofillDialogResult_get##getter((env), (jobj))) |
| + |
| +#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
|
| + (ConvertNullOrJavaStringTo##utf( \ |
| + (env), FETCH_JFIELD((env), (jobj), getter).obj())) |
| + |
| +scoped_ptr<wallet::Address> ParseJavaWalletAddress( |
| + JNIEnv* env, jobject address) { |
| + if (!address) |
| + return scoped_ptr<wallet::Address>(); |
| + |
| + const base::string16 recipient_name = |
| + FETCH_JSTRING(UTF16, env, address, WalletAddressFullName); |
| + const base::string16 address_line_1 = |
| + FETCH_JSTRING(UTF16, env, address, WalletAddressLine1); |
| + const base::string16 address_line_2 = |
| + FETCH_JSTRING(UTF16, env, address, WalletAddressLine2); |
| + const base::string16 locality_name = |
| + FETCH_JSTRING(UTF16, env, address, WalletAddressCity); |
| + const base::string16 administrative_area_name = |
| + FETCH_JSTRING(UTF16, env, address, WalletAddressState); |
| + const base::string16 postal_code_number = |
| + FETCH_JSTRING(UTF16, env, address, WalletAddressPostalCode); |
| + const base::string16 phone_number = |
| + FETCH_JSTRING(UTF16, env, address, WalletAddressPhoneNumber); |
| + |
| + std::string country_name_code = |
| + FETCH_JSTRING(UTF8, env, address, WalletAddressCountryCode); |
| + DCHECK(!country_name_code.empty()); |
| + |
| + return scoped_ptr<wallet::Address>(new wallet::Address( |
| + country_name_code, |
| + recipient_name, |
| + address_line_1, |
| + address_line_2, |
| + locality_name, |
| + administrative_area_name, |
| + postal_code_number, |
| + phone_number, |
| + std::string())); |
| +} |
| + |
| +scoped_ptr<wallet::FullWallet> ParseJavaWallet(JNIEnv* env, jobject wallet) { |
| + const ScopedJavaLocalRef<jobject> billing_address( |
| + FETCH_JFIELD(env, wallet, WalletBillingAddress)); |
| + const ScopedJavaLocalRef<jobject> shipping_address( |
| + FETCH_JFIELD(env, wallet, WalletShippingAddress)); |
| + const ScopedJavaLocalRef<jobject> card( |
| + FETCH_JFIELD(env, wallet, WalletCardInformation)); |
| + |
| + const int expiration_month = |
| + FETCH_JFIELD(env, card.obj(), WalletCardExpirationMonth); |
| + const int expiration_year = |
| + FETCH_JFIELD(env, card.obj(), WalletCardExpirationYear); |
| + const std::string pan = |
| + FETCH_JSTRING(UTF8, env, card.obj(), WalletCardPan); |
| + const std::string cvn = |
| + FETCH_JSTRING(UTF8, env, card.obj(), WalletCardCvn); |
| + |
| + return wallet::FullWallet::CreateFullWalletFromClearText( |
| + expiration_month, |
| + expiration_year, |
| + pan, |
| + cvn, |
| + ParseJavaWalletAddress(env, billing_address.obj()), |
| + ParseJavaWalletAddress(env, shipping_address.obj())); |
| +} |
| + |
| +base::string16 ParseWalletEmail(JNIEnv* env, jobject wallet) { |
| + return FETCH_JSTRING(UTF16, env, wallet, WalletEmail); |
| +} |
| + |
| +std::string ParseGoogleTransactionId(JNIEnv* env, jobject wallet) { |
| + return FETCH_JSTRING(UTF8, env, wallet, WalletGoogleTransactionId); |
| +} |
| + |
| +#undef FETCH_JSTRING |
| +#undef FETCH_FIELD |
| + |
| +} // namespace |
| + |
| +// static |
| +scoped_ptr<wallet::FullWallet> AutofillDialogResult::ConvertFromJava( |
| + JNIEnv* env, jobject wallet) { |
| + return ParseJavaWallet(env, wallet); |
| +} |
| + |
| +// static |
| +base::string16 AutofillDialogResult::GetWalletEmail( |
| + JNIEnv* env, jobject wallet) { |
| + return ParseWalletEmail(env, wallet); |
| +} |
| + |
| +// static |
| +std::string AutofillDialogResult::GetWalletGoogleTransactionId( |
| + JNIEnv* env, jobject wallet) { |
| + return ParseGoogleTransactionId(env, wallet); |
| +} |
| + |
| +// static |
| +bool AutofillDialogResult::RegisterAutofillDialogResult(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +} // namespace autofill |