michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let EXPORTED_SYMBOLS = ["LightweightThemeConsumer"]; michael@0: let Cc = Components.classes; michael@0: let Ci = Components.interfaces; michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm"); michael@0: michael@0: function LightweightThemeConsumer(aDocument) { michael@0: this._doc = aDocument; michael@0: Services.obs.addObserver(this, "lightweight-theme-styling-update", false); michael@0: Services.obs.addObserver(this, "lightweight-theme-apply", false); michael@0: michael@0: this._update(LightweightThemeManager.currentThemeForDisplay); michael@0: } michael@0: michael@0: LightweightThemeConsumer.prototype = { michael@0: observe: function (aSubject, aTopic, aData) { michael@0: if (aTopic == "lightweight-theme-styling-update") michael@0: this._update(JSON.parse(aData)); michael@0: else if (aTopic == "lightweight-theme-apply") michael@0: this._update(LightweightThemeManager.currentThemeForDisplay); michael@0: }, michael@0: michael@0: destroy: function () { michael@0: Services.obs.removeObserver(this, "lightweight-theme-styling-update"); michael@0: Services.obs.removeObserver(this, "lightweight-theme-apply"); michael@0: this._doc = null; michael@0: }, michael@0: michael@0: _update: function (aData) { michael@0: if (!aData) michael@0: aData = { headerURL: "", footerURL: "", textcolor: "", accentcolor: "" }; michael@0: michael@0: let active = !!aData.headerURL; michael@0: michael@0: let msg = active ? { type: "LightweightTheme:Update", data: aData } : michael@0: { type: "LightweightTheme:Disable" }; michael@0: Services.androidBridge.handleGeckoMessage(msg); michael@0: } michael@0: }