tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

process.sys.mjs (2714B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 import { ContentProcessWatcherRegistry } from "resource://devtools/server/connectors/js-process-actor/ContentProcessWatcherRegistry.sys.mjs";
      6 
      7 function watch() {
      8  // There is nothing to watch. This JS Process Actor will automatically be spawned
      9  // for each new DOM Process.
     10 }
     11 function unwatch() {}
     12 
     13 function createTargetsForWatcher(watcherDataObject) {
     14  // Always ignore the parent process. A special WindowGlobal target actor will be spawned.
     15  if (ChromeUtils.domProcessChild.childID == 0) {
     16    return;
     17  }
     18 
     19  createContentProcessTargetActor(watcherDataObject);
     20 }
     21 
     22 /**
     23 * Instantiate a content process target actor for the current process
     24 * and for a given watcher actor.
     25 *
     26 * @param {object} watcherDataObject
     27 */
     28 function createContentProcessTargetActor(watcherDataObject) {
     29  logDOMProcess(
     30    ChromeUtils.domProcessChild,
     31    "Instantiate ContentProcessTarget"
     32  );
     33 
     34  const { connection, loader } =
     35    ContentProcessWatcherRegistry.getOrCreateConnectionForWatcher(
     36      watcherDataObject.watcherActorID
     37    );
     38 
     39  const { ContentProcessTargetActor } = loader.require(
     40    "devtools/server/actors/targets/content-process"
     41  );
     42 
     43  // Create the actual target actor.
     44  const targetActor = new ContentProcessTargetActor(connection, {
     45    sessionContext: watcherDataObject.sessionContext,
     46  });
     47 
     48  ContentProcessWatcherRegistry.onNewTargetActor(
     49    watcherDataObject,
     50    targetActor
     51  );
     52 }
     53 
     54 function destroyTargetsForWatcher(watcherDataObject, options) {
     55  // Unregister and destroy the existing target actors for this target type
     56  const actorsToDestroy = watcherDataObject.actors.filter(
     57    actor => actor.targetType == "process"
     58  );
     59  watcherDataObject.actors = watcherDataObject.actors.filter(
     60    actor => actor.targetType != "process"
     61  );
     62 
     63  for (const actor of actorsToDestroy) {
     64    ContentProcessWatcherRegistry.destroyTargetActor(
     65      watcherDataObject,
     66      actor,
     67      options
     68    );
     69  }
     70 }
     71 
     72 // If true, log info about DOMProcess's being created.
     73 const DEBUG = false;
     74 
     75 /**
     76 * Print information about operation being done against each content process.
     77 *
     78 * @param {nsIDOMProcessChild} domProcessChild
     79 *        The process for which we should log a message.
     80 * @param {string} message
     81 *        Message to log.
     82 */
     83 function logDOMProcess(domProcessChild, message) {
     84  if (!DEBUG) {
     85    return;
     86  }
     87  dump(" [pid:" + domProcessChild + "] " + message + "\n");
     88 }
     89 
     90 export const ProcessTargetWatcher = {
     91  watch,
     92  unwatch,
     93  createTargetsForWatcher,
     94  destroyTargetsForWatcher,
     95 };