| 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/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptWrappable.h" | 10 #include "bindings/core/v8/ScriptWrappable.h" |
| 11 #include "bindings/modules/v8/UnionTypesModules.h" | 11 #include "bindings/modules/v8/UnionTypesModules.h" |
| 12 #include "core/page/PageLifecycleObserver.h" | 12 #include "core/page/PageLifecycleObserver.h" |
| 13 #include "device/nfc/nfc.mojom-wtf.h" | 13 #include "device/nfc/nfc.mojom-wtf.h" |
| 14 #include "modules/nfc/MessageCallback.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "wtf/HashMap.h" |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 | 19 |
| 18 class MessageCallback; | 20 class MessageCallback; |
| 19 class NFCError; | 21 class NFCError; |
| 20 class NFCPushOptions; | 22 class NFCPushOptions; |
| 21 using NFCPushMessage = StringOrArrayBufferOrNFCMessage; | 23 using NFCPushMessage = StringOrArrayBufferOrNFCMessage; |
| 24 class NFCWatchCallback; |
| 22 class NFCWatchOptions; | 25 class NFCWatchOptions; |
| 23 class ServiceRegistry; | 26 class ServiceRegistry; |
| 24 | 27 |
| 25 class NFC final | 28 class NFC final |
| 26 : public GarbageCollectedFinalized<NFC> | 29 : public GarbageCollectedFinalized<NFC> |
| 27 , public ScriptWrappable | 30 , public ScriptWrappable |
| 28 , public PageLifecycleObserver | 31 , public PageLifecycleObserver |
| 29 , WTF_NON_EXPORTED_BASE(public device::wtf::NFCClient) | 32 , WTF_NON_EXPORTED_BASE(public device::wtf::NFCClient) |
| 30 { | 33 { |
| 31 DEFINE_WRAPPERTYPEINFO(); | 34 DEFINE_WRAPPERTYPEINFO(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 // Cancels all watch operations. | 54 // Cancels all watch operations. |
| 52 ScriptPromise cancelWatch(ScriptState*); | 55 ScriptPromise cancelWatch(ScriptState*); |
| 53 | 56 |
| 54 // Implementation of PageLifecycleObserver. | 57 // Implementation of PageLifecycleObserver. |
| 55 void pageVisibilityChanged() override; | 58 void pageVisibilityChanged() override; |
| 56 | 59 |
| 57 // Interface required by garbage collection. | 60 // Interface required by garbage collection. |
| 58 DECLARE_VIRTUAL_TRACE(); | 61 DECLARE_VIRTUAL_TRACE(); |
| 59 | 62 |
| 60 private: | 63 private: |
| 64 friend class NFCWatchCallback; |
| 61 bool Initialize(ServiceRegistry*); | 65 bool Initialize(ServiceRegistry*); |
| 66 |
| 67 // Returns promise with DOMException if feature is not supported |
| 68 // or when context is not secure. Otherwise, returns empty promise. |
| 69 ScriptPromise RejectIfNotSupported(ScriptState*); |
| 62 void OnError(); | 70 void OnError(); |
| 63 // device::wtf::NFCClient implementation | 71 // device::wtf::NFCClient implementation |
| 64 void OnWatch(uint32_t id, device::wtf::NFCMessagePtr) override; | 72 void OnWatch(uint32_t id, device::wtf::NFCMessagePtr) override; |
| 73 void OnWatchRegistered(uint32_t id, MessageCallback*); |
| 65 | 74 |
| 66 private: | 75 private: |
| 67 explicit NFC(LocalFrame*); | 76 explicit NFC(LocalFrame*); |
| 68 device::wtf::NFCPtr m_nfc; | 77 device::wtf::NFCPtr m_nfc; |
| 69 mojo::Binding<device::wtf::NFCClient> m_client; | 78 mojo::Binding<device::wtf::NFCClient> m_client; |
| 79 using WatchCallbacksMap = HeapHashMap<uint32_t, Member<MessageCallback>>; |
| 80 WatchCallbacksMap m_callbacks; |
| 70 }; | 81 }; |
| 71 | 82 |
| 72 } // namespace blink | 83 } // namespace blink |
| 73 | 84 |
| 74 #endif // NFC_h | 85 #endif // NFC_h |
| OLD | NEW |