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"
|
|
|
|
#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;
|
2016-11-06 11:54:29 +03:00
|
|
|
class WorkletGlobalScope;
|
2016-11-06 11:55:20 +03:00
|
|
|
class WorkletFetchHandler;
|
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>
|
|
|
|
Import(const nsAString& aModuleURL, ErrorResult& aRv);
|
|
|
|
|
2016-11-06 11:54:29 +03:00
|
|
|
WorkletGlobalScope*
|
|
|
|
GetOrCreateGlobalScope(JSContext* aCx);
|
|
|
|
|
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);
|
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
2016-11-06 11:54:29 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
|
2016-12-17 00:21:51 +03:00
|
|
|
WorkletType mWorkletType;
|
|
|
|
|
2016-11-06 11:54:29 +03:00
|
|
|
RefPtr<WorkletGlobalScope> mScope;
|
2016-11-06 11:55:20 +03:00
|
|
|
nsRefPtrHashtable<nsCStringHashKey, WorkletFetchHandler> mImportHandlers;
|
|
|
|
|
|
|
|
friend class WorkletFetchHandler;
|
2016-11-06 11:53:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Worklet_h
|