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

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

Issue 2422163002: Web MIDI: use midi_service.mojom for media::midi::PortState (Closed)
Patch Set: gn --check fix Created 4 years, 2 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 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "modules/webmidi/MIDIPort.h" 31 #include "modules/webmidi/MIDIPort.h"
32 32
33 #include "bindings/core/v8/ScriptPromise.h" 33 #include "bindings/core/v8/ScriptPromise.h"
34 #include "core/dom/DOMException.h" 34 #include "core/dom/DOMException.h"
35 #include "modules/webmidi/MIDIAccess.h" 35 #include "modules/webmidi/MIDIAccess.h"
36 #include "modules/webmidi/MIDIConnectionEvent.h" 36 #include "modules/webmidi/MIDIConnectionEvent.h"
37 37
38 using midi::mojom::PortState;
39
38 namespace blink { 40 namespace blink {
39 41
40 using PortState = MIDIAccessor::MIDIPortState;
41
42 MIDIPort::MIDIPort(MIDIAccess* access, 42 MIDIPort::MIDIPort(MIDIAccess* access,
43 const String& id, 43 const String& id,
44 const String& manufacturer, 44 const String& manufacturer,
45 const String& name, 45 const String& name,
46 TypeCode type, 46 TypeCode type,
47 const String& version, 47 const String& version,
48 PortState state) 48 PortState state)
49 : ActiveScriptWrappable(this), 49 : ActiveScriptWrappable(this),
50 ActiveDOMObject(access->getExecutionContext()), 50 ActiveDOMObject(access->getExecutionContext()),
51 m_id(id), 51 m_id(id),
52 m_manufacturer(manufacturer), 52 m_manufacturer(manufacturer),
53 m_name(name), 53 m_name(name),
54 m_type(type), 54 m_type(type),
55 m_version(version), 55 m_version(version),
56 m_access(access), 56 m_access(access),
57 m_connection(ConnectionStateClosed) { 57 m_connection(ConnectionStateClosed) {
58 DCHECK(access); 58 DCHECK(access);
59 DCHECK(type == TypeInput || type == TypeOutput); 59 DCHECK(type == TypeInput || type == TypeOutput);
60 DCHECK(state == PortState::MIDIPortStateDisconnected || 60 DCHECK(state == PortState::DISCONNECTED || state == PortState::CONNECTED);
61 state == PortState::MIDIPortStateConnected);
62 m_state = state; 61 m_state = state;
63 } 62 }
64 63
65 String MIDIPort::connection() const { 64 String MIDIPort::connection() const {
66 switch (m_connection) { 65 switch (m_connection) {
67 case ConnectionStateOpen: 66 case ConnectionStateOpen:
68 return "open"; 67 return "open";
69 case ConnectionStateClosed: 68 case ConnectionStateClosed:
70 return "closed"; 69 return "closed";
71 case ConnectionStatePending: 70 case ConnectionStatePending:
72 return "pending"; 71 return "pending";
73 } 72 }
74 return emptyString(); 73 return emptyString();
75 } 74 }
76 75
77 String MIDIPort::state() const { 76 String MIDIPort::state() const {
78 switch (m_state) { 77 switch (m_state) {
79 case PortState::MIDIPortStateDisconnected: 78 case PortState::DISCONNECTED:
80 return "disconnected"; 79 return "disconnected";
81 case PortState::MIDIPortStateConnected: 80 case PortState::CONNECTED:
81 return "connected";
82 case PortState::OPENED:
83 NOTREACHED();
82 return "connected"; 84 return "connected";
83 } 85 }
84 return emptyString(); 86 return emptyString();
85 } 87 }
86 88
87 String MIDIPort::type() const { 89 String MIDIPort::type() const {
88 switch (m_type) { 90 switch (m_type) {
89 case TypeInput: 91 case TypeInput:
90 return "input"; 92 return "input";
91 case TypeOutput: 93 case TypeOutput:
(...skipping 11 matching lines...) Expand all
103 if (m_connection != ConnectionStateClosed) { 105 if (m_connection != ConnectionStateClosed) {
104 // TODO(toyoshim): Do clear() operation on MIDIOutput. 106 // TODO(toyoshim): Do clear() operation on MIDIOutput.
105 // TODO(toyoshim): Add blink API to perform a real close operation. 107 // TODO(toyoshim): Add blink API to perform a real close operation.
106 setStates(m_state, ConnectionStateClosed); 108 setStates(m_state, ConnectionStateClosed);
107 } 109 }
108 return accept(scriptState); 110 return accept(scriptState);
109 } 111 }
110 112
111 void MIDIPort::setState(PortState state) { 113 void MIDIPort::setState(PortState state) {
112 switch (state) { 114 switch (state) {
113 case PortState::MIDIPortStateDisconnected: 115 case PortState::DISCONNECTED:
114 switch (m_connection) { 116 switch (m_connection) {
115 case ConnectionStateOpen: 117 case ConnectionStateOpen:
116 case ConnectionStatePending: 118 case ConnectionStatePending:
117 setStates(PortState::MIDIPortStateDisconnected, 119 setStates(PortState::DISCONNECTED, ConnectionStatePending);
118 ConnectionStatePending);
119 break; 120 break;
120 case ConnectionStateClosed: 121 case ConnectionStateClosed:
121 // Will do nothing. 122 // Will do nothing.
122 setStates(PortState::MIDIPortStateDisconnected, 123 setStates(PortState::DISCONNECTED, ConnectionStateClosed);
123 ConnectionStateClosed);
124 break; 124 break;
125 } 125 }
126 break; 126 break;
127 case PortState::MIDIPortStateConnected: 127 case PortState::CONNECTED:
128 switch (m_connection) { 128 switch (m_connection) {
129 case ConnectionStateOpen: 129 case ConnectionStateOpen:
130 NOTREACHED(); 130 NOTREACHED();
131 break; 131 break;
132 case ConnectionStatePending: 132 case ConnectionStatePending:
133 // We do not use |setStates| in order not to dispatch events twice. 133 // We do not use |setStates| in order not to dispatch events twice.
134 // |open| calls |setStates|. 134 // |open| calls |setStates|.
135 m_state = PortState::MIDIPortStateConnected; 135 m_state = PortState::CONNECTED;
136 open(); 136 open();
137 break; 137 break;
138 case ConnectionStateClosed: 138 case ConnectionStateClosed:
139 setStates(PortState::MIDIPortStateConnected, ConnectionStateClosed); 139 setStates(PortState::CONNECTED, ConnectionStateClosed);
140 break; 140 break;
141 } 141 }
142 break; 142 break;
143 case PortState::OPENED:
144 NOTREACHED();
145 break;
143 } 146 }
144 } 147 }
145 148
146 ExecutionContext* MIDIPort::getExecutionContext() const { 149 ExecutionContext* MIDIPort::getExecutionContext() const {
147 return m_access->getExecutionContext(); 150 return m_access->getExecutionContext();
148 } 151 }
149 152
150 bool MIDIPort::hasPendingActivity() const { 153 bool MIDIPort::hasPendingActivity() const {
151 // MIDIPort should survive if ConnectionState is "open" or can be "open" via 154 // MIDIPort should survive if ConnectionState is "open" or can be "open" via
152 // a MIDIConnectionEvent even if there are no references from JavaScript. 155 // a MIDIConnectionEvent even if there are no references from JavaScript.
(...skipping 10 matching lines...) Expand all
163 EventTargetWithInlineData::trace(visitor); 166 EventTargetWithInlineData::trace(visitor);
164 ActiveDOMObject::trace(visitor); 167 ActiveDOMObject::trace(visitor);
165 } 168 }
166 169
167 DEFINE_TRACE_WRAPPERS(MIDIPort) { 170 DEFINE_TRACE_WRAPPERS(MIDIPort) {
168 visitor->traceWrappers(m_access); 171 visitor->traceWrappers(m_access);
169 } 172 }
170 173
171 void MIDIPort::open() { 174 void MIDIPort::open() {
172 switch (m_state) { 175 switch (m_state) {
173 case PortState::MIDIPortStateDisconnected: 176 case PortState::DISCONNECTED:
174 setStates(m_state, ConnectionStatePending); 177 setStates(m_state, ConnectionStatePending);
175 break; 178 break;
176 case PortState::MIDIPortStateConnected: 179 case PortState::CONNECTED:
177 // TODO(toyoshim): Add blink API to perform a real open and close 180 // TODO(toyoshim): Add blink API to perform a real open and close
178 // operation. 181 // operation.
179 setStates(m_state, ConnectionStateOpen); 182 setStates(m_state, ConnectionStateOpen);
180 break; 183 break;
184 case PortState::OPENED:
185 NOTREACHED();
186 break;
181 } 187 }
182 } 188 }
183 189
184 ScriptPromise MIDIPort::accept(ScriptState* scriptState) { 190 ScriptPromise MIDIPort::accept(ScriptState* scriptState) {
185 return ScriptPromise::cast( 191 return ScriptPromise::cast(
186 scriptState, 192 scriptState,
187 toV8(this, scriptState->context()->Global(), scriptState->isolate())); 193 toV8(this, scriptState->context()->Global(), scriptState->isolate()));
188 } 194 }
189 195
190 ScriptPromise MIDIPort::reject(ScriptState* scriptState, 196 ScriptPromise MIDIPort::reject(ScriptState* scriptState,
191 ExceptionCode ec, 197 ExceptionCode ec,
192 const String& message) { 198 const String& message) {
193 return ScriptPromise::rejectWithDOMException( 199 return ScriptPromise::rejectWithDOMException(
194 scriptState, DOMException::create(ec, message)); 200 scriptState, DOMException::create(ec, message));
195 } 201 }
196 202
197 void MIDIPort::setStates(PortState state, ConnectionState connection) { 203 void MIDIPort::setStates(PortState state, ConnectionState connection) {
198 DCHECK(state != PortState::MIDIPortStateDisconnected || 204 DCHECK(state != PortState::DISCONNECTED || connection != ConnectionStateOpen);
199 connection != ConnectionStateOpen);
200 if (m_state == state && m_connection == connection) 205 if (m_state == state && m_connection == connection)
201 return; 206 return;
202 m_state = state; 207 m_state = state;
203 m_connection = connection; 208 m_connection = connection;
204 dispatchEvent(MIDIConnectionEvent::create(this)); 209 dispatchEvent(MIDIConnectionEvent::create(this));
205 m_access->dispatchEvent(MIDIConnectionEvent::create(this)); 210 m_access->dispatchEvent(MIDIConnectionEvent::create(this));
206 } 211 }
207 212
208 } // namespace blink 213 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698