summaryrefslogtreecommitdiffstats
path: root/dom/push
diff options
context:
space:
mode:
Diffstat (limited to 'dom/push')
-rw-r--r--dom/push/PushManager.cpp13
-rw-r--r--dom/push/PushSubscription.cpp38
-rw-r--r--dom/push/PushSubscriptionOptions.cpp7
-rw-r--r--dom/push/PushUtil.cpp36
-rw-r--r--dom/push/PushUtil.h39
-rw-r--r--dom/push/moz.build2
6 files changed, 24 insertions, 111 deletions
diff --git a/dom/push/PushManager.cpp b/dom/push/PushManager.cpp
index 74bb4a3d7c..246eef8a55 100644
--- a/dom/push/PushManager.cpp
+++ b/dom/push/PushManager.cpp
@@ -14,7 +14,6 @@
#include "mozilla/dom/PushManagerBinding.h"
#include "mozilla/dom/PushSubscription.h"
#include "mozilla/dom/PushSubscriptionOptionsBinding.h"
-#include "mozilla/dom/PushUtil.h"
#include "mozilla/dom/RootedDictionary.h"
#include "mozilla/dom/ServiceWorker.h"
#include "mozilla/dom/WorkerRunnable.h"
@@ -92,7 +91,7 @@ nsresult GetSubscriptionParams(nsIPushSubscription* aSubscription,
return NS_OK;
}
-class GetSubscriptionResultRunnable final : public WorkerRunnable {
+class GetSubscriptionResultRunnable final : public WorkerThreadRunnable {
public:
GetSubscriptionResultRunnable(WorkerPrivate* aWorkerPrivate,
RefPtr<PromiseWorkerProxy>&& aProxy,
@@ -102,7 +101,7 @@ class GetSubscriptionResultRunnable final : public WorkerRunnable {
nsTArray<uint8_t>&& aRawP256dhKey,
nsTArray<uint8_t>&& aAuthSecret,
nsTArray<uint8_t>&& aAppServerKey)
- : WorkerRunnable(aWorkerPrivate, "GetSubscriptionResultRunnable"),
+ : WorkerThreadRunnable("GetSubscriptionResultRunnable"),
mProxy(std::move(aProxy)),
mStatus(aStatus),
mEndpoint(aEndpoint),
@@ -183,7 +182,7 @@ class GetSubscriptionCallback final : public nsIPushSubscriptionCallback {
worker, std::move(mProxy), aStatus, endpoint, mScope,
std::move(mExpirationTime), std::move(rawP256dhKey),
std::move(authSecret), std::move(appServerKey));
- if (!r->Dispatch()) {
+ if (!r->Dispatch(worker)) {
return NS_ERROR_UNEXPECTED;
}
@@ -292,11 +291,11 @@ class GetSubscriptionRunnable final : public Runnable {
nsTArray<uint8_t> mAppServerKey;
};
-class PermissionResultRunnable final : public WorkerRunnable {
+class PermissionResultRunnable final : public WorkerThreadRunnable {
public:
PermissionResultRunnable(PromiseWorkerProxy* aProxy, nsresult aStatus,
PermissionState aState)
- : WorkerRunnable(aProxy->GetWorkerPrivate(), "PermissionResultRunnable"),
+ : WorkerThreadRunnable("PermissionResultRunnable"),
mProxy(aProxy),
mStatus(aStatus),
mState(aState) {
@@ -351,7 +350,7 @@ class PermissionStateRunnable final : public Runnable {
// This can fail if the worker thread is already shutting down, but there's
// nothing we can do in that case.
- Unused << NS_WARN_IF(!r->Dispatch());
+ Unused << NS_WARN_IF(!r->Dispatch(mProxy->GetWorkerPrivate()));
return NS_OK;
}
diff --git a/dom/push/PushSubscription.cpp b/dom/push/PushSubscription.cpp
index 0afb63eee8..fdc70edd09 100644
--- a/dom/push/PushSubscription.cpp
+++ b/dom/push/PushSubscription.cpp
@@ -17,7 +17,7 @@
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseWorkerProxy.h"
#include "mozilla/dom/PushSubscriptionOptions.h"
-#include "mozilla/dom/PushUtil.h"
+#include "mozilla/dom/TypedArray.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRunnable.h"
@@ -54,12 +54,12 @@ class UnsubscribeResultCallback final : public nsIUnsubscribeResultCallback {
NS_IMPL_ISUPPORTS(UnsubscribeResultCallback, nsIUnsubscribeResultCallback)
-class UnsubscribeResultRunnable final : public WorkerRunnable {
+class UnsubscribeResultRunnable final : public WorkerThreadRunnable {
public:
UnsubscribeResultRunnable(WorkerPrivate* aWorkerPrivate,
RefPtr<PromiseWorkerProxy>&& aProxy,
nsresult aStatus, bool aSuccess)
- : WorkerRunnable(aWorkerPrivate, "UnsubscribeResultRunnable"),
+ : WorkerThreadRunnable("UnsubscribeResultRunnable"),
mProxy(std::move(aProxy)),
mStatus(aStatus),
mSuccess(aSuccess) {
@@ -117,7 +117,7 @@ class WorkerUnsubscribeResultCallback final
WorkerPrivate* worker = mProxy->GetWorkerPrivate();
RefPtr<UnsubscribeResultRunnable> r = new UnsubscribeResultRunnable(
worker, std::move(mProxy), aStatus, aSuccess);
- MOZ_ALWAYS_TRUE(r->Dispatch());
+ MOZ_ALWAYS_TRUE(r->Dispatch(worker));
return NS_OK;
}
@@ -230,30 +230,24 @@ already_AddRefed<PushSubscription> PushSubscription::Constructor(
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
nsTArray<uint8_t> rawKey;
- if (aInitDict.mP256dhKey.WasPassed() &&
- !aInitDict.mP256dhKey.Value().IsNull() &&
- !aInitDict.mP256dhKey.Value().Value().AppendDataTo(rawKey)) {
+ if (!aInitDict.mP256dhKey.IsNull() &&
+ !aInitDict.mP256dhKey.Value().AppendDataTo(rawKey)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsTArray<uint8_t> authSecret;
- if (aInitDict.mAuthSecret.WasPassed() &&
- !aInitDict.mAuthSecret.Value().IsNull() &&
- !aInitDict.mAuthSecret.Value().Value().AppendDataTo(authSecret)) {
+ if (!aInitDict.mAuthSecret.IsNull() &&
+ !aInitDict.mAuthSecret.Value().AppendDataTo(authSecret)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsTArray<uint8_t> appServerKey;
- if (aInitDict.mAppServerKey.WasPassed() &&
- !aInitDict.mAppServerKey.Value().IsNull()) {
- const OwningArrayBufferViewOrArrayBuffer& bufferSource =
- aInitDict.mAppServerKey.Value().Value();
- if (!PushUtil::CopyBufferSourceToArray(bufferSource, appServerKey)) {
- aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
- return nullptr;
- }
+ if (!aInitDict.mAppServerKey.IsNull() &&
+ !AppendTypedArrayDataTo(aInitDict.mAppServerKey.Value(), appServerKey)) {
+ aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
+ return nullptr;
}
Nullable<EpochTimeStamp> expirationTime;
@@ -307,10 +301,10 @@ already_AddRefed<Promise> PushSubscription::Unsubscribe(ErrorResult& aRv) {
void PushSubscription::GetKey(JSContext* aCx, PushEncryptionKeyName aType,
JS::MutableHandle<JSObject*> aKey,
ErrorResult& aRv) {
- if (aType == PushEncryptionKeyName::P256dh) {
- PushUtil::CopyArrayToArrayBuffer(aCx, mRawP256dhKey, aKey, aRv);
- } else if (aType == PushEncryptionKeyName::Auth) {
- PushUtil::CopyArrayToArrayBuffer(aCx, mAuthSecret, aKey, aRv);
+ if (aType == PushEncryptionKeyName::P256dh && !mRawP256dhKey.IsEmpty()) {
+ aKey.set(ArrayBuffer::Create(aCx, mRawP256dhKey, aRv));
+ } else if (aType == PushEncryptionKeyName::Auth && !mAuthSecret.IsEmpty()) {
+ aKey.set(ArrayBuffer::Create(aCx, mAuthSecret, aRv));
} else {
aKey.set(nullptr);
}
diff --git a/dom/push/PushSubscriptionOptions.cpp b/dom/push/PushSubscriptionOptions.cpp
index 1de3d96a2e..b14afa310d 100644
--- a/dom/push/PushSubscriptionOptions.cpp
+++ b/dom/push/PushSubscriptionOptions.cpp
@@ -8,9 +8,9 @@
#include "MainThreadUtils.h"
#include "mozilla/dom/PushSubscriptionOptionsBinding.h"
+#include "mozilla/dom/TypedArray.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/HoldDropJSObjects.h"
-#include "mozilla/dom/PushUtil.h"
#include "nsIGlobalObject.h"
#include "nsWrapperCache.h"
@@ -51,13 +51,10 @@ JSObject* PushSubscriptionOptions::WrapObject(
void PushSubscriptionOptions::GetApplicationServerKey(
JSContext* aCx, JS::MutableHandle<JSObject*> aKey, ErrorResult& aRv) {
if (!mRawAppServerKey.IsEmpty() && !mAppServerKey) {
- JS::Rooted<JSObject*> appServerKey(aCx);
- PushUtil::CopyArrayToArrayBuffer(aCx, mRawAppServerKey, &appServerKey, aRv);
+ mAppServerKey = ArrayBuffer::Create(aCx, mRawAppServerKey, aRv);
if (aRv.Failed()) {
return;
}
- MOZ_ASSERT(appServerKey);
- mAppServerKey = appServerKey;
}
aKey.set(mAppServerKey);
}
diff --git a/dom/push/PushUtil.cpp b/dom/push/PushUtil.cpp
deleted file mode 100644
index b1373391ea..0000000000
--- a/dom/push/PushUtil.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "mozilla/dom/PushUtil.h"
-#include "mozilla/dom/UnionTypes.h"
-
-namespace mozilla::dom {
-
-/* static */
-bool PushUtil::CopyBufferSourceToArray(
- const OwningArrayBufferViewOrArrayBuffer& aSource,
- nsTArray<uint8_t>& aArray) {
- MOZ_ASSERT(aArray.IsEmpty());
- return AppendTypedArrayDataTo(aSource, aArray);
-}
-
-/* static */
-void PushUtil::CopyArrayToArrayBuffer(JSContext* aCx,
- const nsTArray<uint8_t>& aArray,
- JS::MutableHandle<JSObject*> aValue,
- ErrorResult& aRv) {
- if (aArray.IsEmpty()) {
- aValue.set(nullptr);
- return;
- }
- JS::Rooted<JSObject*> buffer(aCx, ArrayBuffer::Create(aCx, aArray, aRv));
- if (NS_WARN_IF(aRv.Failed())) {
- return;
- }
- aValue.set(buffer);
-}
-
-} // namespace mozilla::dom
diff --git a/dom/push/PushUtil.h b/dom/push/PushUtil.h
deleted file mode 100644
index 1e4ccf33a9..0000000000
--- a/dom/push/PushUtil.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_PushUtil_h
-#define mozilla_dom_PushUtil_h
-
-#include "nsTArray.h"
-
-#include "mozilla/dom/TypedArray.h"
-
-namespace mozilla {
-class ErrorResult;
-
-namespace dom {
-
-class OwningArrayBufferViewOrArrayBuffer;
-
-class PushUtil final {
- private:
- PushUtil() = delete;
-
- public:
- static bool CopyBufferSourceToArray(
- const OwningArrayBufferViewOrArrayBuffer& aSource,
- nsTArray<uint8_t>& aArray);
-
- static void CopyArrayToArrayBuffer(JSContext* aCx,
- const nsTArray<uint8_t>& aArray,
- JS::MutableHandle<JSObject*> aValue,
- ErrorResult& aRv);
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_PushUtil_h
diff --git a/dom/push/moz.build b/dom/push/moz.build
index 39da18de23..b2f6f4cc11 100644
--- a/dom/push/moz.build
+++ b/dom/push/moz.build
@@ -44,7 +44,6 @@ EXPORTS.mozilla.dom += [
"PushNotifier.h",
"PushSubscription.h",
"PushSubscriptionOptions.h",
- "PushUtil.h",
]
UNIFIED_SOURCES += [
@@ -52,7 +51,6 @@ UNIFIED_SOURCES += [
"PushNotifier.cpp",
"PushSubscription.cpp",
"PushSubscriptionOptions.cpp",
- "PushUtil.cpp",
]
TEST_DIRS += ["test/xpcshell"]