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 file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 * LightweightThemeChild forwards theme data to in-content pages.
8 export class LightweightThemeChild extends JSWindowActorChild {
11 this._initted = false;
12 Services.cpmm.sharedData.addEventListener("change", this);
16 Services.cpmm.sharedData.removeEventListener("change", this);
19 _getChromeOuterWindowID() {
21 // Getting the browserChild throws an exception when it is null.
22 let browserChild = this.docShell.browserChild;
24 return browserChild.chromeOuterWindowID;
29 Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_DEFAULT
31 return this.browsingContext.topChromeWindow.docShell.outerWindowID;
34 // Return a false-y outerWindowID if we can't manage to get a proper one.
35 // Note that no outerWindowID will ever have this ID.
40 * Handles "change" events on the child sharedData map, and notifies
41 * our content page if its theme data was among the changed keys.
45 // Make sure to update the theme data on first page show.
47 case "DOMContentLoaded":
48 if (!this._initted && this._getChromeOuterWindowID()) {
56 event.changedKeys.includes(`theme/${this._getChromeOuterWindowID()}`)
65 * Forward the theme data to the page.
68 const event = Cu.cloneInto(
71 data: Services.cpmm.sharedData.get(
72 `theme/${this._getChromeOuterWindowID()}`
78 this.contentWindow.dispatchEvent(
79 new this.contentWindow.CustomEvent("LightweightTheme:Set", event)