OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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; |
| 8 |
7 import org.chromium.base.annotations.SuppressFBWarnings; | 9 import org.chromium.base.annotations.SuppressFBWarnings; |
8 import org.chromium.content_public.browser.WebContents; | 10 import org.chromium.content_public.browser.WebContents; |
9 | 11 |
10 /** | 12 /** |
11 * Helper for detecting whether the device supports scanning credit cards and fo
r scanning credit | 13 * Helper for detecting whether the device supports scanning credit cards and fo
r scanning credit |
12 * cards. The default implementation cannot scan cards. An implementing subclass
must provide a | 14 * cards. The default implementation cannot scan cards. An implementing subclass
must provide a |
13 * factory that builds its instances. | 15 * factory that builds its instances. |
14 */ | 16 */ |
15 public class CreditCardScanner { | 17 public class CreditCardScanner { |
16 /** | 18 /** |
17 * Can be used to build subclasses of the scanner without the user of the cl
ass knowing about | 19 * Can be used to build subclasses of the scanner without the user of the cl
ass knowing about |
18 * the subclass name. | 20 * the subclass name. |
19 */ | 21 */ |
20 private static Factory sFactory; | 22 private static Factory sFactory; |
21 | 23 |
22 /** The delegate to notify of scanning result. */ | 24 /** The delegate to notify of scanning result. */ |
23 protected final Delegate mDelegate; | 25 protected final Delegate mDelegate; |
24 | 26 |
| 27 /** Application context. Used in subclass. */ |
| 28 @SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"}) |
| 29 protected final Context mContext; |
| 30 |
25 /** The web contents that's requesting a scan. Used in subclass. */ | 31 /** The web contents that's requesting a scan. Used in subclass. */ |
26 @SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"}) | 32 @SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"}) |
27 protected final WebContents mWebContents; | 33 protected final WebContents mWebContents; |
28 | 34 |
29 /** Builds instances of credit card scanners. */ | 35 /** Builds instances of credit card scanners. */ |
30 public interface Factory { | 36 public interface Factory { |
31 /** | 37 /** |
32 * Builds an instance of credit card scanner. | 38 * Builds an instance of credit card scanner. |
33 * | 39 * |
| 40 * @param context Application context. |
34 * @param webContents The web contents that are requesting a scan. | 41 * @param webContents The web contents that are requesting a scan. |
35 * @param delegate The delegate to notify of scanning result. | 42 * @param delegate The delegate to notify of scanning result. |
36 * @return An object that can scan a credit card. | 43 * @return An object that can scan a credit card. |
37 */ | 44 */ |
38 CreditCardScanner create(WebContents webContents, Delegate delegate); | 45 CreditCardScanner create(Context context, WebContents webContents, Deleg
ate delegate); |
39 } | 46 } |
40 | 47 |
41 /** The delegate for credit card scanning. */ | 48 /** The delegate for credit card scanning. */ |
42 public interface Delegate { | 49 public interface Delegate { |
43 /** | 50 /** |
44 * Notifies the delegate that scanning was cancelled. | 51 * Notifies the delegate that scanning was cancelled. |
45 */ | 52 */ |
46 void onScanCancelled(); | 53 void onScanCancelled(); |
47 | 54 |
48 /** | 55 /** |
(...skipping 13 matching lines...) Expand all Loading... |
62 * | 69 * |
63 * @param factory Can build instances of credit card scanners. | 70 * @param factory Can build instances of credit card scanners. |
64 */ | 71 */ |
65 public static void setFactory(Factory factory) { | 72 public static void setFactory(Factory factory) { |
66 sFactory = factory; | 73 sFactory = factory; |
67 } | 74 } |
68 | 75 |
69 /** | 76 /** |
70 * Creates an instance of a credit card scanner. | 77 * Creates an instance of a credit card scanner. |
71 * | 78 * |
| 79 * @param context Application context. |
72 * @param webContents The web contents that are requesting a scan. | 80 * @param webContents The web contents that are requesting a scan. |
73 * @param delegate The delegate to notify of scanning result. | 81 * @param delegate The delegate to notify of scanning result. |
74 * @return An object that can scan a credit card. | 82 * @return An object that can scan a credit card. |
75 */ | 83 */ |
76 public static CreditCardScanner create(WebContents webContents, Delegate del
egate) { | 84 public static CreditCardScanner create( |
77 return sFactory != null ? sFactory.create(webContents, delegate) | 85 Context context, WebContents webContents, Delegate delegate) { |
78 : new CreditCardScanner(webContents, delegate); | 86 return sFactory != null ? sFactory.create(context, webContents, delegate
) |
| 87 : new CreditCardScanner(context, webContents, de
legate); |
79 } | 88 } |
80 | 89 |
81 /** | 90 /** |
82 * Constructor for the credit card scanner. | 91 * Constructor for the credit card scanner. |
83 * @param webContents The web contents that are requesting a scan. | 92 * |
| 93 * @param context Application context. |
| 94 * @param webContents The web contents that are requesting a scan. |
84 * @param delegate The delegate to notify of scanning result. | 95 * @param delegate The delegate to notify of scanning result. |
85 */ | 96 */ |
86 protected CreditCardScanner(WebContents webContents, Delegate delegate) { | 97 protected CreditCardScanner(Context context, WebContents webContents, Delega
te delegate) { |
| 98 mContext = context; |
87 mWebContents = webContents; | 99 mWebContents = webContents; |
88 mDelegate = delegate; | 100 mDelegate = delegate; |
89 } | 101 } |
90 | 102 |
91 /** | 103 /** |
92 * Returns true if this instance has the ability to scan credit cards. | 104 * Returns true if this instance has the ability to scan credit cards. |
93 * | 105 * |
94 * @return True if has ability to scan credit cards. | 106 * @return True if has ability to scan credit cards. |
95 */ | 107 */ |
96 public boolean canScan() { | 108 public boolean canScan() { |
97 return false; | 109 return false; |
98 } | 110 } |
99 | 111 |
100 /** | 112 /** |
101 * Scans a credit card. Will invoke a delegate callback with the result. | 113 * Scans a credit card. Will invoke a delegate callback with the result. |
102 */ | 114 */ |
103 public void scan() { | 115 public void scan() { |
104 mDelegate.onScanCancelled(); | 116 mDelegate.onScanCancelled(); |
105 } | 117 } |
106 } | 118 } |
OLD | NEW |