1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 let EXPORTED_SYMBOLS = ["Social"];
9 const Ci = Components.interfaces;
10 const Cc = Components.classes;
11 const Cu = Components.utils;
13 Cu.import("resource://gre/modules/Services.jsm");
14 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
16 XPCOMUtils.defineLazyModuleGetter(this, "SocialService",
17 "resource://gre/modules/SocialService.jsm");
22 init: function Social_init(callback) {
28 // Eventually this might want to retrieve a specific provider, but for now
29 // just use the first available.
30 SocialService.getProviderList(function (providers) {
32 this.provider = providers[0];
34 Services.obs.notifyObservers(null, "test-social-ui-ready", "");
39 return this.provider && this.provider.enabled && this.provider.port;
43 SocialService.enabled = val;
46 return SocialService.enabled;
50 return Services.prefs.getBoolPref("social.active");
53 Services.prefs.setBoolPref("social.active", !!val);
57 toggle: function Social_toggle() {
58 this.enabled = !this.enabled;
61 toggleSidebar: function SocialSidebar_toggle() {
62 let prefValue = Services.prefs.getBoolPref("social.sidebar.open");
63 Services.prefs.setBoolPref("social.sidebar.open", !prefValue);
66 sendWorkerMessage: function Social_sendWorkerMessage(message) {
67 // Responses aren't handled yet because there is no actions to perform
68 // based on the response from the provider at this point.
69 if (this.provider && this.provider.port)
70 this.provider.port.postMessage(message);
73 // Sharing functionality
74 _getShareablePageUrl: function Social_getShareablePageUrl(aURI) {
75 let uri = aURI.clone();
77 // Setting userPass on about:config throws.
83 isPageShared: function Social_isPageShared(aURI) {
84 let url = this._getShareablePageUrl(aURI);
85 return this._sharedUrls.hasOwnProperty(url);
88 sharePage: function Social_sharePage(aURI) {
89 let url = this._getShareablePageUrl(aURI);
90 this._sharedUrls[url] = true;
91 this.sendWorkerMessage({
92 topic: "social.user-recommend",
97 unsharePage: function Social_unsharePage(aURI) {
98 let url = this._getShareablePageUrl(aURI);
99 delete this._sharedUrls[url];
100 this.sendWorkerMessage({
101 topic: "social.user-unrecommend",
109 function schedule(callback) {
110 Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);