Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
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
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 let EXPORTED_SYMBOLS = ["LightweightThemeConsumer"];
6 let Cc = Components.classes;
7 let Ci = Components.interfaces;
9 Components.utils.import("resource://gre/modules/Services.jsm");
10 Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
12 function LightweightThemeConsumer(aDocument) {
13 this._doc = aDocument;
14 Services.obs.addObserver(this, "lightweight-theme-styling-update", false);
15 Services.obs.addObserver(this, "lightweight-theme-apply", false);
17 this._update(LightweightThemeManager.currentThemeForDisplay);
18 }
20 LightweightThemeConsumer.prototype = {
21 observe: function (aSubject, aTopic, aData) {
22 if (aTopic == "lightweight-theme-styling-update")
23 this._update(JSON.parse(aData));
24 else if (aTopic == "lightweight-theme-apply")
25 this._update(LightweightThemeManager.currentThemeForDisplay);
26 },
28 destroy: function () {
29 Services.obs.removeObserver(this, "lightweight-theme-styling-update");
30 Services.obs.removeObserver(this, "lightweight-theme-apply");
31 this._doc = null;
32 },
34 _update: function (aData) {
35 if (!aData)
36 aData = { headerURL: "", footerURL: "", textcolor: "", accentcolor: "" };
38 let active = !!aData.headerURL;
40 let msg = active ? { type: "LightweightTheme:Update", data: aData } :
41 { type: "LightweightTheme:Disable" };
42 Services.androidBridge.handleGeckoMessage(msg);
43 }
44 }