/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ /* vim: set ts=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/. */ #include "WorkerPrivate.h" #include "amIAddonManager.h" #include "nsIClassInfo.h" #include "nsIContentSecurityPolicy.h" #include "nsIConsoleService.h" #include "nsIDOMDOMException.h" #include "nsIDOMEvent.h" #include "nsIDOMFile.h" #include "nsIDOMMessageEvent.h" #include "nsIDocument.h" #include "nsIDocShell.h" #include "nsIMemoryReporter.h" #include "nsIPermissionManager.h" #include "nsIScriptError.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptSecurityManager.h" #include "nsPIDOMWindow.h" #include "nsITextToSubURI.h" #include "nsIThreadInternal.h" #include "nsITimer.h" #include "nsIURI.h" #include "nsIURL.h" #include "nsIXPConnect.h" #include #include "jsfriendapi.h" #include "js/OldDebugAPI.h" #include "js/MemoryMetrics.h" #include "mozilla/Assertions.h" #include "mozilla/ContentEvents.h" #include "mozilla/EventDispatcher.h" #include "mozilla/Likely.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/ErrorEvent.h" #include "mozilla/dom/ErrorEventBinding.h" #include "mozilla/dom/Exceptions.h" #include "mozilla/dom/FunctionBinding.h" #include "mozilla/dom/ImageData.h" #include "mozilla/dom/ImageDataBinding.h" #include "mozilla/dom/MessageEvent.h" #include "mozilla/dom/MessageEventBinding.h" #include "mozilla/dom/MessagePortList.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/StructuredClone.h" #include "mozilla/dom/WorkerBinding.h" #include "mozilla/Preferences.h" #include "nsAlgorithm.h" #include "nsContentUtils.h" #include "nsError.h" #include "nsDOMJSUtils.h" #include "nsHostObjectProtocolHandler.h" #include "nsJSEnvironment.h" #include "nsJSUtils.h" #include "nsNetUtil.h" #include "nsPrintfCString.h" #include "nsProxyRelease.h" #include "nsSandboxFlags.h" #include "xpcpublic.h" #ifdef ANDROID #include #endif #ifdef DEBUG #include "nsThreadManager.h" #endif #include "File.h" #include "MessagePort.h" #include "Navigator.h" #include "Principal.h" #include "RuntimeService.h" #include "ScriptLoader.h" #include "ServiceWorkerManager.h" #include "SharedWorker.h" #include "WorkerFeature.h" #include "WorkerRunnable.h" #include "WorkerScope.h" // JS_MaybeGC will run once every second during normal execution. #define PERIODIC_GC_TIMER_DELAY_SEC 1 // A shrinking GC will run five seconds after the last event is processed. #define IDLE_GC_TIMER_DELAY_SEC 5 #define PREF_WORKERS_ENABLED "dom.workers.enabled" #ifdef WORKER_LOGGING #define LOG(_args) do { printf _args ; fflush(stdout); } while (0) #else #define LOG(_args) do { } while (0) #endif using namespace mozilla; using namespace mozilla::dom; USING_WORKERS_NAMESPACE MOZ_DEFINE_MALLOC_SIZE_OF(JsWorkerMallocSizeOf) #ifdef DEBUG BEGIN_WORKERS_NAMESPACE void AssertIsOnMainThread() { MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); } END_WORKERS_NAMESPACE #endif namespace { #ifdef DEBUG const nsIID kDEBUGWorkerEventTargetIID = { 0xccaba3fa, 0x5be2, 0x4de2, { 0xba, 0x87, 0x3b, 0x3b, 0x5b, 0x1d, 0x5, 0xfb } }; #endif template class AutoPtrComparator { typedef nsAutoPtr A; typedef T* B; public: bool Equals(const A& a, const B& b) const { return a && b ? *a == *b : !a && !b ? true : false; } bool LessThan(const A& a, const B& b) const { return a && b ? *a < *b : b ? true : false; } }; template inline AutoPtrComparator GetAutoPtrComparator(const nsTArray >&) { return AutoPtrComparator(); } // Specialize this if there's some class that has multiple nsISupports bases. template struct ISupportsBaseInfo { typedef T ISupportsBase; }; template