Chromium Code Reviews| 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 "core/dom/DOMError.h" | |
| 34 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
| 36 #include "modules/webmidi/MIDIAccessPromise.h" | |
| 35 #include "modules/webmidi/MIDIConnectionEvent.h" | 37 #include "modules/webmidi/MIDIConnectionEvent.h" |
| 36 #include "modules/webmidi/MIDIInput.h" | 38 #include "modules/webmidi/MIDIInput.h" |
| 37 #include "modules/webmidi/MIDIOutput.h" | 39 #include "modules/webmidi/MIDIOutput.h" |
| 38 #include "modules/webmidi/MIDIPort.h" | 40 #include "modules/webmidi/MIDIPort.h" |
| 39 | 41 |
| 40 namespace WebCore { | 42 namespace WebCore { |
| 41 | 43 |
| 42 PassRefPtr<MIDIAccess> MIDIAccess::create(ScriptExecutionContext* context, MIDIA ccessPromise* promise) | 44 PassRefPtr<MIDIAccess> MIDIAccess::create(ScriptExecutionContext* context, MIDIA ccessPromise* promise) |
| 43 { | 45 { |
| 44 RefPtr<MIDIAccess> midiAccess(adoptRef(new MIDIAccess(context, promise))); | 46 RefPtr<MIDIAccess> midiAccess(adoptRef(new MIDIAccess(context, promise))); |
| 45 midiAccess->suspendIfNeeded(); | 47 midiAccess->suspendIfNeeded(); |
| 46 return midiAccess.release(); | 48 return midiAccess.release(); |
| 47 } | 49 } |
| 48 | 50 |
| 49 MIDIAccess::~MIDIAccess() | 51 MIDIAccess::~MIDIAccess() |
| 50 { | 52 { |
| 51 stop(); | 53 stop(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi se) | 56 MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi se) |
| 55 : ActiveDOMObject(context) | 57 : ActiveDOMObject(context) |
| 56 , m_promise(promise) | 58 , m_promise(promise) |
| 59 , m_hasAccess(false) | |
| 57 { | 60 { |
| 58 ScriptWrappable::init(this); | 61 ScriptWrappable::init(this); |
| 62 m_accessor = MIDIAccessor::create(this); | |
| 63 m_accessor->requestAccess(promise->options()->sysexEnabled); | |
| 64 } | |
| 65 | |
| 66 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) | |
| 67 { | |
| 68 ASSERT(isMainThread()); | |
| 69 | |
| 70 m_inputs.append(MIDIInput::create(scriptExecutionContext(), id, manufacturer , name, version)); | |
| 71 } | |
| 72 | |
| 73 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) | |
| 74 { | |
| 75 ASSERT(isMainThread()); | |
| 76 | |
| 77 m_outputs.append(MIDIOutput::create(scriptExecutionContext(), id, manufactur er, name, version)); | |
| 78 } | |
| 79 | |
| 80 void MIDIAccess::didAllowAccess() | |
| 81 { | |
| 82 ASSERT(isMainThread()); | |
| 83 | |
| 84 m_hasAccess = true; | |
| 85 m_promise->fulfill(); | |
| 86 } | |
| 87 | |
| 88 void MIDIAccess::didBlockAccess() | |
| 89 { | |
| 90 ASSERT(isMainThread()); | |
| 91 | |
| 92 m_hasAccess = false; | |
| 93 RefPtr<DOMError> error = DOMError::create("MIDI access blocked"); | |
|
Takashi Toyoshima
2013/06/25 07:48:58
Should be "SecurityError".
http://webaudio.github
Chris Rogers
2013/06/26 01:47:56
Done.
| |
| 94 m_promise->reject(error); | |
| 95 } | |
| 96 | |
| 97 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) | |
| 98 { | |
| 99 ASSERT(isMainThread()); | |
| 100 | |
| 101 if (m_hasAccess && portIndex < m_inputs.size()) | |
| 102 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeSta mp); | |
| 59 } | 103 } |
| 60 | 104 |
| 61 } // namespace WebCore | 105 } // namespace WebCore |
| OLD | NEW |