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

Side by Side Diff: Source/modules/webmidi/MIDIPort.cpp

Issue 1051903002: Web MIDI: implement implicit open() on send() and setOnmidimessage() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 { 90 {
91 switch (m_type) { 91 switch (m_type) {
92 case TypeInput: 92 case TypeInput:
93 return "input"; 93 return "input";
94 case TypeOutput: 94 case TypeOutput:
95 return "output"; 95 return "output";
96 } 96 }
97 return emptyString(); 97 return emptyString();
98 } 98 }
99 99
100 ScriptPromise MIDIPort::open(ScriptState* scriptState) 100 ScriptPromise MIDIPort::open(ScriptState* scriptState)
yhirano 2015/04/02 02:15:10 Why do you need this function? Isn't it enough to
Takashi Toyoshima 2015/04/02 04:03:21 ScriptState is still needed to return Promise at l
yhirano 2015/04/02 04:13:00 Sorry, I overlooked that.
101 { 101 {
102 if (m_connection == ConnectionStateClosed) { 102 open();
103 switch (m_state) {
104 case PortState::MIDIPortStateDisconnected:
105 setStates(m_state, ConnectionStatePending);
106 break;
107 case PortState::MIDIPortStateConnected:
108 // TODO(toyoshim): Add blink API to perform a real open and close
109 // operation.
110 setStates(m_state, ConnectionStateOpen);
111 break;
112 case PortState::MIDIPortStateOpened:
113 // TODO(toyoshim): Remove PortState::MIDIPortStateOpened.
114 ASSERT_NOT_REACHED();
115 break;
116 }
117 }
118 return accept(scriptState); 103 return accept(scriptState);
119 } 104 }
120 105
121 ScriptPromise MIDIPort::close(ScriptState* scriptState) 106 ScriptPromise MIDIPort::close(ScriptState* scriptState)
122 { 107 {
123 if (m_connection != ConnectionStateClosed) { 108 if (m_connection != ConnectionStateClosed) {
124 // TODO(toyoshim): Do clear() operation on MIDIOutput. 109 // TODO(toyoshim): Do clear() operation on MIDIOutput.
125 // TODO(toyoshim): Add blink API to perform a real close operation. 110 // TODO(toyoshim): Add blink API to perform a real close operation.
126 setStates(m_state, ConnectionStateClosed); 111 setStates(m_state, ConnectionStateClosed);
127 } 112 }
128 return accept(scriptState); 113 return accept(scriptState);
129 } 114 }
130 115
131 void MIDIPort::setState(PortState state) 116 void MIDIPort::setState(PortState state)
132 { 117 {
133 setStates(state, m_connection); 118 setStates(state, m_connection);
134 } 119 }
135 120
136 ExecutionContext* MIDIPort::executionContext() const 121 ExecutionContext* MIDIPort::executionContext() const
137 { 122 {
138 return m_access->executionContext(); 123 return m_access->executionContext();
139 } 124 }
140 125
141 DEFINE_TRACE(MIDIPort) 126 DEFINE_TRACE(MIDIPort)
142 { 127 {
143 visitor->trace(m_access); 128 visitor->trace(m_access);
144 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIPort>::trace(visitor ); 129 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIPort>::trace(visitor );
145 } 130 }
146 131
132 void MIDIPort::open()
133 {
134 if (m_connection == ConnectionStateClosed) {
135 switch (m_state) {
136 case PortState::MIDIPortStateDisconnected:
137 setStates(m_state, ConnectionStatePending);
138 break;
139 case PortState::MIDIPortStateConnected:
140 // TODO(toyoshim): Add blink API to perform a real open and close
141 // operation.
142 setStates(m_state, ConnectionStateOpen);
143 break;
144 case PortState::MIDIPortStateOpened:
145 // TODO(toyoshim): Remove PortState::MIDIPortStateOpened.
146 ASSERT_NOT_REACHED();
147 break;
148 }
149 }
150 }
151
147 ScriptPromise MIDIPort::accept(ScriptState* scriptState) 152 ScriptPromise MIDIPort::accept(ScriptState* scriptState)
148 { 153 {
149 return ScriptPromise::cast(scriptState, toV8(this, scriptState->context()->G lobal(), scriptState->isolate())); 154 return ScriptPromise::cast(scriptState, toV8(this, scriptState->context()->G lobal(), scriptState->isolate()));
150 } 155 }
151 156
152 ScriptPromise MIDIPort::reject(ScriptState* scriptState, ExceptionCode ec, const String& message) 157 ScriptPromise MIDIPort::reject(ScriptState* scriptState, ExceptionCode ec, const String& message)
153 { 158 {
154 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(ec, message)); 159 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(ec, message));
155 } 160 }
156 161
157 void MIDIPort::setStates(PortState state, ConnectionState connection) 162 void MIDIPort::setStates(PortState state, ConnectionState connection)
158 { 163 {
159 if (m_state == state && m_connection == connection) 164 if (m_state == state && m_connection == connection)
160 return; 165 return;
161 m_state = state; 166 m_state = state;
162 m_connection = connection; 167 m_connection = connection;
163 dispatchEvent(MIDIConnectionEvent::create(this)); 168 dispatchEvent(MIDIConnectionEvent::create(this));
164 m_access->dispatchEvent(MIDIConnectionEvent::create(this)); 169 m_access->dispatchEvent(MIDIConnectionEvent::create(this));
165 } 170 }
166 171
167 } // namespace blink 172 } // namespace blink
OLDNEW
« Source/modules/webmidi/MIDIPort.h ('K') | « Source/modules/webmidi/MIDIPort.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698