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