| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/notifications/notification_common.h" | 5 #include "chrome/browser/notifications/notification_common.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/browser/ui/browser_window.h" |
| 8 #include "chrome/browser/ui/chrome_pages.h" | 12 #include "chrome/browser/ui/chrome_pages.h" |
| 13 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
| 14 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
| 9 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 11 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 19 #include "ui/message_center/notifier_settings.h" |
| 20 |
| 21 namespace features { |
| 22 |
| 23 const base::Feature kAllowFullscreenWebNotificationsFeature{ |
| 24 "FSNotificationsWeb", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 25 |
| 26 } // namespace features |
| 12 | 27 |
| 13 // static | 28 // static |
| 14 void NotificationCommon::OpenNotificationSettings( | 29 void NotificationCommon::OpenNotificationSettings( |
| 15 content::BrowserContext* browser_context) { | 30 content::BrowserContext* browser_context) { |
| 16 #if defined(OS_ANDROID) | 31 #if defined(OS_ANDROID) |
| 17 // Android settings are opened directly from Java | 32 // Android settings are opened directly from Java |
| 18 NOTIMPLEMENTED(); | 33 NOTIMPLEMENTED(); |
| 19 #else | 34 #else |
| 20 Profile* profile = Profile::FromBrowserContext(browser_context); | 35 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 21 DCHECK(profile); | 36 DCHECK(profile); |
| 22 | 37 |
| 23 if (switches::SettingsWindowEnabled()) { | 38 if (switches::SettingsWindowEnabled()) { |
| 24 chrome::ShowContentSettingsExceptionsInWindow( | 39 chrome::ShowContentSettingsExceptionsInWindow( |
| 25 profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 40 profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 26 } else { | 41 } else { |
| 27 chrome::ScopedTabbedBrowserDisplayer browser_displayer(profile); | 42 chrome::ScopedTabbedBrowserDisplayer browser_displayer(profile); |
| 28 chrome::ShowContentSettingsExceptions(browser_displayer.browser(), | 43 chrome::ShowContentSettingsExceptions(browser_displayer.browser(), |
| 29 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 44 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 30 } | 45 } |
| 31 #endif // defined(OS_ANDROID) | 46 #endif // defined(OS_ANDROID) |
| 32 } | 47 } |
| 48 |
| 49 // static |
| 50 bool NotificationCommon::ShouldDisplayOnFullScreen(Profile* profile, |
| 51 const GURL& origin) { |
| 52 #if defined(OS_ANDROID) |
| 53 NOTIMPLEMENTED(); |
| 54 return false; |
| 55 #endif // defined(OS_ANDROID) |
| 56 |
| 57 // Check to see if this notification comes from a webpage that is displaying |
| 58 // fullscreen content. |
| 59 for (auto* browser : *BrowserList::GetInstance()) { |
| 60 // Only consider the browsers for the profile that created the notification |
| 61 if (browser->profile() != profile) |
| 62 continue; |
| 63 |
| 64 const content::WebContents* active_contents = |
| 65 browser->tab_strip_model()->GetActiveWebContents(); |
| 66 if (!active_contents) |
| 67 continue; |
| 68 |
| 69 // Check to see if |
| 70 // (a) the active tab in the browser shares its origin with the |
| 71 // notification. |
| 72 // (b) the browser is fullscreen |
| 73 // (c) the browser has focus. |
| 74 if (active_contents->GetURL().GetOrigin() == origin && |
| 75 browser->exclusive_access_manager()->context()->IsFullscreen() && |
| 76 browser->window()->IsActive()) { |
| 77 bool enabled = base::FeatureList::IsEnabled( |
| 78 features::kAllowFullscreenWebNotificationsFeature); |
| 79 if (enabled) { |
| 80 UMA_HISTOGRAM_ENUMERATION("Notifications.Display_Fullscreen.Shown", |
| 81 message_center::NotifierId::WEB_PAGE, |
| 82 message_center::NotifierId::SIZE); |
| 83 } else { |
| 84 UMA_HISTOGRAM_ENUMERATION("Notifications.Display_Fullscreen.Suppressed", |
| 85 message_center::NotifierId::WEB_PAGE, |
| 86 message_center::NotifierId::SIZE); |
| 87 } |
| 88 return enabled; |
| 89 } |
| 90 } |
| 91 return false; |
| 92 } |
| OLD | NEW |