michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_MessagePort_h michael@0: #define mozilla_dom_MessagePort_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: michael@0: class nsPIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class DispatchEventRunnable; michael@0: class PostMessageRunnable; michael@0: michael@0: class MessagePortBase : public DOMEventTargetHelper michael@0: { michael@0: protected: michael@0: MessagePortBase(nsPIDOMWindow* aWindow); michael@0: MessagePortBase(); michael@0: michael@0: public: michael@0: michael@0: virtual void michael@0: PostMessageMoz(JSContext* aCx, JS::Handle aMessage, michael@0: const Optional>& aTransferable, michael@0: ErrorResult& aRv) = 0; michael@0: michael@0: virtual void michael@0: Start() = 0; michael@0: michael@0: virtual void michael@0: Close() = 0; michael@0: michael@0: // The 'message' event handler has to call |Start()| method, so we michael@0: // cannot use IMPL_EVENT_HANDLER macro here. michael@0: virtual EventHandlerNonNull* michael@0: GetOnmessage() = 0; michael@0: michael@0: virtual void michael@0: SetOnmessage(EventHandlerNonNull* aCallback) = 0; michael@0: michael@0: // Duplicate this message port. This method is used by the Structured Clone michael@0: // Algorithm and makes the new MessagePort active with the entangled michael@0: // MessagePort of this object. michael@0: virtual already_AddRefed michael@0: Clone() = 0; michael@0: }; michael@0: michael@0: class MessagePort MOZ_FINAL : public MessagePortBase michael@0: { michael@0: friend class DispatchEventRunnable; michael@0: friend class PostMessageRunnable; michael@0: michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort, michael@0: DOMEventTargetHelper) michael@0: michael@0: MessagePort(nsPIDOMWindow* aWindow); michael@0: ~MessagePort(); michael@0: michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; 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: virtual EventHandlerNonNull* michael@0: GetOnmessage() MOZ_OVERRIDE; michael@0: michael@0: virtual void michael@0: SetOnmessage(EventHandlerNonNull* aCallback) MOZ_OVERRIDE; michael@0: michael@0: // Non WebIDL methods michael@0: michael@0: // This method entangles this MessagePort with another one. michael@0: // If it is already entangled, it's disentangled first and enatangle to the michael@0: // new one. michael@0: void michael@0: Entangle(MessagePort* aMessagePort); michael@0: michael@0: virtual already_AddRefed michael@0: Clone() MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: // Dispatch events from the Message Queue using a nsRunnable. michael@0: void Dispatch(); michael@0: michael@0: nsRefPtr mDispatchRunnable; michael@0: michael@0: nsRefPtr mEntangledPort; michael@0: michael@0: nsTArray > mMessageQueue; michael@0: bool mMessageQueueEnabled; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_MessagePort_h