Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/notifications/NotificationManager.h" | 5 #include "modules/notifications/NotificationManager.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "modules/notifications/Notification.h" | 9 #include "modules/notifications/Notification.h" |
| 10 #include "modules/notifications/NotificationPermissionCallback.h" | 10 #include "modules/notifications/NotificationPermissionCallback.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 | 21 |
| 22 // static | 22 // static |
| 23 NotificationManager* NotificationManager::from( | 23 NotificationManager* NotificationManager::from( |
| 24 ExecutionContext* executionContext) { | 24 ExecutionContext* executionContext) { |
| 25 DCHECK(executionContext); | 25 DCHECK(executionContext); |
| 26 DCHECK(executionContext->isContextThread()); | 26 DCHECK(executionContext->isContextThread()); |
| 27 | 27 |
| 28 NotificationManager* manager = static_cast<NotificationManager*>( | 28 NotificationManager* manager = static_cast<NotificationManager*>( |
| 29 Supplement<ExecutionContext>::from(executionContext, supplementName())); | 29 Supplement<ExecutionContext>::from(executionContext, supplementName())); |
| 30 if (!manager) { | 30 if (!manager) { |
| 31 manager = new NotificationManager(executionContext); | 31 manager = new NotificationManager(); |
| 32 Supplement<ExecutionContext>::provideTo(*executionContext, supplementName(), | 32 Supplement<ExecutionContext>::provideTo(*executionContext, supplementName(), |
| 33 manager); | 33 manager); |
| 34 } | 34 } |
| 35 | 35 |
| 36 return manager; | 36 return manager; |
| 37 } | 37 } |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 const char* NotificationManager::supplementName() { | 40 const char* NotificationManager::supplementName() { |
| 41 return "NotificationManager"; | 41 return "NotificationManager"; |
| 42 } | 42 } |
| 43 | 43 |
| 44 NotificationManager::NotificationManager(ExecutionContext* executionContext) | 44 NotificationManager::NotificationManager() {} |
| 45 : ContextLifecycleObserver(executionContext) {} | |
| 46 | 45 |
| 47 NotificationManager::~NotificationManager() {} | 46 NotificationManager::~NotificationManager() {} |
| 48 | 47 |
| 49 mojom::blink::PermissionStatus NotificationManager::permissionStatus() { | 48 mojom::blink::PermissionStatus NotificationManager::permissionStatus( |
| 49 ExecutionContext* executionContext) { | |
| 50 if (!m_notificationService) | 50 if (!m_notificationService) |
| 51 Platform::current()->interfaceProvider()->getInterface( | 51 Platform::current()->interfaceProvider()->getInterface( |
| 52 mojo::GetProxy(&m_notificationService)); | 52 mojo::GetProxy(&m_notificationService)); |
| 53 | 53 |
| 54 mojom::blink::PermissionStatus permissionStatus; | 54 mojom::blink::PermissionStatus permissionStatus; |
| 55 const bool result = m_notificationService->GetPermissionStatus( | 55 const bool result = m_notificationService->GetPermissionStatus( |
| 56 getExecutionContext()->getSecurityOrigin()->toString(), | 56 executionContext->getSecurityOrigin()->toString(), &permissionStatus); |
| 57 &permissionStatus); | |
| 58 DCHECK(result); | 57 DCHECK(result); |
| 59 | 58 |
| 60 return permissionStatus; | 59 return permissionStatus; |
| 61 } | 60 } |
| 62 | 61 |
| 63 ScriptPromise NotificationManager::requestPermission( | 62 ScriptPromise NotificationManager::requestPermission( |
| 64 ScriptState* scriptState, | 63 ScriptState* scriptState, |
| 65 NotificationPermissionCallback* deprecatedCallback) { | 64 NotificationPermissionCallback* deprecatedCallback) { |
| 66 ExecutionContext* context = scriptState->getExecutionContext(); | 65 ExecutionContext* context = scriptState->getExecutionContext(); |
| 67 | 66 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 80 context->getSecurityOrigin(), | 79 context->getSecurityOrigin(), |
| 81 UserGestureIndicator::processingUserGesture(), | 80 UserGestureIndicator::processingUserGesture(), |
| 82 convertToBaseCallback( | 81 convertToBaseCallback( |
| 83 WTF::bind(&NotificationManager::onPermissionRequestComplete, | 82 WTF::bind(&NotificationManager::onPermissionRequestComplete, |
| 84 wrapPersistent(this), wrapPersistent(resolver), | 83 wrapPersistent(this), wrapPersistent(resolver), |
| 85 wrapPersistent(deprecatedCallback)))); | 84 wrapPersistent(deprecatedCallback)))); |
| 86 | 85 |
| 87 return promise; | 86 return promise; |
| 88 } | 87 } |
| 89 | 88 |
| 90 void NotificationManager::contextDestroyed() { | |
| 91 m_notificationService.reset(); | |
| 92 m_permissionService.reset(); | |
|
haraken
2016/12/07 06:56:06
As far as I understand, there is no benefit in res
| |
| 93 } | |
| 94 | |
| 95 void NotificationManager::onPermissionRequestComplete( | 89 void NotificationManager::onPermissionRequestComplete( |
| 96 ScriptPromiseResolver* resolver, | 90 ScriptPromiseResolver* resolver, |
| 97 NotificationPermissionCallback* deprecatedCallback, | 91 NotificationPermissionCallback* deprecatedCallback, |
| 98 mojom::blink::PermissionStatus status) { | 92 mojom::blink::PermissionStatus status) { |
| 99 String statusString = Notification::permissionString(status); | 93 String statusString = Notification::permissionString(status); |
| 100 if (deprecatedCallback) | 94 if (deprecatedCallback) |
| 101 deprecatedCallback->handleEvent(statusString); | 95 deprecatedCallback->handleEvent(statusString); |
| 102 | 96 |
| 103 resolver->resolve(statusString); | 97 resolver->resolve(statusString); |
| 104 } | 98 } |
| 105 | 99 |
| 106 void NotificationManager::onPermissionServiceConnectionError() { | 100 void NotificationManager::onPermissionServiceConnectionError() { |
| 107 if (!Platform::current()) { | 101 if (!Platform::current()) { |
| 108 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 102 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
| 109 return; | 103 return; |
| 110 } | 104 } |
| 111 m_permissionService.reset(); | 105 m_permissionService.reset(); |
| 112 } | 106 } |
| 113 | 107 |
| 114 DEFINE_TRACE(NotificationManager) { | 108 DEFINE_TRACE(NotificationManager) { |
| 115 ContextLifecycleObserver::trace(visitor); | |
| 116 Supplement<ExecutionContext>::trace(visitor); | 109 Supplement<ExecutionContext>::trace(visitor); |
| 117 } | 110 } |
| 118 | 111 |
| 119 } // namespace blink | 112 } // namespace blink |
| OLD | NEW |