Bumping manifests a=b2g-bump
[gecko.git] / dom / base / MessagePort.h
blobca3e8dd74f4e2bd4c04e96a4cae4e914c461e020
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
22 protected:
23 explicit 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;
54 class MessagePort MOZ_FINAL : public MessagePortBase
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 explicit MessagePort(nsPIDOMWindow* aWindow);
66 virtual JSObject*
67 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
69 virtual void
70 PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
71 const Optional<Sequence<JS::Value>>& aTransferable,
72 ErrorResult& aRv) MOZ_OVERRIDE;
74 virtual void
75 Start() MOZ_OVERRIDE;
77 virtual void
78 Close() MOZ_OVERRIDE;
80 virtual EventHandlerNonNull*
81 GetOnmessage() MOZ_OVERRIDE;
83 virtual void
84 SetOnmessage(EventHandlerNonNull* aCallback) MOZ_OVERRIDE;
86 // Non WebIDL methods
88 // This method entangles this MessagePort with another one.
89 // If it is already entangled, it's disentangled first and enatangle to the
90 // new one.
91 void
92 Entangle(MessagePort* aMessagePort);
94 virtual already_AddRefed<MessagePortBase>
95 Clone() MOZ_OVERRIDE;
97 private:
98 ~MessagePort();
100 // Dispatch events from the Message Queue using a nsRunnable.
101 void Dispatch();
103 nsRefPtr<DispatchEventRunnable> mDispatchRunnable;
105 nsRefPtr<MessagePort> mEntangledPort;
107 nsTArray<nsRefPtr<PostMessageRunnable> > mMessageQueue;
108 bool mMessageQueueEnabled;
111 } // namespace dom
112 } // namespace mozilla
114 #endif // mozilla_dom_MessagePort_h