Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1335)

Side by Side Diff: Source/modules/webmidi/MIDIOutput.cpp

Issue 23609033: Web MIDI: MIDIPort doesn't have to be ActiveDOMObject (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: revert idl changes Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/webmidi/MIDIOutput.h ('k') | Source/modules/webmidi/MIDIOutput.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 String getPositionString() { return "at index " + String::number(m_offset) + " (" + String::number(m_data[m_offset]) + ")."; } 157 String getPositionString() { return "at index " + String::number(m_offset) + " (" + String::number(m_data[m_offset]) + ")."; }
158 158
159 const unsigned char* m_data; 159 const unsigned char* m_data;
160 const size_t m_length; 160 const size_t m_length;
161 size_t m_offset; 161 size_t m_offset;
162 }; 162 };
163 163
164 } // namespace 164 } // namespace
165 165
166 PassRefPtr<MIDIOutput> MIDIOutput::create(MIDIAccess* access, unsigned portIndex , ExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version) 166 PassRefPtr<MIDIOutput> MIDIOutput::create(MIDIAccess* access, unsigned portIndex , const String& id, const String& manufacturer, const String& name, const String & version)
167 { 167 {
168 ASSERT(access); 168 ASSERT(access);
169 RefPtr<MIDIOutput> output = adoptRef(new MIDIOutput(access, portIndex, conte xt, id, manufacturer, name, version)); 169 RefPtr<MIDIOutput> output = adoptRef(new MIDIOutput(access, portIndex, id, m anufacturer, name, version));
170 output->suspendIfNeeded();
171 return output.release(); 170 return output.release();
172 } 171 }
173 172
174 MIDIOutput::MIDIOutput(MIDIAccess* access, unsigned portIndex, ExecutionContext* context, const String& id, const String& manufacturer, const String& name, cons t String& version) 173 MIDIOutput::MIDIOutput(MIDIAccess* access, unsigned portIndex, const String& id, const String& manufacturer, const String& name, const String& version)
175 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeOutput, version) 174 : MIDIPort(access, id, manufacturer, name, MIDIPortTypeOutput, version)
176 , m_access(access)
177 , m_portIndex(portIndex) 175 , m_portIndex(portIndex)
178 { 176 {
179 ScriptWrappable::init(this); 177 ScriptWrappable::init(this);
180 } 178 }
181 179
182 MIDIOutput::~MIDIOutput() 180 MIDIOutput::~MIDIOutput()
183 { 181 {
184 } 182 }
185 183
186 void MIDIOutput::send(Uint8Array* array, double timestamp, ExceptionState& excep tionState) 184 void MIDIOutput::send(Uint8Array* array, double timestamp, ExceptionState& excep tionState)
187 { 185 {
188 if (!array) 186 if (!array)
189 return; 187 return;
190 188
191 if (MessageValidator::validate(array, exceptionState, m_access->sysExEnabled ())) 189 if (MessageValidator::validate(array, exceptionState, midiAccess()->sysExEna bled()))
192 m_access->sendMIDIData(m_portIndex, array->data(), array->length(), time stamp); 190 midiAccess()->sendMIDIData(m_portIndex, array->data(), array->length(), timestamp);
193 } 191 }
194 192
195 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, Exception State& exceptionState) 193 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, Exception State& exceptionState)
196 { 194 {
197 RefPtr<Uint8Array> array = Uint8Array::create(unsignedData.size()); 195 RefPtr<Uint8Array> array = Uint8Array::create(unsignedData.size());
198 196
199 for (size_t i = 0; i < unsignedData.size(); ++i) { 197 for (size_t i = 0; i < unsignedData.size(); ++i) {
200 if (unsignedData[i] > 0xff) { 198 if (unsignedData[i] > 0xff) {
201 exceptionState.throwDOMException(TypeError, "The value at index " + String::number(i) + " (" + String::number(unsignedData[i]) + ") is greater than 0xFF."); 199 exceptionState.throwDOMException(TypeError, "The value at index " + String::number(i) + " (" + String::number(unsignedData[i]) + ") is greater than 0xFF.");
202 return; 200 return;
203 } 201 }
204 unsigned char value = unsignedData[i] & 0xff; 202 unsigned char value = unsignedData[i] & 0xff;
205 array->set(i, value); 203 array->set(i, value);
206 } 204 }
207 205
208 send(array.get(), timestamp, exceptionState); 206 send(array.get(), timestamp, exceptionState);
209 } 207 }
210 208
211 void MIDIOutput::send(Uint8Array* data, ExceptionState& exceptionState) 209 void MIDIOutput::send(Uint8Array* data, ExceptionState& exceptionState)
212 { 210 {
213 send(data, 0, exceptionState); 211 send(data, 0, exceptionState);
214 } 212 }
215 213
216 void MIDIOutput::send(Vector<unsigned> unsignedData, ExceptionState& exceptionSt ate) 214 void MIDIOutput::send(Vector<unsigned> unsignedData, ExceptionState& exceptionSt ate)
217 { 215 {
218 send(unsignedData, 0, exceptionState); 216 send(unsignedData, 0, exceptionState);
219 } 217 }
220 218
221 } // namespace WebCore 219 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/webmidi/MIDIOutput.h ('k') | Source/modules/webmidi/MIDIOutput.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698