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/PushSubscription.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 "bindings/core/v8/V8ObjectBuilder.h" | 10 #include "bindings/core/v8/V8ObjectBuilder.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 : m_endpoint(endpoint) | 33 : m_endpoint(endpoint) |
34 , m_subscriptionId(subscriptionId) | 34 , m_subscriptionId(subscriptionId) |
35 , m_serviceWorkerRegistration(serviceWorkerRegistration) | 35 , m_serviceWorkerRegistration(serviceWorkerRegistration) |
36 { | 36 { |
37 } | 37 } |
38 | 38 |
39 PushSubscription::~PushSubscription() | 39 PushSubscription::~PushSubscription() |
40 { | 40 { |
41 } | 41 } |
42 | 42 |
| 43 String PushSubscription::endpoint() const |
| 44 { |
| 45 // TODO(peter): Remove all plumbing which separates the endpoint from the su
bscriptionId |
| 46 // after the deprecation period has finished. https://crbug.com/477401. |
| 47 return m_endpoint + "/" + m_subscriptionId; |
| 48 } |
| 49 |
43 ScriptPromise PushSubscription::unsubscribe(ScriptState* scriptState) | 50 ScriptPromise PushSubscription::unsubscribe(ScriptState* scriptState) |
44 { | 51 { |
45 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 52 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
46 ScriptPromise promise = resolver->promise(); | 53 ScriptPromise promise = resolver->promise(); |
47 | 54 |
48 WebPushProvider* webPushProvider = Platform::current()->pushProvider(); | 55 WebPushProvider* webPushProvider = Platform::current()->pushProvider(); |
49 ASSERT(webPushProvider); | 56 ASSERT(webPushProvider); |
50 | 57 |
51 webPushProvider->unregister(m_serviceWorkerRegistration->webRegistration(),
new CallbackPromiseAdapter<bool, PushError>(resolver)); | 58 webPushProvider->unregister(m_serviceWorkerRegistration->webRegistration(),
new CallbackPromiseAdapter<bool, PushError>(resolver)); |
52 return promise; | 59 return promise; |
53 } | 60 } |
54 | 61 |
55 ScriptValue PushSubscription::toJSONForBinding(ScriptState* scriptState) | 62 ScriptValue PushSubscription::toJSONForBinding(ScriptState* scriptState) |
56 { | 63 { |
57 V8ObjectBuilder result(scriptState); | 64 V8ObjectBuilder result(scriptState); |
58 result.addString("endpoint", m_endpoint); | 65 result.addString("endpoint", endpoint()); |
59 result.addString("subscriptionId", m_subscriptionId); | 66 result.addString("subscriptionId", subscriptionId()); |
60 | 67 |
61 return result.scriptValue(); | 68 return result.scriptValue(); |
62 } | 69 } |
63 | 70 |
64 DEFINE_TRACE(PushSubscription) | 71 DEFINE_TRACE(PushSubscription) |
65 { | 72 { |
66 visitor->trace(m_serviceWorkerRegistration); | 73 visitor->trace(m_serviceWorkerRegistration); |
67 } | 74 } |
68 | 75 |
69 } // namespace blink | 76 } // namespace blink |
OLD | NEW |