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

Side by Side Diff: chrome/browser/extensions/api/notifications/extension_notification_handler.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/extensions/api/notifications/extension_notification_han dler.h" 5 #include "chrome/browser/extensions/api/notifications/extension_notification_han dler.h"
6 6
7 #include "base/feature_list.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/nullable_string16.h" 10 #include "base/strings/nullable_string16.h"
9 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
10 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper.h" 12 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper.h"
11 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper_factory.h" 13 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper_factory.h"
14 #include "chrome/browser/notifications/notification_common.h"
12 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/extensions/api/notifications.h" 16 #include "chrome/common/extensions/api/notifications.h"
17 #include "chrome/common/features.h"
18 #include "extensions/browser/app_window/app_window.h"
19 #include "extensions/browser/app_window/app_window_registry.h"
20 #include "extensions/browser/app_window/native_app_window.h"
14 #include "extensions/common/constants.h" 21 #include "extensions/common/constants.h"
22 #include "ui/message_center/notifier_settings.h"
15 #include "url/gurl.h" 23 #include "url/gurl.h"
16 24
17 namespace extensions { 25 namespace extensions {
18 26
27 namespace notifications = api::notifications;
28
29 const base::Feature kAllowFullscreenAppNotificationsFeature{
30 "FSNotificationsApp", base::FEATURE_ENABLED_BY_DEFAULT};
31
19 namespace { 32 namespace {
20 33
21 std::string GetExtensionId(const std::string& extension_url) { 34 std::string GetExtensionId(const std::string& extension_url) {
22 GURL url(extension_url); 35 GURL url(extension_url);
23 if (!url.is_valid() || !url.SchemeIs(extensions::kExtensionScheme)) 36 if (!url.is_valid() || !url.SchemeIs(extensions::kExtensionScheme))
24 return ""; 37 return "";
25 return url.GetOrigin().host_piece().as_string(); 38 return url.GetOrigin().host_piece().as_string();
26 } 39 }
27 40
28 std::unique_ptr<base::ListValue> CreateBaseEventArgs( 41 std::unique_ptr<base::ListValue> CreateBaseEventArgs(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 EventRouter* event_router = EventRouter::Get(profile); 125 EventRouter* event_router = EventRouter::Get(profile);
113 if (!event_router) 126 if (!event_router)
114 return; 127 return;
115 128
116 std::unique_ptr<Event> event( 129 std::unique_ptr<Event> event(
117 new Event(histogram_value, event_name, std::move(args))); 130 new Event(histogram_value, event_name, std::move(args)));
118 event->user_gesture = user_gesture; 131 event->user_gesture = user_gesture;
119 event_router->DispatchEventToExtension(extension_id, std::move(event)); 132 event_router->DispatchEventToExtension(extension_id, std::move(event));
120 } 133 }
121 134
135 // Should only display when fullscreen if this app is the source of the
136 // fullscreen window.
137 bool ExtensionNotificationHandler::ShouldDisplayOnFullScreen(
138 Profile* profile,
139 const std::string& origin) const {
140 DCHECK(profile);
141 AppWindowRegistry::AppWindowList windows =
142 AppWindowRegistry::Get(profile)->GetAppWindowsForApp(
143 GetExtensionId(origin));
144 for (auto* window : windows) {
145 // Window must be fullscreen and visible
146 if (window->IsFullscreen() && window->GetBaseWindow()->IsActive()) {
147 bool enabled =
148 base::FeatureList::IsEnabled(kAllowFullscreenAppNotificationsFeature);
149 if (enabled) {
150 UMA_HISTOGRAM_ENUMERATION("Notifications.Display_Fullscreen.Shown",
151 message_center::NotifierId::APPLICATION,
152 message_center::NotifierId::SIZE);
153 } else {
154 UMA_HISTOGRAM_ENUMERATION("Notifications.Display_Fullscreen.Suppressed",
155 message_center::NotifierId::APPLICATION,
156 message_center::NotifierId::SIZE);
157 }
158 return enabled;
159 }
160 }
161
162 return false;
163 }
164
122 } // namespace extensions 165 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698