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

Commit e922e7a

Browse files
author
pstanciu
committed
Backed out changeset 669ac95baa5d (bug 1264508) for causing build bustages on PushSubscriptionOptions.cpp CLOSED TREE
1 parent 5568556 commit e922e7a

File tree

8 files changed

+107
-17
lines changed

8 files changed

+107
-17
lines changed

dom/push/PushManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "mozilla/dom/PushManagerBinding.h"
1515
#include "mozilla/dom/PushSubscription.h"
1616
#include "mozilla/dom/PushSubscriptionOptionsBinding.h"
17+
#include "mozilla/dom/PushUtil.h"
1718
#include "mozilla/dom/RootedDictionary.h"
1819
#include "mozilla/dom/ServiceWorker.h"
1920
#include "mozilla/dom/WorkerRunnable.h"

dom/push/PushSubscription.cpp

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

231232
nsTArray<uint8_t> rawKey;
232233
if (aInitDict.mP256dhKey.WasPassed() &&
233-
!aInitDict.mP256dhKey.Value().AppendDataTo(rawKey)) {
234+
!aInitDict.mP256dhKey.Value().IsNull() &&
235+
!aInitDict.mP256dhKey.Value().Value().AppendDataTo(rawKey)) {
234236
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
235237
return nullptr;
236238
}
237239

238240
nsTArray<uint8_t> authSecret;
239241
if (aInitDict.mAuthSecret.WasPassed() &&
240-
!aInitDict.mAuthSecret.Value().AppendDataTo(authSecret)) {
242+
!aInitDict.mAuthSecret.Value().IsNull() &&
243+
!aInitDict.mAuthSecret.Value().Value().AppendDataTo(authSecret)) {
241244
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
242245
return nullptr;
243246
}
244247

245248
nsTArray<uint8_t> appServerKey;
246249
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+
}
250257
}
251258

252259
Nullable<EpochTimeStamp> expirationTime;
253-
if (aInitDict.mExpirationTime.WasPassed()) {
254-
expirationTime.SetValue(aInitDict.mExpirationTime.Value());
255-
} else {
260+
if (aInitDict.mExpirationTime.IsNull()) {
256261
expirationTime.SetNull();
262+
} else {
263+
expirationTime.SetValue(aInitDict.mExpirationTime.Value());
257264
}
258265

259266
RefPtr<PushSubscription> sub = new PushSubscription(
@@ -300,10 +307,10 @@ already_AddRefed<Promise> PushSubscription::Unsubscribe(ErrorResult& aRv) {
300307
void PushSubscription::GetKey(JSContext* aCx, PushEncryptionKeyName aType,
301308
JS::MutableHandle<JSObject*> aKey,
302309
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);
307314
} else {
308315
aKey.set(nullptr);
309316
}

dom/push/PushSubscriptionOptions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "mozilla/dom/PushSubscriptionOptionsBinding.h"
1111
#include "mozilla/ErrorResult.h"
1212
#include "mozilla/HoldDropJSObjects.h"
13+
#include "mozilla/dom/PushUtil.h"
1314
#include "nsIGlobalObject.h"
1415
#include "nsWrapperCache.h"
1516

@@ -50,10 +51,13 @@ JSObject* PushSubscriptionOptions::WrapObject(
5051
void PushSubscriptionOptions::GetApplicationServerKey(
5152
JSContext* aCx, JS::MutableHandle<JSObject*> aKey, ErrorResult& aRv) {
5253
if (!mRawAppServerKey.IsEmpty() && !mAppServerKey) {
53-
mAppServerKey = ArrayBuffer::Create(aCx, mRawAppServerKey, aRv);
54+
JS::Rooted<JSObject*> appServerKey(aCx);
55+
PushUtil::CopyArrayToArrayBuffer(aCx, mRawAppServerKey, &appServerKey, aRv);
5456
if (aRv.Failed()) {
5557
return;
5658
}
59+
MOZ_ASSERT(appServerKey);
60+
mAppServerKey = appServerKey;
5761
}
5862
aKey.set(mAppServerKey);
5963
}

dom/push/PushUtil.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3+
/* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6+
7+
#include "mozilla/dom/PushUtil.h"
8+
#include "mozilla/dom/UnionTypes.h"
9+
10+
namespace mozilla::dom {
11+
12+
/* static */
13+
bool PushUtil::CopyBufferSourceToArray(
14+
const OwningArrayBufferViewOrArrayBuffer& aSource,
15+
nsTArray<uint8_t>& aArray) {
16+
MOZ_ASSERT(aArray.IsEmpty());
17+
return AppendTypedArrayDataTo(aSource, aArray);
18+
}
19+
20+
/* static */
21+
void PushUtil::CopyArrayToArrayBuffer(JSContext* aCx,
22+
const nsTArray<uint8_t>& aArray,
23+
JS::MutableHandle<JSObject*> aValue,
24+
ErrorResult& aRv) {
25+
if (aArray.IsEmpty()) {
26+
aValue.set(nullptr);
27+
return;
28+
}
29+
JS::Rooted<JSObject*> buffer(aCx, ArrayBuffer::Create(aCx, aArray, aRv));
30+
if (NS_WARN_IF(aRv.Failed())) {
31+
return;
32+
}
33+
aValue.set(buffer);
34+
}
35+
36+
} // namespace mozilla::dom

dom/push/PushUtil.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3+
/* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6+
7+
#ifndef mozilla_dom_PushUtil_h
8+
#define mozilla_dom_PushUtil_h
9+
10+
#include "nsTArray.h"
11+
12+
#include "mozilla/dom/TypedArray.h"
13+
14+
namespace mozilla {
15+
class ErrorResult;
16+
17+
namespace dom {
18+
19+
class OwningArrayBufferViewOrArrayBuffer;
20+
21+
class PushUtil final {
22+
private:
23+
PushUtil() = delete;
24+
25+
public:
26+
static bool CopyBufferSourceToArray(
27+
const OwningArrayBufferViewOrArrayBuffer& aSource,
28+
nsTArray<uint8_t>& aArray);
29+
30+
static void CopyArrayToArrayBuffer(JSContext* aCx,
31+
const nsTArray<uint8_t>& aArray,
32+
JS::MutableHandle<JSObject*> aValue,
33+
ErrorResult& aRv);
34+
};
35+
36+
} // namespace dom
37+
} // namespace mozilla
38+
39+
#endif // mozilla_dom_PushUtil_h

dom/push/moz.build

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

4950
UNIFIED_SOURCES += [
5051
"PushManager.cpp",
5152
"PushNotifier.cpp",
5253
"PushSubscription.cpp",
5354
"PushSubscriptionOptions.cpp",
55+
"PushUtil.cpp",
5456
]
5557

5658
TEST_DIRS += ["test/xpcshell"]

dom/serviceworkers/ServiceWorkerEvents.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "mozilla/dom/PromiseNativeHandler.h"
2727
#include "mozilla/dom/PushEventBinding.h"
2828
#include "mozilla/dom/PushMessageDataBinding.h"
29+
#include "mozilla/dom/PushUtil.h"
2930
#include "mozilla/dom/Request.h"
3031
#include "mozilla/dom/Response.h"
3132
#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;
38+
ArrayBuffer? p256dhKey;
39+
ArrayBuffer? authSecret;
40+
BufferSource? appServerKey;
41+
EpochTimeStamp? expirationTime = null;
4242
};
4343

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

0 commit comments

Comments
 (0)