AudioWorkletImpl.h (2074B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 6 7 #ifndef AudioWorkletImpl_h 8 #define AudioWorkletImpl_h 9 10 #include "mozilla/dom/AudioWorkletGlobalScope.h" 11 #include "mozilla/dom/MessagePort.h" 12 #include "mozilla/dom/WorkletImpl.h" 13 14 namespace mozilla { 15 16 class AudioNodeTrack; 17 18 namespace dom { 19 class AudioContext; 20 class AudioWorklet; 21 } // namespace dom 22 23 class AudioWorkletImpl final : public WorkletImpl { 24 public: 25 // Methods for parent thread only: 26 27 static already_AddRefed<dom::AudioWorklet> CreateWorklet( 28 dom::AudioContext* aContext, ErrorResult& aRv); 29 30 JSObject* WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet, 31 JS::Handle<JSObject*> aGivenProto) override; 32 33 nsresult SendControlMessage(already_AddRefed<nsIRunnable> aRunnable) override; 34 35 nsContentPolicyType ContentPolicyType() const override { 36 return nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET; 37 } 38 39 // Execution thread only. 40 dom::AudioWorkletGlobalScope* GetGlobalScope() { 41 return static_cast<dom::AudioWorkletGlobalScope*>( 42 WorkletImpl::GetGlobalScope()); 43 } 44 45 // Any thread: 46 AudioNodeTrack* DestinationTrack() const { return mDestinationTrack; } 47 48 void OnAddModuleStarted() const override; 49 void OnAddModulePromiseSettled() const override; 50 51 protected: 52 // Execution thread only. 53 already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope( 54 JSContext* aCx) override; 55 56 private: 57 AudioWorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, 58 AudioNodeTrack* aDestinationTrack, 59 dom::UniqueMessagePortId&& aPortIdentifier); 60 ~AudioWorkletImpl(); 61 62 const RefPtr<AudioNodeTrack> mDestinationTrack; 63 dom::UniqueMessagePortId mGlobalScopePortIdentifier; 64 }; 65 66 } // namespace mozilla 67 68 #endif // AudioWorkletImpl_h