michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_workers_messageport_h_ michael@0: #define mozilla_dom_workers_messageport_h_ michael@0: michael@0: #include "Workers.h" michael@0: michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/dom/BindingDeclarations.h" michael@0: #include "mozilla/dom/MessagePort.h" michael@0: michael@0: class nsIDOMEvent; michael@0: class nsPIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: class EventChainPreVisitor; michael@0: } // namespace mozilla michael@0: michael@0: BEGIN_WORKERS_NAMESPACE michael@0: michael@0: class SharedWorker; michael@0: class WorkerPrivate; michael@0: michael@0: class MessagePort MOZ_FINAL : public mozilla::dom::MessagePortBase michael@0: { michael@0: friend class SharedWorker; michael@0: friend class WorkerPrivate; michael@0: michael@0: typedef mozilla::ErrorResult ErrorResult; michael@0: michael@0: nsRefPtr mSharedWorker; michael@0: WorkerPrivate* mWorkerPrivate; michael@0: nsTArray> mQueuedEvents; michael@0: uint64_t mSerial; michael@0: bool mStarted; michael@0: michael@0: public: michael@0: static bool michael@0: PrefEnabled(); michael@0: michael@0: virtual void michael@0: PostMessageMoz(JSContext* aCx, JS::Handle aMessage, michael@0: const Optional>& aTransferable, michael@0: ErrorResult& aRv) MOZ_OVERRIDE; michael@0: michael@0: virtual void michael@0: Start() MOZ_OVERRIDE; michael@0: michael@0: virtual void michael@0: Close() MOZ_OVERRIDE; michael@0: michael@0: uint64_t michael@0: Serial() const michael@0: { michael@0: return mSerial; michael@0: } michael@0: michael@0: void michael@0: QueueEvent(nsIDOMEvent* aEvent); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort, DOMEventTargetHelper) michael@0: michael@0: virtual EventHandlerNonNull* michael@0: GetOnmessage() MOZ_OVERRIDE; michael@0: michael@0: virtual void michael@0: SetOnmessage(EventHandlerNonNull* aCallback) MOZ_OVERRIDE; michael@0: michael@0: virtual already_AddRefed michael@0: Clone() MOZ_OVERRIDE; michael@0: michael@0: bool michael@0: IsClosed() const michael@0: { michael@0: return !mSharedWorker && !mWorkerPrivate; michael@0: } michael@0: michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult michael@0: PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; michael@0: michael@0: #ifdef DEBUG michael@0: void michael@0: AssertCorrectThread() const; michael@0: #else michael@0: void michael@0: AssertCorrectThread() const { } michael@0: #endif michael@0: michael@0: private: michael@0: // This class can only be created by SharedWorker or WorkerPrivate. michael@0: MessagePort(nsPIDOMWindow* aWindow, SharedWorker* aSharedWorker, michael@0: uint64_t aSerial); michael@0: MessagePort(WorkerPrivate* aWorkerPrivate, uint64_t aSerial); michael@0: michael@0: // This class is reference-counted and will be destroyed from Release(). michael@0: ~MessagePort(); michael@0: michael@0: void michael@0: CloseInternal(); michael@0: }; michael@0: michael@0: END_WORKERS_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_workers_messageport_h_