| 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 , m_hasBeenDisposed(false) |
| 23 { | 24 { |
| 24 #if ENABLE(OILPAN) | 25 #if ENABLE(OILPAN) |
| 25 // A prefinalizer has already been registered (as a LifecycleObserver); | 26 // A prefinalizer has already been registered (as a LifecycleObserver); |
| 26 // remove it and register a combined one, as the infrastructure doesn't | 27 // remove it and register a combined one, as the infrastructure doesn't |
| 27 // support multiple prefinalizers for an object. | 28 // support multiple prefinalizers for an object. |
| 28 // | 29 // |
| 29 // FIXME: Oilpan: remove LifecycleObserver's need for a prefinalizer, | 30 // FIXME: Oilpan: remove LifecycleObserver's need for a prefinalizer, |
| 30 // and as a consequence, this unregistration step. If the former is independ
ently | 31 // and as a consequence, this unregistration step. If the former is independ
ently |
| 31 // removed, the unregisterPreFinalizer() call will assert. | 32 // removed, the unregisterPreFinalizer() call will assert. |
| 32 ThreadState::current()->unregisterPreFinalizer(*static_cast<LifecycleObserve
r*>(this)); | 33 ThreadState::current()->unregisterPreFinalizer(*static_cast<LifecycleObserve
r*>(this)); |
| 33 ThreadState::current()->registerPreFinalizer(*this); | 34 ThreadState::current()->registerPreFinalizer(*this); |
| 34 #endif | 35 #endif |
| 35 if (options.hasSysex()) | 36 if (options.hasSysex()) |
| 36 m_requestSysex = options.sysex(); | 37 m_requestSysex = options.sysex(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 MIDIAccessInitializer::~MIDIAccessInitializer() | 40 MIDIAccessInitializer::~MIDIAccessInitializer() |
| 40 { | 41 { |
| 41 #if !ENABLE(OILPAN) | 42 #if !ENABLE(OILPAN) |
| 42 dispose(); | 43 dispose(); |
| 43 #endif | 44 #endif |
| 44 } | 45 } |
| 45 | 46 |
| 47 void MIDIAccessInitializer::contextDestroyed() |
| 48 { |
| 49 dispose(); |
| 50 } |
| 51 |
| 46 void MIDIAccessInitializer::dispose() | 52 void MIDIAccessInitializer::dispose() |
| 47 { | 53 { |
| 54 if (m_hasBeenDisposed) |
| 55 return; |
| 56 |
| 57 if (!executionContext()) |
| 58 return; |
| 59 |
| 48 // It is safe to cancel a request which is already finished or cancelled. | 60 // It is safe to cancel a request which is already finished or cancelled. |
| 49 Document* document = toDocument(executionContext()); | 61 Document* document = toDocument(executionContext()); |
| 50 ASSERT(document); | 62 ASSERT(document); |
| 51 if (MIDIController* controller = MIDIController::from(document->frame())) | 63 if (MIDIController* controller = MIDIController::from(document->frame())) |
| 52 controller->cancelSysexPermissionRequest(this); | 64 controller->cancelSysexPermissionRequest(this); |
| 53 | 65 |
| 66 m_hasBeenDisposed = true; |
| 67 |
| 54 #if ENABLE(OILPAN) | 68 #if ENABLE(OILPAN) |
| 55 // Delegate to LifecycleObserver's prefinalizer. | 69 // Delegate to LifecycleObserver's prefinalizer. |
| 56 LifecycleObserver::dispose(); | 70 LifecycleObserver::dispose(); |
| 57 #endif | 71 #endif |
| 58 } | 72 } |
| 59 | 73 |
| 60 ScriptPromise MIDIAccessInitializer::start() | 74 ScriptPromise MIDIAccessInitializer::start() |
| 61 { | 75 { |
| 62 ScriptPromise promise = this->promise(); | 76 ScriptPromise promise = this->promise(); |
| 63 m_accessor = MIDIAccessor::create(this); | 77 m_accessor = MIDIAccessor::create(this); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 { | 138 { |
| 125 return executionContext()->securityOrigin(); | 139 return executionContext()->securityOrigin(); |
| 126 } | 140 } |
| 127 | 141 |
| 128 ExecutionContext* MIDIAccessInitializer::executionContext() const | 142 ExecutionContext* MIDIAccessInitializer::executionContext() const |
| 129 { | 143 { |
| 130 return scriptState()->executionContext(); | 144 return scriptState()->executionContext(); |
| 131 } | 145 } |
| 132 | 146 |
| 133 } // namespace blink | 147 } // namespace blink |
| OLD | NEW |