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

This commit is contained in:
Catalin Badea 2015-02-09 12:42:00 -05:00
parent d6f7422100
commit 80a1b203b6
3 changed files with 29 additions and 0 deletions

View File

@ -18,6 +18,10 @@ interface ServiceWorker : EventTarget {
readonly attribute ServiceWorkerState state;
attribute EventHandler onstatechange;
// FIXME(catalinb): Should inherit this from Worker.
[Throws]
void postMessage(any message, optional sequence<Transferable> transferable);
};
ServiceWorker implements AbstractWorker;

View File

@ -13,6 +13,11 @@
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
#ifdef XP_WIN
#undef PostMessage
#endif
using mozilla::ErrorResult;
using namespace mozilla::dom;
namespace mozilla {
@ -64,6 +69,17 @@ ServiceWorker::WrapObject(JSContext* aCx)
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*
ServiceWorker::GetWorkerPrivate() const
{

View File

@ -61,6 +61,15 @@ public:
DOMEventTargetHelper::DispatchTrustedEvent(NS_LITERAL_STRING("statechange"));
}
#ifdef XP_WIN
#undef PostMessage
#endif
void
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Optional<Sequence<JS::Value>>& aTransferable,
ErrorResult& aRv);
WorkerPrivate*
GetWorkerPrivate() const;