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