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