diff --git a/dom/webidl/ServiceWorker.webidl b/dom/webidl/ServiceWorker.webidl index ad0b02ea83a3..a4fe588b783d 100644 --- a/dom/webidl/ServiceWorker.webidl +++ b/dom/webidl/ServiceWorker.webidl @@ -8,8 +8,6 @@ * */ -// Still unclear what should be subclassed. -// https://github.com/slightlyoff/ServiceWorker/issues/189 [Pref="dom.serviceWorkers.enabled", // XXXbz I have no idea where this should be exposed. The spec makes // no sense. But since it's got a pref, let's say window. @@ -20,6 +18,10 @@ interface ServiceWorker : EventTarget { readonly attribute ServiceWorkerState state; attribute EventHandler onstatechange; + + // FIXME(catalinb): Bug 1053483 - This should be inherited from MessageUtils + [Throws] + void postMessage(any message, optional sequence transferable); }; ServiceWorker implements AbstractWorker; diff --git a/dom/workers/ServiceWorker.cpp b/dom/workers/ServiceWorker.cpp index ee2eab96a4a9..f9cbf3820ab7 100644 --- a/dom/workers/ServiceWorker.cpp +++ b/dom/workers/ServiceWorker.cpp @@ -11,6 +11,7 @@ #include "mozilla/dom/Promise.h" +using mozilla::ErrorResult; using namespace mozilla::dom; USING_WORKERS_NAMESPACE @@ -46,6 +47,17 @@ ServiceWorker::WrapObject(JSContext* aCx) return ServiceWorkerBinding::Wrap(aCx, this); } +void +ServiceWorker::PostMessage(JSContext* aCx, JS::Handle aMessage, + const Optional>& aTransferable, + ErrorResult& aRv) +{ + WorkerPrivate* workerPrivate = GetWorkerPrivate(); + MOZ_ASSERT(workerPrivate); + + workerPrivate->PostMessage(aCx, aMessage, aTransferable, aRv); +} + WorkerPrivate* ServiceWorker::GetWorkerPrivate() const { diff --git a/dom/workers/ServiceWorker.h b/dom/workers/ServiceWorker.h index 0883ad525b81..3c3b7e612abd 100644 --- a/dom/workers/ServiceWorker.h +++ b/dom/workers/ServiceWorker.h @@ -52,6 +52,11 @@ public: aURL = mURL; } + void + PostMessage(JSContext* aCx, JS::Handle aMessage, + const Optional>& aTransferable, + ErrorResult& aRv); + WorkerPrivate* GetWorkerPrivate() const;