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

Side by Side Diff: chrome/browser/extensions/api/notifications/extension_notification_handler.cc

Issue 2938883002: Reland reverted patch once the webkit tests that were failing are (Closed)
Patch Set: 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/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 104
93 SendEvent(profile, extension_id, histogram_value, event_name, 105 SendEvent(profile, extension_id, histogram_value, event_name,
94 EventRouter::USER_GESTURE_ENABLED, std::move(args)); 106 EventRouter::USER_GESTURE_ENABLED, std::move(args));
95 } 107 }
96 108
97 void ExtensionNotificationHandler::OpenSettings(Profile* profile) { 109 void ExtensionNotificationHandler::OpenSettings(Profile* profile) {
98 // Extension notifications don't display a settings button. 110 // Extension notifications don't display a settings button.
99 NOTREACHED(); 111 NOTREACHED();
100 } 112 }
101 113
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
102 void ExtensionNotificationHandler::SendEvent( 145 void ExtensionNotificationHandler::SendEvent(
103 Profile* profile, 146 Profile* profile,
104 const std::string& extension_id, 147 const std::string& extension_id,
105 events::HistogramValue histogram_value, 148 events::HistogramValue histogram_value,
106 const std::string& event_name, 149 const std::string& event_name,
107 EventRouter::UserGestureState user_gesture, 150 EventRouter::UserGestureState user_gesture,
108 std::unique_ptr<base::ListValue> args) { 151 std::unique_ptr<base::ListValue> args) {
109 if (extension_id.empty()) 152 if (extension_id.empty())
110 return; 153 return;
111 154
112 EventRouter* event_router = EventRouter::Get(profile); 155 EventRouter* event_router = EventRouter::Get(profile);
113 if (!event_router) 156 if (!event_router)
114 return; 157 return;
115 158
116 std::unique_ptr<Event> event( 159 std::unique_ptr<Event> event(
117 new Event(histogram_value, event_name, std::move(args))); 160 new Event(histogram_value, event_name, std::move(args)));
118 event->user_gesture = user_gesture; 161 event->user_gesture = user_gesture;
119 event_router->DispatchEventToExtension(extension_id, std::move(event)); 162 event_router->DispatchEventToExtension(extension_id, std::move(event));
120 } 163 }
121 164
122 } // namespace extensions 165 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698