Bug 1492014 add AudioWorkletImpl/PaintWorkletImpl subclasses r=baku

This will be useful for AudioWorklet-specific storage and behavior.

PaintWorkletImpl is in layout/style, because it will be referenced
from CSS.cpp in the same directory.

Depends on D6108

Differential Revision: https://phabricator.services.mozilla.com/D6109

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Karl Tomlinson 2018-09-20 11:34:01 +00:00
Родитель 18b9edd04f
Коммит b4ae5484b7
10 изменённых файлов: 192 добавлений и 66 удалений

Просмотреть файл

@ -102,6 +102,7 @@
#include "mozilla/dom/DocGroup.h"
#include "mozilla/dom/TabGroup.h"
#include "mozilla/StaticPrefs.h"
#include "PaintWorkletImpl.h"
// Interfaces Needed
#include "nsIFrame.h"
@ -241,7 +242,6 @@
#include "mozilla/dom/U2F.h"
#include "mozilla/dom/WebIDLGlobalNameHash.h"
#include "mozilla/dom/Worklet.h"
#include "mozilla/dom/WorkletImpl.h"
#ifdef HAVE_SIDEBAR
#include "mozilla/dom/ExternalBinding.h"
#endif
@ -7820,8 +7820,7 @@ nsGlobalWindowInner::GetPaintWorklet(ErrorResult& aRv)
return nullptr;
}
mPaintWorklet =
WorkletImpl::CreateWorklet(this, principal, WorkletImpl::ePaintWorklet);
mPaintWorklet = PaintWorkletImpl::CreateWorklet(this, principal);
}
return mPaintWorklet;

Просмотреть файл

