2014-12-17 02:32:28 +03: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 Cu = Components.utils;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["UserCustomizations"];
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2015-08-15 02:55:09 +03:00
|
|
|
Cu.import("resource://gre/modules/Extension.jsm");
|
2014-12-17 02:32:28 +03:00
|
|
|
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "console",
|
|
|
|
"@mozilla.org/consoleservice;1",
|
|
|
|
"nsIConsoleService");
|
|
|
|
|
2015-01-17 01:16:03 +03:00
|
|
|
function debug(aMsg) {
|
|
|
|
if (!UserCustomizations._debug) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-15 02:55:09 +03:00
|
|
|
dump("-*-*- UserCustomizations " + aMsg + "\n");
|
2015-01-17 01:16:03 +03:00
|
|
|
}
|
2014-12-17 02:32:28 +03:00
|
|
|
|
|
|
|
function log(aStr) {
|
|
|
|
console.logStringMessage(aStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.UserCustomizations = {
|
2015-08-15 02:55:09 +03:00
|
|
|
extensions: new Map(), // id -> extension. Needed to disable extensions.
|
2014-12-17 02:32:28 +03:00
|
|
|
|
2015-08-15 02:55:09 +03:00
|
|
|
register: function(aApp) {
|
2014-12-17 02:32:28 +03:00
|
|
|
if (!this._enabled || !aApp.enabled || aApp.role != "addon") {
|
|
|
|
debug("Rejecting registration (global enabled=" + this._enabled +
|
|
|
|
") (app role=" + aApp.role +
|
|
|
|
", enabled=" + aApp.enabled + ")");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-15 02:55:09 +03:00
|
|
|
debug("Starting customization registration for " + aApp.manifestURL + "\n");
|
2014-12-17 02:32:28 +03:00
|
|
|
|
2015-08-15 02:55:09 +03:00
|
|
|
let extension = new Extension({
|
|
|
|
id: aApp.manifestURL,
|
|
|
|
resourceURI: Services.io.newURI(aApp.origin + "/", null, null)
|
2014-12-17 02:32:28 +03:00
|
|
|
});
|
|
|
|
|
2015-08-15 02:55:09 +03:00
|
|
|
this.extensions.set(aApp.manifestURL, extension);
|
|
|
|
extension.startup();
|
2014-12-17 02:32:28 +03:00
|
|
|
},
|
|
|
|
|
2015-08-15 02:55:09 +03:00
|
|
|
unregister: function(aApp) {
|
2014-12-17 02:32:28 +03:00
|
|
|
if (!this._enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("Starting customization unregistration for " + aApp.manifestURL);
|
2015-08-15 02:55:09 +03:00
|
|
|
if (this.extensions.has(aApp.manifestURL)) {
|
|
|
|
this.extensions.get(aApp.manifestURL).shutdown();
|
|
|
|
this.extensions.delete(aApp.manifestURL);
|
2014-12-17 02:32:28 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._enabled = false;
|
|
|
|
try {
|
|
|
|
this._enabled = Services.prefs.getBoolPref("dom.apps.customization.enabled");
|
|
|
|
} catch(e) {}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
UserCustomizations.init();
|