Bug 1432963 - Fixing workers headers - part 16 - JSSettings in a workerinternals namespace, r=smaug

This commit is contained in:
Andrea Marchesini 2018-01-31 08:24:59 +01:00
Родитель a5bed23bd8
Коммит 7e52540256
29 изменённых файлов: 360 добавлений и 324 удалений

Просмотреть файл

@ -16,7 +16,7 @@
#include "mozilla/dom/StructuredCloneTags.h"
// for mozilla::dom::workers::kJSPrincipalsDebugToken
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/workerinternals/JSSettings.h"
#include "mozilla/ipc/BackgroundUtils.h"
using namespace mozilla;
@ -90,7 +90,7 @@ JSPrincipals::dump()
nsresult rv = static_cast<nsJSPrincipals *>(this)->GetScriptLocation(str);
fprintf(stderr, "nsIPrincipal (%p) = %s\n", static_cast<void*>(this),
NS_SUCCEEDED(rv) ? str.get() : "(unknown)");
} else if (debugToken == dom::workers::kJSPrincipalsDebugToken) {
} else if (debugToken == dom::workerinternals::kJSPrincipalsDebugToken) {
fprintf(stderr, "Web Worker principal singleton (%p)\n", this);
} else {
fprintf(stderr,

Просмотреть файл

@ -45,7 +45,7 @@
#include "mozilla/dom/VRDisplay.h"
#include "mozilla/dom/VRDisplayEvent.h"
#include "mozilla/dom/VRServiceTest.h"
#include "mozilla/dom/workers/RuntimeService.h"
#include "mozilla/dom/workerinternals/RuntimeService.h"
#include "mozilla/Hal.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/StaticPtr.h"
@ -692,7 +692,8 @@ Navigator::JavaEnabled(CallerType aCallerType, ErrorResult& aRv)
uint64_t
Navigator::HardwareConcurrency()
{
workers::RuntimeService* rts = workers::RuntimeService::GetOrCreateService();
workerinternals::RuntimeService* rts =
workerinternals::RuntimeService::GetOrCreateService();
if (!rts) {
return 1;
}

Просмотреть файл

@ -82,7 +82,7 @@
#include "nsContentCID.h"
#include "nsLayoutStatics.h"
#include "nsCCUncollectableMarker.h"
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsJSPrincipals.h"
#include "mozilla/Attributes.h"

Просмотреть файл

@ -80,7 +80,7 @@
#include "nsContentCID.h"
#include "nsLayoutStatics.h"
#include "nsCCUncollectableMarker.h"
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsJSPrincipals.h"
#include "mozilla/Attributes.h"

Просмотреть файл

@ -32,7 +32,7 @@
#include "mozilla/dom/File.h"
#include "mozilla/dom/PerformanceStorage.h"
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/Unused.h"

Просмотреть файл

@ -13,9 +13,9 @@
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/FetchTypes.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/workers/WorkerCommon.h"
#include "WorkerPrivate.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerPrivate.h"
namespace mozilla {
namespace dom {

Просмотреть файл

@ -10,7 +10,7 @@
#include "mozilla/dom/Event.h"
#include "mozilla/dom/NotificationEventBinding.h"
#include "mozilla/dom/ServiceWorkerEvents.h"
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
namespace mozilla {
namespace dom {

Просмотреть файл

@ -16,9 +16,9 @@
#include "mozilla/dom/PromiseWorkerProxy.h"
#include "mozilla/dom/PushSubscriptionOptions.h"
#include "mozilla/dom/PushUtil.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerScope.h"
#include "mozilla/dom/workers/WorkerCommon.h"
namespace mozilla {
namespace dom {

Просмотреть файл

@ -15,7 +15,7 @@
#include "mozilla/dom/File.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/Response.h"
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "nsProxyRelease.h"
#include "nsContentUtils.h"

Просмотреть файл

@ -9,7 +9,7 @@
#include "MainThreadUtils.h"
#include "mozilla/dom/ServiceWorkerBinding.h" // For ServiceWorkerState
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/OriginAttributes.h"
#include "nsIServiceWorkerManager.h"

132
dom/workers/JSSettings.h Normal file
Просмотреть файл

@ -0,0 +1,132 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_workerinternals_JSSettings_h
#define mozilla_dom_workerinternals_JSSettings_h
#include "jsapi.h"
#include "mozilla/Maybe.h"
#include "nsString.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
namespace workerinternals {
// Random unique constant to facilitate JSPrincipal debugging
const uint32_t kJSPrincipalsDebugToken = 0x7e2df9d2;
struct JSSettings
{
enum {
// All the GC parameters that we support.
JSSettings_JSGC_MAX_BYTES = 0,
JSSettings_JSGC_MAX_MALLOC_BYTES,
JSSettings_JSGC_HIGH_FREQUENCY_TIME_LIMIT,
JSSettings_JSGC_LOW_FREQUENCY_HEAP_GROWTH,
JSSettings_JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN,
JSSettings_JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX,
JSSettings_JSGC_HIGH_FREQUENCY_LOW_LIMIT,
JSSettings_JSGC_HIGH_FREQUENCY_HIGH_LIMIT,
JSSettings_JSGC_ALLOCATION_THRESHOLD,
JSSettings_JSGC_SLICE_TIME_BUDGET,
JSSettings_JSGC_DYNAMIC_HEAP_GROWTH,
JSSettings_JSGC_DYNAMIC_MARK_SLICE,
// JSGC_MODE not supported
// This must be last so that we get an accurate count.
kGCSettingsArraySize
};
struct JSGCSetting
{
mozilla::Maybe<JSGCParamKey> key;
uint32_t value;
JSGCSetting()
: key(), value(0)
{ }
};
// There are several settings that we know we need so it makes sense to
// preallocate here.
typedef JSGCSetting JSGCSettingsArray[kGCSettingsArraySize];
// Settings that change based on chrome/content context.
struct JSContentChromeSettings
{
JS::CompartmentOptions compartmentOptions;
int32_t maxScriptRuntime;
JSContentChromeSettings()
: compartmentOptions(), maxScriptRuntime(0)
{ }
};
JSContentChromeSettings chrome;
JSContentChromeSettings content;
JSGCSettingsArray gcSettings;
JS::ContextOptions contextOptions;
#ifdef JS_GC_ZEAL
uint8_t gcZeal;
uint32_t gcZealFrequency;
#endif
JSSettings()
#ifdef JS_GC_ZEAL
: gcZeal(0), gcZealFrequency(0)
#endif
{
for (uint32_t index = 0; index < ArrayLength(gcSettings); index++) {
new (gcSettings + index) JSGCSetting();
}
}
bool
ApplyGCSetting(JSGCParamKey aKey, uint32_t aValue)
{
JSSettings::JSGCSetting* firstEmptySetting = nullptr;
JSSettings::JSGCSetting* foundSetting = nullptr;
for (uint32_t index = 0; index < ArrayLength(gcSettings); index++) {
JSSettings::JSGCSetting& setting = gcSettings[index];
if (setting.key.isSome() && *setting.key == aKey) {
foundSetting = &setting;
break;
}
if (!firstEmptySetting && setting.key.isNothing()) {
firstEmptySetting = &setting;
}
}
if (aValue) {
if (!foundSetting) {
foundSetting = firstEmptySetting;
if (!foundSetting) {
NS_ERROR("Not enough space for this value!");
return false;
}
}
foundSetting->key = mozilla::Some(aKey);
foundSetting->value = aValue;
return true;
}
if (foundSetting) {
foundSetting->key.reset();
return true;
}
return false;
}
};
} // workerinternals namespace
} // dom namespace
} // mozilla namespace
#endif // mozilla_dom_workerinternals_JSSettings_h

Просмотреть файл

@ -36,7 +36,7 @@ GetWorkerPrincipal()
--sPrincipal.refcount;
} else {
#ifdef DEBUG
sPrincipal.debugToken = workers::kJSPrincipalsDebugToken;
sPrincipal.debugToken = workerinternals::kJSPrincipalsDebugToken;
#endif
}

Просмотреть файл

@ -4,17 +4,17 @@
* 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/. */
#ifndef mozilla_dom_workers_queue_h__
#define mozilla_dom_workers_queue_h__
#ifndef mozilla_dom_workerinternal_Queue_h
#define mozilla_dom_workerinternal_Queue_h
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/Mutex.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
namespace workersinternals {
namespace workerinternals {
template <typename T, int TCount>
struct StorageWithTArray
@ -200,8 +200,8 @@ private:
Queue & operator=(const Queue&);
};
} // workersinternals namespace
} // workerinternals namespace
} // dom namespace
} // mozilla namespace
#endif /* mozilla_dom_workers_queue_h__ */
#endif /* mozilla_dom_workerinternals_Queue_h*/

Просмотреть файл

@ -83,7 +83,11 @@ namespace mozilla {
using namespace ipc;
namespace dom {
namespace workers {
using namespace workers;
using namespace workerinternals;
namespace workerinternals {
// The size of the worker runtime heaps in bytes. May be changed via pref.
#define WORKER_DEFAULT_RUNTIME_HEAPSIZE 32 * 1024 * 1024
@ -1251,131 +1255,6 @@ PlatformOverrideChanged(const char* /* aPrefName */, void* /* aClosure */)
} /* anonymous namespace */
void
CancelWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->CancelWorkersForWindow(aWindow);
}
}
void
FreezeWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->FreezeWorkersForWindow(aWindow);
}
}
void
ThawWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->ThawWorkersForWindow(aWindow);
}
}
void
SuspendWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->SuspendWorkersForWindow(aWindow);
}
}
void
ResumeWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->ResumeWorkersForWindow(aWindow);
}
}
WorkerPrivate*
GetWorkerPrivateFromContext(JSContext* aCx)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aCx);
void* cxPrivate = JS_GetContextPrivate(aCx);
if (!cxPrivate) {
return nullptr;
}
return
static_cast<WorkerThreadContextPrivate*>(cxPrivate)->GetWorkerPrivate();
}
WorkerPrivate*
GetCurrentThreadWorkerPrivate()
{
MOZ_ASSERT(!NS_IsMainThread());
CycleCollectedJSContext* ccjscx = CycleCollectedJSContext::Get();
if (!ccjscx) {
return nullptr;
}
JSContext* cx = ccjscx->Context();
MOZ_ASSERT(cx);
// Note that we can return nullptr if the nsCycleCollector_shutdown() in
// ~WorkerJSContext() triggers any calls to GetCurrentThreadWorkerPrivate().
// At this stage CycleCollectedJSContext::Get() will still return a context,
// but the context private has already been cleared.
return GetWorkerPrivateFromContext(cx);
}
bool
IsCurrentThreadRunningChromeWorker()
{
return GetCurrentThreadWorkerPrivate()->UsesSystemPrincipal();
}
JSContext*
GetCurrentThreadJSContext()
{
WorkerPrivate* wp = GetCurrentThreadWorkerPrivate();
if (!wp) {
return nullptr;
}
return wp->GetJSContext();
}
JSObject*
GetCurrentThreadWorkerGlobal()
{
WorkerPrivate* wp = GetCurrentThreadWorkerPrivate();
if (!wp) {
return nullptr;
}
WorkerGlobalScope* scope = wp->GlobalScope();
if (!scope) {
return nullptr;
}
return scope->GetGlobalJSObject();
}
#ifdef DEBUG
void
AssertIsOnMainThread()
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
}
#endif
struct RuntimeService::IdleThreadInfo
{
RefPtr<WorkerThread> mThread;
@ -2931,6 +2810,136 @@ WorkerThreadPrimaryRunnable::FinishedRunnable::Run()
return NS_OK;
}
} // workerinternals namespace
namespace workers {
void
CancelWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->CancelWorkersForWindow(aWindow);
}
}
void
FreezeWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->FreezeWorkersForWindow(aWindow);
}
}
void
ThawWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->ThawWorkersForWindow(aWindow);
}
}
void
SuspendWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->SuspendWorkersForWindow(aWindow);
}
}
void
ResumeWorkersForWindow(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->ResumeWorkersForWindow(aWindow);
}
}
WorkerPrivate*
GetWorkerPrivateFromContext(JSContext* aCx)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aCx);
void* cxPrivate = JS_GetContextPrivate(aCx);
if (!cxPrivate) {
return nullptr;
}
return
static_cast<WorkerThreadContextPrivate*>(cxPrivate)->GetWorkerPrivate();
}
WorkerPrivate*
GetCurrentThreadWorkerPrivate()
{
MOZ_ASSERT(!NS_IsMainThread());
CycleCollectedJSContext* ccjscx = CycleCollectedJSContext::Get();
if (!ccjscx) {
return nullptr;
}
JSContext* cx = ccjscx->Context();
MOZ_ASSERT(cx);
// Note that we can return nullptr if the nsCycleCollector_shutdown() in
// ~WorkerJSContext() triggers any calls to GetCurrentThreadWorkerPrivate().
// At this stage CycleCollectedJSContext::Get() will still return a context,
// but the context private has already been cleared.
return GetWorkerPrivateFromContext(cx);
}
bool
IsCurrentThreadRunningChromeWorker()
{
return GetCurrentThreadWorkerPrivate()->UsesSystemPrincipal();
}
JSContext*
GetCurrentThreadJSContext()
{
WorkerPrivate* wp = GetCurrentThreadWorkerPrivate();
if (!wp) {
return nullptr;
}
return wp->GetJSContext();
}
JSObject*
GetCurrentThreadWorkerGlobal()
{
WorkerPrivate* wp = GetCurrentThreadWorkerPrivate();
if (!wp) {
return nullptr;
}
WorkerGlobalScope* scope = wp->GlobalScope();
if (!scope) {
return nullptr;
}
return scope->GetGlobalJSObject();
}
#ifdef DEBUG
void
AssertIsOnMainThread()
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
}
#endif
} // workers namespace
} // dom namespace
} // mozilla namespace

