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__
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/dom/Headers.h"
12 #include "mozilla/dom/RequestBinding.h"
20 class RequestOrUSVString
;
26 } // namespace indexedDB
29 } // namespace mozilla
31 BEGIN_WORKERS_NAMESPACE
33 class ServiceWorkerClients
;
36 class WorkerNavigator
;
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
;
51 WorkerPrivate
* mWorkerPrivate
;
53 explicit WorkerGlobalScope(WorkerPrivate
* aWorkerPrivate
);
54 virtual ~WorkerGlobalScope();
58 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
61 WrapGlobalObject(JSContext
* aCx
) = 0;
64 GetGlobalJSObject(void) MOZ_OVERRIDE
69 NS_DECL_ISUPPORTS_INHERITED
70 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScope
,
73 already_AddRefed
<WorkerGlobalScope
>
76 return nsRefPtr
<WorkerGlobalScope
>(this).forget();
82 already_AddRefed
<WorkerLocation
>
85 already_AddRefed
<WorkerNavigator
>
88 already_AddRefed
<WorkerNavigator
>
89 GetExistingNavigator() const;
92 Close(JSContext
* aCx
);
94 OnErrorEventHandlerNonNull
*
97 SetOnerror(OnErrorEventHandlerNonNull
* aHandler
);
100 ImportScripts(JSContext
* aCx
, const Sequence
<nsString
>& aScriptURLs
,
104 SetTimeout(JSContext
* aCx
, Function
& aHandler
, const int32_t aTimeout
,
105 const Sequence
<JS::Value
>& aArguments
, ErrorResult
& aRv
);
107 SetTimeout(JSContext
* /* unused */, const nsAString
& aHandler
,
108 const int32_t aTimeout
, const Sequence
<JS::Value
>& /* unused */,
111 ClearTimeout(int32_t aHandle
, ErrorResult
& aRv
);
113 SetInterval(JSContext
* aCx
, Function
& aHandler
,
114 const Optional
<int32_t>& aTimeout
,
115 const Sequence
<JS::Value
>& aArguments
, ErrorResult
& aRv
);
117 SetInterval(JSContext
* /* unused */, const nsAString
& aHandler
,
118 const Optional
<int32_t>& aTimeout
,
119 const Sequence
<JS::Value
>& /* unused */, ErrorResult
& aRv
);
121 ClearInterval(int32_t aHandle
, ErrorResult
& aRv
);
124 Atob(const nsAString
& aAtob
, nsAString
& aOutput
, ErrorResult
& aRv
) const;
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
)
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() { }
149 explicit DedicatedWorkerGlobalScope(WorkerPrivate
* aWorkerPrivate
);
152 WrapGlobalObject(JSContext
* aCx
) MOZ_OVERRIDE
;
155 PostMessage(JSContext
* aCx
, JS::Handle
<JS::Value
> aMessage
,
156 const Optional
<Sequence
<JS::Value
>>& aTransferable
,
159 IMPL_EVENT_HANDLER(message
)
162 class SharedWorkerGlobalScope MOZ_FINAL
: public WorkerGlobalScope
164 const nsCString mName
;
166 ~SharedWorkerGlobalScope() { }
169 SharedWorkerGlobalScope(WorkerPrivate
* aWorkerPrivate
,
170 const nsCString
& aName
);
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();
191 NS_DECL_ISUPPORTS_INHERITED
192 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerGlobalScope
,
195 ServiceWorkerGlobalScope(WorkerPrivate
* aWorkerPrivate
, const nsACString
& aScope
);
198 WrapGlobalObject(JSContext
* aCx
) MOZ_OVERRIDE
;
201 GetScope(DOMString
& aScope
) const
203 aScope
.AsAString() = mScope
;
215 already_AddRefed
<Promise
>
216 Unregister(ErrorResult
& aRv
);
218 ServiceWorkerClients
*
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
)
230 CreateGlobalScope(JSContext
* aCx
);
232 END_WORKERS_NAMESPACE
235 ToSupports(mozilla::dom::workers::WorkerGlobalScope
* aScope
)
237 return static_cast<nsIDOMEventTarget
*>(aScope
);
240 #endif /* mozilla_dom_workerscope_h__ */