dom/workers/MessagePort.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:bedb1546c06f
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/. */
5
6 #ifndef mozilla_dom_workers_messageport_h_
7 #define mozilla_dom_workers_messageport_h_
8
9 #include "Workers.h"
10
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/dom/BindingDeclarations.h"
13 #include "mozilla/dom/MessagePort.h"
14
15 class nsIDOMEvent;
16 class nsPIDOMWindow;
17
18 namespace mozilla {
19 class EventChainPreVisitor;
20 } // namespace mozilla
21
22 BEGIN_WORKERS_NAMESPACE
23
24 class SharedWorker;
25 class WorkerPrivate;
26
27 class MessagePort MOZ_FINAL : public mozilla::dom::MessagePortBase
28 {
29 friend class SharedWorker;
30 friend class WorkerPrivate;
31
32 typedef mozilla::ErrorResult ErrorResult;
33
34 nsRefPtr<SharedWorker> mSharedWorker;
35 WorkerPrivate* mWorkerPrivate;
36 nsTArray<nsCOMPtr<nsIDOMEvent>> mQueuedEvents;
37 uint64_t mSerial;
38 bool mStarted;
39
40 public:
41 static bool
42 PrefEnabled();
43
44 virtual void
45 PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
46 const Optional<Sequence<JS::Value>>& aTransferable,
47 ErrorResult& aRv) MOZ_OVERRIDE;
48
49 virtual void
50 Start() MOZ_OVERRIDE;
51
52 virtual void
53 Close() MOZ_OVERRIDE;
54
55 uint64_t
56 Serial() const
57 {
58 return mSerial;
59 }
60
61 void
62 QueueEvent(nsIDOMEvent* aEvent);
63
64 NS_DECL_ISUPPORTS_INHERITED
65 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort, DOMEventTargetHelper)
66
67 virtual EventHandlerNonNull*
68 GetOnmessage() MOZ_OVERRIDE;
69
70 virtual void
71 SetOnmessage(EventHandlerNonNull* aCallback) MOZ_OVERRIDE;
72
73 virtual already_AddRefed<MessagePortBase>
74 Clone() MOZ_OVERRIDE;
75
76 bool
77 IsClosed() const
78 {
79 return !mSharedWorker && !mWorkerPrivate;
80 }
81
82 virtual JSObject*
83 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
84
85 virtual nsresult
86 PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
87
88 #ifdef DEBUG
89 void
90 AssertCorrectThread() const;
91 #else
92 void
93 AssertCorrectThread() const { }
94 #endif
95
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);
101
102 // This class is reference-counted and will be destroyed from Release().
103 ~MessagePort();
104
105 void
106 CloseInternal();
107 };
108
109 END_WORKERS_NAMESPACE
110
111 #endif // mozilla_dom_workers_messageport_h_

mercurial