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/PushPermissionCallback.h" | |
19 #include "modules/push_messaging/PushRegistration.h" | 20 #include "modules/push_messaging/PushRegistration.h" |
20 #include "modules/serviceworkers/NavigatorServiceWorker.h" | 21 #include "modules/serviceworkers/NavigatorServiceWorker.h" |
21 #include "modules/serviceworkers/ServiceWorkerContainer.h" | 22 #include "modules/serviceworkers/ServiceWorkerContainer.h" |
22 #include "public/platform/WebPushClient.h" | 23 #include "public/platform/WebPushClient.h" |
23 #include "wtf/RefPtr.h" | 24 #include "wtf/RefPtr.h" |
24 | 25 |
25 namespace blink { | 26 namespace blink { |
26 | 27 |
27 PushManager::PushManager() | 28 PushManager::PushManager() |
28 { | 29 { |
29 } | 30 } |
30 | 31 |
32 // FIXME: This call should be available from workers which will not have a Docum ent object available. | |
33 // See crbug.com/389194 | |
31 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const String& senderId) | 34 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState, const String& senderId) |
32 { | 35 { |
33 ASSERT(scriptState->executionContext()->isDocument()); | 36 ASSERT(scriptState->executionContext()->isDocument()); |
34 | 37 |
35 Document* document = toDocument(scriptState->executionContext()); | 38 Document* document = toDocument(scriptState->executionContext()); |
36 if (!document->domWindow() || !document->page()) | 39 if (!document->domWindow() || !document->page()) |
37 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.")); |
38 | 41 |
39 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se rviceWorker(document->domWindow()->navigator())->provider(); | 42 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se rviceWorker(document->domWindow()->navigator())->provider(); |
40 if (!serviceWorkerProvider) | 43 if (!serviceWorkerProvider) |
41 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.")); |
42 | 45 |
43 WebPushClient* client = PushController::clientFrom(document->page()); | 46 WebPushClient* client = PushController::clientFrom(document->page()); |
44 ASSERT(client); | 47 ASSERT(client); |
45 | 48 |
46 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | 49 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); |
47 ScriptPromise promise = resolver->promise(); | 50 ScriptPromise promise = resolver->promise(); |
48 client->registerPushMessaging(senderId, new CallbackPromiseAdapter<PushRegis tration, PushError>(resolver), serviceWorkerProvider); | 51 client->registerPushMessaging(senderId, new CallbackPromiseAdapter<PushRegis tration, PushError>(resolver), serviceWorkerProvider); |
49 return promise; | 52 return promise; |
50 } | 53 } |
51 | 54 |
55 // FIXME: This call should be available from workers which will not have a Docum ent object available. | |
56 // See crbug.com/389194 | |
57 ScriptPromise PushManager::hasPermission(ScriptState* scriptState) | |
58 { | |
59 ASSERT(scriptState->executionContext()->isDocument()); | |
60 | |
61 Document* document = toDocument(scriptState->executionContext()); | |
62 if (!document->domWindow() || !document->page()) | |
63 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Document is detached from window.")); | |
64 blink::WebPushClient* client = PushController::clientFrom(document->page()); | |
65 ASSERT(client); | |
66 | |
67 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se rviceWorker(document->domWindow()->navigator())->provider(); | |
Peter Beverloo
2014/10/23 11:33:37
Please add a note here explicitly saying that the
Miguel Garcia
2014/10/23 13:59:51
Done.
| |
68 if (!serviceWorkerProvider) | |
69 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "No Service Worker installed for this document.")); | |
70 | |
71 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
72 | |
73 client->getPermissionStatus(new PushPermissionCallback(resolver), serviceWor kerProvider); | |
74 return resolver->promise(); | |
75 } | |
76 | |
52 } // namespace blink | 77 } // namespace blink |
OLD | NEW |