Commit 2274e544 authored by Nicolas Chevobbe's avatar Nicolas Chevobbe
Browse files

Bug 1716284 - [devtools] Add a reflow resource. r=ochameau.

This is meant to replace usage of the ReflowActor.

Differential Revision: https://phabricator.services.mozilla.com/D117899
parent a1ad6732
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -305,7 +305,7 @@ LayoutChangesObserver.prototype = {
  _startEventLoop: function() {
    // Avoid emitting events if the targetActor has been detached (may happen
    // during shutdown)
    if (!this.targetActor || !this.targetActor.attached) {
    if (!this.targetActor || this.targetActor.isDestroyed()) {
      return;
    }

+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ const TYPES = {
  NETWORK_EVENT: "network-event",
  STYLESHEET: "stylesheet",
  NETWORK_EVENT_STACKTRACE: "network-event-stacktrace",
  REFLOW: "reflow",
  SOURCE: "source",
  THREAD_STATE: "thread-state",
  SERVER_SENT_EVENT: "server-sent-event",
@@ -75,6 +76,9 @@ const FrameTargetResources = augmentResourceDictionary({
  [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",
  },
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ DevToolsModules(
    "network-events-stacktraces.js",
    "network-events.js",
    "platform-messages.js",
    "reflow.js",
    "server-sent-events.js",
    "sources.js",
    "storage-cache.js",
+63 −0
Original line number Diff line number Diff line
/* 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";

const {
  TYPES: { REFLOW },
} = require("devtools/server/actors/resources/index");
const Targets = require("devtools/server/actors/targets/index");

const {
  getLayoutChangesObserver,
  releaseLayoutChangesObserver,
} = require("devtools/server/actors/reflow");

class ReflowWatcher {
  /**
   * Start watching for reflows related to a given Target Actor.
   *
   * @param TargetActor targetActor
   *        The target actor from which we should observe reflows
   * @param Object options
   *        Dictionary object with following attributes:
   *        - onAvailable: mandatory function
   *          This will be called for each resource.
   */
  async watch(targetActor, { onAvailable }) {
    // Only track reflow for non-ParentProcess FRAME targets
    if (
      targetActor.targetType !== Targets.TYPES.FRAME ||
      targetActor.typeName === "parentProcessTarget"
    ) {
      return;
    }

    this._targetActor = targetActor;

    const onReflows = reflows => {
      onAvailable([
        {
          resourceType: REFLOW,
          reflows,
        },
      ]);
    };

    this._observer = getLayoutChangesObserver(targetActor);
    this._offReflows = this._observer.on("reflows", onReflows);
    this._observer.start();
  }

  destroy() {
    releaseLayoutChangesObserver(this._targetActor);

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

module.exports = ReflowWatcher;
+1 −0
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
          [Resources.TYPES.PLATFORM_MESSAGE]: true,
          [Resources.TYPES.NETWORK_EVENT]: hasBrowserElement,
          [Resources.TYPES.NETWORK_EVENT_STACKTRACE]: hasBrowserElement,
          [Resources.TYPES.REFLOW]: true,
          [Resources.TYPES.STYLESHEET]: hasBrowserElement,
          [Resources.TYPES.SOURCE]: hasBrowserElement,
          [Resources.TYPES.THREAD_STATE]: hasBrowserElement,
Loading