[Extensions] Allow silent push without notification permission.
Before this change, extensions with service workers could subscribe to
a push server without the user seeing a default notification when a
message is received (see crrev.com/c/4705862) if they passed
`userVisibleOnly: false`.
However, this didn't bypass the notification permission requirement for
subscribing or receiving messages.
After this change, such extensions can fully use the Push API without
the notification permission. This allows them to "silently" (without
requiring a notification) receive push messages without escalating their
permissions.
The requirement for the notification permission is still enforced if an
extension attempts to show a notification while using the Push API.This
is enforced in
`NotificationPermissionContext::GetPermissionStatusInternal()`.
Fixed: 41492640
Change-Id: Idf544ddc22ae38885eb6f5d39364d9660d06cc98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5980884
Auto-Submit: Justin Lulejian <[email protected]>
Reviewed-by: Michael van Ouwerkerk <[email protected]>
Commit-Queue: Michael van Ouwerkerk <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1377556}
diff --git a/chrome/browser/push_messaging/push_messaging_notification_manager.h b/chrome/browser/push_messaging/push_messaging_notification_manager.h
index bbcf9557..e87b6cc 100644
--- a/chrome/browser/push_messaging/push_messaging_notification_manager.h
+++ b/chrome/browser/push_messaging/push_messaging_notification_manager.h
@@ -69,11 +69,19 @@
EnforceRequirementsCallback message_handled_callback,
bool requested_user_visible_only);
- // Checks if userVisibleOnly can be skipped in certain scenarios. Currently
- // that is only allowed for extensions that set userVisibleOnly as false on
- // subscription.
- bool ShouldSkipUserVisibleOnlyRequirements(const GURL& origin,
- bool requested_user_visible_only);
+ // Checks if the userVisibleOnly: true requirement or the notifications
+ // permission requirement can be bypassed in certain scenarios.
+ //
+ // Currently that is only allowed for extensions with workers that set
+ // userVisibleOnly: false on subscription.
+ bool ShouldBypassUserVisibleOnlyRequirement(const GURL& origin,
+ bool requested_user_visible_only);
+ bool ShouldBypassNotificationPermissionRequirement(
+ const GURL& origin,
+ bool requested_user_visible_only) {
+ return ShouldBypassUserVisibleOnlyRequirement(origin,
+ requested_user_visible_only);
+ }
private:
FRIEND_TEST_ALL_PREFIXES(PushMessagingNotificationManagerTest, IsTabVisible);
@@ -109,7 +117,7 @@
#if BUILDFLAG(ENABLE_EXTENSIONS)
// For extensions builds, skip userVisibleOnly requirement for worker-based
// extensions that set it to false.
- bool ShouldSkipExtensionUserVisibleOnlyRequirements(
+ bool ShouldExtensionsBypassUserVisibleOnlyRequirement(
const GURL& origin,
bool requested_user_visible_only);
#endif // BUILDFLAG(ENABLE_EXTENSIONS)