| OLD | NEW |
| 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 "media/midi/midi_service.mojom-blink.h" |
| 10 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" |
| 11 #include "modules/webmidi/MIDIAccessor.h" | 12 #include "modules/webmidi/MIDIAccessor.h" |
| 12 #include "modules/webmidi/MIDIAccessorClient.h" | 13 #include "modules/webmidi/MIDIAccessorClient.h" |
| 13 #include "modules/webmidi/MIDIOptions.h" | 14 #include "modules/webmidi/MIDIOptions.h" |
| 14 #include "modules/webmidi/MIDIPort.h" | 15 #include "modules/webmidi/MIDIPort.h" |
| 15 #include "third_party/WebKit/public/platform/modules/permissions/permission.mojo
m-blink.h" | 16 #include "third_party/WebKit/public/platform/modules/permissions/permission.mojo
m-blink.h" |
| 16 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom-blink.h" | 17 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom-blink.h" |
| 17 #include "wtf/Vector.h" | 18 #include "wtf/Vector.h" |
| 18 #include <memory> | 19 #include <memory> |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| 22 class ScriptState; | 23 class ScriptState; |
| 23 | 24 |
| 24 class MODULES_EXPORT MIDIAccessInitializer : public ScriptPromiseResolver, | 25 class MODULES_EXPORT MIDIAccessInitializer : public ScriptPromiseResolver, |
| 25 public MIDIAccessorClient { | 26 public MIDIAccessorClient { |
| 26 public: | 27 public: |
| 27 struct PortDescriptor { | 28 struct PortDescriptor { |
| 28 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 29 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 29 String id; | 30 String id; |
| 30 String manufacturer; | 31 String manufacturer; |
| 31 String name; | 32 String name; |
| 32 MIDIPort::TypeCode type; | 33 MIDIPort::TypeCode type; |
| 33 String version; | 34 String version; |
| 34 MIDIAccessor::MIDIPortState state; | 35 midi::mojom::PortState state; |
| 35 | 36 |
| 36 PortDescriptor(const String& id, | 37 PortDescriptor(const String& id, |
| 37 const String& manufacturer, | 38 const String& manufacturer, |
| 38 const String& name, | 39 const String& name, |
| 39 MIDIPort::TypeCode type, | 40 MIDIPort::TypeCode type, |
| 40 const String& version, | 41 const String& version, |
| 41 MIDIAccessor::MIDIPortState state) | 42 midi::mojom::PortState state) |
| 42 : id(id), | 43 : id(id), |
| 43 manufacturer(manufacturer), | 44 manufacturer(manufacturer), |
| 44 name(name), | 45 name(name), |
| 45 type(type), | 46 type(type), |
| 46 version(version), | 47 version(version), |
| 47 state(state) {} | 48 state(state) {} |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 static ScriptPromise start(ScriptState* scriptState, | 51 static ScriptPromise start(ScriptState* scriptState, |
| 51 const MIDIOptions& options) { | 52 const MIDIOptions& options) { |
| 52 MIDIAccessInitializer* resolver = | 53 MIDIAccessInitializer* resolver = |
| 53 new MIDIAccessInitializer(scriptState, options); | 54 new MIDIAccessInitializer(scriptState, options); |
| 54 resolver->keepAliveWhilePending(); | 55 resolver->keepAliveWhilePending(); |
| 55 resolver->suspendIfNeeded(); | 56 resolver->suspendIfNeeded(); |
| 56 return resolver->start(); | 57 return resolver->start(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 ~MIDIAccessInitializer() override = default; | 60 ~MIDIAccessInitializer() override = default; |
| 60 | 61 |
| 61 // Eager finalization to allow dispose() operation access | 62 // Eager finalization to allow dispose() operation access |
| 62 // other (non eager) heap objects. | 63 // other (non eager) heap objects. |
| 63 EAGERLY_FINALIZE(); | 64 EAGERLY_FINALIZE(); |
| 64 | 65 |
| 65 // MIDIAccessorClient | 66 // MIDIAccessorClient |
| 66 void didAddInputPort(const String& id, | 67 void didAddInputPort(const String& id, |
| 67 const String& manufacturer, | 68 const String& manufacturer, |
| 68 const String& name, | 69 const String& name, |
| 69 const String& version, | 70 const String& version, |
| 70 MIDIAccessor::MIDIPortState) override; | 71 midi::mojom::PortState) override; |
| 71 void didAddOutputPort(const String& id, | 72 void didAddOutputPort(const String& id, |
| 72 const String& manufacturer, | 73 const String& manufacturer, |
| 73 const String& name, | 74 const String& name, |
| 74 const String& version, | 75 const String& version, |
| 75 MIDIAccessor::MIDIPortState) override; | 76 midi::mojom::PortState) override; |
| 76 void didSetInputPortState(unsigned portIndex, | 77 void didSetInputPortState(unsigned portIndex, |
| 77 MIDIAccessor::MIDIPortState) override; | 78 midi::mojom::PortState) override; |
| 78 void didSetOutputPortState(unsigned portIndex, | 79 void didSetOutputPortState(unsigned portIndex, |
| 79 MIDIAccessor::MIDIPortState) override; | 80 midi::mojom::PortState) override; |
| 80 void didStartSession(midi::mojom::Result) override; | 81 void didStartSession(midi::mojom::Result) override; |
| 81 void didReceiveMIDIData(unsigned portIndex, | 82 void didReceiveMIDIData(unsigned portIndex, |
| 82 const unsigned char* data, | 83 const unsigned char* data, |
| 83 size_t length, | 84 size_t length, |
| 84 double timeStamp) override {} | 85 double timeStamp) override {} |
| 85 | 86 |
| 86 private: | 87 private: |
| 87 MIDIAccessInitializer(ScriptState*, const MIDIOptions&); | 88 MIDIAccessInitializer(ScriptState*, const MIDIOptions&); |
| 88 | 89 |
| 89 ExecutionContext* getExecutionContext() const; | 90 ExecutionContext* getExecutionContext() const; |
| 90 ScriptPromise start(); | 91 ScriptPromise start(); |
| 91 | 92 |
| 92 void contextDestroyed() override; | 93 void contextDestroyed() override; |
| 93 | 94 |
| 94 void onPermissionsUpdated(mojom::blink::PermissionStatus); | 95 void onPermissionsUpdated(mojom::blink::PermissionStatus); |
| 95 void onPermissionUpdated(mojom::blink::PermissionStatus); | 96 void onPermissionUpdated(mojom::blink::PermissionStatus); |
| 96 | 97 |
| 97 std::unique_ptr<MIDIAccessor> m_accessor; | 98 std::unique_ptr<MIDIAccessor> m_accessor; |
| 98 Vector<PortDescriptor> m_portDescriptors; | 99 Vector<PortDescriptor> m_portDescriptors; |
| 99 MIDIOptions m_options; | 100 MIDIOptions m_options; |
| 100 | 101 |
| 101 mojom::blink::PermissionServicePtr m_permissionService; | 102 mojom::blink::PermissionServicePtr m_permissionService; |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 } // namespace blink | 105 } // namespace blink |
| 105 | 106 |
| 106 #endif // MIDIAccessInitializer_h | 107 #endif // MIDIAccessInitializer_h |
| OLD | NEW |