bug 779662 - click-to-play overlay click handler too restrictive. r=jaws
[gecko.git] / browser / modules / Social.jsm
blobd6c30694244cec08b844d534010354e14f6265f1
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/. */
5 "use strict";
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");
19 let Social = {
20   lastEventReceived: 0,
21   provider: null,
22   init: function Social_init(callback) {
23     if (this.provider) {
24       schedule(callback);
25       return;
26     }
28     // Eventually this might want to retrieve a specific provider, but for now
29     // just use the first available.
30     SocialService.getProviderList(function (providers) {
31       if (providers.length)
32         this.provider = providers[0];
33       callback();
34       Services.obs.notifyObservers(null, "test-social-ui-ready", "");
35     }.bind(this));
36   },
38   get uiVisible() {
39     return this.provider && this.provider.enabled && this.provider.port;
40   },
42   set enabled(val) {
43     SocialService.enabled = val;
44   },
45   get enabled() {
46     return SocialService.enabled;
47   },
49   get active() {
50     return Services.prefs.getBoolPref("social.active");
51   },
52   set active(val) {
53     Services.prefs.setBoolPref("social.active", !!val);
54     this.enabled = !!val;
55   },
57   toggle: function Social_toggle() {
58     this.enabled = !this.enabled;
59   },
61   toggleSidebar: function SocialSidebar_toggle() {
62     let prefValue = Services.prefs.getBoolPref("social.sidebar.open");
63     Services.prefs.setBoolPref("social.sidebar.open", !prefValue);
64   },
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);
71   },
73   // Sharing functionality
74   _getShareablePageUrl: function Social_getShareablePageUrl(aURI) {
75     let uri = aURI.clone();
76     try {
77       // Setting userPass on about:config throws.
78       uri.userPass = "";
79     } catch (e) {}
80     return uri.spec;
81   },
83   isPageShared: function Social_isPageShared(aURI) {
84     let url = this._getShareablePageUrl(aURI);
85     return this._sharedUrls.hasOwnProperty(url);
86   },
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",
93       data: { url: url }
94     });
95   },
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",
102       data: { url: url }
103     });
104   },
106   _sharedUrls: {}
109 function schedule(callback) {
110   Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);