Index: chrome/browser/services/gcm/push_messaging_service_impl.cc |
diff --git a/chrome/browser/services/gcm/push_messaging_service_impl.cc b/chrome/browser/services/gcm/push_messaging_service_impl.cc |
index 401bddea9a9c905027c7ec1a75049c9825e5a3a0..fb3400a758a2b017a514df0b4dad5cce83cd3f92 100644 |
--- a/chrome/browser/services/gcm/push_messaging_service_impl.cc |
+++ b/chrome/browser/services/gcm/push_messaging_service_impl.cc |
@@ -32,9 +32,19 @@ |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/child_process_host.h" |
#include "content/public/common/platform_notification_data.h" |
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
#include "ui/base/l10n/l10n_util.h" |
+#if defined(OS_ANDROID) |
+#include "chrome/browser/ui/android/tab_model/tab_model.h" |
+#include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
+#else |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_iterator.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
+#endif |
+ |
namespace gcm { |
namespace { |
@@ -231,6 +241,42 @@ void PushMessagingServiceImpl::RequireUserVisibleUX( |
if (notification_count > 0) |
return; |
+ // Sites with a currently visible tab don't need to show notifications. |
+#if defined(OS_ANDROID) |
+ for (TabModel* tab_model : TabModelList) { |
+ Profile* profile = tab_model->GetProfile(); |
+ content::WebContents* active_web_contents = |
+ tab_model->GetActiveWebContents(); |
+#else |
+ for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
+ Profile* profile = it->profile(); |
+ content::WebContents* active_web_contents = |
+ it->tab_strip_model()->GetActiveWebContents(); |
+#endif |
+ |
+ // Don't leak information from other profiles. |
+ if (!profile || profile->IsOffTheRecord() || |
+ !profile->IsSameProfile(profile_)) |
+ continue; |
+ |
+ // Ignore minimized windows etc. |
+ if (!active_web_contents || !IsWebContentsUserVisible(active_web_contents)) |
+ continue; |
+ |
+ // Allow https://foo.example.com Service Worker to not show notification if |
+ // an https://bar.example.com tab is visible (and hence might conceivably |
+ // be showing UI in response to the push message); but http:// doesn't count |
+ // as even with navigator.connect the Service Worker can't talk to it. |
Michael van Ouwerkerk
2015/01/21 19:13:22
Comment seems long.
johnme
2015/01/21 19:32:19
What I'm doing here is a bit unusual: I'm requirin
|
+ if (application_id.origin.scheme() != |
+ active_web_contents->GetVisibleURL().scheme()) |
+ continue; |
+ if (net::registry_controlled_domains::SameDomainOrHost( |
+ application_id.origin, |
+ active_web_contents->GetVisibleURL(), |
Michael van Ouwerkerk
2015/01/21 19:13:22
Please document why GetLastCommittedUrl is the wro
johnme
2015/01/21 19:32:19
Done.
|
+ net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) |
+ return; |
+ } |
+ |
// If we haven't returned yet, the site failed to show a notification, so we |
// will show a generic notification. See https://crbug.com/437277 |
// TODO(johnme): The generic notification should probably automatically close |