Просмотреть файл

@ -12,6 +12,7 @@
#include "nsIObserver.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/workerinternals/JSSettings.h"
#include "nsClassHashtable.h"
#include "nsHashKeys.h"
#include "nsTArray.h"
@ -25,7 +26,7 @@ class SharedWorker;
struct WorkerLoadInfo;
class WorkerThread;
namespace workers {
namespace workerinternals {
class RuntimeService final : public nsIObserver
{
@ -93,7 +94,7 @@ class RuntimeService final : public nsIObserver
// Only used on the main thread.
nsCOMPtr<nsITimer> mIdleThreadTimer;
static JSSettings sDefaultJSSettings;
static workerinternals::JSSettings sDefaultJSSettings;
public:
struct NavigatorProperties
@ -169,16 +170,16 @@ public:
NoteIdleThread(WorkerThread* aThread);
static void
GetDefaultJSSettings(JSSettings& aSettings)
GetDefaultJSSettings(workerinternals::JSSettings& aSettings)
{
AssertIsOnMainThread();
workers::AssertIsOnMainThread();
aSettings = sDefaultJSSettings;
}
static void
SetDefaultContextOptions(const JS::ContextOptions& aContextOptions)
{
AssertIsOnMainThread();
workers::AssertIsOnMainThread();
sDefaultJSSettings.contextOptions = aContextOptions;
}
@ -200,7 +201,7 @@ public:
static void
SetDefaultJSGCSettings(JSGCParamKey aKey, uint32_t aValue)
{
AssertIsOnMainThread();
workers::AssertIsOnMainThread();
sDefaultJSSettings.ApplyGCSetting(aKey, aValue);
}
@ -211,7 +212,7 @@ public:
static void
SetDefaultGCZeal(uint8_t aGCZeal, uint32_t aFrequency)
{
AssertIsOnMainThread();
workers::AssertIsOnMainThread();
sDefaultJSSettings.gcZeal = aGCZeal;
sDefaultJSSettings.gcZealFrequency = aFrequency;
}
@ -270,7 +271,7 @@ private:
SharedWorker** aSharedWorker);
};
} // workers namespace
} // workerinternals namespace
} // dom namespace
} // mozilla namespace

