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