2015-11-30 14:13:57 +00: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/. */
|
2012-07-12 01:31:19 +00:00
|
|
|
|
2013-03-26 23:15:59 +00:00
|
|
|
// the "exported" symbols
|
2015-09-15 18:19:45 +00:00
|
|
|
var SocialUI,
|
2013-03-26 23:15:59 +00:00
|
|
|
SocialFlyout,
|
2013-09-06 17:56:01 +00:00
|
|
|
SocialMarks,
|
2013-05-07 06:02:58 +00:00
|
|
|
SocialShare,
|
2013-09-09 21:37:04 +00:00
|
|
|
SocialSidebar,
|
2014-11-06 01:22:27 +00:00
|
|
|
SocialStatus,
|
|
|
|
SocialActivationListener;
|
2013-03-26 23:15:59 +00:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-06-17 10:23:40 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PanelFrame",
|
|
|
|
"resource:///modules/PanelFrame.jsm");
|
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "OpenGraphBuilder", function() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource:///modules/Social.jsm", tmp);
|
|
|
|
return tmp.OpenGraphBuilder;
|
|
|
|
});
|
|
|
|
|
2013-09-06 17:56:01 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "DynamicResizeWatcher", function() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource:///modules/Social.jsm", tmp);
|
|
|
|
return tmp.DynamicResizeWatcher;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "sizeSocialPanelToContent", function() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource:///modules/Social.jsm", tmp);
|
|
|
|
return tmp.sizeSocialPanelToContent;
|
|
|
|
});
|
|
|
|
|
2013-12-17 05:21:17 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "CreateSocialStatusWidget", function() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource:///modules/Social.jsm", tmp);
|
|
|
|
return tmp.CreateSocialStatusWidget;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "CreateSocialMarkWidget", function() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource:///modules/Social.jsm", tmp);
|
|
|
|
return tmp.CreateSocialMarkWidget;
|
|
|
|
});
|
|
|
|
|
2014-10-09 19:01:39 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "hookWindowCloseForPanelClose", function() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource://gre/modules/MozSocialAPI.jsm", tmp);
|
|
|
|
return tmp.hookWindowCloseForPanelClose;
|
|
|
|
});
|
|
|
|
|
2013-03-26 23:15:59 +00:00
|
|
|
SocialUI = {
|
2014-03-12 02:25:45 +00:00
|
|
|
_initialized: false,
|
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
// Called on delayed startup to initialize the UI
|
2012-07-12 01:31:19 +00:00
|
|
|
init: function SocialUI_init() {
|
2014-03-12 02:25:45 +00:00
|
|
|
if (this._initialized) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-22 17:33:18 +00:00
|
|
|
let mm = window.getGroupMessageManager("social");
|
|
|
|
mm.loadFrameScript("chrome://browser/content/content.js", true);
|
|
|
|
mm.loadFrameScript("chrome://browser/content/social-content.js", true);
|
2014-03-12 02:25:45 +00:00
|
|
|
|
2012-07-15 23:12:13 +00:00
|
|
|
Services.obs.addObserver(this, "social:ambient-notification-changed", false);
|
|
|
|
Services.obs.addObserver(this, "social:profile-changed", false);
|
2012-10-30 20:10:04 +00:00
|
|
|
Services.obs.addObserver(this, "social:frameworker-error", false);
|
2013-02-08 19:39:25 +00:00
|
|
|
Services.obs.addObserver(this, "social:providers-changed", false);
|
2013-08-21 18:32:46 +00:00
|
|
|
Services.obs.addObserver(this, "social:provider-reload", false);
|
2013-09-04 17:01:38 +00:00
|
|
|
Services.obs.addObserver(this, "social:provider-enabled", false);
|
|
|
|
Services.obs.addObserver(this, "social:provider-disabled", false);
|
2012-07-15 23:12:13 +00:00
|
|
|
|
2012-09-27 00:40:18 +00:00
|
|
|
Services.prefs.addObserver("social.toast-notifications.enabled", this, false);
|
2012-07-18 18:40:05 +00:00
|
|
|
|
2014-10-09 19:02:13 +00:00
|
|
|
CustomizableUI.addListener(this);
|
2014-11-06 01:22:27 +00:00
|
|
|
SocialActivationListener.init();
|
2012-06-22 22:01:34 +00:00
|
|
|
|
2013-12-17 05:37:30 +00:00
|
|
|
// menupopups that list social providers. we only populate them when shown,
|
|
|
|
// and if it has not been done already.
|
|
|
|
document.getElementById("viewSidebarMenu").addEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true);
|
|
|
|
document.getElementById("social-statusarea-popup").addEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true);
|
|
|
|
|
2014-03-12 02:25:45 +00:00
|
|
|
Social.init().then((update) => {
|
|
|
|
if (update)
|
|
|
|
this._providersChanged();
|
|
|
|
// handle SessionStore for the sidebar state
|
|
|
|
SocialSidebar.restoreWindowState();
|
|
|
|
});
|
|
|
|
|
|
|
|
this._initialized = true;
|
2012-07-12 01:31:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Called on window unload
|
|
|
|
uninit: function SocialUI_uninit() {
|
2014-03-12 02:25:45 +00:00
|
|
|
if (!this._initialized) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-25 20:15:08 +00:00
|
|
|
SocialSidebar.saveWindowState();
|
2014-03-12 02:25:45 +00:00
|
|
|
|
2012-07-15 23:12:13 +00:00
|
|
|
Services.obs.removeObserver(this, "social:ambient-notification-changed");
|
|
|
|
Services.obs.removeObserver(this, "social:profile-changed");
|
2012-10-30 20:10:04 +00:00
|
|
|
Services.obs.removeObserver(this, "social:frameworker-error");
|
2013-02-08 19:39:25 +00:00
|
|
|
Services.obs.removeObserver(this, "social:providers-changed");
|
2013-08-21 18:32:46 +00:00
|
|
|
Services.obs.removeObserver(this, "social:provider-reload");
|
2013-09-04 17:01:38 +00:00
|
|
|
Services.obs.removeObserver(this, "social:provider-enabled");
|
|
|
|
Services.obs.removeObserver(this, "social:provider-disabled");
|
2012-07-18 18:40:05 +00:00
|
|
|
|
2012-09-27 00:40:18 +00:00
|
|
|
Services.prefs.removeObserver("social.toast-notifications.enabled", this);
|
2014-10-09 19:02:13 +00:00
|
|
|
CustomizableUI.removeListener(this);
|
2014-11-06 01:22:27 +00:00
|
|
|
SocialActivationListener.uninit();
|
2013-12-17 05:24:44 +00:00
|
|
|
|
2013-12-17 05:37:30 +00:00
|
|
|
document.getElementById("viewSidebarMenu").removeEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true);
|
|
|
|
document.getElementById("social-statusarea-popup").removeEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true);
|
2012-07-12 01:31:19 +00:00
|
|
|
|
2014-03-12 02:25:45 +00:00
|
|
|
this._initialized = false;
|
2012-12-08 04:13:27 +00:00
|
|
|
},
|
2012-06-22 22:01:34 +00:00
|
|
|
|
2012-12-08 04:13:27 +00:00
|
|
|
observe: function SocialUI_observe(subject, topic, data) {
|
2014-08-27 00:03:19 +00:00
|
|
|
switch (topic) {
|
|
|
|
case "social:provider-enabled":
|
|
|
|
SocialMarks.populateToolbarPalette();
|
|
|
|
SocialStatus.populateToolbarPalette();
|
|
|
|
break;
|
|
|
|
case "social:provider-disabled":
|
|
|
|
SocialMarks.removeProvider(data);
|
|
|
|
SocialStatus.removeProvider(data);
|
|
|
|
SocialSidebar.disableProvider(data);
|
|
|
|
break;
|
|
|
|
case "social:provider-reload":
|
|
|
|
SocialStatus.reloadProvider(data);
|
|
|
|
// if the reloaded provider is our current provider, fall through
|
|
|
|
// to social:providers-changed so the ui will be reset
|
|
|
|
if (!SocialSidebar.provider || SocialSidebar.provider.origin != data)
|
|
|
|
return;
|
|
|
|
// currently only the sidebar and flyout have a selected provider.
|
|
|
|
// sidebar provider has changed (possibly to null), ensure the content
|
|
|
|
// is unloaded and the frames are reset, they will be loaded in
|
|
|
|
// providers-changed below if necessary.
|
|
|
|
SocialSidebar.unloadSidebar();
|
|
|
|
SocialFlyout.unload();
|
|
|
|
// fall through to providers-changed to ensure the reloaded provider
|
|
|
|
// is correctly reflected in any UI and the multi-provider menu
|
|
|
|
case "social:providers-changed":
|
|
|
|
this._providersChanged();
|
|
|
|
break;
|
|
|
|
// Provider-specific notifications
|
|
|
|
case "social:ambient-notification-changed":
|
|
|
|
SocialStatus.updateButton(data);
|
|
|
|
break;
|
|
|
|
case "social:profile-changed":
|
|
|
|
// make sure anything that happens here only affects the provider for
|
|
|
|
// which the profile is changing, and that anything we call actually
|
|
|
|
// needs to change based on profile data.
|
|
|
|
SocialStatus.updateButton(data);
|
|
|
|
break;
|
|
|
|
case "social:frameworker-error":
|
|
|
|
if (this.enabled && SocialSidebar.provider && SocialSidebar.provider.origin == data) {
|
2015-05-22 17:33:18 +00:00
|
|
|
SocialSidebar.loadFrameworkerFailure();
|
2014-08-27 00:03:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "nsPref:changed":
|
|
|
|
if (data == "social.toast-notifications.enabled") {
|
|
|
|
SocialSidebar.updateToggleNotifications();
|
|
|
|
}
|
|
|
|
break;
|
2012-12-08 04:13:27 +00:00
|
|
|
}
|
|
|
|
},
|
2012-10-30 06:28:31 +00:00
|
|
|
|
2014-03-12 02:25:45 +00:00
|
|
|
_providersChanged: function() {
|
|
|
|
SocialSidebar.clearProviderMenus();
|
|
|
|
SocialSidebar.update();
|
|
|
|
SocialShare.populateProviderMenu();
|
|
|
|
SocialStatus.populateToolbarPalette();
|
|
|
|
SocialMarks.populateToolbarPalette();
|
2012-07-23 03:49:28 +00:00
|
|
|
},
|
|
|
|
|
2013-04-02 23:28:30 +00:00
|
|
|
showLearnMore: function() {
|
|
|
|
let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "social-api";
|
|
|
|
openUILinkIn(url, "tab");
|
|
|
|
},
|
|
|
|
|
2012-10-16 06:58:13 +00:00
|
|
|
closeSocialPanelForLinkTraversal: function (target, linkNode) {
|
|
|
|
// No need to close the panel if this traversal was not retargeted
|
|
|
|
if (target == "" || target == "_self")
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check to see whether this link traversal was in a social panel
|
|
|
|
let win = linkNode.ownerDocument.defaultView;
|
|
|
|
let container = win.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell)
|
|
|
|
.chromeEventHandler;
|
|
|
|
let containerParent = container.parentNode;
|
|
|
|
if (containerParent.classList.contains("social-panel") &&
|
|
|
|
containerParent instanceof Ci.nsIDOMXULPopupElement) {
|
2013-08-30 16:30:00 +00:00
|
|
|
// allow the link traversal to finish before closing the panel
|
|
|
|
setTimeout(() => {
|
|
|
|
containerParent.hidePopup();
|
|
|
|
}, 0);
|
2012-10-16 06:58:13 +00:00
|
|
|
}
|
2012-10-30 06:25:53 +00:00
|
|
|
},
|
|
|
|
|
2013-01-24 10:14:36 +00:00
|
|
|
get _chromeless() {
|
|
|
|
// Is this a popup window that doesn't want chrome shown?
|
|
|
|
let docElem = document.documentElement;
|
2013-06-14 20:39:42 +00:00
|
|
|
// extrachrome is not restored during session restore, so we need
|
|
|
|
// to check for the toolbar as well.
|
2015-04-29 15:32:05 +00:00
|
|
|
let chromeless = docElem.getAttribute("chromehidden").includes("extrachrome") ||
|
|
|
|
docElem.getAttribute('chromehidden').includes("toolbar");
|
2013-01-24 10:14:36 +00:00
|
|
|
// This property is "fixed" for a window, so avoid doing the check above
|
|
|
|
// multiple times...
|
|
|
|
delete this._chromeless;
|
|
|
|
this._chromeless = chromeless;
|
|
|
|
return chromeless;
|
|
|
|
},
|
|
|
|
|
|
|
|
get enabled() {
|
|
|
|
// Returns whether social is enabled *for this window*.
|
2013-01-29 18:12:13 +00:00
|
|
|
if (this._chromeless || PrivateBrowsingUtils.isWindowPrivate(window))
|
2013-01-24 10:14:36 +00:00
|
|
|
return false;
|
2014-03-12 02:25:45 +00:00
|
|
|
return Social.providers.length > 0;
|
2013-01-24 10:14:36 +00:00
|
|
|
},
|
|
|
|
|
2014-10-09 19:02:13 +00:00
|
|
|
canShareOrMarkPage: function(aURI) {
|
|
|
|
// Bug 898706 we do not enable social in private sessions since frameworker
|
|
|
|
// would be shared between private and non-private windows
|
|
|
|
if (PrivateBrowsingUtils.isWindowPrivate(window))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (aURI && (aURI.schemeIs('http') || aURI.schemeIs('https')));
|
|
|
|
},
|
|
|
|
|
|
|
|
onCustomizeEnd: function(aWindow) {
|
|
|
|
if (aWindow != window)
|
2014-08-21 14:41:23 +00:00
|
|
|
return;
|
2014-10-09 19:02:13 +00:00
|
|
|
// customization mode gets buttons out of sync with command updating, fix
|
|
|
|
// the disabled state
|
|
|
|
let canShare = this.canShareOrMarkPage(gBrowser.currentURI);
|
|
|
|
let shareButton = SocialShare.shareButton;
|
|
|
|
if (shareButton) {
|
|
|
|
if (canShare) {
|
|
|
|
shareButton.removeAttribute("disabled")
|
|
|
|
} else {
|
|
|
|
shareButton.setAttribute("disabled", "true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// update the disabled state of the button based on the command
|
|
|
|
for (let node of SocialMarks.nodes) {
|
|
|
|
if (canShare) {
|
|
|
|
node.removeAttribute("disabled")
|
|
|
|
} else {
|
|
|
|
node.setAttribute("disabled", "true")
|
|
|
|
}
|
|
|
|
}
|
2014-08-21 14:41:23 +00:00
|
|
|
},
|
|
|
|
|
2013-09-06 17:56:01 +00:00
|
|
|
// called on tab/urlbar/location changes and after customization. Update
|
|
|
|
// anything that is tab specific.
|
|
|
|
updateState: function() {
|
2014-10-09 19:02:13 +00:00
|
|
|
if (location == "about:customizing")
|
|
|
|
return;
|
|
|
|
goSetCommandEnabled("Social:PageShareOrMark", this.canShareOrMarkPage(gBrowser.currentURI));
|
2014-05-19 16:38:38 +00:00
|
|
|
if (!SocialUI.enabled)
|
2013-09-06 17:56:01 +00:00
|
|
|
return;
|
2014-10-09 19:02:13 +00:00
|
|
|
// larger update that may change button icons
|
2013-09-06 17:56:01 +00:00
|
|
|
SocialMarks.update();
|
|
|
|
}
|
2012-07-12 01:31:19 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 01:22:27 +00:00
|
|
|
// message manager handlers
|
|
|
|
SocialActivationListener = {
|
|
|
|
init: function() {
|
|
|
|
messageManager.addMessageListener("Social:Activation", this);
|
|
|
|
},
|
|
|
|
uninit: function() {
|
|
|
|
messageManager.removeMessageListener("Social:Activation", this);
|
|
|
|
},
|
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
let data = aMessage.json;
|
|
|
|
let browser = aMessage.target;
|
|
|
|
data.window = window;
|
|
|
|
// if the source if the message is the share panel, we do a one-click
|
|
|
|
// installation. The source of activations is controlled by the
|
|
|
|
// social.directories preference
|
|
|
|
let options;
|
|
|
|
if (browser == SocialShare.iframe && Services.prefs.getBoolPref("social.share.activationPanelEnabled")) {
|
|
|
|
options = { bypassContentCheck: true, bypassInstallPanel: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are in PB mode, we silently do nothing (bug 829404 exists to
|
|
|
|
// do something sensible here...)
|
|
|
|
if (PrivateBrowsingUtils.isWindowPrivate(window))
|
|
|
|
return;
|
|
|
|
Social.installProvider(data, function(manifest) {
|
|
|
|
Social.activateFromOrigin(manifest.origin, function(provider) {
|
|
|
|
if (provider.sidebarURL) {
|
|
|
|
SocialSidebar.show(provider.origin);
|
|
|
|
}
|
|
|
|
if (provider.shareURL) {
|
|
|
|
// Ensure that the share button is somewhere usable.
|
|
|
|
// SocialShare.shareButton may return null if it is in the menu-panel
|
|
|
|
// and has never been visible, so we check the widget directly. If
|
|
|
|
// there is no area for the widget we move it into the toolbar.
|
|
|
|
let widget = CustomizableUI.getWidget("social-share-button");
|
2015-06-04 16:24:45 +00:00
|
|
|
// If the panel is already open, we can be sure that the provider can
|
|
|
|
// already be accessed, possibly anchored to another toolbar button.
|
|
|
|
// In that case we don't move the widget.
|
|
|
|
if (!widget.areaType && SocialShare.panel.state != "open") {
|
2014-11-06 01:22:27 +00:00
|
|
|
CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
|
2015-06-04 16:24:45 +00:00
|
|
|
// Ensure correct state.
|
2014-11-06 01:22:27 +00:00
|
|
|
SocialUI.onCustomizeEnd(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
// make this new provider the selected provider. If the panel hasn't
|
|
|
|
// been opened, we need to make the frame first.
|
|
|
|
SocialShare._createFrame();
|
|
|
|
SocialShare.iframe.setAttribute('src', 'data:text/plain;charset=utf8,');
|
|
|
|
SocialShare.iframe.setAttribute('origin', provider.origin);
|
|
|
|
// get the right button selected
|
|
|
|
SocialShare.populateProviderMenu();
|
|
|
|
if (SocialShare.panel.state == "open") {
|
|
|
|
SocialShare.sharePage(provider.origin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (provider.postActivationURL) {
|
|
|
|
// if activated from an open share panel, we load the landing page in
|
|
|
|
// a background tab
|
|
|
|
gBrowser.loadOneTab(provider.postActivationURL, {inBackground: SocialShare.panel.state == "open"});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 23:15:59 +00:00
|
|
|
SocialFlyout = {
|
2012-08-24 00:11:02 +00:00
|
|
|
get panel() {
|
|
|
|
return document.getElementById("social-flyout-panel");
|
|
|
|
},
|
|
|
|
|
2013-05-31 20:22:51 +00:00
|
|
|
get iframe() {
|
|
|
|
if (!this.panel.firstChild)
|
|
|
|
this._createFrame();
|
|
|
|
return this.panel.firstChild;
|
|
|
|
},
|
|
|
|
|
2012-08-24 00:11:02 +00:00
|
|
|
dispatchPanelEvent: function(name) {
|
2013-05-31 20:22:51 +00:00
|
|
|
let doc = this.iframe.contentDocument;
|
2012-08-24 00:11:02 +00:00
|
|
|
let evt = doc.createEvent("CustomEvent");
|
|
|
|
evt.initCustomEvent(name, true, true, {});
|
|
|
|
doc.documentElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
|
|
|
_createFrame: function() {
|
|
|
|
let panel = this.panel;
|
2013-01-24 10:14:36 +00:00
|
|
|
if (!SocialUI.enabled || panel.firstChild)
|
2012-08-24 00:11:02 +00:00
|
|
|
return;
|
|
|
|
// create and initialize the panel for this window
|
2015-05-22 17:33:18 +00:00
|
|
|
let iframe = document.createElement("browser");
|
2012-08-24 00:11:02 +00:00
|
|
|
iframe.setAttribute("type", "content");
|
2012-09-06 23:13:37 +00:00
|
|
|
iframe.setAttribute("class", "social-panel-frame");
|
2012-08-24 00:11:02 +00:00
|
|
|
iframe.setAttribute("flex", "1");
|
2015-05-22 17:33:18 +00:00
|
|
|
iframe.setAttribute("message", "true");
|
|
|
|
iframe.setAttribute("messagemanagergroup", "social");
|
2013-03-18 19:43:51 +00:00
|
|
|
iframe.setAttribute("tooltip", "aHTMLTooltip");
|
2015-05-22 17:33:18 +00:00
|
|
|
iframe.setAttribute("context", "contentAreaContextMenu");
|
2014-03-12 02:25:45 +00:00
|
|
|
iframe.setAttribute("origin", SocialSidebar.provider.origin);
|
2012-08-24 00:11:02 +00:00
|
|
|
panel.appendChild(iframe);
|
2015-05-22 17:33:18 +00:00
|
|
|
// the xbl bindings for the iframe probably don't exist yet, so we can't
|
|
|
|
// access iframe.messageManager directly - but can get at it with this dance.
|
|
|
|
let mm = iframe.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
|
|
|
|
mm.sendAsyncMessage("Social:SetErrorURL", null,
|
|
|
|
{ template: "about:socialerror?mode=compactInfo&origin=%{origin}" });
|
2012-10-06 00:22:09 +00:00
|
|
|
},
|
|
|
|
|
2012-08-24 00:11:02 +00:00
|
|
|
unload: function() {
|
|
|
|
let panel = this.panel;
|
2012-09-26 06:23:25 +00:00
|
|
|
panel.hidePopup();
|
2012-08-24 00:11:02 +00:00
|
|
|
if (!panel.firstChild)
|
|
|
|
return
|
2013-01-26 20:07:39 +00:00
|
|
|
let iframe = panel.firstChild;
|
|
|
|
panel.removeChild(iframe);
|
2012-08-24 00:11:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onShown: function(aEvent) {
|
2012-10-08 06:14:55 +00:00
|
|
|
let panel = this.panel;
|
2013-05-31 20:22:51 +00:00
|
|
|
let iframe = this.iframe;
|
2012-10-05 03:32:38 +00:00
|
|
|
this._dynamicResizer = new DynamicResizeWatcher();
|
2015-05-22 17:36:30 +00:00
|
|
|
iframe.docShellIsActive = true;
|
2012-08-24 00:11:02 +00:00
|
|
|
if (iframe.contentDocument.readyState == "complete") {
|
2012-10-08 06:14:55 +00:00
|
|
|
this._dynamicResizer.start(panel, iframe);
|
2012-08-24 00:11:02 +00:00
|
|
|
this.dispatchPanelEvent("socialFrameShow");
|
|
|
|
} else {
|
|
|
|
// first time load, wait for load and dispatch after load
|
|
|
|
iframe.addEventListener("load", function panelBrowserOnload(e) {
|
|
|
|
iframe.removeEventListener("load", panelBrowserOnload, true);
|
|
|
|
setTimeout(function() {
|
2012-11-27 06:56:22 +00:00
|
|
|
if (SocialFlyout._dynamicResizer) { // may go null if hidden quickly
|
|
|
|
SocialFlyout._dynamicResizer.start(panel, iframe);
|
|
|
|
SocialFlyout.dispatchPanelEvent("socialFrameShow");
|
|
|
|
}
|
2012-08-24 00:11:02 +00:00
|
|
|
}, 0);
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onHidden: function(aEvent) {
|
2012-10-05 03:32:38 +00:00
|
|
|
this._dynamicResizer.stop();
|
|
|
|
this._dynamicResizer = null;
|
2015-05-22 17:36:30 +00:00
|
|
|
this.iframe.docShellIsActive = false;
|
2012-08-24 00:11:02 +00:00
|
|
|
this.dispatchPanelEvent("socialFrameHide");
|
|
|
|
},
|
|
|
|
|
2013-05-31 20:22:51 +00:00
|
|
|
load: function(aURL, cb) {
|
2014-03-12 02:25:45 +00:00
|
|
|
if (!SocialSidebar.provider)
|
2013-05-31 20:22:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
this.panel.hidden = false;
|
|
|
|
let iframe = this.iframe;
|
|
|
|
// same url with only ref difference does not cause a new load, so we
|
|
|
|
// want to go right to the callback
|
|
|
|
let src = iframe.contentDocument && iframe.contentDocument.documentURIObject;
|
|
|
|
if (!src || !src.equalsExceptRef(Services.io.newURI(aURL, null, null))) {
|
|
|
|
iframe.addEventListener("load", function documentLoaded() {
|
|
|
|
iframe.removeEventListener("load", documentLoaded, true);
|
|
|
|
cb();
|
|
|
|
}, true);
|
|
|
|
iframe.setAttribute("src", aURL);
|
|
|
|
} else {
|
|
|
|
// we still need to set the src to trigger the contents hashchange event
|
|
|
|
// for ref changes
|
|
|
|
iframe.setAttribute("src", aURL);
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-24 00:11:02 +00:00
|
|
|
open: function(aURL, yOffset, aCallback) {
|
2012-10-22 00:28:37 +00:00
|
|
|
// Hide any other social panels that may be open.
|
|
|
|
document.getElementById("social-notification-panel").hidePopup();
|
|
|
|
|
2013-01-24 10:14:36 +00:00
|
|
|
if (!SocialUI.enabled)
|
2012-08-24 00:11:02 +00:00
|
|
|
return;
|
|
|
|
let panel = this.panel;
|
2013-05-31 20:22:51 +00:00
|
|
|
let iframe = this.iframe;
|
2012-08-24 00:11:02 +00:00
|
|
|
|
2013-05-31 20:22:51 +00:00
|
|
|
this.load(aURL, function() {
|
|
|
|
sizeSocialPanelToContent(panel, iframe);
|
|
|
|
let anchor = document.getElementById("social-sidebar-browser");
|
|
|
|
if (panel.state == "open") {
|
|
|
|
panel.moveToAnchor(anchor, "start_before", 0, yOffset, false);
|
|
|
|
} else {
|
|
|
|
panel.openPopup(anchor, "start_before", 0, yOffset, false, false);
|
|
|
|
}
|
|
|
|
if (aCallback) {
|
|
|
|
try {
|
|
|
|
aCallback(iframe.contentWindow);
|
|
|
|
} catch(e) {
|
|
|
|
Cu.reportError(e);
|
2012-08-24 00:11:02 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-31 20:22:51 +00:00
|
|
|
});
|
2012-08-24 00:11:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
SocialShare = {
|
2014-10-09 19:01:39 +00:00
|
|
|
get _dynamicResizer() {
|
|
|
|
delete this._dynamicResizer;
|
|
|
|
this._dynamicResizer = new DynamicResizeWatcher();
|
|
|
|
return this._dynamicResizer;
|
|
|
|
},
|
|
|
|
|
2014-05-19 16:38:38 +00:00
|
|
|
// Share panel may be attached to the overflow or menu button depending on
|
|
|
|
// customization, we need to manage open state of the anchor.
|
|
|
|
get anchor() {
|
|
|
|
let widget = CustomizableUI.getWidget("social-share-button");
|
|
|
|
return widget.forWindow(window).anchor;
|
|
|
|
},
|
2015-06-04 16:24:45 +00:00
|
|
|
// Holds the anchor node in use whilst the panel is open, because it may vary.
|
|
|
|
_currentAnchor: null,
|
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
get panel() {
|
|
|
|
return document.getElementById("social-share-panel");
|
|
|
|
},
|
|
|
|
|
|
|
|
get iframe() {
|
2014-12-23 00:11:56 +00:00
|
|
|
// panel.firstChild is our toolbar hbox, panel.lastChild is the iframe
|
|
|
|
// container hbox used for an interstitial "loading" graphic
|
|
|
|
return this.panel.lastChild.firstChild;
|
2013-05-07 06:02:58 +00:00
|
|
|
},
|
|
|
|
|
2013-11-01 11:52:07 +00:00
|
|
|
uninit: function () {
|
|
|
|
if (this.iframe) {
|
|
|
|
this.iframe.remove();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
_createFrame: function() {
|
|
|
|
let panel = this.panel;
|
2014-10-09 19:01:39 +00:00
|
|
|
if (this.iframe)
|
2013-05-07 06:02:58 +00:00
|
|
|
return;
|
|
|
|
this.panel.hidden = false;
|
|
|
|
// create and initialize the panel for this window
|
2014-07-31 01:32:07 +00:00
|
|
|
let iframe = document.createElement("browser");
|
2013-05-07 06:02:58 +00:00
|
|
|
iframe.setAttribute("type", "content");
|
|
|
|
iframe.setAttribute("class", "social-share-frame");
|
2013-07-29 17:53:00 +00:00
|
|
|
iframe.setAttribute("context", "contentAreaContextMenu");
|
|
|
|
iframe.setAttribute("tooltip", "aHTMLTooltip");
|
2014-07-31 01:32:07 +00:00
|
|
|
iframe.setAttribute("disableglobalhistory", "true");
|
2013-05-07 06:02:58 +00:00
|
|
|
iframe.setAttribute("flex", "1");
|
2015-05-22 17:33:18 +00:00
|
|
|
iframe.setAttribute("message", "true");
|
|
|
|
iframe.setAttribute("messagemanagergroup", "social");
|
2014-12-23 00:11:56 +00:00
|
|
|
panel.lastChild.appendChild(iframe);
|
2015-05-22 17:33:18 +00:00
|
|
|
let mm = iframe.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
|
|
|
|
mm.sendAsyncMessage("Social:SetErrorURL", null,
|
|
|
|
{ template: "about:socialerror?mode=compactInfo&origin=%{origin}&url=%{url}" });
|
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
this.populateProviderMenu();
|
|
|
|
},
|
2013-07-29 17:53:00 +00:00
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
getSelectedProvider: function() {
|
|
|
|
let provider;
|
|
|
|
let lastProviderOrigin = this.iframe && this.iframe.getAttribute("origin");
|
|
|
|
if (lastProviderOrigin) {
|
|
|
|
provider = Social._getProviderFromOrigin(lastProviderOrigin);
|
|
|
|
}
|
|
|
|
return provider;
|
|
|
|
},
|
|
|
|
|
2014-10-09 19:02:13 +00:00
|
|
|
createTooltip: function(event) {
|
|
|
|
let tt = event.target;
|
|
|
|
let provider = Social._getProviderFromOrigin(tt.triggerNode.getAttribute("origin"));
|
|
|
|
tt.firstChild.setAttribute("value", provider.name);
|
|
|
|
tt.lastChild.setAttribute("value", provider.origin);
|
|
|
|
},
|
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
populateProviderMenu: function() {
|
|
|
|
if (!this.iframe)
|
|
|
|
return;
|
2015-12-17 23:19:00 +00:00
|
|
|
let providers = Social.providers.filter(p => p.shareURL);
|
2013-05-07 06:02:58 +00:00
|
|
|
let hbox = document.getElementById("social-share-provider-buttons");
|
2014-10-09 19:01:39 +00:00
|
|
|
// remove everything before the add-share-provider button (which should also
|
|
|
|
// be lastChild if any share providers were added)
|
|
|
|
let addButton = document.getElementById("add-share-provider");
|
2014-12-23 00:11:56 +00:00
|
|
|
while (hbox.lastChild != addButton) {
|
|
|
|
hbox.removeChild(hbox.lastChild);
|
2013-05-07 06:02:58 +00:00
|
|
|
}
|
|
|
|
let selectedProvider = this.getSelectedProvider();
|
|
|
|
for (let provider of providers) {
|
|
|
|
let button = document.createElement("toolbarbutton");
|
2014-12-23 00:11:56 +00:00
|
|
|
button.setAttribute("class", "toolbarbutton-1 share-provider-button");
|
2013-05-07 06:02:58 +00:00
|
|
|
button.setAttribute("type", "radio");
|
|
|
|
button.setAttribute("group", "share-providers");
|
|
|
|
button.setAttribute("image", provider.iconURL);
|
2014-10-09 19:02:13 +00:00
|
|
|
button.setAttribute("tooltip", "share-button-tooltip");
|
2013-05-07 06:02:58 +00:00
|
|
|
button.setAttribute("origin", provider.origin);
|
2014-12-10 22:38:40 +00:00
|
|
|
button.setAttribute("label", provider.name);
|
2014-10-09 19:01:39 +00:00
|
|
|
button.setAttribute("oncommand", "SocialShare.sharePage(this.getAttribute('origin'));");
|
2013-05-07 06:02:58 +00:00
|
|
|
if (provider == selectedProvider) {
|
|
|
|
this.defaultButton = button;
|
|
|
|
}
|
2014-12-23 00:11:56 +00:00
|
|
|
hbox.appendChild(button);
|
2013-05-07 06:02:58 +00:00
|
|
|
}
|
|
|
|
if (!this.defaultButton) {
|
2014-10-09 19:01:39 +00:00
|
|
|
this.defaultButton = addButton;
|
2013-05-07 06:02:58 +00:00
|
|
|
}
|
|
|
|
this.defaultButton.setAttribute("checked", "true");
|
|
|
|
},
|
|
|
|
|
|
|
|
get shareButton() {
|
2014-05-19 16:38:38 +00:00
|
|
|
// web-panels (bookmark/sidebar) don't include customizableui, so
|
|
|
|
// nsContextMenu fails when accessing shareButton, breaking
|
|
|
|
// browser_bug409481.js.
|
|
|
|
if (!window.CustomizableUI)
|
|
|
|
return null;
|
|
|
|
let widget = CustomizableUI.getWidget("social-share-button");
|
|
|
|
if (!widget || !widget.areaType)
|
|
|
|
return null;
|
|
|
|
return widget.forWindow(window).node;
|
2013-05-07 06:02:58 +00:00
|
|
|
},
|
|
|
|
|
2014-07-17 02:15:02 +00:00
|
|
|
_onclick: function() {
|
|
|
|
Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(0);
|
|
|
|
},
|
2014-12-23 00:11:56 +00:00
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
onShowing: function() {
|
2015-06-04 16:24:45 +00:00
|
|
|
(this._currentAnchor || this.anchor).setAttribute("open", "true");
|
2014-07-17 02:15:02 +00:00
|
|
|
this.iframe.addEventListener("click", this._onclick, true);
|
2013-05-07 06:02:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onHidden: function() {
|
2015-06-04 16:24:45 +00:00
|
|
|
(this._currentAnchor || this.anchor).removeAttribute("open");
|
|
|
|
this._currentAnchor = null;
|
2014-07-17 02:15:02 +00:00
|
|
|
this.iframe.removeEventListener("click", this._onclick, true);
|
2013-08-30 16:30:00 +00:00
|
|
|
this.iframe.setAttribute("src", "data:text/plain;charset=utf8,");
|
2014-07-31 01:32:07 +00:00
|
|
|
// make sure that the frame is unloaded after it is hidden
|
|
|
|
this.iframe.docShell.createAboutBlankContentViewer(null);
|
2013-05-07 06:02:58 +00:00
|
|
|
this.currentShare = null;
|
2014-07-31 01:32:07 +00:00
|
|
|
// share panel use is over, purge any history
|
|
|
|
if (this.iframe.sessionHistory) {
|
|
|
|
let purge = this.iframe.sessionHistory.count;
|
|
|
|
if (purge > 0)
|
|
|
|
this.iframe.sessionHistory.PurgeHistory(purge);
|
|
|
|
}
|
2013-05-07 06:02:58 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 16:24:45 +00:00
|
|
|
sharePage: function(providerOrigin, graphData, target, anchor) {
|
2013-05-07 06:02:58 +00:00
|
|
|
// if providerOrigin is undefined, we use the last-used provider, or the
|
|
|
|
// current/default provider. The provider selection in the share panel
|
|
|
|
// will call sharePage with an origin for us to switch to.
|
|
|
|
this._createFrame();
|
|
|
|
let iframe = this.iframe;
|
|
|
|
|
|
|
|
// graphData is an optional param that either defines the full set of data
|
|
|
|
// to be shared, or partial data about the current page. It is set by a call
|
|
|
|
// in mozSocial API, or via nsContentMenu calls. If it is present, it MUST
|
|
|
|
// define at least url. If it is undefined, we're sharing the current url in
|
|
|
|
// the browser tab.
|
2014-07-11 15:50:34 +00:00
|
|
|
let pageData = graphData ? graphData : this.currentShare;
|
|
|
|
let sharedURI = pageData ? Services.io.newURI(pageData.url, null, null) :
|
2013-05-07 06:02:58 +00:00
|
|
|
gBrowser.currentURI;
|
2014-10-09 19:02:13 +00:00
|
|
|
if (!SocialUI.canShareOrMarkPage(sharedURI))
|
2013-05-07 06:02:58 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// the point of this action type is that we can use existing share
|
|
|
|
// endpoints (e.g. oexchange) that do not support additional
|
|
|
|
// socialapi functionality. One tweak is that we shoot an event
|
|
|
|
// containing the open graph data.
|
2014-11-06 01:26:36 +00:00
|
|
|
let _dataFn;
|
2013-05-07 06:02:58 +00:00
|
|
|
if (!pageData || sharedURI == gBrowser.currentURI) {
|
2015-03-05 22:43:05 +00:00
|
|
|
messageManager.addMessageListener("PageMetadata:PageDataResult", _dataFn = (msg) => {
|
|
|
|
messageManager.removeMessageListener("PageMetadata:PageDataResult", _dataFn);
|
2014-11-06 01:26:36 +00:00
|
|
|
let pageData = msg.json;
|
|
|
|
if (graphData) {
|
|
|
|
// overwrite data retreived from page with data given to us as a param
|
|
|
|
for (let p in graphData) {
|
|
|
|
pageData[p] = graphData[p];
|
|
|
|
}
|
2013-05-07 06:02:58 +00:00
|
|
|
}
|
2015-06-04 16:24:45 +00:00
|
|
|
this.sharePage(providerOrigin, pageData, target, anchor);
|
2014-11-06 01:26:36 +00:00
|
|
|
});
|
2015-03-05 22:43:05 +00:00
|
|
|
gBrowser.selectedBrowser.messageManager.sendAsyncMessage("PageMetadata:GetPageData");
|
2014-11-06 01:26:36 +00:00
|
|
|
return;
|
2013-05-07 06:02:58 +00:00
|
|
|
}
|
2014-07-11 15:50:34 +00:00
|
|
|
// if this is a share of a selected item, get any microdata
|
|
|
|
if (!pageData.microdata && target) {
|
2015-03-05 22:43:05 +00:00
|
|
|
messageManager.addMessageListener("PageMetadata:MicrodataResult", _dataFn = (msg) => {
|
|
|
|
messageManager.removeMessageListener("PageMetadata:MicrodataResult", _dataFn);
|
2014-11-06 01:26:36 +00:00
|
|
|
pageData.microdata = msg.data;
|
2015-06-04 16:24:45 +00:00
|
|
|
this.sharePage(providerOrigin, pageData, target, anchor);
|
2014-11-06 01:26:36 +00:00
|
|
|
});
|
2015-03-11 21:19:30 +00:00
|
|
|
gBrowser.selectedBrowser.messageManager.sendAsyncMessage("PageMetadata:GetMicrodata", null, { target });
|
2014-11-06 01:26:36 +00:00
|
|
|
return;
|
2014-07-11 15:50:34 +00:00
|
|
|
}
|
2013-05-07 06:02:58 +00:00
|
|
|
this.currentShare = pageData;
|
|
|
|
|
2014-10-09 19:01:39 +00:00
|
|
|
let provider;
|
|
|
|
if (providerOrigin)
|
|
|
|
provider = Social._getProviderFromOrigin(providerOrigin);
|
|
|
|
else
|
|
|
|
provider = this.getSelectedProvider();
|
|
|
|
if (!provider || !provider.shareURL) {
|
2015-06-04 16:24:45 +00:00
|
|
|
this.showDirectory(anchor);
|
2014-10-09 19:01:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// check the menu button
|
|
|
|
let hbox = document.getElementById("social-share-provider-buttons");
|
|
|
|
let btn = hbox.querySelector("[origin='" + provider.origin + "']");
|
|
|
|
if (btn)
|
|
|
|
btn.checked = true;
|
|
|
|
|
2013-09-06 17:56:01 +00:00
|
|
|
let shareEndpoint = OpenGraphBuilder.generateEndpointURL(provider.shareURL, pageData);
|
2013-05-07 06:02:58 +00:00
|
|
|
|
2014-12-23 00:11:56 +00:00
|
|
|
this._dynamicResizer.stop();
|
2014-05-13 18:10:47 +00:00
|
|
|
let size = provider.getPageSize("share");
|
|
|
|
if (size) {
|
2014-12-23 00:11:56 +00:00
|
|
|
// let the css on the share panel define width, but height
|
|
|
|
// calculations dont work on all sites, so we allow that to be
|
|
|
|
// defined.
|
|
|
|
delete size.width;
|
2014-05-13 18:10:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
// if we've already loaded this provider/page share endpoint, we don't want
|
|
|
|
// to add another load event listener.
|
|
|
|
let endpointMatch = shareEndpoint == iframe.getAttribute("src");
|
2014-12-23 00:11:56 +00:00
|
|
|
if (endpointMatch) {
|
|
|
|
this._dynamicResizer.start(iframe.parentNode, iframe, size);
|
2015-05-22 17:36:30 +00:00
|
|
|
iframe.docShellIsActive = true;
|
2013-05-07 06:02:58 +00:00
|
|
|
let evt = iframe.contentDocument.createEvent("CustomEvent");
|
|
|
|
evt.initCustomEvent("OpenGraphData", true, true, JSON.stringify(pageData));
|
|
|
|
iframe.contentDocument.documentElement.dispatchEvent(evt);
|
|
|
|
} else {
|
2014-12-23 00:11:56 +00:00
|
|
|
iframe.parentNode.setAttribute("loading", "true");
|
2013-05-07 06:02:58 +00:00
|
|
|
// first time load, wait for load and dispatch after load
|
|
|
|
iframe.addEventListener("load", function panelBrowserOnload(e) {
|
|
|
|
iframe.removeEventListener("load", panelBrowserOnload, true);
|
2015-05-22 17:36:30 +00:00
|
|
|
iframe.docShellIsActive = true;
|
2014-12-23 00:11:56 +00:00
|
|
|
iframe.parentNode.removeAttribute("loading");
|
2014-05-13 18:10:47 +00:00
|
|
|
// to support standard share endpoints mimick window.open by setting
|
|
|
|
// window.opener, some share endpoints rely on w.opener to know they
|
|
|
|
// should close the window when done.
|
|
|
|
iframe.contentWindow.opener = iframe.contentWindow;
|
2014-12-23 00:11:56 +00:00
|
|
|
|
|
|
|
SocialShare._dynamicResizer.start(iframe.parentNode, iframe, size);
|
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
let evt = iframe.contentDocument.createEvent("CustomEvent");
|
|
|
|
evt.initCustomEvent("OpenGraphData", true, true, JSON.stringify(pageData));
|
|
|
|
iframe.contentDocument.documentElement.dispatchEvent(evt);
|
|
|
|
}, true);
|
|
|
|
}
|
2014-07-31 01:32:07 +00:00
|
|
|
// if the user switched between share providers we do not want that history
|
|
|
|
// available.
|
|
|
|
if (iframe.sessionHistory) {
|
|
|
|
let purge = iframe.sessionHistory.count;
|
|
|
|
if (purge > 0)
|
|
|
|
iframe.sessionHistory.PurgeHistory(purge);
|
|
|
|
}
|
|
|
|
|
2013-05-07 06:02:58 +00:00
|
|
|
// always ensure that origin belongs to the endpoint
|
|
|
|
let uri = Services.io.newURI(shareEndpoint, null, null);
|
|
|
|
iframe.setAttribute("origin", provider.origin);
|
|
|
|
iframe.setAttribute("src", shareEndpoint);
|
2015-06-04 16:24:45 +00:00
|
|
|
this._openPanel(anchor);
|
2014-10-09 19:01:39 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 16:24:45 +00:00
|
|
|
showDirectory: function(anchor) {
|
2014-10-09 19:01:39 +00:00
|
|
|
this._createFrame();
|
|
|
|
let iframe = this.iframe;
|
2014-12-23 00:11:56 +00:00
|
|
|
if (iframe.getAttribute("src") == "about:providerdirectory")
|
|
|
|
return;
|
2014-10-09 19:01:39 +00:00
|
|
|
iframe.removeAttribute("origin");
|
2014-12-23 00:11:56 +00:00
|
|
|
iframe.parentNode.setAttribute("loading", "true");
|
|
|
|
iframe.addEventListener("DOMContentLoaded", function _dcl(e) {
|
|
|
|
iframe.removeEventListener("DOMContentLoaded", _dcl, true);
|
|
|
|
iframe.parentNode.removeAttribute("loading");
|
|
|
|
}, true);
|
|
|
|
|
2014-10-09 19:01:39 +00:00
|
|
|
iframe.addEventListener("load", function panelBrowserOnload(e) {
|
|
|
|
iframe.removeEventListener("load", panelBrowserOnload, true);
|
2014-12-23 00:11:56 +00:00
|
|
|
|
2014-10-09 19:01:39 +00:00
|
|
|
hookWindowCloseForPanelClose(iframe.contentWindow);
|
|
|
|
SocialShare._dynamicResizer.start(iframe.parentNode, iframe);
|
|
|
|
|
|
|
|
iframe.addEventListener("unload", function panelBrowserOnload(e) {
|
|
|
|
iframe.removeEventListener("unload", panelBrowserOnload, true);
|
|
|
|
SocialShare._dynamicResizer.stop();
|
|
|
|
}, true);
|
|
|
|
}, true);
|
|
|
|
iframe.setAttribute("src", "about:providerdirectory");
|
2015-06-04 16:24:45 +00:00
|
|
|
this._openPanel(anchor);
|
2014-10-09 19:01:39 +00:00
|
|
|
},
|
2013-05-07 06:02:58 +00:00
|
|
|
|
2015-06-04 16:24:45 +00:00
|
|
|
_openPanel: function(anchor) {
|
|
|
|
this._currentAnchor = anchor || this.anchor;
|
|
|
|
anchor = document.getAnonymousElementByAttribute(this._currentAnchor, "class", "toolbarbutton-icon");
|
2013-05-07 06:02:58 +00:00
|
|
|
this.panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
|
2014-07-17 02:15:02 +00:00
|
|
|
Services.telemetry.getHistogramById("SOCIAL_TOOLBAR_BUTTONS").add(0);
|
2013-05-07 06:02:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-26 23:15:59 +00:00
|
|
|
SocialSidebar = {
|
2014-07-17 02:15:02 +00:00
|
|
|
_openStartTime: 0,
|
|
|
|
|
2012-07-18 18:40:05 +00:00
|
|
|
// Whether the sidebar can be shown for this window.
|
|
|
|
get canShow() {
|
2014-03-12 02:25:45 +00:00
|
|
|
if (!SocialUI.enabled || document.mozFullScreen)
|
2013-12-17 05:37:30 +00:00
|
|
|
return false;
|
2014-03-12 02:25:45 +00:00
|
|
|
return Social.providers.some(p => p.sidebarURL);
|
2012-07-18 18:40:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Whether the user has toggled the sidebar on (for windows where it can appear)
|
2012-10-03 23:11:52 +00:00
|
|
|
get opened() {
|
2014-03-12 02:25:45 +00:00
|
|
|
let broadcaster = document.getElementById("socialSidebarBroadcaster");
|
|
|
|
return !broadcaster.hidden;
|
|
|
|
},
|
|
|
|
|
|
|
|
restoreWindowState: function() {
|
2014-06-25 20:15:08 +00:00
|
|
|
// Window state is used to allow different sidebar providers in each window.
|
|
|
|
// We also store the provider used in a pref as the default sidebar to
|
|
|
|
// maintain that state for users who do not restore window state. The
|
|
|
|
// existence of social.sidebar.provider means the sidebar is open with that
|
|
|
|
// provider.
|
2014-03-12 02:25:45 +00:00
|
|
|
this._initialized = true;
|
|
|
|
if (!this.canShow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Services.prefs.prefHasUserValue("social.provider.current")) {
|
|
|
|
// "upgrade" when the first window opens if we have old prefs. We get the
|
|
|
|
// values from prefs this one time, window state will be saved when this
|
|
|
|
// window is closed.
|
|
|
|
let origin = Services.prefs.getCharPref("social.provider.current");
|
|
|
|
Services.prefs.clearUserPref("social.provider.current");
|
|
|
|
// social.sidebar.open default was true, but we only opened if there was
|
|
|
|
// a current provider
|
|
|
|
let opened = origin && true;
|
|
|
|
if (Services.prefs.prefHasUserValue("social.sidebar.open")) {
|
|
|
|
opened = origin && Services.prefs.getBoolPref("social.sidebar.open");
|
|
|
|
Services.prefs.clearUserPref("social.sidebar.open");
|
|
|
|
}
|
|
|
|
let data = {
|
|
|
|
"hidden": !opened,
|
|
|
|
"origin": origin
|
|
|
|
};
|
|
|
|
SessionStore.setWindowValue(window, "socialSidebar", JSON.stringify(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = SessionStore.getWindowValue(window, "socialSidebar");
|
|
|
|
// if this window doesn't have it's own state, use the state from the opener
|
|
|
|
if (!data && window.opener && !window.opener.closed) {
|
2014-06-25 20:15:08 +00:00
|
|
|
try {
|
|
|
|
data = SessionStore.getWindowValue(window.opener, "socialSidebar");
|
|
|
|
} catch(e) {
|
|
|
|
// Window is not tracked, which happens on osx if the window is opened
|
|
|
|
// from the hidden window. That happens when you close the last window
|
|
|
|
// without quiting firefox, then open a new window.
|
|
|
|
}
|
2014-03-12 02:25:45 +00:00
|
|
|
}
|
|
|
|
if (data) {
|
|
|
|
data = JSON.parse(data);
|
|
|
|
document.getElementById("social-sidebar-browser").setAttribute("origin", data.origin);
|
|
|
|
if (!data.hidden)
|
|
|
|
this.show(data.origin);
|
2014-06-25 20:15:08 +00:00
|
|
|
} else if (Services.prefs.prefHasUserValue("social.sidebar.provider")) {
|
|
|
|
// no window state, use the global state if it is available
|
|
|
|
this.show(Services.prefs.getCharPref("social.sidebar.provider"));
|
2014-03-12 02:25:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
saveWindowState: function() {
|
|
|
|
let broadcaster = document.getElementById("socialSidebarBroadcaster");
|
|
|
|
let sidebarOrigin = document.getElementById("social-sidebar-browser").getAttribute("origin");
|
|
|
|
let data = {
|
|
|
|
"hidden": broadcaster.hidden,
|
|
|
|
"origin": sidebarOrigin
|
|
|
|
};
|
2014-07-17 02:15:02 +00:00
|
|
|
if (broadcaster.hidden) {
|
|
|
|
Services.telemetry.getHistogramById("SOCIAL_SIDEBAR_OPEN_DURATION").add(Date.now() / 1000 - this._openStartTime);
|
|
|
|
} else {
|
|
|
|
this._openStartTime = Date.now() / 1000;
|
|
|
|
}
|
2014-06-25 20:15:08 +00:00
|
|
|
|
|
|
|
// Save a global state for users who do not restore state.
|
|
|
|
if (broadcaster.hidden)
|
|
|
|
Services.prefs.clearUserPref("social.sidebar.provider");
|
|
|
|
else
|
|
|
|
Services.prefs.setCharPref("social.sidebar.provider", sidebarOrigin);
|
|
|
|
|
|
|
|
try {
|
|
|
|
SessionStore.setWindowValue(window, "socialSidebar", JSON.stringify(data));
|
|
|
|
} catch(e) {
|
|
|
|
// window not tracked during uninit
|
|
|
|
}
|
2012-07-18 18:40:05 +00:00
|
|
|
},
|
|
|
|
|
2012-10-30 03:52:56 +00:00
|
|
|
setSidebarVisibilityState: function(aEnabled) {
|
2012-08-03 21:42:40 +00:00
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
2012-11-14 04:27:41 +00:00
|
|
|
// it's possible we'll be called twice with aEnabled=false so let's
|
|
|
|
// just assume we may often be called with the same state.
|
|
|
|
if (aEnabled == sbrowser.docShellIsActive)
|
|
|
|
return;
|
|
|
|
sbrowser.docShellIsActive = aEnabled;
|
2012-08-03 21:42:40 +00:00
|
|
|
let evt = sbrowser.contentDocument.createEvent("CustomEvent");
|
2012-10-30 03:52:56 +00:00
|
|
|
evt.initCustomEvent(aEnabled ? "socialFrameShow" : "socialFrameHide", true, true, {});
|
2012-08-03 21:42:40 +00:00
|
|
|
sbrowser.contentDocument.documentElement.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
2013-12-17 05:37:30 +00:00
|
|
|
updateToggleNotifications: function() {
|
|
|
|
let command = document.getElementById("Social:ToggleNotifications");
|
|
|
|
command.setAttribute("checked", Services.prefs.getBoolPref("social.toast-notifications.enabled"));
|
|
|
|
command.setAttribute("hidden", !SocialUI.enabled);
|
|
|
|
},
|
|
|
|
|
2012-11-13 03:52:06 +00:00
|
|
|
update: function SocialSidebar_update() {
|
2014-03-12 02:25:45 +00:00
|
|
|
// ensure we never update before restoreWindowState
|
|
|
|
if (!this._initialized)
|
|
|
|
return;
|
|
|
|
this.ensureProvider();
|
2013-12-17 05:37:30 +00:00
|
|
|
this.updateToggleNotifications();
|
|
|
|
this._updateHeader();
|
2012-10-24 00:09:59 +00:00
|
|
|
clearTimeout(this._unloadTimeoutId);
|
2012-07-18 18:40:05 +00:00
|
|
|
// Hide the toggle menu item if the sidebar cannot appear
|
|
|
|
let command = document.getElementById("Social:ToggleSidebar");
|
2012-10-23 07:47:33 +00:00
|
|
|
command.setAttribute("hidden", this.canShow ? "false" : "true");
|
2012-07-18 18:40:05 +00:00
|
|
|
|
|
|
|
// Hide the sidebar if it cannot appear, or has been toggled off.
|
|
|
|
// Also set the command "checked" state accordingly.
|
2012-10-03 23:11:52 +00:00
|
|
|
let hideSidebar = !this.canShow || !this.opened;
|
2012-07-18 18:40:05 +00:00
|
|
|
let broadcaster = document.getElementById("socialSidebarBroadcaster");
|
|
|
|
broadcaster.hidden = hideSidebar;
|
|
|
|
command.setAttribute("checked", !hideSidebar);
|
|
|
|
|
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
2012-12-08 04:13:27 +00:00
|
|
|
|
2012-08-03 21:42:40 +00:00
|
|
|
if (hideSidebar) {
|
2012-11-05 23:26:33 +00:00
|
|
|
sbrowser.removeEventListener("load", SocialSidebar._loadListener, true);
|
2012-10-30 03:52:56 +00:00
|
|
|
this.setSidebarVisibilityState(false);
|
2012-10-24 00:09:59 +00:00
|
|
|
// If we've been disabled, unload the sidebar content immediately;
|
|
|
|
// if the sidebar was just toggled to invisible, wait a timeout
|
|
|
|
// before unloading.
|
2012-08-03 21:42:40 +00:00
|
|
|
if (!this.canShow) {
|
2012-10-24 00:09:59 +00:00
|
|
|
this.unloadSidebar();
|
|
|
|
} else {
|
|
|
|
this._unloadTimeoutId = setTimeout(
|
|
|
|
this.unloadSidebar,
|
|
|
|
Services.prefs.getIntPref("social.sidebar.unload_timeout_ms")
|
|
|
|
);
|
2012-08-03 21:42:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-03-12 02:25:45 +00:00
|
|
|
sbrowser.setAttribute("origin", this.provider.origin);
|
2012-10-30 20:10:04 +00:00
|
|
|
|
2012-08-03 21:42:40 +00:00
|
|
|
// Make sure the right sidebar URL is loaded
|
2014-03-12 02:25:45 +00:00
|
|
|
if (sbrowser.getAttribute("src") != this.provider.sidebarURL) {
|
2013-12-17 05:37:30 +00:00
|
|
|
// we check readyState right after setting src, we need a new content
|
|
|
|
// viewer to ensure we are checking against the correct document.
|
|
|
|
sbrowser.docShell.createAboutBlankContentViewer(null);
|
2014-03-12 02:25:45 +00:00
|
|
|
sbrowser.setAttribute("src", this.provider.sidebarURL);
|
2013-07-29 16:35:41 +00:00
|
|
|
PopupNotifications.locationChange(sbrowser);
|
2013-07-29 16:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if the document has not loaded, delay until it is
|
|
|
|
if (sbrowser.contentDocument.readyState != "complete") {
|
2013-12-17 05:37:30 +00:00
|
|
|
document.getElementById("social-sidebar-button").setAttribute("loading", "true");
|
2012-11-05 23:26:33 +00:00
|
|
|
sbrowser.addEventListener("load", SocialSidebar._loadListener, true);
|
2012-08-03 21:42:40 +00:00
|
|
|
} else {
|
2012-10-30 03:52:56 +00:00
|
|
|
this.setSidebarVisibilityState(true);
|
2012-08-03 21:42:40 +00:00
|
|
|
}
|
2012-07-18 18:40:05 +00:00
|
|
|
}
|
2013-12-17 05:37:30 +00:00
|
|
|
this._updateCheckedMenuItems(this.opened && this.provider ? this.provider.origin : null);
|
2012-10-06 00:22:09 +00:00
|
|
|
},
|
|
|
|
|
2014-07-17 02:15:02 +00:00
|
|
|
_onclick: function() {
|
|
|
|
Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(3);
|
|
|
|
},
|
|
|
|
|
2012-11-05 23:26:33 +00:00
|
|
|
_loadListener: function SocialSidebar_loadListener() {
|
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
|
|
|
sbrowser.removeEventListener("load", SocialSidebar._loadListener, true);
|
2013-12-17 05:37:30 +00:00
|
|
|
document.getElementById("social-sidebar-button").removeAttribute("loading");
|
2012-11-05 23:26:33 +00:00
|
|
|
SocialSidebar.setSidebarVisibilityState(true);
|
2014-07-17 02:15:02 +00:00
|
|
|
sbrowser.addEventListener("click", SocialSidebar._onclick, true);
|
2012-11-05 23:26:33 +00:00
|
|
|
},
|
|
|
|
|
2012-10-24 00:09:59 +00:00
|
|
|
unloadSidebar: function SocialSidebar_unloadSidebar() {
|
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
|
|
|
if (!sbrowser.hasAttribute("origin"))
|
|
|
|
return;
|
|
|
|
|
2014-07-17 02:15:02 +00:00
|
|
|
sbrowser.removeEventListener("click", SocialSidebar._onclick, true);
|
2012-12-13 01:13:09 +00:00
|
|
|
sbrowser.stop();
|
2012-10-24 00:09:59 +00:00
|
|
|
sbrowser.removeAttribute("origin");
|
2012-11-17 00:59:46 +00:00
|
|
|
sbrowser.setAttribute("src", "about:blank");
|
2013-11-28 03:23:10 +00:00
|
|
|
// We need to explicitly create a new content viewer because the old one
|
|
|
|
// doesn't get destroyed until about:blank has loaded (which does not happen
|
|
|
|
// as long as the element is hidden).
|
|
|
|
sbrowser.docShell.createAboutBlankContentViewer(null);
|
2012-10-24 00:09:59 +00:00
|
|
|
SocialFlyout.unload();
|
|
|
|
},
|
|
|
|
|
|
|
|
_unloadTimeoutId: 0,
|
|
|
|
|
2015-05-22 17:33:18 +00:00
|
|
|
loadFrameworkerFailure: function() {
|
|
|
|
if (this.provider && this.provider.errorState == "frameworker-error") {
|
|
|
|
// we have to explicitly load this error page since it is not being
|
|
|
|
// handled via the normal error page paths.
|
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
|
|
|
sbrowser.setAttribute("src", "about:socialerror?mode=workerFailure&origin=" +
|
|
|
|
encodeURIComponent(this.provider.origin));
|
2012-10-30 20:10:04 +00:00
|
|
|
}
|
2013-12-17 05:37:30 +00:00
|
|
|
},
|
|
|
|
|
2014-03-12 02:25:45 +00:00
|
|
|
_provider: null,
|
|
|
|
ensureProvider: function() {
|
|
|
|
if (this._provider)
|
|
|
|
return;
|
|
|
|
// origin for sidebar is persisted, so get the previously selected sidebar
|
|
|
|
// first, otherwise fallback to the first provider in the list
|
|
|
|
let sbrowser = document.getElementById("social-sidebar-browser");
|
|
|
|
let origin = sbrowser.getAttribute("origin");
|
2015-12-17 23:19:00 +00:00
|
|
|
let providers = Social.providers.filter(p => p.sidebarURL);
|
2014-03-12 02:25:45 +00:00
|
|
|
let provider;
|
|
|
|
if (origin)
|
|
|
|
provider = Social._getProviderFromOrigin(origin);
|
|
|
|
if (!provider && providers.length > 0)
|
|
|
|
provider = providers[0];
|
|
|
|
if (provider)
|
|
|
|
this.provider = provider;
|
|
|
|
},
|
|
|
|
|
2013-12-17 05:37:30 +00:00
|
|
|
get provider() {
|
2014-03-12 02:25:45 +00:00
|
|
|
return this._provider;
|
2013-12-17 05:37:30 +00:00
|
|
|
},
|
|
|
|
|
2014-03-12 02:25:45 +00:00
|
|
|
set provider(provider) {
|
|
|
|
if (!provider || provider.sidebarURL) {
|
|
|
|
this._provider = provider;
|
|
|
|
this._updateHeader();
|
|
|
|
this._updateCheckedMenuItems(provider && provider.origin);
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
disableProvider: function(origin) {
|
|
|
|
if (this._provider && this._provider.origin == origin) {
|
|
|
|
this._provider = null;
|
|
|
|
// force a selection of the next provider if there is one
|
|
|
|
this.ensureProvider();
|
|
|
|
}
|
2013-12-17 05:37:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateHeader: function() {
|
|
|
|
let provider = this.provider;
|
|
|
|
let image, title;
|
|
|
|
if (provider) {
|
|
|
|
image = "url(" + (provider.icon32URL || provider.iconURL) + ")";
|
|
|
|
title = provider.name;
|
|
|
|
}
|
|
|
|
document.getElementById("social-sidebar-favico").style.listStyleImage = image;
|
|
|
|
document.getElementById("social-sidebar-title").value = title;
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateCheckedMenuItems: function(origin) {
|
|
|
|
// update selected menuitems
|
|
|
|
let menuitems = document.getElementsByClassName("social-provider-menuitem");
|
|
|
|
for (let mi of menuitems) {
|
|
|
|
if (origin && mi.getAttribute("origin") == origin) {
|
|
|
|
mi.setAttribute("checked", "true");
|
|
|
|
mi.setAttribute("oncommand", "SocialSidebar.hide();");
|
|
|
|
} else if (mi.getAttribute("checked")) {
|
|
|
|
mi.removeAttribute("checked");
|
|
|
|
mi.setAttribute("oncommand", "SocialSidebar.show(this.getAttribute('origin'));");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function(origin) {
|
|
|
|
// always show the sidebar, and set the provider
|
2014-03-12 02:25:45 +00:00
|
|
|
let broadcaster = document.getElementById("socialSidebarBroadcaster");
|
|
|
|
broadcaster.hidden = false;
|
|
|
|
if (origin)
|
|
|
|
this.provider = Social._getProviderFromOrigin(origin);
|
|
|
|
else
|
|
|
|
SocialSidebar.update();
|
|
|
|
this.saveWindowState();
|
2014-07-17 02:15:02 +00:00
|
|
|
Services.telemetry.getHistogramById("SOCIAL_SIDEBAR_STATE").add(true);
|
2013-12-17 05:37:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
2014-03-12 02:25:45 +00:00
|
|
|
let broadcaster = document.getElementById("socialSidebarBroadcaster");
|
|
|
|
broadcaster.hidden = true;
|
2013-12-17 05:37:30 +00:00
|
|
|
this._updateCheckedMenuItems();
|
2014-03-12 02:25:45 +00:00
|
|
|
this.clearProviderMenus();
|
|
|
|
SocialSidebar.update();
|
|
|
|
this.saveWindowState();
|
2014-07-17 02:15:02 +00:00
|
|
|
Services.telemetry.getHistogramById("SOCIAL_SIDEBAR_STATE").add(false);
|
2014-03-12 02:25:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleSidebar: function SocialSidebar_toggle() {
|
|
|
|
let broadcaster = document.getElementById("socialSidebarBroadcaster");
|
|
|
|
if (broadcaster.hidden)
|
|
|
|
this.show();
|
|
|
|
else
|
|
|
|
this.hide();
|
2013-12-17 05:37:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
populateSidebarMenu: function(event) {
|
|
|
|
// Providers are removed from the view->sidebar menu when there is a change
|
|
|
|
// in providers, so we only have to populate onshowing if there are no
|
|
|
|
// provider menus. We populate this menu so long as there are enabled
|
|
|
|
// providers with sidebars.
|
|
|
|
let popup = event.target;
|
|
|
|
let providerMenuSeps = popup.getElementsByClassName("social-provider-menu");
|
|
|
|
if (providerMenuSeps[0].previousSibling.nodeName == "menuseparator")
|
2014-03-11 00:22:00 +00:00
|
|
|
SocialSidebar.populateProviderMenu(providerMenuSeps[0]);
|
2013-12-17 05:37:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
clearProviderMenus: function() {
|
|
|
|
// called when there is a change in the provider list we clear all menus,
|
|
|
|
// they will be repopulated when the menu is shown
|
|
|
|
let providerMenuSeps = document.getElementsByClassName("social-provider-menu");
|
|
|
|
for (let providerMenuSep of providerMenuSeps) {
|
|
|
|
while (providerMenuSep.previousSibling.nodeName == "menuitem") {
|
|
|
|
let menu = providerMenuSep.parentNode;
|
|
|
|
menu.removeChild(providerMenuSep.previousSibling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-11 00:22:00 +00:00
|
|
|
populateProviderMenu: function(providerMenuSep) {
|
2013-12-17 05:37:30 +00:00
|
|
|
let menu = providerMenuSep.parentNode;
|
|
|
|
// selectable providers are inserted before the provider-menu seperator,
|
|
|
|
// remove any menuitems in that area
|
|
|
|
while (providerMenuSep.previousSibling.nodeName == "menuitem") {
|
|
|
|
menu.removeChild(providerMenuSep.previousSibling);
|
|
|
|
}
|
|
|
|
// only show a selection in the sidebar header menu if there is more than one
|
2015-12-17 23:19:00 +00:00
|
|
|
let providers = Social.providers.filter(p => p.sidebarURL);
|
2013-12-17 05:37:30 +00:00
|
|
|
if (providers.length < 2 && menu.id != "viewSidebarMenu") {
|
|
|
|
providerMenuSep.hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let topSep = providerMenuSep.previousSibling;
|
|
|
|
for (let provider of providers) {
|
|
|
|
let menuitem = document.createElement("menuitem");
|
|
|
|
menuitem.className = "menuitem-iconic social-provider-menuitem";
|
|
|
|
menuitem.setAttribute("image", provider.iconURL);
|
|
|
|
menuitem.setAttribute("label", provider.name);
|
|
|
|
menuitem.setAttribute("origin", provider.origin);
|
|
|
|
if (this.opened && provider == this.provider) {
|
|
|
|
menuitem.setAttribute("checked", "true");
|
|
|
|
menuitem.setAttribute("oncommand", "SocialSidebar.hide();");
|
|
|
|
} else {
|
|
|
|
menuitem.setAttribute("oncommand", "SocialSidebar.show(this.getAttribute('origin'));");
|
|
|
|
}
|
|
|
|
menu.insertBefore(menuitem, providerMenuSep);
|
|
|
|
}
|
|
|
|
topSep.hidden = topSep.nextSibling == providerMenuSep;
|
|
|
|
providerMenuSep.hidden = !providerMenuSep.nextSibling;
|
2012-07-18 18:40:05 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-26 23:15:59 +00:00
|
|
|
|
2013-09-04 17:01:38 +00:00
|
|
|
// this helper class is used by removable/customizable buttons to handle
|
2013-11-22 20:11:19 +00:00
|
|
|
// widget creation/destruction
|
2013-09-04 17:01:38 +00:00
|
|
|
|
|
|
|
// When a provider is installed we show all their UI so the user will see the
|
|
|
|
// functionality of what they installed. The user can later customize the UI,
|
|
|
|
// moving buttons around or off the toolbar.
|
|
|
|
//
|
2013-11-22 20:11:19 +00:00
|
|
|
// On startup, we create the button widgets of any enabled provider.
|
|
|
|
// CustomizableUI handles placement and persistence of placement.
|
2013-12-17 05:21:17 +00:00
|
|
|
function ToolbarHelper(type, createButtonFn, listener) {
|
2013-09-04 17:01:38 +00:00
|
|
|
this._createButton = createButtonFn;
|
|
|
|
this._type = type;
|
2013-12-17 05:21:17 +00:00
|
|
|
|
|
|
|
if (listener) {
|
|
|
|
CustomizableUI.addListener(listener);
|
|
|
|
// remove this listener on window close
|
|
|
|
window.addEventListener("unload", () => {
|
|
|
|
CustomizableUI.removeListener(listener);
|
|
|
|
});
|
|
|
|
}
|
2013-09-04 17:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ToolbarHelper.prototype = {
|
2013-11-22 20:11:19 +00:00
|
|
|
idFromOrigin: function(origin) {
|
|
|
|
// this id needs to pass the checks in CustomizableUI, so remove characters
|
|
|
|
// that wont pass.
|
|
|
|
return this._type + "-" + Services.io.newURI(origin, null, null).hostPort.replace(/[\.:]/g,'-');
|
2013-09-04 17:01:38 +00:00
|
|
|
},
|
|
|
|
|
2013-11-22 20:11:19 +00:00
|
|
|
// should be called on disable of a provider
|
2013-09-04 17:01:38 +00:00
|
|
|
removeProviderButton: function(origin) {
|
2013-11-22 20:11:19 +00:00
|
|
|
CustomizableUI.destroyWidget(this.idFromOrigin(origin));
|
2013-09-04 17:01:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
clearPalette: function() {
|
2015-12-17 23:19:00 +00:00
|
|
|
for (let p of Social.providers) {
|
|
|
|
this.removeProviderButton(p.origin);
|
|
|
|
}
|
2013-09-04 17:01:38 +00:00
|
|
|
},
|
|
|
|
|
2013-11-22 20:11:19 +00:00
|
|
|
// should be called on enable of a provider
|
2013-09-04 17:01:38 +00:00
|
|
|
populatePalette: function() {
|
|
|
|
if (!Social.enabled) {
|
|
|
|
this.clearPalette();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create any buttons that do not exist yet if they have been persisted
|
|
|
|
// as a part of the UI (otherwise they belong in the palette).
|
|
|
|
for (let provider of Social.providers) {
|
2013-11-22 20:11:19 +00:00
|
|
|
let id = this.idFromOrigin(provider.origin);
|
2013-12-17 05:21:17 +00:00
|
|
|
this._createButton(id, provider);
|
2013-09-04 17:01:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var SocialStatusWidgetListener = {
|
2013-12-17 05:21:17 +00:00
|
|
|
_getNodeOrigin: function(aWidgetId) {
|
|
|
|
// we rely on the button id being the same as the widget.
|
|
|
|
let node = document.getElementById(aWidgetId);
|
|
|
|
if (!node)
|
|
|
|
return null
|
|
|
|
if (!node.classList.contains("social-status-button"))
|
|
|
|
return null
|
|
|
|
return node.getAttribute("origin");
|
|
|
|
},
|
|
|
|
onWidgetAdded: function(aWidgetId, aArea, aPosition) {
|
|
|
|
let origin = this._getNodeOrigin(aWidgetId);
|
|
|
|
if (origin)
|
|
|
|
SocialStatus.updateButton(origin);
|
|
|
|
},
|
|
|
|
onWidgetRemoved: function(aWidgetId, aPrevArea) {
|
|
|
|
let origin = this._getNodeOrigin(aWidgetId);
|
|
|
|
if (!origin)
|
|
|
|
return;
|
|
|
|
// When a widget is demoted to the palette ('removed'), it's visual
|
|
|
|
// style should change.
|
|
|
|
SocialStatus.updateButton(origin);
|
|
|
|
SocialStatus._removeFrame(origin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 17:01:38 +00:00
|
|
|
SocialStatus = {
|
|
|
|
populateToolbarPalette: function() {
|
|
|
|
this._toolbarHelper.populatePalette();
|
2014-02-06 12:04:56 +00:00
|
|
|
|
|
|
|
for (let provider of Social.providers)
|
|
|
|
this.updateButton(provider.origin);
|
2013-09-04 17:01:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
removeProvider: function(origin) {
|
2013-09-30 18:05:17 +00:00
|
|
|
this._removeFrame(origin);
|
2013-09-04 17:01:38 +00:00
|
|
|
this._toolbarHelper.removeProviderButton(origin);
|
|
|
|
},
|
|
|
|
|
2013-12-16 23:10:30 +00:00
|
|
|
reloadProvider: function(origin) {
|
|
|
|
let button = document.getElementById(this._toolbarHelper.idFromOrigin(origin));
|
|
|
|
if (button && button.getAttribute("open") == "true")
|
|
|
|
document.getElementById("social-notification-panel").hidePopup();
|
|
|
|
this._removeFrame(origin);
|
|
|
|
},
|
|
|
|
|
2013-09-30 18:05:17 +00:00
|
|
|
_removeFrame: function(origin) {
|
|
|
|
let notificationFrameId = "social-status-" + origin;
|
|
|
|
let frame = document.getElementById(notificationFrameId);
|
|
|
|
if (frame) {
|
|
|
|
frame.parentNode.removeChild(frame);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-04 17:01:38 +00:00
|
|
|
get _toolbarHelper() {
|
|
|
|
delete this._toolbarHelper;
|
2013-12-17 05:21:17 +00:00
|
|
|
this._toolbarHelper = new ToolbarHelper("social-status-button",
|
|
|
|
CreateSocialStatusWidget,
|
|
|
|
SocialStatusWidgetListener);
|
2013-09-04 17:01:38 +00:00
|
|
|
return this._toolbarHelper;
|
|
|
|
},
|
|
|
|
|
2013-11-25 12:39:12 +00:00
|
|
|
updateButton: function(origin) {
|
2013-12-17 05:21:17 +00:00
|
|
|
let id = this._toolbarHelper.idFromOrigin(origin);
|
|
|
|
let widget = CustomizableUI.getWidget(id);
|
|
|
|
if (!widget)
|
|
|
|
return;
|
|
|
|
let button = widget.forWindow(window).node;
|
2013-09-04 17:01:38 +00:00
|
|
|
if (button) {
|
|
|
|
// we only grab the first notification, ignore all others
|
2013-12-17 05:21:17 +00:00
|
|
|
let provider = Social._getProviderFromOrigin(origin);
|
2013-09-04 17:01:38 +00:00
|
|
|
let icons = provider.ambientNotificationIcons;
|
|
|
|
let iconNames = Object.keys(icons);
|
|
|
|
let notif = icons[iconNames[0]];
|
2013-11-25 12:39:12 +00:00
|
|
|
|
|
|
|
// The image and tooltip need to be updated for both
|
|
|
|
// ambient notification and profile changes.
|
2013-12-17 05:21:17 +00:00
|
|
|
let iconURL = provider.icon32URL || provider.iconURL;
|
|
|
|
let tooltiptext;
|
2014-06-27 15:58:13 +00:00
|
|
|
if (!notif || !widget.areaType) {
|
2013-12-17 05:21:17 +00:00
|
|
|
button.style.listStyleImage = "url(" + iconURL + ")";
|
2013-09-04 17:01:38 +00:00
|
|
|
button.setAttribute("badge", "");
|
|
|
|
button.setAttribute("aria-label", "");
|
2013-12-17 05:21:17 +00:00
|
|
|
button.setAttribute("tooltiptext", provider.name);
|
2013-09-04 17:01:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-12-17 05:21:17 +00:00
|
|
|
button.style.listStyleImage = "url(" + (notif.iconURL || iconURL) + ")";
|
|
|
|
button.setAttribute("tooltiptext", notif.label || provider.name);
|
2013-09-04 17:01:38 +00:00
|
|
|
|
|
|
|
let badge = notif.counter || "";
|
|
|
|
button.setAttribute("badge", badge);
|
|
|
|
let ariaLabel = notif.label;
|
|
|
|
// if there is a badge value, we must use a localizable string to insert it.
|
|
|
|
if (badge)
|
|
|
|
ariaLabel = gNavigatorBundle.getFormattedString("social.aria.toolbarButtonBadgeText",
|
|
|
|
[ariaLabel, badge]);
|
|
|
|
button.setAttribute("aria-label", ariaLabel);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-12-19 20:41:09 +00:00
|
|
|
_onclose: function(frame) {
|
2014-07-17 02:15:02 +00:00
|
|
|
frame.removeEventListener("close", this._onclose, true);
|
|
|
|
frame.removeEventListener("click", this._onclick, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onclick: function() {
|
|
|
|
Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(1);
|
|
|
|
},
|
|
|
|
|
2013-09-04 17:01:38 +00:00
|
|
|
showPopup: function(aToolbarButton) {
|
|
|
|
// attach our notification panel if necessary
|
|
|
|
let origin = aToolbarButton.getAttribute("origin");
|
|
|
|
let provider = Social._getProviderFromOrigin(origin);
|
|
|
|
|
2014-08-21 14:44:17 +00:00
|
|
|
PanelFrame.showPopup(window, aToolbarButton, "social", origin,
|
2014-07-17 02:15:02 +00:00
|
|
|
provider.statusURL, provider.getPageSize("status"),
|
|
|
|
(frame) => {
|
2014-12-19 20:41:09 +00:00
|
|
|
frame.addEventListener("close", () => { SocialStatus._onclose(frame) }, true);
|
2014-07-17 02:15:02 +00:00
|
|
|
frame.addEventListener("click", this._onclick, true);
|
|
|
|
});
|
|
|
|
Services.telemetry.getHistogramById("SOCIAL_TOOLBAR_BUTTONS").add(1);
|
2015-05-22 17:33:18 +00:00
|
|
|
}
|
|
|
|
};
|
2013-09-04 17:01:38 +00:00
|
|
|
|
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var SocialMarksWidgetListener = {
|
2015-05-22 17:33:18 +00:00
|
|
|
onWidgetAdded: function(aWidgetId, aArea, aPosition) {
|
|
|
|
let node = document.getElementById(aWidgetId);
|
|
|
|
if (!node || !node.classList.contains("social-mark-button"))
|
|
|
|
return;
|
|
|
|
node._receiveMessage = node.receiveMessage.bind(node);
|
|
|
|
messageManager.addMessageListener("Social:ErrorPageNotify", node._receiveMessage);
|
2013-09-04 17:01:38 +00:00
|
|
|
},
|
2015-05-22 17:33:18 +00:00
|
|
|
onWidgetBeforeDOMChange: function(aNode, aNextNode, aContainer, isRemoval) {
|
|
|
|
if (!isRemoval || !aNode || !aNode.classList.contains("social-mark-button"))
|
|
|
|
return;
|
|
|
|
messageManager.removeMessageListener("Social:ErrorPageNotify", aNode._receiveMessage);
|
|
|
|
delete aNode._receiveMessage;
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 17:56:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SocialMarks
|
|
|
|
*
|
|
|
|
* Handles updates to toolbox and signals all buttons to update when necessary.
|
|
|
|
*/
|
|
|
|
SocialMarks = {
|
2014-10-09 19:02:13 +00:00
|
|
|
get nodes() {
|
2015-12-17 23:19:00 +00:00
|
|
|
for (let p of Social.providers.filter(p => p.markURL)) {
|
2013-12-17 05:24:44 +00:00
|
|
|
let widgetId = SocialMarks._toolbarHelper.idFromOrigin(p.origin);
|
|
|
|
let widget = CustomizableUI.getWidget(widgetId);
|
|
|
|
if (!widget)
|
|
|
|
continue;
|
|
|
|
let node = widget.forWindow(window).node;
|
2014-10-09 19:02:13 +00:00
|
|
|
if (node)
|
|
|
|
yield node;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
update: function() {
|
|
|
|
// querySelectorAll does not work on the menu panel, so we have to do this
|
|
|
|
// the hard way.
|
|
|
|
for (let node of this.nodes) {
|
2014-06-27 15:58:13 +00:00
|
|
|
// xbl binding is not complete on startup when buttons are not in toolbar,
|
|
|
|
// verify update is available
|
2014-10-09 19:02:13 +00:00
|
|
|
if (node.update) {
|
2013-12-17 05:24:44 +00:00
|
|
|
node.update();
|
2014-10-09 19:02:13 +00:00
|
|
|
}
|
2013-12-17 05:24:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-06 17:56:01 +00:00
|
|
|
getProviders: function() {
|
|
|
|
// only rely on providers that the user has placed in the UI somewhere. This
|
|
|
|
// also means that populateToolbarPalette must be called prior to using this
|
|
|
|
// method, otherwise you get a big fat zero. For our use case with context
|
|
|
|
// menu's, this is ok.
|
2015-12-17 23:19:00 +00:00
|
|
|
return Social.providers.filter(p => p.markURL &&
|
2016-01-04 23:49:40 +00:00
|
|
|
document.getElementById(this._toolbarHelper.idFromOrigin(p.origin)));
|
2013-09-06 17:56:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
populateContextMenu: function() {
|
|
|
|
// only show a selection if enabled and there is more than one
|
|
|
|
let providers = this.getProviders();
|
|
|
|
|
|
|
|
// remove all previous entries by class
|
2016-01-04 20:04:57 +00:00
|
|
|
let menus = [...document.getElementsByClassName("context-socialmarks")];
|
|
|
|
for (let m of menus) {
|
2015-12-17 23:19:00 +00:00
|
|
|
m.parentNode.removeChild(m);
|
|
|
|
}
|
2013-09-06 17:56:01 +00:00
|
|
|
|
|
|
|
let contextMenus = [
|
|
|
|
{
|
|
|
|
type: "link",
|
|
|
|
id: "context-marklinkMenu",
|
2013-09-11 13:51:03 +00:00
|
|
|
label: "social.marklinkMenu.label"
|
2013-09-06 17:56:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "page",
|
|
|
|
id: "context-markpageMenu",
|
2013-09-11 13:51:03 +00:00
|
|
|
label: "social.markpageMenu.label"
|
2013-09-06 17:56:01 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
for (let cfg of contextMenus) {
|
|
|
|
this._populateContextPopup(cfg, providers);
|
|
|
|
}
|
2014-08-21 14:41:23 +00:00
|
|
|
this.update();
|
2013-09-06 17:56:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
MENU_LIMIT: 3, // adjustable for testing
|
|
|
|
_populateContextPopup: function(menuInfo, providers) {
|
|
|
|
let menu = document.getElementById(menuInfo.id);
|
|
|
|
let popup = menu.firstChild;
|
|
|
|
for (let provider of providers) {
|
|
|
|
// We show up to MENU_LIMIT providers as single menuitems's at the top
|
|
|
|
// level of the context menu, if we have more than that, dump them *all*
|
|
|
|
// into the menu popup.
|
|
|
|
let mi = document.createElement("menuitem");
|
|
|
|
mi.setAttribute("oncommand", "gContextMenu.markLink(this.getAttribute('origin'));");
|
|
|
|
mi.setAttribute("origin", provider.origin);
|
|
|
|
mi.setAttribute("image", provider.iconURL);
|
|
|
|
if (providers.length <= this.MENU_LIMIT) {
|
|
|
|
// an extra class to make enable/disable easy
|
|
|
|
mi.setAttribute("class", "menuitem-iconic context-socialmarks context-mark"+menuInfo.type);
|
|
|
|
let menuLabel = gNavigatorBundle.getFormattedString(menuInfo.label, [provider.name]);
|
|
|
|
mi.setAttribute("label", menuLabel);
|
|
|
|
menu.parentNode.insertBefore(mi, menu);
|
|
|
|
} else {
|
|
|
|
mi.setAttribute("class", "menuitem-iconic context-socialmarks");
|
|
|
|
mi.setAttribute("label", provider.name);
|
|
|
|
popup.appendChild(mi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
populateToolbarPalette: function() {
|
|
|
|
this._toolbarHelper.populatePalette();
|
|
|
|
this.populateContextMenu();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeProvider: function(origin) {
|
|
|
|
this._toolbarHelper.removeProviderButton(origin);
|
|
|
|
},
|
|
|
|
|
|
|
|
get _toolbarHelper() {
|
|
|
|
delete this._toolbarHelper;
|
2015-05-22 17:33:18 +00:00
|
|
|
this._toolbarHelper = new ToolbarHelper("social-mark-button",
|
|
|
|
CreateSocialMarkWidget,
|
|
|
|
SocialMarksWidgetListener);
|
2013-09-06 17:56:01 +00:00
|
|
|
return this._toolbarHelper;
|
|
|
|
},
|
|
|
|
|
2014-07-11 15:50:34 +00:00
|
|
|
markLink: function(aOrigin, aUrl, aTarget) {
|
2013-09-06 17:56:01 +00:00
|
|
|
// find the button for this provider, and open it
|
2013-11-22 20:11:19 +00:00
|
|
|
let id = this._toolbarHelper.idFromOrigin(aOrigin);
|
2014-07-11 15:50:34 +00:00
|
|
|
document.getElementById(id).markLink(aUrl, aTarget);
|
2013-09-06 17:56:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-26 23:15:59 +00:00
|
|
|
})();
|