1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MIDIAccessInitializer_h 6 #define MIDIAccessInitializer_h 7 8 #include "bindings/v8/ScriptPromise.h" 9 #include "bindings/v8/ScriptPromiseResolverWithContext.h" 10 #include "modules/webmidi/MIDIAccessor.h" 11 #include "modules/webmidi/MIDIAccessorClient.h" 12 #include "modules/webmidi/MIDIOptions.h" 13 #include "modules/webmidi/MIDIPort.h" 14 #include "wtf/OwnPtr.h" 15 #include "wtf/RawPtr.h" 16 #include "wtf/Vector.h" 17 18 namespace WebCore { 19 20 class MIDIAccess; 21 class Navigator; 22 class ScriptState; 23 24 class MIDIAccessInitializer : public ScriptPromiseResolverWithContext, public MIDIAccessorClient { 25 public: 26 struct PortDescriptor { 27 String id; 28 String manufacturer; 29 String name; 30 MIDIPort::MIDIPortTypeCode type; 31 String version; 32 PortDescriptorPortDescriptor33 PortDescriptor(const String& id, const String& manufacturer, const String& name, MIDIPort::MIDIPortTypeCode type, const String& version) 34 : id(id) 35 , manufacturer(manufacturer) 36 , name(name) 37 , type(type) 38 , version(version) { } 39 }; 40 start(ScriptState * scriptState,const MIDIOptions & options)41 static ScriptPromise start(ScriptState* scriptState, const MIDIOptions& options) 42 { 43 RefPtr<MIDIAccessInitializer> p = adoptRef(new MIDIAccessInitializer(scriptState, options)); 44 p->keepAliveWhilePending(); 45 p->suspendIfNeeded(); 46 return p->start(); 47 } 48 49 virtual ~MIDIAccessInitializer(); 50 51 // MIDIAccessorClient 52 virtual void didAddInputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE; 53 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE; 54 virtual void didStartSession(bool success, const String& error, const String& message) OVERRIDE; didReceiveMIDIData(unsigned portIndex,const unsigned char * data,size_t length,double timeStamp)55 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* data, size_t length, double timeStamp) OVERRIDE { } 56 57 void setSysexEnabled(bool value); 58 SecurityOrigin* securityOrigin() const; 59 60 private: 61 ScriptPromise start(); 62 63 MIDIAccessInitializer(ScriptState*, const MIDIOptions&); 64 65 ExecutionContext* executionContext() const; 66 67 OwnPtr<MIDIAccessor> m_accessor; 68 MIDIOptions m_options; 69 bool m_sysexEnabled; 70 Vector<PortDescriptor> m_portDescriptors; 71 }; 72 73 } // namespace WebCore 74 75 76 #endif // MIDIAccessInitializer_h 77