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