diff --git a/dom/workers/WorkerPrefs.h b/dom/workers/WorkerPrefs.h index 415435cf06..31a00e4290 100644 --- a/dom/workers/WorkerPrefs.h +++ b/dom/workers/WorkerPrefs.h @@ -26,6 +26,7 @@ WORKER_SIMPLE_PREF("browser.dom.window.dump.enabled", DumpEnabled, DUMP) WORKER_SIMPLE_PREF("canvas.imagebitmap_extensions.enabled", ImageBitmapExtensionsEnabled, IMAGEBITMAP_EXTENSIONS_ENABLED) WORKER_SIMPLE_PREF("dom.caches.enabled", DOMCachesEnabled, DOM_CACHES) WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CACHES_TESTING) +WORKER_SIMPLE_PREF("dom.min_timeout_value", DOMMinTimoutValue, DOM_MIN_TIMEOUT_VALUE) WORKER_SIMPLE_PREF("dom.performance.enable_user_timing_logging", PerformanceLoggingEnabled, PERFORMANCE_LOGGING_ENABLED) WORKER_SIMPLE_PREF("dom.webnotifications.enabled", DOMWorkerNotificationEnabled, DOM_WORKERNOTIFICATION) WORKER_SIMPLE_PREF("dom.webnotifications.serviceworker.enabled", DOMServiceWorkerNotificationEnabled, DOM_SERVICEWORKERNOTIFICATION) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 7a0c272f56..35d8dd744b 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1995,13 +1995,27 @@ struct WorkerPrivate::TimeoutInfo mNestingLevel = kClampTimeoutNestingLevel; } - void CalculateTargetTime() { + void CalculateTargetTime(JSContext* aCx) { auto target = mInterval; + int32_t minTimeoutValue; + + if (NS_IsMainThread()) { + // We can get the pref value directly. + minTimeoutValue = Preferences::GetInt("dom.min_timeout_value"); + } else { + // We're on a worker thread; go through WorkerPrivate. + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (workerPrivate) { + minTimeoutValue = workerPrivate->DOMMinTimoutValue(); + } else { + // fall back to default 4 ms + minTimeoutValue = 4; + } + } + // Clamp timeout for workers, except chrome workers if (mNestingLevel >= kClampTimeoutNestingLevel && !mOnChromeWorker) { - target = TimeDuration::Max( - mInterval, - TimeDuration::FromMilliseconds(Preferences::GetInt("dom.min_timeout_value"))); + target = TimeDuration::Max(mInterval,TimeDuration::FromMilliseconds(minTimeoutValue)); } mTargetTime = TimeStamp::Now() + target; } @@ -6387,7 +6401,7 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx) // Reschedule intervals. // Reschedule a timeout and, if needed, increase the nesting level. info->AccumulateNestingLevel(info->mNestingLevel); - info->CalculateTargetTime(); + info->CalculateTargetTime(aCx); // Don't re-sort the list here, we'll do that at the end. ++index; }