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