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

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

Issue 1043863002: Web MIDI: final IDL updates to conform the latest WD for shipping (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: drop clear() for now, and add missing update on open_close test 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
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

Powered by Google App Engine
This is Rietveld 408576698