Bumping gaia.json for 4 gaia revision(s) a=gaia-bump
[gecko.git] / dom / workers / WorkerScope.h
blob72d981aa0896227e1ccdf84de93fa91a79965f03
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_workerscope_h__
7 #define mozilla_dom_workerscope_h__
9 #include "Workers.h"
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/dom/Headers.h"
12 #include "mozilla/dom/RequestBinding.h"
14 namespace mozilla {
15 namespace dom {
17 class Console;
18 class Function;
19 class Promise;
20 class RequestOrUSVString;
22 namespace indexedDB {
24 class IDBFactory;
26 } // namespace indexedDB
28 } // namespace dom
29 } // namespace mozilla
31 BEGIN_WORKERS_NAMESPACE
33 class ServiceWorkerClients;
34 class WorkerPrivate;
35 class WorkerLocation;
36 class WorkerNavigator;
37 class Performance;
39 class WorkerGlobalScope : public DOMEventTargetHelper,
40 public nsIGlobalObject
42 typedef mozilla::dom::indexedDB::IDBFactory IDBFactory;
44 nsRefPtr<Console> mConsole;
45 nsRefPtr<WorkerLocation> mLocation;
46 nsRefPtr<WorkerNavigator> mNavigator;
47 nsRefPtr<Performance> mPerformance;
48 nsRefPtr<IDBFactory> mIndexedDB;
50 protected:
51 WorkerPrivate* mWorkerPrivate;
53 explicit WorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
54 virtual ~WorkerGlobalScope();
56 public:
57 virtual JSObject*
58 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
60 virtual JSObject*
61 WrapGlobalObject(JSContext* aCx) = 0;
63 virtual JSObject*
64 GetGlobalJSObject(void) MOZ_OVERRIDE
66 return GetWrapper();
69 NS_DECL_ISUPPORTS_INHERITED
70 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScope,
71 DOMEventTargetHelper)
73 already_AddRefed<WorkerGlobalScope>
74 Self()
76 return nsRefPtr<WorkerGlobalScope>(this).forget();
79 Console*
80 GetConsole();
82 already_AddRefed<WorkerLocation>
83 Location();
85 already_AddRefed<WorkerNavigator>
86 Navigator();
88 already_AddRefed<WorkerNavigator>
89 GetExistingNavigator() const;
91 void
92 Close(JSContext* aCx);
94 OnErrorEventHandlerNonNull*
95 GetOnerror();
96 void
97 SetOnerror(OnErrorEventHandlerNonNull* aHandler);
99 void
100 ImportScripts(JSContext* aCx, const Sequence<nsString>& aScriptURLs,
101 ErrorResult& aRv);
103 int32_t
104 SetTimeout(JSContext* aCx, Function& aHandler, const int32_t aTimeout,
105 const Sequence<JS::Value>& aArguments, ErrorResult& aRv);
106 int32_t
107 SetTimeout(JSContext* /* unused */, const nsAString& aHandler,
108 const int32_t aTimeout, const Sequence<JS::Value>& /* unused */,
109 ErrorResult& aRv);
110 void
111 ClearTimeout(int32_t aHandle, ErrorResult& aRv);
112 int32_t
113 SetInterval(JSContext* aCx, Function& aHandler,
114 const Optional<int32_t>& aTimeout,
115 const Sequence<JS::Value>& aArguments, ErrorResult& aRv);
116 int32_t
117 SetInterval(JSContext* /* unused */, const nsAString& aHandler,
118 const Optional<int32_t>& aTimeout,
119 const Sequence<JS::Value>& /* unused */, ErrorResult& aRv);
120 void
121 ClearInterval(int32_t aHandle, ErrorResult& aRv);
123 void
124 Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const;
125 void
126 Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& aRv) const;
128 IMPL_EVENT_HANDLER(online)
129 IMPL_EVENT_HANDLER(offline)
130 IMPL_EVENT_HANDLER(close)
132 void
133 Dump(const Optional<nsAString>& aString) const;
135 Performance* GetPerformance();
137 already_AddRefed<Promise>
138 Fetch(const RequestOrUSVString& aInput, const RequestInit& aInit, ErrorResult& aRv);
140 already_AddRefed<IDBFactory>
141 GetIndexedDB(ErrorResult& aErrorResult);
144 class DedicatedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
146 ~DedicatedWorkerGlobalScope() { }
148 public:
149 explicit DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
151 virtual JSObject*
152 WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
154 void
155 PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
156 const Optional<Sequence<JS::Value>>& aTransferable,
157 ErrorResult& aRv);
159 IMPL_EVENT_HANDLER(message)
162 class SharedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
164 const nsCString mName;
166 ~SharedWorkerGlobalScope() { }
168 public:
169 SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
170 const nsCString& aName);
172 virtual JSObject*
173 WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
175 void GetName(DOMString& aName) const
177 aName.AsAString() = NS_ConvertUTF8toUTF16(mName);
180 IMPL_EVENT_HANDLER(connect)
183 class ServiceWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
185 const nsString mScope;
186 nsRefPtr<ServiceWorkerClients> mClients;
188 ~ServiceWorkerGlobalScope();
190 public:
191 NS_DECL_ISUPPORTS_INHERITED
192 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerGlobalScope,
193 WorkerGlobalScope)
195 ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, const nsACString& aScope);
197 virtual JSObject*
198 WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
200 void
201 GetScope(DOMString& aScope) const
203 aScope.AsAString() = mScope;
206 void
207 Close() const
209 // no-op close.
212 void
213 Update();
215 already_AddRefed<Promise>
216 Unregister(ErrorResult& aRv);
218 ServiceWorkerClients*
219 Clients();
221 IMPL_EVENT_HANDLER(activate)
222 IMPL_EVENT_HANDLER(beforeevicted)
223 IMPL_EVENT_HANDLER(evicted)
224 IMPL_EVENT_HANDLER(fetch)
225 IMPL_EVENT_HANDLER(install)
226 IMPL_EVENT_HANDLER(message)
229 JSObject*
230 CreateGlobalScope(JSContext* aCx);
232 END_WORKERS_NAMESPACE
234 inline nsISupports*
235 ToSupports(mozilla::dom::workers::WorkerGlobalScope* aScope)
237 return static_cast<nsIDOMEventTarget*>(aScope);
240 #endif /* mozilla_dom_workerscope_h__ */