Index: chrome/browser/autofill/personal_data_manager_android.cc |
diff --git a/chrome/browser/autofill/personal_data_manager_android.cc b/chrome/browser/autofill/personal_data_manager_android.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..aebd54aae0e893d8c0f761a19ba8b1d162d544c8 |
--- /dev/null |
+++ b/chrome/browser/autofill/personal_data_manager_android.cc |
@@ -0,0 +1,138 @@ |
+// 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.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Populates default autofill profile from user's own Android contact. |
+ |
+#include <vector> |
+ |
+#include "base/android/jni_android.h" |
+#include "base/android/jni_array.h" |
+#include "base/android/jni_string.h" |
+#include "base/guid.h" |
+#include "base/logging.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/string16.h" |
+#include "base/utf_string_conversions.h" |
+ |
+#include "chrome/browser/autofill/personal_data_manager.h" |
+#include "chrome/browser/autofill/phone_number.h" |
+ |
+#include "jni/PersonalAutofillPopulator_jni.h" |
+ |
+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.
|
+ "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
|
+ |
+bool RegisterPersonalDataManager(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+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.
|
+ ScopedJavaLocalRef<jobject> populator, |
+ 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.
|
+ ScopedJavaLocalRef<jstring> street = |
+ Java_PersonalAutofillPopulator_getStreet(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> pobox = |
+ Java_PersonalAutofillPopulator_getPobox(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> neighborhood = |
+ Java_PersonalAutofillPopulator_getNeighborhood(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> city = |
+ Java_PersonalAutofillPopulator_getCity(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> region = |
+ Java_PersonalAutofillPopulator_getRegion(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> postalCode = |
+ Java_PersonalAutofillPopulator_getPostalCode(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> country = |
+ Java_PersonalAutofillPopulator_getCountry(env, populator.obj()); |
+ |
+ if (!street.is_null()) |
+ profile->SetRawInfo(ADDRESS_HOME_LINE1, |
+ 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
|
+ if (!city.is_null()) |
+ profile->SetRawInfo(ADDRESS_HOME_CITY, |
+ 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.
|
+ if (!region.is_null()) |
+ profile->SetRawInfo(ADDRESS_HOME_STATE, |
+ ConvertJavaStringToUTF16(region)); |
+ if (!postalCode.is_null()) |
+ profile->SetRawInfo(ADDRESS_HOME_ZIP, |
+ ConvertJavaStringToUTF16(postalCode)); |
aurimas (slooooooooow)
2013/02/15 19:08:35
Align with ADDRESS_HOME_ZIP
apiccion
2013/02/26 23:51:51
Done.
|
+ if (!country.is_null()) |
+ profile->SetRawInfo(ADDRESS_HOME_COUNTRY, |
+ ConvertJavaStringToUTF16(country)); |
aurimas (slooooooooow)
2013/02/15 19:08:35
Align with ADDRESS_HOME_COUNTRY
apiccion
2013/02/26 23:51:51
Done.
|
+} |
+ |
+void LoadNameWithPopulator(JNIEnv * env, |
+ ScopedJavaLocalRef<jobject> populator, |
+ AutofillProfile * profile) { |
+ ScopedJavaLocalRef<jstring> firstName = |
+ Java_PersonalAutofillPopulator_getFirstName(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> middleName= |
+ Java_PersonalAutofillPopulator_getMiddleName(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> lastName = |
+ Java_PersonalAutofillPopulator_getLastName(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> suffix = |
+ Java_PersonalAutofillPopulator_getSuffix(env, populator.obj()); |
+ ScopedJavaLocalRef<jstring> fullName = |
+ Java_PersonalAutofillPopulator_getFullName(env, populator.obj()); |
+ |
+ if (!firstName.is_null()) |
+ profile->SetRawInfo(NAME_FIRST, ConvertJavaStringToUTF16(firstName)); |
+ if (!middleName.is_null()) |
+ profile->SetRawInfo(NAME_MIDDLE, ConvertJavaStringToUTF16(middleName)); |
+ if (!lastName.is_null()) |
+ profile->SetRawInfo(NAME_LAST, ConvertJavaStringToUTF16(lastName)); |
+ if (!fullName.is_null()) |
+ 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.
|
+ if (!suffix.is_null()) |
+ profile->SetRawInfo(NAME_SUFFIX, ConvertJavaStringToUTF16(suffix)); |
+} |
+ |
+void LoadEmailAddressWithPopulator(JNIEnv * env, |
+ ScopedJavaLocalRef<jobject> populator, |
+ AutofillProfile * profile) { |
+ ScopedJavaLocalRef<jobjectArray> emailAddresses = |
+ Java_PersonalAutofillPopulator_getEmailAddresses(env, populator.obj()); |
+ std::vector<string16> emailAddressVector; |
+ if (!emailAddresses.is_null()) { |
+ base::android::AppendJavaStringArrayToStringVector(env, |
+ emailAddresses.obj(), |
+ &emailAddressVector); |
+ profile->SetRawMultiInfo(EMAIL_ADDRESS, emailAddressVector); |
+ } |
+} |
+ |
+void LoadPhoneNumbersWithPopulator(JNIEnv * env, |
+ ScopedJavaLocalRef<jobject> populator, |
+ AutofillProfile * profile) { |
+ ScopedJavaLocalRef<jobjectArray> phoneNumbers = |
+ Java_PersonalAutofillPopulator_getPhoneNumbers(env, populator.obj()); |
+ |
+ std::vector<string16> phoneNumberVector; |
+ if (!phoneNumbers.is_null()) { |
+ base::android::AppendJavaStringArrayToStringVector(env, |
+ phoneNumbers.obj(), |
+ &phoneNumberVector); |
+ profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phoneNumberVector); |
+ } |
+} |
+ |
+void PersonalDataManager::LoadAuxiliaryProfiles() { |
+ auxiliary_profiles_.clear(); |
+ |
+ 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.
|
+ scoped_ptr<AutofillProfile> profile(new AutofillProfile(guid)); |
+ DCHECK(base::IsValidGUID(profile->guid())); |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ ScopedJavaLocalRef<jobject> populator = |
+ 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.
|
+ base::android::GetApplicationContext()); |
+ |
+ LoadNameWithPopulator(env, populator, profile.get()); |
+ LoadEmailAddressWithPopulator(env, populator, profile.get()); |
+ LoadPhoneNumbersWithPopulator(env, populator, profile.get()); |
+ // 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.
|
+ /* Disable address loading until we can parse the big address |
+ blob into its constituent fields */ |
+ auxiliary_profiles_.push_back(profile.release()); |
+} |