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

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

mercurial