Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: chrome/browser/ui/android/autofill/autofill_dialog_result.cc

Issue 22566004: [rAc Android dialog] Stubs for Autofill dialog integration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Ted's suggestions. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/android/autofill/autofill_dialog_result.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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, cls, getter) \
35 (Java_##cls##_get##getter((env), (jobj)))
36
37 #define FETCH_JSTRING(utf, env, jobj, cls, getter) \
38 (ConvertNullOrJavaStringTo##utf( \
39 (env), FETCH_JFIELD((env), (jobj), cls, 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, ResultAddress, Name);
48 const base::string16 address_line_1 =
49 FETCH_JSTRING(UTF16, env, address, ResultAddress, Address1);
50 const base::string16 address_line_2 =
51 FETCH_JSTRING(UTF16, env, address, ResultAddress, Address2);
52 const base::string16 locality_name =
53 FETCH_JSTRING(UTF16, env, address, ResultAddress, City);
54 const base::string16 administrative_area_name =
55 FETCH_JSTRING(UTF16, env, address, ResultAddress, State);
56 const base::string16 postal_code_number =
57 FETCH_JSTRING(UTF16, env, address, ResultAddress, PostalCode);
58 const base::string16 phone_number =
59 FETCH_JSTRING(UTF16, env, address, ResultAddress, PhoneNumber);
60 const std::string country_name_code =
61 FETCH_JSTRING(UTF8, env, address, ResultAddress, CountryCode);
62 DCHECK(!country_name_code.empty());
63
64 return scoped_ptr<wallet::Address>(new wallet::Address(
65 country_name_code,
66 recipient_name,
67 address_line_1,
68 address_line_2,
69 locality_name,
70 administrative_area_name,
71 postal_code_number,
72 phone_number,
73 std::string()));
74 }
75
76 scoped_ptr<wallet::FullWallet> ParseJavaWallet(JNIEnv* env, jobject wallet) {
77 const ScopedJavaLocalRef<jobject> billing_address(
78 FETCH_JFIELD(env, wallet, ResultWallet, BillingAddress));
79 const ScopedJavaLocalRef<jobject> shipping_address(
80 FETCH_JFIELD(env, wallet, ResultWallet, ShippingAddress));
81 const ScopedJavaLocalRef<jobject> card(
82 FETCH_JFIELD(env, wallet, ResultWallet, Card));
83
84 const int expiration_month =
85 FETCH_JFIELD(env, card.obj(), ResultCard, ExpirationMonth);
86 const int expiration_year =
87 FETCH_JFIELD(env, card.obj(), ResultCard, ExpirationYear);
88 const std::string pan =
89 FETCH_JSTRING(UTF8, env, card.obj(), ResultCard, Pan);
90 const std::string cvn =
91 FETCH_JSTRING(UTF8, env, card.obj(), ResultCard, Cvn);
92
93 return wallet::FullWallet::CreateFullWalletFromClearText(
94 expiration_month,
95 expiration_year,
96 pan,
97 cvn,
98 ParseJavaWalletAddress(env, billing_address.obj()),
99 ParseJavaWalletAddress(env, shipping_address.obj()));
100 }
101
102 base::string16 ParseWalletEmail(JNIEnv* env, jobject wallet) {
103 return FETCH_JSTRING(UTF16, env, wallet, ResultWallet, Email);
104 }
105
106 std::string ParseGoogleTransactionId(JNIEnv* env, jobject wallet) {
107 return FETCH_JSTRING(UTF8, env, wallet, ResultWallet, GoogleTransactionId);
108 }
109
110 #undef FETCH_JSTRING
111 #undef FETCH_FIELD
112
113 } // namespace
114
115 // static
116 scoped_ptr<wallet::FullWallet> AutofillDialogResult::ConvertFromJava(
117 JNIEnv* env, jobject wallet) {
118 return ParseJavaWallet(env, wallet);
119 }
120
121 // static
122 base::string16 AutofillDialogResult::GetWalletEmail(
123 JNIEnv* env, jobject wallet) {
124 return ParseWalletEmail(env, wallet);
125 }
126
127 // static
128 std::string AutofillDialogResult::GetWalletGoogleTransactionId(
129 JNIEnv* env, jobject wallet) {
130 return ParseGoogleTransactionId(env, wallet);
131 }
132
133 // static
134 bool AutofillDialogResult::RegisterAutofillDialogResult(JNIEnv* env) {
135 return RegisterNativesImpl(env);
136 }
137
138 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/android/autofill/autofill_dialog_result.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698