OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/webmidi/MIDIAccessInitializer.h" | 6 #include "modules/webmidi/MIDIAccessInitializer.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 controller->requestSysexPermission(this); | 89 controller->requestSysexPermission(this); |
90 else | 90 else |
91 reject(DOMException::create(SecurityError)); | 91 reject(DOMException::create(SecurityError)); |
92 | 92 |
93 return promise; | 93 return promise; |
94 } | 94 } |
95 | 95 |
96 void MIDIAccessInitializer::didAddInputPort(const String& id, const String& manu
facturer, const String& name, const String& version, PortState state) | 96 void MIDIAccessInitializer::didAddInputPort(const String& id, const String& manu
facturer, const String& name, const String& version, PortState state) |
97 { | 97 { |
98 ASSERT(m_accessor); | 98 ASSERT(m_accessor); |
99 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI
DIPortTypeInput, version, state)); | 99 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::Ty
peInput, version, state)); |
100 } | 100 } |
101 | 101 |
102 void MIDIAccessInitializer::didAddOutputPort(const String& id, const String& man
ufacturer, const String& name, const String& version, PortState state) | 102 void MIDIAccessInitializer::didAddOutputPort(const String& id, const String& man
ufacturer, const String& name, const String& version, PortState state) |
103 { | 103 { |
104 ASSERT(m_accessor); | 104 ASSERT(m_accessor); |
105 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI
DIPortTypeOutput, version, state)); | 105 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::Ty
peOutput, version, state)); |
106 } | 106 } |
107 | 107 |
108 void MIDIAccessInitializer::didSetInputPortState(unsigned portIndex, PortState s
tate) | 108 void MIDIAccessInitializer::didSetInputPortState(unsigned portIndex, PortState s
tate) |
109 { | 109 { |
110 // didSetInputPortState() is not allowed to call before didStartSession() | 110 // didSetInputPortState() is not allowed to call before didStartSession() |
111 // is called. Once didStartSession() is called, MIDIAccessorClient methods | 111 // is called. Once didStartSession() is called, MIDIAccessorClient methods |
112 // are delegated to MIDIAccess. See constructor of MIDIAccess. | 112 // are delegated to MIDIAccess. See constructor of MIDIAccess. |
113 ASSERT_NOT_REACHED(); | 113 ASSERT_NOT_REACHED(); |
114 } | 114 } |
115 | 115 |
116 void MIDIAccessInitializer::didSetOutputPortState(unsigned portIndex, PortState
state) | 116 void MIDIAccessInitializer::didSetOutputPortState(unsigned portIndex, PortState
state) |
117 { | 117 { |
118 // See comments on didSetInputPortState(). | 118 // See comments on didSetInputPortState(). |
119 ASSERT_NOT_REACHED(); | 119 ASSERT_NOT_REACHED(); |
120 } | 120 } |
121 | 121 |
122 void MIDIAccessInitializer::didStartSession(bool success, const String& error, c
onst String& message) | 122 void MIDIAccessInitializer::didStartSession(bool success, const String& error, c
onst String& message) |
123 { | 123 { |
124 ASSERT(m_accessor); | 124 ASSERT(m_accessor); |
125 if (success) { | 125 if (success) { |
126 resolve(MIDIAccess::create(m_accessor.release(), m_requestSysex, m_portD
escriptors, executionContext())); | 126 resolve(MIDIAccess::create(m_accessor.release(), m_requestSysex, m_portD
escriptors, executionContext())); |
127 } else { | 127 } else { |
128 // The spec says the name is one of | 128 // The spec says the name is one of |
129 // - SecurityError | 129 // - SecurityError |
130 // - AbortError | 130 // - AbortError |
131 // - InvalidStateError | 131 // - InvalidStateError |
132 // - NotSupportedError | 132 // - NotSupportedError |
133 // FIXME: Do not rely on |error| string. Instead an enum representing | 133 // TODO(toyoshim): Do not rely on |error| string. Instead an enum |
134 // an ExceptionCode should be defined and deliverred. | 134 // representing an ExceptionCode should be defined and deliverred. |
135 ExceptionCode ec = InvalidStateError; | 135 ExceptionCode ec = InvalidStateError; |
136 if (error == DOMException::getErrorName(SecurityError)) { | 136 if (error == DOMException::getErrorName(SecurityError)) { |
137 ec = SecurityError; | 137 ec = SecurityError; |
138 } else if (error == DOMException::getErrorName(AbortError)) { | 138 } else if (error == DOMException::getErrorName(AbortError)) { |
139 ec = AbortError; | 139 ec = AbortError; |
140 } else if (error == DOMException::getErrorName(InvalidStateError)) { | 140 } else if (error == DOMException::getErrorName(InvalidStateError)) { |
141 ec = InvalidStateError; | 141 ec = InvalidStateError; |
142 } else if (error == DOMException::getErrorName(NotSupportedError)) { | 142 } else if (error == DOMException::getErrorName(NotSupportedError)) { |
143 ec = NotSupportedError; | 143 ec = NotSupportedError; |
144 } | 144 } |
(...skipping 14 matching lines...) Expand all Loading... |
159 { | 159 { |
160 return executionContext()->securityOrigin(); | 160 return executionContext()->securityOrigin(); |
161 } | 161 } |
162 | 162 |
163 ExecutionContext* MIDIAccessInitializer::executionContext() const | 163 ExecutionContext* MIDIAccessInitializer::executionContext() const |
164 { | 164 { |
165 return scriptState()->executionContext(); | 165 return scriptState()->executionContext(); |
166 } | 166 } |
167 | 167 |
168 } // namespace blink | 168 } // namespace blink |
OLD | NEW |