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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 | 53 |
| 54 MIDIAccess::~MIDIAccess() | 54 MIDIAccess::~MIDIAccess() |
| 55 { | 55 { |
| 56 stop(); | 56 stop(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi se) | 59 MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi se) |
| 60 : ActiveDOMObject(context) | 60 : ActiveDOMObject(context) |
| 61 , m_promise(promise) | 61 , m_promise(promise) |
| 62 , m_hasAccess(false) | 62 , m_hasAccess(false) |
| 63 , m_midiOptions(*promise->options()) | |
| 63 { | 64 { |
| 64 ScriptWrappable::init(this); | 65 ScriptWrappable::init(this); |
| 65 m_accessor = MIDIAccessor::create(this); | 66 m_accessor = MIDIAccessor::create(this); |
| 66 m_accessor->requestAccess(promise->options()->sysex); | 67 m_accessor->requestAccess(m_midiOptions.sysex); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) | 70 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) |
| 70 { | 71 { |
| 71 ASSERT(isMainThread()); | 72 ASSERT(isMainThread()); |
| 72 | 73 |
| 73 m_inputs.append(MIDIInput::create(scriptExecutionContext(), id, manufacturer , name, version)); | 74 m_inputs.append(MIDIInput::create(scriptExecutionContext(), id, manufacturer , name, version)); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) | 77 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) |
| 77 { | 78 { |
| 78 ASSERT(isMainThread()); | 79 ASSERT(isMainThread()); |
| 79 | 80 |
| 80 m_outputs.append(MIDIOutput::create(scriptExecutionContext(), id, manufactur er, name, version)); | 81 unsigned portIndex = m_outputs.size(); |
| 82 m_outputs.append(MIDIOutput::create(this, portIndex, scriptExecutionContext( ), id, manufacturer, name, version)); | |
| 81 } | 83 } |
| 82 | 84 |
| 83 void MIDIAccess::didAllowAccess() | 85 void MIDIAccess::didAllowAccess() |
| 84 { | 86 { |
| 85 ASSERT(isMainThread()); | 87 ASSERT(isMainThread()); |
| 86 | 88 |
| 87 m_hasAccess = true; | 89 m_hasAccess = true; |
| 88 m_promise->fulfill(); | 90 m_promise->fulfill(); |
| 89 } | 91 } |
| 90 | 92 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 107 // This is how timestamps are defined in the Web MIDI spec. | 109 // This is how timestamps are defined in the Web MIDI spec. |
| 108 Document* document = toDocument(scriptExecutionContext()); | 110 Document* document = toDocument(scriptExecutionContext()); |
| 109 ASSERT(document); | 111 ASSERT(document); |
| 110 | 112 |
| 111 double timeStampInMilliseconds = 1000 * document->loader()->timing()->mo notonicTimeToZeroBasedDocumentTime(timeStamp); | 113 double timeStampInMilliseconds = 1000 * document->loader()->timing()->mo notonicTimeToZeroBasedDocumentTime(timeStamp); |
| 112 | 114 |
| 113 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeSta mpInMilliseconds); | 115 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeSta mpInMilliseconds); |
| 114 } | 116 } |
| 115 } | 117 } |
| 116 | 118 |
| 119 void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, siz e_t length, double timeStampInMilliseconds) | |
| 120 { | |
| 121 if (m_hasAccess && portIndex < m_outputs.size() && data && length > 1) { | |
| 122 // Filter out System Exclusive messages if we're not allowed. | |
| 123 // FIXME: implement more extensive filtering. | |
| 124 if (data[0] >= 0xf0 && !m_midiOptions.sysex) | |
|
Takashi Toyoshima
2013/07/09 10:19:11
It should raise SecurityError if it detects forbid
Chris Rogers
2013/07/17 21:28:12
Done. Now raising SecurityError
Also moved this
| |
| 125 return; | |
| 126 | |
| 127 // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to the same time coordinate system as performance.now() | |
| 128 // into a time in seconds which is based on the time coordinate system o f monotonicallyIncreasingTime(). | |
| 129 double timeStamp; | |
| 130 | |
| 131 if (!timeStampInMilliseconds) { | |
| 132 // We treat a value of 0 (which is the default value) as special, me aning "now". | |
| 133 // We need to translate it exactly to 0 seconds. | |
| 134 timeStamp = 0; | |
| 135 } else { | |
| 136 Document* document = toDocument(scriptExecutionContext()); | |
| 137 ASSERT(document); | |
| 138 double documentStartTime = document->loader()->timing()->referenceMo notonicTime(); | |
| 139 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; | |
| 140 } | |
| 141 | |
| 142 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); | |
| 143 } | |
| 144 } | |
| 145 | |
| 117 void MIDIAccess::stop() | 146 void MIDIAccess::stop() |
| 118 { | 147 { |
| 119 m_hasAccess = false; | 148 m_hasAccess = false; |
| 149 m_accessor.clear(); | |
| 120 } | 150 } |
| 121 | 151 |
| 122 } // namespace WebCore | 152 } // namespace WebCore |
| OLD | NEW |