| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 if (!document->domWindow() || !document->frame()) | 39 if (!document->domWindow() || !document->frame()) |
| 40 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Document is detached from window.")); | 40 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Document is detached from window.")); |
| 41 | 41 |
| 42 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se
rviceWorker(*document->domWindow()->navigator())->provider(); | 42 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se
rviceWorker(*document->domWindow()->navigator())->provider(); |
| 43 if (!serviceWorkerProvider) | 43 if (!serviceWorkerProvider) |
| 44 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "No Service Worker installed for this document.")); | 44 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "No Service Worker installed for this document.")); |
| 45 | 45 |
| 46 WebPushClient* client = PushController::clientFrom(document->frame()); | 46 WebPushClient* client = PushController::clientFrom(document->frame()); |
| 47 ASSERT(client); | 47 ASSERT(client); |
| 48 | 48 |
| 49 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 49 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 50 ScriptPromise promise = resolver->promise(); | 50 ScriptPromise promise = resolver->promise(); |
| 51 | 51 |
| 52 client->registerPushMessaging(new CallbackPromiseAdapter<PushRegistration, P
ushError>(resolver), serviceWorkerProvider); | 52 client->registerPushMessaging(new CallbackPromiseAdapter<PushRegistration, P
ushError>(resolver), serviceWorkerProvider); |
| 53 | 53 |
| 54 return promise; | 54 return promise; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // FIXME: This call should be available from workers which will not have a Docum
ent object available. | 57 // FIXME: This call should be available from workers which will not have a Docum
ent object available. |
| 58 // See crbug.com/389194 | 58 // See crbug.com/389194 |
| 59 ScriptPromise PushManager::hasPermission(ScriptState* scriptState) | 59 ScriptPromise PushManager::hasPermission(ScriptState* scriptState) |
| 60 { | 60 { |
| 61 ASSERT(scriptState->executionContext()->isDocument()); | 61 ASSERT(scriptState->executionContext()->isDocument()); |
| 62 | 62 |
| 63 Document* document = toDocument(scriptState->executionContext()); | 63 Document* document = toDocument(scriptState->executionContext()); |
| 64 if (!document->domWindow() || !document->frame()) | 64 if (!document->domWindow() || !document->frame()) |
| 65 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "Document is detached from window.")); | 65 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "Document is detached from window.")); |
| 66 blink::WebPushClient* client = PushController::clientFrom(document->frame())
; | 66 blink::WebPushClient* client = PushController::clientFrom(document->frame())
; |
| 67 ASSERT(client); | 67 ASSERT(client); |
| 68 | 68 |
| 69 // The currently implemented specification does not require a Service Worker
to be present for the | 69 // The currently implemented specification does not require a Service Worker
to be present for the |
| 70 // hasPermission() call to work, but it will become a requirement soon. | 70 // hasPermission() call to work, but it will become a requirement soon. |
| 71 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se
rviceWorker(*document->domWindow()->navigator())->provider(); | 71 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se
rviceWorker(*document->domWindow()->navigator())->provider(); |
| 72 if (!serviceWorkerProvider) | 72 if (!serviceWorkerProvider) |
| 73 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "No Service Worker installed for this document.")); | 73 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "No Service Worker installed for this document.")); |
| 74 | 74 |
| 75 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 75 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 76 | 76 |
| 77 ScriptPromise promise = resolver->promise(); | 77 ScriptPromise promise = resolver->promise(); |
| 78 client->getPermissionStatus(new PushPermissionStatusCallback(resolver), serv
iceWorkerProvider); | 78 client->getPermissionStatus(new PushPermissionStatusCallback(resolver), serv
iceWorkerProvider); |
| 79 return promise; | 79 return promise; |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace blink | 82 } // namespace blink |
| OLD | NEW |