| Index: third_party/WebKit/Source/modules/notifications/NotificationManager.cpp
|
| diff --git a/third_party/WebKit/Source/modules/notifications/NotificationManager.cpp b/third_party/WebKit/Source/modules/notifications/NotificationManager.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..60512b5a70bb1ee3fd3e0c9f5a653423645661b9
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/notifications/NotificationManager.cpp
|
| @@ -0,0 +1,116 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "modules/notifications/NotificationManager.h"
|
| +
|
| +#include "core/dom/Document.h"
|
| +#include "public/platform/Platform.h"
|
| +#include "public/platform/ServiceRegistry.h"
|
| +#include "public/platform/modules/permissions/permission_status.mojom.h"
|
| +#include "public/platform/modules/permissions/permission_status.mojom-wtf.h"
|
| +
|
| +namespace blink {
|
| +
|
| +#define STATIC_ASSERT_ENUM(a, b) \
|
| + static_assert(static_cast<int>(a) == static_cast<int>(b), "mismatching enum: " #a)
|
| +
|
| +STATIC_ASSERT_ENUM(mojom::PermissionStatus::GRANTED, mojom::wtf::PermissionStatus::GRANTED);
|
| +STATIC_ASSERT_ENUM(mojom::PermissionStatus::DENIED, mojom::wtf::PermissionStatus::DENIED);
|
| +STATIC_ASSERT_ENUM(mojom::PermissionStatus::ASK, mojom::wtf::PermissionStatus::ASK);
|
| +STATIC_ASSERT_ENUM(mojom::PermissionStatus::LAST, mojom::wtf::PermissionStatus::LAST);
|
| +
|
| +// static
|
| +NotificationManager* NotificationManager::from(ExecutionContext* executionContext)
|
| +{
|
| + DCHECK(executionContext);
|
| + DCHECK(executionContext->isContextThread());
|
| +
|
| + NotificationManager* manager = nullptr;
|
| +
|
| + if (executionContext->isDocument()) {
|
| + LocalFrame* localFrame = toDocument(executionContext)->frame();
|
| + DCHECK(localFrame);
|
| +
|
| + manager = static_cast<NotificationManager*>(Supplement<LocalFrame>::from(localFrame, supplementName()));
|
| + if (!manager) {
|
| + manager = new NotificationManager(executionContext);
|
| + Supplement<LocalFrame>::provideTo(*localFrame, supplementName(), manager);
|
| + }
|
| + } else {
|
| + WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(executionContext);
|
| + DCHECK(workerGlobalScope);
|
| +
|
| + manager = static_cast<NotificationManager*>(Supplement<WorkerGlobalScope>::from(workerGlobalScope, supplementName()));
|
| + if (!manager) {
|
| + manager = new NotificationManager(executionContext);
|
| + Supplement<WorkerGlobalScope>::provideTo(*workerGlobalScope, supplementName(), manager);
|
| + }
|
| + }
|
| +
|
| + return manager;
|
| +}
|
| +
|
| +// static
|
| +const char* NotificationManager::supplementName()
|
| +{
|
| + return "NotificationManager";
|
| +}
|
| +
|
| +NotificationManager::NotificationManager(ExecutionContext* executionContext)
|
| + : ContextLifecycleObserver(executionContext)
|
| +{
|
| + Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_service));
|
| +}
|
| +
|
| +NotificationManager::~NotificationManager()
|
| +{
|
| +}
|
| +
|
| +mojom::PermissionStatus NotificationManager::permissionStatus() const
|
| +{
|
| + mojom::wtf::PermissionStatus wtfPermissionStatus;
|
| +
|
| + const bool result =
|
| + m_service->GetPermissionStatus(getOriginString(), &wtfPermissionStatus);
|
| + DCHECK(result);
|
| +
|
| + // Both PermissionStatus enums are generated from the same source, but by using the WTF variant
|
| + // of the NotificationService the same variant of the enum must be used, different from other
|
| + // users. Static assertions for equality are included in this file.
|
| + return static_cast<mojom::PermissionStatus>(wtfPermissionStatus);
|
| +}
|
| +
|
| +void NotificationManager::show(
|
| + mojom::wtf::NotificationPtr notification,
|
| + mojom::wtf::NotificationResourcesPtr notificationResources)
|
| +{
|
| + // TODO: Implement this method.
|
| +}
|
| +
|
| +void NotificationManager::showPersistent(
|
| + mojom::wtf::NotificationPtr notification,
|
| + mojom::wtf::NotificationResourcesPtr notificationResources,
|
| + const mojom::wtf::NotificationService::ShowPersistentCallback& callback)
|
| +{
|
| + m_service->ShowPersistent(getOriginString(), std::move(notification), std::move(notificationResources), callback);
|
| +}
|
| +
|
| +void NotificationManager::contextDestroyed()
|
| +{
|
| + m_service.reset();
|
| +}
|
| +
|
| +String NotificationManager::getOriginString() const
|
| +{
|
| + return getExecutionContext()->getSecurityOrigin()->toString();
|
| +}
|
| +
|
| +DEFINE_TRACE(NotificationManager)
|
| +{
|
| + ContextLifecycleObserver::trace(visitor);
|
| + Supplement<LocalFrame>::trace(visitor);
|
| + Supplement<WorkerGlobalScope>::trace(visitor);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|