toolkit/mozapps/extensions/LightweightThemeManager.jsm
author Kris Maglione <maglione.k@gmail.com>
Fri, 29 Mar 2019 11:37:08 -0700
changeset 466984 ba1529f7fd786c0aa5340c4ccd5738dc69274935
parent 466981 238bd73cdf0b759712c6b5ae8a73d77a930a0663
child 472390 6159d01c9341088edcabb318259c8ce6201c61ac
permissions -rw-r--r--
Bug 1525762: Part 7 - Remove defunct LightweightThemeOptimizer. r=aswan It only works with "persisted" theme images, which no longer exist. Differential Revision: https://phabricator.services.mozilla.com/D25451

/* 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 = ["LightweightThemeManager"];

// Holds optional fallback theme data that will be returned when no data for an
// active theme can be found. This the case for WebExtension Themes, for example.
var _fallbackThemeData = null;

var LightweightThemeManager = {
  set fallbackThemeData(data) {
    if (data && Object.getOwnPropertyNames(data).length) {
      _fallbackThemeData = Object.assign({}, data);
    } else {
      _fallbackThemeData = null;
    }
  },

  /*
   * Returns the currently active theme, taking the fallback theme into account
   * if we'd be using the default theme otherwise.
   *
   * This will always return the original theme data and not make use of
   * locally persisted resources.
   */
  get currentThemeWithFallback() {
    return _fallbackThemeData && _fallbackThemeData.theme;
  },

  get themeData() {
    return _fallbackThemeData || {theme: null};
  },
};