Name Description Size
CacheLoadHandler.cpp force trusted origin 21187
CacheLoadHandler.h [DOMDOC] CacheLoadHandler for Workers A LoadHandler is a ScriptLoader helper class that reacts to an nsIStreamLoader's events for loading JS scripts. It is primarily responsible for decoding the stream into UTF8 or UTF16. Additionally, it takes care of any work that needs to follow the completion of a stream. Every LoadHandler also manages additional tasks for the type of load that it is doing. CacheLoadHandler is a specialized LoadHandler used by ServiceWorkers to implement the installation model used by ServiceWorkers to support running offline. When a ServiceWorker is installed, its main script is evaluated and all script resources that are loaded are saved. The spec does not specify the storage mechanism for this, but we chose to reuse the Cache API[1] mechanism that we expose to content to also store the script and its dependencies. We store the script resources in a special chrome namespace CacheStorage that is not visible to content. Each distinct ServiceWorker installation gets its own Cache keyed by a randomly-generated UUID. In terms of specification, this class implements step 4 of https://w3c.github.io/ServiceWorker/#importscripts Relationship to NetworkLoadHandler During ServiceWorker installation, the CacheLoadHandler falls back on the NetworkLoadHandler by calling `mLoader->LoadScript(...)`. If a script has not been seen before, then we will fall back on loading from the network. However, if the ServiceWorker is already installed, an error will be generated and the ServiceWorker will fail to load, per spec. CacheLoadHandler does not persist some pieces of information, such as the sourceMapUrl. Also, the DOM Cache API storage does not yet support alternate data streams for JS Bytecode or WASM caching; this is tracked by Bug 1336199. [1]: https://developer.mozilla.org/en-US/docs/Web/API/caches 7874
moz.build 862
NetworkLoadHandler.cpp 14797
NetworkLoadHandler.h [DOMDOC] NetworkLoadHandler for Workers A LoadHandler is a ScriptLoader helper class that reacts to an nsIStreamLoader's events for loading JS scripts. It is primarily responsible for decoding the stream into UTF8 or UTF16. Additionally, it takes care of any work that needs to follow the completion of a stream. Every LoadHandler also manages additional tasks for the type of load that it is doing. As part of worker loading we have an number of tasks that we need to take care of after a successfully completed stream, including setting a final URI on the WorkerPrivate if we have loaded a main script, or handling CSP issues. These are handled in DataReceivedFromNetwork, and implement roughly the same set of tasks as you will find in the CacheLoadhandler, which has a companion method DataReceivedFromcache. In the worker context, the LoadHandler is run on the main thread, and all work in this file ultimately is done by the main thread, including decoding. 2890
ScriptResponseHeaderProcessor.cpp 2619
ScriptResponseHeaderProcessor.h ScriptResponseHeaderProcessor This class handles Policy headers. It can be used as a RequestObserver in a Tee, as it is for NetworkLoadHandler in WorkerScriptLoader, or the static method can be called directly, as it is in CacheLoadHandler. 2760
WorkerLoadContext.cpp 2867
WorkerLoadContext.h WorkerLoadContext (for all workers) LoadContexts augment the loading of a ScriptLoadRequest. They describe how a ScriptLoadRequests loading and evaluation needs to be augmented, based on the information provided by the loading context. The WorkerLoadContext has the following generic fields applied to all worker ScriptLoadRequests (and primarily used for error handling): * mMutedErrorFlag Set when we finish loading a script, and used to determine whether a given error is thrown or muted. * mLoadResult In order to report errors correctly in the worker thread, we need to move them from the main thread to the worker. This field records the load error, for throwing when we return to the worker thread. * mKind See documentation of WorkerLoadContext::Kind. * mClientInfo A snapshot of a global living in the system (see documentation for ClientInfo). In worker loading, this field is important for CSP information and knowing what to intercept for Service Worker interception. * mChannel The channel used by this request for it's load. Used for cancellation, in order to cancel the stream. The rest of the fields on this class focus on enabling the ServiceWorker usecase, in particular -- using the Cache API to store the worker so that in the case of (for example) a page refresh, the service worker itself is persisted so that it can do other work. For more details see the CacheLoadHandler.h file. 7514
WorkerModuleLoader.cpp is top level 9017
WorkerModuleLoader.h 3221