OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef MIDIAccess_h | 31 #ifndef MIDIAccess_h |
32 #define MIDIAccess_h | 32 #define MIDIAccess_h |
33 | 33 |
| 34 #include "bindings/v8/MIDIAccessResolver.h" |
| 35 #include "bindings/v8/ScriptPromise.h" |
34 #include "bindings/v8/ScriptWrappable.h" | 36 #include "bindings/v8/ScriptWrappable.h" |
35 #include "core/dom/ActiveDOMObject.h" | 37 #include "core/dom/ActiveDOMObject.h" |
36 #include "core/events/EventTarget.h" | 38 #include "core/events/EventTarget.h" |
37 #include "heap/Handle.h" | 39 #include "heap/Handle.h" |
38 #include "modules/webmidi/MIDIAccessor.h" | 40 #include "modules/webmidi/MIDIAccessor.h" |
39 #include "modules/webmidi/MIDIAccessorClient.h" | 41 #include "modules/webmidi/MIDIAccessorClient.h" |
40 #include "modules/webmidi/MIDIInput.h" | 42 #include "modules/webmidi/MIDIInput.h" |
| 43 #include "modules/webmidi/MIDIOptions.h" |
41 #include "modules/webmidi/MIDIOutput.h" | 44 #include "modules/webmidi/MIDIOutput.h" |
| 45 #include "platform/AsyncMethodRunner.h" |
42 #include "wtf/RefCounted.h" | 46 #include "wtf/RefCounted.h" |
43 #include "wtf/RefPtr.h" | 47 #include "wtf/RefPtr.h" |
44 #include "wtf/Vector.h" | |
45 | 48 |
46 namespace WebCore { | 49 namespace WebCore { |
47 | 50 |
48 class ExecutionContext; | 51 class ExecutionContext; |
49 class MIDIAccessPromise; | |
50 | 52 |
51 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA
ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn
lineData, public MIDIAccessorClient { | 53 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA
ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn
lineData, public MIDIAccessorClient { |
52 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<M
IDIAccess>); | 54 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<M
IDIAccess>); |
53 public: | 55 public: |
54 virtual ~MIDIAccess(); | 56 virtual ~MIDIAccess(); |
55 static PassRefPtrWillBeRawPtr<MIDIAccess> create(ExecutionContext*, MIDIAcce
ssPromise*); | 57 // Returns a promise object that will be resolved with this MIDIAccess. |
| 58 static ScriptPromise request(const MIDIOptions&, ExecutionContext*); |
56 | 59 |
57 MIDIInputVector inputs() const { return m_inputs; } | 60 MIDIInputVector inputs() const { return m_inputs; } |
58 MIDIOutputVector outputs() const { return m_outputs; } | 61 MIDIOutputVector outputs() const { return m_outputs; } |
59 | 62 |
60 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); | 63 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); |
61 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); | 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); |
62 | 65 |
63 void setSysExEnabled(bool); | 66 void setSysExEnabled(bool); |
64 bool sysExEnabled() const { return m_sysExEnabled; } | 67 bool sysExEnabled() const { return m_sysExEnabled; } |
65 | 68 |
66 // EventTarget | 69 // EventTarget |
67 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar
getNames::MIDIAccess; } | 70 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar
getNames::MIDIAccess; } |
68 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD
OMObject::executionContext(); } | 71 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD
OMObject::executionContext(); } |
69 | 72 |
70 // ActiveDOMObject | 73 // ActiveDOMObject |
| 74 virtual void suspend() OVERRIDE; |
| 75 virtual void resume() OVERRIDE; |
71 virtual void stop() OVERRIDE; | 76 virtual void stop() OVERRIDE; |
| 77 virtual bool hasPendingActivity() const OVERRIDE; |
72 | 78 |
73 // MIDIAccessorClient | 79 // MIDIAccessorClient |
74 virtual void didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) OVERRIDE; | 80 virtual void didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) OVERRIDE; |
75 virtual void didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) OVERRIDE; | 81 virtual void didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) OVERRIDE; |
76 virtual void didStartSession(bool success) OVERRIDE; | 82 virtual void didStartSession(bool success) OVERRIDE; |
77 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat
a, size_t length, double timeStamp) OVERRIDE; | 83 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat
a, size_t length, double timeStamp) OVERRIDE; |
78 | 84 |
79 // |timeStampInMilliseconds| is in the same time coordinate system as perfor
mance.now(). | 85 // |timeStampInMilliseconds| is in the same time coordinate system as perfor
mance.now(). |
80 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng
th, double timeStampInMilliseconds); | 86 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng
th, double timeStampInMilliseconds); |
81 | 87 |
82 void trace(Visitor*); | 88 void trace(Visitor*); |
83 | 89 |
84 private: | 90 private: |
85 MIDIAccess(ExecutionContext*, MIDIAccessPromise*); | 91 class PostAction; |
| 92 enum State { |
| 93 Requesting, |
| 94 Resolved, |
| 95 Stopped, |
| 96 }; |
86 | 97 |
87 void startRequest(); | 98 MIDIAccess(const MIDIOptions&, ExecutionContext*); |
| 99 ScriptPromise startRequest(); |
| 100 |
88 void permissionDenied(); | 101 void permissionDenied(); |
89 | 102 |
| 103 void resolve(); |
| 104 void reject(PassRefPtr<DOMError>); |
| 105 void resolveNow(); |
| 106 void rejectNow(); |
| 107 // Called when the promise is resolved or rejected. |
| 108 void doPostAction(State); |
| 109 |
| 110 State m_state; |
90 MIDIInputVector m_inputs; | 111 MIDIInputVector m_inputs; |
91 MIDIOutputVector m_outputs; | 112 MIDIOutputVector m_outputs; |
92 RawPtrWillBeMember<MIDIAccessPromise> m_promise; | |
93 | |
94 OwnPtr<MIDIAccessor> m_accessor; | 113 OwnPtr<MIDIAccessor> m_accessor; |
95 bool m_hasAccess; | 114 OwnPtr<MIDIAccessResolver> m_resolver; |
| 115 MIDIOptions m_options; |
96 bool m_sysExEnabled; | 116 bool m_sysExEnabled; |
97 bool m_requesting; | 117 AsyncMethodRunner<MIDIAccess> m_asyncResolveRunner; |
| 118 AsyncMethodRunner<MIDIAccess> m_asyncRejectRunner; |
| 119 RefPtr<DOMError> m_error; |
98 }; | 120 }; |
99 | 121 |
100 } // namespace WebCore | 122 } // namespace WebCore |
101 | 123 |
102 #endif // MIDIAccess_h | 124 #endif // MIDIAccess_h |
OLD | NEW |