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-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_workers_workerprivate_h__
|
|
|
|
#define mozilla_dom_workers_workerprivate_h__
|
|
|
|
|
2018-01-30 12:10:04 +03:00
|
|
|
#include "WorkerCommon.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
#include "mozilla/CondVar.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2018-01-30 12:14:00 +03:00
|
|
|
#include "nsDOMNavigationTiming.h"
|
|
|
|
#include "nsIContentSecurityPolicy.h"
|
|
|
|
#include "nsIEventTarget.h"
|
2013-06-05 18:04:23 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2015-04-07 20:31:51 +03:00
|
|
|
#include "nsTObserverArray.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
#include "Queue.h"
|
2016-06-23 11:53:14 +03:00
|
|
|
#include "WorkerHolder.h"
|
2018-01-30 12:14:00 +03:00
|
|
|
#include "WorkerLoadInfo.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-04-09 03:28:25 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#undef PostMessage
|
|
|
|
#endif
|
|
|
|
|
2016-05-23 09:56:46 +03:00
|
|
|
class nsIConsoleReportCollector;
|
2014-01-11 04:37:47 +04:00
|
|
|
class nsIThreadInternal;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2018-01-30 12:14:00 +03:00
|
|
|
|
2017-11-21 23:13:04 +03:00
|
|
|
class ClientInfo;
|
|
|
|
class ClientSource;
|
2013-11-05 18:16:26 +04:00
|
|
|
class Function;
|
2015-09-16 06:27:56 +03:00
|
|
|
class MessagePort;
|
|
|
|
class MessagePortIdentifier;
|
2018-01-24 19:17:31 +03:00
|
|
|
class PerformanceStorage;
|
2018-01-31 10:19:10 +03:00
|
|
|
class SharedWorker;
|
2018-01-31 10:21:06 +03:00
|
|
|
class WorkerDebugger;
|
2016-06-28 20:47:23 +03:00
|
|
|
class WorkerDebuggerGlobalScope;
|
2018-01-30 12:12:50 +03:00
|
|
|
class WorkerErrorReport;
|
2018-01-31 10:20:25 +03:00
|
|
|
class WorkerEventTarget;
|
2016-06-28 20:47:23 +03:00
|
|
|
class WorkerGlobalScope;
|
2017-05-17 17:48:54 +03:00
|
|
|
struct WorkerOptions;
|
2018-01-31 10:20:07 +03:00
|
|
|
class WorkerThread;
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2018-01-30 12:14:00 +03:00
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|
2013-10-23 17:16:49 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
class WorkerControlRunnable;
|
|
|
|
class WorkerRunnable;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-02-08 15:50:00 +04:00
|
|
|
// SharedMutex is a small wrapper around an (internal) reference-counted Mutex
|
|
|
|
// object. It exists to avoid changing a lot of code to use Mutex* instead of
|
|
|
|
// Mutex&.
|
|
|
|
class SharedMutex
|
|
|
|
{
|
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class RefCountedMutex final : public Mutex
|
2013-02-08 15:50:00 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit RefCountedMutex(const char* aName)
|
2013-02-08 15:50:00 +04:00
|
|
|
: Mutex(aName)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RefCountedMutex)
|
|
|
|
|
|
|
|
private:
|
|
|
|
~RefCountedMutex()
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<RefCountedMutex> mMutex;
|
2013-02-08 15:50:00 +04:00
|
|
|
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit SharedMutex(const char* aName)
|
2013-02-08 15:50:00 +04:00
|
|
|
: mMutex(new RefCountedMutex(aName))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
SharedMutex(SharedMutex& aOther)
|
|
|
|
: mMutex(aOther.mMutex)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
operator Mutex&()
|
|
|
|
{
|
|
|
|
return *mMutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator const Mutex&() const
|
|
|
|
{
|
|
|
|
return *mMutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertCurrentThreadOwns() const
|
|
|
|
{
|
|
|
|
mMutex->AssertCurrentThreadOwns();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
template <class Derived>
|
2014-04-01 10:13:50 +04:00
|
|
|
class WorkerPrivateParent : public DOMEventTargetHelper
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-10-23 17:16:49 +04:00
|
|
|
protected:
|
|
|
|
class EventTarget;
|
|
|
|
friend class EventTarget;
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
public:
|
|
|
|
struct LocationInfo
|
|
|
|
{
|
|
|
|
nsCString mHref;
|
|
|
|
nsCString mProtocol;
|
|
|
|
nsCString mHost;
|
|
|
|
nsCString mHostname;
|
|
|
|
nsCString mPort;
|
|
|
|
nsCString mPathname;
|
|
|
|
nsCString mSearch;
|
|
|
|
nsCString mHash;
|
2014-01-31 22:22:52 +04:00
|
|
|
nsString mOrigin;
|
2011-07-17 23:09:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
2013-06-05 18:04:23 +04:00
|
|
|
typedef mozilla::ErrorResult ErrorResult;
|
|
|
|
|
2013-02-08 15:50:00 +04:00
|
|
|
SharedMutex mMutex;
|
2011-07-17 23:09:13 +04:00
|
|
|
mozilla::CondVar mCondVar;
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
// Protected by mMutex.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<WorkerRunnable>> mPreStartRunnables;
|
2013-10-23 17:16:49 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
private:
|
|
|
|
WorkerPrivate* mParent;
|
|
|
|
nsString mScriptURL;
|
2017-05-17 17:49:34 +03:00
|
|
|
// This is the worker name for shared workers and dedicated workers.
|
|
|
|
nsString mWorkerName;
|
2011-07-17 23:09:13 +04:00
|
|
|
LocationInfo mLocationInfo;
|
2013-11-05 18:16:24 +04:00
|
|
|
// The lifetime of these objects within LoadInfo is managed explicitly;
|
|
|
|
// they do not need to be cycle collected.
|
2015-02-12 12:50:05 +03:00
|
|
|
WorkerLoadInfo mLoadInfo;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2015-03-19 21:41:42 +03:00
|
|
|
Atomic<bool> mLoadingWorkerScript;
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
// Only used for top level workers.
|
2013-10-23 17:16:49 +04:00
|
|
|
nsTArray<nsCOMPtr<nsIRunnable>> mQueuedRunnables;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-05-17 02:49:43 +04:00
|
|
|
// Protected by mMutex.
|
|
|
|
JSSettings mJSSettings;
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
// Only touched on the parent thread (currently this is always the main
|
|
|
|
// thread as SharedWorkers are always top-level).
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<SharedWorker>> mSharedWorkers;
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2017-11-15 09:58:38 +03:00
|
|
|
// This is touched on parent thread only, but it can be read on a different
|
|
|
|
// thread before crashing because hanging.
|
|
|
|
Atomic<uint64_t> mBusyCount;
|
|
|
|
|
2016-10-25 16:26:04 +03:00
|
|
|
// SharedWorkers may have multiple windows paused, so this must be
|
|
|
|
// a count instead of just a boolean.
|
|
|
|
uint32_t mParentWindowPausedDepth;
|
2011-07-17 23:09:13 +04:00
|
|
|
Status mParentStatus;
|
2015-04-01 12:00:19 +03:00
|
|
|
bool mParentFrozen;
|
2011-07-17 23:09:13 +04:00
|
|
|
bool mIsChromeWorker;
|
2012-03-31 08:42:20 +04:00
|
|
|
bool mMainThreadObjectsForgotten;
|
2016-10-10 22:09:00 +03:00
|
|
|
// mIsSecureContext is set once in our constructor; after that it can be read
|
|
|
|
// from various threads. We could make this const if we were OK with setting
|
|
|
|
// it in the initializer list via calling some function that takes all sorts
|
|
|
|
// of state (loadinfo, worker type, parent).
|
|
|
|
//
|
|
|
|
// It's a bit unfortunate that we have to have an out-of-band boolean for
|
|
|
|
// this, but we need access to this state from the parent thread, and we can't
|
|
|
|
// use our global object's secure state there.
|
|
|
|
bool mIsSecureContext;
|
2013-10-31 03:40:16 +04:00
|
|
|
WorkerType mWorkerType;
|
2014-05-06 13:50:12 +04:00
|
|
|
TimeStamp mCreationTimeStamp;
|
2015-05-25 19:53:07 +03:00
|
|
|
DOMHighResTimeStamp mCreationTimeHighRes;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
protected:
|
2014-02-02 22:08:50 +04:00
|
|
|
// The worker is owned by its thread, which is represented here. This is set
|
|
|
|
// in Construct() and emptied by WorkerFinishedRunnable, and conditionally
|
|
|
|
// traversed by the cycle collector if the busy count is zero.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerPrivate> mSelfRef;
|
2014-02-02 22:08:50 +04:00
|
|
|
|
2016-03-12 00:43:30 +03:00
|
|
|
WorkerPrivateParent(WorkerPrivate* aParent,
|
2013-11-05 18:16:24 +04:00
|
|
|
const nsAString& aScriptURL, bool aIsChromeWorker,
|
|
|
|
WorkerType aWorkerType,
|
2017-05-17 17:49:34 +03:00
|
|
|
const nsAString& aWorkerName,
|
|
|
|
const nsACString& aServiceWorkerScope,
|
2015-02-12 12:50:05 +03:00
|
|
|
WorkerLoadInfo& aLoadInfo);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
~WorkerPrivateParent();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Derived*
|
|
|
|
ParentAsWorkerPrivate() const
|
|
|
|
{
|
|
|
|
return static_cast<Derived*>(const_cast<WorkerPrivateParent*>(this));
|
|
|
|
}
|
|
|
|
|
2011-12-29 22:28:13 +04:00
|
|
|
bool
|
2016-02-26 00:05:39 +03:00
|
|
|
NotifyPrivate(Status aStatus);
|
2011-12-29 22:28:13 +04:00
|
|
|
|
|
|
|
bool
|
2016-03-12 00:43:30 +03:00
|
|
|
TerminatePrivate()
|
2011-12-29 22:28:13 +04:00
|
|
|
{
|
2016-02-26 00:05:39 +03:00
|
|
|
return NotifyPrivate(Terminating);
|
2011-12-29 22:28:13 +04:00
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:24 +04:00
|
|
|
void
|
2013-06-05 18:04:23 +04:00
|
|
|
PostMessageInternal(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
2017-02-03 13:00:38 +03:00
|
|
|
const Sequence<JSObject*>& aTransferable,
|
2013-11-05 18:16:24 +04:00
|
|
|
ErrorResult& aRv);
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
nsresult
|
2016-06-01 03:04:54 +03:00
|
|
|
DispatchPrivate(already_AddRefed<WorkerRunnable> aRunnable, nsIEventTarget* aSyncLoopTarget);
|
2013-10-23 17:16:49 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
public:
|
2013-11-05 18:16:24 +04:00
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-05 18:16:24 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerPrivateParent,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-11-05 18:16:24 +04:00
|
|
|
|
2014-10-27 20:00:05 +03:00
|
|
|
void
|
|
|
|
EnableDebugger();
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableDebugger();
|
|
|
|
|
2014-02-02 22:08:50 +04:00
|
|
|
void
|
|
|
|
ClearSelfRef()
|
|
|
|
{
|
|
|
|
AssertIsOnParentThread();
|
|
|
|
MOZ_ASSERT(mSelfRef);
|
|
|
|
mSelfRef = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
nsresult
|
2016-06-01 03:04:54 +03:00
|
|
|
Dispatch(already_AddRefed<WorkerRunnable> aRunnable)
|
2013-10-23 17:16:49 +04:00
|
|
|
{
|
2015-07-10 06:21:46 +03:00
|
|
|
return DispatchPrivate(Move(aRunnable), nullptr);
|
2013-10-23 17:16:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-06-01 03:04:54 +03:00
|
|
|
DispatchControlRunnable(already_AddRefed<WorkerControlRunnable> aWorkerControlRunnable);
|
2013-10-23 17:16:49 +04:00
|
|
|
|
2015-03-04 17:11:32 +03:00
|
|
|
nsresult
|
2016-06-01 03:04:54 +03:00
|
|
|
DispatchDebuggerRunnable(already_AddRefed<WorkerRunnable> aDebuggerRunnable);
|
2015-03-04 17:11:32 +03:00
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
already_AddRefed<WorkerRunnable>
|
2016-06-01 03:04:54 +03:00
|
|
|
MaybeWrapAsWorkerRunnable(already_AddRefed<nsIRunnable> aRunnable);
|
2013-10-23 17:16:49 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
// May be called on any thread...
|
|
|
|
bool
|
|
|
|
Start();
|
|
|
|
|
|
|
|
// Called on the parent thread.
|
|
|
|
bool
|
2016-02-26 00:05:39 +03:00
|
|
|
Notify(Status aStatus)
|
2011-12-29 22:28:13 +04:00
|
|
|
{
|
2016-02-26 00:05:39 +03:00
|
|
|
return NotifyPrivate(aStatus);
|
2011-12-29 22:28:13 +04:00
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
bool
|
2016-02-26 00:05:39 +03:00
|
|
|
Cancel()
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2016-02-26 00:05:39 +03:00
|
|
|
return Notify(Canceling);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-03-18 06:23:55 +03:00
|
|
|
Kill()
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2016-02-26 00:05:39 +03:00
|
|
|
return Notify(Killing);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2015-04-01 12:00:19 +03:00
|
|
|
// We can assume that an nsPIDOMWindow will be available for Freeze, Thaw
|
|
|
|
// as these are only used for globals going in and out of the bfcache.
|
2016-02-26 23:23:12 +03:00
|
|
|
//
|
|
|
|
// XXXbz: This is a bald-faced lie given the uses in RegisterSharedWorker and
|
|
|
|
// CloseSharedWorkersForWindow, which pass null for aWindow to Thaw and Freeze
|
|
|
|
// respectively. See bug 1251722.
|
2013-06-05 18:04:23 +04:00
|
|
|
bool
|
2016-02-26 23:23:12 +03:00
|
|
|
Freeze(nsPIDOMWindowInner* aWindow);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-06-06 21:28:47 +04:00
|
|
|
bool
|
2016-02-26 23:23:12 +03:00
|
|
|
Thaw(nsPIDOMWindowInner* aWindow);
|
2013-06-06 21:28:47 +04:00
|
|
|
|
2016-10-04 13:14:07 +03:00
|
|
|
// When we debug a worker, we want to disconnect the window and the worker
|
|
|
|
// communication. This happens calling this method.
|
|
|
|
// Note: this method doesn't suspend the worker! Use Freeze/Thaw instead.
|
2015-10-07 13:20:59 +03:00
|
|
|
void
|
2016-10-04 13:14:07 +03:00
|
|
|
ParentWindowPaused();
|
2015-10-07 13:20:59 +03:00
|
|
|
|
|
|
|
void
|
2016-10-04 13:14:07 +03:00
|
|
|
ParentWindowResumed();
|
2015-10-07 13:20:59 +03:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
bool
|
2016-03-12 00:43:30 +03:00
|
|
|
Terminate()
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2012-03-31 08:42:20 +04:00
|
|
|
AssertIsOnParentThread();
|
2016-03-12 00:43:30 +03:00
|
|
|
return TerminatePrivate();
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-04-15 05:35:01 +03:00
|
|
|
Close();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
bool
|
2016-02-26 00:05:39 +03:00
|
|
|
ModifyBusyCount(bool aIncrease);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2017-02-07 18:28:39 +03:00
|
|
|
bool
|
|
|
|
ProxyReleaseMainThreadObjects();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:24 +04:00
|
|
|
void
|
2013-05-04 11:53:00 +04:00
|
|
|
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
2017-02-03 13:00:38 +03:00
|
|
|
const Sequence<JSObject*>& aTransferable,
|
2015-10-01 02:11:03 +03:00
|
|
|
ErrorResult& aRv);
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
void
|
2016-07-07 09:15:15 +03:00
|
|
|
UpdateContextOptions(const JS::ContextOptions& aContextOptions);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2014-09-05 18:26:34 +04:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
UpdateLanguages(const nsTArray<nsString>& aLanguages);
|
2014-09-05 18:26:34 +04:00
|
|
|
|
2012-01-04 23:11:32 +04:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
UpdateJSWorkerMemoryParameter(JSGCParamKey key, uint32_t value);
|
2012-01-04 23:11:32 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
#ifdef JS_GC_ZEAL
|
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
UpdateGCZeal(uint8_t aGCZeal, uint32_t aFrequency);
|
2011-07-17 23:09:13 +04:00
|
|
|
#endif
|
|
|
|
|
2012-01-18 00:05:25 +04:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
GarbageCollect(bool aShrinking);
|
2012-01-18 00:05:25 +04:00
|
|
|
|
2013-12-03 08:07:02 +04:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
CycleCollect(bool aDummy);
|
2013-12-03 08:07:02 +04:00
|
|
|
|
2013-11-20 03:08:50 +04:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
OfflineStatusChangeEvent(bool aIsOffline);
|
2013-11-20 03:08:50 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
void
|
|
|
|
MemoryPressure(bool aDummy);
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
bool
|
2016-02-26 23:23:12 +03:00
|
|
|
RegisterSharedWorker(SharedWorker* aSharedWorker, MessagePort* aPort);
|
2013-06-05 18:04:23 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
BroadcastErrorToSharedWorkers(JSContext* aCx,
|
2017-02-15 17:53:07 +03:00
|
|
|
const WorkerErrorReport* aReport,
|
2017-01-28 17:39:24 +03:00
|
|
|
bool aIsErrorEvent);
|
2013-06-05 18:04:23 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
WorkerScriptLoaded();
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
void
|
2013-10-23 17:16:49 +04:00
|
|
|
QueueRunnable(nsIRunnable* aRunnable)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2016-10-12 16:15:04 +03:00
|
|
|
AssertIsOnParentThread();
|
2011-07-17 23:09:13 +04:00
|
|
|
mQueuedRunnables.AppendElement(aRunnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerPrivate*
|
|
|
|
GetParent() const
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-04-01 12:00:19 +03:00
|
|
|
IsFrozen() const
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
|
|
|
AssertIsOnParentThread();
|
2015-04-01 12:00:19 +03:00
|
|
|
return mParentFrozen;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2015-10-07 13:20:59 +03:00
|
|
|
bool
|
2016-10-04 13:14:07 +03:00
|
|
|
IsParentWindowPaused() const
|
2015-10-07 13:20:59 +03:00
|
|
|
{
|
|
|
|
AssertIsOnParentThread();
|
2016-10-25 16:26:04 +03:00
|
|
|
return mParentWindowPausedDepth > 0;
|
2015-10-07 13:20:59 +03:00
|
|
|
}
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
bool
|
|
|
|
IsAcceptingEvents()
|
|
|
|
{
|
|
|
|
AssertIsOnParentThread();
|
2013-10-23 17:16:49 +04:00
|
|
|
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
return mParentStatus < Terminating;
|
2013-02-08 15:50:00 +04:00
|
|
|
}
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
Status
|
|
|
|
ParentStatus() const
|
|
|
|
{
|
|
|
|
mMutex.AssertCurrentThreadOwns();
|
|
|
|
return mParentStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIScriptContext*
|
|
|
|
GetScriptContext() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mScriptContext;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsString&
|
|
|
|
ScriptURL() const
|
|
|
|
{
|
|
|
|
return mScriptURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString&
|
|
|
|
Domain() const
|
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mDomain;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
bool
|
|
|
|
IsFromWindow() const
|
|
|
|
{
|
|
|
|
return mLoadInfo.mFromWindow;
|
|
|
|
}
|
|
|
|
|
2017-01-04 12:09:00 +03:00
|
|
|
nsLoadFlags
|
|
|
|
GetLoadFlags() const
|
|
|
|
{
|
|
|
|
return mLoadInfo.mLoadFlags;
|
|
|
|
}
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
uint64_t
|
|
|
|
WindowID() const
|
|
|
|
{
|
|
|
|
return mLoadInfo.mWindowID;
|
|
|
|
}
|
|
|
|
|
2015-05-14 22:41:42 +03:00
|
|
|
uint64_t
|
|
|
|
ServiceWorkerID() const
|
|
|
|
{
|
2017-10-30 20:35:07 +03:00
|
|
|
return GetServiceWorkerDescriptor().Id();
|
2015-05-14 22:41:42 +03:00
|
|
|
}
|
|
|
|
|
2017-03-25 02:56:48 +03:00
|
|
|
const nsCString&
|
|
|
|
ServiceWorkerScope() const
|
|
|
|
{
|
2017-10-30 20:35:07 +03:00
|
|
|
return GetServiceWorkerDescriptor().Scope();
|
2017-03-25 02:56:48 +03:00
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
nsIURI*
|
|
|
|
GetBaseURI() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mBaseURI;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2011-11-04 20:32:17 +04:00
|
|
|
void
|
2011-07-17 23:09:13 +04:00
|
|
|
SetBaseURI(nsIURI* aBaseURI);
|
|
|
|
|
|
|
|
nsIURI*
|
2013-06-05 18:04:23 +04:00
|
|
|
GetResolvedScriptURI() const
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mResolvedScriptURI;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:41:42 +03:00
|
|
|
const nsString&
|
|
|
|
ServiceWorkerCacheName() const
|
|
|
|
{
|
2017-10-30 20:35:07 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker());
|
2015-03-19 21:41:42 +03:00
|
|
|
AssertIsOnMainThread();
|
2015-03-20 02:39:01 +03:00
|
|
|
return mLoadInfo.mServiceWorkerCacheName;
|
2015-03-19 21:41:42 +03:00
|
|
|
}
|
2015-03-20 02:39:01 +03:00
|
|
|
|
2017-10-30 20:35:07 +03:00
|
|
|
const ServiceWorkerDescriptor&
|
|
|
|
GetServiceWorkerDescriptor() const
|
|
|
|
{
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mLoadInfo.mServiceWorkerDescriptor.isSome());
|
|
|
|
return mLoadInfo.mServiceWorkerDescriptor.ref();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateServiceWorkerState(ServiceWorkerState aState)
|
|
|
|
{
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mLoadInfo.mServiceWorkerDescriptor.isSome());
|
|
|
|
return mLoadInfo.mServiceWorkerDescriptor.ref().SetState(aState);
|
|
|
|
}
|
|
|
|
|
2018-01-23 18:38:54 +03:00
|
|
|
const Maybe<ServiceWorkerDescriptor>&
|
|
|
|
GetParentController() const
|
|
|
|
{
|
|
|
|
return mLoadInfo.mParentController;
|
|
|
|
}
|
|
|
|
|
2015-05-25 21:21:05 +03:00
|
|
|
const ChannelInfo&
|
|
|
|
GetChannelInfo() const
|
2015-04-24 01:59:52 +03:00
|
|
|
{
|
2015-05-25 21:21:05 +03:00
|
|
|
return mLoadInfo.mChannelInfo;
|
2015-04-24 01:59:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-25 21:21:05 +03:00
|
|
|
SetChannelInfo(const ChannelInfo& aChannelInfo)
|
2015-04-24 01:59:52 +03:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
2015-05-25 21:21:05 +03:00
|
|
|
MOZ_ASSERT(!mLoadInfo.mChannelInfo.IsInitialized());
|
|
|
|
MOZ_ASSERT(aChannelInfo.IsInitialized());
|
|
|
|
mLoadInfo.mChannelInfo = aChannelInfo;
|
2015-04-24 01:59:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-25 21:21:05 +03:00
|
|
|
InitChannelInfo(nsIChannel* aChannel)
|
|
|
|
{
|
|
|
|
mLoadInfo.mChannelInfo.InitFromChannel(aChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InitChannelInfo(const ChannelInfo& aChannelInfo)
|
|
|
|
{
|
|
|
|
mLoadInfo.mChannelInfo = aChannelInfo;
|
|
|
|
}
|
2015-04-24 01:59:52 +03:00
|
|
|
|
2015-03-20 02:39:01 +03:00
|
|
|
// This is used to handle importScripts(). When the worker is first loaded
|
|
|
|
// and executed, it happens in a sync loop. At this point it sets
|
|
|
|
// mLoadingWorkerScript to true. importScripts() calls that occur during the
|
|
|
|
// execution run in nested sync loops and so this continues to return true,
|
|
|
|
// leading to these scripts being cached offline.
|
|
|
|
// mLoadingWorkerScript is set to false when the top level loop ends.
|
|
|
|
// importScripts() in function calls or event handlers are always fetched
|
|
|
|
// from the network.
|
|
|
|
bool
|
|
|
|
LoadScriptAsPartOfLoadingServiceWorkerScript()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsServiceWorker());
|
|
|
|
return mLoadingWorkerScript;
|
|
|
|
}
|
|
|
|
|
2015-03-19 21:41:42 +03:00
|
|
|
void
|
|
|
|
SetLoadingWorkerScript(bool aLoadingWorkerScript)
|
|
|
|
{
|
|
|
|
// any thread
|
|
|
|
MOZ_ASSERT(IsServiceWorker());
|
|
|
|
mLoadingWorkerScript = aLoadingWorkerScript;
|
|
|
|
}
|
|
|
|
|
2014-05-06 13:50:12 +04:00
|
|
|
TimeStamp CreationTimeStamp() const
|
|
|
|
{
|
|
|
|
return mCreationTimeStamp;
|
|
|
|
}
|
|
|
|
|
2015-11-19 23:32:49 +03:00
|
|
|
DOMHighResTimeStamp CreationTime() const
|
2015-05-25 19:53:07 +03:00
|
|
|
{
|
|
|
|
return mCreationTimeHighRes;
|
|
|
|
}
|
|
|
|
|
2016-12-16 11:08:05 +03:00
|
|
|
DOMHighResTimeStamp TimeStampToDOMHighRes(const TimeStamp& aTimeStamp) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!aTimeStamp.IsNull());
|
|
|
|
TimeDuration duration = aTimeStamp - mCreationTimeStamp;
|
|
|
|
return duration.ToMilliseconds();
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
nsIPrincipal*
|
|
|
|
GetPrincipal() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mPrincipal;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2017-12-07 14:29:05 +03:00
|
|
|
nsIPrincipal*
|
|
|
|
GetLoadingPrincipal() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mLoadingPrincipal;
|
|
|
|
}
|
|
|
|
|
2017-02-14 00:06:47 +03:00
|
|
|
const nsAString& Origin() const
|
|
|
|
{
|
|
|
|
return mLoadInfo.mOrigin;
|
|
|
|
}
|
|
|
|
|
2014-12-12 19:06:00 +03:00
|
|
|
nsILoadGroup*
|
|
|
|
GetLoadGroup() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mLoadGroup;
|
|
|
|
}
|
|
|
|
|
2013-12-03 23:31:30 +04:00
|
|
|
// This method allows the principal to be retrieved off the main thread.
|
|
|
|
// Principals are main-thread objects so the caller must ensure that all
|
|
|
|
// access occurs on the main thread.
|
|
|
|
nsIPrincipal*
|
|
|
|
GetPrincipalDontAssertMainThread() const
|
|
|
|
{
|
|
|
|
return mLoadInfo.mPrincipal;
|
|
|
|
}
|
|
|
|
|
2017-02-10 21:34:38 +03:00
|
|
|
nsresult
|
2017-02-07 18:28:39 +03:00
|
|
|
SetPrincipalOnMainThread(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SetPrincipalFromChannel(nsIChannel* aChannel);
|
2011-08-16 07:40:38 +04:00
|
|
|
|
2017-02-07 18:28:39 +03:00
|
|
|
bool
|
|
|
|
FinalChannelPrincipalIsValid(nsIChannel* aChannel);
|
2017-02-23 18:54:41 +03:00
|
|
|
|
2018-01-05 01:35:41 +03:00
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-02-23 18:54:41 +03:00
|
|
|
bool
|
|
|
|
PrincipalURIMatchesScriptURL();
|
2017-02-07 18:28:39 +03:00
|
|
|
#endif
|
|
|
|
|
2011-08-16 07:40:38 +04:00
|
|
|
bool
|
|
|
|
UsesSystemPrincipal() const
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mPrincipalIsSystem;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
const PrincipalInfo&
|
|
|
|
GetPrincipalInfo() const
|
|
|
|
{
|
|
|
|
return *mLoadInfo.mPrincipalInfo;
|
|
|
|
}
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
already_AddRefed<nsIChannel>
|
|
|
|
ForgetWorkerChannel()
|
2013-03-08 02:27:21 +04:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mChannel.forget();
|
2013-03-08 02:27:21 +04:00
|
|
|
}
|
|
|
|
|
2015-04-07 19:19:19 +03:00
|
|
|
nsIDocument* GetDocument() const;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner*
|
2011-07-17 23:09:13 +04:00
|
|
|
GetWindow()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mWindow;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2012-09-15 22:51:55 +04:00
|
|
|
nsIContentSecurityPolicy*
|
|
|
|
GetCSP() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mCSP;
|
2012-09-15 22:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-29 05:20:32 +03:00
|
|
|
SetCSP(nsIContentSecurityPolicy* aCSP);
|
2012-09-15 22:51:55 +04:00
|
|
|
|
2017-02-14 18:06:38 +03:00
|
|
|
nsresult
|
|
|
|
SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue,
|
|
|
|
const nsACString& aCSPReportOnlyHeaderValue);
|
|
|
|
|
2017-02-23 18:54:42 +03:00
|
|
|
void
|
|
|
|
SetReferrerPolicyFromHeaderValue(const nsACString& aReferrerPolicyHeaderValue);
|
|
|
|
|
2016-07-05 06:47:13 +03:00
|
|
|
net::ReferrerPolicy
|
|
|
|
GetReferrerPolicy() const
|
|
|
|
{
|
|
|
|
return mLoadInfo.mReferrerPolicy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetReferrerPolicy(net::ReferrerPolicy aReferrerPolicy)
|
|
|
|
{
|
|
|
|
mLoadInfo.mReferrerPolicy = aReferrerPolicy;
|
|
|
|
}
|
|
|
|
|
2012-09-15 22:51:55 +04:00
|
|
|
bool
|
|
|
|
IsEvalAllowed() const
|
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mEvalAllowed;
|
2012-09-15 22:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetEvalAllowed(bool aEvalAllowed)
|
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
mLoadInfo.mEvalAllowed = aEvalAllowed;
|
2012-09-15 22:51:55 +04:00
|
|
|
}
|
|
|
|
|
2012-10-16 00:54:58 +04:00
|
|
|
bool
|
|
|
|
GetReportCSPViolations() const
|
|
|
|
{
|
2013-06-05 18:04:23 +04:00
|
|
|
return mLoadInfo.mReportCSPViolations;
|
|
|
|
}
|
|
|
|
|
2016-06-30 07:31:59 +03:00
|
|
|
void
|
|
|
|
SetReportCSPViolations(bool aReport)
|
|
|
|
{
|
|
|
|
mLoadInfo.mReportCSPViolations = aReport;
|
|
|
|
}
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
bool
|
|
|
|
XHRParamsAllowed() const
|
|
|
|
{
|
|
|
|
return mLoadInfo.mXHRParamsAllowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetXHRParamsAllowed(bool aAllowed)
|
|
|
|
{
|
|
|
|
mLoadInfo.mXHRParamsAllowed = aAllowed;
|
2012-10-16 00:54:58 +04:00
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
LocationInfo&
|
|
|
|
GetLocationInfo()
|
|
|
|
{
|
|
|
|
return mLocationInfo;
|
|
|
|
}
|
|
|
|
|
2013-05-17 02:49:43 +04:00
|
|
|
void
|
|
|
|
CopyJSSettings(JSSettings& aSettings)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-05-17 02:49:43 +04:00
|
|
|
mozilla::MutexAutoLock lock(mMutex);
|
|
|
|
aSettings = mJSSettings;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2013-12-10 15:43:16 +04:00
|
|
|
void
|
|
|
|
CopyJSCompartmentOptions(JS::CompartmentOptions& aOptions)
|
|
|
|
{
|
|
|
|
mozilla::MutexAutoLock lock(mMutex);
|
|
|
|
aOptions = IsChromeWorker() ? mJSSettings.chrome.compartmentOptions
|
|
|
|
: mJSSettings.content.compartmentOptions;
|
|
|
|
}
|
|
|
|
|
2013-10-31 03:40:16 +04:00
|
|
|
// The ability to be a chrome worker is orthogonal to the type of
|
2014-05-12 20:11:15 +04:00
|
|
|
// worker [Dedicated|Shared|Service].
|
2011-07-17 23:09:13 +04:00
|
|
|
bool
|
|
|
|
IsChromeWorker() const
|
|
|
|
{
|
|
|
|
return mIsChromeWorker;
|
|
|
|
}
|
|
|
|
|
2014-10-29 23:11:33 +03:00
|
|
|
WorkerType
|
|
|
|
Type() const
|
|
|
|
{
|
|
|
|
return mWorkerType;
|
|
|
|
}
|
|
|
|
|
2013-10-31 03:40:16 +04:00
|
|
|
bool
|
|
|
|
IsDedicatedWorker() const
|
|
|
|
{
|
|
|
|
return mWorkerType == WorkerTypeDedicated;
|
|
|
|
}
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
bool
|
|
|
|
IsSharedWorker() const
|
|
|
|
{
|
2013-10-31 03:40:16 +04:00
|
|
|
return mWorkerType == WorkerTypeShared;
|
2013-06-05 18:04:23 +04:00
|
|
|
}
|
|
|
|
|
2014-05-12 20:11:15 +04:00
|
|
|
bool
|
|
|
|
IsServiceWorker() const
|
|
|
|
{
|
|
|
|
return mWorkerType == WorkerTypeService;
|
|
|
|
}
|
|
|
|
|
2015-06-17 04:21:08 +03:00
|
|
|
nsContentPolicyType
|
|
|
|
ContentPolicyType() const
|
|
|
|
{
|
|
|
|
return ContentPolicyType(mWorkerType);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsContentPolicyType
|
|
|
|
ContentPolicyType(WorkerType aWorkerType)
|
|
|
|
{
|
|
|
|
switch (aWorkerType) {
|
|
|
|
case WorkerTypeDedicated:
|
|
|
|
return nsIContentPolicy::TYPE_INTERNAL_WORKER;
|
|
|
|
case WorkerTypeShared:
|
|
|
|
return nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER;
|
|
|
|
case WorkerTypeService:
|
2015-09-12 01:48:43 +03:00
|
|
|
return nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER;
|
2015-06-17 04:21:08 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Invalid worker type");
|
|
|
|
return nsIContentPolicy::TYPE_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 17:49:34 +03:00
|
|
|
const nsString&
|
2015-10-01 02:11:03 +03:00
|
|
|
WorkerName() const
|
2013-06-05 18:04:23 +04:00
|
|
|
{
|
2015-10-01 02:11:03 +03:00
|
|
|
return mWorkerName;
|
2013-06-05 18:04:23 +04:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
bool
|
2015-07-16 00:01:02 +03:00
|
|
|
IsStorageAllowed() const
|
2014-12-17 09:26:15 +03:00
|
|
|
{
|
2015-07-16 00:01:02 +03:00
|
|
|
return mLoadInfo.mStorageAllowed;
|
2014-12-17 09:26:15 +03:00
|
|
|
}
|
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
const OriginAttributes&
|
2016-09-20 04:13:00 +03:00
|
|
|
GetOriginAttributes() const
|
2015-06-26 21:18:18 +03:00
|
|
|
{
|
2016-09-20 04:13:00 +03:00
|
|
|
return mLoadInfo.mOriginAttributes;
|
2015-06-26 21:18:18 +03:00
|
|
|
}
|
|
|
|
|
2015-06-28 06:19:24 +03:00
|
|
|
// Determine if the SW testing per-window flag is set by devtools
|
|
|
|
bool
|
|
|
|
ServiceWorkersTestingInWindow() const
|
|
|
|
{
|
|
|
|
return mLoadInfo.mServiceWorkersTestingInWindow;
|
|
|
|
}
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
void
|
2015-10-18 08:24:48 +03:00
|
|
|
GetAllSharedWorkers(nsTArray<RefPtr<SharedWorker>>& aSharedWorkers);
|
2013-06-05 18:04:23 +04:00
|
|
|
|
|
|
|
void
|
2016-01-30 20:05:36 +03:00
|
|
|
CloseSharedWorkersForWindow(nsPIDOMWindowInner* aWindow);
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2015-09-23 08:54:29 +03:00
|
|
|
void
|
|
|
|
CloseAllSharedWorkers();
|
|
|
|
|
2015-02-21 18:09:17 +03:00
|
|
|
void
|
|
|
|
UpdateOverridenLoadGroup(nsILoadGroup* aBaseLoadGroup);
|
|
|
|
|
2015-07-15 22:21:40 +03:00
|
|
|
already_AddRefed<nsIRunnable>
|
|
|
|
StealLoadFailedAsyncRunnable()
|
|
|
|
{
|
|
|
|
return mLoadInfo.mLoadFailedAsyncRunnable.forget();
|
|
|
|
}
|
|
|
|
|
2016-05-23 09:56:46 +03:00
|
|
|
void
|
|
|
|
FlushReportsToSharedWorkers(nsIConsoleReportCollector* aReporter);
|
|
|
|
|
2013-11-05 18:16:24 +04:00
|
|
|
IMPL_EVENT_HANDLER(message)
|
2017-09-13 06:59:06 +03:00
|
|
|
IMPL_EVENT_HANDLER(messageerror)
|
2013-11-05 18:16:24 +04:00
|
|
|
IMPL_EVENT_HANDLER(error)
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2016-10-10 22:09:00 +03:00
|
|
|
// Check whether this worker is a secure context. For use from the parent
|
|
|
|
// thread only; the canonical "is secure context" boolean is stored on the
|
|
|
|
// compartment of the worker global. The only reason we don't
|
|
|
|
// AssertIsOnParentThread() here is so we can assert that this value matches
|
|
|
|
// the one on the compartment, which has to be done from the worker thread.
|
|
|
|
bool IsSecureContext() const
|
|
|
|
{
|
|
|
|
return mIsSecureContext;
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
AssertIsOnParentThread() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertInnerWindowIsCorrect() const;
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
AssertIsOnParentThread() const
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertInnerWindowIsCorrect() const
|
|
|
|
{ }
|
|
|
|
#endif
|
2017-02-14 18:06:39 +03:00
|
|
|
|
2017-05-26 19:53:35 +03:00
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-02-14 18:06:39 +03:00
|
|
|
bool
|
|
|
|
PrincipalIsValid() const;
|
|
|
|
#endif
|
2017-11-15 09:58:38 +03:00
|
|
|
|
|
|
|
// This method is used by RuntimeService to know what is going wrong the
|
|
|
|
// shutting down.
|
|
|
|
uint32_t
|
|
|
|
BusyCount()
|
|
|
|
{
|
|
|
|
return mBusyCount;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
|
|
|
|
{
|
2016-06-23 11:53:14 +03:00
|
|
|
friend class WorkerHolder;
|
2011-07-17 23:09:13 +04:00
|
|
|
friend class WorkerPrivateParent<WorkerPrivate>;
|
|
|
|
typedef WorkerPrivateParent<WorkerPrivate> ParentType;
|
2013-10-23 17:16:49 +04:00
|
|
|
friend class AutoSyncLoopHolder;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
struct TimeoutInfo;
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
class MemoryReporter;
|
|
|
|
friend class MemoryReporter;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-01-31 10:20:07 +03:00
|
|
|
friend class mozilla::dom::WorkerThread;
|
2014-11-17 22:55:37 +03:00
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
enum GCTimerMode
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-10-23 17:16:49 +04:00
|
|
|
PeriodicTimer = 0,
|
|
|
|
IdleTimer,
|
|
|
|
NoTimer
|
2011-07-17 23:09:13 +04:00
|
|
|
};
|
|
|
|
|
2016-01-07 15:35:31 +03:00
|
|
|
bool mDebuggerRegistered;
|
|
|
|
WorkerDebugger* mDebugger;
|
2014-10-27 20:00:05 +03:00
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
Queue<WorkerControlRunnable*, 4> mControlQueue;
|
2015-03-04 17:11:32 +03:00
|
|
|
Queue<WorkerRunnable*, 4> mDebuggerQueue;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
// Touched on multiple threads, protected with mMutex.
|
|
|
|
JSContext* mJSContext;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerThread> mThread;
|
2014-11-17 22:55:37 +03:00
|
|
|
PRThread* mPRThread;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
// Things touched on worker thread only.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerGlobalScope> mScope;
|
|
|
|
RefPtr<WorkerDebuggerGlobalScope> mDebuggerScope;
|
2011-07-17 23:09:13 +04:00
|
|
|
nsTArray<ParentType*> mChildWorkers;
|
2016-06-23 11:53:14 +03:00
|
|
|
nsTObserverArray<WorkerHolder*> mHolders;
|
2017-05-10 19:27:10 +03:00
|
|
|
uint32_t mNumHoldersPreventingShutdownStart;
|
2013-10-23 17:16:49 +04:00
|
|
|
nsTArray<nsAutoPtr<TimeoutInfo>> mTimeouts;
|
2015-03-27 09:17:16 +03:00
|
|
|
uint32_t mDebuggerEventLoopLevel;
|
2016-11-07 23:30:17 +03:00
|
|
|
RefPtr<ThrottledEventQueue> mMainThreadThrottledEventQueue;
|
2016-09-14 06:14:02 +03:00
|
|
|
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
|
2017-07-21 18:16:23 +03:00
|
|
|
RefPtr<WorkerEventTarget> mWorkerControlEventTarget;
|
2017-07-21 18:16:24 +03:00
|
|
|
RefPtr<WorkerEventTarget> mWorkerHybridEventTarget;
|
2013-10-23 17:16:49 +04:00
|
|
|
|
|
|
|
struct SyncLoopInfo
|
|
|
|
{
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit SyncLoopInfo(EventTarget* aEventTarget);
|
2013-10-23 17:16:49 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<EventTarget> mEventTarget;
|
2013-10-23 17:16:49 +04:00
|
|
|
bool mCompleted;
|
|
|
|
bool mResult;
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool mHasRun;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
// This is only modified on the worker thread, but in DEBUG builds
|
|
|
|
// AssertValidSyncLoop function iterates it on other threads. Therefore
|
|
|
|
// modifications are done with mMutex held *only* in DEBUG builds.
|
|
|
|
nsTArray<nsAutoPtr<SyncLoopInfo>> mSyncLoopStack;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
Bug 1059469: Part 2 - When rescheduling the interval timer, cancel it first, and refactor things so that actually does something. r=bent
RunExpiredTimeouts has "fudging" code to always ensure that we execute at least one timeout. This is intended to cover cases where an nsITimer fires slightly early, but it means we must be careful not to fire a timer more times than we intend to or we'll execute a timeout prematurely.
Consider a sequences of setTimeout calls alternating in delay between 0ms and 1000ms. When the 1000ms timeout fires, it schedules a 0ms timeout. The setTimeout call itself calls RescheduleTimeoutTimer, which schedules the timer for a 0 ms delay. And once we unwind the 1000ms timeout RunExpiredTimeouts will also schedule the timer for a 0 ms delay. If the timer has fired (remember, it's processed on a completely different thread) in the meantime, we ultimately will get two callbacks from nsITimer for our 0 ms timeout. The first will run the 0 ms timeout and schedule a 1000 ms timeout, and the second will run the 1000 ms timeout (remember, RunExpiredTimeouts always runs at least one timeout!) ~999 ms ahead of schedule.
The solution is to cancel the timer in RescheduleTimeoutTimer, so that when we call it the second time it will cause any pending events from the first scheduling to be canceled. But this actually doesn't work at all, because of how we use nsITimer. Before worker threads were capable of accepting arbitrary runnables we created TimerThreadEventTarget, which translates the timer firing to the special worker event queue when the timer thread attempts to *dispatch* a runnable to the worker. We still need this for some of the other types of timers (which use control runnables that interrupt JS, and not the regular event queue). But setTimeout can simply run like a normal nsITimer callback now. We need that here, or calling nsITimer::Cancel won't actually do anything, because the timer's event was ignored and TimerThreadEventTarget created its own event.
2016-01-07 00:18:29 +03:00
|
|
|
nsCOMPtr<nsITimerCallback> mTimerRunnable;
|
2013-10-23 17:16:49 +04:00
|
|
|
|
2015-11-18 06:45:43 +03:00
|
|
|
nsCOMPtr<nsITimer> mGCTimer;
|
2013-10-23 17:16:49 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MemoryReporter> mMemoryReporter;
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2015-07-15 22:21:40 +03:00
|
|
|
// fired on the main thread if the worker script fails to load
|
|
|
|
nsCOMPtr<nsIRunnable> mLoadFailedRunnable;
|
|
|
|
|
2018-01-24 19:17:32 +03:00
|
|
|
RefPtr<PerformanceStorage> mPerformanceStorage;
|
|
|
|
|
2016-08-08 23:33:39 +03:00
|
|
|
JS::UniqueChars mDefaultLocale; // nulled during worker JSContext init
|
2013-10-23 17:16:49 +04:00
|
|
|
TimeStamp mKillTime;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mErrorHandlerRecursionCount;
|
|
|
|
uint32_t mNextTimeoutId;
|
2011-07-17 23:09:13 +04:00
|
|
|
Status mStatus;
|
2017-11-21 23:13:04 +03:00
|
|
|
UniquePtr<ClientSource> mClientSource;
|
2015-04-01 12:00:19 +03:00
|
|
|
bool mFrozen;
|
2011-07-17 23:09:13 +04:00
|
|
|
bool mTimerRunning;
|
|
|
|
bool mRunningExpiredTimeouts;
|
2015-09-29 00:34:28 +03:00
|
|
|
bool mPendingEventQueueClearing;
|
2013-10-23 17:16:49 +04:00
|
|
|
bool mCancelAllPendingRunnables;
|
|
|
|
bool mPeriodicGCTimerRunning;
|
2013-12-20 23:03:19 +04:00
|
|
|
bool mIdleGCTimerRunning;
|
2014-05-29 20:33:04 +04:00
|
|
|
bool mWorkerScriptExecutedSuccessfully;
|
2016-12-19 05:38:53 +03:00
|
|
|
bool mFetchHandlerWasAdded;
|
2013-11-20 03:08:50 +04:00
|
|
|
bool mOnLine;
|
2013-11-24 23:27:15 +04:00
|
|
|
|
2013-11-05 18:16:24 +04:00
|
|
|
protected:
|
2013-10-14 22:38:54 +04:00
|
|
|
~WorkerPrivate();
|
2013-10-14 15:58:05 +04:00
|
|
|
|
2013-11-05 18:16:24 +04:00
|
|
|
public:
|
|
|
|
static already_AddRefed<WorkerPrivate>
|
|
|
|
Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL,
|
2017-05-17 17:48:54 +03:00
|
|
|
const WorkerOptions& aOptions,
|
2013-11-05 18:16:24 +04:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
static already_AddRefed<WorkerPrivate>
|
2013-11-05 18:16:24 +04:00
|
|
|
Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL,
|
|
|
|
bool aIsChromeWorker, WorkerType aWorkerType,
|
2017-05-17 17:49:34 +03:00
|
|
|
const nsAString& aWorkerName,
|
2015-02-12 12:50:05 +03:00
|
|
|
WorkerLoadInfo* aLoadInfo, ErrorResult& aRv);
|
2013-11-05 18:16:24 +04:00
|
|
|
|
2014-05-29 20:19:00 +04:00
|
|
|
static already_AddRefed<WorkerPrivate>
|
|
|
|
Constructor(JSContext* aCx, const nsAString& aScriptURL, bool aIsChromeWorker,
|
2017-05-17 17:49:34 +03:00
|
|
|
WorkerType aWorkerType, const nsAString& aWorkerName,
|
|
|
|
const nsACString& aServiceWorkerScope,
|
2015-02-12 12:50:05 +03:00
|
|
|
WorkerLoadInfo* aLoadInfo, ErrorResult& aRv);
|
2014-05-29 20:19:00 +04:00
|
|
|
|
2013-11-05 18:16:24 +04:00
|
|
|
static bool
|
|
|
|
WorkerAvailable(JSContext* /* unused */, JSObject* /* unused */);
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2015-02-21 18:09:17 +03:00
|
|
|
enum LoadGroupBehavior
|
|
|
|
{
|
|
|
|
InheritLoadGroup,
|
|
|
|
OverrideLoadGroup
|
|
|
|
};
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
static nsresult
|
2016-01-30 20:05:36 +03:00
|
|
|
GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
|
|
|
|
WorkerPrivate* aParent,
|
2013-06-05 18:04:23 +04:00
|
|
|
const nsAString& aScriptURL, bool aIsChromeWorker,
|
2015-06-17 04:21:08 +03:00
|
|
|
LoadGroupBehavior aLoadGroupBehavior, WorkerType aWorkerType,
|
|
|
|
WorkerLoadInfo* aLoadInfo);
|
2015-02-21 18:09:17 +03:00
|
|
|
|
2017-12-07 14:29:05 +03:00
|
|
|
// The passed principal must be the Worker principal in case of a
|
|
|
|
// ServiceWorker and the loading principal for any other type.
|
2015-02-21 18:09:17 +03:00
|
|
|
static void
|
2017-12-07 14:29:05 +03:00
|
|
|
OverrideLoadInfoLoadGroup(WorkerLoadInfo& aLoadInfo,
|
|
|
|
nsIPrincipal* aPrincipal);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-01-07 15:35:31 +03:00
|
|
|
bool
|
|
|
|
IsDebuggerRegistered()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
// No need to lock here since this is only ever modified by the same thread.
|
|
|
|
return mDebuggerRegistered;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetIsDebuggerRegistered(bool aDebuggerRegistered)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mDebuggerRegistered != aDebuggerRegistered);
|
|
|
|
mDebuggerRegistered = aDebuggerRegistered;
|
|
|
|
|
|
|
|
mCondVar.Notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaitForIsDebuggerRegistered(bool aDebuggerRegistered)
|
|
|
|
{
|
|
|
|
AssertIsOnParentThread();
|
|
|
|
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
|
|
|
while (mDebuggerRegistered != aDebuggerRegistered) {
|
|
|
|
mCondVar.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 23:11:33 +03:00
|
|
|
WorkerDebugger*
|
|
|
|
Debugger() const
|
|
|
|
{
|
2015-12-22 16:11:27 +03:00
|
|
|
AssertIsOnMainThread();
|
2016-01-07 15:35:31 +03:00
|
|
|
|
2014-10-29 23:11:33 +03:00
|
|
|
MOZ_ASSERT(mDebugger);
|
|
|
|
return mDebugger;
|
|
|
|
}
|
|
|
|
|
2016-01-07 15:35:31 +03:00
|
|
|
void
|
|
|
|
SetDebugger(WorkerDebugger* aDebugger)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
MOZ_ASSERT(mDebugger != aDebugger);
|
|
|
|
mDebugger = aDebugger;
|
|
|
|
}
|
|
|
|
|
2016-08-08 23:33:39 +03:00
|
|
|
JS::UniqueChars
|
|
|
|
AdoptDefaultLocale()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mDefaultLocale,
|
|
|
|
"the default locale must have been successfully set for anyone "
|
|
|
|
"to be trying to adopt it");
|
|
|
|
return Move(mDefaultLocale);
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
void
|
|
|
|
DoRunLoop(JSContext* aCx);
|
|
|
|
|
|
|
|
bool
|
2014-03-11 01:28:43 +04:00
|
|
|
InterruptCallback(JSContext* aCx);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2017-05-22 21:26:39 +03:00
|
|
|
bool
|
|
|
|
IsOnCurrentThread();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
CloseInternal(JSContext* aCx)
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
return NotifyInternal(aCx, Closing);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-02-29 22:52:43 +03:00
|
|
|
FreezeInternal();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
bool
|
2016-02-29 22:52:43 +03:00
|
|
|
ThawInternal();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
void
|
2016-08-16 09:10:30 +03:00
|
|
|
TraverseTimeouts(nsCycleCollectionTraversalCallback& aCallback);
|
|
|
|
|
|
|
|
void
|
|
|
|
UnlinkTimeouts();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
bool
|
2016-02-26 23:23:12 +03:00
|
|
|
ModifyBusyCountFromWorker(bool aIncrease);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
bool
|
2016-03-28 20:28:14 +03:00
|
|
|
AddChildWorker(ParentType* aChildWorker);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
void
|
2016-03-28 20:28:14 +03:00
|
|
|
RemoveChildWorker(ParentType* aChildWorker);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
2013-06-05 18:04:23 +04:00
|
|
|
PostMessageToParent(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aMessage,
|
2017-02-03 13:00:38 +03:00
|
|
|
const Sequence<JSObject*>& aTransferable,
|
2013-11-05 18:16:26 +04:00
|
|
|
ErrorResult& aRv)
|
2013-06-05 18:04:23 +04:00
|
|
|
{
|
2015-09-16 06:27:56 +03:00
|
|
|
PostMessageToParentInternal(aCx, aMessage, aTransferable, aRv);
|
2013-06-05 18:04:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-03 13:00:38 +03:00
|
|
|
PostMessageToParentMessagePort(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aMessage,
|
|
|
|
const Sequence<JSObject*>& aTransferable,
|
|
|
|
ErrorResult& aRv);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2015-03-27 09:17:16 +03:00
|
|
|
void
|
|
|
|
EnterDebuggerEventLoop();
|
|
|
|
|
|
|
|
void
|
|
|
|
LeaveDebuggerEventLoop();
|
|
|
|
|
2015-03-20 14:15:59 +03:00
|
|
|
void
|
|
|
|
PostMessageToDebugger(const nsAString& aMessage);
|
|
|
|
|
2015-03-30 14:54:38 +03:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
SetDebuggerImmediate(Function& aHandler, ErrorResult& aRv);
|
2015-03-30 14:54:38 +03:00
|
|
|
|
2015-03-26 22:09:45 +03:00
|
|
|
void
|
|
|
|
ReportErrorToDebugger(const nsAString& aFilename, uint32_t aLineno,
|
|
|
|
const nsAString& aMessage);
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
bool
|
|
|
|
NotifyInternal(JSContext* aCx, Status aStatus);
|
|
|
|
|
|
|
|
void
|
2016-08-14 14:39:31 +03:00
|
|
|
ReportError(JSContext* aCx, JS::ConstUTF8CharsZ aToStringResult,
|
|
|
|
JSErrorReport* aReport);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-04-12 02:41:00 +03:00
|
|
|
static void
|
|
|
|
ReportErrorToConsole(const char* aMessage);
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
int32_t
|
2016-08-16 09:10:30 +03:00
|
|
|
SetTimeout(JSContext* aCx, nsIScriptTimeoutHandler* aHandler,
|
|
|
|
int32_t aTimeout, bool aIsInterval,
|
2013-11-05 18:16:26 +04:00
|
|
|
ErrorResult& aRv);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
|
|
|
ClearTimeout(int32_t aId);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
RunExpiredTimeouts(JSContext* aCx);
|
|
|
|
|
|
|
|
bool
|
|
|
|
RescheduleTimeoutTimer(JSContext* aCx);
|
|
|
|
|
|
|
|
void
|
2016-07-07 09:15:15 +03:00
|
|
|
UpdateContextOptionsInternal(JSContext* aCx, const JS::ContextOptions& aContextOptions);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2014-09-05 18:26:34 +04:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
UpdateLanguagesInternal(const nsTArray<nsString>& aLanguages);
|
2014-09-05 18:26:34 +04:00
|
|
|
|
2012-01-04 23:11:32 +04:00
|
|
|
void
|
2013-01-11 02:50:40 +04:00
|
|
|
UpdateJSWorkerMemoryParameterInternal(JSContext* aCx, JSGCParamKey key, uint32_t aValue);
|
2012-01-04 23:11:32 +04:00
|
|
|
|
2014-03-05 03:09:23 +04:00
|
|
|
enum WorkerRanOrNot {
|
|
|
|
WorkerNeverRan = 0,
|
|
|
|
WorkerRan
|
|
|
|
};
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
void
|
2014-03-05 03:09:23 +04:00
|
|
|
ScheduleDeletion(WorkerRanOrNot aRanOrNot);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2011-08-07 05:03:46 +04:00
|
|
|
bool
|
2016-10-28 12:50:16 +03:00
|
|
|
CollectRuntimeStats(JS::RuntimeStats* aRtStats, bool aAnonymize);
|
2011-09-09 04:03:03 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
#ifdef JS_GC_ZEAL
|
|
|
|
void
|
2013-05-17 02:49:43 +04:00
|
|
|
UpdateGCZealInternal(JSContext* aCx, uint8_t aGCZeal, uint32_t aFrequency);
|
2011-07-17 23:09:13 +04:00
|
|
|
#endif
|
|
|
|
|
2012-01-18 00:05:25 +04:00
|
|
|
void
|
|
|
|
GarbageCollectInternal(JSContext* aCx, bool aShrinking,
|
|
|
|
bool aCollectChildren);
|
|
|
|
|
2013-12-03 08:07:02 +04:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
CycleCollectInternal(bool aCollectChildren);
|
2013-12-03 08:07:02 +04:00
|
|
|
|
2013-11-20 03:08:50 +04:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
OfflineStatusChangeEventInternal(bool aIsOffline);
|
2013-11-20 03:08:50 +04:00
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
void
|
|
|
|
MemoryPressureInternal();
|
|
|
|
|
2016-12-19 05:38:53 +03:00
|
|
|
void
|
|
|
|
SetFetchHandlerWasAdded()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsServiceWorker());
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
mFetchHandlerWasAdded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FetchHandlerWasAdded() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsServiceWorker());
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
return mFetchHandlerWasAdded;
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
JSContext*
|
|
|
|
GetJSContext() const
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
return mJSContext;
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
WorkerGlobalScope*
|
|
|
|
GlobalScope() const
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
return mScope;
|
|
|
|
}
|
|
|
|
|
2015-03-04 02:51:53 +03:00
|
|
|
WorkerDebuggerGlobalScope*
|
|
|
|
DebuggerGlobalScope() const
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
return mDebuggerScope;
|
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
void
|
2014-11-17 22:55:37 +03:00
|
|
|
SetThread(WorkerThread* aThread);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
AssertIsOnWorkerThread() const
|
2013-10-23 17:16:49 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
2011-07-17 23:09:13 +04:00
|
|
|
{ }
|
|
|
|
#endif
|
|
|
|
|
2012-12-30 22:21:52 +04:00
|
|
|
// This may block!
|
|
|
|
void
|
|
|
|
BeginCTypesCall();
|
|
|
|
|
|
|
|
// This may block!
|
|
|
|
void
|
|
|
|
EndCTypesCall();
|
|
|
|
|
2013-01-08 16:57:44 +04:00
|
|
|
void
|
|
|
|
BeginCTypesCallback()
|
|
|
|
{
|
|
|
|
// If a callback is beginning then we need to do the exact same thing as
|
|
|
|
// when a ctypes call ends.
|
|
|
|
EndCTypesCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EndCTypesCallback()
|
|
|
|
{
|
|
|
|
// If a callback is ending then we need to do the exact same thing as
|
|
|
|
// when a ctypes call begins.
|
|
|
|
BeginCTypesCall();
|
|
|
|
}
|
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
bool
|
2015-09-16 06:27:56 +03:00
|
|
|
ConnectMessagePort(JSContext* aCx, MessagePortIdentifier& aIdentifier);
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2015-03-04 02:51:53 +03:00
|
|
|
WorkerGlobalScope*
|
|
|
|
GetOrCreateGlobalScope(JSContext* aCx);
|
|
|
|
|
|
|
|
WorkerDebuggerGlobalScope*
|
|
|
|
CreateDebuggerGlobalScope(JSContext* aCx);
|
2013-11-05 18:16:26 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
RegisterBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
|
|
|
|
|
2016-02-22 12:41:09 +03:00
|
|
|
bool
|
|
|
|
RegisterDebuggerBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
|
|
|
|
|
2015-07-28 00:57:34 +03:00
|
|
|
bool
|
2013-11-20 03:08:50 +04:00
|
|
|
OnLine() const
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
return mOnLine;
|
|
|
|
}
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
void
|
|
|
|
StopSyncLoop(nsIEventTarget* aSyncLoopTarget, bool aResult);
|
|
|
|
|
|
|
|
bool
|
|
|
|
AllPendingRunnablesShouldBeCanceled() const
|
|
|
|
{
|
|
|
|
return mCancelAllPendingRunnables;
|
|
|
|
}
|
|
|
|
|
2015-04-09 01:20:59 +03:00
|
|
|
void
|
|
|
|
ClearMainEventQueue(WorkerRanOrNot aRanOrNot);
|
|
|
|
|
2016-02-26 19:32:28 +03:00
|
|
|
void
|
|
|
|
ClearDebuggerEventQueue();
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
void
|
Bug 1179909: Refactor stable state handling. r=smaug
This is motivated by three separate but related problems:
1. Our concept of recursion depth is broken for things that run from AfterProcessNextEvent observers (e.g. Promises). We decrement the recursionDepth counter before firing observers, so a Promise callback running at the lowest event loop depth has a recursion depth of 0 (whereas a regular nsIRunnable would be 1). This is a problem because it's impossible to distinguish a Promise running after a sync XHR's onreadystatechange handler from a top-level event (since the former runs with depth 2 - 1 = 1, and the latter runs with just 1).
2. The nsIThreadObserver mechanism that is used by a lot of code to run "after" the current event is a poor fit for anything that runs script. First, the order the observers fire in is the order they were added, not anything fixed by spec. Additionally, running script can cause the event loop to spin, which is a big source of pain here (bholley has some nasty bug caused by this).
3. We run Promises from different points in the code for workers and main thread. The latter runs from XPConnect's nsIThreadObserver callbacks, while the former runs from a hardcoded call to run Promises in the worker event loop. What workers do is particularly problematic because it means we can't get the right recursion depth no matter what we do to nsThread.
The solve this, this patch does the following:
1. Consolidate some handling of microtasks and all handling of stable state from appshell and WorkerPrivate into CycleCollectedJSRuntime.
2. Make the recursionDepth counter only available to CycleCollectedJSRuntime (and its consumers) and remove it from the nsIThreadInternal and nsIThreadObserver APIs.
3. Adjust the recursionDepth counter so that microtasks run with the recursionDepth of the task they are associated with.
4. Introduce the concept of metastable state to replace appshell's RunBeforeNextEvent. Metastable state is reached after every microtask or task is completed. This provides the semantics that bent and I want for IndexedDB, where transactions autocommit at the end of a microtask and do not "spill" from one microtask into a subsequent microtask. This differs from appshell's RunBeforeNextEvent in two ways:
a) It fires between microtasks, which was the motivation for starting this.
b) It no longer ensures that we're at the same event loop depth in the native event queue. bent decided we don't care about this.
5. Reorder stable state to happen after microtasks such as Promises, per HTML. Right now we call the regular thread observers, including appshell, before the main thread observer (XPConnect), so stable state tasks happen before microtasks.
2015-08-11 16:10:46 +03:00
|
|
|
OnProcessNextEvent();
|
2013-10-23 17:16:49 +04:00
|
|
|
|
|
|
|
void
|
Bug 1179909: Refactor stable state handling. r=smaug
This is motivated by three separate but related problems:
1. Our concept of recursion depth is broken for things that run from AfterProcessNextEvent observers (e.g. Promises). We decrement the recursionDepth counter before firing observers, so a Promise callback running at the lowest event loop depth has a recursion depth of 0 (whereas a regular nsIRunnable would be 1). This is a problem because it's impossible to distinguish a Promise running after a sync XHR's onreadystatechange handler from a top-level event (since the former runs with depth 2 - 1 = 1, and the latter runs with just 1).
2. The nsIThreadObserver mechanism that is used by a lot of code to run "after" the current event is a poor fit for anything that runs script. First, the order the observers fire in is the order they were added, not anything fixed by spec. Additionally, running script can cause the event loop to spin, which is a big source of pain here (bholley has some nasty bug caused by this).
3. We run Promises from different points in the code for workers and main thread. The latter runs from XPConnect's nsIThreadObserver callbacks, while the former runs from a hardcoded call to run Promises in the worker event loop. What workers do is particularly problematic because it means we can't get the right recursion depth no matter what we do to nsThread.
The solve this, this patch does the following:
1. Consolidate some handling of microtasks and all handling of stable state from appshell and WorkerPrivate into CycleCollectedJSRuntime.
2. Make the recursionDepth counter only available to CycleCollectedJSRuntime (and its consumers) and remove it from the nsIThreadInternal and nsIThreadObserver APIs.
3. Adjust the recursionDepth counter so that microtasks run with the recursionDepth of the task they are associated with.
4. Introduce the concept of metastable state to replace appshell's RunBeforeNextEvent. Metastable state is reached after every microtask or task is completed. This provides the semantics that bent and I want for IndexedDB, where transactions autocommit at the end of a microtask and do not "spill" from one microtask into a subsequent microtask. This differs from appshell's RunBeforeNextEvent in two ways:
a) It fires between microtasks, which was the motivation for starting this.
b) It no longer ensures that we're at the same event loop depth in the native event queue. bent decided we don't care about this.
5. Reorder stable state to happen after microtasks such as Promises, per HTML. Right now we call the regular thread observers, including appshell, before the main thread observer (XPConnect), so stable state tasks happen before microtasks.
2015-08-11 16:10:46 +03:00
|
|
|
AfterProcessNextEvent();
|
2013-10-23 17:16:49 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
AssertValidSyncLoop(nsIEventTarget* aSyncLoopTarget)
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
|
|
|
|
2014-05-29 20:33:04 +04:00
|
|
|
void
|
|
|
|
SetWorkerScriptExecutedSuccessfully()
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
// Should only be called once!
|
|
|
|
MOZ_ASSERT(!mWorkerScriptExecutedSuccessfully);
|
|
|
|
mWorkerScriptExecutedSuccessfully = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only valid after CompileScriptRunnable has finished running!
|
|
|
|
bool
|
|
|
|
WorkerScriptExecutedSuccessfully() const
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
return mWorkerScriptExecutedSuccessfully;
|
|
|
|
}
|
|
|
|
|
2015-07-15 22:21:40 +03:00
|
|
|
void
|
|
|
|
MaybeDispatchLoadFailedRunnable();
|
|
|
|
|
2016-09-14 06:14:02 +03:00
|
|
|
// Get the event target to use when dispatching to the main thread
|
|
|
|
// from this Worker thread. This may be the main thread itself or
|
2016-11-07 23:30:17 +03:00
|
|
|
// a ThrottledEventQueue to the main thread.
|
2016-09-14 06:14:02 +03:00
|
|
|
nsIEventTarget*
|
|
|
|
MainThreadEventTarget();
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DispatchToMainThread(nsIRunnable* aRunnable,
|
|
|
|
uint32_t aFlags = NS_DISPATCH_NORMAL);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DispatchToMainThread(already_AddRefed<nsIRunnable> aRunnable,
|
|
|
|
uint32_t aFlags = NS_DISPATCH_NORMAL);
|
|
|
|
|
2017-01-26 19:01:33 +03:00
|
|
|
// Get an event target that will dispatch runnables as control runnables on
|
|
|
|
// the worker thread. Implement nsICancelableRunnable if you wish to take
|
|
|
|
// action on cancelation.
|
2017-07-21 18:16:23 +03:00
|
|
|
nsISerialEventTarget*
|
2017-01-26 19:01:33 +03:00
|
|
|
ControlEventTarget();
|
|
|
|
|
2017-07-21 18:16:24 +03:00
|
|
|
// Get an event target that will attempt to dispatch a normal WorkerRunnable,
|
|
|
|
// but if that fails will then fall back to a control runnable.
|
|
|
|
nsISerialEventTarget*
|
|
|
|
HybridEventTarget();
|
|
|
|
|
2017-11-15 09:58:38 +03:00
|
|
|
void
|
|
|
|
DumpCrashInformation(nsACString& aString);
|
|
|
|
|
2017-11-27 22:48:17 +03:00
|
|
|
bool
|
2017-11-21 23:13:04 +03:00
|
|
|
EnsureClientSource();
|
|
|
|
|
|
|
|
const ClientInfo&
|
|
|
|
GetClientInfo() const;
|
|
|
|
|
2018-01-12 04:46:08 +03:00
|
|
|
const ClientState
|
|
|
|
GetClientState() const;
|
|
|
|
|
|
|
|
const Maybe<ServiceWorkerDescriptor>
|
|
|
|
GetController() const;
|
|
|
|
|
2017-12-06 04:45:22 +03:00
|
|
|
void
|
|
|
|
Control(const ServiceWorkerDescriptor& aServiceWorker);
|
|
|
|
|
2017-11-21 23:13:04 +03:00
|
|
|
void
|
|
|
|
ExecutionReady();
|
|
|
|
|
2018-01-24 19:17:31 +03:00
|
|
|
PerformanceStorage*
|
|
|
|
GetPerformanceStorage();
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
private:
|
2016-03-12 00:43:30 +03:00
|
|
|
WorkerPrivate(WorkerPrivate* aParent,
|
2013-11-05 18:16:24 +04:00
|
|
|
const nsAString& aScriptURL, bool aIsChromeWorker,
|
2017-05-17 17:49:34 +03:00
|
|
|
WorkerType aWorkerType, const nsAString& aWorkerName,
|
|
|
|
const nsACString& aServiceWorkerScope,
|
2015-02-12 12:50:05 +03:00
|
|
|
WorkerLoadInfo& aLoadInfo);
|
2012-09-15 22:51:55 +04:00
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
bool
|
|
|
|
MayContinueRunning()
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
Status status;
|
|
|
|
{
|
2013-10-23 17:16:49 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
2011-07-17 23:09:13 +04:00
|
|
|
status = mStatus;
|
|
|
|
}
|
|
|
|
|
2016-09-01 07:33:05 +03:00
|
|
|
if (status < Terminating) {
|
|
|
|
return true;
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2016-09-01 07:33:05 +03:00
|
|
|
return false;
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
void
|
2016-02-27 05:15:56 +03:00
|
|
|
CancelAllTimeouts();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-05-11 21:45:58 +03:00
|
|
|
enum class ProcessAllControlRunnablesResult
|
|
|
|
{
|
|
|
|
// We did not process anything.
|
|
|
|
Nothing,
|
|
|
|
// We did process something, states may have changed, but we can keep
|
|
|
|
// executing script.
|
|
|
|
MayContinue,
|
|
|
|
// We did process something, and should not continue executing script.
|
|
|
|
Abort
|
|
|
|
};
|
|
|
|
|
|
|
|
ProcessAllControlRunnablesResult
|
2013-10-23 17:16:49 +04:00
|
|
|
ProcessAllControlRunnables()
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-10-23 17:16:49 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
return ProcessAllControlRunnablesLocked();
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
2011-09-09 04:03:03 +04:00
|
|
|
|
2016-05-11 21:45:58 +03:00
|
|
|
ProcessAllControlRunnablesResult
|
2013-10-23 17:16:49 +04:00
|
|
|
ProcessAllControlRunnablesLocked();
|
2012-09-17 04:20:16 +04:00
|
|
|
|
2012-12-30 22:21:52 +04:00
|
|
|
void
|
|
|
|
EnableMemoryReporter();
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableMemoryReporter();
|
|
|
|
|
|
|
|
void
|
|
|
|
WaitForWorkerEvents(PRIntervalTime interval = PR_INTERVAL_NO_TIMEOUT);
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
2013-06-05 18:04:23 +04:00
|
|
|
PostMessageToParentInternal(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aMessage,
|
2017-02-03 13:00:38 +03:00
|
|
|
const Sequence<JSObject*>& aTransferable,
|
2013-11-05 18:16:26 +04:00
|
|
|
ErrorResult& aRv);
|
2013-11-24 23:27:15 +04:00
|
|
|
|
2017-01-05 12:05:32 +03:00
|
|
|
// If the worker shutdown status is equal or greater then aFailStatus, this
|
|
|
|
// operation will fail and nullptr will be returned. See WorkerHolder.h for
|
|
|
|
// more information about the correct value to use.
|
2013-10-23 17:16:49 +04:00
|
|
|
already_AddRefed<nsIEventTarget>
|
2017-01-05 12:05:32 +03:00
|
|
|
CreateNewSyncLoop(Status aFailStatus);
|
2013-10-23 17:16:49 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
RunCurrentSyncLoop();
|
|
|
|
|
2014-01-11 04:37:47 +04:00
|
|
|
bool
|
|
|
|
DestroySyncLoop(uint32_t aLoopIndex, nsIThreadInternal* aThread = nullptr);
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
void
|
|
|
|
InitializeGCTimers();
|
|
|
|
|
|
|
|
void
|
|
|
|
SetGCTimerMode(GCTimerMode aMode);
|
|
|
|
|
|
|
|
void
|
|
|
|
ShutdownGCTimers();
|
2016-06-23 11:53:14 +03:00
|
|
|
|
|
|
|
bool
|
2016-08-18 17:11:04 +03:00
|
|
|
AddHolder(WorkerHolder* aHolder, Status aFailStatus);
|
2016-06-23 11:53:14 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
RemoveHolder(WorkerHolder* aHolder);
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyHolders(JSContext* aCx, Status aStatus);
|
|
|
|
|
|
|
|
bool
|
|
|
|
HasActiveHolders()
|
|
|
|
{
|
|
|
|
return !(mChildWorkers.IsEmpty() && mTimeouts.IsEmpty() &&
|
|
|
|
mHolders.IsEmpty());
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
};
|
|
|
|
|
2013-11-05 18:16:24 +04:00
|
|
|
// This class is only used to trick the DOM bindings. We never create
|
|
|
|
// instances of it, and static_casting to it is fine since it doesn't add
|
|
|
|
// anything to WorkerPrivate.
|
|
|
|
class ChromeWorkerPrivate : public WorkerPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static already_AddRefed<ChromeWorkerPrivate>
|
|
|
|
Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL,
|
|
|
|
ErrorResult& rv);
|
|
|
|
|
|
|
|
static bool
|
2014-08-05 06:20:35 +04:00
|
|
|
WorkerAvailable(JSContext* aCx, JSObject* /* unused */);
|
2013-11-05 18:16:24 +04:00
|
|
|
|
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
ChromeWorkerPrivate() = delete;
|
|
|
|
ChromeWorkerPrivate(const ChromeWorkerPrivate& aRHS) = delete;
|
|
|
|
ChromeWorkerPrivate& operator =(const ChromeWorkerPrivate& aRHS) = delete;
|
2013-11-05 18:16:24 +04:00
|
|
|
};
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
WorkerPrivate*
|
|
|
|
GetWorkerPrivateFromContext(JSContext* aCx);
|
|
|
|
|
2013-11-05 18:16:24 +04:00
|
|
|
WorkerPrivate*
|
|
|
|
GetCurrentThreadWorkerPrivate();
|
|
|
|
|
2013-08-30 13:47:19 +04:00
|
|
|
bool
|
|
|
|
IsCurrentThreadRunningChromeWorker();
|
|
|
|
|
2013-09-09 07:29:21 +04:00
|
|
|
JSContext*
|
|
|
|
GetCurrentThreadJSContext();
|
|
|
|
|
2016-02-18 06:56:36 +03:00
|
|
|
JSObject*
|
|
|
|
GetCurrentThreadWorkerGlobal();
|
|
|
|
|
2012-12-22 00:14:47 +04:00
|
|
|
class AutoSyncLoopHolder
|
|
|
|
{
|
2013-10-23 17:16:49 +04:00
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
nsCOMPtr<nsIEventTarget> mTarget;
|
2014-01-11 04:37:47 +04:00
|
|
|
uint32_t mIndex;
|
2013-10-23 17:16:49 +04:00
|
|
|
|
2012-12-22 00:14:47 +04:00
|
|
|
public:
|
2017-01-05 12:05:32 +03:00
|
|
|
// See CreateNewSyncLoop() for more information about the correct value to use
|
|
|
|
// for aFailStatus.
|
|
|
|
AutoSyncLoopHolder(WorkerPrivate* aWorkerPrivate, Status aFailStatus)
|
2014-01-11 04:37:47 +04:00
|
|
|
: mWorkerPrivate(aWorkerPrivate)
|
2017-01-05 12:05:32 +03:00
|
|
|
, mTarget(aWorkerPrivate->CreateNewSyncLoop(aFailStatus))
|
2014-01-11 04:37:47 +04:00
|
|
|
, mIndex(aWorkerPrivate->mSyncLoopStack.Length() - 1)
|
2012-12-22 00:14:47 +04:00
|
|
|
{
|
2013-10-23 17:16:49 +04:00
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
2012-12-22 00:14:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSyncLoopHolder()
|
|
|
|
{
|
2017-01-05 12:05:32 +03:00
|
|
|
if (mWorkerPrivate && mTarget) {
|
2013-10-23 17:16:49 +04:00
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
mWorkerPrivate->StopSyncLoop(mTarget, false);
|
2014-01-11 04:37:47 +04:00
|
|
|
mWorkerPrivate->DestroySyncLoop(mIndex);
|
2012-12-22 00:14:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-10-23 17:16:49 +04:00
|
|
|
Run()
|
2012-12-22 00:14:47 +04:00
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = mWorkerPrivate;
|
|
|
|
mWorkerPrivate = nullptr;
|
2013-10-23 17:16:49 +04:00
|
|
|
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
return workerPrivate->RunCurrentSyncLoop();
|
2012-12-22 00:14:47 +04:00
|
|
|
}
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
nsIEventTarget*
|
2017-01-05 12:05:32 +03:00
|
|
|
GetEventTarget() const
|
2012-12-22 00:14:47 +04:00
|
|
|
{
|
2017-01-05 12:05:32 +03:00
|
|
|
// This can be null if CreateNewSyncLoop() fails.
|
2013-10-23 17:16:49 +04:00
|
|
|
return mTarget;
|
2012-12-22 00:14:47 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_workers_workerprivate_h__ */
|