OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/notifications_api.h" | 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/notifications/notification_ui_manager.h" | 24 #include "chrome/browser/notifications/notification_ui_manager.h" |
25 #include "chrome/browser/notifications/notifier_state_tracker.h" | 25 #include "chrome/browser/notifications/notifier_state_tracker.h" |
26 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 26 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/common/extensions/api/notifications/notification_style.h" | 28 #include "chrome/common/extensions/api/notifications/notification_style.h" |
29 #include "components/keyed_service/content/browser_context_keyed_service_shutdow
n_notifier_factory.h" | 29 #include "components/keyed_service/content/browser_context_keyed_service_shutdow
n_notifier_factory.h" |
30 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h" | 30 #include "components/keyed_service/core/keyed_service_shutdown_notifier.h" |
31 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 34 #include "extensions/browser/app_window/app_window.h" |
| 35 #include "extensions/browser/app_window/app_window_registry.h" |
| 36 #include "extensions/browser/app_window/native_app_window.h" |
34 #include "extensions/browser/event_router.h" | 37 #include "extensions/browser/event_router.h" |
35 #include "extensions/browser/extension_system_provider.h" | 38 #include "extensions/browser/extension_system_provider.h" |
36 #include "extensions/browser/extensions_browser_client.h" | 39 #include "extensions/browser/extensions_browser_client.h" |
37 #include "extensions/common/extension.h" | 40 #include "extensions/common/extension.h" |
38 #include "extensions/common/features/feature.h" | 41 #include "extensions/common/features/feature.h" |
39 #include "third_party/skia/include/core/SkBitmap.h" | 42 #include "third_party/skia/include/core/SkBitmap.h" |
40 #include "ui/base/layout.h" | 43 #include "ui/base/layout.h" |
41 #include "ui/gfx/image/image.h" | 44 #include "ui/gfx/image/image.h" |
42 #include "ui/gfx/image/image_skia.h" | 45 #include "ui/gfx/image/image_skia.h" |
43 #include "ui/gfx/image/image_skia_operations.h" | 46 #include "ui/gfx/image/image_skia_operations.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 }; | 139 }; |
137 | 140 |
138 class NotificationsApiDelegate : public NotificationDelegate { | 141 class NotificationsApiDelegate : public NotificationDelegate { |
139 public: | 142 public: |
140 NotificationsApiDelegate(ChromeAsyncExtensionFunction* api_function, | 143 NotificationsApiDelegate(ChromeAsyncExtensionFunction* api_function, |
141 Profile* profile, | 144 Profile* profile, |
142 const std::string& extension_id, | 145 const std::string& extension_id, |
143 const std::string& id) | 146 const std::string& id) |
144 : api_function_(api_function), | 147 : api_function_(api_function), |
145 event_router_(EventRouter::Get(profile)), | 148 event_router_(EventRouter::Get(profile)), |
| 149 profile_(profile), |
146 extension_id_(extension_id), | 150 extension_id_(extension_id), |
147 id_(id), | 151 id_(id), |
148 scoped_id_(CreateScopedIdentifier(extension_id, id)) { | 152 scoped_id_(CreateScopedIdentifier(extension_id, id)) { |
149 DCHECK(api_function_); | 153 DCHECK(api_function_); |
150 shutdown_notifier_subscription_ = | 154 shutdown_notifier_subscription_ = |
151 ShutdownNotifierFactory::GetInstance()->Get(profile)->Subscribe( | 155 ShutdownNotifierFactory::GetInstance()->Get(profile)->Subscribe( |
152 base::Bind(&NotificationsApiDelegate::Shutdown, | 156 base::Bind(&NotificationsApiDelegate::Shutdown, |
153 base::Unretained(this))); | 157 base::Unretained(this))); |
154 } | 158 } |
155 | 159 |
(...skipping 25 matching lines...) Expand all Loading... |
181 void ButtonClick(int index) override { | 185 void ButtonClick(int index) override { |
182 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); | 186 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); |
183 args->AppendInteger(index); | 187 args->AppendInteger(index); |
184 SendEvent(events::NOTIFICATIONS_ON_BUTTON_CLICKED, | 188 SendEvent(events::NOTIFICATIONS_ON_BUTTON_CLICKED, |
185 notifications::OnButtonClicked::kEventName, | 189 notifications::OnButtonClicked::kEventName, |
186 EventRouter::USER_GESTURE_ENABLED, std::move(args)); | 190 EventRouter::USER_GESTURE_ENABLED, std::move(args)); |
187 } | 191 } |
188 | 192 |
189 std::string id() const override { return scoped_id_; } | 193 std::string id() const override { return scoped_id_; } |
190 | 194 |
| 195 // Should only display when fullscreen if this app is the source of the |
| 196 // fullscreen window. |
| 197 bool ShouldDisplayOverFullscreen() const override { |
| 198 AppWindowRegistry::AppWindowList windows = |
| 199 AppWindowRegistry::Get(profile_)->GetAppWindowsForApp(extension_id_); |
| 200 for (const auto& window : windows) { |
| 201 // Window must be fullscreen and visible |
| 202 if (window->IsFullscreen() && window->GetBaseWindow()->IsActive()) |
| 203 return true; |
| 204 } |
| 205 return false; |
| 206 } |
| 207 |
191 private: | 208 private: |
192 ~NotificationsApiDelegate() override {} | 209 ~NotificationsApiDelegate() override {} |
193 | 210 |
194 void SendEvent(events::HistogramValue histogram_value, | 211 void SendEvent(events::HistogramValue histogram_value, |
195 const std::string& name, | 212 const std::string& name, |
196 EventRouter::UserGestureState user_gesture, | 213 EventRouter::UserGestureState user_gesture, |
197 std::unique_ptr<base::ListValue> args) { | 214 std::unique_ptr<base::ListValue> args) { |
198 if (!event_router_) | 215 if (!event_router_) |
199 return; | 216 return; |
200 | 217 |
(...skipping 14 matching lines...) Expand all Loading... |
215 return args; | 232 return args; |
216 } | 233 } |
217 | 234 |
218 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; | 235 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; |
219 | 236 |
220 // Since this class is refcounted it may outlive the profile. We listen for | 237 // Since this class is refcounted it may outlive the profile. We listen for |
221 // profile-keyed service shutdown events and reset to nullptr at that time, | 238 // profile-keyed service shutdown events and reset to nullptr at that time, |
222 // so make sure to check for a valid pointer before use. | 239 // so make sure to check for a valid pointer before use. |
223 EventRouter* event_router_; | 240 EventRouter* event_router_; |
224 | 241 |
| 242 Profile* profile_; |
225 const std::string extension_id_; | 243 const std::string extension_id_; |
226 const std::string id_; | 244 const std::string id_; |
227 const std::string scoped_id_; | 245 const std::string scoped_id_; |
228 | 246 |
229 std::unique_ptr<KeyedServiceShutdownNotifier::Subscription> | 247 std::unique_ptr<KeyedServiceShutdownNotifier::Subscription> |
230 shutdown_notifier_subscription_; | 248 shutdown_notifier_subscription_; |
231 | 249 |
232 DISALLOW_COPY_AND_ASSIGN(NotificationsApiDelegate); | 250 DISALLOW_COPY_AND_ASSIGN(NotificationsApiDelegate); |
233 }; | 251 }; |
234 | 252 |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 : api::notifications::PERMISSION_LEVEL_DENIED; | 740 : api::notifications::PERMISSION_LEVEL_DENIED; |
723 | 741 |
724 SetResult(base::MakeUnique<base::StringValue>( | 742 SetResult(base::MakeUnique<base::StringValue>( |
725 api::notifications::ToString(result))); | 743 api::notifications::ToString(result))); |
726 SendResponse(true); | 744 SendResponse(true); |
727 | 745 |
728 return true; | 746 return true; |
729 } | 747 } |
730 | 748 |
731 } // namespace extensions | 749 } // namespace extensions |
OLD | NEW |