2012-06-03 10:32:37 +04: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 {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
Cu.import("resource://services-common/utils.js");
|
2012-06-27 00:14:32 +04:00
|
|
|
Cu.import("resource://services-common/preferences.js");
|
2012-06-03 10:32:37 +04:00
|
|
|
|
|
|
|
function AitcService() {
|
|
|
|
this.aitc = null;
|
|
|
|
this.wrappedJSObject = this;
|
|
|
|
}
|
|
|
|
AitcService.prototype = {
|
|
|
|
classID: Components.ID("{a3d387ca-fd26-44ca-93be-adb5fda5a78d}"),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference]),
|
|
|
|
|
|
|
|
observe: function observe(subject, topic, data) {
|
|
|
|
switch (topic) {
|
|
|
|
case "app-startup":
|
|
|
|
// We listen for this event beacause Aitc won't work until there is
|
|
|
|
// atleast 1 visible top-level XUL window.
|
|
|
|
Services.obs.addObserver(this, "sessionstore-windows-restored", true);
|
|
|
|
break;
|
|
|
|
case "sessionstore-windows-restored":
|
|
|
|
Services.obs.removeObserver(this, "sessionstore-windows-restored");
|
|
|
|
|
|
|
|
// Don't start AITC if classic sync is on.
|
|
|
|
if (Preferences.get("services.sync.engine.apps", false)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Start AITC only if it is enabled.
|
|
|
|
if (!Preferences.get("services.aitc.enabled", false)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-27 00:14:32 +04:00
|
|
|
// Start AITC service only if apps.enabled is true. If false, setup
|
|
|
|
// an observer in case the value changes as a result of an access to
|
|
|
|
// the DOM API.
|
|
|
|
if (Preferences.get("dom.mozApps.used", false)) {
|
2012-06-03 10:32:37 +04:00
|
|
|
this.start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait and see if the user wants anything apps related.
|
2012-06-27 00:14:32 +04:00
|
|
|
Preferences.observe("dom.mozApps.used", function checkIfEnabled() {
|
|
|
|
if (Preferences.get("dom.mozApps.used", false)) {
|
|
|
|
Preferences.ignore("dom.mozApps.used", checkIfEnabled, this);
|
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
}, this);
|
2012-06-03 10:32:37 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
start: function start() {
|
2012-06-16 01:47:33 +04:00
|
|
|
if (this.aitc) {
|
|
|
|
return;
|
2012-06-03 10:32:37 +04:00
|
|
|
}
|
2012-06-16 01:47:33 +04:00
|
|
|
|
|
|
|
// Log to stdout if enabled.
|
2012-06-27 00:14:32 +04:00
|
|
|
Cu.import("resource://services-aitc/main.js");
|
2012-06-16 01:47:33 +04:00
|
|
|
Cu.import("resource://services-common/log4moz.js");
|
|
|
|
let root = Log4Moz.repository.getLogger("Service.AITC");
|
|
|
|
root.level = Log4Moz.Level[Preferences.get("services.aitc.log.level")];
|
|
|
|
if (Preferences.get("services.aitc.log.dump")) {
|
|
|
|
root.addAppender(new Log4Moz.DumpAppender());
|
|
|
|
}
|
|
|
|
this.aitc = new Aitc();
|
2012-06-27 00:14:32 +04:00
|
|
|
Services.obs.notifyObservers(null, "service:aitc:started", null);
|
2012-06-03 10:32:37 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const components = [AitcService];
|
|
|
|
const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|