2018-09-18 12:36:38 +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 https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_worklet_WorkletImpl_h
|
|
|
|
#define mozilla_dom_worklet_WorkletImpl_h
|
|
|
|
|
|
|
|
#include "MainThreadUtils.h"
|
2020-02-06 16:45:47 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2018-09-18 12:36:38 +03:00
|
|
|
#include "mozilla/OriginAttributes.h"
|
2019-09-09 03:41:57 +03:00
|
|
|
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
2018-09-18 12:36:38 +03:00
|
|
|
|
|
|
|
class nsPIDOMWindowInner;
|
|
|
|
class nsIPrincipal;
|
2018-09-18 12:29:15 +03:00
|
|
|
class nsIRunnable;
|
2018-09-18 12:36:38 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Worklet;
|
|
|
|
class WorkletGlobalScope;
|
|
|
|
class WorkletThread;
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
class WorkletLoadInfo {
|
|
|
|
public:
|
2019-09-09 03:42:05 +03:00
|
|
|
explicit WorkletLoadInfo(nsPIDOMWindowInner* aWindow);
|
2018-09-18 12:36:38 +03:00
|
|
|
|
|
|
|
uint64_t OuterWindowID() const { return mOuterWindowID; }
|
|
|
|
uint64_t InnerWindowID() const { return mInnerWindowID; }
|
|
|
|
|
|
|
|
private:
|
2018-09-18 12:34:11 +03:00
|
|
|
// Modified only in constructor.
|
2018-09-18 12:36:38 +03:00
|
|
|
uint64_t mOuterWindowID;
|
2018-09-18 12:34:11 +03:00
|
|
|
const uint64_t mInnerWindowID;
|
2018-09-18 12:36:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WorkletImpl is accessed from both the worklet's parent thread (on which the
|
|
|
|
* Worklet object lives) and the worklet's execution thread. It is owned by
|
2018-09-18 12:33:49 +03:00
|
|
|
* Worklet and WorkletGlobalScope. No parent thread cycle collected objects
|
|
|
|
* are owned indefinitely by WorkletImpl because WorkletImpl is not cycle
|
|
|
|
* collected.
|
2018-09-18 12:36:38 +03:00
|
|
|
*/
|
|
|
|
class WorkletImpl {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WorkletImpl);
|
|
|
|
|
|
|
|
// Methods for parent thread only:
|
|
|
|
|
|
|
|
virtual JSObject* WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet,
|
|
|
|
JS::Handle<JSObject*> aGivenProto);
|
|
|
|
|
2018-12-20 10:58:13 +03:00
|
|
|
virtual nsresult SendControlMessage(already_AddRefed<nsIRunnable> aRunnable);
|
2018-11-29 02:47:01 +03:00
|
|
|
|
2019-09-09 03:42:05 +03:00
|
|
|
nsIPrincipal* Principal() const {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
2018-11-29 02:45:04 +03:00
|
|
|
void NotifyWorkletFinished();
|
2018-09-18 12:36:38 +03:00
|
|
|
|
|
|
|
// Execution thread only.
|
2019-04-01 19:54:58 +03:00
|
|
|
dom::WorkletGlobalScope* GetGlobalScope();
|
2018-09-18 12:36:38 +03:00
|
|
|
|
|
|
|
// Any thread.
|
2018-09-18 12:29:15 +03:00
|
|
|
|
2018-09-18 12:36:38 +03:00
|
|
|
const WorkletLoadInfo& LoadInfo() const { return mWorkletLoadInfo; }
|
2019-09-09 03:42:05 +03:00
|
|
|
const OriginAttributes& OriginAttributesRef() const {
|
2019-09-09 03:41:59 +03:00
|
|
|
return mPrincipalInfo.get_NullPrincipalInfo().attrs();
|
2019-09-09 03:42:05 +03:00
|
|
|
}
|
2019-09-09 03:41:57 +03:00
|
|
|
const ipc::PrincipalInfo& PrincipalInfo() const { return mPrincipalInfo; }
|
2018-09-18 12:36:38 +03:00
|
|
|
|
2020-02-06 16:45:47 +03:00
|
|
|
const Maybe<nsID>& GetAgentClusterId() const { return mAgentClusterId; }
|
|
|
|
|
2020-02-06 16:50:11 +03:00
|
|
|
bool IsSharedMemoryAllowed() const { return mSharedMemoryAllowed; }
|
|
|
|
|
2018-09-20 14:34:01 +03:00
|
|
|
protected:
|
|
|
|
WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal);
|
|
|
|
virtual ~WorkletImpl();
|
|
|
|
|
|
|
|
virtual already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() = 0;
|
2018-09-18 12:36:38 +03:00
|
|
|
|
2019-09-09 03:41:57 +03:00
|
|
|
// Modified only in constructor.
|
|
|
|
ipc::PrincipalInfo mPrincipalInfo;
|
2019-09-09 03:42:05 +03:00
|
|
|
// Accessed on only worklet parent thread.
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
|
|
|
|
const WorkletLoadInfo mWorkletLoadInfo;
|
2018-09-18 12:36:38 +03:00
|
|
|
|
|
|
|
// Parent thread only.
|
|
|
|
RefPtr<dom::WorkletThread> mWorkletThread;
|
2018-11-29 02:47:01 +03:00
|
|
|
bool mTerminated;
|
2019-04-01 19:54:58 +03:00
|
|
|
|
|
|
|
// Execution thread only.
|
|
|
|
RefPtr<dom::WorkletGlobalScope> mGlobalScope;
|
2020-02-06 16:45:47 +03:00
|
|
|
|
|
|
|
Maybe<nsID> mAgentClusterId;
|
2020-02-06 16:50:11 +03:00
|
|
|
|
|
|
|
bool mSharedMemoryAllowed;
|
2018-09-18 12:36:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_worklet_WorkletImpl_h
|