Просмотреть файл

@ -58,7 +58,8 @@ SharedWorker::Constructor(const GlobalObject& aGlobal,
{
AssertIsOnMainThread();
workers::RuntimeService* rts = workers::RuntimeService::GetOrCreateService();
workerinternals::RuntimeService* rts =
workerinternals::RuntimeService::GetOrCreateService();
if (!rts) {
aRv = NS_ERROR_NOT_AVAILABLE;
return nullptr;

Просмотреть файл

@ -27,13 +27,13 @@ class MessagePort;
class StringOrWorkerOptions;
class WorkerPrivate;
namespace workers {
namespace workerinternals {
class RuntimeService;
}
class SharedWorker final : public DOMEventTargetHelper
{
friend class workers::RuntimeService;
friend class workerinternals::RuntimeService;
typedef mozilla::ErrorResult ErrorResult;
typedef mozilla::dom::GlobalObject GlobalObject;

Просмотреть файл

@ -37,115 +37,6 @@ class WorkerPrivate;
namespace workers {
struct PrivatizableBase
{ };
struct JSSettings
{
enum {
// All the GC parameters that we support.
JSSettings_JSGC_MAX_BYTES = 0,
JSSettings_JSGC_MAX_MALLOC_BYTES,
JSSettings_JSGC_HIGH_FREQUENCY_TIME_LIMIT,
JSSettings_JSGC_LOW_FREQUENCY_HEAP_GROWTH,
JSSettings_JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN,
JSSettings_JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX,
JSSettings_JSGC_HIGH_FREQUENCY_LOW_LIMIT,
JSSettings_JSGC_HIGH_FREQUENCY_HIGH_LIMIT,
JSSettings_JSGC_ALLOCATION_THRESHOLD,
JSSettings_JSGC_SLICE_TIME_BUDGET,
JSSettings_JSGC_DYNAMIC_HEAP_GROWTH,
JSSettings_JSGC_DYNAMIC_MARK_SLICE,
// JSGC_MODE not supported
// This must be last so that we get an accurate count.
kGCSettingsArraySize
};
struct JSGCSetting
{
mozilla::Maybe<JSGCParamKey> key;
uint32_t value;
JSGCSetting()
: key(), value(0)
{ }
};
// There are several settings that we know we need so it makes sense to
// preallocate here.
typedef JSGCSetting JSGCSettingsArray[kGCSettingsArraySize];
// Settings that change based on chrome/content context.
struct JSContentChromeSettings
{
JS::CompartmentOptions compartmentOptions;
int32_t maxScriptRuntime;
JSContentChromeSettings()
: compartmentOptions(), maxScriptRuntime(0)
{ }
};
JSContentChromeSettings chrome;
JSContentChromeSettings content;
JSGCSettingsArray gcSettings;
JS::ContextOptions contextOptions;
#ifdef JS_GC_ZEAL
uint8_t gcZeal;
uint32_t gcZealFrequency;
#endif
JSSettings()
#ifdef JS_GC_ZEAL
: gcZeal(0), gcZealFrequency(0)
#endif
{
for (uint32_t index = 0; index < ArrayLength(gcSettings); index++) {
new (gcSettings + index) JSGCSetting();
}
}
bool
ApplyGCSetting(JSGCParamKey aKey, uint32_t aValue)
{
JSSettings::JSGCSetting* firstEmptySetting = nullptr;
JSSettings::JSGCSetting* foundSetting = nullptr;
for (uint32_t index = 0; index < ArrayLength(gcSettings); index++) {
JSSettings::JSGCSetting& setting = gcSettings[index];
if (setting.key.isSome() && *setting.key == aKey) {
foundSetting = &setting;
break;
}
if (!firstEmptySetting && setting.key.isNothing()) {
firstEmptySetting = &setting;
}
}
if (aValue) {
if (!foundSetting) {
foundSetting = firstEmptySetting;
if (!foundSetting) {
NS_ERROR("Not enough space for this value!");
return false;
}
}
foundSetting->key = mozilla::Some(aKey);
foundSetting->value = aValue;
return true;
}
if (foundSetting) {
foundSetting->key.reset();
return true;
}
return false;
}
};
// All of these are implemented in RuntimeService.cpp
#ifdef DEBUG
@ -198,9 +89,6 @@ IsDebuggerGlobal(JSObject* global);
bool
IsDebuggerSandbox(JSObject* object);
// Random unique constant to facilitate JSPrincipal debugging
const uint32_t kJSPrincipalsDebugToken = 0x7e2df9d2;
} // workers namespace
} // dom namespace
} // mozilla namespace

Просмотреть файл

@ -7,7 +7,7 @@
#ifndef mozilla_dom_workers_WorkerDebugger_h
#define mozilla_dom_workers_WorkerDebugger_h
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "nsIWorkerDebugger.h"
namespace mozilla {

Просмотреть файл

@ -7,7 +7,7 @@
#ifndef mozilla_dom_workers_workerdebuggermanager_h
#define mozilla_dom_workers_workerdebuggermanager_h
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "nsIObserver.h"
#include "nsIWorkerDebuggerManager.h"

Просмотреть файл

@ -7,7 +7,7 @@
#ifndef mozilla_dom_workers_WorkerHolder_h
#define mozilla_dom_workers_WorkerHolder_h
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
namespace mozilla {
namespace dom {

Просмотреть файл

@ -8,7 +8,7 @@
#define mozilla_dom_workers_WorkerLoadInfo_h
#include "mozilla/dom/ChannelInfo.h"
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "nsIInterfaceRequestor.h"
#include "nsILoadContext.h"

Просмотреть файл

@ -25,7 +25,7 @@ class Connection;
class WorkerNavigator final : public nsWrapperCache
{
typedef struct workers::RuntimeService::NavigatorProperties NavigatorProperties;
typedef struct workerinternals::RuntimeService::NavigatorProperties NavigatorProperties;
NavigatorProperties mProperties;
RefPtr<StorageManager> mStorageManager;

Просмотреть файл

@ -95,6 +95,7 @@ TimeoutsLog()
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::dom::workers;
using namespace mozilla::dom::workerinternals;
using namespace mozilla::ipc;
MOZ_DEFINE_MALLOC_SIZE_OF(JsWorkerMallocSizeOf)
@ -241,7 +242,7 @@ private:
NS_WARNING("Failed to dispatch, going to leak!");
}
workers::RuntimeService* runtime = workers::RuntimeService::GetService();
RuntimeService* runtime = RuntimeService::GetService();
NS_ASSERTION(runtime, "This should never be null!");
mFinishedWorker->DisableDebugger();
@ -273,9 +274,9 @@ private:
NS_IMETHOD
Run() override
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
workers::RuntimeService* runtime = workers::RuntimeService::GetService();
RuntimeService* runtime = RuntimeService::GetService();
MOZ_ASSERT(runtime);
mFinishedWorker->DisableDebugger();
@ -555,7 +556,7 @@ public:
if (aWorkerPrivate) {
aWorkerPrivate->AssertIsOnWorkerThread();
} else {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
}
// Now fire a runnable to do the same on the parent's thread if we can.
@ -1213,7 +1214,7 @@ private:
~FinishCollectRunnable()
{
// mHandleReport and mHandlerData are released on the main thread.
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
}
FinishCollectRunnable(const FinishCollectRunnable&) = delete;
@ -1247,7 +1248,7 @@ WorkerPrivate::MemoryReporter::CollectReports(nsIHandleReportCallback* aHandleRe
nsISupports* aData,
bool aAnonymize)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
RefPtr<CollectReportsRunnable> runnable;
@ -1299,7 +1300,7 @@ WorkerPrivate::MemoryReporter::CollectReports(nsIHandleReportCallback* aHandleRe
void
WorkerPrivate::MemoryReporter::TryToMapAddon(nsACString &path)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
mMutex.AssertCurrentThreadOwns();
if (mAlreadyMappedToAddon || !mWorkerPrivate) {
@ -1388,7 +1389,7 @@ WorkerPrivate::MemoryReporter::FinishCollectRunnable::FinishCollectRunnable(
NS_IMETHODIMP
WorkerPrivate::MemoryReporter::FinishCollectRunnable::Run()
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
nsCOMPtr<nsIMemoryReporterManager> manager =
do_GetService("@mozilla.org/memory-reporter-manager;1");
@ -1441,7 +1442,7 @@ template <class Derived>
nsIDocument*
WorkerPrivateParent<Derived>::GetDocument() const
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
if (mLoadInfo.mWindow) {
return mLoadInfo.mWindow->GetExtantDoc();
}
@ -1462,7 +1463,7 @@ template <class Derived>
void
WorkerPrivateParent<Derived>::SetCSP(nsIContentSecurityPolicy* aCSP)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
if (!aCSP) {
return;
}
@ -1476,7 +1477,7 @@ nsresult
WorkerPrivateParent<Derived>::SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue,
const nsACString& aCSPReportOnlyHeaderValue)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
MOZ_DIAGNOSTIC_ASSERT(!mLoadInfo.mCSP);
NS_ConvertASCIItoUTF16 cspHeaderValue(aCSPHeaderValue);
@ -1576,7 +1577,7 @@ WorkerPrivateParent<Derived>::WorkerPrivateParent(
MOZ_ASSERT_IF(!IsDedicatedWorker(), NS_IsMainThread());
if (aLoadInfo.mWindow) {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
BindToOwner(aLoadInfo.mWindow);
}
@ -1600,9 +1601,9 @@ WorkerPrivateParent<Derived>::WorkerPrivateParent(
}
}
else {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
workers::RuntimeService::GetDefaultJSSettings(mJSSettings);
RuntimeService::GetDefaultJSSettings(mJSSettings);
// Our secure context state depends on the kind of worker we have.
if (UsesSystemPrincipal() || IsServiceWorker()) {
@ -1866,7 +1867,7 @@ WorkerPrivateParent<Derived>::NotifyPrivate(WorkerStatus aStatus)
}
if (IsSharedWorker()) {
workers::RuntimeService* runtime = workers::RuntimeService::GetService();
RuntimeService* runtime = RuntimeService::GetService();
MOZ_ASSERT(runtime);
runtime->ForgetSharedWorker(ParentAsWorkerPrivate());
@ -1914,7 +1915,7 @@ WorkerPrivateParent<Derived>::Freeze(nsPIDOMWindowInner* aWindow)
// frozen. It can happen that mSharedWorkers is empty but this thread has
// not been unregistered yet.
if ((IsSharedWorker() || IsServiceWorker()) && !mSharedWorkers.IsEmpty()) {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
bool allFrozen = true;
@ -1973,7 +1974,7 @@ WorkerPrivateParent<Derived>::Thaw(nsPIDOMWindowInner* aWindow)
// It can happen that mSharedWorkers is empty but this thread has not been
// unregistered yet.
if ((IsSharedWorker() || IsServiceWorker()) && !mSharedWorkers.IsEmpty()) {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
bool anyRunning = false;
@ -2040,7 +2041,7 @@ template <class Derived>
void
WorkerPrivateParent<Derived>::ParentWindowPaused()
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
MOZ_ASSERT_IF(IsDedicatedWorker(), mParentWindowPausedDepth == 0);
mParentWindowPausedDepth += 1;
}
@ -2049,7 +2050,7 @@ template <class Derived>
void
WorkerPrivateParent<Derived>::ParentWindowResumed()
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
MOZ_ASSERT(mParentWindowPausedDepth > 0);
MOZ_ASSERT_IF(IsDedicatedWorker(), mParentWindowPausedDepth == 1);
@ -2385,7 +2386,7 @@ bool
WorkerPrivateParent<Derived>::RegisterSharedWorker(SharedWorker* aSharedWorker,
MessagePort* aPort)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
MOZ_ASSERT(aSharedWorker);
MOZ_ASSERT(IsSharedWorker());
MOZ_ASSERT(!mSharedWorkers.Contains(aSharedWorker));
@ -2416,7 +2417,7 @@ WorkerPrivateParent<Derived>::BroadcastErrorToSharedWorkers(
const WorkerErrorReport* aReport,
bool aIsErrorEvent)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
if (aIsErrorEvent && JSREPORT_IS_WARNING(aReport->mFlags)) {
// Don't fire any events anywhere. Just log to console.
@ -2550,7 +2551,7 @@ void
WorkerPrivateParent<Derived>::GetAllSharedWorkers(
nsTArray<RefPtr<SharedWorker>>& aSharedWorkers)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
MOZ_ASSERT(IsSharedWorker() || IsServiceWorker());
if (!aSharedWorkers.IsEmpty()) {
@ -2567,7 +2568,7 @@ void
WorkerPrivateParent<Derived>::CloseSharedWorkersForWindow(
nsPIDOMWindowInner* aWindow)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
MOZ_ASSERT(IsSharedWorker() || IsServiceWorker());
MOZ_ASSERT(aWindow);
@ -2604,7 +2605,7 @@ template <class Derived>
void
WorkerPrivateParent<Derived>::CloseAllSharedWorkers()
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
MOZ_ASSERT(IsSharedWorker() || IsServiceWorker());
for (uint32_t i = 0; i < mSharedWorkers.Length(); ++i) {
@ -2620,7 +2621,7 @@ template <class Derived>
void
WorkerPrivateParent<Derived>::WorkerScriptLoaded()
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
if (IsSharedWorker() || IsServiceWorker()) {
// No longer need to hold references to the window or document we came from.
@ -2633,7 +2634,7 @@ template <class Derived>
void
WorkerPrivateParent<Derived>::SetBaseURI(nsIURI* aBaseURI)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
if (!mLoadInfo.mBaseURI) {
NS_ASSERTION(GetParent(), "Shouldn't happen without a parent!");
@ -2727,7 +2728,7 @@ template <class Derived>
void
WorkerPrivateParent<Derived>::UpdateOverridenLoadGroup(nsILoadGroup* aBaseLoadGroup)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
// The load group should have been overriden at init time.
mLoadInfo.mInterfaceRequestor->MaybeAddTabChild(aBaseLoadGroup);
@ -2738,7 +2739,7 @@ void
WorkerPrivateParent<Derived>::FlushReportsToSharedWorkers(
nsIConsoleReportCollector* aReporter)
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
AutoTArray<RefPtr<SharedWorker>, 10> sharedWorkers;
AutoTArray<WindowAction, 10> windowActions;
@ -2831,7 +2832,7 @@ WorkerPrivateParent<Derived>::AssertIsOnParentThread() const
GetParent()->AssertIsOnWorkerThread();
}
else {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
}
}
@ -2846,7 +2847,7 @@ WorkerPrivateParent<Derived>::AssertInnerWindowIsCorrect() const
return;
}
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
nsPIDOMWindowOuter* outer = mLoadInfo.mWindow->GetOuterWindow();
NS_ASSERTION(outer && outer->GetCurrentInnerWindow() == mLoadInfo.mWindow,
@ -2904,7 +2905,7 @@ WorkerPrivate::WorkerPrivate(WorkerPrivate* aParent,
mOnLine = aParent->OnLine();
}
else {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
mOnLine = !NS_IsOffline();
}
@ -3048,7 +3049,7 @@ WorkerPrivate::Constructor(JSContext* aCx,
return nullptr;
}
} else {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
}
Maybe<WorkerLoadInfo> stackLoadInfo;
@ -3070,17 +3071,17 @@ WorkerPrivate::Constructor(JSContext* aCx,
// NB: This has to be done before creating the WorkerPrivate, because it will
// attempt to use static variables that are initialized in the RuntimeService
// constructor.
workers::RuntimeService* runtimeService;
RuntimeService* runtimeService;
if (!parent) {
runtimeService = workers::RuntimeService::GetOrCreateService();
runtimeService = RuntimeService::GetOrCreateService();
if (!runtimeService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
}
else {
runtimeService = workers::RuntimeService::GetService();
runtimeService = RuntimeService::GetService();
}
MOZ_ASSERT(runtimeService);
@ -3138,7 +3139,7 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
MOZ_ASSERT_IF(NS_IsMainThread(), aCx == nsContentUtils::GetCurrentJSContext());
if (aWindow) {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
}
WorkerLoadInfo loadInfo;
@ -3188,7 +3189,7 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
aParent->ServiceWorkersTestingInWindow();
loadInfo.mParentController = aParent->GetController();
} else {
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
// Make sure that the IndexedDatabaseManager is set up
Unused << NS_WARN_IF(!IndexedDatabaseManager::GetOrCreate());
@ -5535,7 +5536,7 @@ WorkerPrivate::DumpCrashInformation(nsACString& aString)
PerformanceStorage*
WorkerPrivate::GetPerformanceStorage()
{
workers::AssertIsOnMainThread();
AssertIsOnMainThread();
if (!mPerformanceStorage) {
mPerformanceStorage = PerformanceStorageWorker::Create(this);

Просмотреть файл

@ -7,7 +7,7 @@
#ifndef mozilla_dom_workers_workerprivate_h__
#define mozilla_dom_workers_workerprivate_h__
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/CondVar.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "nsDOMNavigationTiming.h"
@ -18,7 +18,8 @@
#include "mozilla/dom/WorkerHolder.h"
#include "mozilla/dom/WorkerLoadInfo.h"
#include "mozilla/dom/workers/Queue.h"
#include "mozilla/dom/workerinternals/JSSettings.h"
#include "mozilla/dom/workerinternals/Queue.h"
#ifdef XP_WIN
#undef PostMessage
@ -144,7 +145,7 @@ private:
nsTArray<nsCOMPtr<nsIRunnable>> mQueuedRunnables;
// Protected by mMutex.
workers::JSSettings mJSSettings;
workerinternals::JSSettings mJSSettings;
// Only touched on the parent thread (currently this is always the main
// thread as SharedWorkers are always top-level).
@ -707,7 +708,7 @@ public:
}
void
CopyJSSettings(workers::JSSettings& aSettings)
CopyJSSettings(workerinternals::JSSettings& aSettings)
{
mozilla::MutexAutoLock lock(mMutex);
aSettings = mJSSettings;
@ -889,8 +890,8 @@ class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
bool mDebuggerRegistered;
WorkerDebugger* mDebugger;
workersinternals::Queue<WorkerControlRunnable*, 4> mControlQueue;
workersinternals::Queue<WorkerRunnable*, 4> mDebuggerQueue;
workerinternals::Queue<WorkerControlRunnable*, 4> mControlQueue;
workerinternals::Queue<WorkerRunnable*, 4> mDebuggerQueue;
// Touched on multiple threads, protected with mMutex.
JSContext* mJSContext;

Просмотреть файл

@ -7,7 +7,7 @@
#ifndef mozilla_dom_workers_workerrunnable_h__
#define mozilla_dom_workers_workerrunnable_h__
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerHolder.h"
#include "nsICancelableRunnable.h"

Просмотреть файл

@ -7,7 +7,7 @@
#ifndef mozilla_dom_workerscope_h__
#define mozilla_dom_workerscope_h__
#include "mozilla/dom/workers/WorkerCommon.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/Headers.h"
#include "mozilla/dom/RequestBinding.h"

Просмотреть файл

@ -23,7 +23,7 @@ class WorkerRunnable;
class WorkerPrivate;
template <class> class WorkerPrivateParent;
namespace workers {
namespace workerinternals {
class RuntimeService;
}
@ -32,7 +32,7 @@ class RuntimeService;
// full access to private methods (as would happen if they were simply friends).
class WorkerThreadFriendKey
{
friend class workers::RuntimeService;
friend class workerinternals::RuntimeService;
friend class WorkerPrivate;
friend class WorkerPrivateParent<WorkerPrivate>;

Просмотреть файл

@ -10,6 +10,7 @@ with Files("**"):
# Public stuff.
EXPORTS.mozilla.dom += [
'SharedWorker.h',
'WorkerCommon.h',
'WorkerDebugger.h',
'WorkerDebuggerManager.h',
'WorkerHolder.h',
@ -22,10 +23,11 @@ EXPORTS.mozilla.dom += [
'WorkerScope.h',
]
EXPORTS.mozilla.dom.workers += [
# Private stuff.
EXPORTS.mozilla.dom.workerinternals += [
'JSSettings.h',
'Queue.h',
'RuntimeService.h',
'WorkerCommon.h',
]
XPIDL_MODULE = 'dom_workers'