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

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

Issue 1860933002: Handle null values when constructing a native AutofillProfile from an Android one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autofill/android/personal_data_manager_android.h" 5 #include "chrome/browser/autofill/android/personal_data_manager_android.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/android/jni_array.h" 9 #include "base/android/jni_array.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 ConvertUTF16ToJavaString( 66 ConvertUTF16ToJavaString(
67 env, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)).obj(), 67 env, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)).obj(),
68 ConvertUTF16ToJavaString( 68 ConvertUTF16ToJavaString(
69 env, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)).obj(), 69 env, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)).obj(),
70 ConvertUTF16ToJavaString( 70 ConvertUTF16ToJavaString(
71 env, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)).obj(), 71 env, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)).obj(),
72 ConvertUTF16ToJavaString(env, profile.GetRawInfo(EMAIL_ADDRESS)).obj(), 72 ConvertUTF16ToJavaString(env, profile.GetRawInfo(EMAIL_ADDRESS)).obj(),
73 ConvertUTF8ToJavaString(env, profile.language_code()).obj()); 73 ConvertUTF8ToJavaString(env, profile.language_code()).obj());
74 } 74 }
75 75
76 void MaybeSetRawInfo(AutofillProfile* profile,
77 autofill::ServerFieldType type,
78 const base::android::JavaRef<jstring>& jstr) {
79 if (!jstr.is_null())
80 profile->SetRawInfo(type, ConvertJavaStringToUTF16(jstr));
81 }
82
76 void PopulateNativeProfileFromJava( 83 void PopulateNativeProfileFromJava(
77 const jobject& jprofile, 84 const JavaParamRef<jobject>& jprofile,
78 JNIEnv* env, 85 JNIEnv* env,
79 AutofillProfile* profile) { 86 AutofillProfile* profile) {
80 profile->set_origin( 87 profile->set_origin(
81 ConvertJavaStringToUTF8( 88 ConvertJavaStringToUTF8(
82 Java_AutofillProfile_getOrigin(env, jprofile))); 89 Java_AutofillProfile_getOrigin(env, jprofile.obj())));
83 profile->SetInfo( 90 profile->SetInfo(AutofillType(NAME_FULL),
84 AutofillType(NAME_FULL),
85 ConvertJavaStringToUTF16(Java_AutofillProfile_getFullName(env, jprofile)),
86 g_browser_process->GetApplicationLocale());
87 profile->SetRawInfo(autofill::COMPANY_NAME,
88 ConvertJavaStringToUTF16(
89 Java_AutofillProfile_getCompanyName(env, jprofile)));
90 profile->SetRawInfo(
91 autofill::ADDRESS_HOME_STREET_ADDRESS,
92 ConvertJavaStringToUTF16(
93 Java_AutofillProfile_getStreetAddress(env, jprofile)));
94 profile->SetRawInfo(
95 autofill::ADDRESS_HOME_STATE,
96 ConvertJavaStringToUTF16(Java_AutofillProfile_getRegion(env, jprofile)));
97 profile->SetRawInfo(autofill::ADDRESS_HOME_CITY,
98 ConvertJavaStringToUTF16(
99 Java_AutofillProfile_getLocality(env, jprofile)));
100 profile->SetRawInfo(
101 autofill::ADDRESS_HOME_DEPENDENT_LOCALITY,
102 ConvertJavaStringToUTF16(
103 Java_AutofillProfile_getDependentLocality(env, jprofile)));
104 profile->SetRawInfo(autofill::ADDRESS_HOME_ZIP,
105 ConvertJavaStringToUTF16(
106 Java_AutofillProfile_getPostalCode(env, jprofile)));
107 profile->SetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE,
108 ConvertJavaStringToUTF16(
109 Java_AutofillProfile_getSortingCode(env, jprofile)));
110 profile->SetInfo(AutofillType(ADDRESS_HOME_COUNTRY),
111 ConvertJavaStringToUTF16( 91 ConvertJavaStringToUTF16(
112 Java_AutofillProfile_getCountryCode(env, jprofile)), 92 Java_AutofillProfile_getFullName(env, jprofile.obj())),
113 g_browser_process->GetApplicationLocale()); 93 g_browser_process->GetApplicationLocale());
114 profile->SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER, 94 MaybeSetRawInfo(profile, autofill::COMPANY_NAME,
115 ConvertJavaStringToUTF16( 95 Java_AutofillProfile_getCompanyName(env, jprofile.obj()));
116 Java_AutofillProfile_getPhoneNumber(env, jprofile))); 96 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_STREET_ADDRESS,
117 profile->SetRawInfo(autofill::EMAIL_ADDRESS, 97 Java_AutofillProfile_getStreetAddress(env, jprofile.obj()));
118 ConvertJavaStringToUTF16( 98 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_STATE,
119 Java_AutofillProfile_getEmailAddress(env, jprofile))); 99 Java_AutofillProfile_getRegion(env, jprofile.obj()));
100 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_CITY,
101 Java_AutofillProfile_getLocality(env, jprofile.obj()));
102 MaybeSetRawInfo(
103 profile, autofill::ADDRESS_HOME_DEPENDENT_LOCALITY,
104 Java_AutofillProfile_getDependentLocality(env, jprofile.obj()));
105 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_ZIP,
106 Java_AutofillProfile_getPostalCode(env, jprofile.obj()));
107 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_SORTING_CODE,
108 Java_AutofillProfile_getSortingCode(env, jprofile.obj()));
109 ScopedJavaLocalRef<jstring> country_code =
110 Java_AutofillProfile_getCountryCode(env, jprofile.obj());
111 if (!country_code.is_null()) {
112 profile->SetInfo(AutofillType(ADDRESS_HOME_COUNTRY),
113 ConvertJavaStringToUTF16(country_code),
114 g_browser_process->GetApplicationLocale());
115 }
116 MaybeSetRawInfo(profile, autofill::PHONE_HOME_WHOLE_NUMBER,
117 Java_AutofillProfile_getPhoneNumber(env, jprofile.obj()));
118 MaybeSetRawInfo(profile, autofill::EMAIL_ADDRESS,
119 Java_AutofillProfile_getEmailAddress(env, jprofile.obj()));
120 profile->set_language_code( 120 profile->set_language_code(
121 ConvertJavaStringToUTF8( 121 ConvertJavaStringToUTF8(
122 Java_AutofillProfile_getLanguageCode(env, jprofile))); 122 Java_AutofillProfile_getLanguageCode(env, jprofile.obj())));
123 } 123 }
124 124
125 ScopedJavaLocalRef<jobject> CreateJavaCreditCardFromNative( 125 ScopedJavaLocalRef<jobject> CreateJavaCreditCardFromNative(
126 JNIEnv* env, 126 JNIEnv* env,
127 const CreditCard& card) { 127 const CreditCard& card) {
128 return Java_CreditCard_create( 128 return Java_CreditCard_create(
129 env, ConvertUTF8ToJavaString(env, card.guid()).obj(), 129 env, ConvertUTF8ToJavaString(env, card.guid()).obj(),
130 ConvertUTF8ToJavaString(env, card.origin()).obj(), 130 ConvertUTF8ToJavaString(env, card.origin()).obj(),
131 card.record_type() == CreditCard::LOCAL_CARD, 131 card.record_type() == CreditCard::LOCAL_CARD,
132 card.record_type() == CreditCard::FULL_SERVER_CARD, 132 card.record_type() == CreditCard::FULL_SERVER_CARD,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); 358 base::android::ConvertJavaStringToUTF16(env, jcountry_name)));
359 } 359 }
360 360
361 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 361 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
362 PersonalDataManagerAndroid* personal_data_manager_android = 362 PersonalDataManagerAndroid* personal_data_manager_android =
363 new PersonalDataManagerAndroid(env, obj); 363 new PersonalDataManagerAndroid(env, obj);
364 return reinterpret_cast<intptr_t>(personal_data_manager_android); 364 return reinterpret_cast<intptr_t>(personal_data_manager_android);
365 } 365 }
366 366
367 } // namespace autofill 367 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698