|
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/. */ |
|
4 |
|
5 let EXPORTED_SYMBOLS = ["LightweightThemeConsumer"]; |
|
6 let Cc = Components.classes; |
|
7 let Ci = Components.interfaces; |
|
8 |
|
9 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
10 Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm"); |
|
11 |
|
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); |
|
16 |
|
17 this._update(LightweightThemeManager.currentThemeForDisplay); |
|
18 } |
|
19 |
|
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 }, |
|
27 |
|
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 }, |
|
33 |
|
34 _update: function (aData) { |
|
35 if (!aData) |
|
36 aData = { headerURL: "", footerURL: "", textcolor: "", accentcolor: "" }; |
|
37 |
|
38 let active = !!aData.headerURL; |
|
39 |
|
40 let msg = active ? { type: "LightweightTheme:Update", data: aData } : |
|
41 { type: "LightweightTheme:Disable" }; |
|
42 Services.androidBridge.handleGeckoMessage(msg); |
|
43 } |
|
44 } |