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