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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 private: | 59 private: |
60 MessageValidator(Uint8Array* array) | 60 MessageValidator(Uint8Array* array) |
61 : m_data(array->data()) | 61 : m_data(array->data()) |
62 , m_length(array->length()) | 62 , m_length(array->length()) |
63 , m_offset(0) { } | 63 , m_offset(0) { } |
64 | 64 |
65 bool process(ExceptionState& exceptionState, bool sysExEnabled) | 65 bool process(ExceptionState& exceptionState, bool sysExEnabled) |
66 { | 66 { |
67 while (!isEndOfData() && acceptRealTimeMessages()) { | 67 while (!isEndOfData() && acceptRealTimeMessages()) { |
68 if (!isStatusByte()) { | 68 if (!isStatusByte()) { |
69 exceptionState.throwDOMException(TypeError, "Running status is n
ot allowed " + getPositionString()); | 69 exceptionState.throwTypeError("Running status is not allowed " +
getPositionString()); |
70 return false; | 70 return false; |
71 } | 71 } |
72 if (isEndOfSysEx()) { | 72 if (isEndOfSysEx()) { |
73 exceptionState.throwDOMException(TypeError, "Unexpected end of s
ystem exclusive message " + getPositionString()); | 73 exceptionState.throwTypeError("Unexpected end of system exclusiv
e message " + getPositionString()); |
74 return false; | 74 return false; |
75 } | 75 } |
76 if (isReservedStatusByte()) { | 76 if (isReservedStatusByte()) { |
77 exceptionState.throwDOMException(TypeError, "Reserved status is
not allowed " + getPositionString()); | 77 exceptionState.throwTypeError("Reserved status is not allowed "
+ getPositionString()); |
78 return false; | 78 return false; |
79 } | 79 } |
80 if (isSysEx()) { | 80 if (isSysEx()) { |
81 if (!sysExEnabled) { | 81 if (!sysExEnabled) { |
82 exceptionState.throwDOMException(InvalidAccessError, "System
exclusive message is not allowed " + getPositionString()); | 82 exceptionState.throwDOMException(InvalidAccessError, "System
exclusive message is not allowed " + getPositionString()); |
83 return false; | 83 return false; |
84 } | 84 } |
85 if (!acceptCurrentSysEx()) { | 85 if (!acceptCurrentSysEx()) { |
86 if (isEndOfData()) | 86 if (isEndOfData()) |
87 exceptionState.throwDOMException(TypeError, "System excl
usive message is not ended by end of system exclusive message."); | 87 exceptionState.throwTypeError("System exclusive message
is not ended by end of system exclusive message."); |
88 else | 88 else |
89 exceptionState.throwDOMException(TypeError, "System excl
usive message contains a status byte " + getPositionString()); | 89 exceptionState.throwTypeError("System exclusive message
contains a status byte " + getPositionString()); |
90 return false; | 90 return false; |
91 } | 91 } |
92 } else { | 92 } else { |
93 if (!acceptCurrentMessage()) { | 93 if (!acceptCurrentMessage()) { |
94 if (isEndOfData()) | 94 if (isEndOfData()) |
95 exceptionState.throwDOMException(TypeError, "Message is
incomplete."); | 95 exceptionState.throwTypeError("Message is incomplete."); |
96 else | 96 else |
97 exceptionState.throwDOMException(TypeError, "Unexpected
status byte at index " + getPositionString()); | 97 exceptionState.throwTypeError("Unexpected status byte at
index " + getPositionString()); |
98 return false; | 98 return false; |
99 } | 99 } |
100 } | 100 } |
101 } | 101 } |
102 return true; | 102 return true; |
103 } | 103 } |
104 | 104 |
105 private: | 105 private: |
106 bool isEndOfData() { return m_offset >= m_length; } | 106 bool isEndOfData() { return m_offset >= m_length; } |
107 bool isSysEx() { return m_data[m_offset] == 0xf0; } | 107 bool isSysEx() { return m_data[m_offset] == 0xf0; } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, Exception
State& exceptionState) | 205 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, Exception
State& exceptionState) |
206 { | 206 { |
207 if (timestamp == 0.0) | 207 if (timestamp == 0.0) |
208 timestamp = now(executionContext()); | 208 timestamp = now(executionContext()); |
209 | 209 |
210 RefPtr<Uint8Array> array = Uint8Array::create(unsignedData.size()); | 210 RefPtr<Uint8Array> array = Uint8Array::create(unsignedData.size()); |
211 | 211 |
212 for (size_t i = 0; i < unsignedData.size(); ++i) { | 212 for (size_t i = 0; i < unsignedData.size(); ++i) { |
213 if (unsignedData[i] > 0xff) { | 213 if (unsignedData[i] > 0xff) { |
214 exceptionState.throwDOMException(TypeError, "The value at index " +
String::number(i) + " (" + String::number(unsignedData[i]) + ") is greater than
0xFF."); | 214 exceptionState.throwTypeError("The value at index " + String::number
(i) + " (" + String::number(unsignedData[i]) + ") is greater than 0xFF."); |
215 return; | 215 return; |
216 } | 216 } |
217 unsigned char value = unsignedData[i] & 0xff; | 217 unsigned char value = unsignedData[i] & 0xff; |
218 array->set(i, value); | 218 array->set(i, value); |
219 } | 219 } |
220 | 220 |
221 send(array.get(), timestamp, exceptionState); | 221 send(array.get(), timestamp, exceptionState); |
222 } | 222 } |
223 | 223 |
224 void MIDIOutput::send(Uint8Array* data, ExceptionState& exceptionState) | 224 void MIDIOutput::send(Uint8Array* data, ExceptionState& exceptionState) |
225 { | 225 { |
226 send(data, 0.0, exceptionState); | 226 send(data, 0.0, exceptionState); |
227 } | 227 } |
228 | 228 |
229 void MIDIOutput::send(Vector<unsigned> unsignedData, ExceptionState& exceptionSt
ate) | 229 void MIDIOutput::send(Vector<unsigned> unsignedData, ExceptionState& exceptionSt
ate) |
230 { | 230 { |
231 send(unsignedData, 0.0, exceptionState); | 231 send(unsignedData, 0.0, exceptionState); |
232 } | 232 } |
233 | 233 |
234 void MIDIOutput::trace(Visitor* visitor) | 234 void MIDIOutput::trace(Visitor* visitor) |
235 { | 235 { |
236 MIDIPort::trace(visitor); | 236 MIDIPort::trace(visitor); |
237 } | 237 } |
238 | 238 |
239 } // namespace WebCore | 239 } // namespace WebCore |
OLD | NEW |