|
17 | 17 | #include "mozilla/dom/Promise.h" |
18 | 18 | #include "mozilla/dom/PromiseWorkerProxy.h" |
19 | 19 | #include "mozilla/dom/PushSubscriptionOptions.h" |
| 20 | +#include "mozilla/dom/PushUtil.h" |
20 | 21 | #include "mozilla/dom/WorkerCommon.h" |
21 | 22 | #include "mozilla/dom/WorkerPrivate.h" |
22 | 23 | #include "mozilla/dom/WorkerRunnable.h" |
@@ -230,30 +231,36 @@ already_AddRefed<PushSubscription> PushSubscription::Constructor( |
230 | 231 |
|
231 | 232 | nsTArray<uint8_t> rawKey; |
232 | 233 | if (aInitDict.mP256dhKey.WasPassed() && |
233 | | - !aInitDict.mP256dhKey.Value().AppendDataTo(rawKey)) { |
| 234 | + !aInitDict.mP256dhKey.Value().IsNull() && |
| 235 | + !aInitDict.mP256dhKey.Value().Value().AppendDataTo(rawKey)) { |
234 | 236 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
235 | 237 | return nullptr; |
236 | 238 | } |
237 | 239 |
|
238 | 240 | nsTArray<uint8_t> authSecret; |
239 | 241 | if (aInitDict.mAuthSecret.WasPassed() && |
240 | | - !aInitDict.mAuthSecret.Value().AppendDataTo(authSecret)) { |
| 242 | + !aInitDict.mAuthSecret.Value().IsNull() && |
| 243 | + !aInitDict.mAuthSecret.Value().Value().AppendDataTo(authSecret)) { |
241 | 244 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
242 | 245 | return nullptr; |
243 | 246 | } |
244 | 247 |
|
245 | 248 | nsTArray<uint8_t> appServerKey; |
246 | 249 | if (aInitDict.mAppServerKey.WasPassed() && |
247 | | - !AppendTypedArrayDataTo(aInitDict.mAppServerKey.Value(), appServerKey)) { |
248 | | - aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
249 | | - return nullptr; |
| 250 | + !aInitDict.mAppServerKey.Value().IsNull()) { |
| 251 | + const OwningArrayBufferViewOrArrayBuffer& bufferSource = |
| 252 | + aInitDict.mAppServerKey.Value().Value(); |
| 253 | + if (!PushUtil::CopyBufferSourceToArray(bufferSource, appServerKey)) { |
| 254 | + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
| 255 | + return nullptr; |
| 256 | + } |
250 | 257 | } |
251 | 258 |
|
252 | 259 | Nullable<EpochTimeStamp> expirationTime; |
253 | | - if (aInitDict.mExpirationTime.WasPassed()) { |
254 | | - expirationTime.SetValue(aInitDict.mExpirationTime.Value()); |
255 | | - } else { |
| 260 | + if (aInitDict.mExpirationTime.IsNull()) { |
256 | 261 | expirationTime.SetNull(); |
| 262 | + } else { |
| 263 | + expirationTime.SetValue(aInitDict.mExpirationTime.Value()); |
257 | 264 | } |
258 | 265 |
|
259 | 266 | RefPtr<PushSubscription> sub = new PushSubscription( |
@@ -300,10 +307,10 @@ already_AddRefed<Promise> PushSubscription::Unsubscribe(ErrorResult& aRv) { |
300 | 307 | void PushSubscription::GetKey(JSContext* aCx, PushEncryptionKeyName aType, |
301 | 308 | JS::MutableHandle<JSObject*> aKey, |
302 | 309 | ErrorResult& aRv) { |
303 | | - if (aType == PushEncryptionKeyName::P256dh && !mRawP256dhKey.IsEmpty()) { |
304 | | - aKey.set(ArrayBuffer::Create(aCx, mRawP256dhKey, aRv)); |
305 | | - } else if (aType == PushEncryptionKeyName::Auth && !mAuthSecret.IsEmpty()) { |
306 | | - aKey.set(ArrayBuffer::Create(aCx, mAuthSecret, aRv)); |
| 310 | + if (aType == PushEncryptionKeyName::P256dh) { |
| 311 | + PushUtil::CopyArrayToArrayBuffer(aCx, mRawP256dhKey, aKey, aRv); |
| 312 | + } else if (aType == PushEncryptionKeyName::Auth) { |
| 313 | + PushUtil::CopyArrayToArrayBuffer(aCx, mAuthSecret, aKey, aRv); |
307 | 314 | } else { |
308 | 315 | aKey.set(nullptr); |
309 | 316 | } |
|
0 commit comments