diff --git a/dom/webidl/Client.webidl b/dom/webidl/Client.webidl index 7abb65ab1..c961c2b31 100644 --- a/dom/webidl/Client.webidl +++ b/dom/webidl/Client.webidl @@ -15,7 +15,9 @@ interface Client { readonly attribute DOMString id; [Throws] - void postMessage(any message, optional sequence transfer = []); + void postMessage(any message, sequence transferable); + [Throws] + void postMessage(any message, optional StructuredSerializeOptions options); }; [Exposed=ServiceWorker] diff --git a/dom/webidl/ServiceWorker.webidl b/dom/webidl/ServiceWorker.webidl index 6dab46a16..ff80fafc2 100644 --- a/dom/webidl/ServiceWorker.webidl +++ b/dom/webidl/ServiceWorker.webidl @@ -20,7 +20,9 @@ interface ServiceWorker : EventTarget { attribute EventHandler onstatechange; [Throws] - void postMessage(any message, optional sequence transferable = []); + void postMessage(any message, sequence transferable); + [Throws] + void postMessage(any message, optional StructuredSerializeOptions options); }; ServiceWorker implements AbstractWorker; diff --git a/dom/workers/ServiceWorker.cpp b/dom/workers/ServiceWorker.cpp index f2be038d6..a1b38b248 100644 --- a/dom/workers/ServiceWorker.cpp +++ b/dom/workers/ServiceWorker.cpp @@ -15,6 +15,7 @@ #include "mozilla/Preferences.h" #include "mozilla/dom/Promise.h" +#include "mozilla/dom/MessagePortBinding.h" #include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h" #ifdef XP_WIN @@ -98,6 +99,15 @@ ServiceWorker::PostMessage(JSContext* aCx, JS::Handle aMessage, aRv = workerPrivate->SendMessageEvent(aCx, aMessage, aTransferable, Move(clientInfo)); } +void +ServiceWorker::PostMessage(JSContext* aCx, + JS::Handle aMessage, + const StructuredSerializeOptions& aOptions, + ErrorResult& aRv) +{ + PostMessage(aCx, aMessage, aOptions.mTransfer, aRv); +} + } // namespace workers } // namespace dom } // namespace mozilla diff --git a/dom/workers/ServiceWorker.h b/dom/workers/ServiceWorker.h index 01f6973c6..7c046a05c 100644 --- a/dom/workers/ServiceWorker.h +++ b/dom/workers/ServiceWorker.h @@ -16,6 +16,8 @@ class nsPIDOMWindowInner; namespace mozilla { namespace dom { +struct StructuredSerializeOptions; + namespace workers { class ServiceWorkerInfo; @@ -67,6 +69,12 @@ public: const Sequence& aTransferable, ErrorResult& aRv); + void + PostMessage(JSContext* aCx, + JS::Handle aMessage, + const StructuredSerializeOptions& aOptions, + ErrorResult& aRv); + private: // This class can only be created from ServiceWorkerInfo::GetOrCreateInstance(). ServiceWorker(nsPIDOMWindowInner* aWindow, ServiceWorkerInfo* aInfo); diff --git a/dom/workers/ServiceWorkerClient.cpp b/dom/workers/ServiceWorkerClient.cpp index 783efa68a..1f6e4da3a 100644 --- a/dom/workers/ServiceWorkerClient.cpp +++ b/dom/workers/ServiceWorkerClient.cpp @@ -12,6 +12,7 @@ #include "mozilla/dom/Navigator.h" #include "mozilla/dom/ServiceWorkerMessageEvent.h" #include "mozilla/dom/ServiceWorkerMessageEventBinding.h" +#include "mozilla/dom/MessagePortBinding.h" #include "nsGlobalWindow.h" #include "nsIBrowserDOMWindow.h" #include "nsIDocument.h" @@ -221,3 +222,11 @@ ServiceWorkerClient::PostMessage(JSContext* aCx, JS::Handle aMessage, } } +void +ServiceWorkerClient::PostMessage(JSContext* aCx, + JS::Handle aMessage, + const StructuredSerializeOptions& aOptions, + ErrorResult& aRv) +{ + PostMessage(aCx, aMessage, aOptions.mTransfer, aRv); +} diff --git a/dom/workers/ServiceWorkerClient.h b/dom/workers/ServiceWorkerClient.h index a3f2027d9..0bb9c3176 100644 --- a/dom/workers/ServiceWorkerClient.h +++ b/dom/workers/ServiceWorkerClient.h @@ -95,6 +95,12 @@ public: const Sequence& aTransferable, ErrorResult& aRv); + void + PostMessage(JSContext* aCx, + JS::Handle aMessage, + const StructuredSerializeOptions& aOptions, + ErrorResult& aRv); + JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; protected: