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 20 matching lines...) Expand all Loading... |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/webmidi/MIDIAccess.h" | 32 #include "modules/webmidi/MIDIAccess.h" |
33 | 33 |
34 #include "core/dom/DOMError.h" | 34 #include "core/dom/DOMError.h" |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
37 #include "core/loader/DocumentLoadTiming.h" | 37 #include "core/loader/DocumentLoadTiming.h" |
38 #include "core/loader/DocumentLoader.h" | 38 #include "core/loader/DocumentLoader.h" |
39 #include "modules/webmidi/MIDIAccessPromise.h" | 39 #include "modules/webmidi/MIDIAccessPromise.h" |
40 #include "modules/webmidi/MIDIConnectionEvent.h" | 40 #include "modules/webmidi/MIDIConnectionEvent.h" |
| 41 #include "modules/webmidi/MIDIController.h" |
41 #include "modules/webmidi/MIDIInput.h" | 42 #include "modules/webmidi/MIDIInput.h" |
42 #include "modules/webmidi/MIDIOutput.h" | 43 #include "modules/webmidi/MIDIOutput.h" |
43 #include "modules/webmidi/MIDIPort.h" | 44 #include "modules/webmidi/MIDIPort.h" |
44 | 45 |
45 namespace WebCore { | 46 namespace WebCore { |
46 | 47 |
47 PassRefPtr<MIDIAccess> MIDIAccess::create(ScriptExecutionContext* context, MIDIA
ccessPromise* promise) | 48 PassRefPtr<MIDIAccess> MIDIAccess::create(ScriptExecutionContext* context, MIDIA
ccessPromise* promise) |
48 { | 49 { |
49 RefPtr<MIDIAccess> midiAccess(adoptRef(new MIDIAccess(context, promise))); | 50 RefPtr<MIDIAccess> midiAccess(adoptRef(new MIDIAccess(context, promise))); |
50 midiAccess->suspendIfNeeded(); | 51 midiAccess->suspendIfNeeded(); |
| 52 midiAccess->startRequest(); |
51 return midiAccess.release(); | 53 return midiAccess.release(); |
52 } | 54 } |
53 | 55 |
54 MIDIAccess::~MIDIAccess() | 56 MIDIAccess::~MIDIAccess() |
55 { | 57 { |
56 stop(); | 58 stop(); |
57 } | 59 } |
58 | 60 |
59 MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi
se) | 61 MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi
se) |
60 : ActiveDOMObject(context) | 62 : ActiveDOMObject(context) |
61 , m_promise(promise) | 63 , m_promise(promise) |
62 , m_hasAccess(false) | 64 , m_hasAccess(false) |
| 65 , m_enableSysEx(false) |
| 66 , m_requesting(false) |
63 { | 67 { |
64 ScriptWrappable::init(this); | 68 ScriptWrappable::init(this); |
65 m_accessor = MIDIAccessor::create(this); | 69 m_accessor = MIDIAccessor::create(this); |
66 m_accessor->requestAccess(promise->options()->sysex); | 70 } |
| 71 |
| 72 void MIDIAccess::enableSysEx(bool enable) |
| 73 { |
| 74 m_requesting = false; |
| 75 m_enableSysEx = enable; |
| 76 if (enable) |
| 77 m_accessor->requestAccess(); |
| 78 else |
| 79 didBlockAccess(); |
67 } | 80 } |
68 | 81 |
69 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) | 82 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) |
70 { | 83 { |
71 ASSERT(isMainThread()); | 84 ASSERT(isMainThread()); |
72 | 85 |
| 86 // FIXME: Pass m_enableSysEx flag to filter system exclusive messages correc
tly. |
73 m_inputs.append(MIDIInput::create(scriptExecutionContext(), id, manufacturer
, name, version)); | 87 m_inputs.append(MIDIInput::create(scriptExecutionContext(), id, manufacturer
, name, version)); |
74 } | 88 } |
75 | 89 |
76 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) | 90 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) |
77 { | 91 { |
78 ASSERT(isMainThread()); | 92 ASSERT(isMainThread()); |
79 | 93 |
| 94 // FIXME: Pass m_enableSysEx flag to filter system exclusive messages correc
tly. |
80 m_outputs.append(MIDIOutput::create(scriptExecutionContext(), id, manufactur
er, name, version)); | 95 m_outputs.append(MIDIOutput::create(scriptExecutionContext(), id, manufactur
er, name, version)); |
81 } | 96 } |
82 | 97 |
83 void MIDIAccess::didAllowAccess() | 98 void MIDIAccess::didAllowAccess() |
84 { | 99 { |
85 ASSERT(isMainThread()); | 100 ASSERT(isMainThread()); |
86 | 101 |
87 m_hasAccess = true; | 102 m_hasAccess = true; |
88 m_promise->fulfill(); | 103 m_promise->fulfill(); |
89 } | 104 } |
(...skipping 20 matching lines...) Expand all Loading... |
110 | 125 |
111 double timeStampInMilliseconds = 1000 * document->loader()->timing()->mo
notonicTimeToZeroBasedDocumentTime(timeStamp); | 126 double timeStampInMilliseconds = 1000 * document->loader()->timing()->mo
notonicTimeToZeroBasedDocumentTime(timeStamp); |
112 | 127 |
113 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeSta
mpInMilliseconds); | 128 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeSta
mpInMilliseconds); |
114 } | 129 } |
115 } | 130 } |
116 | 131 |
117 void MIDIAccess::stop() | 132 void MIDIAccess::stop() |
118 { | 133 { |
119 m_hasAccess = false; | 134 m_hasAccess = false; |
| 135 if (!m_requesting) |
| 136 return; |
| 137 m_requesting = false; |
| 138 Document* document = toDocument(scriptExecutionContext()); |
| 139 ASSERT(document); |
| 140 MIDIController* controller = MIDIController::from(document->page()); |
| 141 ASSERT(controller); |
| 142 controller->cancelSysExPermissionRequest(this); |
| 143 } |
| 144 |
| 145 void MIDIAccess::startRequest() |
| 146 { |
| 147 if (!m_promise->options()->sysex) { |
| 148 m_accessor->requestAccess(); |
| 149 return; |
| 150 } |
| 151 Document* document = toDocument(scriptExecutionContext()); |
| 152 ASSERT(document); |
| 153 MIDIController* controller = MIDIController::from(document->page()); |
| 154 if (controller) { |
| 155 m_requesting = true; |
| 156 controller->requestSysExPermission(this); |
| 157 } else { |
| 158 didBlockAccess(); |
| 159 } |
120 } | 160 } |
121 | 161 |
122 } // namespace WebCore | 162 } // namespace WebCore |
OLD | NEW |