OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/services/gcm/push_messaging_service_impl.h" | 5 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
26 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
27 #include "components/content_settings/core/common/permission_request_id.h" | 27 #include "components/content_settings/core/common/permission_request_id.h" |
28 #include "components/gcm_driver/gcm_driver.h" | 28 #include "components/gcm_driver/gcm_driver.h" |
29 #include "components/pref_registry/pref_registry_syncable.h" | 29 #include "components/pref_registry/pref_registry_syncable.h" |
30 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
31 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
33 #include "content/public/common/child_process_host.h" | 33 #include "content/public/common/child_process_host.h" |
34 #include "content/public/common/platform_notification_data.h" | 34 #include "content/public/common/platform_notification_data.h" |
35 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | |
35 #include "third_party/skia/include/core/SkBitmap.h" | 36 #include "third_party/skia/include/core/SkBitmap.h" |
36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
37 | 38 |
39 #if defined(OS_ANDROID) | |
40 #include "chrome/browser/ui/android/tab_model/tab_model.h" | |
41 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | |
42 #else | |
43 #include "chrome/browser/ui/browser.h" | |
44 #include "chrome/browser/ui/browser_iterator.h" | |
45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
46 #endif | |
47 | |
38 namespace gcm { | 48 namespace gcm { |
39 | 49 |
40 namespace { | 50 namespace { |
41 const int kMaxRegistrations = 1000000; | 51 const int kMaxRegistrations = 1000000; |
42 | 52 |
43 blink::WebPushPermissionStatus ToPushPermission(ContentSetting setting) { | 53 blink::WebPushPermissionStatus ToPushPermission(ContentSetting setting) { |
44 switch (setting) { | 54 switch (setting) { |
45 case CONTENT_SETTING_ALLOW: | 55 case CONTENT_SETTING_ALLOW: |
46 return blink::WebPushPermissionStatusGranted; | 56 return blink::WebPushPermissionStatusGranted; |
47 case CONTENT_SETTING_BLOCK: | 57 case CONTENT_SETTING_BLOCK: |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 PlatformNotificationServiceImpl::GetInstance(); | 234 PlatformNotificationServiceImpl::GetInstance(); |
225 // Can't use g_browser_process->notification_ui_manager(), since the test uses | 235 // Can't use g_browser_process->notification_ui_manager(), since the test uses |
226 // PlatformNotificationServiceImpl::SetNotificationUIManagerForTesting. | 236 // PlatformNotificationServiceImpl::SetNotificationUIManagerForTesting. |
227 // TODO(peter): Remove the need to use both APIs here once Notification.get() | 237 // TODO(peter): Remove the need to use both APIs here once Notification.get() |
228 // is supported. | 238 // is supported. |
229 int notification_count = notification_service->GetNotificationUIManager()-> | 239 int notification_count = notification_service->GetNotificationUIManager()-> |
230 GetAllIdsByProfileAndSourceOrigin(profile_, application_id.origin).size(); | 240 GetAllIdsByProfileAndSourceOrigin(profile_, application_id.origin).size(); |
231 if (notification_count > 0) | 241 if (notification_count > 0) |
232 return; | 242 return; |
233 | 243 |
244 // Sites with a currently visible tab don't need to show notifications. | |
245 #if defined(OS_ANDROID) | |
246 for (TabModel* tab_model : TabModelList) { | |
247 Profile* profile = tab_model->GetProfile(); | |
248 content::WebContents* active_web_contents = | |
249 tab_model->GetActiveWebContents(); | |
250 #else | |
251 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
252 Profile* profile = it->profile(); | |
253 content::WebContents* active_web_contents = | |
254 it->tab_strip_model()->GetActiveWebContents(); | |
255 #endif | |
256 | |
257 // Don't leak information from other profiles. | |
258 if (!profile || profile->IsOffTheRecord() || | |
259 !profile->IsSameProfile(profile_)) { | |
260 continue; | |
261 } | |
262 | |
263 // Ignore minimized windows etc. | |
264 if (!active_web_contents || | |
265 active_web_contents->IsHiddenIgnoringCapturing()) | |
266 continue; | |
267 | |
268 // Use the visible URL since that's the one the user is aware of (and it | |
269 // doesn't matter whether the page loaded successfully). | |
270 const GURL& active_url = active_web_contents->GetVisibleURL(); | |
271 | |
272 // Allow https://foo.example.com Service Worker to not show notification if | |
273 // an https://bar.example.com tab is visible (and hence might conceivably | |
274 // be showing UI in response to the push message); but http:// doesn't count | |
275 // as even with navigator.connect the Service Worker can't talk to it. | |
mlamouri (slow - plz ping)
2015/01/26 11:53:35
So that means that if I have one https://<username
| |
276 if (application_id.origin.scheme() != active_url.scheme()) | |
277 continue; | |
278 if (net::registry_controlled_domains::SameDomainOrHost( | |
279 application_id.origin, active_url, | |
280 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) { | |
281 return; | |
282 } | |
283 } | |
284 | |
234 // If we haven't returned yet, the site failed to show a notification, so we | 285 // If we haven't returned yet, the site failed to show a notification, so we |
235 // will show a generic notification. See https://crbug.com/437277 | 286 // will show a generic notification. See https://crbug.com/437277 |
236 // TODO(johnme): The generic notification should probably automatically close | 287 // TODO(johnme): The generic notification should probably automatically close |
237 // itself when the next push message arrives? | 288 // itself when the next push message arrives? |
238 content::PlatformNotificationData notification_data; | 289 content::PlatformNotificationData notification_data; |
239 // TODO(johnme): Switch to FormatOriginForDisplay from crbug.com/402698 | 290 // TODO(johnme): Switch to FormatOriginForDisplay from crbug.com/402698 |
240 notification_data.title = l10n_util::GetStringFUTF16( | 291 notification_data.title = l10n_util::GetStringFUTF16( |
241 IDS_PUSH_MESSAGING_GENERIC_NOTIFICATION_TITLE, | 292 IDS_PUSH_MESSAGING_GENERIC_NOTIFICATION_TITLE, |
242 base::UTF8ToUTF16(application_id.origin.host())); | 293 base::UTF8ToUTF16(application_id.origin.host())); |
243 notification_data.direction = | 294 notification_data.direction = |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { | 543 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { |
493 gcm::PushMessagingPermissionContext* permission_context = | 544 gcm::PushMessagingPermissionContext* permission_context = |
494 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); | 545 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); |
495 DCHECK(permission_context); | 546 DCHECK(permission_context); |
496 | 547 |
497 return permission_context->GetPermissionStatus(origin, origin) == | 548 return permission_context->GetPermissionStatus(origin, origin) == |
498 CONTENT_SETTING_ALLOW; | 549 CONTENT_SETTING_ALLOW; |
499 } | 550 } |
500 | 551 |
501 } // namespace gcm | 552 } // namespace gcm |
OLD | NEW |