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

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

Issue 962523005: Web MIDI: add open() and close() to MIDIPort (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: review #14 Created 5 years, 10 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 a34aff62bb064afbc21d753f3d64630b6852a006..5a8b0db5287826a63c16d23d4440d95be9ff17fb 100644
--- a/Source/modules/webmidi/MIDIPort.cpp
+++ b/Source/modules/webmidi/MIDIPort.cpp
@@ -31,28 +31,48 @@
#include "config.h"
#include "modules/webmidi/MIDIPort.h"
+#include "bindings/core/v8/ScriptPromise.h"
+#include "core/dom/DOMError.h"
#include "modules/webmidi/MIDIAccess.h"
#include "modules/webmidi/MIDIConnectionEvent.h"
namespace blink {
-MIDIPort::MIDIPort(MIDIAccess* access, const String& id, const String& manufacturer, const String& name, MIDIPortTypeCode type, const String& version, bool isActive)
+using PortState = MIDIAccessor::MIDIPortState;
+
+MIDIPort::MIDIPort(MIDIAccess* access, const String& id, const String& manufacturer, const String& name, MIDIPortTypeCode 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_isActive(isActive)
{
ASSERT(access);
ASSERT(type == MIDIPortTypeInput || type == MIDIPortTypeOutput);
+ ASSERT(state == PortState::MIDIPortStateDisconnected
+ || state == PortState::MIDIPortStateConnected
+ || state == PortState::MIDIPortStateOpened);
+ // FIXME: 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::state() const
{
- // FIXME: Support complete MIDIPortState once Blink API is updated.
- return m_isActive ? "opened" : "disconnected";
+ switch (m_state) {
+ case PortState::MIDIPortStateDisconnected:
+ return "disconnected";
+ case PortState::MIDIPortStateConnected:
+ return "connected";
+ case PortState::MIDIPortStateOpened:
+ return "opened";
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ return emptyString();
}
String MIDIPort::type() const
@@ -68,9 +88,45 @@ String MIDIPort::type() const
return emptyString();
}
-void MIDIPort::setActiveState(bool isActive)
+ScriptPromise MIDIPort::open(ScriptState* scriptState)
+{
+ 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:
+ return accept(scriptState);
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ return reject(scriptState, "InvalidStateError", "The port is in unknown state.");
+}
+
+ScriptPromise MIDIPort::close(ScriptState* scriptState)
+{
+ 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:
+ return accept(scriptState);
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ return reject(scriptState, "InvalidStateError", "The port is in unknown state.");
+}
+
+void MIDIPort::setState(PortState state)
{
- m_isActive = isActive;
+ if (m_state == state)
+ return;
+ m_state = state;
dispatchEvent(MIDIConnectionEvent::create(this));
}
@@ -85,4 +141,15 @@ DEFINE_TRACE(MIDIPort)
RefCountedGarbageCollectedEventTargetWithInlineData<MIDIPort>::trace(visitor);
}
+ScriptPromise MIDIPort::accept(ScriptState* scriptState)
+{
+ return ScriptPromise::cast(scriptState, toV8(this, scriptState->context()->Global(), scriptState->isolate()));
+}
+
+ScriptPromise MIDIPort::reject(ScriptState* scriptState, const String& name, const String& message)
+{
+ return ScriptPromise::reject(scriptState, toV8(DOMError::create(name, message), scriptState->context()->Global(), scriptState->isolate()));
+}
+
+
} // 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