2011-07-17 12:09:13 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-05-21 04:12:37 -07: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 12:09:13 -07:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_workers_workerprivate_h__
|
|
|
|
#define mozilla_dom_workers_workerprivate_h__
|
|
|
|
|
|
|
|
#include "Workers.h"
|
|
|
|
|
2012-09-15 11:51:55 -07:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2011-07-17 12:09:13 -07:00
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsIThreadInternal.h"
|
2012-09-05 10:47:57 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
#include "jsapi.h"
|
2013-02-08 03:50:00 -08:00
|
|
|
#include "mozilla/Assertions.h"
|
2011-07-17 12:09:13 -07:00
|
|
|
#include "mozilla/CondVar.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsEventQueue.h"
|
|
|
|
#include "nsStringGlue.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTPriorityQueue.h"
|
2012-04-24 03:58:07 -07:00
|
|
|
#include "StructuredCloneTags.h"
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
#include "EventTarget.h"
|
|
|
|
#include "Queue.h"
|
|
|
|
#include "WorkerFeature.h"
|
|
|
|
|
|
|
|
class JSAutoStructuredCloneBuffer;
|
2013-03-07 14:27:21 -08:00
|
|
|
class nsIChannel;
|
2011-07-17 12:09:13 -07:00
|
|
|
class nsIDocument;
|
2012-12-30 10:21:52 -08:00
|
|
|
class nsIMemoryMultiReporter;
|
2011-07-17 12:09:13 -07:00
|
|
|
class nsIPrincipal;
|
|
|
|
class nsIScriptContext;
|
|
|
|
class nsIURI;
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
class nsITimer;
|
2012-05-04 00:22:18 -07:00
|
|
|
class nsIXPCScriptNotify;
|
2013-04-11 20:52:32 -07:00
|
|
|
namespace JS { class RuntimeStats; }
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
class WorkerPrivate;
|
|
|
|
|
|
|
|
class WorkerRunnable : public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Target { ParentThread, WorkerThread };
|
|
|
|
enum BusyBehavior { ModifyBusyCount, UnchangedBusyCount };
|
2012-02-09 20:54:47 -08:00
|
|
|
enum ClearingBehavior { SkipWhenClearing, RunWhenClearing };
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
Target mTarget;
|
2012-02-09 20:54:47 -08:00
|
|
|
BusyBehavior mBusyBehavior;
|
|
|
|
ClearingBehavior mClearingBehavior;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
bool
|
|
|
|
Dispatch(JSContext* aCx);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
DispatchToMainThread(nsIRunnable*);
|
|
|
|
|
2012-02-09 20:54:47 -08:00
|
|
|
bool
|
|
|
|
WantsToRunDuringClear()
|
|
|
|
{
|
|
|
|
return mClearingBehavior == RunWhenClearing;
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
protected:
|
|
|
|
WorkerRunnable(WorkerPrivate* aWorkerPrivate, Target aTarget,
|
2012-02-09 20:54:47 -08:00
|
|
|
BusyBehavior aBusyBehavior,
|
|
|
|
ClearingBehavior aClearingBehavior)
|
2011-07-17 12:09:13 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
: mWorkerPrivate(aWorkerPrivate), mTarget(aTarget),
|
2012-02-09 20:54:47 -08:00
|
|
|
mBusyBehavior(aBusyBehavior), mClearingBehavior(aClearingBehavior)
|
2011-07-17 12:09:13 -07:00
|
|
|
{ }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual ~WorkerRunnable()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate);
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
|
|
|
bool aDispatchResult);
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
DispatchInternal();
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) = 0;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aRunResult);
|
|
|
|
|
2012-05-04 00:22:18 -07:00
|
|
|
void NotifyScriptExecutedIfNeeded() const;
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
private:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
class WorkerSyncRunnable : public WorkerRunnable
|
|
|
|
{
|
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mSyncQueueKey;
|
2011-07-17 12:09:13 -07:00
|
|
|
bool mBypassSyncQueue;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class WorkerPrivate;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
WorkerSyncRunnable(WorkerPrivate* aWorkerPrivate, uint32_t aSyncQueueKey,
|
2012-02-09 20:54:47 -08:00
|
|
|
bool aBypassSyncQueue = false,
|
|
|
|
ClearingBehavior aClearingBehavior = SkipWhenClearing)
|
|
|
|
: WorkerRunnable(aWorkerPrivate, WorkerThread, UnchangedBusyCount,
|
2012-02-14 14:33:11 -08:00
|
|
|
aClearingBehavior),
|
2011-07-17 12:09:13 -07:00
|
|
|
mSyncQueueKey(aSyncQueueKey), mBypassSyncQueue(aBypassSyncQueue)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual ~WorkerSyncRunnable()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
DispatchInternal();
|
|
|
|
};
|
|
|
|
|
2013-03-07 14:27:21 -08:00
|
|
|
class MainThreadSyncRunnable : public WorkerSyncRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MainThreadSyncRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
ClearingBehavior aClearingBehavior,
|
|
|
|
uint32_t aSyncQueueKey,
|
|
|
|
bool aBypassSyncEventQueue)
|
|
|
|
: WorkerSyncRunnable(aWorkerPrivate, aSyncQueueKey, aBypassSyncEventQueue,
|
|
|
|
aClearingBehavior)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
|
|
|
bool aDispatchResult) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
class WorkerControlRunnable : public WorkerRunnable
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
WorkerControlRunnable(WorkerPrivate* aWorkerPrivate, Target aTarget,
|
|
|
|
BusyBehavior aBusyBehavior)
|
2012-02-09 20:54:47 -08:00
|
|
|
: WorkerRunnable(aWorkerPrivate, aTarget, aBusyBehavior, SkipWhenClearing)
|
2011-07-17 12:09:13 -07:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual ~WorkerControlRunnable()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
DispatchInternal();
|
|
|
|
};
|
|
|
|
|
2013-02-08 03:50:00 -08: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;
|
|
|
|
|
|
|
|
class RefCountedMutex : public Mutex
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RefCountedMutex(const char* aName)
|
|
|
|
: Mutex(aName)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RefCountedMutex)
|
|
|
|
|
|
|
|
private:
|
|
|
|
~RefCountedMutex()
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
nsRefPtr<RefCountedMutex> mMutex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SharedMutex(const char* aName)
|
|
|
|
: mMutex(new RefCountedMutex(aName))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
SharedMutex(SharedMutex& aOther)
|
|
|
|
: mMutex(aOther.mMutex)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
operator Mutex&()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mMutex);
|
|
|
|
return *mMutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator const Mutex&() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mMutex);
|
|
|
|
return *mMutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertCurrentThreadOwns() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mMutex);
|
|
|
|
mMutex->AssertCurrentThreadOwns();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
template <class Derived>
|
2012-03-30 21:42:20 -07:00
|
|
|
class WorkerPrivateParent : public EventTarget
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct LocationInfo
|
|
|
|
{
|
|
|
|
nsCString mHref;
|
|
|
|
nsCString mProtocol;
|
|
|
|
nsCString mHost;
|
|
|
|
nsCString mHostname;
|
|
|
|
nsCString mPort;
|
|
|
|
nsCString mPathname;
|
|
|
|
nsCString mSearch;
|
|
|
|
nsCString mHash;
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
2013-02-08 03:50:00 -08:00
|
|
|
SharedMutex mMutex;
|
2011-07-17 12:09:13 -07:00
|
|
|
mozilla::CondVar mCondVar;
|
2012-12-30 10:21:52 -08:00
|
|
|
mozilla::CondVar mMemoryReportCondVar;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
JSObject* mJSObject;
|
|
|
|
WorkerPrivate* mParent;
|
|
|
|
JSContext* mParentJSContext;
|
|
|
|
nsString mScriptURL;
|
|
|
|
nsCString mDomain;
|
|
|
|
LocationInfo mLocationInfo;
|
|
|
|
|
|
|
|
// Main-thread things.
|
|
|
|
nsCOMPtr<nsPIDOMWindow> mWindow;
|
|
|
|
nsCOMPtr<nsIScriptContext> mScriptContext;
|
2012-05-04 00:22:18 -07:00
|
|
|
nsCOMPtr<nsIXPCScriptNotify> mScriptNotify;
|
2011-07-17 12:09:13 -07:00
|
|
|
nsCOMPtr<nsIURI> mBaseURI;
|
|
|
|
nsCOMPtr<nsIURI> mScriptURI;
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2013-03-07 14:27:21 -08:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2012-09-15 11:51:55 -07:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> mCSP;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
// Only used for top level workers.
|
|
|
|
nsTArray<nsRefPtr<WorkerRunnable> > mQueuedRunnables;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mBusyCount;
|
2011-07-17 12:09:13 -07:00
|
|
|
Status mParentStatus;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mJSContextOptions;
|
|
|
|
uint32_t mJSRuntimeHeapSize;
|
2013-01-10 14:50:40 -08:00
|
|
|
uint32_t mJSWorkerAllocationThreshold;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mGCZeal;
|
2011-07-17 12:09:13 -07:00
|
|
|
bool mJSObjectRooted;
|
|
|
|
bool mParentSuspended;
|
|
|
|
bool mIsChromeWorker;
|
2011-08-15 20:40:38 -07:00
|
|
|
bool mPrincipalIsSystem;
|
2012-03-30 21:42:20 -07:00
|
|
|
bool mMainThreadObjectsForgotten;
|
2012-09-15 11:51:55 -07:00
|
|
|
bool mEvalAllowed;
|
2012-10-15 13:54:58 -07:00
|
|
|
bool mReportCSPViolations;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
WorkerPrivateParent(JSContext* aCx, JSObject* aObject, WorkerPrivate* aParent,
|
|
|
|
JSContext* aParentJSContext, const nsAString& aScriptURL,
|
|
|
|
bool aIsChromeWorker, const nsACString& aDomain,
|
|
|
|
nsCOMPtr<nsPIDOMWindow>& aWindow,
|
|
|
|
nsCOMPtr<nsIScriptContext>& aScriptContext,
|
|
|
|
nsCOMPtr<nsIURI>& aBaseURI,
|
2012-09-15 11:51:55 -07:00
|
|
|
nsCOMPtr<nsIPrincipal>& aPrincipal,
|
2013-03-07 14:27:21 -08:00
|
|
|
nsCOMPtr<nsIChannel>& aChannel,
|
2012-09-15 11:51:55 -07:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy>& aCSP,
|
2012-10-15 13:54:58 -07:00
|
|
|
bool aEvalAllowed,
|
|
|
|
bool aReportCSPViolations);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
~WorkerPrivateParent();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Derived*
|
|
|
|
ParentAsWorkerPrivate() const
|
|
|
|
{
|
|
|
|
return static_cast<Derived*>(const_cast<WorkerPrivateParent*>(this));
|
|
|
|
}
|
|
|
|
|
2012-03-19 07:34:58 -07:00
|
|
|
// aCx is null when called from the finalizer
|
2011-12-29 10:28:13 -08:00
|
|
|
bool
|
2012-03-19 07:34:58 -07:00
|
|
|
NotifyPrivate(JSContext* aCx, Status aStatus);
|
2011-12-29 10:28:13 -08:00
|
|
|
|
2012-03-19 07:34:58 -07:00
|
|
|
// aCx is null when called from the finalizer
|
2011-12-29 10:28:13 -08:00
|
|
|
bool
|
2012-03-19 07:34:58 -07:00
|
|
|
TerminatePrivate(JSContext* aCx)
|
2011-12-29 10:28:13 -08:00
|
|
|
{
|
2012-03-19 07:34:58 -07:00
|
|
|
return NotifyPrivate(aCx, Terminating);
|
2011-12-29 10:28:13 -08:00
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
public:
|
|
|
|
// May be called on any thread...
|
|
|
|
bool
|
|
|
|
Start();
|
|
|
|
|
|
|
|
// Called on the parent thread.
|
|
|
|
bool
|
2011-12-29 10:28:13 -08:00
|
|
|
Notify(JSContext* aCx, Status aStatus)
|
|
|
|
{
|
2012-03-19 07:34:58 -07:00
|
|
|
return NotifyPrivate(aCx, aStatus);
|
2011-12-29 10:28:13 -08:00
|
|
|
}
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
Cancel(JSContext* aCx)
|
|
|
|
{
|
|
|
|
return Notify(aCx, Canceling);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Kill(JSContext* aCx)
|
|
|
|
{
|
|
|
|
return Notify(aCx, Killing);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Suspend(JSContext* aCx);
|
|
|
|
|
|
|
|
bool
|
|
|
|
Resume(JSContext* aCx);
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
virtual void
|
2012-04-26 13:57:33 -07:00
|
|
|
_trace(JSTracer* aTrc) MOZ_OVERRIDE;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
virtual void
|
2012-04-26 13:57:33 -07:00
|
|
|
_finalize(JSFreeOp* aFop) MOZ_OVERRIDE;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
void
|
2012-03-30 21:42:20 -07:00
|
|
|
Finish(JSContext* aCx)
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
RootJSObject(aCx, false);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Terminate(JSContext* aCx)
|
|
|
|
{
|
2012-03-30 21:42:20 -07:00
|
|
|
AssertIsOnParentThread();
|
|
|
|
RootJSObject(aCx, false);
|
2012-03-19 07:34:58 -07:00
|
|
|
return TerminatePrivate(aCx);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Close(JSContext* aCx);
|
|
|
|
|
|
|
|
bool
|
|
|
|
ModifyBusyCount(JSContext* aCx, bool aIncrease);
|
|
|
|
|
|
|
|
bool
|
|
|
|
RootJSObject(JSContext* aCx, bool aRoot);
|
|
|
|
|
|
|
|
void
|
|
|
|
ForgetMainThreadObjects(nsTArray<nsCOMPtr<nsISupports> >& aDoomed);
|
|
|
|
|
|
|
|
bool
|
2013-05-04 00:53:00 -07:00
|
|
|
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
|
|
|
JS::Handle<JS::Value> aTransferable);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2011-08-24 13:44:35 -07:00
|
|
|
GetInnerWindowId();
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
UpdateJSContextOptions(JSContext* aCx, uint32_t aOptions);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-01-04 11:11:32 -08:00
|
|
|
void
|
2013-01-10 14:50:40 -08:00
|
|
|
UpdateJSWorkerMemoryParameter(JSContext* aCx, JSGCParamKey key, uint32_t value);
|
2012-01-04 11:11:32 -08:00
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
#ifdef JS_GC_ZEAL
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
UpdateGCZeal(JSContext* aCx, uint8_t aGCZeal);
|
2011-07-17 12:09:13 -07:00
|
|
|
#endif
|
|
|
|
|
2012-01-17 12:05:25 -08:00
|
|
|
void
|
|
|
|
GarbageCollect(JSContext* aCx, bool aShrinking);
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
void
|
|
|
|
QueueRunnable(WorkerRunnable* aRunnable)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
mQueuedRunnables.AppendElement(aRunnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerPrivate*
|
|
|
|
GetParent() const
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsSuspended() const
|
|
|
|
{
|
|
|
|
AssertIsOnParentThread();
|
|
|
|
return mParentSuspended;
|
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
bool
|
|
|
|
IsAcceptingEvents()
|
|
|
|
{
|
|
|
|
AssertIsOnParentThread();
|
|
|
|
bool acceptingEvents;
|
2013-02-08 03:50:00 -08:00
|
|
|
{
|
|
|
|
mozilla::MutexAutoLock lock(mMutex);
|
|
|
|
acceptingEvents = mParentStatus < Terminating;
|
|
|
|
}
|
2012-03-30 21:42:20 -07:00
|
|
|
return acceptingEvents;
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
Status
|
|
|
|
ParentStatus() const
|
|
|
|
{
|
|
|
|
mMutex.AssertCurrentThreadOwns();
|
|
|
|
return mParentStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext*
|
|
|
|
ParentJSContext() const;
|
|
|
|
|
|
|
|
nsIScriptContext*
|
|
|
|
GetScriptContext() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mScriptContext;
|
|
|
|
}
|
|
|
|
|
2012-05-04 00:22:18 -07:00
|
|
|
nsIXPCScriptNotify*
|
|
|
|
GetScriptNotify() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mScriptNotify;
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
JSObject*
|
|
|
|
GetJSObject() const
|
|
|
|
{
|
|
|
|
return mJSObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsString&
|
|
|
|
ScriptURL() const
|
|
|
|
{
|
|
|
|
return mScriptURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString&
|
|
|
|
Domain() const
|
|
|
|
{
|
|
|
|
return mDomain;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI*
|
|
|
|
GetBaseURI() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mBaseURI;
|
|
|
|
}
|
|
|
|
|
2011-11-04 09:32:17 -07:00
|
|
|
void
|
2011-07-17 12:09:13 -07:00
|
|
|
SetBaseURI(nsIURI* aBaseURI);
|
|
|
|
|
|
|
|
nsIURI*
|
|
|
|
GetScriptURI() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mScriptURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetScriptURI(nsIURI* aScriptURI)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
mScriptURI = aScriptURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal*
|
|
|
|
GetPrincipal() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-08-15 20:40:38 -07:00
|
|
|
SetPrincipal(nsIPrincipal* aPrincipal);
|
|
|
|
|
|
|
|
bool
|
|
|
|
UsesSystemPrincipal() const
|
2011-07-17 12:09:13 -07:00
|
|
|
{
|
2011-08-15 20:40:38 -07:00
|
|
|
return mPrincipalIsSystem;
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
2013-03-07 14:27:21 -08:00
|
|
|
nsIChannel*
|
|
|
|
GetChannel() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mChannel;
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
nsIDocument*
|
|
|
|
GetDocument() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
2012-09-05 10:47:57 -07:00
|
|
|
return mWindow ? mWindow->GetExtantDoc() : nullptr;
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindow*
|
|
|
|
GetWindow()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mWindow;
|
|
|
|
}
|
|
|
|
|
2012-09-15 11:51:55 -07:00
|
|
|
nsIContentSecurityPolicy*
|
|
|
|
GetCSP() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mCSP;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetCSP(nsIContentSecurityPolicy* aCSP)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
mCSP = aCSP;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsEvalAllowed() const
|
|
|
|
{
|
|
|
|
return mEvalAllowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetEvalAllowed(bool aEvalAllowed)
|
|
|
|
{
|
|
|
|
mEvalAllowed = aEvalAllowed;
|
|
|
|
}
|
|
|
|
|
2012-10-15 13:54:58 -07:00
|
|
|
bool
|
|
|
|
GetReportCSPViolations() const
|
|
|
|
{
|
|
|
|
return mReportCSPViolations;
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
LocationInfo&
|
|
|
|
GetLocationInfo()
|
|
|
|
{
|
|
|
|
return mLocationInfo;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2011-07-17 12:09:13 -07:00
|
|
|
GetJSContextOptions() const
|
|
|
|
{
|
|
|
|
return mJSContextOptions;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-01-04 11:11:32 -08:00
|
|
|
GetJSRuntimeHeapSize() const
|
|
|
|
{
|
|
|
|
return mJSRuntimeHeapSize;
|
|
|
|
}
|
|
|
|
|
2013-01-10 14:50:40 -08:00
|
|
|
uint32_t
|
|
|
|
GetJSWorkerAllocationThreshold() const
|
|
|
|
{
|
|
|
|
return mJSWorkerAllocationThreshold;
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
#ifdef JS_GC_ZEAL
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2011-07-17 12:09:13 -07:00
|
|
|
GetGCZeal() const
|
|
|
|
{
|
|
|
|
return mGCZeal;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsChromeWorker() const
|
|
|
|
{
|
|
|
|
return mIsChromeWorker;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
AssertIsOnParentThread() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertInnerWindowIsCorrect() const;
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
AssertIsOnParentThread() const
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertInnerWindowIsCorrect() const
|
|
|
|
{ }
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
|
|
|
|
{
|
|
|
|
friend class WorkerPrivateParent<WorkerPrivate>;
|
|
|
|
typedef WorkerPrivateParent<WorkerPrivate> ParentType;
|
|
|
|
|
|
|
|
struct TimeoutInfo;
|
|
|
|
|
2012-02-09 20:54:47 -08:00
|
|
|
typedef Queue<WorkerRunnable*, 50> EventQueue;
|
2011-07-17 12:09:13 -07:00
|
|
|
EventQueue mQueue;
|
|
|
|
EventQueue mControlQueue;
|
|
|
|
|
|
|
|
struct SyncQueue
|
|
|
|
{
|
2012-02-09 20:54:47 -08:00
|
|
|
Queue<WorkerRunnable*, 10> mQueue;
|
2011-07-17 12:09:13 -07:00
|
|
|
bool mComplete;
|
|
|
|
bool mResult;
|
|
|
|
|
|
|
|
SyncQueue()
|
|
|
|
: mComplete(false), mResult(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~SyncQueue()
|
|
|
|
{
|
2012-02-09 20:54:47 -08:00
|
|
|
WorkerRunnable* event;
|
2011-07-17 12:09:13 -07:00
|
|
|
while (mQueue.Pop(event)) {
|
|
|
|
event->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-08 03:50:00 -08:00
|
|
|
class MemoryReporter;
|
|
|
|
friend class MemoryReporter;
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
nsTArray<nsAutoPtr<SyncQueue> > mSyncQueues;
|
|
|
|
|
|
|
|
// Touched on multiple threads, protected with mMutex.
|
|
|
|
JSContext* mJSContext;
|
2011-12-04 23:58:27 -08:00
|
|
|
nsRefPtr<WorkerCrossThreadDispatcher> mCrossThreadDispatcher;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
// Things touched on worker thread only.
|
|
|
|
nsTArray<ParentType*> mChildWorkers;
|
|
|
|
nsTArray<WorkerFeature*> mFeatures;
|
|
|
|
nsTArray<nsAutoPtr<TimeoutInfo> > mTimeouts;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2013-02-08 03:50:00 -08:00
|
|
|
nsRefPtr<MemoryReporter> mMemoryReporter;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
mozilla::TimeStamp mKillTime;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mErrorHandlerRecursionCount;
|
|
|
|
uint32_t mNextTimeoutId;
|
2011-07-17 12:09:13 -07:00
|
|
|
Status mStatus;
|
|
|
|
bool mSuspended;
|
|
|
|
bool mTimerRunning;
|
|
|
|
bool mRunningExpiredTimeouts;
|
|
|
|
bool mCloseHandlerStarted;
|
|
|
|
bool mCloseHandlerFinished;
|
2011-09-08 17:03:03 -07:00
|
|
|
bool mMemoryReporterRunning;
|
2012-12-30 10:21:52 -08:00
|
|
|
bool mBlockedForMemoryReporter;
|
2012-09-16 17:20:16 -07:00
|
|
|
bool mXHRParamsAllowed;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
~WorkerPrivate();
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
static already_AddRefed<WorkerPrivate>
|
2013-05-04 00:53:00 -07:00
|
|
|
Create(JSContext* aCx, JS::Handle<JSObject*> aObj, WorkerPrivate* aParent,
|
|
|
|
JS::Handle<JSString*> aScriptURL, bool aIsChromeWorker);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
DoRunLoop(JSContext* aCx);
|
|
|
|
|
|
|
|
bool
|
|
|
|
OperationCallback(JSContext* aCx);
|
|
|
|
|
|
|
|
bool
|
|
|
|
Dispatch(WorkerRunnable* aEvent)
|
|
|
|
{
|
|
|
|
return Dispatch(aEvent, &mQueue);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Dispatch(WorkerSyncRunnable* aEvent)
|
|
|
|
{
|
|
|
|
if (aEvent->mBypassSyncQueue) {
|
|
|
|
return Dispatch(aEvent, &mQueue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return DispatchToSyncQueue(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Dispatch(WorkerControlRunnable* aEvent)
|
|
|
|
{
|
|
|
|
return Dispatch(aEvent, &mControlQueue);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CloseInternal(JSContext* aCx)
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
return NotifyInternal(aCx, Closing);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SuspendInternal(JSContext* aCx);
|
|
|
|
|
|
|
|
bool
|
|
|
|
ResumeInternal(JSContext* aCx);
|
|
|
|
|
|
|
|
void
|
|
|
|
TraceInternal(JSTracer* aTrc);
|
|
|
|
|
|
|
|
bool
|
|
|
|
ModifyBusyCountFromWorker(JSContext* aCx, bool aIncrease);
|
|
|
|
|
|
|
|
bool
|
|
|
|
AddChildWorker(JSContext* aCx, ParentType* aChildWorker);
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoveChildWorker(JSContext* aCx, ParentType* aChildWorker);
|
|
|
|
|
|
|
|
bool
|
|
|
|
AddFeature(JSContext* aCx, WorkerFeature* aFeature);
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoveFeature(JSContext* aCx, WorkerFeature* aFeature);
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyFeatures(JSContext* aCx, Status aStatus);
|
|
|
|
|
|
|
|
bool
|
|
|
|
HasActiveFeatures()
|
|
|
|
{
|
|
|
|
return !(mChildWorkers.IsEmpty() && mTimeouts.IsEmpty() &&
|
|
|
|
mFeatures.IsEmpty());
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2011-07-17 12:09:13 -07:00
|
|
|
CreateNewSyncLoop();
|
|
|
|
|
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
RunSyncLoop(JSContext* aCx, uint32_t aSyncLoopKey);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
StopSyncLoop(uint32_t aSyncLoopKey, bool aSyncResult);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-12-21 12:14:47 -08:00
|
|
|
void
|
|
|
|
DestroySyncLoop(uint32_t aSyncLoopKey);
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
bool
|
2013-05-04 00:53:00 -07:00
|
|
|
PostMessageToParent(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
|
|
|
JS::Handle<JS::Value> transferable);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
NotifyInternal(JSContext* aCx, Status aStatus);
|
|
|
|
|
|
|
|
void
|
|
|
|
ReportError(JSContext* aCx, const char* aMessage, JSErrorReport* aReport);
|
|
|
|
|
|
|
|
bool
|
2012-02-28 15:11:11 -08:00
|
|
|
SetTimeout(JSContext* aCx, unsigned aArgc, jsval* aVp, bool aIsInterval);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
bool
|
2012-10-11 16:38:04 -07:00
|
|
|
ClearTimeout(JSContext* aCx, uint32_t aId);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
RunExpiredTimeouts(JSContext* aCx);
|
|
|
|
|
|
|
|
bool
|
|
|
|
RescheduleTimeoutTimer(JSContext* aCx);
|
|
|
|
|
|
|
|
void
|
|
|
|
CloseHandlerStarted()
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
mCloseHandlerStarted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CloseHandlerFinished()
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
mCloseHandlerFinished = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
UpdateJSContextOptionsInternal(JSContext* aCx, uint32_t aOptions);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-01-04 11:11:32 -08:00
|
|
|
void
|
2013-01-10 14:50:40 -08:00
|
|
|
UpdateJSWorkerMemoryParameterInternal(JSContext* aCx, JSGCParamKey key, uint32_t aValue);
|
2012-01-04 11:11:32 -08:00
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
void
|
|
|
|
ScheduleDeletion(bool aWasPending);
|
|
|
|
|
2011-08-06 18:03:46 -07:00
|
|
|
bool
|
2013-04-11 20:52:32 -07:00
|
|
|
BlockAndCollectRuntimeStats(JS::RuntimeStats* aRtStats);
|
2011-09-08 17:03:03 -07:00
|
|
|
|
2012-09-16 17:20:16 -07:00
|
|
|
bool
|
|
|
|
XHRParamsAllowed() const
|
|
|
|
{
|
|
|
|
return mXHRParamsAllowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetXHRParamsAllowed(bool aAllowed)
|
|
|
|
{
|
|
|
|
mXHRParamsAllowed = aAllowed;
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
#ifdef JS_GC_ZEAL
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
UpdateGCZealInternal(JSContext* aCx, uint8_t aGCZeal);
|
2011-07-17 12:09:13 -07:00
|
|
|
#endif
|
|
|
|
|
2012-01-17 12:05:25 -08:00
|
|
|
void
|
|
|
|
GarbageCollectInternal(JSContext* aCx, bool aShrinking,
|
|
|
|
bool aCollectChildren);
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
JSContext*
|
|
|
|
GetJSContext() const
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
return mJSContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
AssertIsOnWorkerThread() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetThread(nsIThread* aThread)
|
|
|
|
{
|
|
|
|
mThread = aThread;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
AssertIsOnWorkerThread() const
|
|
|
|
{ }
|
|
|
|
#endif
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
WorkerCrossThreadDispatcher*
|
|
|
|
GetCrossThreadDispatcher();
|
|
|
|
|
2012-12-30 10:21:52 -08:00
|
|
|
// This may block!
|
|
|
|
void
|
|
|
|
BeginCTypesCall();
|
|
|
|
|
|
|
|
// This may block!
|
|
|
|
void
|
|
|
|
EndCTypesCall();
|
|
|
|
|
2013-01-08 04:57:44 -08: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();
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
private:
|
|
|
|
WorkerPrivate(JSContext* aCx, JSObject* aObject, WorkerPrivate* aParent,
|
|
|
|
JSContext* aParentJSContext, const nsAString& aScriptURL,
|
|
|
|
bool aIsChromeWorker, const nsACString& aDomain,
|
|
|
|
nsCOMPtr<nsPIDOMWindow>& aWindow,
|
|
|
|
nsCOMPtr<nsIScriptContext>& aScriptContext,
|
2012-09-15 11:51:55 -07:00
|
|
|
nsCOMPtr<nsIURI>& aBaseURI, nsCOMPtr<nsIPrincipal>& aPrincipal,
|
2013-03-07 14:27:21 -08:00
|
|
|
nsCOMPtr<nsIChannel>& aChannel,
|
2012-09-16 17:20:16 -07:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy>& aCSP, bool aEvalAllowed,
|
2012-10-15 13:54:58 -07:00
|
|
|
bool aReportCSPViolations, bool aXHRParamsAllowed);
|
2012-09-15 11:51:55 -07:00
|
|
|
|
|
|
|
static bool
|
|
|
|
GetContentSecurityPolicy(JSContext *aCx,
|
|
|
|
nsIContentSecurityPolicy** aCsp);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
Dispatch(WorkerRunnable* aEvent, EventQueue* aQueue);
|
|
|
|
|
|
|
|
bool
|
|
|
|
DispatchToSyncQueue(WorkerSyncRunnable* aEvent);
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearQueue(EventQueue* aQueue);
|
|
|
|
|
|
|
|
bool
|
|
|
|
MayContinueRunning()
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
Status status;
|
|
|
|
{
|
|
|
|
mozilla::MutexAutoLock lock(mMutex);
|
|
|
|
status = mStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status >= Killing) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (status >= Running) {
|
|
|
|
return mKillTime.IsNull() || RemainingRunTimeMS() > 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2011-07-17 12:09:13 -07:00
|
|
|
RemainingRunTimeMS() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
CancelAllTimeouts(JSContext* aCx);
|
|
|
|
|
|
|
|
bool
|
|
|
|
ScheduleKillCloseEventRunnable(JSContext* aCx);
|
|
|
|
|
|
|
|
void
|
|
|
|
StopAcceptingEvents()
|
|
|
|
{
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
mozilla::MutexAutoLock lock(mMutex);
|
|
|
|
|
|
|
|
mStatus = Dead;
|
2012-07-30 07:20:58 -07:00
|
|
|
mJSContext = nullptr;
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
ClearQueue(&mControlQueue);
|
2012-02-09 20:54:47 -08:00
|
|
|
ClearQueue(&mQueue);
|
2011-07-17 12:09:13 -07:00
|
|
|
}
|
2011-09-08 17:03:03 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
ProcessAllControlRunnables();
|
2012-09-16 17:20:16 -07:00
|
|
|
|
2012-12-30 10:21:52 -08:00
|
|
|
void
|
|
|
|
EnableMemoryReporter();
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableMemoryReporter();
|
|
|
|
|
|
|
|
void
|
|
|
|
WaitForWorkerEvents(PRIntervalTime interval = PR_INTERVAL_NO_TIMEOUT);
|
|
|
|
|
2012-09-16 17:20:16 -07:00
|
|
|
static bool
|
|
|
|
CheckXHRParamsAllowed(nsPIDOMWindow* aWindow);
|
2011-07-17 12:09:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
WorkerPrivate*
|
|
|
|
GetWorkerPrivateFromContext(JSContext* aCx);
|
|
|
|
|
2011-08-15 20:40:38 -07:00
|
|
|
enum WorkerStructuredDataType
|
|
|
|
{
|
2012-04-24 03:58:07 -07:00
|
|
|
DOMWORKER_SCTAG_FILE = SCTAG_DOM_MAX,
|
2011-08-15 20:40:38 -07:00
|
|
|
DOMWORKER_SCTAG_BLOB,
|
|
|
|
|
|
|
|
DOMWORKER_SCTAG_END
|
|
|
|
};
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
JSStructuredCloneCallbacks*
|
2011-08-15 20:40:38 -07:00
|
|
|
WorkerStructuredCloneCallbacks(bool aMainRuntime);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
|
|
|
JSStructuredCloneCallbacks*
|
2011-08-15 20:40:38 -07:00
|
|
|
ChromeWorkerStructuredCloneCallbacks(bool aMainRuntime);
|
2011-07-17 12:09:13 -07:00
|
|
|
|
2012-12-21 12:14:47 -08:00
|
|
|
class AutoSyncLoopHolder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoSyncLoopHolder(WorkerPrivate* aWorkerPrivate)
|
|
|
|
: mWorkerPrivate(aWorkerPrivate), mSyncLoopKey(UINT32_MAX)
|
|
|
|
{
|
|
|
|
mSyncLoopKey = mWorkerPrivate->CreateNewSyncLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSyncLoopHolder()
|
|
|
|
{
|
|
|
|
if (mWorkerPrivate) {
|
|
|
|
mWorkerPrivate->StopSyncLoop(mSyncLoopKey, false);
|
|
|
|
mWorkerPrivate->DestroySyncLoop(mSyncLoopKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RunAndForget(JSContext* aCx)
|
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = mWorkerPrivate;
|
|
|
|
mWorkerPrivate = nullptr;
|
|
|
|
return workerPrivate->RunSyncLoop(aCx, mSyncLoopKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SyncQueueKey() const
|
|
|
|
{
|
|
|
|
return mSyncLoopKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
WorkerPrivate* mWorkerPrivate;
|
|
|
|
uint32_t mSyncLoopKey;
|
|
|
|
};
|
|
|
|
|
2011-07-17 12:09:13 -07:00
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_workers_workerprivate_h__ */
|