2013-04-11 14:44:33 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const DEBUG = false;
|
|
|
|
function debug(s) { dump("-*- NavigatorPropertyHelper: " + s + "\n"); }
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
function NavigatorPropertyHelper() { };
|
|
|
|
|
|
|
|
NavigatorPropertyHelper.prototype = {
|
|
|
|
|
|
|
|
classID : Components.ID("{f0d03420-a0ce-11e2-9e96-0800200c9a66}"),
|
|
|
|
QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|
|
|
|
|
|
|
observe: function observe(subject, topic, data) {
|
|
|
|
if (DEBUG) debug("topic: " + topic + ", data: " + data);
|
|
|
|
let cm = Components.classes["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
|
2013-04-11 21:45:40 -07:00
|
|
|
|
|
|
|
let enableAndAddObserver = function(oldCategory, newCategory) {
|
|
|
|
let enumerator = cm.enumerateCategory(oldCategory);
|
|
|
|
while (enumerator.hasMoreElements()) {
|
|
|
|
let entry = enumerator.getNext().QueryInterface(Ci.nsISupportsCString);
|
|
|
|
let keyVal = cm.getCategoryEntry(oldCategory, entry).split(',');
|
2013-04-11 14:44:33 -07:00
|
|
|
try {
|
2013-04-11 21:45:40 -07:00
|
|
|
if (Services.prefs.getBoolPref(entry)) {
|
|
|
|
if (DEBUG) debug("enable: " + keyVal[0]);
|
|
|
|
cm.addCategoryEntry(newCategory, keyVal[0], keyVal[1], false, false);
|
2013-04-11 14:44:33 -07:00
|
|
|
}
|
|
|
|
} catch (ex) {
|
2013-04-11 21:45:40 -07:00
|
|
|
if (DEBUG) debug("no pref found: " + entry);
|
2013-04-11 14:44:33 -07:00
|
|
|
}
|
2013-04-11 21:45:40 -07:00
|
|
|
Services.prefs.addObserver(entry, this, true);
|
|
|
|
}
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
function addOrRemoveCategory(oldCategory, newCategory) {
|
|
|
|
let keyVal = cm.getCategoryEntry(oldCategory, data).split(',');
|
|
|
|
let key = keyVal[0];
|
|
|
|
let val = keyVal[1];
|
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref(data)) {
|
|
|
|
if (DEBUG) debug("enable: " + key);
|
|
|
|
cm.addCategoryEntry(newCategory, key, val, false, false);
|
|
|
|
} else {
|
|
|
|
if (DEBUG) debug("disable: " + key);
|
|
|
|
cm.deleteCategoryEntry(newCategory, key, false);
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
cm.deleteCategoryEntry(newCategory, key, false);
|
|
|
|
if (DEBUG) debug("no pref found: " + data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (topic) {
|
|
|
|
case 'app-startup':
|
|
|
|
enableAndAddObserver("JavaScript-navigator-property-maybe", "JavaScript-navigator-property");
|
|
|
|
enableAndAddObserver("JavaScript-global-constructor-maybe", "JavaScript-global-constructor");
|
|
|
|
break;
|
|
|
|
case 'nsPref:changed':
|
|
|
|
addOrRemoveCategory("JavaScript-navigator-property-maybe", "JavaScript-navigator-property");
|
|
|
|
addOrRemoveCategory("JavaScript-global-constructor-maybe", "JavaScript-global-constructor");
|
2013-04-11 14:44:33 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (DEBUG) debug("unknown topic: " + topic);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NavigatorPropertyHelper])
|