@ -40,7 +40,6 @@
#include "mozilla/dom/StereoPannerNodeBinding.h"
#include "mozilla/dom/WaveShaperNodeBinding.h"
#include "mozilla/dom/Worklet.h"
#include "mozilla/dom/WorkletImpl.h"
#include "AudioBuffer.h"
#include "AudioBufferSourceNode.h"
@ -49,6 +48,7 @@
#include "AudioListener.h"
#include "AudioNodeStream.h"
#include "AudioStream.h"
#include "AudioWorkletImpl.h"
#include "AutoplayPolicy.h"
#include "BiquadFilterNode.h"
#include "ChannelMergerNode.h"
@ -64,7 +64,6 @@
#include "MediaStreamAudioSourceNode.h"
#include "MediaStreamGraph.h"
#include "nsContentUtils.h"
#include "nsGlobalWindowInner.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsPIDOMWindow.h"
@ -592,20 +591,7 @@ Worklet*
AudioContext::GetAudioWorklet(ErrorResult& aRv)
{
if (!mWorklet) {
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
if (NS_WARN_IF(!window)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsIPrincipal> principal =
nsGlobalWindowInner::Cast(window)->GetPrincipal();
if (NS_WARN_IF(!principal)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
mWorklet =
WorkletImpl::CreateWorklet(window, principal, WorkletImpl::eAudioWorklet);
mWorklet = AudioWorkletImpl::CreateWorklet(this, aRv);
}
return mWorklet;

Просмотреть файл

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "AudioWorkletImpl.h"
#include "AudioContext.h"
#include "mozilla/dom/AudioWorkletBinding.h"
#include "mozilla/dom/AudioWorkletGlobalScope.h"
#include "mozilla/dom/Worklet.h"
#include "mozilla/dom/WorkletThread.h"
#include "nsGlobalWindowInner.h"
namespace mozilla {
/* static */ already_AddRefed<dom::Worklet>
AudioWorkletImpl::CreateWorklet(dom::AudioContext* aContext, ErrorResult& aRv)
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsPIDOMWindowInner> window = aContext->GetOwner();
if (NS_WARN_IF(!window)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsIPrincipal> principal =
nsGlobalWindowInner::Cast(window)->GetPrincipal();
if (NS_WARN_IF(!principal)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<AudioWorkletImpl> impl = new AudioWorkletImpl(window, principal);
return MakeAndAddRef<dom::Worklet>(window, std::move(impl));
}
AudioWorkletImpl::AudioWorkletImpl(nsPIDOMWindowInner* aWindow,
nsIPrincipal* aPrincipal)
: WorkletImpl(aWindow, aPrincipal)
{
}
AudioWorkletImpl::~AudioWorkletImpl() = default;
JSObject*
AudioWorkletImpl::WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet,
JS::Handle<JSObject*> aGivenProto)
{
MOZ_ASSERT(NS_IsMainThread());
return dom::AudioWorklet_Binding::Wrap(aCx, aWorklet, aGivenProto);
}
already_AddRefed<dom::WorkletGlobalScope>
AudioWorkletImpl::ConstructGlobalScope()
{
dom::WorkletThread::AssertIsOnWorkletThread();
return MakeAndAddRef<dom::AudioWorkletGlobalScope>(this);
}
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#ifndef AudioWorkletImpl_h
#define AudioWorkletImpl_h
#include "mozilla/dom/WorkletImpl.h"
namespace mozilla {
namespace dom {
class AudioContext;
}
class AudioWorkletImpl final : public WorkletImpl
{
public:
// Methods for parent thread only:
static already_AddRefed<dom::Worklet>
CreateWorklet(dom::AudioContext* aContext, ErrorResult& aRv);
JSObject*
WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet,
JS::Handle<JSObject*> aGivenProto) override;
protected:
// Execution thread only.
already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() override;
private:
AudioWorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal);
~AudioWorkletImpl();
};
} // namespace mozilla
#endif // AudioWorkletImpl_h

Просмотреть файл

@ -89,6 +89,7 @@ UNIFIED_SOURCES += [
'AudioParamMap.cpp',
'AudioProcessingEvent.cpp',
'AudioScheduledSourceNode.cpp',
'AudioWorkletImpl.cpp',
'AudioWorkletNode.cpp',
'AudioWorkletProcessor.cpp',
'BiquadFilterNode.cpp',

Просмотреть файл

@ -6,13 +6,10 @@
#include "WorkletImpl.h"
#include "AudioWorkletGlobalScope.h"
#include "PaintWorkletGlobalScope.h"
#include "Worklet.h"
#include "WorkletThread.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/dom/AudioWorkletBinding.h"
#include "mozilla/dom/DOMPrefs.h"
#include "mozilla/dom/RegisterWorkletBindings.h"
#include "mozilla/dom/WorkletBinding.h"
@ -45,22 +42,9 @@ WorkletLoadInfo::~WorkletLoadInfo()
// ---------------------------------------------------------------------------
// WorkletImpl
/* static */ already_AddRefed<dom::Worklet>
WorkletImpl::CreateWorklet(nsPIDOMWindowInner* aWindow,
nsIPrincipal* aPrincipal,
WorkletType aWorkletType)
{
MOZ_ASSERT(NS_IsMainThread());
RefPtr<WorkletImpl> impl = new WorkletImpl(aWindow, aPrincipal, aWorkletType);
return MakeAndAddRef<dom::Worklet>(aWindow, std::move(impl));
}
WorkletImpl::WorkletImpl(nsPIDOMWindowInner* aWindow,
nsIPrincipal* aPrincipal,
WorkletType aWorkletType)
nsIPrincipal* aPrincipal)
: mWorkletLoadInfo(aWindow, aPrincipal)
, mWorkletType(aWorkletType)
{
}
@ -71,11 +55,7 @@ WorkletImpl::WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet,
JS::Handle<JSObject*> aGivenProto)
{
MOZ_ASSERT(NS_IsMainThread());
if (mWorkletType == eAudioWorklet) {
return dom::AudioWorklet_Binding::Wrap(aCx, aWorklet, aGivenProto);
} else {
return dom::Worklet_Binding::Wrap(aCx, aWorklet, aGivenProto);
}
return dom::Worklet_Binding::Wrap(aCx, aWorklet, aGivenProto);
}
already_AddRefed<dom::WorkletGlobalScope>
@ -83,16 +63,7 @@ WorkletImpl::CreateGlobalScope(JSContext* aCx)
{
dom::WorkletThread::AssertIsOnWorkletThread();
RefPtr<dom::WorkletGlobalScope> scope;
switch (mWorkletType) {
case eAudioWorklet:
scope = new dom::AudioWorkletGlobalScope(this);
break;
case ePaintWorklet:
scope = new dom::PaintWorkletGlobalScope(this);
break;
}
RefPtr<dom::WorkletGlobalScope> scope = ConstructGlobalScope();
JS::Rooted<JSObject*> global(aCx);
NS_ENSURE_TRUE(scope->WrapGlobalObject(aCx, &global), nullptr);

Просмотреть файл

@ -70,18 +70,9 @@ class WorkletImpl
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WorkletImpl);
enum WorkletType {
eAudioWorklet,
ePaintWorklet,
};
// Methods for parent thread only:
static already_AddRefed<dom::Worklet>
CreateWorklet(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
WorkletType aWorkletType);
JSObject*
virtual JSObject*
WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet,
JS::Handle<JSObject*> aGivenProto);
@ -98,15 +89,15 @@ public:
// Use DispatchRunnable only when the thread is known to already exist.
nsresult DispatchRunnable(already_AddRefed<nsIRunnable> aRunnable);
private:
WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
WorkletType aWorkletType);
~WorkletImpl();
protected:
WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal);
virtual ~WorkletImpl();
virtual already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() = 0;
// The only WorkletLoadInfo member modified is mPrincipal which is accessed
// on only the parent thread.
WorkletLoadInfo mWorkletLoadInfo;
const WorkletType mWorkletType;
// Parent thread only.
RefPtr<dom::WorkletThread> mWorkletThread;

