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 |
26 | |
Michael van Ouwerkerk
2014/10/20 11:25:42
nit: delete this extra empty line
Miguel Garcia
2014/10/22 12:58:43
Done.
| |
25 namespace blink { | 27 namespace blink { |
26 | 28 |
27 PushManager::PushManager() | 29 PushManager::PushManager() |
28 { | 30 { |
29 } | 31 } |
30 | 32 |
33 // FIXME: This calls should be available from workers which will not have a Docu ment object available. | |
Michael van Ouwerkerk
2014/10/20 11:25:42
nit: s/This/These/
Michael van Ouwerkerk
2014/10/20 11:25:42
crbug.com/389194
Miguel Garcia
2014/10/22 12:58:43
Done.
| |
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 calls should be available from workers which will not have a Docu ment object available. | |
Michael van Ouwerkerk
2014/10/20 11:25:42
nit: same as above
Miguel Garcia
2014/10/22 12:58:43
Done.
| |
56 ScriptPromise PushManager::hasPermission(ScriptState* scriptState) | |
57 { | |
58 ASSERT(scriptState->executionContext()->isDocument()); | |
59 | |
60 Document* document = toDocument(scriptState->executionContext()); | |
61 if (!document->domWindow() || !document->page()) | |
62 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Document is detached from window.")); | |
63 blink::WebPushClient* client = PushController::clientFrom(document->page()); | |
64 ASSERT(client); | |
65 | |
66 WebServiceWorkerProvider* serviceWorkerProvider = NavigatorServiceWorker::se rviceWorker(document->domWindow()->navigator())->provider(); | |
67 if (!serviceWorkerProvider) | |
68 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "No Service Worker installed for this document.")); | |
Michael van Ouwerkerk
2014/10/20 11:25:42
The spec says to not provide any arguments when re
Peter Beverloo
2014/10/20 12:23:49
We don't care at all about whether there's a Servi
Miguel Garcia
2014/10/22 12:58:43
mm I don't know, we use the service worker stuff l
Michael van Ouwerkerk
2014/10/22 13:20:01
You could take the origin from the RenderFrameHost
Michael van Ouwerkerk
2014/10/22 15:52:45
Ok on further discussion... in future, when called
| |
69 | |
70 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
71 | |
72 client->permissionStatus(new PushPermissionCallback(resolver), serviceWorker Provider); | |
Michael van Ouwerkerk
2014/10/20 11:25:42
It's not a simple getter is it? Then please name t
Miguel Garcia
2014/10/22 12:58:43
Done.
| |
73 return resolver->promise(); | |
74 } | |
75 | |
52 } // namespace blink | 76 } // namespace blink |
OLD | NEW |