2016-11-06 11:53:34 +03:00
|
|
|
/* -*- 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 http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_Worklet_h
|
|
|
|
#define mozilla_dom_Worklet_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2018-04-12 07:21:20 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2016-11-06 11:53:34 +03:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2016-11-06 11:55:20 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2016-11-06 11:53:34 +03:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2016-11-06 11:54:29 +03:00
|
|
|
class nsIPrincipal;
|
2016-11-06 11:53:34 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Promise;
|
2018-04-12 07:21:20 +03:00
|
|
|
class Worklet;
|
2016-11-06 11:55:20 +03:00
|
|
|
class WorkletFetchHandler;
|
2018-04-12 06:14:48 +03:00
|
|
|
class WorkletGlobalScope;
|
|
|
|
class WorkletThread;
|
2017-02-01 23:43:37 +03:00
|
|
|
enum class CallerType : uint32_t;
|
2016-11-06 11:53:34 +03:00
|
|
|
|
2018-04-12 07:21:20 +03:00
|
|
|
class WorkletLoadInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WorkletLoadInfo();
|
|
|
|
~WorkletLoadInfo();
|
|
|
|
|
|
|
|
uint64_t OuterWindowID() const { return mOuterWindowID; }
|
|
|
|
uint64_t InnerWindowID() const { return mInnerWindowID; }
|
|
|
|
bool DumpEnabled() const { return mDumpEnabled; }
|
|
|
|
|
|
|
|
const OriginAttributes& OriginAttributesRef() const
|
|
|
|
{
|
|
|
|
return mOriginAttributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal* Principal() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint64_t mOuterWindowID;
|
|
|
|
uint64_t mInnerWindowID;
|
|
|
|
bool mDumpEnabled;
|
|
|
|
OriginAttributes mOriginAttributes;
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
|
|
|
|
friend class Worklet;
|
|
|
|
friend class WorkletThread;
|
|
|
|
};
|
|
|
|
|
2016-11-06 11:53:34 +03:00
|
|
|
class Worklet final : public nsISupports
|
|
|
|
, public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Worklet)
|
|
|
|
|
2016-12-17 00:21:51 +03:00
|
|
|
enum WorkletType {
|
|
|
|
eAudioWorklet,
|
|
|
|
ePaintWorklet,
|
|
|
|
};
|
|
|
|
|
|
|
|
Worklet(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
|
|
|
|
WorkletType aWorkletType);
|
2016-11-06 11:53:34 +03:00
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const
|
2016-11-06 11:53:34 +03:00
|
|
|
{
|
2016-11-06 11:54:52 +03:00
|
|
|
return mWindow;
|
2016-11-06 11:53:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2017-02-01 23:43:37 +03:00
|
|
|
Import(const nsAString& aModuleURL, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv);
|
2016-11-06 11:53:34 +03:00
|
|
|
|
2018-04-12 06:14:48 +03:00
|
|
|
WorkletType Type() const
|
|
|
|
{
|
|
|
|
return mWorkletType;
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<WorkletGlobalScope>
|
|
|
|
CreateGlobalScope(JSContext* aCx, WorkletType aWorkletType);
|
|
|
|
|
|
|
|
WorkletThread*
|
|
|
|
GetOrCreateThread();
|
2016-11-06 11:54:29 +03:00
|
|
|
|
2018-04-12 07:21:20 +03:00
|
|
|
const WorkletLoadInfo&
|
|
|
|
LoadInfo() const
|
|
|
|
{
|
|
|
|
return mWorkletLoadInfo;
|
|
|
|
}
|
|
|
|
|
2016-11-06 11:53:34 +03:00
|
|
|
private:
|
2016-11-06 11:54:29 +03:00
|
|
|
~Worklet();
|
2016-11-06 11:53:34 +03:00
|
|
|
|
2016-11-06 11:55:20 +03:00
|
|
|
WorkletFetchHandler*
|
|
|
|
GetImportFetchHandler(const nsACString& aURI);
|
|
|
|
|
|
|
|
void
|
|
|
|
AddImportFetchHandler(const nsACString& aURI, WorkletFetchHandler* aHandler);
|
|
|
|
|
2018-04-12 06:14:48 +03:00
|
|
|
void
|
|
|
|
TerminateThread();
|
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
2016-11-06 11:54:29 +03:00
|
|
|
|
2016-12-17 00:21:51 +03:00
|
|
|
WorkletType mWorkletType;
|
|
|
|
|
2016-11-06 11:55:20 +03:00
|
|
|
nsRefPtrHashtable<nsCStringHashKey, WorkletFetchHandler> mImportHandlers;
|
|
|
|
|
2018-04-12 06:14:48 +03:00
|
|
|
RefPtr<WorkletThread> mWorkletThread;
|
|
|
|
|
2018-04-12 07:21:20 +03:00
|
|
|
WorkletLoadInfo mWorkletLoadInfo;
|
|
|
|
|
2016-11-06 11:55:20 +03:00
|
|
|
friend class WorkletFetchHandler;
|
2016-11-06 11:53:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Worklet_h
|