Просмотреть файл

@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "PaintWorkletImpl.h"
#include "mozilla/dom/PaintWorkletGlobalScope.h"
#include "mozilla/dom/Worklet.h"
#include "mozilla/dom/WorkletThread.h"
namespace mozilla {
/* static */ already_AddRefed<dom::Worklet>
PaintWorkletImpl::CreateWorklet(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal)
{
MOZ_ASSERT(NS_IsMainThread());
RefPtr<PaintWorkletImpl> impl = new PaintWorkletImpl(aWindow, aPrincipal);
return MakeAndAddRef<dom::Worklet>(aWindow, std::move(impl));
}
PaintWorkletImpl::PaintWorkletImpl(nsPIDOMWindowInner* aWindow,
nsIPrincipal* aPrincipal)
: WorkletImpl(aWindow, aPrincipal)
{
}
PaintWorkletImpl::~PaintWorkletImpl() = default;
already_AddRefed<dom::WorkletGlobalScope>
PaintWorkletImpl::ConstructGlobalScope()
{
dom::WorkletThread::AssertIsOnWorkletThread();
return MakeAndAddRef<dom::PaintWorkletGlobalScope>(this);
}
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#ifndef PaintWorkletImpl_h
#define PaintWorkletImpl_h
#include "mozilla/dom/WorkletImpl.h"
namespace mozilla {
class PaintWorkletImpl final : public WorkletImpl
{
public:
// Methods for parent thread only:
static already_AddRefed<dom::Worklet>
CreateWorklet(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal);
protected:
// Execution thread only.
already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() override;
private:
PaintWorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal);
~PaintWorkletImpl();
};
} // namespace mozilla
#endif // PaintWorkletImpl_h

Просмотреть файл

@ -202,6 +202,7 @@ UNIFIED_SOURCES += [
'nsStyleTransformMatrix.cpp',
'nsStyleUtil.cpp',
'nsTransitionManager.cpp',
'PaintWorkletImpl.cpp',
'PostTraversalTask.cpp',
'PreloadedStyleSheet.cpp',
'Rule.cpp',