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

Unified Diff: Source/modules/webmidi/MIDIOutput.cpp

Issue 18858006: Implement MIDIOutput.send() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: forward declare MIDIAccess Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/webmidi/MIDIOutput.h ('k') | Source/modules/webmidi/MIDIOutput.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webmidi/MIDIOutput.cpp
diff --git a/Source/modules/webmidi/MIDIOutput.cpp b/Source/modules/webmidi/MIDIOutput.cpp
index e9066f0561fc600d24a8c1dd0fe59623522c6950..5e05cccdf430848c4df111c80c67a3f66f91b5a6 100644
--- a/Source/modules/webmidi/MIDIOutput.cpp
+++ b/Source/modules/webmidi/MIDIOutput.cpp
@@ -31,30 +31,66 @@
#include "config.h"
#include "modules/webmidi/MIDIOutput.h"
+#include "core/dom/ExceptionCode.h"
+#include "modules/webmidi/MIDIAccess.h"
+
namespace WebCore {
-PassRefPtr<MIDIOutput> MIDIOutput::create(ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version)
+PassRefPtr<MIDIOutput> MIDIOutput::create(MIDIAccess* access, unsigned portIndex, ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version)
{
- return adoptRef(new MIDIOutput(context, id, manufacturer, name, version));
+ return adoptRef(new MIDIOutput(access, portIndex, context, id, manufacturer, name, version));
}
-MIDIOutput::MIDIOutput(ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version)
+MIDIOutput::MIDIOutput(MIDIAccess* access, unsigned portIndex, ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version)
: MIDIPort(context, id, manufacturer, name, MIDIPortTypeOutput, version)
+ , m_access(access)
+ , m_portIndex(portIndex)
{
ScriptWrappable::init(this);
}
-void MIDIOutput::send(Uint8Array* data, double timestamp)
+void MIDIOutput::send(Uint8Array* array, double timestamp, ExceptionCode& ec)
+{
+ if (!array)
+ return;
+
+ const unsigned char* data = array->data();
+ size_t length = array->length();
+
+ // Filter out System Exclusive messages if we're not allowed.
+ // FIXME: implement more extensive filtering.
+ if (length > 0 && data[0] >= 0xf0 && !m_access->sysExEnabled()) {
+ ec = SecurityError;
+ return;
+ }
+
+ m_access->sendMIDIData(m_portIndex, data, length, timestamp);
+}
+
+void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, ExceptionCode& ec)
+{
+ RefPtr<Uint8Array> array = Uint8Array::create(unsignedData.size());
+
+ for (size_t i = 0; i < unsignedData.size(); ++i) {
+ if (unsignedData[i] > 0xff) {
+ ec = InvalidStateError;
+ return;
+ }
+ unsigned char value = unsignedData[i] & 0xff;
+ array->set(i, value);
+ }
+
+ send(array.get(), timestamp, ec);
+}
+
+void MIDIOutput::send(Uint8Array* data, ExceptionCode& ec)
{
- // FIXME: Implement MIDI protocol validation here. System exclusive
- // messages must be checked at the same time.
- // Actual sending operation will be implemented in core/platform/midi.
+ send(data, 0, ec);
}
-void MIDIOutput::send(Vector<unsigned>, double timestamp)
+void MIDIOutput::send(Vector<unsigned> unsignedData, ExceptionCode& ec)
{
- // FIXME: Ditto. Implementation will be shared between these two send
- // functions.
+ send(unsignedData, 0, ec);
}
} // namespace WebCore
« 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