Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: Source/modules/webmidi/MIDIAccessInitializer.h

Issue 649683006: Web MIDI: add blink APIs to notify device connection events (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address comments at #7 Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MIDIAccessInitializer_h 5 #ifndef MIDIAccessInitializer_h
6 #define MIDIAccessInitializer_h 6 #define MIDIAccessInitializer_h
7 7
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "modules/webmidi/MIDIAccessor.h" 10 #include "modules/webmidi/MIDIAccessor.h"
11 #include "modules/webmidi/MIDIAccessorClient.h" 11 #include "modules/webmidi/MIDIAccessorClient.h"
12 #include "modules/webmidi/MIDIPort.h" 12 #include "modules/webmidi/MIDIPort.h"
13 #include "wtf/OwnPtr.h" 13 #include "wtf/OwnPtr.h"
14 #include "wtf/Vector.h" 14 #include "wtf/Vector.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 class MIDIOptions; 18 class MIDIOptions;
19 class ScriptState; 19 class ScriptState;
20 20
21 class MIDIAccessInitializer : public ScriptPromiseResolver, public MIDIAccessorC lient { 21 class MIDIAccessInitializer : public ScriptPromiseResolver, public MIDIAccessorC lient {
22 public: 22 public:
23 struct PortDescriptor { 23 struct PortDescriptor {
24 String id; 24 String id;
25 String manufacturer; 25 String manufacturer;
26 String name; 26 String name;
27 MIDIPort::MIDIPortTypeCode type; 27 MIDIPort::MIDIPortTypeCode type;
28 String version; 28 String version;
29 bool active;
tkent 2014/10/20 05:54:07 should be |isActive|
Takashi Toyoshima 2014/10/20 06:24:18 Done.
29 30
30 PortDescriptor(const String& id, const String& manufacturer, const Strin g& name, MIDIPort::MIDIPortTypeCode type, const String& version) 31 PortDescriptor(const String& id, const String& manufacturer, const Strin g& name, MIDIPort::MIDIPortTypeCode type, const String& version, bool active)
31 : id(id) 32 : id(id)
32 , manufacturer(manufacturer) 33 , manufacturer(manufacturer)
33 , name(name) 34 , name(name)
34 , type(type) 35 , type(type)
35 , version(version) { } 36 , version(version)
37 , active(active) { }
36 }; 38 };
37 39
38 static ScriptPromise start(ScriptState* scriptState, const MIDIOptions& opti ons) 40 static ScriptPromise start(ScriptState* scriptState, const MIDIOptions& opti ons)
39 { 41 {
40 RefPtr<MIDIAccessInitializer> p = adoptRef(new MIDIAccessInitializer(scr iptState, options)); 42 RefPtr<MIDIAccessInitializer> p = adoptRef(new MIDIAccessInitializer(scr iptState, options));
41 p->keepAliveWhilePending(); 43 p->keepAliveWhilePending();
42 p->suspendIfNeeded(); 44 p->suspendIfNeeded();
43 return p->start(); 45 return p->start();
44 } 46 }
45 47
46 virtual ~MIDIAccessInitializer(); 48 virtual ~MIDIAccessInitializer();
47 49
48 // MIDIAccessorClient 50 // MIDIAccessorClient
49 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) override; 51 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version, bool active) override;
50 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) override; 52 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version, bool active) override;
53 virtual void didSetInputPortState(unsigned portIndex, bool active) override;
54 virtual void didSetOutputPortState(unsigned portIndex, bool active) override ;
51 virtual void didStartSession(bool success, const String& error, const String & message) override; 55 virtual void didStartSession(bool success, const String& error, const String & message) override;
52 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) override { } 56 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) override { }
53 57
54 void resolveSysexPermission(bool allowed); 58 void resolveSysexPermission(bool allowed);
55 SecurityOrigin* securityOrigin() const; 59 SecurityOrigin* securityOrigin() const;
56 60
57 private: 61 private:
58 ScriptPromise start(); 62 ScriptPromise start();
59 63
60 MIDIAccessInitializer(ScriptState*, const MIDIOptions&); 64 MIDIAccessInitializer(ScriptState*, const MIDIOptions&);
61 65
62 ExecutionContext* executionContext() const; 66 ExecutionContext* executionContext() const;
63 67
64 OwnPtr<MIDIAccessor> m_accessor; 68 OwnPtr<MIDIAccessor> m_accessor;
65 bool m_requestSysex; 69 bool m_requestSysex;
66 Vector<PortDescriptor> m_portDescriptors; 70 Vector<PortDescriptor> m_portDescriptors;
67 }; 71 };
68 72
69 } // namespace blink 73 } // namespace blink
70 74
71 75
72 #endif // MIDIAccessInitializer_h 76 #endif // MIDIAccessInitializer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698