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 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/webmidi/MIDIInput.h" | 32 #include "modules/webmidi/MIDIInput.h" |
33 | 33 |
34 #include "modules/webmidi/MIDIAccess.h" | 34 #include "modules/webmidi/MIDIAccess.h" |
35 #include "modules/webmidi/MIDIMessageEvent.h" | 35 #include "modules/webmidi/MIDIMessageEvent.h" |
36 | 36 |
37 namespace WebCore { | 37 namespace WebCore { |
38 | 38 |
39 PassRefPtr<MIDIInput> MIDIInput::create(MIDIAccess* access, ExecutionContext* co
ntext, const String& id, const String& manufacturer, const String& name, const S
tring& version) | 39 PassRefPtr<MIDIInput> MIDIInput::create(MIDIAccess* access, const String& id, co
nst String& manufacturer, const String& name, const String& version) |
40 { | 40 { |
41 ASSERT(access); | 41 ASSERT(access); |
42 RefPtr<MIDIInput> input = adoptRef(new MIDIInput(access, context, id, manufa
cturer, name, version)); | 42 RefPtr<MIDIInput> input = adoptRef(new MIDIInput(access, id, manufacturer, n
ame, version)); |
43 input->suspendIfNeeded(); | |
44 return input.release(); | 43 return input.release(); |
45 } | 44 } |
46 | 45 |
47 MIDIInput::MIDIInput(MIDIAccess* access, ExecutionContext* context, const String
& id, const String& manufacturer, const String& name, const String& version) | 46 MIDIInput::MIDIInput(MIDIAccess* access, const String& id, const String& manufac
turer, const String& name, const String& version) |
48 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeInput, version) | 47 : MIDIPort(access, id, manufacturer, name, MIDIPortTypeInput, version) |
49 , m_access(access) | |
50 { | 48 { |
51 ScriptWrappable::init(this); | 49 ScriptWrappable::init(this); |
52 } | 50 } |
53 | 51 |
54 void MIDIInput::didReceiveMIDIData(unsigned portIndex, const unsigned char* data
, size_t length, double timeStamp) | 52 void MIDIInput::didReceiveMIDIData(unsigned portIndex, const unsigned char* data
, size_t length, double timeStamp) |
55 { | 53 { |
56 ASSERT(isMainThread()); | 54 ASSERT(isMainThread()); |
57 | 55 |
58 if (!length) | 56 if (!length) |
59 return; | 57 return; |
60 | 58 |
61 // Drop SysEx message here when the client does not request it. Note that th
is is not a security check but an | 59 // Drop SysEx message here when the client does not request it. Note that th
is is not a security check but an |
62 // automatic filtering for clients that do not want SysEx message. Also note
that SysEx message will never be sent | 60 // automatic filtering for clients that do not want SysEx message. Also note
that SysEx message will never be sent |
63 // unless the current process has an explicit permission to handle SysEx mes
sage. | 61 // unless the current process has an explicit permission to handle SysEx mes
sage. |
64 if (data[0] == 0xf0 && !m_access->sysExEnabled()) | 62 if (data[0] == 0xf0 && !midiAccess()->sysExEnabled()) |
65 return; | 63 return; |
66 RefPtr<Uint8Array> array = Uint8Array::create(data, length); | 64 RefPtr<Uint8Array> array = Uint8Array::create(data, length); |
67 dispatchEvent(MIDIMessageEvent::create(timeStamp, array)); | 65 dispatchEvent(MIDIMessageEvent::create(timeStamp, array)); |
68 } | 66 } |
69 | 67 |
70 } // namespace WebCore | 68 } // namespace WebCore |
OLD | NEW |