|
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/. */ |
|
5 |
|
6 #ifndef mozilla_dom_workerscope_h__ |
|
7 #define mozilla_dom_workerscope_h__ |
|
8 |
|
9 #include "Workers.h" |
|
10 #include "mozilla/DOMEventTargetHelper.h" |
|
11 |
|
12 namespace mozilla { |
|
13 namespace dom { |
|
14 |
|
15 class Console; |
|
16 class Function; |
|
17 |
|
18 } // namespace dom |
|
19 } // namespace mozilla |
|
20 |
|
21 BEGIN_WORKERS_NAMESPACE |
|
22 |
|
23 class WorkerPrivate; |
|
24 class WorkerLocation; |
|
25 class WorkerNavigator; |
|
26 |
|
27 class WorkerGlobalScope : public DOMEventTargetHelper, |
|
28 public nsIGlobalObject |
|
29 { |
|
30 nsRefPtr<Console> mConsole; |
|
31 nsRefPtr<WorkerLocation> mLocation; |
|
32 nsRefPtr<WorkerNavigator> mNavigator; |
|
33 |
|
34 protected: |
|
35 WorkerPrivate* mWorkerPrivate; |
|
36 |
|
37 WorkerGlobalScope(WorkerPrivate* aWorkerPrivate); |
|
38 virtual ~WorkerGlobalScope(); |
|
39 |
|
40 public: |
|
41 virtual JSObject* |
|
42 WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
43 |
|
44 virtual JSObject* |
|
45 WrapGlobalObject(JSContext* aCx) = 0; |
|
46 |
|
47 virtual JSObject* |
|
48 GetGlobalJSObject(void) MOZ_OVERRIDE |
|
49 { |
|
50 return GetWrapper(); |
|
51 } |
|
52 |
|
53 NS_DECL_ISUPPORTS_INHERITED |
|
54 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScope, |
|
55 DOMEventTargetHelper) |
|
56 |
|
57 already_AddRefed<WorkerGlobalScope> |
|
58 Self() |
|
59 { |
|
60 return nsRefPtr<WorkerGlobalScope>(this).forget(); |
|
61 } |
|
62 |
|
63 already_AddRefed<Console> |
|
64 GetConsole(); |
|
65 |
|
66 already_AddRefed<WorkerLocation> |
|
67 Location(); |
|
68 |
|
69 already_AddRefed<WorkerNavigator> |
|
70 Navigator(); |
|
71 |
|
72 already_AddRefed<WorkerNavigator> |
|
73 GetExistingNavigator() const; |
|
74 |
|
75 void |
|
76 Close(JSContext* aCx); |
|
77 |
|
78 OnErrorEventHandlerNonNull* |
|
79 GetOnerror(); |
|
80 void |
|
81 SetOnerror(OnErrorEventHandlerNonNull* aHandler); |
|
82 |
|
83 void |
|
84 ImportScripts(JSContext* aCx, const Sequence<nsString>& aScriptURLs, |
|
85 ErrorResult& aRv); |
|
86 |
|
87 int32_t |
|
88 SetTimeout(JSContext* aCx, Function& aHandler, const int32_t aTimeout, |
|
89 const Sequence<JS::Value>& aArguments, ErrorResult& aRv); |
|
90 int32_t |
|
91 SetTimeout(JSContext* /* unused */, const nsAString& aHandler, |
|
92 const int32_t aTimeout, const Sequence<JS::Value>& /* unused */, |
|
93 ErrorResult& aRv); |
|
94 void |
|
95 ClearTimeout(int32_t aHandle, ErrorResult& aRv); |
|
96 int32_t |
|
97 SetInterval(JSContext* aCx, Function& aHandler, |
|
98 const Optional<int32_t>& aTimeout, |
|
99 const Sequence<JS::Value>& aArguments, ErrorResult& aRv); |
|
100 int32_t |
|
101 SetInterval(JSContext* /* unused */, const nsAString& aHandler, |
|
102 const Optional<int32_t>& aTimeout, |
|
103 const Sequence<JS::Value>& /* unused */, ErrorResult& aRv); |
|
104 void |
|
105 ClearInterval(int32_t aHandle, ErrorResult& aRv); |
|
106 |
|
107 void |
|
108 Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const; |
|
109 void |
|
110 Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& aRv) const; |
|
111 |
|
112 IMPL_EVENT_HANDLER(online) |
|
113 IMPL_EVENT_HANDLER(offline) |
|
114 IMPL_EVENT_HANDLER(close) |
|
115 |
|
116 void |
|
117 Dump(const Optional<nsAString>& aString) const; |
|
118 }; |
|
119 |
|
120 class DedicatedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope |
|
121 { |
|
122 ~DedicatedWorkerGlobalScope() { } |
|
123 |
|
124 public: |
|
125 DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate); |
|
126 |
|
127 static bool |
|
128 Visible(JSContext* aCx, JSObject* aObj); |
|
129 |
|
130 virtual JSObject* |
|
131 WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE; |
|
132 |
|
133 void |
|
134 PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage, |
|
135 const Optional<Sequence<JS::Value>>& aTransferable, |
|
136 ErrorResult& aRv); |
|
137 |
|
138 IMPL_EVENT_HANDLER(message) |
|
139 }; |
|
140 |
|
141 class SharedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope |
|
142 { |
|
143 const nsCString mName; |
|
144 |
|
145 ~SharedWorkerGlobalScope() { } |
|
146 |
|
147 public: |
|
148 SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, |
|
149 const nsCString& aName); |
|
150 |
|
151 static bool |
|
152 Visible(JSContext* aCx, JSObject* aObj); |
|
153 |
|
154 virtual JSObject* |
|
155 WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE; |
|
156 |
|
157 void GetName(DOMString& aName) const { |
|
158 aName.AsAString() = NS_ConvertUTF8toUTF16(mName); |
|
159 } |
|
160 |
|
161 IMPL_EVENT_HANDLER(connect) |
|
162 }; |
|
163 |
|
164 JSObject* |
|
165 CreateGlobalScope(JSContext* aCx); |
|
166 |
|
167 END_WORKERS_NAMESPACE |
|
168 |
|
169 #endif /* mozilla_dom_workerscope_h__ */ |