Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 3ede13d

Browse files
Bug 1264508 - Use generic helpers for converting ArrayBuffer or BufferSource to/from nsTArray in Push API code. r=webidl,saschanaz
Differential Revision: https://phabricator.services.mozilla.com/D207176
1 parent 7838c13 commit 3ede13d

File tree

8 files changed

+17
-107
lines changed

8 files changed

+17
-107
lines changed

dom/push/PushManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "mozilla/dom/PushManagerBinding.h"
1515
#include "mozilla/dom/PushSubscription.h"
1616
#include "mozilla/dom/PushSubscriptionOptionsBinding.h"
17-
#include "mozilla/dom/PushUtil.h"
1817
#include "mozilla/dom/RootedDictionary.h"
1918
#include "mozilla/dom/ServiceWorker.h"
2019
#include "mozilla/dom/WorkerRunnable.h"

dom/push/PushSubscription.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "mozilla/dom/Promise.h"
1818
#include "mozilla/dom/PromiseWorkerProxy.h"
1919
#include "mozilla/dom/PushSubscriptionOptions.h"
20-
#include "mozilla/dom/PushUtil.h"
2120
#include "mozilla/dom/WorkerCommon.h"
2221
#include "mozilla/dom/WorkerPrivate.h"
2322
#include "mozilla/dom/WorkerRunnable.h"
@@ -231,36 +230,30 @@ already_AddRefed<PushSubscription> PushSubscription::Constructor(
231230

232231
nsTArray<uint8_t> rawKey;
233232
if (aInitDict.mP256dhKey.WasPassed() &&
234-
!aInitDict.mP256dhKey.Value().IsNull() &&
235-
!aInitDict.mP256dhKey.Value().Value().AppendDataTo(rawKey)) {
233+
!aInitDict.mP256dhKey.Value().AppendDataTo(rawKey)) {
236234
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
237235
return nullptr;
238236
}
239237

240238
nsTArray<uint8_t> authSecret;
241239
if (aInitDict.mAuthSecret.WasPassed() &&
242-
!aInitDict.mAuthSecret.Value().IsNull() &&
243-
!aInitDict.mAuthSecret.Value().Value().AppendDataTo(authSecret)) {
240+
!aInitDict.mAuthSecret.Value().AppendDataTo(authSecret)) {
244241
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
245242
return nullptr;
246243
}
247244

248245
nsTArray<uint8_t> appServerKey;
249246
if (aInitDict.mAppServerKey.WasPassed() &&
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-
}
247+
!AppendTypedArrayDataTo(aInitDict.mAppServerKey.Value(), appServerKey)) {
248+
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
249+
return nullptr;
257250
}
258251

259252
Nullable<EpochTimeStamp> expirationTime;
260-
if (aInitDict.mExpirationTime.IsNull()) {
261-
expirationTime.SetNull();
262-
} else {
253+
if (aInitDict.mExpirationTime.WasPassed()) {
263254
expirationTime.SetValue(aInitDict.mExpirationTime.Value());
255+
} else {
256+
expirationTime.SetNull();
264257
}
265258

266259
RefPtr<PushSubscription> sub = new PushSubscription(
@@ -307,10 +300,10 @@ already_AddRefed<Promise> PushSubscription::Unsubscribe(ErrorResult& aRv) {
307300
void PushSubscription::GetKey(JSContext* aCx, PushEncryptionKeyName aType,
308301
JS::MutableHandle<JSObject*> aKey,
309302
ErrorResult& 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);
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));
314307
} else {
315308
aKey.set(nullptr);
316309
}

dom/push/PushSubscriptionOptions.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "mozilla/dom/PushSubscriptionOptionsBinding.h"
1111
#include "mozilla/ErrorResult.h"
1212
#include "mozilla/HoldDropJSObjects.h"
13-
#include "mozilla/dom/PushUtil.h"
1413
#include "nsIGlobalObject.h"
1514
#include "nsWrapperCache.h"
1615

@@ -51,13 +50,10 @@ JSObject* PushSubscriptionOptions::WrapObject(
5150
void PushSubscriptionOptions::GetApplicationServerKey(
5251
JSContext* aCx, JS::MutableHandle<JSObject*> aKey, ErrorResult& aRv) {
5352
if (!mRawAppServerKey.IsEmpty() && !mAppServerKey) {
54-
JS::Rooted<JSObject*> appServerKey(aCx);
55-
PushUtil::CopyArrayToArrayBuffer(aCx, mRawAppServerKey, &appServerKey, aRv);
53+
mAppServerKey = ArrayBuffer::Create(aCx, mRawAppServerKey, aRv);
5654
if (aRv.Failed()) {
5755
return;
5856
}
59-
MOZ_ASSERT(appServerKey);
60-
mAppServerKey = appServerKey;
6157
}
6258
aKey.set(mAppServerKey);
6359
}

dom/push/PushUtil.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.

dom/push/PushUtil.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

dom/push/moz.build

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ EXPORTS.mozilla.dom += [
4444
"PushNotifier.h",
4545
"PushSubscription.h",
4646
"PushSubscriptionOptions.h",
47-
"PushUtil.h",
4847
]
4948

5049
UNIFIED_SOURCES += [
5150
"PushManager.cpp",
5251
"PushNotifier.cpp",
5352
"PushSubscription.cpp",
5453
"PushSubscriptionOptions.cpp",
55-
"PushUtil.cpp",
5654
]
5755

5856
TEST_DIRS += ["test/xpcshell"]

dom/serviceworkers/ServiceWorkerEvents.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "mozilla/dom/PromiseNativeHandler.h"
2727
#include "mozilla/dom/PushEventBinding.h"
2828
#include "mozilla/dom/PushMessageDataBinding.h"
29-
#include "mozilla/dom/PushUtil.h"
3029
#include "mozilla/dom/Request.h"
3130
#include "mozilla/dom/Response.h"
3231
#include "mozilla/dom/ServiceWorkerOp.h"

dom/webidl/PushSubscription.webidl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ dictionary PushSubscriptionInit
3535
{
3636
required USVString endpoint;
3737
required USVString scope;
38-
ArrayBuffer? p256dhKey;
39-
ArrayBuffer? authSecret;
40-
BufferSource? appServerKey;
41-
EpochTimeStamp? expirationTime = null;
38+
ArrayBuffer p256dhKey;
39+
ArrayBuffer authSecret;
40+
BufferSource appServerKey;
41+
EpochTimeStamp expirationTime;
4242
};
4343

4444
[Exposed=(Window,Worker), Func="ServiceWorkerVisible"]

0 commit comments

Comments
 (0)