Bumping gaia.json for 4 gaia revision(s) a=gaia-bump
[gecko.git] / dom / workers / MessagePort.h
blob6eeffbbfbb3f8b3669a72ee0f101edd96d1b1cf8
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
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 file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_workers_messageport_h_
7 #define mozilla_dom_workers_messageport_h_
9 #include "mozilla/dom/workers/Workers.h"
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/dom/BindingDeclarations.h"
13 #include "mozilla/dom/MessagePort.h"
15 class nsIDOMEvent;
16 class nsPIDOMWindow;
18 namespace mozilla {
19 class EventChainPreVisitor;
20 } // namespace mozilla
22 BEGIN_WORKERS_NAMESPACE
24 class SharedWorker;
25 class WorkerPrivate;
27 class MessagePort MOZ_FINAL : public mozilla::dom::MessagePortBase
29 friend class SharedWorker;
30 friend class WorkerPrivate;
32 typedef mozilla::ErrorResult ErrorResult;
34 nsRefPtr<SharedWorker> mSharedWorker;
35 WorkerPrivate* mWorkerPrivate;
36 nsTArray<nsCOMPtr<nsIDOMEvent>> mQueuedEvents;
37 uint64_t mSerial;
38 bool mStarted;
40 public:
41 static bool
42 PrefEnabled();
44 virtual void
45 PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
46 const Optional<Sequence<JS::Value>>& aTransferable,
47 ErrorResult& aRv) MOZ_OVERRIDE;
49 virtual void
50 Start() MOZ_OVERRIDE;
52 virtual void
53 Close() MOZ_OVERRIDE;
55 uint64_t
56 Serial() const
58 return mSerial;
61 void
62 QueueEvent(nsIDOMEvent* aEvent);
64 NS_DECL_ISUPPORTS_INHERITED
65 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort, DOMEventTargetHelper)
67 virtual EventHandlerNonNull*
68 GetOnmessage() MOZ_OVERRIDE;
70 virtual void
71 SetOnmessage(EventHandlerNonNull* aCallback) MOZ_OVERRIDE;
73 virtual already_AddRefed<MessagePortBase>
74 Clone() MOZ_OVERRIDE;
76 bool
77 IsClosed() const
79 return !mSharedWorker && !mWorkerPrivate;
82 virtual JSObject*
83 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
85 virtual nsresult
86 PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
88 #ifdef DEBUG
89 void
90 AssertCorrectThread() const;
91 #else
92 void
93 AssertCorrectThread() const { }
94 #endif
96 private:
97 // This class can only be created by SharedWorker or WorkerPrivate.
98 MessagePort(nsPIDOMWindow* aWindow, SharedWorker* aSharedWorker,
99 uint64_t aSerial);
100 MessagePort(WorkerPrivate* aWorkerPrivate, uint64_t aSerial);
102 // This class is reference-counted and will be destroyed from Release().
103 ~MessagePort();
105 void
106 CloseInternal();
109 END_WORKERS_NAMESPACE
111 #endif // mozilla_dom_workers_messageport_h_