2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2015-01-18 06:17:06 +03:00
|
|
|
#include "nsWeakReference.h"
|
2015-07-30 21:47:00 +03:00
|
|
|
#include "mozilla/dom/ImageBitmapSource.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;
|
2016-02-17 00:46:08 +03:00
|
|
|
class IDBFactory;
|
2014-09-10 19:21:32 +04:00
|
|
|
class Promise;
|
2014-11-20 14:58:00 +03:00
|
|
|
class RequestOrUSVString;
|
2015-04-04 08:46:07 +03:00
|
|
|
class ServiceWorkerRegistrationWorkerThread;
|
2016-03-16 21:51:11 +03:00
|
|
|
class WorkerLocation;
|
2016-03-19 00:15:46 +03:00
|
|
|
class WorkerNavigator;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2015-03-02 16:23:00 +03:00
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
class CacheStorage;
|
|
|
|
|
|
|
|
} // namespace cache
|
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;
|
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,
|
2015-01-18 06:17:06 +03:00
|
|
|
public nsIGlobalObject,
|
|
|
|
public nsSupportsWeakReference
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
2016-02-17 00:46:08 +03:00
|
|
|
typedef mozilla::dom::IDBFactory IDBFactory;
|
2014-12-17 09:26:15 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Console> mConsole;
|
|
|
|
RefPtr<WorkerLocation> mLocation;
|
|
|
|
RefPtr<WorkerNavigator> mNavigator;
|
|
|
|
RefPtr<Performance> mPerformance;
|
|
|
|
RefPtr<IDBFactory> mIndexedDB;
|
|
|
|
RefPtr<cache::CacheStorage> mCacheStorage;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2015-07-23 18:30:27 +03:00
|
|
|
uint32_t mWindowInteractionsAllowed;
|
|
|
|
|
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*
|
2015-03-21 19:28:04 +03:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2015-01-09 00:56:42 +03:00
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx, JS::MutableHandle<JSObject*> aReflector) = 0;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
GetGlobalJSObject(void) override
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2015-04-27 20:38:12 +03:00
|
|
|
WorkerGlobalScope*
|
2013-11-05 18:16:26 +04:00
|
|
|
Self()
|
|
|
|
{
|
2015-04-27 20:38:12 +03:00
|
|
|
return this;
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
|
|
|
|
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
|
2015-03-06 06:48:07 +03:00
|
|
|
Close(JSContext* aCx, ErrorResult& aRv);
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
OnErrorEventHandlerNonNull*
|
|
|
|
GetOnerror();
|
|
|
|
void
|
|
|
|
SetOnerror(OnErrorEventHandlerNonNull* aHandler);
|
|
|
|
|
|
|
|
void
|
2016-02-29 22:52:42 +03:00
|
|
|
ImportScripts(const Sequence<nsString>& aScriptURLs, ErrorResult& aRv);
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
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
|
2016-03-10 12:50:56 +03:00
|
|
|
ClearTimeout(int32_t aHandle);
|
2013-11-05 18:16:26 +04:00
|
|
|
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
|
2016-03-10 12:50:56 +03:00
|
|
|
ClearInterval(int32_t aHandle);
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
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);
|
2015-03-02 16:23:00 +03:00
|
|
|
|
|
|
|
already_AddRefed<cache::CacheStorage>
|
|
|
|
GetCaches(ErrorResult& aRv);
|
2015-07-30 21:47:00 +03:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
CreateImageBitmap(const ImageBitmapSource& aImage, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
CreateImageBitmap(const ImageBitmapSource& aImage,
|
|
|
|
int32_t aSx, int32_t aSy, int32_t aSw, int32_t aSh,
|
|
|
|
ErrorResult& aRv);
|
2015-07-23 18:30:27 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
WindowInteractionAllowed() const
|
|
|
|
{
|
|
|
|
return mWindowInteractionsAllowed > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AllowWindowInteraction()
|
|
|
|
{
|
|
|
|
mWindowInteractionsAllowed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ConsumeWindowInteraction()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWindowInteractionsAllowed > 0);
|
|
|
|
mWindowInteractionsAllowed--;
|
|
|
|
}
|
2013-11-05 18:16:26 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DedicatedWorkerGlobalScope final : public WorkerGlobalScope
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
|
|
|
~DedicatedWorkerGlobalScope() { }
|
|
|
|
|
|
|
|
public:
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2015-01-09 00:56:42 +03:00
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx,
|
2015-03-21 19:28:04 +03:00
|
|
|
JS::MutableHandle<JSObject*> aReflector) 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)
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class SharedWorkerGlobalScope final : public WorkerGlobalScope
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
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
|
|
|
|
2015-01-09 00:56:42 +03:00
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx,
|
2015-03-21 19:28:04 +03:00
|
|
|
JS::MutableHandle<JSObject*> aReflector) 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)
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ServiceWorkerGlobalScope final : public WorkerGlobalScope
|
2014-05-14 01:28:01 +04:00
|
|
|
{
|
|
|
|
const nsString mScope;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ServiceWorkerClients> mClients;
|
|
|
|
RefPtr<ServiceWorkerRegistrationWorkerThread> mRegistration;
|
2014-10-27 14:03:00 +03:00
|
|
|
|
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)
|
2015-06-26 04:50:24 +03:00
|
|
|
IMPL_EVENT_HANDLER(notificationclick)
|
2014-10-27 14:03:00 +03:00
|
|
|
|
2014-05-14 01:28:01 +04:00
|
|
|
ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, const nsACString& aScope);
|
|
|
|
|
2015-01-09 00:56:42 +03:00
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx,
|
2015-03-21 19:28:04 +03:00
|
|
|
JS::MutableHandle<JSObject*> aReflector) override;
|
2014-05-14 01:28:01 +04:00
|
|
|
|
2015-10-25 23:36:27 +03:00
|
|
|
static bool
|
|
|
|
OpenWindowEnabled(JSContext* aCx, JSObject* aObj);
|
|
|
|
|
2014-05-14 01:28:01 +04:00
|
|
|
void
|
2015-02-13 02:39:26 +03:00
|
|
|
GetScope(nsString& aScope) const
|
2014-05-14 01:28:01 +04:00
|
|
|
{
|
2015-02-13 02:39:26 +03:00
|
|
|
aScope = mScope;
|
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
|
|
|
|
2015-04-04 08:46:07 +03:00
|
|
|
ServiceWorkerRegistrationWorkerThread*
|
|
|
|
Registration();
|
|
|
|
|
2015-06-02 14:12:00 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
SkipWaiting(ErrorResult& aRv);
|
|
|
|
|
2014-05-14 01:28:01 +04:00
|
|
|
IMPL_EVENT_HANDLER(activate)
|
|
|
|
IMPL_EVENT_HANDLER(fetch)
|
|
|
|
IMPL_EVENT_HANDLER(install)
|
|
|
|
IMPL_EVENT_HANDLER(message)
|
2015-04-23 21:43:40 +03:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(push)
|
|
|
|
IMPL_EVENT_HANDLER(pushsubscriptionchange)
|
|
|
|
|
2014-05-14 01:28:01 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class WorkerDebuggerGlobalScope final : public DOMEventTargetHelper,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIGlobalObject
|
2015-03-04 02:51:53 +03:00
|
|
|
{
|
|
|
|
WorkerPrivate* mWorkerPrivate;
|
2016-02-11 20:41:17 +03:00
|
|
|
RefPtr<Console> mConsole;
|
2015-03-04 02:51:53 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit WorkerDebuggerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2016-02-11 20:41:17 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerDebuggerGlobalScope,
|
|
|
|
DOMEventTargetHelper)
|
2015-03-04 02:51:53 +03:00
|
|
|
|
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2015-03-04 02:51:53 +03:00
|
|
|
{
|
|
|
|
MOZ_CRASH("Shouldn't get here!");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aReflector);
|
|
|
|
|
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
GetGlobalJSObject(void) override
|
2015-03-04 02:51:53 +03:00
|
|
|
{
|
|
|
|
return GetWrapper();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-18 16:04:57 +03:00
|
|
|
GetGlobal(JSContext* aCx, JS::MutableHandle<JSObject*> aGlobal,
|
|
|
|
ErrorResult& aRv);
|
2015-03-04 02:51:53 +03:00
|
|
|
|
2015-03-31 13:22:40 +03:00
|
|
|
void
|
|
|
|
CreateSandbox(JSContext* aCx, const nsAString& aName,
|
|
|
|
JS::Handle<JSObject*> aPrototype,
|
|
|
|
JS::MutableHandle<JSObject*> aResult);
|
|
|
|
|
|
|
|
void
|
|
|
|
LoadSubScript(JSContext* aCx, const nsAString& aURL,
|
|
|
|
const Optional<JS::Handle<JSObject*>>& aSandbox,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-03-27 09:17:16 +03:00
|
|
|
void
|
|
|
|
EnterEventLoop();
|
|
|
|
|
|
|
|
void
|
|
|
|
LeaveEventLoop();
|
|
|
|
|
2015-03-20 14:15:59 +03:00
|
|
|
void
|
|
|
|
PostMessage(const nsAString& aMessage);
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(message)
|
|
|
|
|
2015-03-30 14:54:38 +03:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
SetImmediate(Function& aHandler, ErrorResult& aRv);
|
2015-03-30 14:54:38 +03:00
|
|
|
|
2015-03-26 22:09:45 +03:00
|
|
|
void
|
|
|
|
ReportError(JSContext* aCx, const nsAString& aMessage);
|
|
|
|
|
2016-02-11 20:41:17 +03:00
|
|
|
Console*
|
|
|
|
GetConsole(ErrorResult& aRv);
|
|
|
|
|
2015-03-04 02:51:53 +03:00
|
|
|
void
|
|
|
|
Dump(JSContext* aCx, const Optional<nsAString>& aString) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~WorkerDebuggerGlobalScope();
|
|
|
|
};
|
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__ */
|