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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
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 #include "config.h" | 31 #include "config.h" |
32 #include "modules/webmidi/MIDIAccess.h" | 32 #include "modules/webmidi/MIDIAccess.h" |
33 | 33 |
34 #include "bindings/v8/ScriptFunction.h" | |
35 #include "bindings/v8/ScriptPromise.h" | |
36 #include "bindings/v8/ScriptPromiseResolverWithContext.h" | |
37 #include "bindings/v8/V8Binding.h" | |
38 #include "core/dom/DOMError.h" | |
39 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
40 #include "core/loader/DocumentLoadTiming.h" | 35 #include "core/loader/DocumentLoadTiming.h" |
41 #include "core/loader/DocumentLoader.h" | 36 #include "core/loader/DocumentLoader.h" |
42 #include "modules/webmidi/MIDIAccessInitializer.h" | 37 #include "modules/webmidi/MIDIAccessInitializer.h" |
43 #include "modules/webmidi/MIDIConnectionEvent.h" | 38 #include "modules/webmidi/MIDIConnectionEvent.h" |
44 #include "modules/webmidi/MIDIController.h" | 39 #include "modules/webmidi/MIDIController.h" |
45 #include "modules/webmidi/MIDIOptions.h" | 40 #include "modules/webmidi/MIDIOptions.h" |
46 #include "modules/webmidi/MIDIPort.h" | 41 #include "modules/webmidi/MIDIPort.h" |
47 #include "platform/AsyncMethodRunner.h" | 42 #include "platform/AsyncMethodRunner.h" |
48 #include <v8.h> | 43 #include <v8.h> |
49 | 44 |
50 namespace WebCore { | 45 namespace WebCore { |
51 | 46 |
52 ScriptPromise MIDIAccess::request(const MIDIOptions& options, ScriptState* scrip
tState) | 47 MIDIAccess::MIDIAccess(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled, con
st Vector<MIDIAccessInitializer::PortDescriptor>& ports, ExecutionContext* execu
tionContext) |
| 48 : ActiveDOMObject(executionContext) |
| 49 , m_accessor(accessor) |
| 50 , m_sysexEnabled(sysexEnabled) |
53 { | 51 { |
54 RefPtrWillBeRawPtr<MIDIAccess> midiAccess(adoptRefWillBeRefCountedGarbageCol
lected(new MIDIAccess(options, scriptState->executionContext()))); | 52 ScriptWrappable::init(this); |
55 midiAccess->suspendIfNeeded(); | 53 m_accessor->setClient(this); |
56 // Create a wrapper to expose this object to the V8 GC so that | 54 for (size_t i = 0; i < ports.size(); ++i) { |
57 // hasPendingActivity takes effect. | 55 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; |
58 toV8NoInline(midiAccess.get(), scriptState->context()->Global(), scriptState
->isolate()); | 56 if (port.type == MIDIPort::MIDIPortTypeInput) { |
59 // Now this object is retained because hasPending returns true. | 57 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer,
port.name, port.version)); |
60 return midiAccess->m_initializer->initialize(scriptState); | 58 } else { |
| 59 m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id,
port.manufacturer, port.name, port.version)); |
| 60 } |
| 61 } |
61 } | 62 } |
62 | 63 |
63 MIDIAccess::~MIDIAccess() | 64 MIDIAccess::~MIDIAccess() |
64 { | 65 { |
65 } | 66 } |
66 | 67 |
67 MIDIAccess::MIDIAccess(const MIDIOptions& options, ExecutionContext* context) | |
68 : ActiveDOMObject(context) | |
69 , m_initializer(MIDIAccessInitializer::create(options, this)) | |
70 { | |
71 ScriptWrappable::init(this); | |
72 } | |
73 | |
74 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) | 68 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) |
75 { | 69 { |
76 ASSERT(isMainThread()); | 70 ASSERT(isMainThread()); |
77 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version)); | 71 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version)); |
78 } | 72 } |
79 | 73 |
80 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) | 74 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) |
81 { | 75 { |
82 ASSERT(isMainThread()); | 76 ASSERT(isMainThread()); |
83 unsigned portIndex = m_outputs.size(); | 77 unsigned portIndex = m_outputs.size(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 double documentStartTime = document->loader()->timing()->referenceMonoto
nicTime(); | 113 double documentStartTime = document->loader()->timing()->referenceMonoto
nicTime(); |
120 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; | 114 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; |
121 } | 115 } |
122 | 116 |
123 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); | 117 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); |
124 } | 118 } |
125 | 119 |
126 void MIDIAccess::stop() | 120 void MIDIAccess::stop() |
127 { | 121 { |
128 m_accessor.clear(); | 122 m_accessor.clear(); |
129 m_initializer->cancel(); | |
130 } | |
131 | |
132 bool MIDIAccess::hasPendingActivity() const | |
133 { | |
134 return m_initializer->hasPendingActivity(); | |
135 } | |
136 | |
137 void MIDIAccess::initialize(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled
) | |
138 { | |
139 ASSERT(accessor); | |
140 m_accessor = accessor; | |
141 m_accessor->setClient(this); | |
142 m_sysexEnabled = sysexEnabled; | |
143 } | 123 } |
144 | 124 |
145 void MIDIAccess::trace(Visitor* visitor) | 125 void MIDIAccess::trace(Visitor* visitor) |
146 { | 126 { |
147 visitor->trace(m_inputs); | 127 visitor->trace(m_inputs); |
148 visitor->trace(m_outputs); | 128 visitor->trace(m_outputs); |
149 EventTargetWithInlineData::trace(visitor); | 129 EventTargetWithInlineData::trace(visitor); |
150 } | 130 } |
151 | 131 |
152 } // namespace WebCore | 132 } // namespace WebCore |
OLD | NEW |