| 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" | 48 #include "wtf/WeakPtr.h" |
| 45 | 49 |
| 46 namespace WebCore { | 50 namespace WebCore { |
| 47 | 51 |
| 48 class ExecutionContext; | 52 class ExecutionContext; |
| 49 class MIDIAccessPromise; | |
| 50 | 53 |
| 51 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA
ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn
lineData, public MIDIAccessorClient { | 54 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA
ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn
lineData, public MIDIAccessorClient { |
| 52 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<M
IDIAccess>); | 55 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<M
IDIAccess>); |
| 53 public: | 56 public: |
| 54 virtual ~MIDIAccess(); | 57 virtual ~MIDIAccess(); |
| 55 static PassRefPtrWillBeRawPtr<MIDIAccess> create(ExecutionContext*, MIDIAcce
ssPromise*); | 58 // Returns a promise object that will be resolved with this MIDIAccess. |
| 59 static ScriptPromise request(const MIDIOptions&, ExecutionContext*); |
| 56 | 60 |
| 57 MIDIInputVector inputs() const { return m_inputs; } | 61 MIDIInputVector inputs() const { return m_inputs; } |
| 58 MIDIOutputVector outputs() const { return m_outputs; } | 62 MIDIOutputVector outputs() const { return m_outputs; } |
| 59 | 63 |
| 60 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); | 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); |
| 61 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); | 65 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); |
| 62 | 66 |
| 63 void setSysExEnabled(bool); | 67 void setSysExEnabled(bool); |
| 64 bool sysExEnabled() const { return m_sysExEnabled; } | 68 bool sysExEnabled() const { return m_sysExEnabled; } |
| 65 | 69 |
| 66 // EventTarget | 70 // EventTarget |
| 67 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar
getNames::MIDIAccess; } | 71 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar
getNames::MIDIAccess; } |
| 68 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD
OMObject::executionContext(); } | 72 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD
OMObject::executionContext(); } |
| 69 | 73 |
| 70 // ActiveDOMObject | 74 // ActiveDOMObject |
| 75 virtual void suspend() OVERRIDE; |
| 76 virtual void resume() OVERRIDE; |
| 71 virtual void stop() OVERRIDE; | 77 virtual void stop() OVERRIDE; |
| 78 virtual bool hasPendingActivity() const OVERRIDE; |
| 72 | 79 |
| 73 // MIDIAccessorClient | 80 // MIDIAccessorClient |
| 74 virtual void didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) OVERRIDE; | 81 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; | 82 virtual void didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) OVERRIDE; |
| 76 virtual void didStartSession(bool success) OVERRIDE; | 83 virtual void didStartSession(bool success) OVERRIDE; |
| 77 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat
a, size_t length, double timeStamp) OVERRIDE; | 84 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat
a, size_t length, double timeStamp) OVERRIDE; |
| 78 | 85 |
| 79 // |timeStampInMilliseconds| is in the same time coordinate system as perfor
mance.now(). | 86 // |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); | 87 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng
th, double timeStampInMilliseconds); |
| 81 | 88 |
| 82 void trace(Visitor*); | 89 void trace(Visitor*); |
| 83 | 90 |
| 84 private: | 91 private: |
| 85 MIDIAccess(ExecutionContext*, MIDIAccessPromise*); | 92 class PostAction; |
| 93 enum State { |
| 94 Requesting, |
| 95 Resolved, |
| 96 Stopped, |
| 97 }; |
| 86 | 98 |
| 87 void startRequest(); | 99 MIDIAccess(const MIDIOptions&, ExecutionContext*); |
| 100 ScriptPromise startRequest(); |
| 101 |
| 88 void permissionDenied(); | 102 void permissionDenied(); |
| 89 | 103 |
| 104 void resolve(); |
| 105 void reject(PassRefPtr<DOMError>); |
| 106 void resolveNow(); |
| 107 void rejectNow(); |
| 108 // Called when the promise is resolved or rejected. |
| 109 void doPostAction(State); |
| 110 |
| 111 State m_state; |
| 112 WeakPtrFactory<MIDIAccess> m_weakPtrFactory; |
| 90 MIDIInputVector m_inputs; | 113 MIDIInputVector m_inputs; |
| 91 MIDIOutputVector m_outputs; | 114 MIDIOutputVector m_outputs; |
| 92 RawPtrWillBeMember<MIDIAccessPromise> m_promise; | |
| 93 | |
| 94 OwnPtr<MIDIAccessor> m_accessor; | 115 OwnPtr<MIDIAccessor> m_accessor; |
| 95 bool m_hasAccess; | 116 OwnPtr<MIDIAccessResolver> m_resolver; |
| 117 MIDIOptions m_options; |
| 96 bool m_sysExEnabled; | 118 bool m_sysExEnabled; |
| 97 bool m_requesting; | 119 AsyncMethodRunner<MIDIAccess> m_asyncResolveRunner; |
| 120 AsyncMethodRunner<MIDIAccess> m_asyncRejectRunner; |
| 121 RefPtr<DOMError> m_error; |
| 98 }; | 122 }; |
| 99 | 123 |
| 100 } // namespace WebCore | 124 } // namespace WebCore |
| 101 | 125 |
| 102 #endif // MIDIAccess_h | 126 #endif // MIDIAccess_h |
| OLD | NEW |