OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 module device.nfc; | 5 module device.nfc; |
6 | 6 |
7 enum NFCErrorType { | 7 enum NFCErrorType { |
8 SECURITY, | 8 SECURITY, |
9 NOT_SUPPORTED, | 9 NOT_SUPPORTED, |
10 DEVICE_DISABLED, | 10 DEVICE_DISABLED, |
11 NOT_FOUND, | 11 NOT_FOUND, |
12 INVALID_MESSAGE, | 12 INVALID_MESSAGE, |
13 OPERATION_CANCELLED, | 13 OPERATION_CANCELLED, |
14 TIMER_EXPIRED, | 14 TIMER_EXPIRED, |
15 CANNOT_CANCEL, | 15 CANNOT_CANCEL, |
16 IO_ERROR | 16 IO_ERROR |
17 }; | 17 }; |
18 | 18 |
19 enum NFCRecordType { | 19 enum NFCRecordType { |
20 EMPTY, | 20 EMPTY, |
21 TEXT, | 21 TEXT, |
22 URL, | 22 URL, |
23 JSON, | 23 JSON, |
24 OPAQUE_RECORD | 24 OPAQUE_RECORD |
25 }; | 25 }; |
26 | 26 |
27 enum NFCPushTarget { | 27 enum NFCPushTarget { |
28 // The target of a push operation must be the NFC tag. | |
28 TAG, | 29 TAG, |
30 // The target of a push operation must be the NFC peer (device to device). | |
29 PEER, | 31 PEER, |
32 // The target of a push operation must be either NFC tag or peer. | |
30 ANY | 33 ANY |
31 }; | 34 }; |
32 | 35 |
33 enum NFCWatchMode { | 36 enum NFCWatchMode { |
37 // Restricts scope of the watch operation. Only Web NFC messages must be | |
38 // used by matching algorithm. | |
34 WEBNFC_ONLY, | 39 WEBNFC_ONLY, |
40 // Allows performing watch operation for all NFC messages. For example, NFC | |
41 // tags with valid NDEF messages. | |
35 ANY | 42 ANY |
36 }; | 43 }; |
37 | 44 |
38 struct NFCError { | 45 struct NFCError { |
39 NFCErrorType error_type; | 46 NFCErrorType error_type; |
40 }; | 47 }; |
41 | 48 |
42 struct NFCRecord { | 49 struct NFCRecord { |
50 // The type of NFCRecord. | |
43 NFCRecordType recordType; | 51 NFCRecordType recordType; |
52 | |
53 // Represents the IANA media type of the NFCRecord data field. | |
44 string? mediaType; | 54 string? mediaType; |
55 | |
56 // Payload of the NFCRecord. | |
45 array<uint8> data; | 57 array<uint8> data; |
46 }; | 58 }; |
47 | 59 |
48 struct NFCMessage { | 60 struct NFCMessage { |
61 // The body of the NFCMessage is a collection of NFCRecord objects. | |
49 array<NFCRecord> data; | 62 array<NFCRecord> data; |
63 | |
64 // The |url| field is an ASCII serialized origin, optionally followed by a URL | |
65 // path. It represents Web NFC id, that can be used for matching Web NFC | |
66 // content with the filter specified by |url| field in NFCWatchOptions. | |
50 string? url; | 67 string? url; |
51 }; | 68 }; |
52 | 69 |
53 struct NFCPushOptions { | 70 struct NFCPushOptions { |
71 // The target of the push operation. | |
54 NFCPushTarget target; | 72 NFCPushTarget target; |
73 | |
74 // The timeout for the push operation, in milliseconds. | |
55 double timeout; | 75 double timeout; |
76 | |
77 // If the property is true, the push operation will suspend active watchers | |
78 // until it's completion. | |
dcheng
2016/08/17 17:18:47
Nit: its.
| |
56 bool ignoreRead; | 79 bool ignoreRead; |
57 }; | 80 }; |
58 | 81 |
59 struct NFCRecordTypeFilter { | 82 struct NFCRecordTypeFilter { |
60 NFCRecordType recordType; | 83 NFCRecordType recordType; |
61 }; | 84 }; |
62 | 85 |
63 struct NFCWatchOptions { | 86 struct NFCWatchOptions { |
87 // Defines filtering constraint for NFC messages with specified |url|. | |
64 string? url; | 88 string? url; |
89 | |
90 // Defines filtering constraint for NFC records with specified record type. | |
65 NFCRecordTypeFilter? recordFilter; | 91 NFCRecordTypeFilter? recordFilter; |
92 | |
93 // Defines media type filtering constraint. | |
66 string? mediaType; | 94 string? mediaType; |
95 | |
96 // Defines mode of watch operation. | |
67 NFCWatchMode mode; | 97 NFCWatchMode mode; |
68 }; | 98 }; |
69 | 99 |
70 interface NFC { | 100 interface NFC { |
71 // NFCClient interface is used to notify |client| when NFCMessage matches one | 101 // NFCClient interface is used to notify |client| when NFCMessage matches one |
72 // or more pending watch operations. | 102 // or more pending watch operations. |
73 SetClient(NFCClient client); | 103 SetClient(NFCClient client); |
74 | 104 |
75 // Pushes data to NFC device. | 105 // Pushes data to NFC device. |
76 // NFCPushOptions specify timeout and type of device where data should be | 106 // NFCPushOptions specify timeout and type of device where data should be |
77 // pushed. If timeout is defined and data is not pushed before timeout is | 107 // pushed. If timeout is defined and data is not pushed before timeout is |
78 // expired, callback with corresponding error is called. | 108 // expired, callback with corresponding error is called. |
79 Push(NFCMessage message, NFCPushOptions? options) => (NFCError? error); | 109 Push(NFCMessage message, NFCPushOptions? options) => (NFCError? error); |
80 | 110 |
81 // Cancels pending push request. | 111 // Cancels pending push request. |
82 CancelPush(NFCPushTarget target) => (NFCError? error); | 112 CancelPush(NFCPushTarget target) => (NFCError? error); |
83 | 113 |
84 // Starts watching for nearby NFC devices with data that matches | 114 // Starts watching for nearby NFC devices with data that matches |
85 // NFCWatchOptions filtering criteria. On success, watch ID is returned. | 115 // NFCWatchOptions filtering criteria. On success, watch id is returned. |
86 Watch(NFCWatchOptions options) => (uint32 id, NFCError? error); | 116 Watch(NFCWatchOptions options) => (uint32 id, NFCError? error); |
87 | 117 |
88 // Cancels watch operation with provided id. | 118 // Cancels watch operation with provided id. |
89 CancelWatch (uint32 id) => (NFCError? error); | 119 CancelWatch (uint32 id) => (NFCError? error); |
90 | 120 |
91 // Cancels all watch operations. | 121 // Cancels all watch operations. |
92 CancelAllWatches () => (NFCError? error); | 122 CancelAllWatches () => (NFCError? error); |
93 | 123 |
94 // Suspends all pending NFC operations. Could be used when web page | 124 // Suspends all pending NFC operations. Could be used when web page |
95 // visibility or focus is lost. | 125 // visibility or focus is lost. |
96 SuspendNFCOperations(); | 126 SuspendNFCOperations(); |
97 | 127 |
98 // Resumes all suspended NFC operations. | 128 // Resumes all suspended NFC operations. |
99 ResumeNFCOperations(); | 129 ResumeNFCOperations(); |
100 }; | 130 }; |
101 | 131 |
102 interface NFCClient { | 132 interface NFCClient { |
103 OnWatch(array<uint32> watchIDs, NFCMessage message); | 133 OnWatch(array<uint32> watchIDs, NFCMessage message); |
104 }; | 134 }; |
OLD | NEW |