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 11 matching lines...) Expand all Loading... |
22 #include "content/public/browser/platform_notification_context.h" | 22 #include "content/public/browser/platform_notification_context.h" |
23 #include "content/public/browser/push_messaging_service.h" | 23 #include "content/public/browser/push_messaging_service.h" |
24 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
25 #include "content/public/browser/storage_partition.h" | 25 #include "content/public/browser/storage_partition.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 27 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
28 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
31 | 31 |
32 #if defined(OS_ANDROID) | 32 #if defined(ANDROID_JAVA_UI) |
33 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 33 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
34 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 34 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
35 #else | 35 #else |
36 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
37 #include "chrome/browser/ui/browser_iterator.h" | 37 #include "chrome/browser/ui/browser_iterator.h" |
38 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
39 #endif | 39 #endif |
40 | 40 |
41 using content::BrowserThread; | 41 using content::BrowserThread; |
42 | 42 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 111 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
112 // TODO(johnme): Hiding an existing notification should also count as a useful | 112 // TODO(johnme): Hiding an existing notification should also count as a useful |
113 // user-visible action done in response to a push message - but make sure that | 113 // user-visible action done in response to a push message - but make sure that |
114 // sending two messages in rapid succession which show then hide a | 114 // sending two messages in rapid succession which show then hide a |
115 // notification doesn't count. | 115 // notification doesn't count. |
116 int notification_count = success ? data.size() : 0; | 116 int notification_count = success ? data.size() : 0; |
117 bool notification_shown = notification_count > 0; | 117 bool notification_shown = notification_count > 0; |
118 | 118 |
119 bool notification_needed = true; | 119 bool notification_needed = true; |
120 // Sites with a currently visible tab don't need to show notifications. | 120 // Sites with a currently visible tab don't need to show notifications. |
121 #if defined(OS_ANDROID) | 121 #if defined(ANDROID_JAVA_UI) |
122 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { | 122 for (auto it = TabModelList::begin(); it != TabModelList::end(); ++it) { |
123 Profile* profile = (*it)->GetProfile(); | 123 Profile* profile = (*it)->GetProfile(); |
124 content::WebContents* active_web_contents = | 124 content::WebContents* active_web_contents = |
125 (*it)->GetActiveWebContents(); | 125 (*it)->GetActiveWebContents(); |
126 #else | 126 #else |
127 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 127 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
128 Profile* profile = it->profile(); | 128 Profile* profile = it->profile(); |
129 content::WebContents* active_web_contents = | 129 content::WebContents* active_web_contents = |
130 it->tab_strip_model()->GetActiveWebContents(); | 130 it->tab_strip_model()->GetActiveWebContents(); |
131 #endif | 131 #endif |
(...skipping 13 matching lines...) Expand all Loading... |
145 break; | 145 break; |
146 } | 146 } |
147 | 147 |
148 // Use the visible URL since that's the one the user is aware of (and it | 148 // Use the visible URL since that's the one the user is aware of (and it |
149 // doesn't matter whether the page loaded successfully). | 149 // doesn't matter whether the page loaded successfully). |
150 const GURL& active_url = active_web_contents->GetVisibleURL(); | 150 const GURL& active_url = active_web_contents->GetVisibleURL(); |
151 if (requesting_origin == active_url.GetOrigin()) { | 151 if (requesting_origin == active_url.GetOrigin()) { |
152 notification_needed = false; | 152 notification_needed = false; |
153 break; | 153 break; |
154 } | 154 } |
155 #if defined(OS_ANDROID) | |
156 } | 155 } |
157 #else | |
158 } | |
159 #endif | |
160 | 156 |
161 // If more than one notification is showing for this Service Worker, close | 157 // If more than one notification is showing for this Service Worker, close |
162 // the default notification if it happens to be part of this group. | 158 // the default notification if it happens to be part of this group. |
163 if (notification_count >= 2) { | 159 if (notification_count >= 2) { |
164 for (const auto& notification_database_data : data) { | 160 for (const auto& notification_database_data : data) { |
165 if (notification_database_data.notification_data.tag != | 161 if (notification_database_data.notification_data.tag != |
166 kPushMessagingForcedNotificationTag) | 162 kPushMessagingForcedNotificationTag) |
167 continue; | 163 continue; |
168 | 164 |
169 PlatformNotificationServiceImpl* platform_notification_service = | 165 PlatformNotificationServiceImpl* platform_notification_service = |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 return; | 324 return; |
329 } | 325 } |
330 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( | 326 PlatformNotificationServiceImpl::GetInstance()->DisplayPersistentNotification( |
331 profile_, | 327 profile_, |
332 persistent_notification_id, | 328 persistent_notification_id, |
333 requesting_origin, | 329 requesting_origin, |
334 SkBitmap() /* icon */, | 330 SkBitmap() /* icon */, |
335 notification_data); | 331 notification_data); |
336 message_handled_closure.Run(); | 332 message_handled_closure.Run(); |
337 } | 333 } |
OLD | NEW |