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