/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Helper dictionaries, which will contain data specific to each resource type. // - `path` is the absolute path to the module defining the Resource Watcher class. // // Also see the attributes added by `augmentResourceDictionary` for each type: // - `watchers` is a weak map which will store Resource Watchers // (i.e. devtools/server/actors/resources/ class instances) // keyed by target actor -or- watcher actor. // - `WatcherClass` is a shortcut to the Resource Watcher module. // Each module exports a Resource Watcher class. // // These are several dictionaries, which depend how the resource watcher classes are instantiated.
// Frame target resources are spawned via a BrowsingContext Target Actor. // Their watcher class receives a target actor as first argument. // They are instantiated for each observed BrowsingContext, from the content process where it runs. // They are meant to observe all resources related to a given Browsing Context. const FrameTargetResources = augmentResourceDictionary({
[TYPES.CACHE_STORAGE]: {
path: "devtools/server/actors/resources/storage-cache",
},
[TYPES.CONSOLE_MESSAGE]: {
path: "devtools/server/actors/resources/console-messages",
},
[TYPES.CSS_CHANGE]: {
path: "devtools/server/actors/resources/css-changes",
},
[TYPES.CSS_MESSAGE]: {
path: "devtools/server/actors/resources/css-messages",
},
[TYPES.CSS_REGISTERED_PROPERTIES]: {
path: "devtools/server/actors/resources/css-registered-properties",
},
[TYPES.DOCUMENT_EVENT]: {
path: "devtools/server/actors/resources/document-event",
},
[TYPES.ERROR_MESSAGE]: {
path: "devtools/server/actors/resources/error-messages",
},
[TYPES.JSTRACER_STATE]: {
path: "devtools/server/actors/resources/jstracer-state",
},
[TYPES.JSTRACER_TRACE]: {
path: "devtools/server/actors/resources/jstracer-trace",
},
[TYPES.LOCAL_STORAGE]: {
path: "devtools/server/actors/resources/storage-local-storage",
},
[TYPES.PLATFORM_MESSAGE]: {
path: "devtools/server/actors/resources/platform-messages",
},
[TYPES.SESSION_STORAGE]: {
path: "devtools/server/actors/resources/storage-session-storage",
},
[TYPES.STYLESHEET]: {
path: "devtools/server/actors/resources/stylesheets",
},
[TYPES.NETWORK_EVENT]: {
path: "devtools/server/actors/resources/network-events-content",
},
[TYPES.NETWORK_EVENT_DECODED_BODY_SIZE]: {
path: "devtools/server/actors/resources/network-events-decoded-body-size",
},
[TYPES.NETWORK_EVENT_STACKTRACE]: {
path: "devtools/server/actors/resources/network-events-stacktraces",
},
[TYPES.REFLOW]: {
path: "devtools/server/actors/resources/reflow",
},
[TYPES.SOURCE]: {
path: "devtools/server/actors/resources/sources",
},
[TYPES.THREAD_STATE]: {
path: "devtools/server/actors/resources/thread-states",
},
[TYPES.SERVER_SENT_EVENT]: {
path: "devtools/server/actors/resources/server-sent-events",
},
[TYPES.WEBSOCKET]: {
path: "devtools/server/actors/resources/websockets",
},
[TYPES.WEBTRANSPORT]: {
path: "devtools/server/actors/resources/webtransport",
},
});
// Process target resources are spawned via a Process Target Actor. // Their watcher class receives a process target actor as first argument. // They are instantiated for each observed Process (parent and all content processes). // They are meant to observe all resources related to a given process. const ProcessTargetResources = augmentResourceDictionary({
[TYPES.CONSOLE_MESSAGE]: {
path: "devtools/server/actors/resources/console-messages",
},
[TYPES.JSTRACER_TRACE]: {
path: "devtools/server/actors/resources/jstracer-trace",
},
[TYPES.JSTRACER_STATE]: {
path: "devtools/server/actors/resources/jstracer-state",
},
[TYPES.ERROR_MESSAGE]: {
path: "devtools/server/actors/resources/error-messages",
},
[TYPES.PLATFORM_MESSAGE]: {
path: "devtools/server/actors/resources/platform-messages",
},
[TYPES.SOURCE]: {
path: "devtools/server/actors/resources/sources",
},
[TYPES.THREAD_STATE]: {
path: "devtools/server/actors/resources/thread-states",
},
});
// Worker target resources are spawned via a Worker Target Actor. // Their watcher class receives a worker target actor as first argument. // They are instantiated for each observed worker, from the worker thread. // They are meant to observe all resources related to a given worker. // // We'll only support a few resource types in Workers (console-message, source, // thread state, …) as error and platform messages are not supported since we need access // to Ci, which isn't available in worker context. // Errors are emitted from the content process main thread so the user would still get them. const WorkerTargetResources = augmentResourceDictionary({
[TYPES.CONSOLE_MESSAGE]: {
path: "devtools/server/actors/resources/console-messages",
},
[TYPES.JSTRACER_TRACE]: {
path: "devtools/server/actors/resources/jstracer-trace",
},
[TYPES.JSTRACER_STATE]: {
path: "devtools/server/actors/resources/jstracer-state",
},
[TYPES.SOURCE]: {
path: "devtools/server/actors/resources/sources",
},
[TYPES.THREAD_STATE]: {
path: "devtools/server/actors/resources/thread-states",
},
});
// Web Extension Content Script resources are spawn for each content script, // from the web page's main thread it relates to. // // Similarly to workers, it doesn't relate to any DOM Document, // but only a JavaScript context. So it only expose a subset of resources. const WebExtensionContentScriptTargetResources = augmentResourceDictionary({
[TYPES.CONSOLE_MESSAGE]: {
path: "devtools/server/actors/resources/console-messages",
},
[TYPES.JSTRACER_TRACE]: {
path: "devtools/server/actors/resources/jstracer-trace",
},
[TYPES.JSTRACER_STATE]: {
path: "devtools/server/actors/resources/jstracer-state",
},
[TYPES.SOURCE]: {
path: "devtools/server/actors/resources/sources",
},
[TYPES.THREAD_STATE]: {
path: "devtools/server/actors/resources/thread-states",
},
});
// Parent process resources are spawned via the Watcher Actor. // Their watcher class receives the watcher actor as first argument. // They are instantiated once per watcher from the parent process. // They are meant to observe all resources related to a given context designated by the Watcher (and its sessionContext) // they should be observed from the parent process. const ParentProcessResources = augmentResourceDictionary({
[TYPES.NETWORK_EVENT]: {
path: "devtools/server/actors/resources/network-events",
},
[TYPES.COOKIE]: {
path: "devtools/server/actors/resources/storage-cookie",
},
[TYPES.EXTENSION_STORAGE]: {
path: "devtools/server/actors/resources/storage-extension",
},
[TYPES.INDEXED_DB]: {
path: "devtools/server/actors/resources/storage-indexed-db",
},
[TYPES.DOCUMENT_EVENT]: {
path: "devtools/server/actors/resources/parent-process-document-event",
},
[TYPES.LAST_PRIVATE_CONTEXT_EXIT]: {
path: "devtools/server/actors/resources/last-private-context-exit",
},
[TYPES.SESSION_HISTORY]: {
path: "devtools/server/actors/resources/session-history",
},
});
// Root resources are spawned via the Root Actor. // Their watcher class receives the root actor as first argument. // They are instantiated only once from the parent process. // They are meant to observe anything easily observable from the parent process // that isn't related to any particular context/target. // This is especially useful when you need to observe something without having to instantiate a Watcher actor. const RootResources = augmentResourceDictionary({
[TYPES.EXTENSIONS_BGSCRIPT_STATUS]: {
path: "devtools/server/actors/resources/extensions-backgroundscript-status",
},
});
exports.RootResources = RootResources;
function augmentResourceDictionary(dict) { for (const resource of Object.values(dict)) {
resource.watchers = new WeakMap();
/** *ForatargetType,returntherelateddictionary. * *@paramStringtargetType *AtargetTypestring(SeeTargets.TYPES)
*/ function getResourceTypeDictionaryForTargetType(targetType) { switch (targetType) { case Targets.TYPES.FRAME: return FrameTargetResources; case Targets.TYPES.PROCESS: return ProcessTargetResources; case Targets.TYPES.WORKER: return WorkerTargetResources; case Targets.TYPES.SERVICE_WORKER: return WorkerTargetResources; case Targets.TYPES.SHARED_WORKER: return WorkerTargetResources; case Targets.TYPES.CONTENT_SCRIPT: return WebExtensionContentScriptTargetResources; default: thrownew Error(`Unsupported target actor typeName '${targetType}'`);
}
}
/** *Foragivenactor,returntheobjectstoredinoneofthepreviousdictionary *thatcontainsinfoabouthowtolistenforagivenresourcetype,fromagivenactor. * *@paramActorrootOrWatcherOrTargetActor *EitheraRootActororWatcherActororaTargetActorwhichcanbelisteningtoaresource. *@paramStringresourceType *Theresourcetypetobeobserved.
*/ function getResourceTypeEntry(rootOrWatcherOrTargetActor, resourceType) { const dict = getResourceTypeDictionary(rootOrWatcherOrTargetActor); if (!(resourceType in dict)) { thrownew Error(
`Unsupported resource type '${resourceType}'for ${rootOrWatcherOrTargetActor.typeName}`
);
} return dict[resourceType];
}
/** *Startwatchingforanewlistofresourcetypes. *Thiswillalsoemitallalreadyexistingresourcesbeforeresolving. * *@paramActorrootOrWatcherOrTargetActor *EitheraRootActororWatcherActororaTargetActorwhichcanbelisteningtoaresource: **RootActorwillbeusedforresourcesobservedfromtheparentprocessandaren'trelatedtoanyparticular *context/descriptor.TheycanbeobservedrightawaywhenconnectingtotheRDPserver *withoutinstantiatinganyactorotherthantherootactor. **WatcherActorwillbeusedforresourceslistenedfromtheparentprocess. **TargetActorwillbeusedforresourceslistenedfromthecontentprocess. *Thisactor: *-defineswhatcontexttoobserve(browsingcontext,process,worker,...) *ViabrowsingContextID,windows,docShellsattributesforthetargetactor. *Viathe`sessionContext`objectforthewatcheractor. *(onlyforWatcherandTargetactors.Rootactoriscontext-less.) *-exposes`notifyResources`methodtobenotifiedaboutalltheresourcesupdates *Thismethodwillreceivetwoarguments: *-{String}updateType,whichcanbe"available","updated",or"destroyed" *-{Array<Object>}resources,whichwillbethelistofresource'sforms *orspecialupdateobjectfor"updated"scenario. *@paramArray<String>resourceTypes *Listofalltypeofresourcetolistento.
*/
async function watchResources(rootOrWatcherOrTargetActor, resourceTypes) { // If we are given a target actor, filter out the resource types supported by the target. // When using sharedData to pass types between processes, we are passing them for all target types. const { targetType } = rootOrWatcherOrTargetActor; // Only target actors usecase will have a target type. // For Root and Watcher we process the `resourceTypes` list unfiltered. if (targetType) {
resourceTypes = getResourceTypesForTargetType(resourceTypes, targetType);
} const promises = []; for (const resourceType of resourceTypes) { const { watchers, WatcherClass } = getResourceTypeEntry(
rootOrWatcherOrTargetActor,
resourceType
);
// Ignore resources we're already listening to if (watchers.has(rootOrWatcherOrTargetActor)) { continue;
}
// Don't watch for console messages from the worker target if worker messages are still // being cloned to the main process, otherwise we'll get duplicated messages in the // console output (See Bug 1778852). if (
resourceType == TYPES.CONSOLE_MESSAGE &&
rootOrWatcherOrTargetActor.workerConsoleApiMessagesDispatchedToMainThread
) { continue;
}
// Force sending resources to the client before we resolve. // So that resources are received by the client // before WatcherActor.watchResources resolves. // This is important when ResourceCommand.watchResources's `ignoreExistingResources` flag is set to false (default behavior). // The client code expects all resources to be emitted when this server method resolves. if (rootOrWatcherOrTargetActor.emitResources) {
rootOrWatcherOrTargetActor.emitResources();
}
}
exports.watchResources = watchResources;
function getParentProcessResourceTypes(resourceTypes) { return resourceTypes.filter(resourceType => { return resourceType in ParentProcessResources;
});
}
exports.getParentProcessResourceTypes = getParentProcessResourceTypes;
function hasResourceTypesForTargets(resourceTypes) { return resourceTypes.some(resourceType => { return resourceType in FrameTargetResources;
});
}
exports.hasResourceTypesForTargets = hasResourceTypesForTargets;
/** *Stopwatchingforalistofresourcetypes. * *@paramActorrootOrWatcherOrTargetActor *Therelatedactor,alreadypassedtowatchResources. *@paramArray<String>resourceTypes *Listofalltypeofresourcetostoplisteningto.
*/ function unwatchResources(rootOrWatcherOrTargetActor, resourceTypes) { // If we are given a target actor, filter out the resource types supported by the target. // When using sharedData to pass types between processes, we are passing them for all target types. const { targetType } = rootOrWatcherOrTargetActor; // Only target actors usecase will have a target type. // For Root and Watcher we process the `resourceTypes` list unfiltered. if (targetType) {
resourceTypes = getResourceTypesForTargetType(resourceTypes, targetType);
} for (const resourceType of resourceTypes) { // Pull all info about this resource type from `Resources` global object const { watchers } = getResourceTypeEntry(
rootOrWatcherOrTargetActor,
resourceType
);
/** *Clearresourcesforalistofresourcetypes. * *@paramActorrootOrWatcherOrTargetActor *Therelatedactor,alreadypassedtowatchResources. *@paramArray<String>resourceTypes *Listofalltypeofresourcetoclear.
*/ function clearResources(rootOrWatcherOrTargetActor, resourceTypes) { // If we are given a target actor, filter out the resource types supported by the target. // When using sharedData to pass types between processes, we are passing them for all target types. const { targetType } = rootOrWatcherOrTargetActor; // Only target actors usecase will have a target type. // For Root and Watcher we process the `resourceTypes` list unfiltered. if (targetType) {
resourceTypes = getResourceTypesForTargetType(resourceTypes, targetType);
} for (const resourceType of resourceTypes) { const { watchers } = getResourceTypeEntry(
rootOrWatcherOrTargetActor,
resourceType
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.