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 11 matching lines...) Expand all Loading... |
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); | 29 ScriptWrappable::init(this); |
30 } | 30 } |
31 | 31 |
32 PushManager::~PushManager() | |
33 { | |
34 } | |
35 | |
36 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const
String& senderId) | 32 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const
String& senderId) |
37 { | 33 { |
38 ASSERT(scriptState->executionContext()->isDocument()); | 34 ASSERT(scriptState->executionContext()->isDocument()); |
39 | 35 |
40 Document* document = toDocument(scriptState->executionContext()); | 36 Document* document = toDocument(scriptState->executionContext()); |
41 if (!document->domWindow() || !document->page()) | 37 if (!document->domWindow() || !document->page()) |
42 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Document is detached from window.")); | 38 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Document is detached from window.")); |
43 | 39 |
44 blink::WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWor
ker::serviceWorker(document->domWindow()->navigator())->provider(); | 40 blink::WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWor
ker::serviceWorker(document->domWindow()->navigator())->provider(); |
45 if (!serviceWorkerProvider) | 41 if (!serviceWorkerProvider) |
46 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "No Service Worker installed for this document.")); | 42 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "No Service Worker installed for this document.")); |
47 | 43 |
48 blink::WebPushClient* client = PushController::clientFrom(document->page()); | 44 blink::WebPushClient* client = PushController::clientFrom(document->page()); |
49 ASSERT(client); | 45 ASSERT(client); |
50 | 46 |
51 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 47 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
52 ScriptPromise promise = resolver->promise(); | 48 ScriptPromise promise = resolver->promise(); |
53 client->registerPushMessaging(senderId, new CallbackPromiseAdapter<PushRegis
tration, PushError>(resolver), serviceWorkerProvider); | 49 client->registerPushMessaging(senderId, new CallbackPromiseAdapter<PushRegis
tration, PushError>(resolver), serviceWorkerProvider); |
54 return promise; | 50 return promise; |
55 } | 51 } |
56 | 52 |
57 } // namespace blink | 53 } // namespace blink |
OLD | NEW |