| 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) | 29 #if ENABLE(OILPAN) |
| 30 // A prefinalizer has already been registered (as a LifecycleObserver); | 30 #if ENABLE(ASSERT) |
| 31 // remove it and register a combined one, as the infrastructure doesn't | 31 // A prefinalizer has already been registered for ScriptPromiseResolver; |
| 32 // remove it and register a combined one as the infrastructure doesn't |
| 32 // support multiple prefinalizers for an object. | 33 // support multiple prefinalizers for an object. |
| 33 // | 34 ThreadState::current()->unregisterPreFinalizer(*static_cast<ScriptPromiseRes
olver*>(this)); |
| 34 // FIXME: Oilpan: remove LifecycleObserver's need for a prefinalizer, | 35 #endif |
| 35 // and as a consequence, this unregistration step. If the former is independ
ently | |
| 36 // removed, the unregisterPreFinalizer() call will assert. | |
| 37 ThreadState::current()->unregisterPreFinalizer(*static_cast<LifecycleObserve
r*>(this)); | |
| 38 ThreadState::current()->registerPreFinalizer(*this); | 36 ThreadState::current()->registerPreFinalizer(*this); |
| 39 #endif | 37 #endif |
| 40 if (options.hasSysex()) | 38 if (options.hasSysex()) |
| 41 m_requestSysex = options.sysex(); | 39 m_requestSysex = options.sysex(); |
| 42 } | 40 } |
| 43 | 41 |
| 44 MIDIAccessInitializer::~MIDIAccessInitializer() | 42 MIDIAccessInitializer::~MIDIAccessInitializer() |
| 45 { | 43 { |
| 46 #if !ENABLE(OILPAN) | 44 #if !ENABLE(OILPAN) |
| 47 dispose(); | 45 dispose(); |
| 48 #endif | 46 #endif |
| 49 } | 47 } |
| 50 | 48 |
| 51 void MIDIAccessInitializer::contextDestroyed() | 49 void MIDIAccessInitializer::contextDestroyed() |
| 52 { | 50 { |
| 53 dispose(); | 51 dispose(); |
| 52 LifecycleObserver::contextDestroyed(); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void MIDIAccessInitializer::dispose() | 55 void MIDIAccessInitializer::dispose() |
| 57 { | 56 { |
| 58 if (m_hasBeenDisposed) | 57 if (m_hasBeenDisposed) |
| 59 return; | 58 return; |
| 60 | 59 |
| 61 if (!executionContext()) | 60 if (!executionContext()) |
| 62 return; | 61 return; |
| 63 | 62 |
| 64 if (!m_sysexPermissionResolved) { | 63 if (!m_sysexPermissionResolved) { |
| 65 Document* document = toDocument(executionContext()); | 64 Document* document = toDocument(executionContext()); |
| 66 ASSERT(document); | 65 ASSERT(document); |
| 67 if (MIDIController* controller = MIDIController::from(document->frame())
) | 66 if (MIDIController* controller = MIDIController::from(document->frame())
) |
| 68 controller->cancelSysexPermissionRequest(this); | 67 controller->cancelSysexPermissionRequest(this); |
| 69 m_sysexPermissionResolved = true; | 68 m_sysexPermissionResolved = true; |
| 70 } | 69 } |
| 71 | 70 |
| 72 m_hasBeenDisposed = true; | 71 m_hasBeenDisposed = true; |
| 73 | 72 #if ENABLE(OILPAN) && ENABLE(ASSERT) |
| 74 #if ENABLE(OILPAN) | 73 ScriptPromiseResolver::dispose(); |
| 75 // Delegate to LifecycleObserver's prefinalizer. | |
| 76 LifecycleObserver::dispose(); | |
| 77 #endif | 74 #endif |
| 78 } | 75 } |
| 79 | 76 |
| 80 ScriptPromise MIDIAccessInitializer::start() | 77 ScriptPromise MIDIAccessInitializer::start() |
| 81 { | 78 { |
| 82 ScriptPromise promise = this->promise(); | 79 ScriptPromise promise = this->promise(); |
| 83 m_accessor = MIDIAccessor::create(this); | 80 m_accessor = MIDIAccessor::create(this); |
| 84 | 81 |
| 85 if (!m_requestSysex) { | 82 if (!m_requestSysex) { |
| 86 m_accessor->startSession(); | 83 m_accessor->startSession(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 { | 159 { |
| 163 return executionContext()->securityOrigin(); | 160 return executionContext()->securityOrigin(); |
| 164 } | 161 } |
| 165 | 162 |
| 166 ExecutionContext* MIDIAccessInitializer::executionContext() const | 163 ExecutionContext* MIDIAccessInitializer::executionContext() const |
| 167 { | 164 { |
| 168 return scriptState()->executionContext(); | 165 return scriptState()->executionContext(); |
| 169 } | 166 } |
| 170 | 167 |
| 171 } // namespace blink | 168 } // namespace blink |
| OLD | NEW |