2016-11-06 08:53:34 +00: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"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2016-11-06 08:55:20 +00:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2016-11-06 08:53:34 +00:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2016-11-06 08:54:52 +00:00
|
|
|
class nsPIDOMWindowInner;
|
2016-11-06 08:54:29 +00:00
|
|
|
class nsIPrincipal;
|
2016-11-06 08:53:34 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Promise;
|
2016-11-06 08:54:29 +00:00
|
|
|
class WorkletGlobalScope;
|
2016-11-06 08:55:20 +00:00
|
|
|
class WorkletFetchHandler;
|
2017-02-01 20:43:37 +00:00
|
|
|
enum class CallerType : uint32_t;
|
2016-11-06 08:53:34 +00:00
|
|
|
|
|
|
|
class Worklet final : public nsISupports
|
|
|
|
, public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Worklet)
|
|
|
|
|
2016-12-16 21:21:51 +00:00
|
|
|
enum WorkletType {
|
|
|
|
eAudioWorklet,
|
|
|
|
ePaintWorklet,
|
|
|
|
};
|
|
|
|
|
|
|
|
Worklet(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
|
|
|
|
WorkletType aWorkletType);
|
2016-11-06 08:53:34 +00:00
|
|
|
|
2016-11-06 08:54:52 +00:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const
|
2016-11-06 08:53:34 +00:00
|
|
|
{
|
2016-11-06 08:54:52 +00:00
|
|
|
return mWindow;
|
2016-11-06 08:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2017-02-01 20:43:37 +00:00
|
|
|
Import(const nsAString& aModuleURL, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv);
|
2016-11-06 08:53:34 +00:00
|
|
|
|
2016-11-06 08:54:29 +00:00
|
|
|
WorkletGlobalScope*
|
|
|
|
GetOrCreateGlobalScope(JSContext* aCx);
|
|
|
|
|
2016-11-06 08:53:34 +00:00
|
|
|
private:
|
2016-11-06 08:54:29 +00:00
|
|
|
~Worklet();
|
2016-11-06 08:53:34 +00:00
|
|
|
|
2016-11-06 08:55:20 +00:00
|
|
|
WorkletFetchHandler*
|
|
|
|
GetImportFetchHandler(const nsACString& aURI);
|
|
|
|
|
|
|
|
void
|
|
|
|
AddImportFetchHandler(const nsACString& aURI, WorkletFetchHandler* aHandler);
|
|
|
|
|
2016-11-06 08:54:52 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
2016-11-06 08:54:29 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
|
2016-12-16 21:21:51 +00:00
|
|
|
WorkletType mWorkletType;
|
|
|
|
|
2016-11-06 08:54:29 +00:00
|
|
|
RefPtr<WorkletGlobalScope> mScope;
|
2016-11-06 08:55:20 +00:00
|
|
|
nsRefPtrHashtable<nsCStringHashKey, WorkletFetchHandler> mImportHandlers;
|
|
|
|
|
|
|
|
friend class WorkletFetchHandler;
|
2016-11-06 08:53:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Worklet_h
|