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/budget_service/budget_manager.h" | 14 #include "chrome/browser/budget_service/budget_manager.h" |
15 #include "chrome/browser/budget_service/budget_manager_factory.h" | 15 #include "chrome/browser/budget_service/budget_manager_factory.h" |
16 #include "chrome/browser/engagement/site_engagement_service.h" | 16 #include "chrome/browser/engagement/site_engagement_service.h" |
17 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 17 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 19 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
20 #include "chrome/common/features.h" | |
21 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
22 #include "components/rappor/public/rappor_utils.h" | 21 #include "components/rappor/public/rappor_utils.h" |
23 #include "components/rappor/rappor_service_impl.h" | 22 #include "components/rappor/rappor_service_impl.h" |
24 #include "components/url_formatter/elide_url.h" | 23 #include "components/url_formatter/elide_url.h" |
25 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
26 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/platform_notification_context.h" | 26 #include "content/public/browser/platform_notification_context.h" |
28 #include "content/public/browser/push_messaging_service.h" | 27 #include "content/public/browser/push_messaging_service.h" |
29 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
30 #include "content/public/browser/storage_partition.h" | 29 #include "content/public/browser/storage_partition.h" |
31 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
32 #include "content/public/common/notification_resources.h" | 31 #include "content/public/common/notification_resources.h" |
33 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
34 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 33 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
35 #include "third_party/WebKit/public/platform/modules/budget_service/budget_servi
ce.mojom.h" | 34 #include "third_party/WebKit/public/platform/modules/budget_service/budget_servi
ce.mojom.h" |
36 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
37 #include "url/gurl.h" | 36 #include "url/gurl.h" |
38 | 37 |
39 #if BUILDFLAG(ANDROID_JAVA_UI) | 38 #if defined(OS_ANDROID) |
40 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 39 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
41 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 40 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
42 #else | 41 #else |
43 #include "chrome/browser/ui/browser.h" | 42 #include "chrome/browser/ui/browser.h" |
44 #include "chrome/browser/ui/browser_list.h" | 43 #include "chrome/browser/ui/browser_list.h" |
45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 44 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
46 #endif | 45 #endif |
47 | 46 |
48 using content::BrowserThread; | 47 using content::BrowserThread; |
49 using content::NotificationDatabaseData; | 48 using content::NotificationDatabaseData; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 140 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
142 // TODO(johnme): Hiding an existing notification should also count as a useful | 141 // TODO(johnme): Hiding an existing notification should also count as a useful |
143 // user-visible action done in response to a push message - but make sure that | 142 // user-visible action done in response to a push message - but make sure that |
144 // sending two messages in rapid succession which show then hide a | 143 // sending two messages in rapid succession which show then hide a |
145 // notification doesn't count. | 144 // notification doesn't count. |
146 int notification_count = success ? data.size() : 0; | 145 int notification_count = success ? data.size() : 0; |
147 bool notification_shown = notification_count > 0; | 146 bool notification_shown = notification_count > 0; |
148 bool notification_needed = true; | 147 bool notification_needed = true; |
149 | 148 |
150 // Sites with a currently visible tab don't need to show notifications. | 149 // Sites with a currently visible tab don't need to show notifications. |
151 #if BUILDFLAG(ANDROID_JAVA_UI) | 150 #if defined(OS_ANDROID) |
152 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { | 151 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { |
153 Profile* profile = (*it)->GetProfile(); | 152 Profile* profile = (*it)->GetProfile(); |
154 WebContents* active_web_contents = (*it)->GetActiveWebContents(); | 153 WebContents* active_web_contents = (*it)->GetActiveWebContents(); |
155 #else | 154 #else |
156 for (auto* browser : *BrowserList::GetInstance()) { | 155 for (auto* browser : *BrowserList::GetInstance()) { |
157 Profile* profile = browser->profile(); | 156 Profile* profile = browser->profile(); |
158 WebContents* active_web_contents = | 157 WebContents* active_web_contents = |
159 browser->tab_strip_model()->GetActiveWebContents(); | 158 browser->tab_strip_model()->GetActiveWebContents(); |
160 #endif | 159 #endif |
161 if (IsTabVisible(profile, active_web_contents, origin)) { | 160 if (IsTabVisible(profile, active_web_contents, origin)) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // Do not pass service worker scope. The origin will be used instead of the | 317 // Do not pass service worker scope. The origin will be used instead of the |
319 // service worker scope to determine whether a notification should be | 318 // service worker scope to determine whether a notification should be |
320 // attributed to a WebAPK on Android. This is OK because this code path is hit | 319 // attributed to a WebAPK on Android. This is OK because this code path is hit |
321 // rarely. | 320 // rarely. |
322 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 321 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
323 profile_, notification_id, GURL() /* service_worker_scope */, origin, | 322 profile_, notification_id, GURL() /* service_worker_scope */, origin, |
324 notification_data, NotificationResources()); | 323 notification_data, NotificationResources()); |
325 | 324 |
326 message_handled_closure.Run(); | 325 message_handled_closure.Run(); |
327 } | 326 } |
OLD | NEW |