| 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 "modules/notifications/NotificationManager.h" |
| 6 |
| 7 #include "core/dom/Document.h" |
| 8 #include "public/platform/Platform.h" |
| 9 #include "public/platform/ServiceRegistry.h" |
| 10 #include "public/platform/modules/permissions/permission_status.mojom.h" |
| 11 #include "public/platform/modules/permissions/permission_status.mojom-blink.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 #define STATIC_ASSERT_ENUM(a, b) \ |
| 16 static_assert(static_cast<int>(a) == static_cast<int>(b), "mismatching enum:
" #a) |
| 17 |
| 18 STATIC_ASSERT_ENUM(mojom::PermissionStatus::GRANTED, mojom::blink::PermissionSta
tus::GRANTED); |
| 19 STATIC_ASSERT_ENUM(mojom::PermissionStatus::DENIED, mojom::blink::PermissionStat
us::DENIED); |
| 20 STATIC_ASSERT_ENUM(mojom::PermissionStatus::ASK, mojom::blink::PermissionStatus:
:ASK); |
| 21 STATIC_ASSERT_ENUM(mojom::PermissionStatus::LAST, mojom::blink::PermissionStatus
::LAST); |
| 22 |
| 23 // static |
| 24 NotificationManager* NotificationManager::from(ExecutionContext* executionContex
t) |
| 25 { |
| 26 DCHECK(executionContext); |
| 27 DCHECK(executionContext->isContextThread()); |
| 28 |
| 29 NotificationManager* manager = static_cast<NotificationManager*>(Supplement<
ExecutionContext>::from(executionContext, supplementName())); |
| 30 if (!manager) { |
| 31 manager = new NotificationManager(executionContext); |
| 32 Supplement<ExecutionContext>::provideTo(*executionContext, supplementNam
e(), manager); |
| 33 } |
| 34 |
| 35 return manager; |
| 36 } |
| 37 |
| 38 // static |
| 39 const char* NotificationManager::supplementName() |
| 40 { |
| 41 return "NotificationManager"; |
| 42 } |
| 43 |
| 44 NotificationManager::NotificationManager(ExecutionContext* executionContext) |
| 45 : ContextLifecycleObserver(executionContext) |
| 46 { |
| 47 Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProx
y(&m_service)); |
| 48 } |
| 49 |
| 50 NotificationManager::~NotificationManager() |
| 51 { |
| 52 } |
| 53 |
| 54 mojom::PermissionStatus NotificationManager::permissionStatus() const |
| 55 { |
| 56 mojom::blink::PermissionStatus blinkPermissionStatus; |
| 57 |
| 58 const bool result = |
| 59 m_service->GetPermissionStatus(getOriginString(), &blinkPermissionStatus
); |
| 60 DCHECK(result); |
| 61 |
| 62 // Both PermissionStatus enums are generated from the same source, but by us
ing the WTF variant |
| 63 // of the NotificationService the same variant of the enum must be used, dif
ferent from other |
| 64 // users. Static assertions for equality are included in this file. |
| 65 return static_cast<mojom::PermissionStatus>(blinkPermissionStatus); |
| 66 } |
| 67 |
| 68 void NotificationManager::display( |
| 69 mojom::blink::NotificationPtr notification, |
| 70 mojom::blink::NotificationResourcesPtr notificationResources, |
| 71 mojom::blink::NotificationClientPtr notificationClient, |
| 72 const mojom::blink::NotificationService::DisplayCallback& callback) |
| 73 { |
| 74 m_service->Display(getOriginString(), std::move(notification), std::move(not
ificationResources), std::move(notificationClient), callback); |
| 75 } |
| 76 |
| 77 void NotificationManager::displayPersistent( |
| 78 int64_t serviceWorkerRegistrationId, |
| 79 mojom::blink::NotificationPtr notification, |
| 80 mojom::blink::NotificationResourcesPtr notificationResources, |
| 81 const mojom::blink::NotificationService::DisplayPersistentCallback& callback
) |
| 82 { |
| 83 m_service->DisplayPersistent(getOriginString(), serviceWorkerRegistrationId,
std::move(notification), std::move(notificationResources), callback); |
| 84 } |
| 85 |
| 86 void NotificationManager::getNotifications( |
| 87 int64_t serviceWorkerRegistrationId, |
| 88 const String& tag, |
| 89 const mojom::blink::NotificationService::GetNotificationsCallback& callback)
const |
| 90 { |
| 91 m_service->GetNotifications(getOriginString(), serviceWorkerRegistrationId,
tag, callback); |
| 92 } |
| 93 |
| 94 void NotificationManager::close(const String& id, const mojom::blink::Notificati
onService::CloseCallback& callback) |
| 95 { |
| 96 m_service->Close(getOriginString(), id, callback); |
| 97 } |
| 98 |
| 99 void NotificationManager::contextDestroyed() |
| 100 { |
| 101 m_service.reset(); |
| 102 } |
| 103 |
| 104 String NotificationManager::getOriginString() const |
| 105 { |
| 106 return getExecutionContext()->getSecurityOrigin()->toString(); |
| 107 } |
| 108 |
| 109 DEFINE_TRACE(NotificationManager) |
| 110 { |
| 111 ContextLifecycleObserver::trace(visitor); |
| 112 Supplement<ExecutionContext>::trace(visitor); |
| 113 } |
| 114 |
| 115 } // namespace blink |
| OLD | NEW |