OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" | 5 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" |
6 | 6 |
7 #include <bitset> | 7 #include <bitset> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 if (requesting_origin == active_url.GetOrigin()) { | 146 if (requesting_origin == active_url.GetOrigin()) { |
147 notification_needed = false; | 147 notification_needed = false; |
148 break; | 148 break; |
149 } | 149 } |
150 #if defined(OS_ANDROID) | 150 #if defined(OS_ANDROID) |
151 } | 151 } |
152 #else | 152 #else |
153 } | 153 } |
154 #endif | 154 #endif |
155 | 155 |
156 // If more than two notifications are showing for this Service Worker, close | 156 // If more than one notification is showing for this Service Worker, close |
157 // the default notification if it happens to be part of this group. | 157 // the default notification if it happens to be part of this group. |
158 if (notification_count >= 2) { | 158 if (notification_count >= 2) { |
159 for (const auto& notification_database_data : data) { | 159 for (const auto& notification_database_data : data) { |
160 if (notification_database_data.notification_data.tag != | 160 if (notification_database_data.notification_data.tag != |
161 kPushMessagingForcedNotificationTag) | 161 kPushMessagingForcedNotificationTag) |
162 continue; | 162 continue; |
163 | 163 |
164 PlatformNotificationServiceImpl* platform_notification_service = | 164 PlatformNotificationServiceImpl* platform_notification_service = |
165 PlatformNotificationServiceImpl::GetInstance(); | 165 PlatformNotificationServiceImpl::GetInstance(); |
166 | 166 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 content:: | 251 content:: |
252 PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); | 252 PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); |
253 rappor::SampleDomainAndRegistryFromGURL( | 253 rappor::SampleDomainAndRegistryFromGURL( |
254 g_browser_process->rappor_service(), | 254 g_browser_process->rappor_service(), |
255 "PushMessaging.GenericNotificationShown.Origin", | 255 "PushMessaging.GenericNotificationShown.Origin", |
256 requesting_origin); | 256 requesting_origin); |
257 | 257 |
258 // The site failed to show a notification when one was needed, and they have | 258 // The site failed to show a notification when one was needed, and they have |
259 // already failed once in the previous 10 push messages, so we will show a | 259 // already failed once in the previous 10 push messages, so we will show a |
260 // generic notification. See https://crbug.com/437277. | 260 // generic notification. See https://crbug.com/437277. |
261 // | |
262 // TODO(johnme): The generic notification should probably automatically close | |
263 // itself when the next push message arrives? | |
264 content::PlatformNotificationData notification_data; | 261 content::PlatformNotificationData notification_data; |
265 notification_data.title = | 262 notification_data.title = |
266 url_formatter::FormatUrlForSecurityDisplayOmitScheme( | 263 url_formatter::FormatUrlForSecurityDisplayOmitScheme( |
267 requesting_origin, | 264 requesting_origin, |
268 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 265 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
269 notification_data.direction = | 266 notification_data.direction = |
270 content::PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT; | 267 content::PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT; |
271 notification_data.body = | 268 notification_data.body = |
272 l10n_util::GetStringUTF16(IDS_PUSH_MESSAGING_GENERIC_NOTIFICATION_BODY); | 269 l10n_util::GetStringUTF16(IDS_PUSH_MESSAGING_GENERIC_NOTIFICATION_BODY); |
273 notification_data.tag = kPushMessagingForcedNotificationTag; | 270 notification_data.tag = kPushMessagingForcedNotificationTag; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 return; | 323 return; |
327 } | 324 } |
328 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 325 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
329 profile_, | 326 profile_, |
330 persistent_notification_id, | 327 persistent_notification_id, |
331 requesting_origin, | 328 requesting_origin, |
332 SkBitmap() /* icon */, | 329 SkBitmap() /* icon */, |
333 notification_data); | 330 notification_data); |
334 message_handled_closure.Run(); | 331 message_handled_closure.Run(); |
335 } | 332 } |
OLD | NEW |