| 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/browser/notifications/blink_notification_service_impl.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/browser/notifications/platform_notification_context_impl.h" |
| 10 #include "content/browser/notifications/type_converters.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/content_browser_client.h" |
| 13 #include "content/public/browser/platform_notification_service.h" |
| 14 #include "content/public/common/content_client.h" |
| 15 #include "content/public/common/notification_resources.h" |
| 16 #include "content/public/common/platform_notification_data.h" |
| 17 #include "skia/public/type_converters.h" |
| 18 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 19 |
| 20 namespace content { |
| 21 |
| 22 // TODO: |
| 23 // - Have some convenience getter for the PlatformNotificationService. |
| 24 // - Have some convenience getter for the browser context (member?) |
| 25 |
| 26 BlinkNotificationServiceImpl::BlinkNotificationServiceImpl( |
| 27 PlatformNotificationContextImpl* notification_context, |
| 28 mojo::InterfaceRequest<blink::mojom::NotificationService> request) |
| 29 : notification_context_(notification_context), |
| 30 binding_(this, std::move(request)) { |
| 31 } |
| 32 |
| 33 BlinkNotificationServiceImpl::~BlinkNotificationServiceImpl() {} |
| 34 |
| 35 void BlinkNotificationServiceImpl::GetPermissionStatus( |
| 36 const mojo::String& origin, |
| 37 const GetPermissionStatusCallback& callback) { |
| 38 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 39 |
| 40 PlatformNotificationService* service = |
| 41 GetContentClient()->browser()->GetPlatformNotificationService(); |
| 42 DCHECK(service); |
| 43 |
| 44 blink::mojom::PermissionStatus permission_status = |
| 45 service->CheckPermissionOnUIThread( |
| 46 notification_context_->browser_context(), |
| 47 GURL(origin.get()), 0 /* render_process_id */); |
| 48 |
| 49 callback.Run(permission_status); |
| 50 } |
| 51 |
| 52 void BlinkNotificationServiceImpl::ShowPersistent( |
| 53 const mojo::String& origin, |
| 54 blink::mojom::NotificationPtr notification, |
| 55 blink::mojom::NotificationResourcesPtr notification_resources, |
| 56 const ShowPersistentCallback& callback) { |
| 57 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 58 |
| 59 PlatformNotificationService* service = |
| 60 GetContentClient()->browser()->GetPlatformNotificationService(); |
| 61 DCHECK(service); |
| 62 |
| 63 PlatformNotificationData notification_data = |
| 64 notification.To<PlatformNotificationData>(); |
| 65 |
| 66 NotificationResources resources; |
| 67 resources.notification_icon = notification_resources->icon.To<SkBitmap>(); |
| 68 |
| 69 service->DisplayPersistentNotification( |
| 70 notification_context_->browser_context(), |
| 71 42 /* persistent_notification_id */, |
| 72 GURL(origin.get()), |
| 73 notification_data, |
| 74 resources); |
| 75 |
| 76 callback.Run(blink::mojom::NotificationDisplayResult::SUCCESS); |
| 77 } |
| 78 |
| 79 } // namespace content |
| OLD | NEW |