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 package org.chromium.chrome.browser.autofill; | 5 package org.chromium.chrome.browser.autofill; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 | 8 |
9 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
11 import org.chromium.base.annotations.CalledByNative; | 11 import org.chromium.base.annotations.CalledByNative; |
12 import org.chromium.base.annotations.JNINamespace; | 12 import org.chromium.base.annotations.JNINamespace; |
13 import org.chromium.chrome.R; | 13 import org.chromium.chrome.R; |
14 import org.chromium.chrome.browser.ResourceId; | 14 import org.chromium.chrome.browser.ResourceId; |
15 import org.chromium.content_public.browser.WebContents; | |
15 | 16 |
16 import java.util.ArrayList; | 17 import java.util.ArrayList; |
17 import java.util.List; | 18 import java.util.List; |
18 | 19 |
19 /** | 20 /** |
20 * Android wrapper of the PersonalDataManager which provides access from the Jav a | 21 * Android wrapper of the PersonalDataManager which provides access from the Jav a |
21 * layer. | 22 * layer. |
22 * | 23 * |
23 * Only usable from the UI thread as it's primary purpose is for supporting the Android | 24 * Only usable from the UI thread as it's primary purpose is for supporting the Android |
24 * preferences UI. | 25 * preferences UI. |
25 * | 26 * |
26 * See chrome/browser/autofill/personal_data_manager.h for more details. | 27 * See chrome/browser/autofill/personal_data_manager.h for more details. |
27 */ | 28 */ |
28 @JNINamespace("autofill") | 29 @JNINamespace("autofill") |
29 public class PersonalDataManager { | 30 public class PersonalDataManager { |
30 | 31 |
31 /** | 32 /** |
32 * Observer of PersonalDataManager events. | 33 * Observer of PersonalDataManager events. |
33 */ | 34 */ |
34 public interface PersonalDataManagerObserver { | 35 public interface PersonalDataManagerObserver { |
35 /** | 36 /** |
36 * Called when the data is changed. | 37 * Called when the data is changed. |
37 */ | 38 */ |
38 public abstract void onPersonalDataChanged(); | 39 public abstract void onPersonalDataChanged(); |
39 } | 40 } |
40 | 41 |
41 /** | 42 /** |
43 * Callback for full card request. | |
44 */ | |
45 public interface FullCardRequestDelegate { | |
46 /** | |
47 * Called when user provided the full card details, including the CVC an d the full PAN. | |
48 * | |
49 * @param card The full card. | |
50 * @param cvc The CVC for the card. | |
51 */ | |
52 public abstract void onFullCardDetails(CreditCard card, String cvc); | |
Ted C
2016/04/22 23:34:56
drop public and abstract in interfaces
please use gerrit instead
2016/04/23 01:17:42
Done.
| |
53 | |
54 /** | |
55 * Called when user did not provide full card details. | |
56 */ | |
57 public abstract void onFullCardError(); | |
58 } | |
59 | |
60 /** | |
42 * Autofill address information. | 61 * Autofill address information. |
43 */ | 62 */ |
44 public static class AutofillProfile { | 63 public static class AutofillProfile { |
45 private String mGUID; | 64 private String mGUID; |
46 private String mOrigin; | 65 private String mOrigin; |
47 private boolean mIsLocal; | 66 private boolean mIsLocal; |
48 private String mFullName; | 67 private String mFullName; |
49 private String mCompanyName; | 68 private String mCompanyName; |
50 private String mStreetAddress; | 69 private String mStreetAddress; |
51 private String mRegion; | 70 private String mRegion; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 ThreadUtils.assertOnUiThread(); | 427 ThreadUtils.assertOnUiThread(); |
409 if (sManager == null) { | 428 if (sManager == null) { |
410 sManager = new PersonalDataManager(); | 429 sManager = new PersonalDataManager(); |
411 } | 430 } |
412 return sManager; | 431 return sManager; |
413 } | 432 } |
414 | 433 |
415 private final long mPersonalDataManagerAndroid; | 434 private final long mPersonalDataManagerAndroid; |
416 private final List<PersonalDataManagerObserver> mDataObservers = | 435 private final List<PersonalDataManagerObserver> mDataObservers = |
417 new ArrayList<PersonalDataManagerObserver>(); | 436 new ArrayList<PersonalDataManagerObserver>(); |
437 private FullCardRequestDelegate mFullCardRequestDelegate; | |
418 | 438 |
419 private PersonalDataManager() { | 439 private PersonalDataManager() { |
420 // Note that this technically leaks the native object, however, Personal DataManager | 440 // Note that this technically leaks the native object, however, Personal DataManager |
421 // is a singleton that lives forever and there's no clean shutdown of Ch rome on Android | 441 // is a singleton that lives forever and there's no clean shutdown of Ch rome on Android |
422 mPersonalDataManagerAndroid = nativeInit(); | 442 mPersonalDataManagerAndroid = nativeInit(); |
423 } | 443 } |
424 | 444 |
425 /** | 445 /** |
426 * Called from native when template URL service is done loading. | 446 * Called from native when template URL service is done loading. |
427 */ | 447 */ |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 | 525 |
506 public void deleteCreditCard(String guid) { | 526 public void deleteCreditCard(String guid) { |
507 ThreadUtils.assertOnUiThread(); | 527 ThreadUtils.assertOnUiThread(); |
508 nativeRemoveByGUID(mPersonalDataManagerAndroid, guid); | 528 nativeRemoveByGUID(mPersonalDataManagerAndroid, guid); |
509 } | 529 } |
510 | 530 |
511 public void clearUnmaskedCache(String guid) { | 531 public void clearUnmaskedCache(String guid) { |
512 nativeClearUnmaskedCache(mPersonalDataManagerAndroid, guid); | 532 nativeClearUnmaskedCache(mPersonalDataManagerAndroid, guid); |
513 } | 533 } |
514 | 534 |
535 public void unmaskCard(WebContents webContents, String guid, FullCardRequest Delegate delegate) { | |
536 if (mFullCardRequestDelegate != null) { | |
Ted C
2016/04/22 23:34:56
this looks fishy to me. you cancel the previous d
please use gerrit instead
2016/04/23 01:17:43
Done.
| |
537 delegate.onFullCardError(); | |
538 return; | |
539 } | |
540 | |
541 mFullCardRequestDelegate = delegate; | |
542 nativeGetFullCardForPaymentRequest(mPersonalDataManagerAndroid, webConte nts, guid); | |
543 } | |
544 | |
545 @CalledByNative | |
546 private void onFullCardDetails(CreditCard card, String cvc) { | |
547 ThreadUtils.assertOnUiThread(); | |
548 assert mFullCardRequestDelegate != null; | |
549 mFullCardRequestDelegate.onFullCardDetails(card, cvc); | |
550 mFullCardRequestDelegate = null; | |
551 } | |
552 | |
553 @CalledByNative | |
554 private void onFullCardError() { | |
555 ThreadUtils.assertOnUiThread(); | |
556 assert mFullCardRequestDelegate != null; | |
557 mFullCardRequestDelegate.onFullCardError(); | |
558 mFullCardRequestDelegate = null; | |
559 } | |
560 | |
515 /** | 561 /** |
516 * @return Whether the Autofill feature is enabled. | 562 * @return Whether the Autofill feature is enabled. |
517 */ | 563 */ |
518 public static boolean isAutofillEnabled() { | 564 public static boolean isAutofillEnabled() { |
519 return nativeIsAutofillEnabled(); | 565 return nativeIsAutofillEnabled(); |
520 } | 566 } |
521 | 567 |
522 /** | 568 /** |
523 * Enables or disables the Autofill feature. | 569 * Enables or disables the Autofill feature. |
524 * @param enable True to disable Autofill, false otherwise. | 570 * @param enable True to disable Autofill, false otherwise. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 private native int nativeGetCreditCardCount(long nativePersonalDataManagerAn droid); | 607 private native int nativeGetCreditCardCount(long nativePersonalDataManagerAn droid); |
562 private native CreditCard nativeGetCreditCardByIndex(long nativePersonalData ManagerAndroid, | 608 private native CreditCard nativeGetCreditCardByIndex(long nativePersonalData ManagerAndroid, |
563 int index); | 609 int index); |
564 private native CreditCard nativeGetCreditCardByGUID(long nativePersonalDataM anagerAndroid, | 610 private native CreditCard nativeGetCreditCardByGUID(long nativePersonalDataM anagerAndroid, |
565 String guid); | 611 String guid); |
566 private native String nativeSetCreditCard(long nativePersonalDataManagerAndr oid, | 612 private native String nativeSetCreditCard(long nativePersonalDataManagerAndr oid, |
567 CreditCard card); | 613 CreditCard card); |
568 private native void nativeRemoveByGUID(long nativePersonalDataManagerAndroid , String guid); | 614 private native void nativeRemoveByGUID(long nativePersonalDataManagerAndroid , String guid); |
569 private native void nativeClearUnmaskedCache( | 615 private native void nativeClearUnmaskedCache( |
570 long nativePersonalDataManagerAndroid, String guid); | 616 long nativePersonalDataManagerAndroid, String guid); |
617 private native void nativeGetFullCardForPaymentRequest(long nativePersonalDa taManagerAndroid, | |
618 WebContents webContents, String guid); | |
571 private static native boolean nativeIsAutofillEnabled(); | 619 private static native boolean nativeIsAutofillEnabled(); |
572 private static native void nativeSetAutofillEnabled(boolean enable); | 620 private static native void nativeSetAutofillEnabled(boolean enable); |
573 private static native boolean nativeIsAutofillManaged(); | 621 private static native boolean nativeIsAutofillManaged(); |
574 private static native boolean nativeIsPaymentsIntegrationEnabled(); | 622 private static native boolean nativeIsPaymentsIntegrationEnabled(); |
575 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl e); | 623 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl e); |
576 private static native String nativeToCountryCode(String countryName); | 624 private static native String nativeToCountryCode(String countryName); |
577 } | 625 } |
OLD | NEW |