2013-06-05 07:04:23 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* 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_workers_messageport_h_
|
|
|
|
#define mozilla_dom_workers_messageport_h_
|
|
|
|
|
|
|
|
#include "Workers.h"
|
|
|
|
|
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2013-11-05 06:16:26 -08:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
|
|
#include "mozilla/dom/MessagePort.h"
|
2013-06-05 07:04:23 -07:00
|
|
|
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
2014-03-17 21:48:19 -07:00
|
|
|
namespace mozilla {
|
|
|
|
class EventChainPreVisitor;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-06-05 07:04:23 -07:00
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
class SharedWorker;
|
2013-11-05 06:16:26 -08:00
|
|
|
class WorkerPrivate;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
class MessagePort MOZ_FINAL : public mozilla::dom::MessagePortBase
|
2013-06-05 07:04:23 -07:00
|
|
|
{
|
|
|
|
friend class SharedWorker;
|
2013-11-05 06:16:26 -08:00
|
|
|
friend class WorkerPrivate;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
|
|
|
typedef mozilla::ErrorResult ErrorResult;
|
|
|
|
|
|
|
|
nsRefPtr<SharedWorker> mSharedWorker;
|
2013-11-05 06:16:26 -08:00
|
|
|
WorkerPrivate* mWorkerPrivate;
|
2013-06-05 07:04:23 -07:00
|
|
|
nsTArray<nsCOMPtr<nsIDOMEvent>> mQueuedEvents;
|
|
|
|
uint64_t mSerial;
|
|
|
|
bool mStarted;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool
|
|
|
|
PrefEnabled();
|
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
virtual void
|
2013-11-11 00:04:41 -08:00
|
|
|
PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
2013-10-08 08:51:42 -07:00
|
|
|
const Optional<Sequence<JS::Value>>& aTransferable,
|
2013-11-05 06:16:26 -08:00
|
|
|
ErrorResult& aRv) MOZ_OVERRIDE;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
virtual void
|
|
|
|
Start() MOZ_OVERRIDE;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
virtual void
|
|
|
|
Close() MOZ_OVERRIDE;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
|
|
|
uint64_t
|
|
|
|
Serial() const
|
|
|
|
{
|
|
|
|
return mSerial;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QueueEvent(nsIDOMEvent* aEvent);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort, nsDOMEventTargetHelper)
|
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
virtual EventHandlerNonNull*
|
|
|
|
GetOnmessage() MOZ_OVERRIDE;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
virtual void
|
|
|
|
SetOnmessage(EventHandlerNonNull* aCallback) MOZ_OVERRIDE;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
virtual already_AddRefed<MessagePortBase>
|
|
|
|
Clone() MOZ_OVERRIDE;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
IsClosed() const
|
|
|
|
{
|
2013-11-05 06:16:26 -08:00
|
|
|
return !mSharedWorker && !mWorkerPrivate;
|
2013-06-05 07:04:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual JSObject*
|
2013-11-11 00:04:41 -08:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
|
|
|
virtual nsresult
|
2014-03-17 21:48:19 -07:00
|
|
|
PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
|
2013-06-05 07:04:23 -07:00
|
|
|
|
2013-11-05 06:16:26 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
AssertCorrectThread() const;
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
AssertCorrectThread() const { }
|
|
|
|
#endif
|
|
|
|
|
2013-06-05 07:04:23 -07:00
|
|
|
private:
|
2013-11-05 06:16:26 -08:00
|
|
|
// This class can only be created by SharedWorker or WorkerPrivate.
|
2013-06-05 07:04:23 -07:00
|
|
|
MessagePort(nsPIDOMWindow* aWindow, SharedWorker* aSharedWorker,
|
|
|
|
uint64_t aSerial);
|
2013-11-05 06:16:26 -08:00
|
|
|
MessagePort(WorkerPrivate* aWorkerPrivate, uint64_t aSerial);
|
2013-06-05 07:04:23 -07:00
|
|
|
|
|
|
|
// This class is reference-counted and will be destroyed from Release().
|
|
|
|
~MessagePort();
|
|
|
|
|
|
|
|
void
|
|
|
|
CloseInternal();
|
|
|
|
};
|
|
|
|
|
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_messageport_h_
|