| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/notifications/notification_service_worker_client_impl
.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "content/renderer/service_worker/service_worker_context_client.h" |
| 9 #include "third_party/WebKit/public/platform/Platform.h" |
| 10 #include "third_party/WebKit/public/platform/WebThread.h" |
| 11 #include "third_party/WebKit/public/platform/modules/notifications/notification.
mojom-blink.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 namespace { |
| 16 |
| 17 // Converts |status| to the Blink variant of the enum and invokes the |callback| |
| 18 // with the result of the conversion. |
| 19 void ConvertToBlinkStatus( |
| 20 const mojo::Callback<void(mojom::blink::ServiceWorkerEventStatus)>& |
| 21 callback, |
| 22 mojom::ServiceWorkerEventStatus status) { |
| 23 callback.Run(static_cast<mojom::blink::ServiceWorkerEventStatus>(status)); |
| 24 } |
| 25 |
| 26 } // namespace |
| 27 |
| 28 // static |
| 29 void NotificationServiceWorkerClientImpl::Create( |
| 30 mojo::InterfaceRequest<mojom::blink::NotificationServiceWorkerClient> |
| 31 request) { |
| 32 new NotificationServiceWorkerClientImpl(std::move(request)); |
| 33 } |
| 34 |
| 35 NotificationServiceWorkerClientImpl::NotificationServiceWorkerClientImpl( |
| 36 mojo::InterfaceRequest<mojom::blink::NotificationServiceWorkerClient> |
| 37 request) |
| 38 : binding_(this, std::move(request)) {} |
| 39 |
| 40 NotificationServiceWorkerClientImpl::~NotificationServiceWorkerClientImpl() {} |
| 41 |
| 42 void NotificationServiceWorkerClientImpl::Click( |
| 43 blink::mojom::blink::NotificationPtr notification, |
| 44 int32_t action_index, |
| 45 const ClickCallback& callback) { |
| 46 DCHECK(!blink::Platform::current()->mainThread()->isCurrentThread()); |
| 47 |
| 48 ServiceWorkerContextClient* client = |
| 49 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 50 |
| 51 if (!client) { |
| 52 callback.Run(mojom::blink::ServiceWorkerEventStatus::ABORTED); |
| 53 return; |
| 54 } |
| 55 |
| 56 client->DispatchNotificationClickEvent( |
| 57 std::move(notification), action_index, |
| 58 base::Bind(&ConvertToBlinkStatus, callback)); |
| 59 } |
| 60 |
| 61 void NotificationServiceWorkerClientImpl::Close( |
| 62 blink::mojom::blink::NotificationPtr notification, |
| 63 const CloseCallback& callback) { |
| 64 DCHECK(!blink::Platform::current()->mainThread()->isCurrentThread()); |
| 65 |
| 66 ServiceWorkerContextClient* client = |
| 67 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 68 |
| 69 if (!client) { |
| 70 callback.Run(mojom::blink::ServiceWorkerEventStatus::ABORTED); |
| 71 return; |
| 72 } |
| 73 |
| 74 client->DispatchNotificationCloseEvent( |
| 75 std::move(notification), base::Bind(&ConvertToBlinkStatus, callback)); |
| 76 } |
| 77 |
| 78 } // namespace content |
| OLD | NEW |