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

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: TODO: ActiveDOMObject 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 | « Source/modules/webmidi/MIDIPort.h ('k') | Source/modules/webmidi/MIDIPort.idl » ('j') | 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 519de7fa4cc98b9707f8da8b4ae30b82768f1b8a..cfa50060f741af5acd9fb1127ef9f95c04a75cd8 100644
--- a/Source/modules/webmidi/MIDIPort.cpp
+++ b/Source/modules/webmidi/MIDIPort.cpp
@@ -40,37 +40,48 @@ namespace blink {
using PortState = MIDIAccessor::MIDIPortState;
-MIDIPort::MIDIPort(MIDIAccess* access, const String& id, const String& manufacturer, const String& name, MIDIPortTypeCode type, const String& version, PortState state)
+MIDIPort::MIDIPort(MIDIAccess* access, const String& id, const String& manufacturer, const String& name, TypeCode type, const String& version, PortState state)
: m_id(id)
, m_manufacturer(manufacturer)
, m_name(name)
, m_type(type)
, m_version(version)
, m_access(access)
+ , m_connection(ConnectionStateClosed)
{
ASSERT(access);
- ASSERT(type == MIDIPortTypeInput || type == MIDIPortTypeOutput);
+ ASSERT(type == TypeInput || type == TypeOutput);
ASSERT(state == PortState::MIDIPortStateDisconnected
|| state == PortState::MIDIPortStateConnected
|| state == PortState::MIDIPortStateOpened);
- // FIXME: Remove following code once blink API has a real open and close
- // operations.
+ // TODO(toyoshim): Remove following code once blink API has a real open and
+ // close operations.
if (state == PortState::MIDIPortStateOpened)
state = PortState::MIDIPortStateConnected;
m_state = state;
}
+String MIDIPort::connection() const
+{
+ switch (m_connection) {
+ case ConnectionStateOpen:
+ return "open";
+ case ConnectionStateClosed:
+ return "closed";
+ case ConnectionStatePending:
+ return "pending";
+ }
+ return emptyString();
+}
+
String MIDIPort::state() const
{
switch (m_state) {
case PortState::MIDIPortStateDisconnected:
return "disconnected";
case PortState::MIDIPortStateConnected:
- return "connected";
case PortState::MIDIPortStateOpened:
- return "opened";
- default:
- ASSERT_NOT_REACHED();
+ return "connected";
}
return emptyString();
}
@@ -78,28 +89,26 @@ String MIDIPort::state() const
String MIDIPort::type() const
{
switch (m_type) {
- case MIDIPortTypeInput:
+ case TypeInput:
return "input";
- case MIDIPortTypeOutput:
+ case TypeOutput:
return "output";
- default:
- ASSERT_NOT_REACHED();
}
return emptyString();
}
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:
- // FIXME: Add blink API to perform a real open operation.
- setState(PortState::MIDIPortStateOpened);
- // fall through
- case PortState::MIDIPortStateOpened:
+ // TODO(toyoshim): Add blink API to perform a real open operation.
+ setStates(m_state, ConnectionStateOpen);
return accept(scriptState);
- default:
+ case PortState::MIDIPortStateOpened:
+ // TODO(toyoshim): Remove PortState::MIDIPortStateOpened.
ASSERT_NOT_REACHED();
}
return reject(scriptState, InvalidStateError, "The port is in unknown state.");
@@ -107,16 +116,16 @@ ScriptPromise MIDIPort::open(ScriptState* 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::MIDIPortStateOpened:
- // FIXME: Add blink API to perform a real close operation.
- setState(PortState::MIDIPortStateConnected);
- // fall through
case PortState::MIDIPortStateConnected:
+ // TODO(toyoshim): Add blink API to perform a real close operation.
+ setStates(m_state, ConnectionStateClosed);
return accept(scriptState);
- default:
+ case PortState::MIDIPortStateOpened:
+ // TODO(toyoshim): Remove PortState::MIDIPortStateOpened.
ASSERT_NOT_REACHED();
}
return reject(scriptState, InvalidStateError, "The port is in unknown state.");
@@ -124,10 +133,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 +157,13 @@ ScriptPromise MIDIPort::reject(ScriptState* scriptState, ExceptionCode ec, const
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(ec, message));
}
+void MIDIPort::setStates(PortState state, ConnectionState connection)
+{
+ if (m_state == state && m_connection == connection)
+ return;
+ m_state = state;
+ m_connection = connection;
+ dispatchEvent(MIDIConnectionEvent::create(this));
+}
+
} // namespace blink
« no previous file with comments | « Source/modules/webmidi/MIDIPort.h ('k') | Source/modules/webmidi/MIDIPort.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698