Skip to content

Commit 4281024

Browse files
committed
Bug 1497431 - Implement PushManager.prototype.expirationTime + toJSON() r=mt,peterv
Adds expirationTime to PushManager, which uses EpochTimeStamp. See w3c/push-api#338 Differential Revision: https://phabricator.services.mozilla.com/D128046
1 parent dac29e9 commit 4281024

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

dom/push/PushManager.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class GetSubscriptionResultRunnable final : public WorkerRunnable {
9898
RefPtr<PromiseWorkerProxy>&& aProxy,
9999
nsresult aStatus, const nsAString& aEndpoint,
100100
const nsAString& aScope,
101+
Nullable<EpochTimeStamp>&& aExpirationTime,
101102
nsTArray<uint8_t>&& aRawP256dhKey,
102103
nsTArray<uint8_t>&& aAuthSecret,
103104
nsTArray<uint8_t>&& aAppServerKey)
@@ -106,6 +107,7 @@ class GetSubscriptionResultRunnable final : public WorkerRunnable {
106107
mStatus(aStatus),
107108
mEndpoint(aEndpoint),
108109
mScope(aScope),
110+
mExpirationTime(std::move(aExpirationTime)),
109111
mRawP256dhKey(std::move(aRawP256dhKey)),
110112
mAuthSecret(std::move(aAuthSecret)),
111113
mAppServerKey(std::move(aAppServerKey)) {}
@@ -117,8 +119,9 @@ class GetSubscriptionResultRunnable final : public WorkerRunnable {
117119
promise->MaybeResolve(JS::NullHandleValue);
118120
} else {
119121
RefPtr<PushSubscription> sub = new PushSubscription(
120-
nullptr, mEndpoint, mScope, std::move(mRawP256dhKey),
121-
std::move(mAuthSecret), std::move(mAppServerKey));
122+
nullptr, mEndpoint, mScope, std::move(mExpirationTime),
123+
std::move(mRawP256dhKey), std::move(mAuthSecret),
124+
std::move(mAppServerKey));
122125
promise->MaybeResolve(sub);
123126
}
124127
} else if (NS_ERROR_GET_MODULE(mStatus) == NS_ERROR_MODULE_DOM_PUSH) {
@@ -139,6 +142,7 @@ class GetSubscriptionResultRunnable final : public WorkerRunnable {
139142
nsresult mStatus;
140143
nsString mEndpoint;
141144
nsString mScope;
145+
Nullable<EpochTimeStamp> mExpirationTime;
142146
nsTArray<uint8_t> mRawP256dhKey;
143147
nsTArray<uint8_t> mAuthSecret;
144148
nsTArray<uint8_t> mAppServerKey;
@@ -173,8 +177,8 @@ class GetSubscriptionCallback final : public nsIPushSubscriptionCallback {
173177
WorkerPrivate* worker = mProxy->GetWorkerPrivate();
174178
RefPtr<GetSubscriptionResultRunnable> r = new GetSubscriptionResultRunnable(
175179
worker, std::move(mProxy), aStatus, endpoint, mScope,
176-
std::move(rawP256dhKey), std::move(authSecret),
177-
std::move(appServerKey));
180+
std::move(mExpirationTime), std::move(rawP256dhKey),
181+
std::move(authSecret), std::move(appServerKey));
178182
if (!r->Dispatch()) {
179183
return NS_ERROR_UNEXPECTED;
180184
}
@@ -193,6 +197,7 @@ class GetSubscriptionCallback final : public nsIPushSubscriptionCallback {
193197
private:
194198
RefPtr<PromiseWorkerProxy> mProxy;
195199
nsString mScope;
200+
Nullable<EpochTimeStamp> mExpirationTime;
196201
};
197202

198203
NS_IMPL_ISUPPORTS(GetSubscriptionCallback, nsIPushSubscriptionCallback)

dom/push/PushSubscription.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ class UnsubscribeRunnable final : public Runnable {
181181
PushSubscription::PushSubscription(nsIGlobalObject* aGlobal,
182182
const nsAString& aEndpoint,
183183
const nsAString& aScope,
184+
Nullable<EpochTimeStamp>&& aExpirationTime,
184185
nsTArray<uint8_t>&& aRawP256dhKey,
185186
nsTArray<uint8_t>&& aAuthSecret,
186187
nsTArray<uint8_t>&& aAppServerKey)
187188
: mEndpoint(aEndpoint),
188189
mScope(aScope),
190+
mExpirationTime(std::move(aExpirationTime)),
189191
mRawP256dhKey(std::move(aRawP256dhKey)),
190192
mAuthSecret(std::move(aAuthSecret)) {
191193
if (NS_IsMainThread()) {
@@ -252,9 +254,16 @@ already_AddRefed<PushSubscription> PushSubscription::Constructor(
252254
}
253255
}
254256

257+
Nullable<EpochTimeStamp> expirationTime;
258+
if (aInitDict.mExpirationTime.IsNull()) {
259+
expirationTime.SetNull();
260+
} else {
261+
expirationTime.SetValue(aInitDict.mExpirationTime.Value());
262+
}
263+
255264
RefPtr<PushSubscription> sub = new PushSubscription(
256-
global, aInitDict.mEndpoint, aInitDict.mScope, std::move(rawKey),
257-
std::move(authSecret), std::move(appServerKey));
265+
global, aInitDict.mEndpoint, aInitDict.mScope, std::move(expirationTime),
266+
std::move(rawKey), std::move(authSecret), std::move(appServerKey));
258267

259268
return sub.forget();
260269
}
@@ -325,6 +334,7 @@ void PushSubscription::ToJSON(PushSubscriptionJSON& aJSON, ErrorResult& aRv) {
325334
aRv.Throw(rv);
326335
return;
327336
}
337+
aJSON.mExpirationTime.Construct(mExpirationTime);
328338
}
329339

330340
already_AddRefed<PushSubscriptionOptions> PushSubscription::Options() {

dom/push/PushSubscription.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "mozilla/dom/PushSubscriptionBinding.h"
1919
#include "mozilla/dom/PushSubscriptionOptionsBinding.h"
2020
#include "mozilla/dom/TypedArray.h"
21+
#include "domstubs.h"
2122

2223
class nsIGlobalObject;
2324

@@ -34,7 +35,9 @@ class PushSubscription final : public nsISupports, public nsWrapperCache {
3435
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PushSubscription)
3536

3637
PushSubscription(nsIGlobalObject* aGlobal, const nsAString& aEndpoint,
37-
const nsAString& aScope, nsTArray<uint8_t>&& aP256dhKey,
38+
const nsAString& aScope,
39+
Nullable<EpochTimeStamp>&& aExpirationTime,
40+
nsTArray<uint8_t>&& aP256dhKey,
3841
nsTArray<uint8_t>&& aAuthSecret,
3942
nsTArray<uint8_t>&& aAppServerKey);
4043

@@ -48,6 +51,8 @@ class PushSubscription final : public nsISupports, public nsWrapperCache {
4851
void GetKey(JSContext* cx, PushEncryptionKeyName aType,
4952
JS::MutableHandle<JSObject*> aKey, ErrorResult& aRv);
5053

54+
Nullable<EpochTimeStamp> GetExpirationTime() { return mExpirationTime; };
55+
5156
static already_AddRefed<PushSubscription> Constructor(
5257
GlobalObject& aGlobal, const PushSubscriptionInit& aInitDict,
5358
ErrorResult& aRv);
@@ -65,6 +70,7 @@ class PushSubscription final : public nsISupports, public nsWrapperCache {
6570

6671
nsString mEndpoint;
6772
nsString mScope;
73+
Nullable<EpochTimeStamp> mExpirationTime;
6874
nsTArray<uint8_t> mRawP256dhKey;
6975
nsTArray<uint8_t> mAuthSecret;
7076
nsCOMPtr<nsIGlobalObject> mGlobal;

dom/webidl/PushSubscription.webidl

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dictionary PushSubscriptionJSON
2828
// PushSubscriptionKeys thing is not even in the spec; "keys" is a record
2929
// there.
3030
PushSubscriptionKeys keys = {};
31+
EpochTimeStamp? expirationTime;
3132
};
3233

3334
dictionary PushSubscriptionInit
@@ -37,6 +38,7 @@ dictionary PushSubscriptionInit
3738
ArrayBuffer? p256dhKey;
3839
ArrayBuffer? authSecret;
3940
BufferSource? appServerKey;
41+
EpochTimeStamp? expirationTime = null;
4042
};
4143

4244
[Exposed=(Window,Worker), Pref="dom.push.enabled"]
@@ -47,6 +49,7 @@ interface PushSubscription
4749

4850
readonly attribute USVString endpoint;
4951
readonly attribute PushSubscriptionOptions options;
52+
readonly attribute EpochTimeStamp? expirationTime;
5053
[Throws]
5154
ArrayBuffer? getKey(PushEncryptionKeyName name);
5255
[Throws, UseCounter]

testing/web-platform/meta/push-api/idlharness.https.any.js.ini

+1-14
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
[PushManager interface object length]
33
expected: FAIL
44

5-
[PushSubscription interface: attribute expirationTime]
6-
expected: FAIL
7-
85
[PushSubscription interface object length]
96
expected: FAIL
107

@@ -19,9 +16,6 @@
1916
[PushManager interface object length]
2017
expected: FAIL
2118

22-
[PushSubscription interface: attribute expirationTime]
23-
expected: FAIL
24-
2519
[PushSubscription interface object length]
2620
expected: FAIL
2721

@@ -34,13 +28,10 @@
3428

3529
[idlharness.https.any.serviceworker.html]
3630
expected:
37-
if (os == "win") and debug and not webrender and (processor == "x86_64"): ["OK", "CRASH"]
31+
if (os == "win") and debug and not webrender and (processor == "x86_64"): [OK, CRASH]
3832
[PushSubscriptionChangeEvent must be primary interface of new PushSubscriptionChangeEvent("pushsubscriptionchange")]
3933
expected: FAIL
4034

41-
[PushSubscription interface: attribute expirationTime]
42-
expected: FAIL
43-
4435
[PushSubscriptionChangeEvent interface object length]
4536
expected: FAIL
4637

@@ -91,9 +82,6 @@
9182
[PushManager interface object length]
9283
expected: FAIL
9384

94-
[PushSubscription interface: attribute expirationTime]
95-
expected: FAIL
96-
9785
[PushSubscription interface object length]
9886
expected: FAIL
9987

@@ -102,4 +90,3 @@
10290

10391
[PushManager interface: attribute supportedContentEncodings]
10492
expected: FAIL
105-

0 commit comments

Comments
 (0)