| 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 15 matching lines...) Expand all Loading... |
| 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 "core/dom/DOMError.h" | 34 #include "core/dom/DOMError.h" |
| 35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
| 36 #include "core/dom/ScriptExecutionContext.h" |
| 36 #include "modules/webmidi/MIDIAccessPromise.h" | 37 #include "modules/webmidi/MIDIAccessPromise.h" |
| 37 #include "modules/webmidi/MIDIConnectionEvent.h" | 38 #include "modules/webmidi/MIDIConnectionEvent.h" |
| 38 #include "modules/webmidi/MIDIInput.h" | 39 #include "modules/webmidi/MIDIInput.h" |
| 39 #include "modules/webmidi/MIDIOutput.h" | 40 #include "modules/webmidi/MIDIOutput.h" |
| 40 #include "modules/webmidi/MIDIPort.h" | 41 #include "modules/webmidi/MIDIPort.h" |
| 42 #include "weborigin/SecurityOrigin.h" |
| 41 | 43 |
| 42 namespace WebCore { | 44 namespace WebCore { |
| 43 | 45 |
| 44 PassRefPtr<MIDIAccess> MIDIAccess::create(ScriptExecutionContext* context, MIDIA
ccessPromise* promise) | 46 PassRefPtr<MIDIAccess> MIDIAccess::create(ScriptExecutionContext* context, MIDIA
ccessPromise* promise) |
| 45 { | 47 { |
| 46 RefPtr<MIDIAccess> midiAccess(adoptRef(new MIDIAccess(context, promise))); | 48 RefPtr<MIDIAccess> midiAccess(adoptRef(new MIDIAccess(context, promise))); |
| 47 midiAccess->suspendIfNeeded(); | 49 midiAccess->suspendIfNeeded(); |
| 48 return midiAccess.release(); | 50 return midiAccess.release(); |
| 49 } | 51 } |
| 50 | 52 |
| 51 MIDIAccess::~MIDIAccess() | 53 MIDIAccess::~MIDIAccess() |
| 52 { | 54 { |
| 53 stop(); | 55 stop(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi
se) | 58 MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi
se) |
| 57 : ActiveDOMObject(context) | 59 : ActiveDOMObject(context) |
| 58 , m_promise(promise) | 60 , m_promise(promise) |
| 59 , m_hasAccess(false) | 61 , m_hasAccess(false) |
| 60 { | 62 { |
| 61 ScriptWrappable::init(this); | 63 ScriptWrappable::init(this); |
| 62 m_accessor = MIDIAccessor::create(this); | 64 m_accessor = MIDIAccessor::create(this); |
| 63 m_accessor->requestAccess(promise->options()->sysexEnabled); | 65 m_accessor->requestAccess(context->securityOrigin()->toString(), promise->op
tions()->sysexEnabled); |
| 64 } | 66 } |
| 65 | 67 |
| 66 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) |
| 67 { | 69 { |
| 68 ASSERT(isMainThread()); | 70 ASSERT(isMainThread()); |
| 69 | 71 |
| 70 m_inputs.append(MIDIInput::create(scriptExecutionContext(), id, manufacturer
, name, version)); | 72 m_inputs.append(MIDIInput::create(scriptExecutionContext(), id, manufacturer
, name, version)); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) | 75 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 101 if (m_hasAccess && portIndex < m_inputs.size()) | 103 if (m_hasAccess && portIndex < m_inputs.size()) |
| 102 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeSta
mp); | 104 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeSta
mp); |
| 103 } | 105 } |
| 104 | 106 |
| 105 void MIDIAccess::stop() | 107 void MIDIAccess::stop() |
| 106 { | 108 { |
| 107 m_hasAccess = false; | 109 m_hasAccess = false; |
| 108 } | 110 } |
| 109 | 111 |
| 110 } // namespace WebCore | 112 } // namespace WebCore |
| OLD | NEW |