Index: chrome/browser/notifications/notification_common.cc |
diff --git a/chrome/browser/notifications/notification_common.cc b/chrome/browser/notifications/notification_common.cc |
index 3320f6af8eb14996d7f69bf38bc66bad5a8caa5e..2e87b6780deda3a7dfb1094f94325eec8b4929dd 100644 |
--- a/chrome/browser/notifications/notification_common.cc |
+++ b/chrome/browser/notifications/notification_common.cc |
@@ -4,11 +4,25 @@ |
#include "chrome/browser/notifications/notification_common.h" |
+#include "base/metrics/histogram_macros.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/chrome_pages.h" |
+#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
+#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/common/chrome_switches.h" |
#include "content/public/browser/browser_context.h" |
+#include "ui/message_center/notifier_settings.h" |
+ |
+namespace features { |
+ |
+const base::Feature kAllowFullscreenWebNotificationsFeature{ |
+ "FSNotificationsWeb", base::FEATURE_ENABLED_BY_DEFAULT}; |
+} // namespace features |
// static |
void NotificationCommon::OpenNotificationSettings( |
@@ -16,7 +30,8 @@ void NotificationCommon::OpenNotificationSettings( |
#if defined(OS_ANDROID) |
// Android settings are opened directly from Java |
NOTIMPLEMENTED(); |
-#else |
+ return; |
+#endif // defined(OS_ANDROID) |
Profile* profile = Profile::FromBrowserContext(browser_context); |
DCHECK(profile); |
@@ -28,5 +43,49 @@ void NotificationCommon::OpenNotificationSettings( |
chrome::ShowContentSettingsExceptions(browser_displayer.browser(), |
CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
} |
+} |
+ |
+// static |
+bool NotificationCommon::ActiveTabIsFullScreen(Profile* profile, |
+ const GURL& origin) { |
+#if defined(OS_ANDROID) |
+ NOTIMPLEMENTED(); |
+ return false; |
#endif // defined(OS_ANDROID) |
+ |
+ // Check to see if this notification comes from a webpage that is displaying |
+ // fullscreen content. |
+ for (auto* browser : *BrowserList::GetInstance()) { |
+ // Only consider the browsers for the profile that created the notification |
+ if (browser->profile() != profile) |
+ continue; |
+ |
+ const content::WebContents* active_contents = |
+ browser->tab_strip_model()->GetActiveWebContents(); |
+ if (!active_contents) |
+ continue; |
+ |
+ // Check to see if |
+ // (a) the active tab in the browser shares its origin with the |
+ // notification. |
+ // (b) the browser is fullscreen |
+ // (c) the browser has focus. |
+ if (active_contents->GetURL().GetOrigin() == origin && |
+ browser->exclusive_access_manager()->context()->IsFullscreen() && |
+ browser->window()->IsActive()) { |
+ bool enabled = base::FeatureList::IsEnabled( |
+ features::kAllowFullscreenWebNotificationsFeature); |
+ if (enabled) { |
+ UMA_HISTOGRAM_ENUMERATION("Notifications.Display_Fullscreen.Shown", |
+ message_center::NotifierId::WEB_PAGE, |
+ message_center::NotifierId::SIZE); |
+ } else { |
+ UMA_HISTOGRAM_ENUMERATION("Notifications.Display_Fullscreen.Suppressed", |
+ message_center::NotifierId::WEB_PAGE, |
+ message_center::NotifierId::SIZE); |
+ } |
+ return enabled; |
+ } |
+ } |
+ return false; |
} |