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

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

Issue 1041213004: Web MIDI API: update open() and close() implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@midi_wd
Patch Set: done Created 5 years, 9 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 | « LayoutTests/webmidi/open_close-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webmidi/MIDIPort.cpp
diff --git a/Source/modules/webmidi/MIDIPort.cpp b/Source/modules/webmidi/MIDIPort.cpp
index cfa50060f741af5acd9fb1127ef9f95c04a75cd8..4664eacf578c1c8652d811e0e37333136cf0b25a 100644
--- a/Source/modules/webmidi/MIDIPort.cpp
+++ b/Source/modules/webmidi/MIDIPort.cpp
@@ -99,36 +99,33 @@ String MIDIPort::type() const
ScriptPromise MIDIPort::open(ScriptState* scriptState)
{
- // TODO(toyoshim): Implement the latest open() algorithm.
- switch (m_state) {
- case PortState::MIDIPortStateDisconnected:
- return reject(scriptState, InvalidStateError, "The port has been disconnected.");
- case PortState::MIDIPortStateConnected:
- // TODO(toyoshim): Add blink API to perform a real open operation.
- setStates(m_state, ConnectionStateOpen);
- return accept(scriptState);
- case PortState::MIDIPortStateOpened:
- // TODO(toyoshim): Remove PortState::MIDIPortStateOpened.
- ASSERT_NOT_REACHED();
+ if (m_connection == ConnectionStateClosed) {
+ switch (m_state) {
+ case PortState::MIDIPortStateDisconnected:
+ setStates(m_state, ConnectionStatePending);
+ break;
+ case PortState::MIDIPortStateConnected:
+ // TODO(toyoshim): Add blink API to perform a real open and close
+ // operation.
+ setStates(m_state, ConnectionStateOpen);
+ break;
+ case PortState::MIDIPortStateOpened:
+ // TODO(toyoshim): Remove PortState::MIDIPortStateOpened.
+ ASSERT_NOT_REACHED();
+ break;
+ }
}
- return reject(scriptState, InvalidStateError, "The port is in unknown state.");
+ return accept(scriptState);
}
ScriptPromise MIDIPort::close(ScriptState* scriptState)
{
- // TODO(toyoshim): Implement the latest close() algorithm.
- switch (m_state) {
- case PortState::MIDIPortStateDisconnected:
- return reject(scriptState, InvalidStateError, "The port has been disconnected.");
- case PortState::MIDIPortStateConnected:
+ if (m_connection != ConnectionStateClosed) {
+ // TODO(toyoshim): Do clear() operation on MIDIOutput.
// TODO(toyoshim): Add blink API to perform a real close operation.
setStates(m_state, ConnectionStateClosed);
- return accept(scriptState);
- case PortState::MIDIPortStateOpened:
- // TODO(toyoshim): Remove PortState::MIDIPortStateOpened.
- ASSERT_NOT_REACHED();
}
- return reject(scriptState, InvalidStateError, "The port is in unknown state.");
+ return accept(scriptState);
}
void MIDIPort::setState(PortState state)
@@ -164,6 +161,7 @@ void MIDIPort::setStates(PortState state, ConnectionState connection)
m_state = state;
m_connection = connection;
dispatchEvent(MIDIConnectionEvent::create(this));
+ m_access->dispatchEvent(MIDIConnectionEvent::create(this));
}
} // namespace blink
« no previous file with comments | « LayoutTests/webmidi/open_close-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698