mobile/android/modules/LightweightThemeConsumer.jsm

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 let EXPORTED_SYMBOLS = ["LightweightThemeConsumer"];
michael@0 6 let Cc = Components.classes;
michael@0 7 let Ci = Components.interfaces;
michael@0 8
michael@0 9 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 10 Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
michael@0 11
michael@0 12 function LightweightThemeConsumer(aDocument) {
michael@0 13 this._doc = aDocument;
michael@0 14 Services.obs.addObserver(this, "lightweight-theme-styling-update", false);
michael@0 15 Services.obs.addObserver(this, "lightweight-theme-apply", false);
michael@0 16
michael@0 17 this._update(LightweightThemeManager.currentThemeForDisplay);
michael@0 18 }
michael@0 19
michael@0 20 LightweightThemeConsumer.prototype = {
michael@0 21 observe: function (aSubject, aTopic, aData) {
michael@0 22 if (aTopic == "lightweight-theme-styling-update")
michael@0 23 this._update(JSON.parse(aData));
michael@0 24 else if (aTopic == "lightweight-theme-apply")
michael@0 25 this._update(LightweightThemeManager.currentThemeForDisplay);
michael@0 26 },
michael@0 27
michael@0 28 destroy: function () {
michael@0 29 Services.obs.removeObserver(this, "lightweight-theme-styling-update");
michael@0 30 Services.obs.removeObserver(this, "lightweight-theme-apply");
michael@0 31 this._doc = null;
michael@0 32 },
michael@0 33
michael@0 34 _update: function (aData) {
michael@0 35 if (!aData)
michael@0 36 aData = { headerURL: "", footerURL: "", textcolor: "", accentcolor: "" };
michael@0 37
michael@0 38 let active = !!aData.headerURL;
michael@0 39
michael@0 40 let msg = active ? { type: "LightweightTheme:Update", data: aData } :
michael@0 41 { type: "LightweightTheme:Disable" };
michael@0 42 Services.androidBridge.handleGeckoMessage(msg);
michael@0 43 }
michael@0 44 }

mercurial