| 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 "content/browser/notifications/platform_notification_context_impl.h" |
| 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/content_browser_client.h" |
| 11 #include "content/public/browser/platform_notification_service.h" |
| 12 #include "content/public/common/content_client.h" |
| 13 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 14 #include "url/gurl.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 namespace { |
| 19 |
| 20 // Returns the implementation of the PlatformNotificationService. May be NULL. |
| 21 PlatformNotificationService* Service() { |
| 22 return GetContentClient()->browser()->GetPlatformNotificationService(); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 27 BlinkNotificationServiceImpl::BlinkNotificationServiceImpl( |
| 28 PlatformNotificationContextImpl* notification_context, |
| 29 ResourceContext* resource_context, |
| 30 int render_process_id, |
| 31 mojo::InterfaceRequest<blink::mojom::NotificationService> request) |
| 32 : notification_context_(notification_context), |
| 33 resource_context_(resource_context), |
| 34 render_process_id_(render_process_id), |
| 35 binding_(this, std::move(request)) { |
| 36 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 37 DCHECK(notification_context_); |
| 38 DCHECK(resource_context_); |
| 39 |
| 40 binding_.set_connection_error_handler( |
| 41 base::Bind(&BlinkNotificationServiceImpl::OnConnectionError, |
| 42 base::Unretained(this) /* the channel is owned by this */)); |
| 43 } |
| 44 |
| 45 BlinkNotificationServiceImpl::~BlinkNotificationServiceImpl() { |
| 46 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 47 } |
| 48 |
| 49 void BlinkNotificationServiceImpl::GetPermissionStatus( |
| 50 const mojo::String& origin, |
| 51 const GetPermissionStatusCallback& callback) { |
| 52 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 53 |
| 54 if (!Service()) { |
| 55 callback.Run(blink::mojom::PermissionStatus::DENIED); |
| 56 return; |
| 57 } |
| 58 |
| 59 blink::mojom::PermissionStatus permission_status = |
| 60 Service()->CheckPermissionOnIOThread( |
| 61 resource_context_, GURL(origin.get()), render_process_id_); |
| 62 |
| 63 callback.Run(permission_status); |
| 64 } |
| 65 |
| 66 void BlinkNotificationServiceImpl::OnConnectionError() { |
| 67 notification_context_->RemoveService(this); |
| 68 // |this| has now been deleted. |
| 69 } |
| 70 |
| 71 } // namespace content |
| OLD | NEW |