Chromium Code Reviews| 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 "modules/push_messaging/PushSubscription.h" | 5 #include "modules/push_messaging/PushSubscription.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 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 28 matching lines...) Expand all Loading... | |
| 39 : endpoint_(subscription.endpoint), | 39 : endpoint_(subscription.endpoint), |
| 40 options_(PushSubscriptionOptions::Create(subscription.options)), | 40 options_(PushSubscriptionOptions::Create(subscription.options)), |
| 41 p256dh_(DOMArrayBuffer::Create(subscription.p256dh.Data(), | 41 p256dh_(DOMArrayBuffer::Create(subscription.p256dh.Data(), |
| 42 subscription.p256dh.size())), | 42 subscription.p256dh.size())), |
| 43 auth_(DOMArrayBuffer::Create(subscription.auth.Data(), | 43 auth_(DOMArrayBuffer::Create(subscription.auth.Data(), |
| 44 subscription.auth.size())), | 44 subscription.auth.size())), |
| 45 service_worker_registration_(service_worker_registration) {} | 45 service_worker_registration_(service_worker_registration) {} |
| 46 | 46 |
| 47 PushSubscription::~PushSubscription() {} | 47 PushSubscription::~PushSubscription() {} |
| 48 | 48 |
| 49 DOMTimeStamp PushSubscription::expirationTime(bool& is_null) const { | |
|
jochen (gone - plz use gerrit)
2017/05/05 14:35:42
why not bool*?
Peter Beverloo
2017/05/05 14:42:55
WebKit was very much about references as opposed t
| |
| 50 // This attribute reflects the time at which the subscription will expire, | |
| 51 // which is not relevant to this implementation yet as subscription refreshes | |
| 52 // are not supported. | |
| 53 is_null = true; | |
| 54 | |
| 55 return 0; | |
| 56 } | |
| 57 | |
| 49 DOMArrayBuffer* PushSubscription::getKey(const AtomicString& name) const { | 58 DOMArrayBuffer* PushSubscription::getKey(const AtomicString& name) const { |
| 50 if (name == "p256dh") | 59 if (name == "p256dh") |
| 51 return p256dh_; | 60 return p256dh_; |
| 52 if (name == "auth") | 61 if (name == "auth") |
| 53 return auth_; | 62 return auth_; |
| 54 | 63 |
| 55 return nullptr; | 64 return nullptr; |
| 56 } | 65 } |
| 57 | 66 |
| 58 ScriptPromise PushSubscription::unsubscribe(ScriptState* script_state) { | 67 ScriptPromise PushSubscription::unsubscribe(ScriptState* script_state) { |
| 59 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 68 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 60 ScriptPromise promise = resolver->Promise(); | 69 ScriptPromise promise = resolver->Promise(); |
| 61 | 70 |
| 62 WebPushProvider* web_push_provider = Platform::Current()->PushProvider(); | 71 WebPushProvider* web_push_provider = Platform::Current()->PushProvider(); |
| 63 DCHECK(web_push_provider); | 72 DCHECK(web_push_provider); |
| 64 | 73 |
| 65 web_push_provider->Unsubscribe( | 74 web_push_provider->Unsubscribe( |
| 66 service_worker_registration_->WebRegistration(), | 75 service_worker_registration_->WebRegistration(), |
| 67 WTF::MakeUnique<CallbackPromiseAdapter<bool, PushError>>(resolver)); | 76 WTF::MakeUnique<CallbackPromiseAdapter<bool, PushError>>(resolver)); |
| 68 return promise; | 77 return promise; |
| 69 } | 78 } |
| 70 | 79 |
| 71 ScriptValue PushSubscription::toJSONForBinding(ScriptState* script_state) { | 80 ScriptValue PushSubscription::toJSONForBinding(ScriptState* script_state) { |
| 72 DCHECK(p256dh_); | 81 DCHECK(p256dh_); |
| 73 | 82 |
| 74 V8ObjectBuilder result(script_state); | 83 V8ObjectBuilder result(script_state); |
| 75 result.AddString("endpoint", endpoint()); | 84 result.AddString("endpoint", endpoint()); |
| 85 result.AddNull("expirationTime"); | |
| 76 | 86 |
| 77 V8ObjectBuilder keys(script_state); | 87 V8ObjectBuilder keys(script_state); |
| 78 keys.Add("p256dh", | 88 keys.Add("p256dh", |
| 79 WTF::Base64URLEncode(static_cast<const char*>(p256dh_->Data()), | 89 WTF::Base64URLEncode(static_cast<const char*>(p256dh_->Data()), |
| 80 p256dh_->ByteLength())); | 90 p256dh_->ByteLength())); |
| 81 keys.Add("auth", WTF::Base64URLEncode(static_cast<const char*>(auth_->Data()), | 91 keys.Add("auth", WTF::Base64URLEncode(static_cast<const char*>(auth_->Data()), |
| 82 auth_->ByteLength())); | 92 auth_->ByteLength())); |
| 83 result.Add("keys", keys); | 93 result.Add("keys", keys); |
| 84 | 94 |
| 85 return result.GetScriptValue(); | 95 return result.GetScriptValue(); |
| 86 } | 96 } |
| 87 | 97 |
| 88 DEFINE_TRACE(PushSubscription) { | 98 DEFINE_TRACE(PushSubscription) { |
| 89 visitor->Trace(options_); | 99 visitor->Trace(options_); |
| 90 visitor->Trace(p256dh_); | 100 visitor->Trace(p256dh_); |
| 91 visitor->Trace(auth_); | 101 visitor->Trace(auth_); |
| 92 visitor->Trace(service_worker_registration_); | 102 visitor->Trace(service_worker_registration_); |
| 93 } | 103 } |
| 94 | 104 |
| 95 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |