DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (409f3966645a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
/* 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";

var EXPORTED_SYMBOLS = ["LightweightThemeChild"];

ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");

/**
 * LightweightThemeChild forwards theme data to in-content pages.
 * It is both instantiated by the traditional Actor mechanism,
 * and also manually within the sidebar JS global (which has no message manager)
 */
class LightweightThemeChild extends ActorChild {
  constructor(mm) {
    super(mm);

    this.init();
  }

  /**
   * Initializes the actor for the current page, sending it any existing
   * theme data, and adding shared data change listeners so it can
   * notify the page of future updates.
   *
   * This is called when the actor is constructed, and any time
   * ActorManagerChild receives a pageshow event for the page we're
   * attached to.
   */
  init() {
    Services.cpmm.sharedData.addEventListener("change", this);
    this.update(this.mm.chromeOuterWindowID, this.content);
  }

  /**
   * Cleans up any global listeners registered by the actor.
   *
   * This is called by ActorManagerChild any time it receives a pagehide
   * event for the page we're attached to.
   */
  cleanup() {
    Services.cpmm.sharedData.removeEventListener("change", this);
  }

  /**
   * Handles "change" events on the child sharedData map, and notifies
   * our content page if its theme data was among the changed keys.
   */
  handleEvent(event) {
    if (event.type === "change") {
      if (event.changedKeys.includes(`theme/${this.mm.chromeOuterWindowID}`)) {
        this.update(this.mm.chromeOuterWindowID, this.content);
      }
    }
  }

  /**
   * Forward the theme data to the page.
   * @param {Object} outerWindowID The outerWindowID the parent process window has.
   * @param {Object} content The receiving global
   */
  update(outerWindowID, content) {
    const event = Cu.cloneInto({
      detail: {
        data: Services.cpmm.sharedData.get(`theme/${outerWindowID}`),
      },
    }, content);
    content.dispatchEvent(new content.CustomEvent("LightweightTheme:Set",
                                                  event));
  }
}