OLD | NEW |
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 "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/command_line.h" |
9 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 14 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/sync/profile_sync_service.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
16 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
17 #include "components/autofill/core/browser/autofill_country.h" | 21 #include "components/autofill/core/browser/autofill_country.h" |
18 #include "components/autofill/core/browser/autofill_type.h" | 22 #include "components/autofill/core/browser/autofill_type.h" |
19 #include "components/autofill/core/browser/field_types.h" | 23 #include "components/autofill/core/browser/field_types.h" |
20 #include "components/autofill/core/browser/personal_data_manager.h" | 24 #include "components/autofill/core/browser/personal_data_manager.h" |
| 25 #include "components/autofill/core/common/autofill_switches.h" |
21 #include "jni/PersonalDataManager_jni.h" | 26 #include "jni/PersonalDataManager_jni.h" |
22 | 27 |
23 using base::android::ConvertJavaStringToUTF8; | 28 using base::android::ConvertJavaStringToUTF8; |
24 using base::android::ConvertUTF16ToJavaString; | 29 using base::android::ConvertUTF16ToJavaString; |
25 using base::android::ConvertUTF8ToJavaString; | 30 using base::android::ConvertUTF8ToJavaString; |
26 using base::android::ScopedJavaLocalRef; | 31 using base::android::ScopedJavaLocalRef; |
27 | 32 |
28 namespace autofill { | 33 namespace autofill { |
29 namespace { | 34 namespace { |
30 | 35 |
| 36 Profile* GetProfile() { |
| 37 return ProfileManager::GetActiveUserProfile()->GetOriginalProfile(); |
| 38 } |
| 39 |
31 PrefService* GetPrefs() { | 40 PrefService* GetPrefs() { |
32 return | 41 return GetProfile()->GetPrefs(); |
33 ProfileManager::GetActiveUserProfile()->GetOriginalProfile()->GetPrefs(); | |
34 } | 42 } |
35 | 43 |
36 ScopedJavaLocalRef<jobject> CreateJavaProfileFromNative( | 44 ScopedJavaLocalRef<jobject> CreateJavaProfileFromNative( |
37 JNIEnv* env, | 45 JNIEnv* env, |
38 const AutofillProfile& profile) { | 46 const AutofillProfile& profile) { |
39 return Java_AutofillProfile_create( | 47 return Java_AutofillProfile_create( |
40 env, | 48 env, |
41 ConvertUTF8ToJavaString(env, profile.guid()).obj(), | 49 ConvertUTF8ToJavaString(env, profile.guid()).obj(), |
42 ConvertUTF8ToJavaString(env, profile.origin()).obj(), | 50 ConvertUTF8ToJavaString(env, profile.origin()).obj(), |
43 ConvertUTF16ToJavaString(env, profile.GetRawInfo(NAME_FULL)).obj(), | 51 ConvertUTF16ToJavaString(env, profile.GetRawInfo(NAME_FULL)).obj(), |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 298 |
291 return base::android::ToJavaArrayOfStrings(env, labels); | 299 return base::android::ToJavaArrayOfStrings(env, labels); |
292 } | 300 } |
293 | 301 |
294 void PersonalDataManagerAndroid::RemoveByGUID(JNIEnv* env, | 302 void PersonalDataManagerAndroid::RemoveByGUID(JNIEnv* env, |
295 jobject unused_obj, | 303 jobject unused_obj, |
296 jstring jguid) { | 304 jstring jguid) { |
297 personal_data_manager_->RemoveByGUID(ConvertJavaStringToUTF8(env, jguid)); | 305 personal_data_manager_->RemoveByGUID(ConvertJavaStringToUTF8(env, jguid)); |
298 } | 306 } |
299 | 307 |
| 308 void PersonalDataManagerAndroid::ClearUnmaskedCache(JNIEnv* env, |
| 309 jobject unused_obj) { |
| 310 personal_data_manager_->ResetFullServerCards(); |
| 311 } |
| 312 |
300 void PersonalDataManagerAndroid::OnPersonalDataChanged() { | 313 void PersonalDataManagerAndroid::OnPersonalDataChanged() { |
301 JNIEnv* env = base::android::AttachCurrentThread(); | 314 JNIEnv* env = base::android::AttachCurrentThread(); |
302 if (weak_java_obj_.get(env).is_null()) | 315 if (weak_java_obj_.get(env).is_null()) |
303 return; | 316 return; |
304 | 317 |
305 Java_PersonalDataManager_personalDataChanged(env, | 318 Java_PersonalDataManager_personalDataChanged(env, |
306 weak_java_obj_.get(env).obj()); | 319 weak_java_obj_.get(env).obj()); |
307 } | 320 } |
308 | 321 |
309 // static | 322 // static |
310 bool PersonalDataManagerAndroid::Register(JNIEnv* env) { | 323 bool PersonalDataManagerAndroid::Register(JNIEnv* env) { |
311 return RegisterNativesImpl(env); | 324 return RegisterNativesImpl(env); |
312 } | 325 } |
313 | 326 |
314 // Returns whether the Autofill feature is enabled. | 327 // Returns whether the Autofill feature is enabled. |
315 static jboolean IsAutofillEnabled(JNIEnv* env, jclass clazz) { | 328 static jboolean IsAutofillEnabled(JNIEnv* env, jclass clazz) { |
316 return GetPrefs()->GetBoolean(autofill::prefs::kAutofillEnabled); | 329 return GetPrefs()->GetBoolean(autofill::prefs::kAutofillEnabled); |
317 } | 330 } |
318 | 331 |
319 // Enables or disables the Autofill feature. | 332 // Enables or disables the Autofill feature. |
320 static void SetAutofillEnabled(JNIEnv* env, jclass clazz, jboolean enable) { | 333 static void SetAutofillEnabled(JNIEnv* env, jclass clazz, jboolean enable) { |
321 GetPrefs()->SetBoolean(autofill::prefs::kAutofillEnabled, enable); | 334 GetPrefs()->SetBoolean(autofill::prefs::kAutofillEnabled, enable); |
322 } | 335 } |
323 | 336 |
324 // Returns whether Autofill feature is managed. | 337 // Returns whether the Autofill feature is managed. |
325 static jboolean IsAutofillManaged(JNIEnv* env, jclass clazz) { | 338 static jboolean IsAutofillManaged(JNIEnv* env, jclass clazz) { |
326 return GetPrefs()->IsManagedPreference(autofill::prefs::kAutofillEnabled); | 339 return GetPrefs()->IsManagedPreference(autofill::prefs::kAutofillEnabled); |
327 } | 340 } |
328 | 341 |
| 342 // Returns whether the Wallet import feature is available. |
| 343 static jboolean IsWalletImportFeatureAvailable(JNIEnv* env, jclass clazz) { |
| 344 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 345 autofill::switches::kEnableWalletCardImport)) { |
| 346 return false; |
| 347 } |
| 348 |
| 349 // TODO(estade): what to do in the IsManaged case? |
| 350 ProfileSyncService* service = |
| 351 ProfileSyncServiceFactory::GetInstance()->GetForProfile(GetProfile()); |
| 352 return service->IsSyncEnabledAndLoggedIn(); |
| 353 } |
| 354 |
| 355 // Returns whether the Wallet import feature is enabled. |
| 356 static jboolean IsWalletImportEnabled(JNIEnv* env, jclass clazz) { |
| 357 // TODO(estade): there is no pref yet, so just pretend yes. |
| 358 return true; |
| 359 } |
| 360 |
| 361 // Enables or disables the Wallet import feature. |
| 362 static void SetWalletImportEnabled(JNIEnv* env, jclass clazz, jboolean enable) { |
| 363 // TODO(estade): there is no pref yet, so no-op. |
| 364 } |
| 365 |
329 // Returns an ISO 3166-1-alpha-2 country code for a |jcountry_name| using | 366 // Returns an ISO 3166-1-alpha-2 country code for a |jcountry_name| using |
330 // the application locale, or an empty string. | 367 // the application locale, or an empty string. |
331 static jstring ToCountryCode(JNIEnv* env, jclass clazz, jstring jcountry_name) { | 368 static jstring ToCountryCode(JNIEnv* env, jclass clazz, jstring jcountry_name) { |
332 return ConvertUTF8ToJavaString( | 369 return ConvertUTF8ToJavaString( |
333 env, | 370 env, |
334 AutofillCountry::GetCountryCode( | 371 AutofillCountry::GetCountryCode( |
335 base::android::ConvertJavaStringToUTF16(env, jcountry_name), | 372 base::android::ConvertJavaStringToUTF16(env, jcountry_name), |
336 g_browser_process->GetApplicationLocale())).Release(); | 373 g_browser_process->GetApplicationLocale())).Release(); |
337 } | 374 } |
338 | 375 |
339 static jlong Init(JNIEnv* env, jobject obj) { | 376 static jlong Init(JNIEnv* env, jobject obj) { |
340 PersonalDataManagerAndroid* personal_data_manager_android = | 377 PersonalDataManagerAndroid* personal_data_manager_android = |
341 new PersonalDataManagerAndroid(env, obj); | 378 new PersonalDataManagerAndroid(env, obj); |
342 return reinterpret_cast<intptr_t>(personal_data_manager_android); | 379 return reinterpret_cast<intptr_t>(personal_data_manager_android); |
343 } | 380 } |
344 | 381 |
345 } // namespace autofill | 382 } // namespace autofill |
OLD | NEW |