| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/webmidi/MIDIAccessInitializer.h" | 6 #include "modules/webmidi/MIDIAccessInitializer.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMError.h" | 10 #include "core/dom/DOMError.h" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/frame/Navigator.h" | 12 #include "core/frame/Navigator.h" |
| 13 #include "modules/webmidi/MIDIAccess.h" | 13 #include "modules/webmidi/MIDIAccess.h" |
| 14 #include "modules/webmidi/MIDIController.h" | 14 #include "modules/webmidi/MIDIController.h" |
| 15 #include "modules/webmidi/MIDIOptions.h" | 15 #include "modules/webmidi/MIDIOptions.h" |
| 16 #include "modules/webmidi/MIDIPort.h" | 16 #include "modules/webmidi/MIDIPort.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 using PortState = WebMIDIAccessorClient::MIDIPortState; |
| 21 |
| 20 MIDIAccessInitializer::MIDIAccessInitializer(ScriptState* scriptState, const MID
IOptions& options) | 22 MIDIAccessInitializer::MIDIAccessInitializer(ScriptState* scriptState, const MID
IOptions& options) |
| 21 : ScriptPromiseResolver(scriptState) | 23 : ScriptPromiseResolver(scriptState) |
| 22 , m_requestSysex(false) | 24 , m_requestSysex(false) |
| 23 , m_hasBeenDisposed(false) | 25 , m_hasBeenDisposed(false) |
| 24 , m_sysexPermissionResolved(false) | 26 , m_sysexPermissionResolved(false) |
| 25 { | 27 { |
| 26 #if ENABLE(OILPAN) | 28 #if ENABLE(OILPAN) |
| 27 // A prefinalizer has already been registered (as a LifecycleObserver); | 29 // A prefinalizer has already been registered (as a LifecycleObserver); |
| 28 // remove it and register a combined one, as the infrastructure doesn't | 30 // remove it and register a combined one, as the infrastructure doesn't |
| 29 // support multiple prefinalizers for an object. | 31 // support multiple prefinalizers for an object. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 Document* document = toDocument(executionContext()); | 88 Document* document = toDocument(executionContext()); |
| 87 ASSERT(document); | 89 ASSERT(document); |
| 88 if (MIDIController* controller = MIDIController::from(document->frame())) | 90 if (MIDIController* controller = MIDIController::from(document->frame())) |
| 89 controller->requestSysexPermission(this); | 91 controller->requestSysexPermission(this); |
| 90 else | 92 else |
| 91 reject(DOMError::create("SecurityError")); | 93 reject(DOMError::create("SecurityError")); |
| 92 | 94 |
| 93 return promise; | 95 return promise; |
| 94 } | 96 } |
| 95 | 97 |
| 96 void MIDIAccessInitializer::didAddInputPort(const String& id, const String& manu
facturer, const String& name, const String& version, bool isActive) | 98 void MIDIAccessInitializer::didAddInputPort(const String& id, const String& manu
facturer, const String& name, const String& version, PortState state) |
| 97 { | 99 { |
| 98 ASSERT(m_accessor); | 100 ASSERT(m_accessor); |
| 99 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI
DIPortTypeInput, version, isActive)); | 101 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI
DIPortTypeInput, version, state)); |
| 100 } | 102 } |
| 101 | 103 |
| 102 void MIDIAccessInitializer::didAddOutputPort(const String& id, const String& man
ufacturer, const String& name, const String& version, bool isActive) | 104 void MIDIAccessInitializer::didAddOutputPort(const String& id, const String& man
ufacturer, const String& name, const String& version, PortState state) |
| 103 { | 105 { |
| 104 ASSERT(m_accessor); | 106 ASSERT(m_accessor); |
| 105 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI
DIPortTypeOutput, version, isActive)); | 107 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI
DIPortTypeOutput, version, state)); |
| 106 } | 108 } |
| 107 | 109 |
| 108 void MIDIAccessInitializer::didSetInputPortState(unsigned portIndex, bool isActi
ve) | 110 void MIDIAccessInitializer::didSetInputPortState(unsigned portIndex, PortState s
tate) |
| 109 { | 111 { |
| 110 // didSetInputPortState() is not allowed to call before didStartSession() | 112 // didSetInputPortState() is not allowed to call before didStartSession() |
| 111 // is called. Once didStartSession() is called, MIDIAccessorClient methods | 113 // is called. Once didStartSession() is called, MIDIAccessorClient methods |
| 112 // are delegated to MIDIAccess. See constructor of MIDIAccess. | 114 // are delegated to MIDIAccess. See constructor of MIDIAccess. |
| 113 ASSERT_NOT_REACHED(); | 115 ASSERT_NOT_REACHED(); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void MIDIAccessInitializer::didSetOutputPortState(unsigned portIndex, bool isAct
ive) | 118 void MIDIAccessInitializer::didSetOutputPortState(unsigned portIndex, PortState
state) |
| 117 { | 119 { |
| 118 // See comments on didSetInputPortState(). | 120 // See comments on didSetInputPortState(). |
| 119 ASSERT_NOT_REACHED(); | 121 ASSERT_NOT_REACHED(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void MIDIAccessInitializer::didStartSession(bool success, const String& error, c
onst String& message) | 124 void MIDIAccessInitializer::didStartSession(bool success, const String& error, c
onst String& message) |
| 123 { | 125 { |
| 124 ASSERT(m_accessor); | 126 ASSERT(m_accessor); |
| 125 if (success) { | 127 if (success) { |
| 126 resolve(MIDIAccess::create(m_accessor.release(), m_requestSysex, m_portD
escriptors, executionContext())); | 128 resolve(MIDIAccess::create(m_accessor.release(), m_requestSysex, m_portD
escriptors, executionContext())); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 142 { | 144 { |
| 143 return executionContext()->securityOrigin(); | 145 return executionContext()->securityOrigin(); |
| 144 } | 146 } |
| 145 | 147 |
| 146 ExecutionContext* MIDIAccessInitializer::executionContext() const | 148 ExecutionContext* MIDIAccessInitializer::executionContext() const |
| 147 { | 149 { |
| 148 return scriptState()->executionContext(); | 150 return scriptState()->executionContext(); |
| 149 } | 151 } |
| 150 | 152 |
| 151 } // namespace blink | 153 } // namespace blink |
| OLD | NEW |