1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_workers_messageport_h_
7 #define mozilla_dom_workers_messageport_h_
9 #include "mozilla/dom/workers/Workers.h"
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/dom/BindingDeclarations.h"
13 #include "mozilla/dom/MessagePort.h"
19 class EventChainPreVisitor
;
20 } // namespace mozilla
22 BEGIN_WORKERS_NAMESPACE
27 class MessagePort MOZ_FINAL
: public mozilla::dom::MessagePortBase
29 friend class SharedWorker
;
30 friend class WorkerPrivate
;
32 typedef mozilla::ErrorResult ErrorResult
;
34 nsRefPtr
<SharedWorker
> mSharedWorker
;
35 WorkerPrivate
* mWorkerPrivate
;
36 nsTArray
<nsCOMPtr
<nsIDOMEvent
>> mQueuedEvents
;
45 PostMessageMoz(JSContext
* aCx
, JS::Handle
<JS::Value
> aMessage
,
46 const Optional
<Sequence
<JS::Value
>>& aTransferable
,
47 ErrorResult
& aRv
) MOZ_OVERRIDE
;
62 QueueEvent(nsIDOMEvent
* aEvent
);
64 NS_DECL_ISUPPORTS_INHERITED
65 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort
, DOMEventTargetHelper
)
67 virtual EventHandlerNonNull
*
68 GetOnmessage() MOZ_OVERRIDE
;
71 SetOnmessage(EventHandlerNonNull
* aCallback
) MOZ_OVERRIDE
;
73 virtual already_AddRefed
<MessagePortBase
>
79 return !mSharedWorker
&& !mWorkerPrivate
;
83 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
86 PreHandleEvent(EventChainPreVisitor
& aVisitor
) MOZ_OVERRIDE
;
90 AssertCorrectThread() const;
93 AssertCorrectThread() const { }
97 // This class can only be created by SharedWorker or WorkerPrivate.
98 MessagePort(nsPIDOMWindow
* aWindow
, SharedWorker
* aSharedWorker
,
100 MessagePort(WorkerPrivate
* aWorkerPrivate
, uint64_t aSerial
);
102 // This class is reference-counted and will be destroyed from Release().
109 END_WORKERS_NAMESPACE
111 #endif // mozilla_dom_workers_messageport_h_