Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: chrome/browser/notifications/notification_common.cc

Issue 2921263002: Remove many delegates, let's see what breaks
Patch Set: compile Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 } // namespace features
12 26
13 // static 27 // static
14 void NotificationCommon::OpenNotificationSettings( 28 void NotificationCommon::OpenNotificationSettings(
15 content::BrowserContext* browser_context) { 29 content::BrowserContext* browser_context) {
16 #if defined(OS_ANDROID) 30 #if defined(OS_ANDROID)
17 // Android settings are opened directly from Java 31 // Android settings are opened directly from Java
18 NOTIMPLEMENTED(); 32 NOTIMPLEMENTED();
19 #else 33 return;
34 #endif // defined(OS_ANDROID)
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 }
46 }
47
48 // static
49 bool NotificationCommon::ActiveTabIsFullScreen(Profile* profile,
50 const GURL& origin) {
51 #if defined(OS_ANDROID)
52 NOTIMPLEMENTED();
53 return false;
31 #endif // defined(OS_ANDROID) 54 #endif // defined(OS_ANDROID)
55
56 // Check to see if this notification comes from a webpage that is displaying
57 // fullscreen content.
58 for (auto* browser : *BrowserList::GetInstance()) {
59 // Only consider the browsers for the profile that created the notification
60 if (browser->profile() != profile)
61 continue;
62
63 const content::WebContents* active_contents =
64 browser->tab_strip_model()->GetActiveWebContents();
65 if (!active_contents)
66 continue;
67
68 // Check to see if
69 // (a) the active tab in the browser shares its origin with the
70 // notification.
71 // (b) the browser is fullscreen
72 // (c) the browser has focus.
73 if (active_contents->GetURL().GetOrigin() == origin &&
74 browser->exclusive_access_manager()->context()->IsFullscreen() &&
75 browser->window()->IsActive()) {
76 bool enabled = base::FeatureList::IsEnabled(
77 features::kAllowFullscreenWebNotificationsFeature);
78 if (enabled) {
79 UMA_HISTOGRAM_ENUMERATION("Notifications.Display_Fullscreen.Shown",
80 message_center::NotifierId::WEB_PAGE,
81 message_center::NotifierId::SIZE);
82 } else {
83 UMA_HISTOGRAM_ENUMERATION("Notifications.Display_Fullscreen.Suppressed",
84 message_center::NotifierId::WEB_PAGE,
85 message_center::NotifierId::SIZE);
86 }
87 return enabled;
88 }
89 }
90 return false;
32 } 91 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_common.h ('k') | chrome/browser/notifications/notification_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698