Bug 1843046: Do not allow notifications in private window.r=saschanaz

Differential Revision: https://phabricator.services.mozilla.com/D184064
This commit is contained in:
hsingh 2023-08-15 20:48:13 +00:00
Родитель c023063eaa
Коммит 058e2f8b2a
1 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -477,6 +477,9 @@ NotificationPermissionRequest::Run() {
bool blocked = false;
if (isSystem) {
mPermission = NotificationPermission::Granted;
} else if (mPrincipal->GetPrivateBrowsingId() != 0) {
mPermission = NotificationPermission::Denied;
blocked = true;
} else {
// File are automatically granted permission.
@ -1452,7 +1455,12 @@ already_AddRefed<Promise> Notification::RequestPermission(
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
if (!principal) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(window->AsGlobal(), aRv);
if (aRv.Failed()) {
@ -1506,6 +1514,14 @@ NotificationPermission Notification::GetPermissionInternal(
}
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
if (!principal) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return NotificationPermission::Denied;
}
if (principal->GetPrivateBrowsingId() != 0) {
return NotificationPermission::Denied;
}
// Disallow showing notification if our origin is not the same origin as the
// toplevel one, see https://github.com/whatwg/notifications/issues/177.
if (!StaticPrefs::dom_webnotifications_allowcrossoriginiframe()) {