| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/notifications/notification_manager.h" | 5 #include "content/child/notifications/notification_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
| 13 #include "content/child/notifications/notification_data_conversions.h" | 13 #include "content/child/notifications/notification_data_conversions.h" |
| 14 #include "content/child/notifications/notification_dispatcher.h" | 14 #include "content/child/notifications/notification_dispatcher.h" |
| 15 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 15 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 16 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
| 17 #include "content/public/common/notification_resources.h" | 17 #include "content/public/common/notification_resources.h" |
| 18 #include "content/public/common/platform_notification_data.h" | 18 #include "content/public/common/platform_notification_data.h" |
| 19 #include "third_party/WebKit/public/platform/URLConversion.h" | 19 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 20 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 20 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 21 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onDelegate.h" | 21 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onDelegate.h" |
| 22 | 22 |
| 23 using blink::WebNotificationPermission; | |
| 24 | |
| 25 namespace content { | 23 namespace content { |
| 26 namespace { | 24 namespace { |
| 27 | 25 |
| 28 int CurrentWorkerId() { | 26 int CurrentWorkerId() { |
| 29 return WorkerThread::GetCurrentId(); | 27 return WorkerThread::GetCurrentId(); |
| 30 } | 28 } |
| 31 | 29 |
| 32 NotificationResources ToNotificationResources( | 30 NotificationResources ToNotificationResources( |
| 33 std::unique_ptr<blink::WebNotificationResources> web_resources) { | 31 std::unique_ptr<blink::WebNotificationResources> web_resources) { |
| 34 NotificationResources resources; | 32 NotificationResources resources; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 blink::WebNotificationDelegate* delegate) { | 202 blink::WebNotificationDelegate* delegate) { |
| 205 for (auto& iter : active_page_notifications_) { | 203 for (auto& iter : active_page_notifications_) { |
| 206 if (iter.second != delegate) | 204 if (iter.second != delegate) |
| 207 continue; | 205 continue; |
| 208 | 206 |
| 209 active_page_notifications_.erase(iter.first); | 207 active_page_notifications_.erase(iter.first); |
| 210 return; | 208 return; |
| 211 } | 209 } |
| 212 } | 210 } |
| 213 | 211 |
| 214 WebNotificationPermission NotificationManager::checkPermission( | 212 blink::mojom::PermissionStatus NotificationManager::checkPermission( |
| 215 const blink::WebSecurityOrigin& origin) { | 213 const blink::WebSecurityOrigin& origin) { |
| 216 WebNotificationPermission permission = | 214 blink::mojom::PermissionStatus permission_status = |
| 217 blink::WebNotificationPermissionAllowed; | 215 blink::mojom::PermissionStatus::DENIED; |
| 216 |
| 218 // TODO(mkwst): This is potentially doing the wrong thing with unique | 217 // TODO(mkwst): This is potentially doing the wrong thing with unique |
| 219 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See | 218 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See |
| 220 // https://crbug.com/490074 for detail. | 219 // https://crbug.com/490074 for detail. |
| 221 thread_safe_sender_->Send(new PlatformNotificationHostMsg_CheckPermission( | 220 thread_safe_sender_->Send(new PlatformNotificationHostMsg_CheckPermission( |
| 222 blink::WebStringToGURL(origin.toString()), &permission)); | 221 blink::WebStringToGURL(origin.toString()), &permission_status)); |
| 223 | 222 |
| 224 return permission; | 223 return permission_status; |
| 225 } | 224 } |
| 226 | 225 |
| 227 bool NotificationManager::OnMessageReceived(const IPC::Message& message) { | 226 bool NotificationManager::OnMessageReceived(const IPC::Message& message) { |
| 228 bool handled = true; | 227 bool handled = true; |
| 229 IPC_BEGIN_MESSAGE_MAP(NotificationManager, message) | 228 IPC_BEGIN_MESSAGE_MAP(NotificationManager, message) |
| 230 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShow, OnDidShow); | 229 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShow, OnDidShow); |
| 231 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShowPersistent, | 230 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShowPersistent, |
| 232 OnDidShowPersistent) | 231 OnDidShowPersistent) |
| 233 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClose, OnDidClose); | 232 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClose, OnDidClose); |
| 234 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClick, OnDidClick); | 233 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClick, OnDidClick); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 300 |
| 302 notifications[i] = web_notification_info; | 301 notifications[i] = web_notification_info; |
| 303 } | 302 } |
| 304 | 303 |
| 305 callbacks->onSuccess(notifications); | 304 callbacks->onSuccess(notifications); |
| 306 | 305 |
| 307 pending_get_notification_requests_.Remove(request_id); | 306 pending_get_notification_requests_.Remove(request_id); |
| 308 } | 307 } |
| 309 | 308 |
| 310 } // namespace content | 309 } // namespace content |
| OLD | NEW |