@@ -39,6 +39,9 @@ const char kBadMessageImproperNotificationImage[] =
3939 " disabled." ;
4040const char kBadMessageInvalidNotificationTriggerTimestamp [] =
4141 " Received an invalid notification trigger timestamp." ;
42+ const char kBadMessageInvalidNotificationActionButtons [] =
43+ " Received a notification with a number of action images that does not "
44+ " match the number of actions." ;
4245
4346// Returns the implementation of the PlatformNotificationService. May be NULL.
4447PlatformNotificationService* GetNotificationService (
@@ -132,7 +135,8 @@ void BlinkNotificationServiceImpl::DisplayNonPersistentNotification(
132135 mojo::PendingRemote<blink::mojom::NonPersistentNotificationListener>
133136 event_listener_remote) {
134137 DCHECK_CURRENTLY_ON (BrowserThread::UI);
135- if (!ValidateNotificationResources (notification_resources))
138+ if (!ValidateNotificationDataAndResources (platform_notification_data,
139+ notification_resources))
136140 return ;
137141
138142 if (!GetNotificationService (browser_context_))
@@ -187,28 +191,31 @@ BlinkNotificationServiceImpl::CheckPermissionStatus() {
187191 origin_.GetURL ());
188192}
189193
190- bool BlinkNotificationServiceImpl::ValidateNotificationResources (
194+ bool BlinkNotificationServiceImpl::ValidateNotificationDataAndResources (
195+ const blink::PlatformNotificationData& platform_notification_data,
191196 const blink::NotificationResources& notification_resources) {
192- if (notification_resources.image .drawsNothing () ||
193- base::FeatureList::IsEnabled (features::kNotificationContentImage ))
194- return true ;
195- receiver_.ReportBadMessage (kBadMessageImproperNotificationImage );
196- // The above ReportBadMessage() closes |binding_| but does not trigger its
197- // connection error handler, so we need to call the error handler explicitly
198- // here to do some necessary work.
199- OnConnectionError ();
200- return false ;
201- }
197+ if (platform_notification_data.actions .size () !=
198+ notification_resources.action_icons .size ()) {
199+ receiver_.ReportBadMessage (kBadMessageInvalidNotificationActionButtons );
200+ OnConnectionError ();
201+ return false ;
202+ }
202203
203- // Checks if this notification has a valid trigger.
204- bool BlinkNotificationServiceImpl::ValidateNotificationData (
205- const blink::PlatformNotificationData& notification_data) {
206- if (!CheckNotificationTriggerRange (notification_data)) {
204+ if (!CheckNotificationTriggerRange (platform_notification_data)) {
207205 receiver_.ReportBadMessage (kBadMessageInvalidNotificationTriggerTimestamp );
208206 OnConnectionError ();
209207 return false ;
210208 }
211209
210+ if (!notification_resources.image .drawsNothing () &&
211+ !base::FeatureList::IsEnabled (features::kNotificationContentImage )) {
212+ receiver_.ReportBadMessage (kBadMessageImproperNotificationImage );
213+ // The above ReportBadMessage() closes |binding_| but does not trigger its
214+ // connection error handler, so we need to call the error handler explicitly
215+ // here to do some necessary work.
216+ OnConnectionError ();
217+ return false ;
218+ }
212219 return true ;
213220}
214221
@@ -218,10 +225,8 @@ void BlinkNotificationServiceImpl::DisplayPersistentNotification(
218225 const blink::NotificationResources& notification_resources,
219226 DisplayPersistentNotificationCallback callback) {
220227 DCHECK_CURRENTLY_ON (BrowserThread::UI);
221- if (!ValidateNotificationResources (notification_resources))
222- return ;
223-
224- if (!ValidateNotificationData (platform_notification_data))
228+ if (!ValidateNotificationDataAndResources (platform_notification_data,
229+ notification_resources))
225230 return ;
226231
227232 if (!GetNotificationService (browser_context_)) {
0 commit comments