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:53:34 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
2018-09-18 12:36:38 +03:00
|
|
|
|
|
|
|
class WorkletImpl;
|
|
|
|
|
2016-11-06 11:53:34 +03:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Promise;
|
2016-11-06 11:55:20 +03:00
|
|
|
class WorkletFetchHandler;
|
2018-07-10 15:24:14 +03:00
|
|
|
struct WorkletOptions;
|
2017-02-01 23:43:37 +03:00
|
|
|
enum class CallerType : uint32_t;
|
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)
|
|
|
|
|
2019-01-31 10:16:31 +03:00
|
|
|
// |aOwnedObject| may be provided by the WorkletImpl as a parent thread
|
|
|
|
// object to keep alive and traverse for CC as long as the Worklet has
|
|
|
|
// references remaining.
|
|
|
|
Worklet(nsPIDOMWindowInner* aWindow, RefPtr<WorkletImpl> aImpl,
|
|
|
|
nsISupports* aOwnedObject = nullptr);
|
2016-11-06 11:53:34 +03:00
|
|
|
|
2016-11-06 11:54:52 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const { return mWindow; }
|
2016-11-06 11:53:34 +03:00
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
2018-07-10 15:24:14 +03:00
|
|
|
already_AddRefed<Promise> AddModule(const nsAString& aModuleURL,
|
|
|
|
const WorkletOptions& aOptions,
|
|
|
|
CallerType aCallerType, ErrorResult& aRv);
|
2016-11-06 11:53:34 +03:00
|
|
|
|
2019-03-29 19:12:08 +03:00
|
|
|
WorkletImpl* Impl() const { return mImpl; }
|
|
|
|
|
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;
|
2019-01-31 10:16:31 +03:00
|
|
|
nsCOMPtr<nsISupports> mOwnedObject;
|
2016-11-06 11:54:29 +03:00
|
|
|
|
2016-11-06 11:55:20 +03:00
|
|
|
nsRefPtrHashtable<nsCStringHashKey, WorkletFetchHandler> mImportHandlers;
|
|
|
|
|
2018-09-18 12:36:38 +03:00
|
|
|
const RefPtr<WorkletImpl> mImpl;
|
2018-04-12 07:21:20 +03:00
|
|
|
|
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
|