Bug 1611855 - Worklet must be part of the same parent's agentCluster - part 1, r=padenot

Differential Revision: https://phabricator.services.mozilla.com/D61136

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2020-02-06 13:45:47 +00:00
parent b0457ded54
commit 175bac3a30
11 changed files with 34 additions and 20 deletions

View File

@ -182,6 +182,14 @@ Maybe<ClientInfo> nsIGlobalObject::GetClientInfo() const {
return Maybe<ClientInfo>();
}
Maybe<nsID> nsIGlobalObject::GetAgentClusterId() const {
Maybe<ClientInfo> ci = GetClientInfo();
if (ci.isSome()) {
return ci.value().AgentClusterId();
}
return Nothing();
}
Maybe<ServiceWorkerDescriptor> nsIGlobalObject::GetController() const {
// By default globals do not have a service worker controller. Only real
// window and worker globals can currently be controlled as a client.

View File

@ -144,6 +144,8 @@ class nsIGlobalObject : public nsISupports,
virtual mozilla::Maybe<mozilla::dom::ClientInfo> GetClientInfo() const;
virtual mozilla::Maybe<nsID> GetAgentClusterId() const;
virtual mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> GetController()
const;

View File

@ -353,10 +353,7 @@ void BroadcastChannel::PostMessage(JSContext* aCx,
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
MOZ_ASSERT(global);
if (global) {
Maybe<ClientInfo> clientInfo = global->GetClientInfo();
if (clientInfo) {
agentClusterId = clientInfo->AgentClusterId();
}
agentClusterId = global->GetAgentClusterId();
}
RefPtr<SharedMessageBody> data = new SharedMessageBody(

View File

@ -71,13 +71,10 @@ void SharedMessageBody::Read(JSContext* aCx,
nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
MOZ_ASSERT(global);
Maybe<ClientInfo> clientInfo = global->GetClientInfo();
if (clientInfo) {
Maybe<nsID> agentClusterId = clientInfo->AgentClusterId();
if (agentClusterId.isSome() &&
mAgentClusterId.value().Equals(agentClusterId.value())) {
cloneDataPolicy.allowIntraClusterClonableSharedObjects();
}
Maybe<nsID> agentClusterId = global->GetAgentClusterId();
if (agentClusterId.isSome() &&
mAgentClusterId.value().Equals(agentClusterId.value())) {
cloneDataPolicy.allowIntraClusterClonableSharedObjects();
}
}

View File

@ -33,7 +33,7 @@ NS_IMPL_ADDREF_INHERITED(AudioWorkletGlobalScope, WorkletGlobalScope)
NS_IMPL_RELEASE_INHERITED(AudioWorkletGlobalScope, WorkletGlobalScope)
AudioWorkletGlobalScope::AudioWorkletGlobalScope(AudioWorkletImpl* aImpl)
: mImpl(aImpl) {}
: WorkletGlobalScope(aImpl->GetAgentClusterId()), mImpl(aImpl) {}
bool AudioWorkletGlobalScope::WrapGlobalObject(
JSContext* aCx, JS::MutableHandle<JSObject*> aReflector) {

View File

@ -332,10 +332,7 @@ void MessagePort::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
Maybe<nsID> agentClusterId;
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
if (global) {
Maybe<ClientInfo> clientInfo = global->GetClientInfo();
if (clientInfo) {
agentClusterId = clientInfo->AgentClusterId();
}
agentClusterId = global->GetAgentClusterId();
}
RefPtr<SharedMessageBody> data = new SharedMessageBody(

View File

@ -36,8 +36,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WorkletGlobalScope)
NS_INTERFACE_MAP_ENTRY(WorkletGlobalScope)
NS_INTERFACE_MAP_END
WorkletGlobalScope::WorkletGlobalScope()
: mCreationTimeStamp(TimeStamp::Now()) {}
WorkletGlobalScope::WorkletGlobalScope(const Maybe<nsID>& aAgentClusterId)
: mCreationTimeStamp(TimeStamp::Now()), mAgentClusterId(aAgentClusterId) {}
WorkletGlobalScope::~WorkletGlobalScope() = default;

View File

@ -9,6 +9,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/Maybe.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "nsDOMNavigationTiming.h"
@ -37,7 +38,7 @@ class WorkletGlobalScope : public nsIGlobalObject, public nsWrapperCache {
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WorkletGlobalScope)
WorkletGlobalScope();
explicit WorkletGlobalScope(const Maybe<nsID>& aAgentClusterId);
nsIGlobalObject* GetParentObject() const { return nullptr; }
@ -64,12 +65,15 @@ class WorkletGlobalScope : public nsIGlobalObject, public nsWrapperCache {
return duration.ToMilliseconds();
}
Maybe<nsID> GetAgentClusterId() const override { return mAgentClusterId; }
protected:
~WorkletGlobalScope();
;
private:
TimeStamp mCreationTimeStamp;
Maybe<nsID> mAgentClusterId;
RefPtr<Console> mConsole;
};

View File

@ -40,6 +40,10 @@ WorkletImpl::WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal)
mTerminated(false) {
Unused << NS_WARN_IF(
NS_FAILED(ipc::PrincipalToPrincipalInfo(mPrincipal, &mPrincipalInfo)));
if (aWindow->GetDocGroup()) {
mAgentClusterId.emplace(aWindow->GetDocGroup()->AgentClusterId());
}
}
WorkletImpl::~WorkletImpl() {

View File

@ -8,6 +8,7 @@
#define mozilla_dom_worklet_WorkletImpl_h
#include "MainThreadUtils.h"
#include "mozilla/Maybe.h"
#include "mozilla/OriginAttributes.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
@ -74,6 +75,8 @@ class WorkletImpl {
}
const ipc::PrincipalInfo& PrincipalInfo() const { return mPrincipalInfo; }
const Maybe<nsID>& GetAgentClusterId() const { return mAgentClusterId; }
protected:
WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal);
virtual ~WorkletImpl();
@ -93,6 +96,8 @@ class WorkletImpl {
// Execution thread only.
RefPtr<dom::WorkletGlobalScope> mGlobalScope;
Maybe<nsID> mAgentClusterId;
};
} // namespace mozilla

View File

@ -15,7 +15,7 @@ namespace mozilla {
namespace dom {
PaintWorkletGlobalScope::PaintWorkletGlobalScope(PaintWorkletImpl* aImpl)
: mImpl(aImpl) {}
: WorkletGlobalScope(aImpl->GetAgentClusterId()), mImpl(aImpl) {}
bool PaintWorkletGlobalScope::WrapGlobalObject(
JSContext* aCx, JS::MutableHandle<JSObject*> aReflector) {