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

Side by Side Diff: chrome/browser/autofill/personal_data_manager_android.cc

Issue 12282004: Added personal_data_manager android implementation for auto-populating auto-fill on android builds … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
aurimas (slooooooooow) 2013/02/15 19:08:35 2013
apiccion 2013/02/26 23:51:51 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Populates default autofill profile from user's own Android contact.
6
7 #include <vector>
8
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h"
12 #include "base/guid.h"
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/string16.h"
16 #include "base/utf_string_conversions.h"
17
18 #include "chrome/browser/autofill/personal_data_manager.h"
19 #include "chrome/browser/autofill/phone_number.h"
20
21 #include "jni/PersonalAutofillPopulator_jni.h"
22
23 static const std::string ANDROID_ME_CONTACT_AUOTFILL_PROFILE_GUID =
Ilya Sherman 2013/02/16 04:14:37 nit: This should be "const char kAndroidMeContactA
apiccion 2013/02/26 23:51:51 Done.
apiccion 2013/02/26 23:51:51 Done.
24 "9A9E1C06-7A3B-48FA-AA4F-135CA6FC25D9";
aurimas (slooooooooow) 2013/02/15 19:08:35 Where is this specified?
apiccion 2013/02/26 23:51:51 Randomly generated guid. We need a consistent guid
25
26 bool RegisterPersonalDataManager(JNIEnv* env) {
27 return RegisterNativesImpl(env);
28 }
29
30 void LoadAddressWithPopulator(JNIEnv * env,
aurimas (slooooooooow) 2013/02/15 19:08:35 Should all of these functions live in some sort of
apiccion 2013/02/26 23:51:51 Done.
31 ScopedJavaLocalRef<jobject> populator,
32 AutofillProfile * profile) {
Ilya Sherman 2013/02/16 04:14:37 nit: No space before the asterisk. (Applies throu
apiccion 2013/02/26 23:51:51 Done.
33 ScopedJavaLocalRef<jstring> street =
34 Java_PersonalAutofillPopulator_getStreet(env, populator.obj());
35 ScopedJavaLocalRef<jstring> pobox =
36 Java_PersonalAutofillPopulator_getPobox(env, populator.obj());
37 ScopedJavaLocalRef<jstring> neighborhood =
38 Java_PersonalAutofillPopulator_getNeighborhood(env, populator.obj());
39 ScopedJavaLocalRef<jstring> city =
40 Java_PersonalAutofillPopulator_getCity(env, populator.obj());
41 ScopedJavaLocalRef<jstring> region =
42 Java_PersonalAutofillPopulator_getRegion(env, populator.obj());
43 ScopedJavaLocalRef<jstring> postalCode =
44 Java_PersonalAutofillPopulator_getPostalCode(env, populator.obj());
45 ScopedJavaLocalRef<jstring> country =
46 Java_PersonalAutofillPopulator_getCountry(env, populator.obj());
47
48 if (!street.is_null())
49 profile->SetRawInfo(ADDRESS_HOME_LINE1,
50 ConvertJavaStringToUTF16(street));
Ilya Sherman 2013/02/16 04:14:37 Android addresses can't have address line 2 data?
apiccion 2013/02/26 23:51:51 Added function to build address line 2 from misc d
51 if (!city.is_null())
52 profile->SetRawInfo(ADDRESS_HOME_CITY,
53 ConvertJavaStringToUTF16(city));
Ilya Sherman 2013/02/16 04:14:37 nit: Curly braces, since this if-stmt's body spans
apiccion 2013/02/26 23:51:51 Done.
54 if (!region.is_null())
55 profile->SetRawInfo(ADDRESS_HOME_STATE,
56 ConvertJavaStringToUTF16(region));
57 if (!postalCode.is_null())
58 profile->SetRawInfo(ADDRESS_HOME_ZIP,
59 ConvertJavaStringToUTF16(postalCode));
aurimas (slooooooooow) 2013/02/15 19:08:35 Align with ADDRESS_HOME_ZIP
apiccion 2013/02/26 23:51:51 Done.
60 if (!country.is_null())
61 profile->SetRawInfo(ADDRESS_HOME_COUNTRY,
62 ConvertJavaStringToUTF16(country));
aurimas (slooooooooow) 2013/02/15 19:08:35 Align with ADDRESS_HOME_COUNTRY
apiccion 2013/02/26 23:51:51 Done.
63 }
64
65 void LoadNameWithPopulator(JNIEnv * env,
66 ScopedJavaLocalRef<jobject> populator,
67 AutofillProfile * profile) {
68 ScopedJavaLocalRef<jstring> firstName =
69 Java_PersonalAutofillPopulator_getFirstName(env, populator.obj());
70 ScopedJavaLocalRef<jstring> middleName=
71 Java_PersonalAutofillPopulator_getMiddleName(env, populator.obj());
72 ScopedJavaLocalRef<jstring> lastName =
73 Java_PersonalAutofillPopulator_getLastName(env, populator.obj());
74 ScopedJavaLocalRef<jstring> suffix =
75 Java_PersonalAutofillPopulator_getSuffix(env, populator.obj());
76 ScopedJavaLocalRef<jstring> fullName =
77 Java_PersonalAutofillPopulator_getFullName(env, populator.obj());
78
79 if (!firstName.is_null())
80 profile->SetRawInfo(NAME_FIRST, ConvertJavaStringToUTF16(firstName));
81 if (!middleName.is_null())
82 profile->SetRawInfo(NAME_MIDDLE, ConvertJavaStringToUTF16(middleName));
83 if (!lastName.is_null())
84 profile->SetRawInfo(NAME_LAST, ConvertJavaStringToUTF16(lastName));
85 if (!fullName.is_null())
86 profile->SetRawInfo(NAME_FULL, ConvertJavaStringToUTF16(fullName));
Ilya Sherman 2013/02/16 04:14:37 You should either set the first, middle, and last
apiccion 2013/02/26 23:51:51 Done.
87 if (!suffix.is_null())
88 profile->SetRawInfo(NAME_SUFFIX, ConvertJavaStringToUTF16(suffix));
89 }
90
91 void LoadEmailAddressWithPopulator(JNIEnv * env,
92 ScopedJavaLocalRef<jobject> populator,
93 AutofillProfile * profile) {
94 ScopedJavaLocalRef<jobjectArray> emailAddresses =
95 Java_PersonalAutofillPopulator_getEmailAddresses(env, populator.obj());
96 std::vector<string16> emailAddressVector;
97 if (!emailAddresses.is_null()) {
98 base::android::AppendJavaStringArrayToStringVector(env,
99 emailAddresses.obj(),
100 &emailAddressVector);
101 profile->SetRawMultiInfo(EMAIL_ADDRESS, emailAddressVector);
102 }
103 }
104
105 void LoadPhoneNumbersWithPopulator(JNIEnv * env,
106 ScopedJavaLocalRef<jobject> populator,
107 AutofillProfile * profile) {
108 ScopedJavaLocalRef<jobjectArray> phoneNumbers =
109 Java_PersonalAutofillPopulator_getPhoneNumbers(env, populator.obj());
110
111 std::vector<string16> phoneNumberVector;
112 if (!phoneNumbers.is_null()) {
113 base::android::AppendJavaStringArrayToStringVector(env,
114 phoneNumbers.obj(),
115 &phoneNumberVector);
116 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phoneNumberVector);
117 }
118 }
119
120 void PersonalDataManager::LoadAuxiliaryProfiles() {
121 auxiliary_profiles_.clear();
122
123 std::string guid(ANDROID_ME_CONTACT_AUOTFILL_PROFILE_GUID);
Ilya Sherman 2013/02/16 04:14:37 nit: No need to make a copy here.
apiccion 2013/02/26 23:51:51 Done.
124 scoped_ptr<AutofillProfile> profile(new AutofillProfile(guid));
125 DCHECK(base::IsValidGUID(profile->guid()));
126 JNIEnv* env = base::android::AttachCurrentThread();
127 ScopedJavaLocalRef<jobject> populator =
128 Java_PersonalAutofillPopulator_create(env,
David Trainor- moved to gerrit 2013/02/19 19:03:13 I'm not sure about the formatting here. You might
apiccion 2013/02/26 23:51:51 Done.
129 base::android::GetApplicationContext());
130
131 LoadNameWithPopulator(env, populator, profile.get());
132 LoadEmailAddressWithPopulator(env, populator, profile.get());
133 LoadPhoneNumbersWithPopulator(env, populator, profile.get());
134 // LoadAddressWithPopulator(env, populator, profile.get());
aurimas (slooooooooow) 2013/02/15 19:08:35 Why is this like commented out?
David Trainor- moved to gerrit 2013/02/19 19:03:13 I think Address parsing isn't working. Can we jus
apiccion 2013/02/26 23:51:51 Done.
135 /* Disable address loading until we can parse the big address
136 blob into its constituent fields */
137 auxiliary_profiles_.push_back(profile.release());
138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698