summaryrefslogtreecommitdiffstats
path: root/application/basilisk/components/newtab/NewTabPrefsProvider.jsm
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-07-18 08:24:24 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-07-18 08:24:24 +0200
commitfc61780b35af913801d72086456f493f63197da6 (patch)
treef85891288a7bd988da9f0f15ae64e5c63f00d493 /application/basilisk/components/newtab/NewTabPrefsProvider.jsm
parent69f7f9e5f1475891ce11cc4f431692f965b0cd30 (diff)
parent50d3e596bbe89c95615f96eb71f6bc5be737a1db (diff)
downloadUXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar.gz
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar.lz
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.tar.xz
UXP-9ccb235f04529c1ec345d87dad6521cb567d20bb.zip
Merge commit '50d3e596bbe89c95615f96eb71f6bc5be737a1db' into Basilisk-releasev2018.07.18
# Conflicts: # browser/app/profile/firefox.js # browser/components/preferences/jar.mn
Diffstat (limited to 'application/basilisk/components/newtab/NewTabPrefsProvider.jsm')
-rw-r--r--application/basilisk/components/newtab/NewTabPrefsProvider.jsm114
1 files changed, 114 insertions, 0 deletions
diff --git a/application/basilisk/components/newtab/NewTabPrefsProvider.jsm b/application/basilisk/components/newtab/NewTabPrefsProvider.jsm
new file mode 100644
index 000000000..c1d8b4149
--- /dev/null
+++ b/application/basilisk/components/newtab/NewTabPrefsProvider.jsm
@@ -0,0 +1,114 @@
+/* global Services, Preferences, EventEmitter, XPCOMUtils */
+/* exported NewTabPrefsProvider */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["NewTabPrefsProvider"];
+
+const {interfaces: Ci, utils: Cu} = Components;
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Preferences.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyGetter(this, "EventEmitter", function() {
+ const {EventEmitter} = Cu.import("resource://devtools/shared/event-emitter.js", {});
+ return EventEmitter;
+});
+
+// Supported prefs and data type
+const gPrefsMap = new Map([
+ ["browser.newtabpage.remote", "bool"],
+ ["browser.newtabpage.remote.mode", "str"],
+ ["browser.newtabpage.remote.version", "str"],
+ ["browser.newtabpage.enabled", "bool"],
+ ["browser.newtabpage.enhanced", "bool"],
+ ["browser.newtabpage.introShown", "bool"],
+ ["browser.newtabpage.updateIntroShown", "bool"],
+ ["browser.newtabpage.pinned", "str"],
+ ["browser.newtabpage.blocked", "str"],
+ ["intl.locale.matchOS", "bool"],
+ ["general.useragent.locale", "localized"],
+ ["browser.search.hiddenOneOffs", "str"],
+]);
+
+// prefs that are important for the newtab page
+const gNewtabPagePrefs = new Set([
+ "browser.newtabpage.enabled",
+ "browser.newtabpage.enhanced",
+ "browser.newtabpage.pinned",
+ "browser.newtabpage.blocked",
+ "browser.newtabpage.introShown",
+ "browser.newtabpage.updateIntroShown",
+ "browser.search.hiddenOneOffs",
+]);
+
+let PrefsProvider = function PrefsProvider() {
+ EventEmitter.decorate(this);
+};
+
+PrefsProvider.prototype = {
+
+ observe(subject, topic, data) { // jshint ignore:line
+ if (topic === "nsPref:changed") {
+ if (gPrefsMap.has(data)) {
+ switch (gPrefsMap.get(data)) {
+ case "bool":
+ this.emit(data, Preferences.get(data, false));
+ break;
+ case "str":
+ this.emit(data, Preferences.get(data, ""));
+ break;
+ case "localized":
+ try {
+ this.emit(data, Preferences.get(data, "", Ci.nsIPrefLocalizedString));
+ } catch (e) {
+ this.emit(data, Preferences.get(data, ""));
+ }
+ break;
+ default:
+ this.emit(data);
+ break;
+ }
+ }
+ } else {
+ Cu.reportError(new Error("NewTabPrefsProvider observing unknown topic"));
+ }
+ },
+
+ /*
+ * Return the preferences that are important to the newtab page
+ */
+ get newtabPagePrefs() {
+ let results = {};
+ for (let pref of gNewtabPagePrefs) {
+ results[pref] = Preferences.get(pref, null);
+ }
+ return results;
+ },
+
+ get prefsMap() {
+ return gPrefsMap;
+ },
+
+ init() {
+ for (let pref of gPrefsMap.keys()) {
+ Services.prefs.addObserver(pref, this, false);
+ }
+ },
+
+ uninit() {
+ for (let pref of gPrefsMap.keys()) {
+ Services.prefs.removeObserver(pref, this, false);
+ }
+ }
+};
+
+/**
+ * Singleton that serves as the default new tab pref provider for the grid.
+ */
+const gPrefs = new PrefsProvider();
+
+let NewTabPrefsProvider = {
+ prefs: gPrefs,
+ newtabPagePrefSet: gNewtabPagePrefs,
+};