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-31 10:24:59 +03:00
|
|
|
#include "mozilla/dom/WorkerCommon.h"
|
2019-03-19 18:14:11 +03:00
|
|
|
#include "mozilla/Attributes.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-03-13 20:36:34 +03:00
|
|
|
#include "mozilla/RelativeTimeline.h"
|
2019-04-12 08:31:40 +03:00
|
|
|
#include "nsContentUtils.h"
|
2018-01-30 12:14:00 +03:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
|
|
|
#include "nsIEventTarget.h"
|
2015-04-07 20:31:51 +03:00
|
|
|
#include "nsTObserverArray.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2019-01-24 03:56:56 +03:00
|
|
|
#include "js/ContextOptions.h"
|
2018-02-08 10:26:05 +03:00
|
|
|
#include "mozilla/dom/Worker.h"
|
2018-01-31 10:24:08 +03:00
|
|
|
#include "mozilla/dom/WorkerHolder.h"
|
|
|
|
#include "mozilla/dom/WorkerLoadInfo.h"
|
2018-01-31 10:24:59 +03:00
|
|
|
#include "mozilla/dom/workerinternals/JSSettings.h"
|
|
|
|
#include "mozilla/dom/workerinternals/Queue.h"
|
2018-03-06 12:19:19 +03:00
|
|
|
#include "mozilla/PerformanceCounter.h"
|
2018-11-13 23:22:40 +03:00
|
|
|
#include "mozilla/ThreadBound.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
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 {
|
2018-10-18 15:20:14 +03:00
|
|
|
class ThrottledEventQueue;
|
2013-11-05 18:16:26 +04:00
|
|
|
namespace dom {
|
2018-01-30 12:14:00 +03:00
|
|
|
|
2018-02-02 19:35:28 +03:00
|
|
|
// If you change this, the corresponding list in nsIWorkerDebugger.idl needs
|
|
|
|
// to be updated too.
|
|
|
|
enum WorkerType { WorkerTypeDedicated, WorkerTypeShared, WorkerTypeService };
|
|
|
|
|
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-11-20 02:18:33 +03:00
|
|
|
class RemoteWorkerChild;
|
2018-01-31 10:22:56 +03:00
|
|
|
class WorkerControlRunnable;
|
2018-07-10 19:53:03 +03:00
|
|
|
class WorkerCSPEventListener;
|
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;
|
2018-01-31 10:22:56 +03:00
|
|
|
class WorkerRunnable;
|
2018-10-23 09:30:30 +03:00
|
|
|
class WorkerDebuggeeRunnable;
|
2018-01-31 10:20:07 +03:00
|
|
|
class WorkerThread;
|
2013-11-05 18:16:26 +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) : Mutex(aName) {}
|
2013-02-08 15:50:00 +04:00
|
|
|
|
|
|
|
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(); }
|
|
|
|
};
|
|
|
|
|
2018-03-13 20:36:34 +03:00
|
|
|
class WorkerPrivate : public RelativeTimeline {
|
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
|
|
|
};
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(WorkerPrivate)
|
|
|
|
|
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, WorkerLoadInfo* aLoadInfo,
|
2015-02-12 12:50:05 +03:00
|
|
|
ErrorResult& aRv);
|
2014-05-29 20:19:00 +04:00
|
|
|
|
2015-02-21 18:09:17 +03:00
|
|
|
enum LoadGroupBehavior { InheritLoadGroup, OverrideLoadGroup };
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
static nsresult 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
|
|
|
|
2018-02-08 11:33:32 +03:00
|
|
|
void Traverse(nsCycleCollectionTraversalCallback& aCb);
|
|
|
|
|
|
|
|
void ClearSelfAndParentEventTargetRef() {
|
|
|
|
AssertIsOnParentThread();
|
|
|
|
MOZ_ASSERT(mSelfRef);
|
|
|
|
mParentEventTargetRef = nullptr;
|
|
|
|
mSelfRef = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
// May be called on any thread...
|
|
|
|
bool Start();
|
|
|
|
|
|
|
|
// Called on the parent thread.
|
2018-04-19 01:02:08 +03:00
|
|
|
bool Notify(WorkerStatus aStatus);
|
2018-02-08 11:33:34 +03:00
|
|
|
|
|
|
|
bool Cancel() { return Notify(Canceling); }
|
|
|
|
|
|
|
|
bool Kill() { return Notify(Killing); }
|
|
|
|
|
|
|
|
bool Close();
|
|
|
|
|
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.
|
|
|
|
static void OverrideLoadInfoLoadGroup(WorkerLoadInfo& aLoadInfo,
|
|
|
|
nsIPrincipal* aPrincipal);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-01-07 15:35:31 +03:00
|
|
|
bool IsDebuggerRegistered() {
|
2018-02-05 21:55:07 +03:00
|
|
|
AssertIsOnMainThread();
|
2016-01-07 15:35:31 +03:00
|
|
|
|
|
|
|
// No need to lock here since this is only ever modified by the same thread.
|
|
|
|
return mDebuggerRegistered;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetIsDebuggerRegistered(bool aDebuggerRegistered) {
|
2018-02-05 21:55:07 +03:00
|
|
|
AssertIsOnMainThread();
|
2016-01-07 15:35:31 +03:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 02:04:18 +03:00
|
|
|
nsresult SetIsDebuggerReady(bool aReady);
|
|
|
|
|
2014-10-29 23:11:33 +03:00
|
|
|
WorkerDebugger* Debugger() const {
|
2018-02-05 21:55:07 +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) {
|
2018-02-05 21:55:07 +03:00
|
|
|
AssertIsOnMainThread();
|
2016-01-07 15:35:31 +03:00
|
|
|
|
|
|
|
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");
|
2018-05-30 22:15:35 +03:00
|
|
|
return std::move(mDefaultLocale);
|
2016-08-08 23:33:39 +03:00
|
|
|
}
|
|
|
|
|
2019-03-19 18:14:11 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2011-07-17 23:09:13 +04:00
|
|
|
void DoRunLoop(JSContext* aCx);
|
|
|
|
|
2014-03-11 01:28:43 +04:00
|
|
|
bool 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
|
|
|
|
2018-04-17 21:51:03 +03:00
|
|
|
void CloseInternal();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-02-29 22:52:43 +03:00
|
|
|
bool FreezeInternal();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-02-29 22:52:43 +03:00
|
|
|
bool ThawInternal();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-07-10 11:09:59 +03:00
|
|
|
void PropagateFirstPartyStorageAccessGrantedInternal();
|
|
|
|
|
2016-08-16 09:10:30 +03:00
|
|
|
void TraverseTimeouts(nsCycleCollectionTraversalCallback& aCallback);
|
|
|
|
|
|
|
|
void UnlinkTimeouts();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-02-26 23:23:12 +03:00
|
|
|
bool ModifyBusyCountFromWorker(bool aIncrease);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
bool AddChildWorker(WorkerPrivate* aChildWorker);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
void RemoveChildWorker(WorkerPrivate* aChildWorker);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-06-05 18:04:23 +04:00
|
|
|
void PostMessageToParent(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
2017-02-03 13:00:38 +03:00
|
|
|
const Sequence<JSObject*>& aTransferable,
|
2018-04-19 01:02:08 +03:00
|
|
|
ErrorResult& aRv);
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2017-02-03 13:00:38 +03:00
|
|
|
void PostMessageToParentMessagePort(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aMessage,
|
|
|
|
const Sequence<JSObject*>& aTransferable,
|
|
|
|
ErrorResult& aRv);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2019-03-19 18:14:11 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void EnterDebuggerEventLoop();
|
2015-03-27 09:17:16 +03:00
|
|
|
|
|
|
|
void LeaveDebuggerEventLoop();
|
|
|
|
|
2015-03-20 14:15:59 +03:00
|
|
|
void PostMessageToDebugger(const nsAString& aMessage);
|
|
|
|
|
2016-02-26 23:23:12 +03:00
|
|
|
void 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);
|
|
|
|
|
2018-03-13 17:25:50 +03:00
|
|
|
bool NotifyInternal(WorkerStatus aStatus);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-08-14 14:39:31 +03:00
|
|
|
void 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);
|
|
|
|
|
2018-01-25 04:59:04 +03:00
|
|
|
static void ReportErrorToConsole(const char* aMessage,
|
|
|
|
const nsTArray<nsString>& aParams);
|
|
|
|
|
2016-08-16 09:10:30 +03:00
|
|
|
int32_t SetTimeout(JSContext* aCx, nsIScriptTimeoutHandler* aHandler,
|
|
|
|
int32_t aTimeout, bool aIsInterval, 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
|
|
|
|
2019-03-19 23:52:03 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT bool RunExpiredTimeouts(JSContext* aCx);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
bool RescheduleTimeoutTimer(JSContext* aCx);
|
|
|
|
|
2016-07-07 09:15:15 +03:00
|
|
|
void UpdateContextOptionsInternal(JSContext* aCx,
|
|
|
|
const JS::ContextOptions& aContextOptions);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-02-26 23:23:12 +03:00
|
|
|
void UpdateLanguagesInternal(const nsTArray<nsString>& aLanguages);
|
2014-09-05 18:26:34 +04:00
|
|
|
|
2013-01-11 02:50:40 +04:00
|
|
|
void 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 };
|
|
|
|
|
|
|
|
void ScheduleDeletion(WorkerRanOrNot aRanOrNot);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2016-10-28 12:50:16 +03:00
|
|
|
bool 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
|
2013-05-17 02:49:43 +04:00
|
|
|
void 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);
|
|
|
|
|
2016-02-26 23:23:12 +03:00
|
|
|
void CycleCollectInternal(bool aCollectChildren);
|
2013-12-03 08:07:02 +04:00
|
|
|
|
2016-02-26 23:23:12 +03:00
|
|
|
void 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 {
|
2018-11-13 23:22:40 +03:00
|
|
|
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
|
|
|
|
return data->mScope;
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
|
|
|
|
2015-03-04 02:51:53 +03:00
|
|
|
WorkerDebuggerGlobalScope* DebuggerGlobalScope() const {
|
2018-11-13 23:22:40 +03:00
|
|
|
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
|
|
|
|
return data->mDebuggerScope;
|
2015-03-04 02:51:53 +03:00
|
|
|
}
|
|
|
|
|
2018-10-23 09:17:13 +03:00
|
|
|
nsICSPEventListener* CSPEventListener() const;
|
|
|
|
|
2014-11-17 22:55:37 +03:00
|
|
|
void SetThread(WorkerThread* aThread);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-11-13 23:22:40 +03:00
|
|
|
void SetWorkerPrivateInWorkerThread(WorkerThread* aThread);
|
|
|
|
|
|
|
|
void ResetWorkerPrivateInWorkerThread();
|
|
|
|
|
2018-03-13 23:16:48 +03:00
|
|
|
bool IsOnWorkerThread() const;
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-11-20 02:18:33 +03:00
|
|
|
bool ConnectMessagePort(JSContext* aCx,
|
|
|
|
const 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);
|
|
|
|
|
2013-11-20 03:08:50 +04:00
|
|
|
bool OnLine() const {
|
2018-11-13 23:22:40 +03:00
|
|
|
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
|
|
|
|
return data->mOnLine;
|
2013-11-20 03:08:50 +04:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
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
|
|
|
void OnProcessNextEvent();
|
2013-10-23 17:16:49 +04:00
|
|
|
|
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
|
|
|
void 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;
|
|
|
|
}
|
|
|
|
|
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.
|
2019-03-05 19:47:05 +03:00
|
|
|
nsIEventTarget* MainThreadEventTargetForMessaging();
|
|
|
|
|
|
|
|
nsresult DispatchToMainThreadForMessaging(
|
|
|
|
nsIRunnable* aRunnable, uint32_t aFlags = NS_DISPATCH_NORMAL);
|
|
|
|
|
|
|
|
nsresult DispatchToMainThreadForMessaging(
|
|
|
|
already_AddRefed<nsIRunnable> aRunnable,
|
|
|
|
uint32_t aFlags = NS_DISPATCH_NORMAL);
|
|
|
|
|
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);
|
|
|
|
|
2018-10-23 09:30:30 +03:00
|
|
|
nsresult DispatchDebuggeeToMainThread(
|
|
|
|
already_AddRefed<WorkerDebuggeeRunnable> 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.
|
|
|
|
nsISerialEventTarget* 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-21 23:13:04 +03:00
|
|
|
bool EnsureClientSource();
|
|
|
|
|
2018-07-10 19:53:03 +03:00
|
|
|
bool EnsureCSPEventListener();
|
|
|
|
|
2018-03-14 17:27:13 +03:00
|
|
|
void EnsurePerformanceStorage();
|
|
|
|
|
2018-04-04 14:36:25 +03:00
|
|
|
void EnsurePerformanceCounter();
|
|
|
|
|
2017-11-21 23:13:04 +03:00
|
|
|
Maybe<ClientInfo> GetClientInfo() const;
|
|
|
|
|
2018-01-12 04:46:08 +03:00
|
|
|
const ClientState GetClientState() const;
|
|
|
|
|
|
|
|
const Maybe<ServiceWorkerDescriptor> GetController();
|
|
|
|
|
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();
|
|
|
|
|
2018-03-06 12:19:19 +03:00
|
|
|
PerformanceCounter* GetPerformanceCounter();
|
|
|
|
|
2018-02-08 11:33:32 +03:00
|
|
|
bool IsAcceptingEvents() {
|
|
|
|
AssertIsOnParentThread();
|
|
|
|
|
|
|
|
MutexAutoLock lock(mMutex);
|
2018-07-12 20:33:41 +03:00
|
|
|
return mParentStatus < Canceling;
|
2018-02-08 11:33:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WorkerStatus ParentStatusProtected() {
|
|
|
|
AssertIsOnParentThread();
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
return mParentStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerStatus ParentStatus() const {
|
|
|
|
mMutex.AssertCurrentThreadOwns();
|
|
|
|
return mParentStatus;
|
|
|
|
}
|
|
|
|
|
2018-02-08 10:26:05 +03:00
|
|
|
Worker* ParentEventTargetRef() const {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mParentEventTargetRef);
|
|
|
|
return mParentEventTargetRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetParentEventTargetRef(Worker* aParentEventTargetRef) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aParentEventTargetRef);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mParentEventTargetRef);
|
|
|
|
mParentEventTargetRef = aParentEventTargetRef;
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:33:32 +03:00
|
|
|
bool ModifyBusyCount(bool aIncrease);
|
|
|
|
|
|
|
|
// This method is used by RuntimeService to know what is going wrong the
|
|
|
|
// shutting down.
|
|
|
|
uint32_t BusyCount() { return mBusyCount; }
|
|
|
|
|
2018-02-08 11:33:33 +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; }
|
|
|
|
|
2018-03-01 22:24:20 +03:00
|
|
|
// Check whether we're running in automation.
|
|
|
|
bool IsInAutomation() const { return mIsInAutomation; }
|
|
|
|
|
2018-02-08 11:33:32 +03:00
|
|
|
TimeStamp CreationTimeStamp() const { return mCreationTimeStamp; }
|
|
|
|
|
|
|
|
DOMHighResTimeStamp CreationTime() const { return mCreationTimeHighRes; }
|
|
|
|
|
|
|
|
DOMHighResTimeStamp TimeStampToDOMHighRes(const TimeStamp& aTimeStamp) const {
|
|
|
|
MOZ_ASSERT(!aTimeStamp.IsNull());
|
|
|
|
TimeDuration duration = aTimeStamp - mCreationTimeStamp;
|
|
|
|
return duration.ToMilliseconds();
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
LocationInfo& GetLocationInfo() { return mLocationInfo; }
|
|
|
|
|
|
|
|
void CopyJSSettings(workerinternals::JSSettings& aSettings) {
|
|
|
|
mozilla::MutexAutoLock lock(mMutex);
|
|
|
|
aSettings = mJSSettings;
|
|
|
|
}
|
|
|
|
|
2018-05-17 11:59:45 +03:00
|
|
|
void CopyJSRealmOptions(JS::RealmOptions& aOptions) {
|
2018-02-08 11:33:33 +03:00
|
|
|
mozilla::MutexAutoLock lock(mMutex);
|
2018-05-17 11:59:45 +03:00
|
|
|
aOptions = IsChromeWorker() ? mJSSettings.chrome.realmOptions
|
|
|
|
: mJSSettings.content.realmOptions;
|
2018-02-08 11:33:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// The ability to be a chrome worker is orthogonal to the type of
|
|
|
|
// worker [Dedicated|Shared|Service].
|
|
|
|
bool IsChromeWorker() const { return mIsChromeWorker; }
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
WorkerPrivate* GetParent() const { return mParent; }
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
bool IsFrozen() const {
|
|
|
|
AssertIsOnParentThread();
|
|
|
|
return mParentFrozen;
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
bool IsParentWindowPaused() const {
|
|
|
|
AssertIsOnParentThread();
|
2018-11-20 02:18:21 +03:00
|
|
|
return mParentWindowPaused;
|
2018-02-08 11:33:33 +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.
|
|
|
|
void ParentWindowPaused();
|
|
|
|
|
|
|
|
void ParentWindowResumed();
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
const nsString& ScriptURL() const { return mScriptURL; }
|
|
|
|
|
|
|
|
const nsString& WorkerName() const { return mWorkerName; }
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
WorkerType Type() const { return mWorkerType; }
|
|
|
|
|
|
|
|
bool IsDedicatedWorker() const { return mWorkerType == WorkerTypeDedicated; }
|
|
|
|
|
|
|
|
bool IsSharedWorker() const { return mWorkerType == WorkerTypeShared; }
|
|
|
|
|
|
|
|
bool IsServiceWorker() const { return mWorkerType == WorkerTypeService; }
|
|
|
|
|
|
|
|
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:
|
|
|
|
return nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Invalid worker type");
|
|
|
|
return nsIContentPolicy::TYPE_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
nsIScriptContext* GetScriptContext() const {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mScriptContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString& Domain() const { return mLoadInfo.mDomain; }
|
|
|
|
|
|
|
|
bool IsFromWindow() const { return mLoadInfo.mFromWindow; }
|
|
|
|
|
|
|
|
nsLoadFlags GetLoadFlags() const { return mLoadInfo.mLoadFlags; }
|
|
|
|
|
|
|
|
uint64_t WindowID() const { return mLoadInfo.mWindowID; }
|
|
|
|
|
|
|
|
uint64_t ServiceWorkerID() const { return GetServiceWorkerDescriptor().Id(); }
|
|
|
|
|
|
|
|
const nsCString& ServiceWorkerScope() const {
|
|
|
|
return GetServiceWorkerDescriptor().Scope();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI* GetBaseURI() const {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mBaseURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetBaseURI(nsIURI* aBaseURI);
|
|
|
|
|
|
|
|
nsIURI* GetResolvedScriptURI() const {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mResolvedScriptURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsString& ServiceWorkerCacheName() const {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker());
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mServiceWorkerCacheName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ServiceWorkerDescriptor& GetServiceWorkerDescriptor() const {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mLoadInfo.mServiceWorkerDescriptor.isSome());
|
|
|
|
return mLoadInfo.mServiceWorkerDescriptor.ref();
|
|
|
|
}
|
|
|
|
|
2018-02-14 22:23:15 +03:00
|
|
|
const ServiceWorkerRegistrationDescriptor&
|
|
|
|
GetServiceWorkerRegistrationDescriptor() const {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
mLoadInfo.mServiceWorkerRegistrationDescriptor.isSome());
|
|
|
|
return mLoadInfo.mServiceWorkerRegistrationDescriptor.ref();
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
void UpdateServiceWorkerState(ServiceWorkerState aState) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mLoadInfo.mServiceWorkerDescriptor.isSome());
|
|
|
|
return mLoadInfo.mServiceWorkerDescriptor.ref().SetState(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Maybe<ServiceWorkerDescriptor>& GetParentController() const {
|
|
|
|
return mLoadInfo.mParentController;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ChannelInfo& GetChannelInfo() const { return mLoadInfo.mChannelInfo; }
|
|
|
|
|
|
|
|
void SetChannelInfo(const ChannelInfo& aChannelInfo) {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
MOZ_ASSERT(!mLoadInfo.mChannelInfo.IsInitialized());
|
|
|
|
MOZ_ASSERT(aChannelInfo.IsInitialized());
|
|
|
|
mLoadInfo.mChannelInfo = aChannelInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitChannelInfo(nsIChannel* aChannel) {
|
|
|
|
mLoadInfo.mChannelInfo.InitFromChannel(aChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitChannelInfo(const ChannelInfo& aChannelInfo) {
|
|
|
|
mLoadInfo.mChannelInfo = aChannelInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal* GetPrincipal() const {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mPrincipal;
|
|
|
|
}
|
|
|
|
|
2019-04-12 08:31:25 +03:00
|
|
|
nsIPrincipal* GetEffectiveStoragePrincipal() const {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mStoragePrincipal;
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
nsIPrincipal* GetLoadingPrincipal() const {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mLoadingPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAString& Origin() const { return mLoadInfo.mOrigin; }
|
|
|
|
|
|
|
|
nsILoadGroup* GetLoadGroup() const {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mLoadGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UsesSystemPrincipal() const { return mLoadInfo.mPrincipalIsSystem; }
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
const mozilla::ipc::PrincipalInfo& GetPrincipalInfo() const {
|
2018-02-08 11:33:33 +03:00
|
|
|
return *mLoadInfo.mPrincipalInfo;
|
|
|
|
}
|
|
|
|
|
2019-04-12 08:31:25 +03:00
|
|
|
const mozilla::ipc::PrincipalInfo& GetEffectiveStoragePrincipalInfo() const {
|
|
|
|
return *mLoadInfo.mStoragePrincipalInfo;
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
already_AddRefed<nsIChannel> ForgetWorkerChannel() {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mChannel.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindowInner* GetWindow() {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContentSecurityPolicy* GetCSP() const {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mLoadInfo.mCSP;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCSP(nsIContentSecurityPolicy* aCSP);
|
|
|
|
|
|
|
|
nsresult SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue,
|
|
|
|
const nsACString& aCSPReportOnlyHeaderValue);
|
|
|
|
|
|
|
|
void SetReferrerPolicyFromHeaderValue(
|
|
|
|
const nsACString& aReferrerPolicyHeaderValue);
|
|
|
|
|
|
|
|
net::ReferrerPolicy GetReferrerPolicy() const {
|
|
|
|
return mLoadInfo.mReferrerPolicy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetReferrerPolicy(net::ReferrerPolicy aReferrerPolicy) {
|
|
|
|
mLoadInfo.mReferrerPolicy = aReferrerPolicy;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEvalAllowed() const { return mLoadInfo.mEvalAllowed; }
|
|
|
|
|
|
|
|
void SetEvalAllowed(bool aEvalAllowed) {
|
|
|
|
mLoadInfo.mEvalAllowed = aEvalAllowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetReportCSPViolations() const { return mLoadInfo.mReportCSPViolations; }
|
|
|
|
|
|
|
|
void SetReportCSPViolations(bool aReport) {
|
|
|
|
mLoadInfo.mReportCSPViolations = aReport;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XHRParamsAllowed() const { return mLoadInfo.mXHRParamsAllowed; }
|
|
|
|
|
|
|
|
void SetXHRParamsAllowed(bool aAllowed) {
|
|
|
|
mLoadInfo.mXHRParamsAllowed = aAllowed;
|
|
|
|
}
|
|
|
|
|
2019-04-12 08:31:40 +03:00
|
|
|
nsContentUtils::StorageAccess StorageAccess() const {
|
2018-07-10 11:09:59 +03:00
|
|
|
AssertIsOnWorkerThread();
|
2019-04-12 08:31:40 +03:00
|
|
|
if (mLoadInfo.mFirstPartyStorageAccessGranted) {
|
|
|
|
return nsContentUtils::StorageAccess::eAllow;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mLoadInfo.mStorageAccess;
|
2018-02-08 11:33:33 +03:00
|
|
|
}
|
|
|
|
|
2019-03-08 12:04:11 +03:00
|
|
|
nsICookieSettings* CookieSettings() const {
|
|
|
|
// Any thread.
|
|
|
|
MOZ_ASSERT(mLoadInfo.mCookieSettings);
|
|
|
|
return mLoadInfo.mCookieSettings;
|
|
|
|
}
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
const OriginAttributes& GetOriginAttributes() const {
|
|
|
|
return mLoadInfo.mOriginAttributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine if the SW testing per-window flag is set by devtools
|
|
|
|
bool ServiceWorkersTestingInWindow() const {
|
|
|
|
return mLoadInfo.mServiceWorkersTestingInWindow;
|
|
|
|
}
|
|
|
|
|
2018-06-05 20:49:13 +03:00
|
|
|
// Determine if the worker is currently loading its top level script.
|
|
|
|
bool IsLoadingWorkerScript() const { return mLoadingWorkerScript; }
|
2018-02-08 11:33:33 +03:00
|
|
|
|
2018-06-05 20:49:13 +03:00
|
|
|
// Called by ScriptLoader to track when this worker is loading its
|
|
|
|
// top level script.
|
2018-02-08 11:33:33 +03:00
|
|
|
void SetLoadingWorkerScript(bool aLoadingWorkerScript) {
|
|
|
|
// any thread
|
|
|
|
mLoadingWorkerScript = aLoadingWorkerScript;
|
|
|
|
}
|
|
|
|
|
2018-11-20 02:18:33 +03:00
|
|
|
RemoteWorkerChild* GetRemoteWorkerController();
|
2018-02-08 11:33:33 +03:00
|
|
|
|
2018-11-20 02:18:33 +03:00
|
|
|
void SetRemoteWorkerController(RemoteWorkerChild* aController);
|
2018-02-08 11:33:33 +03:00
|
|
|
|
2018-02-08 11:33:33 +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.
|
|
|
|
bool Freeze(nsPIDOMWindowInner* aWindow);
|
|
|
|
|
|
|
|
bool Thaw(nsPIDOMWindowInner* aWindow);
|
|
|
|
|
2018-07-10 11:09:59 +03:00
|
|
|
void PropagateFirstPartyStorageAccessGranted();
|
|
|
|
|
2018-02-08 11:33:33 +03:00
|
|
|
void EnableDebugger();
|
|
|
|
|
|
|
|
void DisableDebugger();
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
already_AddRefed<WorkerRunnable> MaybeWrapAsWorkerRunnable(
|
|
|
|
already_AddRefed<nsIRunnable> aRunnable);
|
|
|
|
|
|
|
|
bool ProxyReleaseMainThreadObjects();
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
void GarbageCollect(bool aShrinking);
|
|
|
|
|
|
|
|
void CycleCollect(bool aDummy);
|
|
|
|
|
2019-04-12 08:31:25 +03:00
|
|
|
nsresult SetPrincipalsOnMainThread(nsIPrincipal* aPrincipal,
|
|
|
|
nsIPrincipal* aStoragePrincipal,
|
|
|
|
nsILoadGroup* aLoadGroup);
|
2018-02-08 11:33:34 +03:00
|
|
|
|
2019-04-12 08:31:25 +03:00
|
|
|
nsresult SetPrincipalsFromChannel(nsIChannel* aChannel);
|
2018-02-08 11:33:34 +03:00
|
|
|
|
|
|
|
bool FinalChannelPrincipalIsValid(nsIChannel* aChannel);
|
|
|
|
|
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
bool PrincipalURIMatchesScriptURL();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void UpdateOverridenLoadGroup(nsILoadGroup* aBaseLoadGroup);
|
|
|
|
|
|
|
|
void WorkerScriptLoaded();
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* GetDocument() const;
|
2018-02-08 11:33:34 +03:00
|
|
|
|
|
|
|
void MemoryPressure(bool aDummy);
|
|
|
|
|
|
|
|
void UpdateContextOptions(const JS::ContextOptions& aContextOptions);
|
|
|
|
|
|
|
|
void UpdateLanguages(const nsTArray<nsString>& aLanguages);
|
|
|
|
|
|
|
|
void UpdateJSWorkerMemoryParameter(JSGCParamKey key, uint32_t value);
|
|
|
|
|
|
|
|
#ifdef JS_GC_ZEAL
|
|
|
|
void UpdateGCZeal(uint8_t aGCZeal, uint32_t aFrequency);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void OfflineStatusChangeEvent(bool aIsOffline);
|
|
|
|
|
2018-04-17 06:08:26 +03:00
|
|
|
nsresult Dispatch(already_AddRefed<WorkerRunnable> aRunnable,
|
|
|
|
nsIEventTarget* aSyncLoopTarget = nullptr);
|
2018-02-08 11:33:34 +03:00
|
|
|
|
|
|
|
nsresult DispatchControlRunnable(
|
|
|
|
already_AddRefed<WorkerControlRunnable> aWorkerControlRunnable);
|
|
|
|
|
|
|
|
nsresult DispatchDebuggerRunnable(
|
|
|
|
already_AddRefed<WorkerRunnable> aDebuggerRunnable);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void AssertIsOnParentThread() const;
|
|
|
|
|
|
|
|
void AssertInnerWindowIsCorrect() const;
|
|
|
|
#else
|
|
|
|
void AssertIsOnParentThread() const {}
|
|
|
|
|
|
|
|
void AssertInnerWindowIsCorrect() const {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
bool PrincipalIsValid() const;
|
|
|
|
#endif
|
|
|
|
|
2018-04-17 21:51:04 +03:00
|
|
|
void StartCancelingTimer();
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
private:
|
2016-03-12 00:43:30 +03:00
|
|
|
WorkerPrivate(WorkerPrivate* aParent, const nsAString& aScriptURL,
|
2017-05-17 17:49:34 +03:00
|
|
|
bool aIsChromeWorker, 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
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
~WorkerPrivate();
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
bool MayContinueRunning() {
|
|
|
|
AssertIsOnWorkerThread();
|
|
|
|
|
2018-01-31 10:23:44 +03:00
|
|
|
WorkerStatus status;
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-10-23 17:16:49 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
2011-07-17 23:09:13 +04:00
|
|
|
status = mStatus;
|
|
|
|
}
|
|
|
|
|
2018-07-12 20:33:41 +03:00
|
|
|
if (status < Canceling) {
|
2016-09-01 07:33:05 +03:00
|
|
|
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
|
|
|
|
2016-02-27 05:15:56 +03:00
|
|
|
void 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 ProcessAllControlRunnables() {
|
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
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
ProcessAllControlRunnablesResult ProcessAllControlRunnablesLocked();
|
2012-09-17 04:20:16 +04:00
|
|
|
|
2012-12-30 22:21:52 +04:00
|
|
|
void EnableMemoryReporter();
|
|
|
|
|
|
|
|
void DisableMemoryReporter();
|
|
|
|
|
2018-02-09 23:17:26 +03:00
|
|
|
void WaitForWorkerEvents();
|
2012-12-30 22:21:52 +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.
|
2018-01-31 10:23:44 +03:00
|
|
|
already_AddRefed<nsIEventTarget> CreateNewSyncLoop(WorkerStatus aFailStatus);
|
2013-10-23 17:16:49 +04:00
|
|
|
|
|
|
|
bool RunCurrentSyncLoop();
|
|
|
|
|
2018-03-16 17:20:29 +03:00
|
|
|
bool DestroySyncLoop(uint32_t aLoopIndex);
|
2014-01-11 04:37:47 +04:00
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
void InitializeGCTimers();
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
enum GCTimerMode { PeriodicTimer = 0, IdleTimer, NoTimer };
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
void SetGCTimerMode(GCTimerMode aMode);
|
|
|
|
|
|
|
|
void ShutdownGCTimers();
|
2016-06-23 11:53:14 +03:00
|
|
|
|
2018-01-31 10:23:44 +03:00
|
|
|
bool AddHolder(WorkerHolder* aHolder, WorkerStatus aFailStatus);
|
2016-06-23 11:53:14 +03:00
|
|
|
|
|
|
|
void RemoveHolder(WorkerHolder* aHolder);
|
|
|
|
|
2018-03-13 17:25:50 +03:00
|
|
|
void NotifyHolders(WorkerStatus aStatus);
|
2016-06-23 11:53:14 +03:00
|
|
|
|
|
|
|
bool HasActiveHolders() {
|
2018-11-13 23:22:40 +03:00
|
|
|
MOZ_ACCESS_THREAD_BOUND(mWorkerThreadAccessible, data);
|
|
|
|
return !(data->mChildWorkers.IsEmpty() && data->mTimeouts.IsEmpty() &&
|
|
|
|
data->mHolders.IsEmpty());
|
2016-06-23 11:53:14 +03:00
|
|
|
}
|
2018-02-08 11:33:34 +03:00
|
|
|
|
2019-02-13 02:04:18 +03:00
|
|
|
// Internal logic to dispatch a runnable. This is separate from Dispatch()
|
|
|
|
// to allow runnables to be atomically dispatched in bulk.
|
|
|
|
nsresult DispatchLockHeld(already_AddRefed<WorkerRunnable> aRunnable,
|
|
|
|
nsIEventTarget* aSyncLoopTarget,
|
|
|
|
const MutexAutoLock& aProofOfLock);
|
|
|
|
|
2019-04-02 23:53:16 +03:00
|
|
|
// This method dispatches a simple runnable that starts the shutdown procedure
|
|
|
|
// after a self.close(). This method is called after a ClearMainEventQueue()
|
|
|
|
// to be sure that the canceling runnable is the only one in the queue. We
|
|
|
|
// need this async operation to be sure that all the current JS code is
|
|
|
|
// executed.
|
|
|
|
void DispatchCancelingRunnable();
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
class EventTarget;
|
|
|
|
friend class EventTarget;
|
|
|
|
friend class mozilla::dom::WorkerHolder;
|
|
|
|
friend class AutoSyncLoopHolder;
|
|
|
|
|
|
|
|
struct TimeoutInfo;
|
|
|
|
|
|
|
|
class MemoryReporter;
|
|
|
|
friend class MemoryReporter;
|
|
|
|
|
|
|
|
friend class mozilla::dom::WorkerThread;
|
|
|
|
|
|
|
|
SharedMutex mMutex;
|
|
|
|
mozilla::CondVar mCondVar;
|
|
|
|
|
|
|
|
WorkerPrivate* mParent;
|
|
|
|
|
|
|
|
nsString mScriptURL;
|
|
|
|
|
|
|
|
// This is the worker name for shared workers and dedicated workers.
|
|
|
|
nsString mWorkerName;
|
|
|
|
|
|
|
|
WorkerType mWorkerType;
|
|
|
|
|
|
|
|
// The worker is owned by its thread, which is represented here. This is set
|
|
|
|
// in Constructor() and emptied by WorkerFinishedRunnable, and conditionally
|
|
|
|
// traversed by the cycle collector if the busy count is zero.
|
|
|
|
//
|
|
|
|
// There are 4 ways a worker can be terminated:
|
|
|
|
// 1. GC/CC - When the worker is in idle state (busycount == 0), it allows to
|
|
|
|
// traverse the 'hidden' mParentEventTargetRef pointer. This is the exposed
|
|
|
|
// Worker webidl object. Doing this, CC will be able to detect a cycle and
|
2018-07-12 20:33:41 +03:00
|
|
|
// Unlink is called. In Unlink, Worker calls Cancel().
|
|
|
|
// 2. Worker::Cancel() is called - the shutdown procedure starts immediately.
|
2018-02-08 11:33:34 +03:00
|
|
|
// 3. WorkerScope::Close() is called - Similar to point 2.
|
|
|
|
// 4. xpcom-shutdown notification - We call Kill().
|
|
|
|
RefPtr<Worker> mParentEventTargetRef;
|
|
|
|
RefPtr<WorkerPrivate> mSelfRef;
|
|
|
|
|
|
|
|
// The lifetime of these objects within LoadInfo is managed explicitly;
|
|
|
|
// they do not need to be cycle collected.
|
|
|
|
WorkerLoadInfo mLoadInfo;
|
|
|
|
LocationInfo mLocationInfo;
|
|
|
|
|
|
|
|
// Protected by mMutex.
|
|
|
|
workerinternals::JSSettings mJSSettings;
|
|
|
|
|
|
|
|
WorkerDebugger* mDebugger;
|
|
|
|
|
|
|
|
workerinternals::Queue<WorkerControlRunnable*, 4> mControlQueue;
|
|
|
|
workerinternals::Queue<WorkerRunnable*, 4> mDebuggerQueue;
|
|
|
|
|
|
|
|
// Touched on multiple threads, protected with mMutex.
|
|
|
|
JSContext* mJSContext;
|
|
|
|
RefPtr<WorkerThread> mThread;
|
|
|
|
PRThread* mPRThread;
|
|
|
|
|
2018-11-13 23:22:40 +03:00
|
|
|
// Accessed from main thread
|
2019-03-05 19:47:05 +03:00
|
|
|
RefPtr<ThrottledEventQueue> mMainThreadEventTargetForMessaging;
|
2018-10-17 11:44:43 +03:00
|
|
|
RefPtr<ThrottledEventQueue> mMainThreadEventTarget;
|
2018-11-13 23:22:40 +03:00
|
|
|
|
|
|
|
// Accessed from worker thread and destructing thread
|
2018-02-08 11:33:34 +03:00
|
|
|
RefPtr<WorkerEventTarget> mWorkerControlEventTarget;
|
|
|
|
RefPtr<WorkerEventTarget> mWorkerHybridEventTarget;
|
|
|
|
|
2018-10-23 09:30:30 +03:00
|
|
|
// A pauseable queue for WorkerDebuggeeRunnables directed at the main thread.
|
|
|
|
// See WorkerDebuggeeRunnable for details.
|
|
|
|
RefPtr<ThrottledEventQueue> mMainThreadDebuggeeEventTarget;
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
struct SyncLoopInfo {
|
|
|
|
explicit SyncLoopInfo(EventTarget* aEventTarget);
|
|
|
|
|
|
|
|
RefPtr<EventTarget> mEventTarget;
|
|
|
|
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;
|
|
|
|
|
2018-04-17 21:51:04 +03:00
|
|
|
nsCOMPtr<nsITimer> mCancelingTimer;
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
// fired on the main thread if the worker script fails to load
|
|
|
|
nsCOMPtr<nsIRunnable> mLoadFailedRunnable;
|
|
|
|
|
|
|
|
RefPtr<PerformanceStorage> mPerformanceStorage;
|
|
|
|
|
2018-07-10 19:53:03 +03:00
|
|
|
RefPtr<WorkerCSPEventListener> mCSPEventListener;
|
|
|
|
|
2018-02-08 11:33:34 +03:00
|
|
|
// Protected by mMutex.
|
|
|
|
nsTArray<RefPtr<WorkerRunnable>> mPreStartRunnables;
|
|
|
|
|
2018-11-20 02:18:21 +03:00
|
|
|
// Only touched on the parent thread. This is set only if IsSharedWorker().
|
2018-11-20 02:18:33 +03:00
|
|
|
RefPtr<RemoteWorkerChild> mRemoteWorkerController;
|
2018-02-08 11:33:34 +03:00
|
|
|
|
|
|
|
JS::UniqueChars mDefaultLocale; // nulled during worker JSContext init
|
|
|
|
TimeStamp mKillTime;
|
|
|
|
WorkerStatus mParentStatus;
|
|
|
|
WorkerStatus mStatus;
|
|
|
|
|
|
|
|
// This is touched on parent thread only, but it can be read on a different
|
|
|
|
// thread before crashing because hanging.
|
|
|
|
Atomic<uint64_t> mBusyCount;
|
|
|
|
|
|
|
|
Atomic<bool> mLoadingWorkerScript;
|
|
|
|
|
|
|
|
TimeStamp mCreationTimeStamp;
|
|
|
|
DOMHighResTimeStamp mCreationTimeHighRes;
|
|
|
|
|
|
|
|
// Things touched on worker thread only.
|
2018-11-13 23:22:40 +03:00
|
|
|
struct WorkerThreadAccessible {
|
|
|
|
explicit WorkerThreadAccessible(WorkerPrivate* aParent);
|
|
|
|
|
|
|
|
RefPtr<WorkerGlobalScope> mScope;
|
|
|
|
RefPtr<WorkerDebuggerGlobalScope> mDebuggerScope;
|
|
|
|
nsTArray<WorkerPrivate*> mChildWorkers;
|
|
|
|
nsTObserverArray<WorkerHolder*> mHolders;
|
|
|
|
nsTArray<nsAutoPtr<TimeoutInfo>> mTimeouts;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
nsCOMPtr<nsITimerCallback> mTimerRunnable;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mGCTimer;
|
2018-02-08 11:33:34 +03:00
|
|
|
|
2018-11-13 23:22:40 +03:00
|
|
|
RefPtr<MemoryReporter> mMemoryReporter;
|
|
|
|
|
|
|
|
UniquePtr<ClientSource> mClientSource;
|
|
|
|
|
|
|
|
uint32_t mNumHoldersPreventingShutdownStart;
|
|
|
|
uint32_t mDebuggerEventLoopLevel;
|
|
|
|
|
|
|
|
uint32_t mErrorHandlerRecursionCount;
|
|
|
|
uint32_t mNextTimeoutId;
|
|
|
|
|
|
|
|
bool mFrozen;
|
|
|
|
bool mTimerRunning;
|
|
|
|
bool mRunningExpiredTimeouts;
|
|
|
|
bool mPeriodicGCTimerRunning;
|
|
|
|
bool mIdleGCTimerRunning;
|
|
|
|
bool mOnLine;
|
|
|
|
};
|
|
|
|
ThreadBound<WorkerThreadAccessible> mWorkerThreadAccessible;
|
2018-02-08 11:33:34 +03:00
|
|
|
|
2019-04-02 23:53:16 +03:00
|
|
|
uint32_t mPostSyncLoopOperations;
|
|
|
|
|
|
|
|
// List of operations to do at the end of the last sync event loop.
|
|
|
|
enum {
|
|
|
|
ePendingEventQueueClearing = 0x01,
|
|
|
|
eDispatchCancelingRunnable = 0x02,
|
|
|
|
};
|
|
|
|
|
2018-11-20 02:18:21 +03:00
|
|
|
bool mParentWindowPaused;
|
2018-02-08 11:33:34 +03:00
|
|
|
|
|
|
|
bool mCancelAllPendingRunnables;
|
|
|
|
bool mWorkerScriptExecutedSuccessfully;
|
|
|
|
bool mFetchHandlerWasAdded;
|
|
|
|
bool mMainThreadObjectsForgotten;
|
|
|
|
bool mIsChromeWorker;
|
|
|
|
bool mParentFrozen;
|
|
|
|
|
|
|
|
// mIsSecureContext is set once in our constructor; after that it can be read
|
2018-11-21 23:02:51 +03:00
|
|
|
// from various threads.
|
2018-02-08 11:33:34 +03:00
|
|
|
//
|
|
|
|
// 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.
|
2018-11-21 23:02:51 +03:00
|
|
|
const bool mIsSecureContext;
|
2018-02-08 11:33:34 +03:00
|
|
|
|
|
|
|
bool mDebuggerRegistered;
|
2018-03-01 22:24:20 +03:00
|
|
|
|
2019-02-13 02:04:18 +03:00
|
|
|
// During registration, this worker may be marked as not being ready to
|
|
|
|
// execute debuggee runnables or content.
|
|
|
|
//
|
|
|
|
// Protected by mMutex.
|
|
|
|
bool mDebuggerReady;
|
|
|
|
nsTArray<RefPtr<WorkerRunnable>> mDelayedDebuggeeRunnables;
|
|
|
|
|
2018-03-01 22:24:20 +03:00
|
|
|
// mIsInAutomation is true when we're running in test automation.
|
|
|
|
// We expose some extra testing functions in that case.
|
|
|
|
bool mIsInAutomation;
|
2018-03-06 12:19:19 +03:00
|
|
|
|
2018-04-24 23:03:06 +03:00
|
|
|
// This pointer will be null if dom.performance.enable_scheduler_timing is
|
|
|
|
// false (default value)
|
2018-03-06 12:19:19 +03:00
|
|
|
RefPtr<mozilla::PerformanceCounter> mPerformanceCounter;
|
2011-07-17 23:09:13 +04:00
|
|
|
};
|
|
|
|
|
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.
|
2018-01-31 10:23:44 +03:00
|
|
|
AutoSyncLoopHolder(WorkerPrivate* aWorkerPrivate, WorkerStatus 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) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-23 17:16:49 +04:00
|
|
|
bool 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
|
|
|
}
|
|
|
|
|
2017-01-05 12:05:32 +03:00
|
|
|
nsIEventTarget* GetEventTarget() const {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-31 10:24:08 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2011-07-17 23:09:13 +04:00
|
|
|
|
|
|
|
#endif /* mozilla_dom_workers_workerprivate_h__ */
|