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 "core/frame/LocalDOMWindow.h" | 16 #include "core/frame/LocalDOMWindow.h" |
17 #include "modules/push_messaging/PushController.h" | 17 #include "modules/push_messaging/PushController.h" |
18 #include "modules/push_messaging/PushError.h" | 18 #include "modules/push_messaging/PushError.h" |
19 #include "modules/push_messaging/PushRegistration.h" | 19 #include "modules/push_messaging/PushRegistration.h" |
20 #include "modules/serviceworkers/NavigatorServiceWorker.h" | 20 #include "modules/serviceworkers/NavigatorServiceWorker.h" |
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 ScriptWrappable::init(this); | |
30 } | 29 } |
31 | 30 |
32 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const
String& senderId) | 31 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const
String& senderId) |
33 { | 32 { |
34 ASSERT(scriptState->executionContext()->isDocument()); | 33 ASSERT(scriptState->executionContext()->isDocument()); |
35 | 34 |
36 Document* document = toDocument(scriptState->executionContext()); | 35 Document* document = toDocument(scriptState->executionContext()); |
37 if (!document->domWindow() || !document->page()) | 36 if (!document->domWindow() || !document->page()) |
38 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.")); |
39 | 38 |
40 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se
rviceWorker(document->domWindow()->navigator())->provider(); | 39 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se
rviceWorker(document->domWindow()->navigator())->provider(); |
41 if (!serviceWorkerProvider) | 40 if (!serviceWorkerProvider) |
42 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.")); |
43 | 42 |
44 WebPushClient* client = PushController::clientFrom(document->page()); | 43 WebPushClient* client = PushController::clientFrom(document->page()); |
45 ASSERT(client); | 44 ASSERT(client); |
46 | 45 |
47 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 46 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
48 ScriptPromise promise = resolver->promise(); | 47 ScriptPromise promise = resolver->promise(); |
49 client->registerPushMessaging(senderId, new CallbackPromiseAdapter<PushRegis
tration, PushError>(resolver), serviceWorkerProvider); | 48 client->registerPushMessaging(senderId, new CallbackPromiseAdapter<PushRegis
tration, PushError>(resolver), serviceWorkerProvider); |
50 return promise; | 49 return promise; |
51 } | 50 } |
52 | 51 |
53 } // namespace blink | 52 } // namespace blink |
OLD | NEW |