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 10 matching lines...) Expand all Loading... |
21 #include "modules/serviceworkers/ServiceWorkerContainer.h" | 21 #include "modules/serviceworkers/ServiceWorkerContainer.h" |
22 #include "public/platform/WebPushClient.h" | 22 #include "public/platform/WebPushClient.h" |
23 #include "wtf/RefPtr.h" | 23 #include "wtf/RefPtr.h" |
24 | 24 |
25 namespace blink { | 25 namespace blink { |
26 | 26 |
27 PushManager::PushManager() | 27 PushManager::PushManager() |
28 { | 28 { |
29 } | 29 } |
30 | 30 |
31 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const
String& senderId) | 31 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState) |
32 { | 32 { |
33 ASSERT(scriptState->executionContext()->isDocument()); | 33 ASSERT(scriptState->executionContext()->isDocument()); |
34 | 34 |
35 Document* document = toDocument(scriptState->executionContext()); | 35 Document* document = toDocument(scriptState->executionContext()); |
36 if (!document->domWindow() || !document->page()) | 36 if (!document->domWindow() || !document->page()) |
37 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Document is detached from window.")); | 37 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Document is detached from window.")); |
38 | 38 |
39 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se
rviceWorker(document->domWindow()->navigator())->provider(); | 39 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se
rviceWorker(document->domWindow()->navigator())->provider(); |
40 if (!serviceWorkerProvider) | 40 if (!serviceWorkerProvider) |
41 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "No Service Worker installed for this document.")); | 41 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "No Service Worker installed for this document.")); |
42 | 42 |
43 WebPushClient* client = PushController::clientFrom(document->page()); | 43 WebPushClient* client = PushController::clientFrom(document->page()); |
44 ASSERT(client); | 44 ASSERT(client); |
45 | 45 |
46 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 46 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
47 ScriptPromise promise = resolver->promise(); | 47 ScriptPromise promise = resolver->promise(); |
48 client->registerPushMessaging(senderId, new CallbackPromiseAdapter<PushRegis
tration, PushError>(resolver), serviceWorkerProvider); | 48 client->registerPushMessaging(new CallbackPromiseAdapter<PushRegistration, P
ushError>(resolver), serviceWorkerProvider); |
49 return promise; | 49 return promise; |
50 } | 50 } |
51 | 51 |
52 } // namespace blink | 52 } // namespace blink |
OLD | NEW |