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 #ifndef NFC_h | 5 #ifndef NFC_h |
6 #define NFC_h | 6 #define NFC_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
10 #include "bindings/modules/v8/StringOrArrayBufferOrNFCMessage.h" | 10 #include "bindings/modules/v8/StringOrArrayBufferOrNFCMessage.h" |
11 #include "core/frame/LocalFrameLifecycleObserver.h" | 11 #include "core/dom/ContextLifecycleObserver.h" |
12 #include "core/page/PageLifecycleObserver.h" | 12 #include "core/page/PageLifecycleObserver.h" |
| 13 #include "device/nfc/nfc.mojom-blink.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" |
13 | 15 |
14 namespace blink { | 16 namespace blink { |
15 | 17 |
16 class MessageCallback; | 18 class MessageCallback; |
| 19 class NFCError; |
17 class NFCPushOptions; | 20 class NFCPushOptions; |
18 using NFCPushMessage = StringOrArrayBufferOrNFCMessage; | 21 using NFCPushMessage = StringOrArrayBufferOrNFCMessage; |
19 class NFCWatchOptions; | 22 class NFCWatchOptions; |
| 23 class ServiceRegistry; |
20 | 24 |
21 class NFC final | 25 class NFC final |
22 : public GarbageCollected<NFC> | 26 : public GarbageCollectedFinalized<NFC> |
23 , public ScriptWrappable | 27 , public ScriptWrappable |
24 , public LocalFrameLifecycleObserver | 28 , public PageLifecycleObserver |
25 , public PageLifecycleObserver { | 29 , public ContextLifecycleObserver |
| 30 , public device::nfc::blink::NFCClient { |
26 DEFINE_WRAPPERTYPEINFO(); | 31 DEFINE_WRAPPERTYPEINFO(); |
27 USING_GARBAGE_COLLECTED_MIXIN(NFC); | 32 USING_GARBAGE_COLLECTED_MIXIN(NFC); |
| 33 USING_PRE_FINALIZER(NFC, dispose); |
28 | 34 |
29 public: | 35 public: |
30 static NFC* create(LocalFrame*); | 36 static NFC* create(LocalFrame*); |
31 | 37 |
| 38 virtual ~NFC(); |
| 39 |
| 40 void dispose(); |
| 41 |
| 42 // ContextLifecycleObserver overrides. |
| 43 void contextDestroyed() override; |
| 44 |
32 // Pushes NFCPushMessage asynchronously to NFC tag / peer. | 45 // Pushes NFCPushMessage asynchronously to NFC tag / peer. |
33 ScriptPromise push(ScriptState*, const NFCPushMessage&, const NFCPushOptions
&); | 46 ScriptPromise push(ScriptState*, const NFCPushMessage&, const NFCPushOptions
&); |
34 | 47 |
35 // Cancels ongoing push operation. | 48 // Cancels ongoing push operation. |
36 ScriptPromise cancelPush(ScriptState*, const String&); | 49 ScriptPromise cancelPush(ScriptState*, const String&); |
37 | 50 |
38 // Starts watching for NFC messages that match NFCWatchOptions criteria. | 51 // Starts watching for NFC messages that match NFCWatchOptions criteria. |
39 ScriptPromise watch(ScriptState*, MessageCallback*, const NFCWatchOptions&); | 52 ScriptPromise watch(ScriptState*, MessageCallback*, const NFCWatchOptions&); |
40 | 53 |
41 // Cancels watch operation with id. | 54 // Cancels watch operation with id. |
42 ScriptPromise cancelWatch(ScriptState*, long id); | 55 ScriptPromise cancelWatch(ScriptState*, long id); |
43 | 56 |
44 // Cancels all watch operations. | 57 // Cancels all watch operations. |
45 ScriptPromise cancelWatch(ScriptState*); | 58 ScriptPromise cancelWatch(ScriptState*); |
46 | 59 |
47 // Implementation of LocalFrameLifecycleObserver. | |
48 void willDetachFrameHost() override; | |
49 | |
50 // Implementation of PageLifecycleObserver. | 60 // Implementation of PageLifecycleObserver. |
51 void pageVisibilityChanged() override; | 61 void pageVisibilityChanged() override; |
52 | 62 |
53 // Interface required by garbage collection. | 63 // Interface required by garbage collection. |
54 DECLARE_VIRTUAL_TRACE(); | 64 DECLARE_VIRTUAL_TRACE(); |
55 | 65 |
56 private: | 66 private: |
| 67 void OnRequestCompleted(ScriptPromiseResolver*, device::nfc::blink::NFCError
Ptr); |
| 68 void OnConnectionError(); |
| 69 |
| 70 // device::nfc::blink::NFCClient implementation. |
| 71 void OnWatch(mojo::WTFArray<uint32_t> ids, device::nfc::blink::NFCMessagePtr
) override; |
| 72 |
| 73 private: |
57 explicit NFC(LocalFrame*); | 74 explicit NFC(LocalFrame*); |
| 75 device::nfc::blink::NFCPtr m_nfc; |
| 76 mojo::Binding<device::nfc::blink::NFCClient> m_client; |
| 77 HeapHashSet<Member<ScriptPromiseResolver>> m_requests; |
58 }; | 78 }; |
59 | 79 |
60 } // namespace blink | 80 } // namespace blink |
61 | 81 |
62 #endif // NFC_h | 82 #endif // NFC_h |
OLD | NEW |