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