Bug 1739779 - Check if the global is eligible for messaging before sending/receiving BroadcastChannel messages, r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D224030
This commit is contained in:
Andrea Marchesini 2024-10-01 06:25:05 +00:00
parent a7281f816e
commit ee1f5ecbde
2 changed files with 11 additions and 18 deletions

View File

@ -271,21 +271,17 @@ already_AddRefed<BroadcastChannel> BroadcastChannel::Constructor(
void BroadcastChannel::PostMessage(JSContext* aCx,
JS::Handle<JS::Value> aMessage,
ErrorResult& aRv) {
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
if (!global || !global->IsEligibleForMessaging()) {
return;
}
if (mState != StateActive) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
Maybe<nsID> agentClusterId;
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
MOZ_ASSERT(global);
if (global) {
agentClusterId = global->GetAgentClusterId();
}
if (!global->IsEligibleForMessaging()) {
return;
}
Maybe<nsID> agentClusterId = global->GetAgentClusterId();
RefPtr<SharedMessageBody> data = new SharedMessageBody(
StructuredCloneHolder::TransferringNotSupported, agentClusterId);
@ -364,6 +360,11 @@ void BroadcastChannel::DisconnectFromOwner() {
}
void BroadcastChannel::MessageReceived(const MessageData& aData) {
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
if (!global || !global->IsEligibleForMessaging()) {
return;
}
if (NS_FAILED(CheckCurrentGlobalCorrectness())) {
RemoveDocFromBFCache();
return;

View File

@ -1,11 +1,3 @@
[detached-iframe.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[BroadcastChannel messages from detached iframe to parent should be ignored (BC created before detaching)]
expected: FAIL
[BroadcastChannel messages within detached iframe should be ignored (BCs created before detaching)]
expected: FAIL
[BroadcastChannel messages within detached iframe should be ignored (BCs created after detaching)]
expected: FAIL