| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/push_messaging/PushManager.h" | 6 #include "modules/push_messaging/PushManager.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #include "bindings/core/v8/ScriptState.h" | 11 #include "bindings/core/v8/ScriptState.h" |
| 12 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
| 13 #include "core/dom/Document.h" | 13 #include "core/dom/Document.h" |
| 14 #include "core/dom/ExceptionCode.h" | 14 #include "core/dom/ExceptionCode.h" |
| 15 #include "core/dom/ExecutionContext.h" | 15 #include "core/dom/ExecutionContext.h" |
| 16 #include "modules/push_messaging/PushController.h" | 16 #include "modules/push_messaging/PushController.h" |
| 17 #include "modules/push_messaging/PushError.h" | 17 #include "modules/push_messaging/PushError.h" |
| 18 #include "modules/push_messaging/PushPermissionStatusCallback.h" | 18 #include "modules/push_messaging/PushPermissionStatusCallback.h" |
| 19 #include "modules/push_messaging/PushRegistration.h" | 19 #include "modules/push_messaging/PushRegistration.h" |
| 20 #include "modules/push_messaging/PushRegistrationCallbacks.h" |
| 20 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 21 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 21 #include "public/platform/Platform.h" | 22 #include "public/platform/Platform.h" |
| 22 #include "public/platform/WebPushClient.h" | 23 #include "public/platform/WebPushClient.h" |
| 23 #include "public/platform/WebPushProvider.h" | 24 #include "public/platform/WebPushProvider.h" |
| 24 #include "wtf/RefPtr.h" | 25 #include "wtf/RefPtr.h" |
| 25 | 26 |
| 26 namespace blink { | 27 namespace blink { |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 WebPushProvider* pushProvider() | 30 WebPushProvider* pushProvider() |
| (...skipping 20 matching lines...) Expand all Loading... |
| 50 ScriptPromise promise = resolver->promise(); | 51 ScriptPromise promise = resolver->promise(); |
| 51 | 52 |
| 52 // The document context is the only reasonable context from which to ask the
user for permission | 53 // The document context is the only reasonable context from which to ask the
user for permission |
| 53 // to use the Push API. The embedder should persist the permission so that l
ater calls in | 54 // to use the Push API. The embedder should persist the permission so that l
ater calls in |
| 54 // different contexts can succeed. | 55 // different contexts can succeed. |
| 55 if (scriptState->executionContext()->isDocument()) { | 56 if (scriptState->executionContext()->isDocument()) { |
| 56 Document* document = toDocument(scriptState->executionContext()); | 57 Document* document = toDocument(scriptState->executionContext()); |
| 57 // FIXME: add test coverage for this condition - https://crbug.com/44043
1 | 58 // FIXME: add test coverage for this condition - https://crbug.com/44043
1 |
| 58 if (!document->domWindow() || !document->frame()) | 59 if (!document->domWindow() || !document->frame()) |
| 59 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(InvalidStateError, "Document is detached from window.")); | 60 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(InvalidStateError, "Document is detached from window.")); |
| 60 PushController::clientFrom(document->frame()).registerPushMessaging(m_re
gistration->webRegistration(), new CallbackPromiseAdapter<PushRegistration, Push
Error>(resolver)); | 61 PushController::clientFrom(document->frame()).registerPushMessaging(m_re
gistration->webRegistration(), new PushRegistrationCallbacks(resolver, m_registr
ation)); |
| 61 } else { | 62 } else { |
| 62 pushProvider()->registerPushMessaging(m_registration->webRegistration(),
new CallbackPromiseAdapter<PushRegistration, PushError>(resolver)); | 63 pushProvider()->registerPushMessaging(m_registration->webRegistration(),
new PushRegistrationCallbacks(resolver, m_registration)); |
| 63 } | 64 } |
| 64 | 65 |
| 65 return promise; | 66 return promise; |
| 66 } | 67 } |
| 67 | 68 |
| 68 ScriptPromise PushManager::hasPermission(ScriptState* scriptState) | 69 ScriptPromise PushManager::hasPermission(ScriptState* scriptState) |
| 69 { | 70 { |
| 70 if (scriptState->executionContext()->isDocument()) { | 71 if (scriptState->executionContext()->isDocument()) { |
| 71 Document* document = toDocument(scriptState->executionContext()); | 72 Document* document = toDocument(scriptState->executionContext()); |
| 72 // FIXME: add test coverage for this condition - https://crbug.com/44043
1 | 73 // FIXME: add test coverage for this condition - https://crbug.com/44043
1 |
| 73 if (!document->domWindow() || !document->frame()) | 74 if (!document->domWindow() || !document->frame()) |
| 74 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(InvalidStateError, "Document is detached from window.")); | 75 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(InvalidStateError, "Document is detached from window.")); |
| 75 } | 76 } |
| 76 | 77 |
| 77 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 78 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
| 78 ScriptPromise promise = resolver->promise(); | 79 ScriptPromise promise = resolver->promise(); |
| 79 pushProvider()->getPermissionStatus(m_registration->webRegistration(), new P
ushPermissionStatusCallback(resolver)); | 80 pushProvider()->getPermissionStatus(m_registration->webRegistration(), new P
ushPermissionStatusCallback(resolver)); |
| 80 return promise; | 81 return promise; |
| 81 } | 82 } |
| 82 | 83 |
| 83 void PushManager::trace(Visitor* visitor) | 84 void PushManager::trace(Visitor* visitor) |
| 84 { | 85 { |
| 85 visitor->trace(m_registration); | 86 visitor->trace(m_registration); |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace blink | 89 } // namespace blink |
| OLD | NEW |