| 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 17 matching lines...) Expand all Loading... |
| 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/ScriptPromise.h" | 34 #include "bindings/v8/ScriptPromise.h" |
| 35 #include "bindings/v8/ScriptWrappable.h" | 35 #include "bindings/v8/ScriptWrappable.h" |
| 36 #include "core/dom/ActiveDOMObject.h" | 36 #include "core/dom/ActiveDOMObject.h" |
| 37 #include "modules/EventTargetModules.h" | 37 #include "modules/EventTargetModules.h" |
| 38 #include "modules/webmidi/MIDIAccessInitializer.h" |
| 38 #include "modules/webmidi/MIDIAccessor.h" | 39 #include "modules/webmidi/MIDIAccessor.h" |
| 39 #include "modules/webmidi/MIDIAccessorClient.h" | 40 #include "modules/webmidi/MIDIAccessorClient.h" |
| 40 #include "modules/webmidi/MIDIInput.h" | 41 #include "modules/webmidi/MIDIInput.h" |
| 41 #include "modules/webmidi/MIDIOutput.h" | 42 #include "modules/webmidi/MIDIOutput.h" |
| 42 #include "platform/AsyncMethodRunner.h" | 43 #include "platform/AsyncMethodRunner.h" |
| 43 #include "platform/heap/Handle.h" | 44 #include "platform/heap/Handle.h" |
| 44 #include "wtf/RefCounted.h" | 45 #include "wtf/RefCounted.h" |
| 45 #include "wtf/RefPtr.h" | 46 #include "wtf/RefPtr.h" |
| 47 #include "wtf/Vector.h" |
| 46 #include "wtf/WeakPtr.h" | 48 #include "wtf/WeakPtr.h" |
| 47 | 49 |
| 48 namespace WebCore { | 50 namespace WebCore { |
| 49 | 51 |
| 50 class ExecutionContext; | 52 class ExecutionContext; |
| 51 class MIDIAccessInitializer; | |
| 52 struct MIDIOptions; | 53 struct MIDIOptions; |
| 53 | 54 |
| 54 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA
ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn
lineData, public MIDIAccessorClient { | 55 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA
ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn
lineData, public MIDIAccessorClient { |
| 55 REFCOUNTED_EVENT_TARGET(MIDIAccess); | 56 REFCOUNTED_EVENT_TARGET(MIDIAccess); |
| 56 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MIDIAccess); | 57 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MIDIAccess); |
| 57 public: | 58 public: |
| 59 static PassRefPtrWillBeRawPtr<MIDIAccess> create(PassOwnPtr<MIDIAccessor> ac
cessor, bool sysexEnabled, const Vector<MIDIAccessInitializer::PortDescriptor>&
ports, ExecutionContext* executionContext) |
| 60 { |
| 61 RefPtrWillBeRawPtr<MIDIAccess> access = adoptRefWillBeRefCountedGarbageC
ollected(new MIDIAccess(accessor, sysexEnabled, ports, executionContext)); |
| 62 access->suspendIfNeeded(); |
| 63 return access; |
| 64 } |
| 58 virtual ~MIDIAccess(); | 65 virtual ~MIDIAccess(); |
| 59 // Returns a promise object that will be resolved with this MIDIAccess. | |
| 60 static ScriptPromise request(const MIDIOptions&, ScriptState*); | |
| 61 | 66 |
| 62 MIDIInputVector inputs() const { return m_inputs; } | 67 MIDIInputVector inputs() const { return m_inputs; } |
| 63 MIDIOutputVector outputs() const { return m_outputs; } | 68 MIDIOutputVector outputs() const { return m_outputs; } |
| 64 | 69 |
| 65 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); | 70 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); |
| 66 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); | 71 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); |
| 67 | 72 |
| 68 bool sysexEnabled() const { return m_sysexEnabled; } | 73 bool sysexEnabled() const { return m_sysexEnabled; } |
| 69 | 74 |
| 70 // EventTarget | 75 // EventTarget |
| 71 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar
getNames::MIDIAccess; } | 76 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar
getNames::MIDIAccess; } |
| 72 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD
OMObject::executionContext(); } | 77 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD
OMObject::executionContext(); } |
| 73 | 78 |
| 74 // ActiveDOMObject | 79 // ActiveDOMObject |
| 75 virtual void stop() OVERRIDE; | 80 virtual void stop() OVERRIDE; |
| 76 virtual bool hasPendingActivity() const OVERRIDE; | |
| 77 | 81 |
| 78 // MIDIAccessorClient | 82 // MIDIAccessorClient |
| 79 virtual void didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) OVERRIDE; | 83 virtual void didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) OVERRIDE; |
| 80 virtual void didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) OVERRIDE; | 84 virtual void didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) OVERRIDE; |
| 81 virtual void didStartSession(bool success, const String& error, const String
& message) OVERRIDE { } | 85 virtual void didStartSession(bool success, const String& error, const String
& message) OVERRIDE { } |
| 82 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat
a, size_t length, double timeStamp) OVERRIDE; | 86 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat
a, size_t length, double timeStamp) OVERRIDE; |
| 83 | 87 |
| 84 // |timeStampInMilliseconds| is in the same time coordinate system as perfor
mance.now(). | 88 // |timeStampInMilliseconds| is in the same time coordinate system as perfor
mance.now(). |
| 85 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng
th, double timeStampInMilliseconds); | 89 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng
th, double timeStampInMilliseconds); |
| 86 | 90 |
| 87 // Initialize this object before exposing it to JavaScript. | |
| 88 void initialize(PassOwnPtr<MIDIAccessor>, bool sysexEnabled); | |
| 89 | |
| 90 virtual void trace(Visitor*) OVERRIDE; | 91 virtual void trace(Visitor*) OVERRIDE; |
| 91 | 92 |
| 92 private: | 93 private: |
| 93 MIDIAccess(const MIDIOptions&, ExecutionContext*); | 94 MIDIAccess(PassOwnPtr<MIDIAccessor>, bool sysexEnabled, const Vector<MIDIAcc
essInitializer::PortDescriptor>&, ExecutionContext*); |
| 94 | 95 |
| 96 OwnPtr<MIDIAccessor> m_accessor; |
| 97 bool m_sysexEnabled; |
| 95 MIDIInputVector m_inputs; | 98 MIDIInputVector m_inputs; |
| 96 MIDIOutputVector m_outputs; | 99 MIDIOutputVector m_outputs; |
| 97 OwnPtr<MIDIAccessor> m_accessor; | |
| 98 bool m_sysexEnabled; | |
| 99 | |
| 100 // FIXME: Stop owning initializer in this class. | |
| 101 OwnPtr<MIDIAccessInitializer> m_initializer; | |
| 102 }; | 100 }; |
| 103 | 101 |
| 104 } // namespace WebCore | 102 } // namespace WebCore |
| 105 | 103 |
| 106 #endif // MIDIAccess_h | 104 #endif // MIDIAccess_h |
| OLD | NEW |