2015-05-03 19:32:37 +00: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 11:12:37 +00: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 06:21:26 +00:00
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
#ifndef mozilla_dom_workerscope_h__
|
|
|
|
#define mozilla_dom_workerscope_h__
|
2011-07-17 19:09:13 +00:00
|
|
|
|
|
|
|
#include "Workers.h"
|
2014-04-01 06:13:50 +00:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-07-25 01:30:07 +00:00
|
|
|
#include "mozilla/dom/Headers.h"
|
|
|
|
#include "mozilla/dom/RequestBinding.h"
|
2015-01-18 03:17:06 +00:00
|
|
|
#include "nsWeakReference.h"
|
2015-07-30 18:47:00 +00:00
|
|
|
#include "mozilla/dom/ImageBitmapSource.h"
|
2013-11-05 14:16:26 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-02-27 23:39:30 +00:00
|
|
|
class Console;
|
2013-11-05 14:16:26 +00:00
|
|
|
class Function;
|
2016-02-16 21:46:08 +00:00
|
|
|
class IDBFactory;
|
2014-09-10 15:21:32 +00:00
|
|
|
class Promise;
|
2014-11-20 11:58:00 +00:00
|
|
|
class RequestOrUSVString;
|
2015-04-04 05:46:07 +00:00
|
|
|
class ServiceWorkerRegistrationWorkerThread;
|
2013-11-05 14:16:26 +00:00
|
|
|
|
2015-03-02 13:23:00 +00:00
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
class CacheStorage;
|
|
|
|
|
|
|
|
} // namespace cache
|
2013-11-05 14:16:26 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2011-07-17 19:09:13 +00:00
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
2014-10-27 11:03:00 +00:00
|
|
|
class ServiceWorkerClients;
|
2013-11-05 14:16:26 +00:00
|
|
|
class WorkerPrivate;
|
|
|
|
class WorkerLocation;
|
|
|
|
class WorkerNavigator;
|
2014-08-29 23:50:06 +00:00
|
|
|
class Performance;
|
2013-11-05 14:16:26 +00:00
|
|
|
|
2014-04-01 06:13:50 +00:00
|
|
|
class WorkerGlobalScope : public DOMEventTargetHelper,
|
2015-01-18 03:17:06 +00:00
|
|
|
public nsIGlobalObject,
|
|
|
|
public nsSupportsWeakReference
|
2013-11-05 14:16:26 +00:00
|
|
|
{
|
2016-02-16 21:46:08 +00:00
|
|
|
typedef mozilla::dom::IDBFactory IDBFactory;
|
2014-12-17 06:26:15 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Console> mConsole;
|
|
|
|
RefPtr<WorkerLocation> mLocation;
|
|
|
|
RefPtr<WorkerNavigator> mNavigator;
|
|
|
|
RefPtr<Performance> mPerformance;
|
|
|
|
RefPtr<IDBFactory> mIndexedDB;
|
|
|
|
RefPtr<cache::CacheStorage> mCacheStorage;
|
2013-11-05 14:16:26 +00:00
|
|
|
|
2015-07-23 15:30:27 +00:00
|
|
|
uint32_t mWindowInteractionsAllowed;
|
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
protected:
|
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
|
2014-09-01 22:26:43 +00:00
|
|
|
explicit WorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
2013-11-05 14:16:26 +00:00
|
|
|
virtual ~WorkerGlobalScope();
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual JSObject*
|
2015-03-21 16:28:04 +00:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-05 14:16:26 +00:00
|
|
|
|
2015-01-08 21:56:42 +00:00
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx, JS::MutableHandle<JSObject*> aReflector) = 0;
|
2013-11-05 14:16:26 +00:00
|
|
|
|
|
|
|
virtual JSObject*
|
2015-03-21 16:28:04 +00:00
|
|
|
GetGlobalJSObject(void) override
|
2013-11-05 14:16:26 +00:00
|
|
|
{
|
|
|
|
return GetWrapper();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScope,
|
2014-04-01 06:13:50 +00:00
|
|
|
DOMEventTargetHelper)
|
2013-11-05 14:16:26 +00:00
|
|
|
|
2015-04-27 17:38:12 +00:00
|
|
|
WorkerGlobalScope*
|
2013-11-05 14:16:26 +00:00
|
|
|
Self()
|
|
|
|
{
|
2015-04-27 17:38:12 +00:00
|
|
|
return this;
|
2013-11-05 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
2014-08-08 12:34:30 +00:00
|
|
|
Console*
|
2014-02-27 23:39:30 +00:00
|
|
|
GetConsole();
|
2014-01-26 12:35:17 +00:00
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
already_AddRefed<WorkerLocation>
|
|
|
|
Location();
|
2013-11-19 23:08:50 +00:00
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
already_AddRefed<WorkerNavigator>
|
|
|
|
Navigator();
|
2013-11-19 23:08:50 +00:00
|
|
|
|
|
|
|
already_AddRefed<WorkerNavigator>
|
|
|
|
GetExistingNavigator() const;
|
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
void
|
2015-03-06 03:48:07 +00:00
|
|
|
Close(JSContext* aCx, ErrorResult& aRv);
|
2013-11-05 14:16:26 +00:00
|
|
|
|
|
|
|
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 15:13:38 +00:00
|
|
|
SetTimeout(JSContext* /* unused */, const nsAString& aHandler,
|
|
|
|
const int32_t aTimeout, const Sequence<JS::Value>& /* unused */,
|
2013-11-05 14:16:26 +00: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 15:13:38 +00:00
|
|
|
SetInterval(JSContext* /* unused */, const nsAString& aHandler,
|
|
|
|
const Optional<int32_t>& aTimeout,
|
|
|
|
const Sequence<JS::Value>& /* unused */, ErrorResult& aRv);
|
2013-11-05 14:16:26 +00: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-19 23:08:50 +00:00
|
|
|
IMPL_EVENT_HANDLER(online)
|
|
|
|
IMPL_EVENT_HANDLER(offline)
|
2013-11-05 14:16:26 +00:00
|
|
|
IMPL_EVENT_HANDLER(close)
|
|
|
|
|
|
|
|
void
|
|
|
|
Dump(const Optional<nsAString>& aString) const;
|
2014-08-29 23:50:06 +00:00
|
|
|
|
|
|
|
Performance* GetPerformance();
|
2014-07-25 01:30:07 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-11-20 11:58:00 +00:00
|
|
|
Fetch(const RequestOrUSVString& aInput, const RequestInit& aInit, ErrorResult& aRv);
|
2014-12-17 06:26:15 +00:00
|
|
|
|
|
|
|
already_AddRefed<IDBFactory>
|
|
|
|
GetIndexedDB(ErrorResult& aErrorResult);
|
2015-03-02 13:23:00 +00:00
|
|
|
|
|
|
|
already_AddRefed<cache::CacheStorage>
|
|
|
|
GetCaches(ErrorResult& aRv);
|
2015-07-30 18:47:00 +00: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 15:30:27 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
WindowInteractionAllowed() const
|
|
|
|
{
|
|
|
|
return mWindowInteractionsAllowed > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AllowWindowInteraction()
|
|
|
|
{
|
|
|
|
mWindowInteractionsAllowed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ConsumeWindowInteraction()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWindowInteractionsAllowed > 0);
|
|
|
|
mWindowInteractionsAllowed--;
|
|
|
|
}
|
2013-11-05 14:16:26 +00:00
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class DedicatedWorkerGlobalScope final : public WorkerGlobalScope
|
2013-11-05 14:16:26 +00:00
|
|
|
{
|
|
|
|
~DedicatedWorkerGlobalScope() { }
|
|
|
|
|
|
|
|
public:
|
2014-09-01 22:26:43 +00:00
|
|
|
explicit DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
2013-11-05 14:16:26 +00:00
|
|
|
|
2015-01-08 21:56:42 +00:00
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx,
|
2015-03-21 16:28:04 +00:00
|
|
|
JS::MutableHandle<JSObject*> aReflector) override;
|
2013-11-05 14:16:26 +00: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 16:28:04 +00:00
|
|
|
class SharedWorkerGlobalScope final : public WorkerGlobalScope
|
2013-11-05 14:16:26 +00:00
|
|
|
{
|
2014-02-06 14:39:10 +00:00
|
|
|
const nsCString mName;
|
2013-11-05 14:16:26 +00:00
|
|
|
|
|
|
|
~SharedWorkerGlobalScope() { }
|
|
|
|
|
|
|
|
public:
|
2014-02-06 14:39:10 +00:00
|
|
|
SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
|
|
|
|
const nsCString& aName);
|
2013-11-05 14:16:26 +00:00
|
|
|
|
2015-01-08 21:56:42 +00:00
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx,
|
2015-03-21 16:28:04 +00:00
|
|
|
JS::MutableHandle<JSObject*> aReflector) override;
|
2013-11-05 14:16:26 +00:00
|
|
|
|
2014-05-13 21:28:01 +00:00
|
|
|
void GetName(DOMString& aName) const
|
|
|
|
{
|
2014-02-06 14:39:10 +00:00
|
|
|
aName.AsAString() = NS_ConvertUTF8toUTF16(mName);
|
2013-11-05 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(connect)
|
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class ServiceWorkerGlobalScope final : public WorkerGlobalScope
|
2014-05-13 21:28:01 +00:00
|
|
|
{
|
|
|
|
const nsString mScope;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ServiceWorkerClients> mClients;
|
|
|
|
RefPtr<ServiceWorkerRegistrationWorkerThread> mRegistration;
|
2014-10-27 11:03:00 +00:00
|
|
|
|
2014-10-27 11:03:00 +00:00
|
|
|
~ServiceWorkerGlobalScope();
|
2014-05-13 21:28:01 +00:00
|
|
|
|
|
|
|
public:
|
2014-10-27 11:03:00 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerGlobalScope,
|
|
|
|
WorkerGlobalScope)
|
2015-06-26 01:50:24 +00:00
|
|
|
IMPL_EVENT_HANDLER(notificationclick)
|
2014-10-27 11:03:00 +00:00
|
|
|
|
2014-05-13 21:28:01 +00:00
|
|
|
ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, const nsACString& aScope);
|
|
|
|
|
2015-01-08 21:56:42 +00:00
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx,
|
2015-03-21 16:28:04 +00:00
|
|
|
JS::MutableHandle<JSObject*> aReflector) override;
|
2014-05-13 21:28:01 +00:00
|
|
|
|
2015-06-12 23:28:13 +00:00
|
|
|
static bool
|
|
|
|
InterceptionEnabled(JSContext* aCx, JSObject* aObj);
|
|
|
|
|
2015-10-25 20:36:27 +00:00
|
|
|
static bool
|
|
|
|
OpenWindowEnabled(JSContext* aCx, JSObject* aObj);
|
|
|
|
|
2014-05-13 21:28:01 +00:00
|
|
|
void
|
2015-02-12 23:39:26 +00:00
|
|
|
GetScope(nsString& aScope) const
|
2014-05-13 21:28:01 +00:00
|
|
|
{
|
2015-02-12 23:39:26 +00:00
|
|
|
aScope = mScope;
|
2014-05-13 21:28:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-27 11:03:00 +00:00
|
|
|
ServiceWorkerClients*
|
2014-10-27 11:03:00 +00:00
|
|
|
Clients();
|
2014-10-27 11:03:00 +00:00
|
|
|
|
2015-04-04 05:46:07 +00:00
|
|
|
ServiceWorkerRegistrationWorkerThread*
|
|
|
|
Registration();
|
|
|
|
|
2015-06-02 11:12:00 +00:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
SkipWaiting(ErrorResult& aRv);
|
|
|
|
|
2014-05-13 21:28:01 +00:00
|
|
|
IMPL_EVENT_HANDLER(activate)
|
|
|
|
IMPL_EVENT_HANDLER(fetch)
|
|
|
|
IMPL_EVENT_HANDLER(install)
|
|
|
|
IMPL_EVENT_HANDLER(message)
|
2015-04-23 18:43:40 +00:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(push)
|
|
|
|
IMPL_EVENT_HANDLER(pushsubscriptionchange)
|
|
|
|
|
2014-05-13 21:28:01 +00:00
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class WorkerDebuggerGlobalScope final : public DOMEventTargetHelper,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsIGlobalObject
|
2015-03-03 23:51:53 +00:00
|
|
|
{
|
|
|
|
WorkerPrivate* mWorkerPrivate;
|
2016-02-11 17:41:17 +00:00
|
|
|
RefPtr<Console> mConsole;
|
2015-03-03 23:51:53 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit WorkerDebuggerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2016-02-11 17:41:17 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerDebuggerGlobalScope,
|
|
|
|
DOMEventTargetHelper)
|
2015-03-03 23:51:53 +00:00
|
|
|
|
|
|
|
virtual JSObject*
|
2015-03-21 16:28:04 +00:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2015-03-03 23:51:53 +00:00
|
|
|
{
|
|
|
|
MOZ_CRASH("Shouldn't get here!");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
WrapGlobalObject(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aReflector);
|
|
|
|
|
|
|
|
virtual JSObject*
|
2015-03-21 16:28:04 +00:00
|
|
|
GetGlobalJSObject(void) override
|
2015-03-03 23:51:53 +00:00
|
|
|
{
|
|
|
|
return GetWrapper();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetGlobal(JSContext* aCx, JS::MutableHandle<JSObject*> aGlobal);
|
|
|
|
|
2015-03-31 10:22:40 +00: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 06:17:16 +00:00
|
|
|
void
|
|
|
|
EnterEventLoop();
|
|
|
|
|
|
|
|
void
|
|
|
|
LeaveEventLoop();
|
|
|
|
|
2015-03-20 11:15:59 +00:00
|
|
|
void
|
|
|
|
PostMessage(const nsAString& aMessage);
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(message)
|
|
|
|
|
2015-03-30 11:54:38 +00:00
|
|
|
void
|
2016-02-26 20:23:12 +00:00
|
|
|
SetImmediate(Function& aHandler, ErrorResult& aRv);
|
2015-03-30 11:54:38 +00:00
|
|
|
|
2015-03-26 19:09:45 +00:00
|
|
|
void
|
|
|
|
ReportError(JSContext* aCx, const nsAString& aMessage);
|
|
|
|
|
2016-02-11 17:41:17 +00:00
|
|
|
Console*
|
|
|
|
GetConsole(ErrorResult& aRv);
|
|
|
|
|
2015-03-03 23:51:53 +00:00
|
|
|
void
|
|
|
|
Dump(JSContext* aCx, const Optional<nsAString>& aString) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~WorkerDebuggerGlobalScope();
|
|
|
|
};
|
2012-01-18 18:05:38 +00:00
|
|
|
|
2011-07-17 19:09:13 +00:00
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
2014-10-27 11:03:00 +00:00
|
|
|
inline nsISupports*
|
|
|
|
ToSupports(mozilla::dom::workers::WorkerGlobalScope* aScope)
|
|
|
|
{
|
|
|
|
return static_cast<nsIDOMEventTarget*>(aScope);
|
|
|
|
}
|
|
|
|
|
2013-11-05 14:16:26 +00:00
|
|
|
#endif /* mozilla_dom_workerscope_h__ */
|