2011-07-17 23:09:13 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-01-07 09:21:26 +03:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
#ifndef mozilla_dom_workerscope_h__
|
|
|
|
#define mozilla_dom_workerscope_h__
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
#include "Workers.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-07-25 05:30:07 +04:00
|
|
|
#include "mozilla/dom/Headers.h"
|
|
|
|
#include "mozilla/dom/RequestBinding.h"
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-02-28 03:39:30 +04:00
|
|
|
class Console;
|
2013-11-05 18:16:26 +04:00
|
|
|
class Function;
|
2014-09-10 19:21:32 +04:00
|
|
|
class Promise;
|
2014-11-20 14:58:00 +03:00
|
|
|
class RequestOrUSVString;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
namespace indexedDB {
|
|
|
|
|
|
|
|
class IDBFactory;
|
|
|
|
|
|
|
|
} // namespace indexedDB
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
2014-10-27 14:03:00 +03:00
|
|
|
class ServiceWorkerClients;
|
2013-11-05 18:16:26 +04:00
|
|
|
class WorkerPrivate;
|
|
|
|
class WorkerLocation;
|
|
|
|
class WorkerNavigator;
|
2014-08-30 03:50:06 +04:00
|
|
|
class Performance;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
class WorkerGlobalScope : public DOMEventTargetHelper,
|
2013-11-05 18:16:26 +04:00
|
|
|
public nsIGlobalObject
|
|
|
|
{
|
2014-12-17 09:26:15 +03:00
|
|
|
typedef mozilla::dom::indexedDB::IDBFactory IDBFactory;
|
|
|
|
|
2014-02-28 03:39:30 +04:00
|
|
|
nsRefPtr<Console> mConsole;
|
2013-11-05 18:16:26 +04:00
|
|
|
nsRefPtr<WorkerLocation> mLocation;
|
|
|
|
nsRefPtr<WorkerNavigator> mNavigator;
|
2014-08-30 03:50:06 +04:00
|
|
|
nsRefPtr<Performance> mPerformance;
|
2014-12-17 09:26:15 +03:00
|
|
|
nsRefPtr<IDBFactory> mIndexedDB;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit WorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
2013-11-05 18:16:26 +04:00
|
|
|
virtual ~WorkerGlobalScope();
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
virtual JSObject*
|
2013-12-10 15:43:16 +04:00
|
|
|
WrapGlobalObject(JSContext* aCx) = 0;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
virtual JSObject*
|
|
|
|
GetGlobalJSObject(void) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return GetWrapper();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScope,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
already_AddRefed<WorkerGlobalScope>
|
|
|
|
Self()
|
|
|
|
{
|
|
|
|
return nsRefPtr<WorkerGlobalScope>(this).forget();
|
|
|
|
}
|
|
|
|
|
2014-08-08 16:34:30 +04:00
|
|
|
Console*
|
2014-02-28 03:39:30 +04:00
|
|
|
GetConsole();
|
2014-01-26 16:35:17 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
already_AddRefed<WorkerLocation>
|
|
|
|
Location();
|
2013-11-20 03:08:50 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
already_AddRefed<WorkerNavigator>
|
|
|
|
Navigator();
|
2013-11-20 03:08:50 +04:00
|
|
|
|
|
|
|
already_AddRefed<WorkerNavigator>
|
|
|
|
GetExistingNavigator() const;
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
|
|
|
Close(JSContext* aCx);
|
|
|
|
|
|
|
|
OnErrorEventHandlerNonNull*
|
|
|
|
GetOnerror();
|
|
|
|
void
|
|
|
|
SetOnerror(OnErrorEventHandlerNonNull* aHandler);
|
|
|
|
|
|
|
|
void
|
|
|
|
ImportScripts(JSContext* aCx, const Sequence<nsString>& aScriptURLs,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
SetTimeout(JSContext* aCx, Function& aHandler, const int32_t aTimeout,
|
|
|
|
const Sequence<JS::Value>& aArguments, ErrorResult& aRv);
|
|
|
|
int32_t
|
2014-02-19 19:13:38 +04:00
|
|
|
SetTimeout(JSContext* /* unused */, const nsAString& aHandler,
|
|
|
|
const int32_t aTimeout, const Sequence<JS::Value>& /* unused */,
|
2013-11-05 18:16:26 +04:00
|
|
|
ErrorResult& aRv);
|
|
|
|
void
|
|
|
|
ClearTimeout(int32_t aHandle, ErrorResult& aRv);
|
|
|
|
int32_t
|
|
|
|
SetInterval(JSContext* aCx, Function& aHandler,
|
|
|
|
const Optional<int32_t>& aTimeout,
|
|
|
|
const Sequence<JS::Value>& aArguments, ErrorResult& aRv);
|
|
|
|
int32_t
|
2014-02-19 19:13:38 +04:00
|
|
|
SetInterval(JSContext* /* unused */, const nsAString& aHandler,
|
|
|
|
const Optional<int32_t>& aTimeout,
|
|
|
|
const Sequence<JS::Value>& /* unused */, ErrorResult& aRv);
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
|
|
|
ClearInterval(int32_t aHandle, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
|
|
|
Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const;
|
|
|
|
void
|
|
|
|
Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& aRv) const;
|
|
|
|
|
2013-11-20 03:08:50 +04:00
|
|
|
IMPL_EVENT_HANDLER(online)
|
|
|
|
IMPL_EVENT_HANDLER(offline)
|
2013-11-05 18:16:26 +04:00
|
|
|
IMPL_EVENT_HANDLER(close)
|
|
|
|
|
|
|
|
void
|
|
|
|
Dump(const Optional<nsAString>& aString) const;
|
2014-08-30 03:50:06 +04:00
|
|
|
|
|
|
|
Performance* GetPerformance();
|
2014-07-25 05:30:07 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-11-20 14:58:00 +03:00
|
|
|
Fetch(const RequestOrUSVString& aInput, const RequestInit& aInit, ErrorResult& aRv);
|
2014-12-17 09:26:15 +03:00
|
|
|
|
|
|
|
already_AddRefed<IDBFactory>
|
|
|
|
GetIndexedDB(ErrorResult& aErrorResult);
|
2013-11-05 18:16:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class DedicatedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
|
|
|
|
{
|
|
|
|
~DedicatedWorkerGlobalScope() { }
|
|
|
|
|
|
|
|
public:
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
virtual JSObject*
|
2013-12-10 15:43:16 +04:00
|
|
|
WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
|
|
|
const Optional<Sequence<JS::Value>>& aTransferable,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(message)
|
|
|
|
};
|
|
|
|
|
|
|
|
class SharedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
|
|
|
|
{
|
2014-02-06 18:39:10 +04:00
|
|
|
const nsCString mName;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
~SharedWorkerGlobalScope() { }
|
|
|
|
|
|
|
|
public:
|
2014-02-06 18:39:10 +04:00
|
|
|
SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
|
|
|
|
const nsCString& aName);
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
virtual JSObject*
|
2013-12-10 15:43:16 +04:00
|
|
|
WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2014-05-14 01:28:01 +04:00
|
|
|
void GetName(DOMString& aName) const
|
|
|
|
{
|
2014-02-06 18:39:10 +04:00
|
|
|
aName.AsAString() = NS_ConvertUTF8toUTF16(mName);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(connect)
|
|
|
|
};
|
|
|
|
|
2014-05-14 01:28:01 +04:00
|
|
|
class ServiceWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
|
|
|
|
{
|
|
|
|
const nsString mScope;
|
2014-10-27 14:03:00 +03:00
|
|
|
nsRefPtr<ServiceWorkerClients> mClients;
|
|
|
|
|
2014-10-27 14:03:00 +03:00
|
|
|
~ServiceWorkerGlobalScope();
|
2014-05-14 01:28:01 +04:00
|
|
|
|
|
|
|
public:
|
2014-10-27 14:03:00 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerGlobalScope,
|
|
|
|
WorkerGlobalScope)
|
|
|
|
|
2014-05-14 01:28:01 +04:00
|
|
|
ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, const nsACString& aScope);
|
|
|
|
|
|
|
|
virtual JSObject*
|
|
|
|
WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
void
|
|
|
|
GetScope(DOMString& aScope) const
|
|
|
|
{
|
|
|
|
aScope.AsAString() = mScope;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Close() const
|
|
|
|
{
|
|
|
|
// no-op close.
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Update()
|
|
|
|
{
|
|
|
|
// FIXME(nsm): Bug 982728
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:21:32 +04:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Unregister(ErrorResult& aRv);
|
2014-05-14 01:28:01 +04:00
|
|
|
|
2014-10-27 14:03:00 +03:00
|
|
|
ServiceWorkerClients*
|
2014-10-27 14:03:00 +03:00
|
|
|
Clients();
|
2014-10-27 14:03:00 +03:00
|
|
|
|
2014-05-14 01:28:01 +04:00
|
|
|
IMPL_EVENT_HANDLER(activate)
|
|
|
|
IMPL_EVENT_HANDLER(beforeevicted)
|
|
|
|
IMPL_EVENT_HANDLER(evicted)
|
|
|
|
IMPL_EVENT_HANDLER(fetch)
|
|
|
|
IMPL_EVENT_HANDLER(install)
|
|
|
|
IMPL_EVENT_HANDLER(message)
|
|
|
|
};
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
JSObject*
|
2013-06-05 18:04:23 +04:00
|
|
|
CreateGlobalScope(JSContext* aCx);
|
2012-01-18 22:05:38 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
2014-10-27 14:03:00 +03:00
|
|
|
inline nsISupports*
|
|
|
|
ToSupports(mozilla::dom::workers::WorkerGlobalScope* aScope)
|
|
|
|
{
|
|
|
|
return static_cast<nsIDOMEventTarget*>(aScope);
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
#endif /* mozilla_dom_workerscope_h__ */
|