| 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/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/frame/Navigator.h" | 13 #include "core/frame/Navigator.h" |
| 14 #include "modules/webmidi/MIDIAccess.h" | 14 #include "modules/webmidi/MIDIAccess.h" |
| 15 #include "modules/webmidi/MIDIController.h" | 15 #include "modules/webmidi/MIDIController.h" |
| 16 #include "modules/webmidi/MIDIOptions.h" | 16 #include "modules/webmidi/MIDIOptions.h" |
| 17 #include "modules/webmidi/MIDIPort.h" | 17 #include "modules/webmidi/MIDIPort.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 using PortState = WebMIDIAccessorClient::MIDIPortState; | 21 using PortState = WebMIDIAccessorClient::MIDIPortState; |
| 22 | 22 |
| 23 MIDIAccessInitializer::MIDIAccessInitializer(ScriptState* scriptState, const MID
IOptions& options) | 23 MIDIAccessInitializer::MIDIAccessInitializer(ScriptState* scriptState, const MID
IOptions& options) |
| 24 : ScriptPromiseResolver(scriptState) | 24 : ScriptPromiseResolver(scriptState) |
| 25 , m_requestSysex(false) | 25 , m_requestSysex(false) |
| 26 , m_hasBeenDisposed(false) | 26 , m_hasBeenDisposed(false) |
| 27 , m_sysexPermissionResolved(false) | 27 , m_sysexPermissionResolved(false) |
| 28 { | 28 { |
| 29 #if ENABLE(OILPAN) | |
| 30 #if ENABLE(ASSERT) | |
| 31 // A prefinalizer has already been registered for ScriptPromiseResolver; | |
| 32 // remove it and register a combined one as the infrastructure doesn't | |
| 33 // support multiple prefinalizers for an object. | |
| 34 ThreadState::current()->unregisterPreFinalizer(*static_cast<ScriptPromiseRes
olver*>(this)); | |
| 35 #endif | |
| 36 ThreadState::current()->registerPreFinalizer(*this); | |
| 37 #endif | |
| 38 if (options.hasSysex()) | 29 if (options.hasSysex()) |
| 39 m_requestSysex = options.sysex(); | 30 m_requestSysex = options.sysex(); |
| 40 } | 31 } |
| 41 | 32 |
| 42 MIDIAccessInitializer::~MIDIAccessInitializer() | 33 MIDIAccessInitializer::~MIDIAccessInitializer() |
| 43 { | 34 { |
| 44 #if !ENABLE(OILPAN) | |
| 45 dispose(); | 35 dispose(); |
| 46 #endif | |
| 47 } | 36 } |
| 48 | 37 |
| 49 void MIDIAccessInitializer::contextDestroyed() | 38 void MIDIAccessInitializer::contextDestroyed() |
| 50 { | 39 { |
| 51 dispose(); | 40 dispose(); |
| 52 LifecycleObserver::contextDestroyed(); | 41 LifecycleObserver::contextDestroyed(); |
| 53 } | 42 } |
| 54 | 43 |
| 55 void MIDIAccessInitializer::dispose() | 44 void MIDIAccessInitializer::dispose() |
| 56 { | 45 { |
| 57 if (m_hasBeenDisposed) | 46 if (m_hasBeenDisposed) |
| 58 return; | 47 return; |
| 59 | 48 |
| 60 if (!executionContext()) | 49 if (!executionContext()) |
| 61 return; | 50 return; |
| 62 | 51 |
| 63 if (!m_sysexPermissionResolved) { | 52 if (!m_sysexPermissionResolved) { |
| 64 Document* document = toDocument(executionContext()); | 53 Document* document = toDocument(executionContext()); |
| 65 ASSERT(document); | 54 ASSERT(document); |
| 66 if (MIDIController* controller = MIDIController::from(document->frame())
) | 55 if (MIDIController* controller = MIDIController::from(document->frame())
) |
| 67 controller->cancelSysexPermissionRequest(this); | 56 controller->cancelSysexPermissionRequest(this); |
| 68 m_sysexPermissionResolved = true; | 57 m_sysexPermissionResolved = true; |
| 69 } | 58 } |
| 70 | 59 |
| 71 m_hasBeenDisposed = true; | 60 m_hasBeenDisposed = true; |
| 72 #if ENABLE(OILPAN) && ENABLE(ASSERT) | |
| 73 ScriptPromiseResolver::dispose(); | |
| 74 #endif | |
| 75 } | 61 } |
| 76 | 62 |
| 77 ScriptPromise MIDIAccessInitializer::start() | 63 ScriptPromise MIDIAccessInitializer::start() |
| 78 { | 64 { |
| 79 ScriptPromise promise = this->promise(); | 65 ScriptPromise promise = this->promise(); |
| 80 m_accessor = MIDIAccessor::create(this); | 66 m_accessor = MIDIAccessor::create(this); |
| 81 | 67 |
| 82 if (!m_requestSysex) { | 68 if (!m_requestSysex) { |
| 83 m_accessor->startSession(); | 69 m_accessor->startSession(); |
| 84 return promise; | 70 return promise; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 { | 145 { |
| 160 return executionContext()->securityOrigin(); | 146 return executionContext()->securityOrigin(); |
| 161 } | 147 } |
| 162 | 148 |
| 163 ExecutionContext* MIDIAccessInitializer::executionContext() const | 149 ExecutionContext* MIDIAccessInitializer::executionContext() const |
| 164 { | 150 { |
| 165 return scriptState()->executionContext(); | 151 return scriptState()->executionContext(); |
| 166 } | 152 } |
| 167 | 153 |
| 168 } // namespace blink | 154 } // namespace blink |
| OLD | NEW |