2012-06-20 18:01:27 -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/. */
|
|
|
|
|
|
|
|
const EXPORTED_SYMBOLS = ["SocialService"];
|
|
|
|
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
2012-06-26 19:03:32 -07:00
|
|
|
|
2012-06-20 18:01:27 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-07-05 14:01:38 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2012-06-26 19:03:32 -07:00
|
|
|
Cu.import("resource://gre/modules/SocialProvider.jsm");
|
2012-06-20 18:01:27 -07:00
|
|
|
|
|
|
|
const MANIFEST_PREFS = Services.prefs.getBranch("social.manifest.");
|
|
|
|
|
2012-07-05 14:01:38 -07:00
|
|
|
let SocialServiceInternal = {};
|
2012-06-20 18:01:27 -07:00
|
|
|
|
2012-07-05 14:01:38 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(SocialServiceInternal, "providers", function () {
|
|
|
|
let providers = {};
|
|
|
|
let prefs = MANIFEST_PREFS.getChildList("", {});
|
|
|
|
prefs.forEach(function (pref) {
|
|
|
|
try {
|
|
|
|
var manifest = JSON.parse(MANIFEST_PREFS.getCharPref(pref));
|
2012-06-20 18:01:27 -07:00
|
|
|
if (manifest && typeof(manifest) == "object") {
|
2012-07-05 14:01:38 -07:00
|
|
|
let provider = new SocialProvider(manifest);
|
|
|
|
providers[provider.origin] = provider;
|
2012-06-20 18:01:27 -07:00
|
|
|
}
|
2012-07-05 14:01:38 -07:00
|
|
|
} catch (err) {
|
2012-07-09 02:09:56 -07:00
|
|
|
Cu.reportError("SocialService: failed to load provider: " + pref +
|
|
|
|
", exception: " + err);
|
2012-07-05 14:01:38 -07:00
|
|
|
}
|
|
|
|
}, this);
|
2012-06-20 18:01:27 -07:00
|
|
|
|
2012-07-05 14:01:38 -07:00
|
|
|
return providers;
|
|
|
|
});
|
|
|
|
|
|
|
|
const SocialService = {
|
2012-06-20 18:01:27 -07:00
|
|
|
getProvider: function getProvider(origin, onDone) {
|
|
|
|
schedule((function () {
|
2012-07-05 14:01:38 -07:00
|
|
|
onDone(SocialServiceInternal.providers[origin] || null);
|
2012-06-20 18:01:27 -07:00
|
|
|
}).bind(this));
|
|
|
|
},
|
|
|
|
|
2012-07-05 14:01:38 -07:00
|
|
|
// Returns an array of installed provider origins.
|
|
|
|
getProviderList: function getProviderList(onDone) {
|
|
|
|
let providers = [p for each (p in SocialServiceInternal.providers)];
|
|
|
|
schedule((function () {
|
|
|
|
onDone(providers);
|
|
|
|
}).bind(this));
|
|
|
|
}
|
|
|
|
};
|
2012-06-20 18:01:27 -07:00
|
|
|
|
|
|
|
function schedule(callback) {
|
|
|
|
Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
}
|