dom/base/MessagePort.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     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
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef mozilla_dom_MessagePort_h
     7 #define mozilla_dom_MessagePort_h
     9 #include "mozilla/Attributes.h"
    10 #include "mozilla/DOMEventTargetHelper.h"
    12 class nsPIDOMWindow;
    14 namespace mozilla {
    15 namespace dom {
    17 class DispatchEventRunnable;
    18 class PostMessageRunnable;
    20 class MessagePortBase : public DOMEventTargetHelper
    21 {
    22 protected:
    23   MessagePortBase(nsPIDOMWindow* aWindow);
    24   MessagePortBase();
    26 public:
    28   virtual void
    29   PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
    30                 const Optional<Sequence<JS::Value>>& aTransferable,
    31                 ErrorResult& aRv) = 0;
    33   virtual void
    34   Start() = 0;
    36   virtual void
    37   Close() = 0;
    39   // The 'message' event handler has to call |Start()| method, so we
    40   // cannot use IMPL_EVENT_HANDLER macro here.
    41   virtual EventHandlerNonNull*
    42   GetOnmessage() = 0;
    44   virtual void
    45   SetOnmessage(EventHandlerNonNull* aCallback) = 0;
    47   // Duplicate this message port. This method is used by the Structured Clone
    48   // Algorithm and makes the new MessagePort active with the entangled
    49   // MessagePort of this object.
    50   virtual already_AddRefed<MessagePortBase>
    51   Clone() = 0;
    52 };
    54 class MessagePort MOZ_FINAL : public MessagePortBase
    55 {
    56   friend class DispatchEventRunnable;
    57   friend class PostMessageRunnable;
    59 public:
    60   NS_DECL_ISUPPORTS_INHERITED
    61   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort,
    62                                            DOMEventTargetHelper)
    64   MessagePort(nsPIDOMWindow* aWindow);
    65   ~MessagePort();
    67   virtual JSObject*
    68   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    70   virtual void
    71   PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
    72                  const Optional<Sequence<JS::Value>>& aTransferable,
    73                  ErrorResult& aRv) MOZ_OVERRIDE;
    75   virtual void
    76   Start() MOZ_OVERRIDE;
    78   virtual void
    79   Close() MOZ_OVERRIDE;
    81   virtual EventHandlerNonNull*
    82   GetOnmessage() MOZ_OVERRIDE;
    84   virtual void
    85   SetOnmessage(EventHandlerNonNull* aCallback) MOZ_OVERRIDE;
    87   // Non WebIDL methods
    89   // This method entangles this MessagePort with another one.
    90   // If it is already entangled, it's disentangled first and enatangle to the
    91   // new one.
    92   void
    93   Entangle(MessagePort* aMessagePort);
    95   virtual already_AddRefed<MessagePortBase>
    96   Clone() MOZ_OVERRIDE;
    98 private:
    99   // Dispatch events from the Message Queue using a nsRunnable.
   100   void Dispatch();
   102   nsRefPtr<DispatchEventRunnable> mDispatchRunnable;
   104   nsRefPtr<MessagePort> mEntangledPort;
   106   nsTArray<nsRefPtr<PostMessageRunnable> > mMessageQueue;
   107   bool mMessageQueueEnabled;
   108 };
   110 } // namespace dom
   111 } // namespace mozilla
   113 #endif // mozilla_dom_MessagePort_h

mercurial