Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_workers_sharedworker_h__
7 #define mozilla_dom_workers_sharedworker_h__
9 #include "Workers.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "mozilla/dom/workers/bindings/MessagePort.h"
13 #include "mozilla/DOMEventTargetHelper.h"
15 class nsIDOMEvent;
16 class nsPIDOMWindow;
18 namespace mozilla {
19 class EventChainPreVisitor;
20 } // namespace mozilla
22 BEGIN_WORKERS_NAMESPACE
24 class MessagePort;
25 class RuntimeService;
26 class WorkerPrivate;
28 class SharedWorker MOZ_FINAL : public DOMEventTargetHelper
29 {
30 friend class MessagePort;
31 friend class RuntimeService;
33 typedef mozilla::ErrorResult ErrorResult;
34 typedef mozilla::dom::GlobalObject GlobalObject;
36 nsRefPtr<WorkerPrivate> mWorkerPrivate;
37 nsRefPtr<MessagePort> mMessagePort;
38 nsTArray<nsCOMPtr<nsIDOMEvent>> mSuspendedEvents;
39 uint64_t mSerial;
40 bool mSuspended;
42 public:
43 static already_AddRefed<SharedWorker>
44 Constructor(const GlobalObject& aGlobal, JSContext* aCx,
45 const nsAString& aScriptURL, const Optional<nsAString>& aName,
46 ErrorResult& aRv);
48 already_AddRefed<MessagePort>
49 Port();
51 uint64_t
52 Serial() const
53 {
54 return mSerial;
55 }
57 bool
58 IsSuspended() const
59 {
60 return mSuspended;
61 }
63 void
64 Suspend();
66 void
67 Resume();
69 void
70 QueueEvent(nsIDOMEvent* aEvent);
72 void
73 Close();
75 NS_DECL_ISUPPORTS_INHERITED
76 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SharedWorker, DOMEventTargetHelper)
78 IMPL_EVENT_HANDLER(error)
80 virtual JSObject*
81 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
83 virtual nsresult
84 PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
86 WorkerPrivate*
87 GetWorkerPrivate() const
88 {
89 return mWorkerPrivate;
90 }
92 private:
93 // This class can only be created from the RuntimeService.
94 SharedWorker(nsPIDOMWindow* aWindow,
95 WorkerPrivate* aWorkerPrivate);
97 // This class is reference-counted and will be destroyed from Release().
98 ~SharedWorker();
100 // Only called by MessagePort.
101 void
102 PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
103 const Optional<Sequence<JS::Value>>& aTransferable,
104 ErrorResult& aRv);
106 // Only called by RuntimeService.
107 void
108 NoteDeadWorker(JSContext* aCx);
109 };
111 END_WORKERS_NAMESPACE
113 #endif // mozilla_dom_workers_sharedworker_h__