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