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/WorkletImpl.h" 11 #include "mozilla/dom/AudioWorkletGlobalScope.h" 12 13 namespace mozilla { 14 15 class AudioNodeTrack; 16 17 namespace dom { 18 class AudioContext; 19 } 20 21 class AudioWorkletImpl final : public WorkletImpl { 22 public: 23 // Methods for parent thread only: 24 25 static already_AddRefed<dom::Worklet> CreateWorklet( 26 dom::AudioContext* aContext, ErrorResult& aRv); 27 28 JSObject* WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet, 29 JS::Handle<JSObject*> aGivenProto) override; 30 31 nsresult SendControlMessage(already_AddRefed<nsIRunnable> aRunnable) override; 32 ContentPolicyType()33 nsContentPolicyType ContentPolicyType() const override { 34 return nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET; 35 } 36 37 // Execution thread only. GetGlobalScope()38 dom::AudioWorkletGlobalScope* GetGlobalScope() { 39 return static_cast<dom::AudioWorkletGlobalScope*>( 40 WorkletImpl::GetGlobalScope()); 41 } 42 43 // Any thread: DestinationTrack()44 AudioNodeTrack* DestinationTrack() const { return mDestinationTrack; } 45 46 protected: 47 // Execution thread only. 48 already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() override; 49 50 private: 51 AudioWorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal, 52 AudioNodeTrack* aDestinationTrack); 53 ~AudioWorkletImpl(); 54 55 const RefPtr<AudioNodeTrack> mDestinationTrack; 56 }; 57 58 } // namespace mozilla 59 60 #endif // AudioWorkletImpl_h 61