| 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" | |
| 8 #include "chrome/browser/profiles/profile.h" | 7 #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" | |
| 12 #include "chrome/browser/ui/chrome_pages.h" | 8 #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" | |
| 15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 9 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 17 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 18 #include "content/public/browser/browser_context.h" | 11 #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 | |
| 27 | 12 |
| 28 // static | 13 // static |
| 29 void NotificationCommon::OpenNotificationSettings( | 14 void NotificationCommon::OpenNotificationSettings( |
| 30 content::BrowserContext* browser_context) { | 15 content::BrowserContext* browser_context) { |
| 31 #if defined(OS_ANDROID) | 16 #if defined(OS_ANDROID) |
| 32 // Android settings are opened directly from Java | 17 // Android settings are opened directly from Java |
| 33 NOTIMPLEMENTED(); | 18 NOTIMPLEMENTED(); |
| 34 #else | 19 #else |
| 35 Profile* profile = Profile::FromBrowserContext(browser_context); | 20 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 36 DCHECK(profile); | 21 DCHECK(profile); |
| 37 | 22 |
| 38 if (switches::SettingsWindowEnabled()) { | 23 if (switches::SettingsWindowEnabled()) { |
| 39 chrome::ShowContentSettingsExceptionsInWindow( | 24 chrome::ShowContentSettingsExceptionsInWindow( |
| 40 profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 25 profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 41 } else { | 26 } else { |
| 42 chrome::ScopedTabbedBrowserDisplayer browser_displayer(profile); | 27 chrome::ScopedTabbedBrowserDisplayer browser_displayer(profile); |
| 43 chrome::ShowContentSettingsExceptions(browser_displayer.browser(), | 28 chrome::ShowContentSettingsExceptions(browser_displayer.browser(), |
| 44 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 29 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 45 } | 30 } |
| 46 #endif // defined(OS_ANDROID) | 31 #endif // defined(OS_ANDROID) |
| 47 } | 32 } |
| 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 |