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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <bitset> | 9 #include <bitset> |
10 | 10 |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 14 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 16 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
17 #include "chrome/common/features.h" | 17 #include "chrome/common/features.h" |
18 #include "chrome/common/pref_names.h" | |
19 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
20 #include "components/prefs/pref_service.h" | |
21 #include "components/rappor/rappor_utils.h" | 19 #include "components/rappor/rappor_utils.h" |
22 #include "components/url_formatter/elide_url.h" | 20 #include "components/url_formatter/elide_url.h" |
23 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/platform_notification_context.h" | 23 #include "content/public/browser/platform_notification_context.h" |
26 #include "content/public/browser/push_messaging_service.h" | 24 #include "content/public/browser/push_messaging_service.h" |
27 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
28 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
29 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
30 #include "content/public/common/notification_resources.h" | 28 #include "content/public/common/notification_resources.h" |
(...skipping 27 matching lines...) Expand all Loading... |
58 content::PUSH_USER_VISIBLE_STATUS_LAST + 1); | 56 content::PUSH_USER_VISIBLE_STATUS_LAST + 1); |
59 } | 57 } |
60 | 58 |
61 content::StoragePartition* GetStoragePartition(Profile* profile, | 59 content::StoragePartition* GetStoragePartition(Profile* profile, |
62 const GURL& origin) { | 60 const GURL& origin) { |
63 return content::BrowserContext::GetStoragePartitionForSite(profile, origin); | 61 return content::BrowserContext::GetStoragePartitionForSite(profile, origin); |
64 } | 62 } |
65 | 63 |
66 NotificationDatabaseData CreateDatabaseData( | 64 NotificationDatabaseData CreateDatabaseData( |
67 const GURL& origin, | 65 const GURL& origin, |
68 int64_t service_worker_registration_id, | 66 int64_t service_worker_registration_id) { |
69 const std::string& languages) { | |
70 PlatformNotificationData notification_data; | 67 PlatformNotificationData notification_data; |
71 notification_data.title = | 68 notification_data.title = |
72 url_formatter::FormatUrlForSecurityDisplayOmitScheme(origin, languages); | 69 url_formatter::FormatUrlForSecurityDisplayOmitScheme(origin); |
73 notification_data.direction = | 70 notification_data.direction = |
74 PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT; | 71 PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT; |
75 notification_data.body = | 72 notification_data.body = |
76 l10n_util::GetStringUTF16(IDS_PUSH_MESSAGING_GENERIC_NOTIFICATION_BODY); | 73 l10n_util::GetStringUTF16(IDS_PUSH_MESSAGING_GENERIC_NOTIFICATION_BODY); |
77 notification_data.tag = kPushMessagingForcedNotificationTag; | 74 notification_data.tag = kPushMessagingForcedNotificationTag; |
78 notification_data.icon = GURL(); | 75 notification_data.icon = GURL(); |
79 notification_data.silent = true; | 76 notification_data.silent = true; |
80 | 77 |
81 NotificationDatabaseData database_data; | 78 NotificationDatabaseData database_data; |
82 database_data.origin = origin; | 79 database_data.origin = origin; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 289 } |
293 RecordUserVisibleStatus( | 290 RecordUserVisibleStatus( |
294 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); | 291 content::PUSH_USER_VISIBLE_STATUS_REQUIRED_BUT_NOT_SHOWN_GRACE_EXCEEDED); |
295 rappor::SampleDomainAndRegistryFromGURL( | 292 rappor::SampleDomainAndRegistryFromGURL( |
296 g_browser_process->rappor_service(), | 293 g_browser_process->rappor_service(), |
297 "PushMessaging.GenericNotificationShown.Origin", origin); | 294 "PushMessaging.GenericNotificationShown.Origin", origin); |
298 | 295 |
299 // The site failed to show a notification when one was needed, and they have | 296 // The site failed to show a notification when one was needed, and they have |
300 // already failed once in the previous 10 push messages, so we will show a | 297 // already failed once in the previous 10 push messages, so we will show a |
301 // generic notification. See https://crbug.com/437277. | 298 // generic notification. See https://crbug.com/437277. |
302 NotificationDatabaseData database_data = CreateDatabaseData( | 299 NotificationDatabaseData database_data = |
303 origin, service_worker_registration_id, | 300 CreateDatabaseData(origin, service_worker_registration_id); |
304 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | |
305 scoped_refptr<PlatformNotificationContext> notification_context = | 301 scoped_refptr<PlatformNotificationContext> notification_context = |
306 GetStoragePartition(profile_, origin)->GetPlatformNotificationContext(); | 302 GetStoragePartition(profile_, origin)->GetPlatformNotificationContext(); |
307 BrowserThread::PostTask( | 303 BrowserThread::PostTask( |
308 BrowserThread::IO, FROM_HERE, | 304 BrowserThread::IO, FROM_HERE, |
309 base::Bind(&PlatformNotificationContext::WriteNotificationData, | 305 base::Bind(&PlatformNotificationContext::WriteNotificationData, |
310 notification_context, origin, database_data, | 306 notification_context, origin, database_data, |
311 base::Bind(&PushMessagingNotificationManager:: | 307 base::Bind(&PushMessagingNotificationManager:: |
312 DidWriteNotificationDataIOProxy, | 308 DidWriteNotificationDataIOProxy, |
313 weak_factory_.GetWeakPtr(), origin, | 309 weak_factory_.GetWeakPtr(), origin, |
314 database_data.notification_data, | 310 database_data.notification_data, |
(...skipping 28 matching lines...) Expand all Loading... |
343 message_handled_closure.Run(); | 339 message_handled_closure.Run(); |
344 return; | 340 return; |
345 } | 341 } |
346 | 342 |
347 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 343 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
348 profile_, persistent_notification_id, origin, notification_data, | 344 profile_, persistent_notification_id, origin, notification_data, |
349 NotificationResources()); | 345 NotificationResources()); |
350 | 346 |
351 message_handled_closure.Run(); | 347 message_handled_closure.Run(); |
352 } | 348 } |
OLD | NEW |