OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "modules/push_messaging/PushRegistration.h" | |
7 | |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
10 #include "modules/push_messaging/PushError.h" | |
11 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | |
12 #include "public/platform/Platform.h" | |
13 #include "public/platform/WebPushProvider.h" | |
14 #include "public/platform/WebPushRegistration.h" | |
15 #include "wtf/OwnPtr.h" | |
16 | |
17 namespace blink { | |
18 | |
19 PushRegistration* PushRegistration::take(ScriptPromiseResolver*, WebPushRegistra
tion* pushRegistration, ServiceWorkerRegistration* serviceWorkerRegistration) | |
20 { | |
21 OwnPtr<WebPushRegistration> registration = adoptPtr(pushRegistration); | |
22 return new PushRegistration(registration->endpoint, registration->registrati
onId, serviceWorkerRegistration); | |
23 } | |
24 | |
25 void PushRegistration::dispose(WebPushRegistration* pushRegistration) | |
26 { | |
27 if (pushRegistration) | |
28 delete pushRegistration; | |
29 } | |
30 | |
31 PushRegistration::PushRegistration(const String& endpoint, const String& registr
ationId, ServiceWorkerRegistration* serviceWorkerRegistration) | |
32 : m_endpoint(endpoint) | |
33 , m_registrationId(registrationId) | |
34 , m_serviceWorkerRegistration(serviceWorkerRegistration) | |
35 { | |
36 } | |
37 | |
38 PushRegistration::~PushRegistration() | |
39 { | |
40 } | |
41 | |
42 ScriptPromise PushRegistration::unregister(ScriptState* scriptState) | |
43 { | |
44 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | |
45 ScriptPromise promise = resolver->promise(); | |
46 | |
47 WebPushProvider* webPushProvider = Platform::current()->pushProvider(); | |
48 ASSERT(webPushProvider); | |
49 | |
50 webPushProvider->unregister(m_serviceWorkerRegistration->webRegistration(),
new CallbackPromiseAdapter<bool, PushError>(resolver)); | |
51 return promise; | |
52 } | |
53 | |
54 void PushRegistration::trace(Visitor* visitor) | |
55 { | |
56 visitor->trace(m_serviceWorkerRegistration); | |
57 } | |
58 | |
59 } // namespace blink | |
OLD | NEW |