mobile/android/modules/LightweightThemeConsumer.jsm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/modules/LightweightThemeConsumer.jsm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +let EXPORTED_SYMBOLS = ["LightweightThemeConsumer"];
     1.9 +let Cc = Components.classes;
    1.10 +let Ci = Components.interfaces;
    1.11 +
    1.12 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.13 +Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
    1.14 +
    1.15 +function LightweightThemeConsumer(aDocument) {
    1.16 +  this._doc = aDocument;
    1.17 +  Services.obs.addObserver(this, "lightweight-theme-styling-update", false);
    1.18 +  Services.obs.addObserver(this, "lightweight-theme-apply", false);
    1.19 +
    1.20 +  this._update(LightweightThemeManager.currentThemeForDisplay);
    1.21 +}
    1.22 +
    1.23 +LightweightThemeConsumer.prototype = {
    1.24 +  observe: function (aSubject, aTopic, aData) {
    1.25 +    if (aTopic == "lightweight-theme-styling-update")
    1.26 +      this._update(JSON.parse(aData));
    1.27 +    else if (aTopic == "lightweight-theme-apply")
    1.28 +      this._update(LightweightThemeManager.currentThemeForDisplay);
    1.29 +  },
    1.30 +
    1.31 +  destroy: function () {
    1.32 +    Services.obs.removeObserver(this, "lightweight-theme-styling-update");
    1.33 +    Services.obs.removeObserver(this, "lightweight-theme-apply");
    1.34 +    this._doc = null;
    1.35 +  },
    1.36 +
    1.37 +  _update: function (aData) {
    1.38 +    if (!aData)
    1.39 +      aData = { headerURL: "", footerURL: "", textcolor: "", accentcolor: "" };
    1.40 +
    1.41 +    let active = !!aData.headerURL;
    1.42 +
    1.43 +    let msg = active ? { type: "LightweightTheme:Update", data: aData } :
    1.44 +                       { type: "LightweightTheme:Disable" };
    1.45 +    Services.androidBridge.handleGeckoMessage(msg);
    1.46 +  }
    1.47 +}

mercurial