| 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 MIDIAccessInitializer::MIDIAccessInitializer(ScriptState* scriptState, const MID
IOptions& options) | 20 MIDIAccessInitializer::MIDIAccessInitializer(ScriptState* scriptState, const MID
IOptions& options) |
| 21 : ScriptPromiseResolver(scriptState) | 21 : ScriptPromiseResolver(scriptState) |
| 22 , m_requestSysex(false) | 22 , m_requestSysex(false) |
| 23 { | 23 { |
| 24 if (options.hasSysex()) | 24 if (options.hasSysex()) |
| 25 m_requestSysex = options.sysex(); | 25 m_requestSysex = options.sysex(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 MIDIAccessInitializer::~MIDIAccessInitializer() | 28 MIDIAccessInitializer::~MIDIAccessInitializer() |
| 29 { | 29 { |
| 30 // It is safe to cancel a request which is already finished or canceld. | 30 #if !ENABLE(OILPAN) |
| 31 dispose(); |
| 32 #endif |
| 33 } |
| 34 |
| 35 void MIDIAccessInitializer::dispose() |
| 36 { |
| 37 // It is safe to cancel a request which is already finished or cancelled. |
| 31 Document* document = toDocument(executionContext()); | 38 Document* document = toDocument(executionContext()); |
| 32 ASSERT(document); | 39 ASSERT(document); |
| 33 MIDIController* controller = MIDIController::from(document->frame()); | 40 if (MIDIController* controller = MIDIController::from(document->frame())) |
| 34 if (controller) | |
| 35 controller->cancelSysexPermissionRequest(this); | 41 controller->cancelSysexPermissionRequest(this); |
| 36 } | 42 } |
| 37 | 43 |
| 38 ScriptPromise MIDIAccessInitializer::start() | 44 ScriptPromise MIDIAccessInitializer::start() |
| 39 { | 45 { |
| 40 ScriptPromise promise = this->promise(); | 46 ScriptPromise promise = this->promise(); |
| 41 m_accessor = MIDIAccessor::create(this); | 47 m_accessor = MIDIAccessor::create(this); |
| 42 | 48 |
| 43 if (!m_requestSysex) { | 49 if (!m_requestSysex) { |
| 44 m_accessor->startSession(); | 50 m_accessor->startSession(); |
| 45 return promise; | 51 return promise; |
| 46 } | 52 } |
| 47 Document* document = toDocument(executionContext()); | 53 Document* document = toDocument(executionContext()); |
| 48 ASSERT(document); | 54 ASSERT(document); |
| 49 MIDIController* controller = MIDIController::from(document->frame()); | 55 if (MIDIController* controller = MIDIController::from(document->frame())) |
| 50 if (controller) { | |
| 51 controller->requestSysexPermission(this); | 56 controller->requestSysexPermission(this); |
| 52 } else { | 57 else |
| 53 reject(DOMError::create("SecurityError")); | 58 reject(DOMError::create("SecurityError")); |
| 54 } | 59 |
| 55 return promise; | 60 return promise; |
| 56 } | 61 } |
| 57 | 62 |
| 58 void MIDIAccessInitializer::didAddInputPort(const String& id, const String& manu
facturer, const String& name, const String& version, bool isActive) | 63 void MIDIAccessInitializer::didAddInputPort(const String& id, const String& manu
facturer, const String& name, const String& version, bool isActive) |
| 59 { | 64 { |
| 60 ASSERT(m_accessor); | 65 ASSERT(m_accessor); |
| 61 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI
DIPortTypeInput, version, isActive)); | 66 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI
DIPortTypeInput, version, isActive)); |
| 62 } | 67 } |
| 63 | 68 |
| 64 void MIDIAccessInitializer::didAddOutputPort(const String& id, const String& man
ufacturer, const String& name, const String& version, bool isActive) | 69 void MIDIAccessInitializer::didAddOutputPort(const String& id, const String& man
ufacturer, const String& name, const String& version, bool isActive) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 { | 108 { |
| 104 return executionContext()->securityOrigin(); | 109 return executionContext()->securityOrigin(); |
| 105 } | 110 } |
| 106 | 111 |
| 107 ExecutionContext* MIDIAccessInitializer::executionContext() const | 112 ExecutionContext* MIDIAccessInitializer::executionContext() const |
| 108 { | 113 { |
| 109 return scriptState()->executionContext(); | 114 return scriptState()->executionContext(); |
| 110 } | 115 } |
| 111 | 116 |
| 112 } // namespace blink | 117 } // namespace blink |
| OLD | NEW |