| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 13 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 15 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
| 16 #include "chrome/common/features.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 18 #include "components/rappor/rappor_utils.h" | 19 #include "components/rappor/rappor_utils.h" |
| 19 #include "components/url_formatter/elide_url.h" | 20 #include "components/url_formatter/elide_url.h" |
| 20 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/platform_notification_context.h" | 23 #include "content/public/browser/platform_notification_context.h" |
| 23 #include "content/public/browser/push_messaging_service.h" | 24 #include "content/public/browser/push_messaging_service.h" |
| 24 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 28 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 28 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "url/gurl.h" | 31 #include "url/gurl.h" |
| 31 | 32 |
| 32 #if defined(OS_ANDROID) | 33 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 33 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 34 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 34 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 35 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 35 #else | 36 #else |
| 36 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
| 37 #include "chrome/browser/ui/browser_iterator.h" | 38 #include "chrome/browser/ui/browser_iterator.h" |
| 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 39 #endif | 40 #endif |
| 40 | 41 |
| 41 using content::BrowserThread; | 42 using content::BrowserThread; |
| 42 using content::NotificationDatabaseData; | 43 using content::NotificationDatabaseData; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 138 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 138 // TODO(johnme): Hiding an existing notification should also count as a useful | 139 // TODO(johnme): Hiding an existing notification should also count as a useful |
| 139 // user-visible action done in response to a push message - but make sure that | 140 // user-visible action done in response to a push message - but make sure that |
| 140 // sending two messages in rapid succession which show then hide a | 141 // sending two messages in rapid succession which show then hide a |
| 141 // notification doesn't count. | 142 // notification doesn't count. |
| 142 int notification_count = success ? data.size() : 0; | 143 int notification_count = success ? data.size() : 0; |
| 143 bool notification_shown = notification_count > 0; | 144 bool notification_shown = notification_count > 0; |
| 144 bool notification_needed = true; | 145 bool notification_needed = true; |
| 145 | 146 |
| 146 // Sites with a currently visible tab don't need to show notifications. | 147 // Sites with a currently visible tab don't need to show notifications. |
| 147 #if defined(OS_ANDROID) | 148 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 148 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { | 149 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { |
| 149 Profile* profile = (*it)->GetProfile(); | 150 Profile* profile = (*it)->GetProfile(); |
| 150 WebContents* active_web_contents = (*it)->GetActiveWebContents(); | 151 WebContents* active_web_contents = (*it)->GetActiveWebContents(); |
| 151 #else | 152 #else |
| 152 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 153 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 153 Profile* profile = it->profile(); | 154 Profile* profile = it->profile(); |
| 154 WebContents* active_web_contents = | 155 WebContents* active_web_contents = |
| 155 it->tab_strip_model()->GetActiveWebContents(); | 156 it->tab_strip_model()->GetActiveWebContents(); |
| 156 #endif | 157 #endif |
| 157 if (IsTabVisible(profile, active_web_contents, origin)) { | 158 if (IsTabVisible(profile, active_web_contents, origin)) { |
| 158 notification_needed = false; | 159 notification_needed = false; |
| 159 break; | 160 break; |
| 160 } | 161 } |
| 161 #if defined(OS_ANDROID) | |
| 162 } | 162 } |
| 163 #else | |
| 164 } | |
| 165 #endif | |
| 166 | 163 |
| 167 // If more than one notification is showing for this Service Worker, close | 164 // If more than one notification is showing for this Service Worker, close |
| 168 // the default notification if it happens to be part of this group. | 165 // the default notification if it happens to be part of this group. |
| 169 if (notification_count >= 2) { | 166 if (notification_count >= 2) { |
| 170 for (const auto& notification_database_data : data) { | 167 for (const auto& notification_database_data : data) { |
| 171 if (notification_database_data.notification_data.tag != | 168 if (notification_database_data.notification_data.tag != |
| 172 kPushMessagingForcedNotificationTag) | 169 kPushMessagingForcedNotificationTag) |
| 173 continue; | 170 continue; |
| 174 | 171 |
| 175 PlatformNotificationServiceImpl* platform_notification_service = | 172 PlatformNotificationServiceImpl* platform_notification_service = |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 message_handled_closure.Run(); | 331 message_handled_closure.Run(); |
| 335 return; | 332 return; |
| 336 } | 333 } |
| 337 | 334 |
| 338 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 335 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
| 339 profile_, persistent_notification_id, origin, SkBitmap() /* icon */, | 336 profile_, persistent_notification_id, origin, SkBitmap() /* icon */, |
| 340 notification_data); | 337 notification_data); |
| 341 | 338 |
| 342 message_handled_closure.Run(); | 339 message_handled_closure.Run(); |
| 343 } | 340 } |
| OLD | NEW |