Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/devtools/server/actors/targets/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 4 kB image not shown  

Quelle  content-script.js   Sprache: JAVA

 
/* 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/. */


"use strict";

/*
 * Target actor for all Web Extension Content Scripts running against matching
 * web pages defined in the extension manifest.
 * They are running the same thread as the page (i.e. the main thread).
 *
 * See devtools/docs/contributor/backend/actor-hierarchy.md for more details about all the targets.
 */


const { ThreadActor } = require("resource://devtools/server/actors/thread.js");
const {
  WebConsoleActor,
} = require("resource://devtools/server/actors/webconsole.js");
const makeDebugger = require("resource://devtools/server/actors/utils/make-debugger.js");
const { assert } = require("resource://devtools/shared/DevToolsUtils.js");
const {
  SourcesManager,
} = require("resource://devtools/server/actors/utils/sources-manager.js");
const {
  contentScriptTargetSpec,
} = require("resource://devtools/shared/specs/targets/content-script.js");
const Targets = require("resource://devtools/server/actors/targets/index.js");
const Resources = require("resource://devtools/server/actors/resources/index.js");
const {
  BaseTargetActor,
} = require("resource://devtools/server/actors/targets/base-target-actor.js");

loader.lazyRequireGetter(
  this,
  "TracerActor",
  "resource://devtools/server/actors/tracer.js",
  true
);

class WebExtensionContentScriptTargetActor extends BaseTargetActor {
  constructor(conn, { sessionContext, contentScriptSandbox } = {}) {
    super(conn, Targets.TYPES.CONTENT_SCRIPT, contentScriptTargetSpec);

    this.threadActor = null;
    this.sessionContext = sessionContext;
    this.contentScriptSandbox = contentScriptSandbox;
    const metadata = Cu.getSandboxMetadata(contentScriptSandbox);
    this.addonId = metadata.addonId;
    this.innerWindowId = metadata["inner-window-id"];

    // Use a debugger against a unique global
    this.makeDebugger = makeDebugger.bind(null, {
      findDebuggees: _dbg => [this.contentScriptSandbox],

      // Only accept the content script sandbox and nothing else.
      shouldAddNewGlobalAsDebuggee: () => false,
    });
  }

  get isRootActor() {
    return false;
  }

  // This will be used by the Console actor for evaluations
  get targetGlobal() {
    return this.contentScriptSandbox;
  }

  get sourcesManager() {
    if (!this._sourcesManager) {
      assert(
        this.threadActor,
        "threadActor should exist when creating SourcesManager."
      );
      this._sourcesManager = new SourcesManager(this.threadActor);
    }
    return this._sourcesManager;
  }

  /*
   * Return a Debugger instance or create one if there is none yet
   */

  get dbg() {
    if (!this._dbg) {
      this._dbg = this.makeDebugger();
    }
    return this._dbg;
  }

  form() {
    if (!this._consoleActor) {
      this._consoleActor = new WebConsoleActor(this.conn, this);
      this.manage(this._consoleActor);
    }

    if (!this.threadActor) {
      this.threadActor = new ThreadActor(this);
      this.manage(this.threadActor);
    }
    if (!this.tracerActor) {
      this.tracerActor = new TracerActor(this.conn, this);
      this.manage(this.tracerActor);
    }

    const policy = WebExtensionPolicy.getByID(this.addonId);

    return {
      actor: this.actorID,

      // Use the related extension as content script title
      // as content scripts have no name, they are just a group of JS files
      // running against a web page.
      title: policy.name,

      // The ID of the document against which this content script executes
      innerWindowId: this.innerWindowId,

      consoleActor: this._consoleActor.actorID,
      threadActor: this.threadActor.actorID,
      tracerActor: this.tracerActor.actorID,

      traits: {
        networkMonitor: false,
        // See trait description in browsing-context.js
        supportsTopLevelTargetFlag: false,
      },
    };
  }

  destroy({ isModeSwitching } = {}) {
    // Avoid reentrancy. We will destroy the Transport when emitting "destroyed",
    // which will force destroying all actors.
    if (this.destroying) {
      return;
    }
    this.destroying = true;

    // Unregistering watchers first is important
    // otherwise you might have leaks reported when running browser_browser_toolbox_netmonitor.js in debug builds
    Resources.unwatchAllResources(this);

    this.emit("destroyed", { isModeSwitching });

    super.destroy();

    if (this.threadActor) {
      this.threadActor = null;
    }

    if (this._sourcesManager) {
      this._sourcesManager.destroy();
      this._sourcesManager = null;
    }

    if (this._dbg) {
      this._dbg.disable();
      this._dbg = null;
    }
  }
}

exports.WebExtensionContentScriptTargetActor =
  WebExtensionContentScriptTargetActor;

Messung V0.5
C=92 H=89 G=90

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

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.