OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.payments; | 5 package org.chromium.chrome.browser.payments; |
6 | 6 |
7 import android.content.Context; | |
8 import android.os.Handler; | 7 import android.os.Handler; |
9 import android.text.TextUtils; | 8 import android.text.TextUtils; |
10 | 9 |
11 import org.json.JSONObject; | |
12 | |
13 import org.chromium.chrome.browser.autofill.PersonalDataManager; | 10 import org.chromium.chrome.browser.autofill.PersonalDataManager; |
14 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 11 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
15 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; | 12 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
16 import org.chromium.content_public.browser.WebContents; | 13 import org.chromium.content_public.browser.WebContents; |
17 | 14 |
| 15 import org.json.JSONObject; |
| 16 |
18 import java.util.ArrayList; | 17 import java.util.ArrayList; |
19 import java.util.HashSet; | 18 import java.util.HashSet; |
20 import java.util.List; | 19 import java.util.List; |
21 import java.util.Set; | 20 import java.util.Set; |
22 | 21 |
23 /** | 22 /** |
24 * Provides access to locally stored user credit cards. | 23 * Provides access to locally stored user credit cards. |
25 */ | 24 */ |
26 public class AutofillPaymentApp implements PaymentApp { | 25 public class AutofillPaymentApp implements PaymentApp { |
27 private final Context mContext; | |
28 private final WebContents mWebContents; | 26 private final WebContents mWebContents; |
29 | 27 |
30 /** | 28 /** |
31 * Builds a payment app backed by autofill cards. | 29 * Builds a payment app backed by autofill cards. |
32 * | 30 * |
33 * @param context The context. | |
34 * @param webContents The web contents where PaymentRequest was invoked. | 31 * @param webContents The web contents where PaymentRequest was invoked. |
35 */ | 32 */ |
36 public AutofillPaymentApp(Context context, WebContents webContents) { | 33 public AutofillPaymentApp(WebContents webContents) { |
37 mContext = context; | |
38 mWebContents = webContents; | 34 mWebContents = webContents; |
39 } | 35 } |
40 | 36 |
41 @Override | 37 @Override |
42 public void getInstruments(JSONObject unusedDetails, final InstrumentsCallba
ck callback) { | 38 public void getInstruments(JSONObject unusedDetails, final InstrumentsCallba
ck callback) { |
43 PersonalDataManager pdm = PersonalDataManager.getInstance(); | 39 PersonalDataManager pdm = PersonalDataManager.getInstance(); |
44 List<CreditCard> cards = pdm.getCreditCardsToSuggest(); | 40 List<CreditCard> cards = pdm.getCreditCardsToSuggest(); |
45 final List<PaymentInstrument> instruments = new ArrayList<>(cards.size()
); | 41 final List<PaymentInstrument> instruments = new ArrayList<>(cards.size()
); |
46 | 42 |
47 for (int i = 0; i < cards.size(); i++) { | 43 for (int i = 0; i < cards.size(); i++) { |
48 CreditCard card = cards.get(i); | 44 CreditCard card = cards.get(i); |
49 AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAd
dressId()) | 45 AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAd
dressId()) |
50 ? null : pdm.getProfile(card.getBillingAddressId()); | 46 ? null : pdm.getProfile(card.getBillingAddressId()); |
51 instruments.add(new AutofillPaymentInstrument(mContext, mWebContents
, card, | 47 instruments.add(new AutofillPaymentInstrument(mWebContents, card, bi
llingAddress)); |
52 billingAddress)); | |
53 } | 48 } |
54 | 49 |
55 new Handler().post(new Runnable() { | 50 new Handler().post(new Runnable() { |
56 @Override | 51 @Override |
57 public void run() { | 52 public void run() { |
58 callback.onInstrumentsReady(AutofillPaymentApp.this, instruments
); | 53 callback.onInstrumentsReady(AutofillPaymentApp.this, instruments
); |
59 } | 54 } |
60 }); | 55 }); |
61 } | 56 } |
62 | 57 |
(...skipping 18 matching lines...) Expand all Loading... |
81 methods.add("generic"); | 76 methods.add("generic"); |
82 | 77 |
83 return methods; | 78 return methods; |
84 } | 79 } |
85 | 80 |
86 @Override | 81 @Override |
87 public String getIdentifier() { | 82 public String getIdentifier() { |
88 return "Chrome_Autofill_Payment_App"; | 83 return "Chrome_Autofill_Payment_App"; |
89 } | 84 } |
90 } | 85 } |
OLD | NEW |