Chromium Code Reviews| Index: Source/modules/webmidi/MIDIPort.cpp |
| diff --git a/Source/modules/webmidi/MIDIPort.cpp b/Source/modules/webmidi/MIDIPort.cpp |
| index 519de7fa4cc98b9707f8da8b4ae30b82768f1b8a..20824dcf3820de76b078dbf5f85535599665bfa1 100644 |
| --- a/Source/modules/webmidi/MIDIPort.cpp |
| +++ b/Source/modules/webmidi/MIDIPort.cpp |
| @@ -47,6 +47,7 @@ MIDIPort::MIDIPort(MIDIAccess* access, const String& id, const String& manufactu |
| , m_type(type) |
| , m_version(version) |
| , m_access(access) |
| + , m_connection(MIDIPortConnectionStateClosed) |
| { |
| ASSERT(access); |
| ASSERT(type == MIDIPortTypeInput || type == MIDIPortTypeOutput); |
| @@ -60,6 +61,21 @@ MIDIPort::MIDIPort(MIDIAccess* access, const String& id, const String& manufactu |
| m_state = state; |
| } |
| +String MIDIPort::connection() const |
| +{ |
| + switch (m_connection) { |
| + case MIDIPortConnectionStateOpen: |
| + return "open"; |
| + case MIDIPortConnectionStateClosed: |
| + return "closed"; |
| + case MIDIPortConnectionStatePending: |
| + return "pending"; |
| + default: |
|
tkent
2015/03/30 23:16:30
Please do not add "default:" It prevents compile-
Takashi Toyoshima
2015/03/31 01:19:48
Done.
|
| + ASSERT_NOT_REACHED(); |
| + } |
| + return emptyString(); |
| +} |
| + |
| String MIDIPort::state() const |
| { |
| switch (m_state) { |
| @@ -67,8 +83,6 @@ String MIDIPort::state() const |
| return "disconnected"; |
| case PortState::MIDIPortStateConnected: |
| return "connected"; |
| - case PortState::MIDIPortStateOpened: |
| - return "opened"; |
| default: |
| ASSERT_NOT_REACHED(); |
| } |
| @@ -90,14 +104,13 @@ String MIDIPort::type() const |
| ScriptPromise MIDIPort::open(ScriptState* scriptState) |
| { |
| + // FIXME: Implement the latest open() algorithm. |
|
tkent
2015/03/30 23:16:30
nit: FIXME -> TODO(toyoshim)
Takashi Toyoshima
2015/03/31 01:19:48
Done.
|
| switch (m_state) { |
| case PortState::MIDIPortStateDisconnected: |
| return reject(scriptState, InvalidStateError, "The port has been disconnected."); |
| case PortState::MIDIPortStateConnected: |
| // FIXME: Add blink API to perform a real open operation. |
| - setState(PortState::MIDIPortStateOpened); |
| - // fall through |
| - case PortState::MIDIPortStateOpened: |
| + setStates(m_state, MIDIPortConnectionStateOpen); |
| return accept(scriptState); |
| default: |
| ASSERT_NOT_REACHED(); |
| @@ -107,14 +120,13 @@ ScriptPromise MIDIPort::open(ScriptState* scriptState) |
| ScriptPromise MIDIPort::close(ScriptState* scriptState) |
| { |
| + // FIXME: Implement the latest close() algorithm. |
|
tkent
2015/03/30 23:16:30
Ditto.
Takashi Toyoshima
2015/03/31 01:19:48
Done.
|
| switch (m_state) { |
| case PortState::MIDIPortStateDisconnected: |
| return reject(scriptState, InvalidStateError, "The port has been disconnected."); |
| - case PortState::MIDIPortStateOpened: |
| - // FIXME: Add blink API to perform a real close operation. |
| - setState(PortState::MIDIPortStateConnected); |
| - // fall through |
| case PortState::MIDIPortStateConnected: |
| + // FIXME: Add blink API to perform a real close operation. |
| + setStates(m_state, MIDIPortConnectionStateClosed); |
| return accept(scriptState); |
| default: |
| ASSERT_NOT_REACHED(); |
| @@ -124,10 +136,7 @@ ScriptPromise MIDIPort::close(ScriptState* scriptState) |
| void MIDIPort::setState(PortState state) |
| { |
| - if (m_state == state) |
| - return; |
| - m_state = state; |
| - dispatchEvent(MIDIConnectionEvent::create(this)); |
| + setStates(state, m_connection); |
| } |
| ExecutionContext* MIDIPort::executionContext() const |
| @@ -151,4 +160,13 @@ ScriptPromise MIDIPort::reject(ScriptState* scriptState, ExceptionCode ec, const |
| return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(ec, message)); |
| } |
| +void MIDIPort::setStates(PortState state, MIDIPortConnectionState connection) |
| +{ |
| + if (m_state == state && m_connection == connection) |
| + return; |
| + m_state = state; |
| + m_connection = connection; |
| + dispatchEvent(MIDIConnectionEvent::create(this)); |
|
tkent
2015/03/30 23:16:30
Is it possible to delete |this| by JavaScript code
Takashi Toyoshima
2015/03/31 01:19:48
Ah, I see. JavaScript can release the last referen
|
| +} |
| + |
| } // namespace blink |