Chromium Code Reviews| 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 "platform/weborigin/SecurityOrigin.h" | |
| 8 #include "public/platform/Platform.h" | |
| 9 #include "public/platform/ServiceRegistry.h" | |
| 10 #include "public/platform/modules/permissions/permission_status.mojom-blink.h" | |
| 11 #include "public/platform/modules/permissions/permission_status.mojom.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)); | |
|
Peter Beverloo
2016/05/05 16:43:53
@sammc -
There will be one NotificationManager pe
Sam McNally
2016/05/06 05:14:09
Platform::serviceRegistry() should be the right pl
Michael van Ouwerkerk
2016/05/06 10:46:07
This would be really useful. Where would the brows
| |
| 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::contextDestroyed() | |
| 69 { | |
| 70 m_service.reset(); | |
| 71 } | |
| 72 | |
| 73 String NotificationManager::getOriginString() const | |
| 74 { | |
| 75 return getExecutionContext()->getSecurityOrigin()->toString(); | |
| 76 } | |
| 77 | |
| 78 DEFINE_TRACE(NotificationManager) | |
| 79 { | |
| 80 ContextLifecycleObserver::trace(visitor); | |
| 81 Supplement<ExecutionContext>::trace(visitor); | |
| 82 } | |
| 83 | |
| 84 } // namespace blink | |
| OLD | NEW |