| 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/dom/ContextLifecycleObserver.h" | 11 #include "core/frame/LocalFrameLifecycleObserver.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" | |
| 15 | 13 |
| 16 namespace blink { | 14 namespace blink { |
| 17 | 15 |
| 18 class MessageCallback; | 16 class MessageCallback; |
| 19 class NFCError; | |
| 20 class NFCPushOptions; | 17 class NFCPushOptions; |
| 21 using NFCPushMessage = StringOrArrayBufferOrNFCMessage; | 18 using NFCPushMessage = StringOrArrayBufferOrNFCMessage; |
| 22 class NFCWatchOptions; | 19 class NFCWatchOptions; |
| 23 class ServiceRegistry; | |
| 24 | 20 |
| 25 class NFC final | 21 class NFC final |
| 26 : public GarbageCollectedFinalized<NFC> | 22 : public GarbageCollected<NFC> |
| 27 , public ScriptWrappable | 23 , public ScriptWrappable |
| 28 , public PageLifecycleObserver | 24 , public LocalFrameLifecycleObserver |
| 29 , public ContextLifecycleObserver | 25 , public PageLifecycleObserver { |
| 30 , public device::nfc::blink::NFCClient { | |
| 31 DEFINE_WRAPPERTYPEINFO(); | 26 DEFINE_WRAPPERTYPEINFO(); |
| 32 USING_GARBAGE_COLLECTED_MIXIN(NFC); | 27 USING_GARBAGE_COLLECTED_MIXIN(NFC); |
| 33 USING_PRE_FINALIZER(NFC, dispose); | |
| 34 | 28 |
| 35 public: | 29 public: |
| 36 static NFC* create(LocalFrame*); | 30 static NFC* create(LocalFrame*); |
| 37 | 31 |
| 38 virtual ~NFC(); | |
| 39 | |
| 40 void dispose(); | |
| 41 | |
| 42 // ContextLifecycleObserver overrides. | |
| 43 void contextDestroyed() override; | |
| 44 | |
| 45 // Pushes NFCPushMessage asynchronously to NFC tag / peer. | 32 // Pushes NFCPushMessage asynchronously to NFC tag / peer. |
| 46 ScriptPromise push(ScriptState*, const NFCPushMessage&, const NFCPushOptions
&); | 33 ScriptPromise push(ScriptState*, const NFCPushMessage&, const NFCPushOptions
&); |
| 47 | 34 |
| 48 // Cancels ongoing push operation. | 35 // Cancels ongoing push operation. |
| 49 ScriptPromise cancelPush(ScriptState*, const String&); | 36 ScriptPromise cancelPush(ScriptState*, const String&); |
| 50 | 37 |
| 51 // Starts watching for NFC messages that match NFCWatchOptions criteria. | 38 // Starts watching for NFC messages that match NFCWatchOptions criteria. |
| 52 ScriptPromise watch(ScriptState*, MessageCallback*, const NFCWatchOptions&); | 39 ScriptPromise watch(ScriptState*, MessageCallback*, const NFCWatchOptions&); |
| 53 | 40 |
| 54 // Cancels watch operation with id. | 41 // Cancels watch operation with id. |
| 55 ScriptPromise cancelWatch(ScriptState*, long id); | 42 ScriptPromise cancelWatch(ScriptState*, long id); |
| 56 | 43 |
| 57 // Cancels all watch operations. | 44 // Cancels all watch operations. |
| 58 ScriptPromise cancelWatch(ScriptState*); | 45 ScriptPromise cancelWatch(ScriptState*); |
| 59 | 46 |
| 47 // Implementation of LocalFrameLifecycleObserver. |
| 48 void willDetachFrameHost() override; |
| 49 |
| 60 // Implementation of PageLifecycleObserver. | 50 // Implementation of PageLifecycleObserver. |
| 61 void pageVisibilityChanged() override; | 51 void pageVisibilityChanged() override; |
| 62 | 52 |
| 63 // Interface required by garbage collection. | 53 // Interface required by garbage collection. |
| 64 DECLARE_VIRTUAL_TRACE(); | 54 DECLARE_VIRTUAL_TRACE(); |
| 65 | 55 |
| 66 private: | 56 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: | |
| 74 explicit NFC(LocalFrame*); | 57 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; | |
| 78 }; | 58 }; |
| 79 | 59 |
| 80 } // namespace blink | 60 } // namespace blink |
| 81 | 61 |
| 82 #endif // NFC_h | 62 #endif // NFC_h |
| OLD | NEW |