| 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 | 43 |
| 49 namespace WebCore { | 44 namespace WebCore { |
| 50 | 45 |
| 51 ScriptPromise MIDIAccess::request(const MIDIOptions& options, ScriptState* scrip
tState) | 46 MIDIAccess::MIDIAccess(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled, con
st Vector<MIDIAccessInitializer::PortDescriptor>& ports, ExecutionContext* execu
tionContext) |
| 47 : ActiveDOMObject(executionContext) |
| 48 , m_accessor(accessor) |
| 49 , m_sysexEnabled(sysexEnabled) |
| 52 { | 50 { |
| 53 RefPtrWillBeRawPtr<MIDIAccess> midiAccess(adoptRefWillBeRefCountedGarbageCol
lected(new MIDIAccess(options, scriptState->executionContext()))); | 51 ScriptWrappable::init(this); |
| 54 midiAccess->suspendIfNeeded(); | 52 m_accessor->setClient(this); |
| 55 // Create a wrapper to expose this object to the V8 GC so that | 53 for (size_t i = 0; i < ports.size(); ++i) { |
| 56 // hasPendingActivity takes effect. | 54 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; |
| 57 toV8NoInline(midiAccess.get(), scriptState->context()->Global(), scriptState
->isolate()); | 55 if (port.type == MIDIPort::MIDIPortTypeInput) { |
| 58 // Now this object is retained because hasPending returns true. | 56 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer,
port.name, port.version)); |
| 59 return midiAccess->m_initializer->initialize(scriptState); | 57 } else { |
| 58 m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id,
port.manufacturer, port.name, port.version)); |
| 59 } |
| 60 } |
| 60 } | 61 } |
| 61 | 62 |
| 62 MIDIAccess::~MIDIAccess() | 63 MIDIAccess::~MIDIAccess() |
| 63 { | 64 { |
| 64 } | 65 } |
| 65 | 66 |
| 66 MIDIAccess::MIDIAccess(const MIDIOptions& options, ExecutionContext* context) | |
| 67 : ActiveDOMObject(context) | |
| 68 , m_initializer(MIDIAccessInitializer::create(options, this)) | |
| 69 { | |
| 70 ScriptWrappable::init(this); | |
| 71 } | |
| 72 | |
| 73 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) | 67 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) |
| 74 { | 68 { |
| 75 ASSERT(isMainThread()); | 69 ASSERT(isMainThread()); |
| 76 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version)); | 70 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version)); |
| 77 } | 71 } |
| 78 | 72 |
| 79 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) | 73 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) |
| 80 { | 74 { |
| 81 ASSERT(isMainThread()); | 75 ASSERT(isMainThread()); |
| 82 unsigned portIndex = m_outputs.size(); | 76 unsigned portIndex = m_outputs.size(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 double documentStartTime = document->loader()->timing()->referenceMonoto
nicTime(); | 112 double documentStartTime = document->loader()->timing()->referenceMonoto
nicTime(); |
| 119 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; | 113 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; |
| 120 } | 114 } |
| 121 | 115 |
| 122 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); | 116 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); |
| 123 } | 117 } |
| 124 | 118 |
| 125 void MIDIAccess::stop() | 119 void MIDIAccess::stop() |
| 126 { | 120 { |
| 127 m_accessor.clear(); | 121 m_accessor.clear(); |
| 128 m_initializer->cancel(); | |
| 129 } | |
| 130 | |
| 131 bool MIDIAccess::hasPendingActivity() const | |
| 132 { | |
| 133 return m_initializer->hasPendingActivity(); | |
| 134 } | |
| 135 | |
| 136 void MIDIAccess::initialize(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled
) | |
| 137 { | |
| 138 ASSERT(accessor); | |
| 139 m_accessor = accessor; | |
| 140 m_accessor->setClient(this); | |
| 141 m_sysexEnabled = sysexEnabled; | |
| 142 } | 122 } |
| 143 | 123 |
| 144 void MIDIAccess::trace(Visitor* visitor) | 124 void MIDIAccess::trace(Visitor* visitor) |
| 145 { | 125 { |
| 146 visitor->trace(m_inputs); | 126 visitor->trace(m_inputs); |
| 147 visitor->trace(m_outputs); | 127 visitor->trace(m_outputs); |
| 148 EventTargetWithInlineData::trace(visitor); | 128 EventTargetWithInlineData::trace(visitor); |
| 149 } | 129 } |
| 150 | 130 |
| 151 } // namespace WebCore | 131 } // namespace WebCore |
| OLD | NEW |