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