Bug 982726 - Patch 2 - Add postMessage to service worker. r=baku

--HG--
extra : amend_source : e69a2f5438b485ff2819c633047c0cb46f663d01
extra : transplant_source : %96%CE%FC%C8J%EEm%9B%DA%CCZIlK5%9E%EB%99%D3%F3
This commit is contained in:
Catalin Badea 2014-08-15 00:43:00 -07:00
Родитель a2d3be8aeb
Коммит e77acd5d9e
3 изменённых файлов: 21 добавлений и 2 удалений

Просмотреть файл

@ -8,8 +8,6 @@
* *
*/ */
// Still unclear what should be subclassed.
// https://github.com/slightlyoff/ServiceWorker/issues/189
[Pref="dom.serviceWorkers.enabled", [Pref="dom.serviceWorkers.enabled",
// XXXbz I have no idea where this should be exposed. The spec makes // 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. // no sense. But since it's got a pref, let's say window.
@ -20,6 +18,10 @@ interface ServiceWorker : EventTarget {
readonly attribute ServiceWorkerState state; readonly attribute ServiceWorkerState state;
attribute EventHandler onstatechange; attribute EventHandler onstatechange;
// FIXME(catalinb): Bug 1053483 - This should be inherited from MessageUtils
[Throws]
void postMessage(any message, optional sequence<Transferable> transferable);
}; };
ServiceWorker implements AbstractWorker; ServiceWorker implements AbstractWorker;

Просмотреть файл

@ -11,6 +11,7 @@
#include "mozilla/dom/Promise.h" #include "mozilla/dom/Promise.h"
using mozilla::ErrorResult;
using namespace mozilla::dom; using namespace mozilla::dom;
USING_WORKERS_NAMESPACE USING_WORKERS_NAMESPACE
@ -46,6 +47,17 @@ ServiceWorker::WrapObject(JSContext* aCx)
return ServiceWorkerBinding::Wrap(aCx, this); return ServiceWorkerBinding::Wrap(aCx, this);
} }
void
ServiceWorker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Optional<Sequence<JS::Value>>& aTransferable,
ErrorResult& aRv)
{
WorkerPrivate* workerPrivate = GetWorkerPrivate();
MOZ_ASSERT(workerPrivate);
workerPrivate->PostMessage(aCx, aMessage, aTransferable, aRv);
}
WorkerPrivate* WorkerPrivate*
ServiceWorker::GetWorkerPrivate() const ServiceWorker::GetWorkerPrivate() const
{ {

Просмотреть файл

@ -52,6 +52,11 @@ public:
aURL = mURL; aURL = mURL;
} }
void
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Optional<Sequence<JS::Value>>& aTransferable,
ErrorResult& aRv);
WorkerPrivate* WorkerPrivate*
GetWorkerPrivate() const; GetWorkerPrivate() const;